Re: [rust-dev] Debugging rust for a newbie

2014-07-23 Thread Urban Hafner
Hey Huon,

thanks for the help. The problem is really obvious now that you mention it!
Thanks for the debugging tips however. Coming from Ruby all I ever use are
print statements. So it's good to know how to do it!

Urban


On Wed, Jul 23, 2014 at 10:02 AM, Huon Wilson  wrote:

>  It is unlikely to be a lifetimes thing; far, far more likely to be a
> "normal" infinite recursion. The size of the stack frame of each function
> is fixed at compile time, so the way to blow the stack is by calling a lot
> of functions deeply, e.g. it's not possible to write a loop that places
> more and more objects on the stack (not in safe code, anyway).
>
> You can get a backtrace by running the test in a conventional debugger,
> e.g. `gdb --args ./tester produces_a_move`, then type `run`. When it hits
> the abort, gdb will freeze execution and you can run `backtrace` to see the
> function call stack, to see what is recursing deeply.
>
> You can make rustc emit debug info which makes gdb far more useful, by
> compiling with `-g` or, equivalently, `--debuginfo=2`. (Depending on your
> platform, 'lldb' may be better.)
>
>
> If all else fails, you can fall back to println debugging, e.g.
>
> fn gen_move(&self, ...) -> Move {
> println!("calling gen_move");
>
> // ...
> }
>
> ---
>
> Just glancing over your code, it looks like there's mutual recursion
> between Playout::run and McEngine::gen_move:
>
> - McEngine::gen_move calls Playout::run
> https://github.com/ujh/iomrascalai/blob/88e09fdd/src/engine/mc/mod.rs#L82
> - Playout::run calls Playout::gen_move
> https://github.com/ujh/iomrascalai/blob/88e09fdd/src/playout/mod.rs#L42
> - Playout::gen_move calls McEngine::gen_move
> https://github.com/ujh/iomrascalai/blob/88e09fdd/src/playout/mod.rs#L49
>
>
> Huon
>
>
>
> On 23/07/14 17:42, Urban Hafner wrote:
>
> Hey there,
>
>  I'm still quite new to Rust. Until now I was able to fix all my bugs by
> writing tests and/or randomly adding lifetime parameters to keep the
> compiler happy. Now I've hit my first stack overflow. I assume it's due to
> the fact that I've screwed up the lifetimes and the objects live too long
> although I'm not even sure about that. Now my question is: How do I debug
> this? Is there a way to figure out how long objects live? Or how would one
> go about debugging this?
>
>  Oh, if you're interested in the failing code:
> https://github.com/ujh/iomrascalai/pull/46
>
>  Cheers,
>
>  Urban
> --
> Freelancer
>
> Available for hire for Ruby, Ruby on Rails, and JavaScript projects
>
> More at http://urbanhafner.com
>
>
> ___
> Rust-dev mailing 
> listRust-dev@mozilla.orghttps://mail.mozilla.org/listinfo/rust-dev
>
>
>
> ___
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>


-- 
Freelancer

Available for hire for Ruby, Ruby on Rails, and JavaScript projects

More at http://urbanhafner.com
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Debugging rust for a newbie

2014-07-23 Thread Huon Wilson
It is unlikely to be a lifetimes thing; far, far more likely to be a 
"normal" infinite recursion. The size of the stack frame of each 
function is fixed at compile time, so the way to blow the stack is by 
calling a lot of functions deeply, e.g. it's not possible to write a 
loop that places more and more objects on the stack (not in safe code, 
anyway).


You can get a backtrace by running the test in a conventional debugger, 
e.g. `gdb --args ./tester produces_a_move`, then type `run`. When it 
hits the abort, gdb will freeze execution and you can run `backtrace` to 
see the function call stack, to see what is recursing deeply.


You can make rustc emit debug info which makes gdb far more useful, by 
compiling with `-g` or, equivalently, `--debuginfo=2`. (Depending on 
your platform, 'lldb' may be better.)



If all else fails, you can fall back to println debugging, e.g.

fn gen_move(&self, ...) -> Move {
println!("calling gen_move");

// ...
}

---

Just glancing over your code, it looks like there's mutual recursion 
between Playout::run and McEngine::gen_move:


- McEngine::gen_move calls Playout::run 
https://github.com/ujh/iomrascalai/blob/88e09fdd/src/engine/mc/mod.rs#L82
- Playout::run calls Playout::gen_move 
https://github.com/ujh/iomrascalai/blob/88e09fdd/src/playout/mod.rs#L42
- Playout::gen_move calls McEngine::gen_move 
https://github.com/ujh/iomrascalai/blob/88e09fdd/src/playout/mod.rs#L49



Huon


On 23/07/14 17:42, Urban Hafner wrote:

Hey there,

I'm still quite new to Rust. Until now I was able to fix all my bugs 
by writing tests and/or randomly adding lifetime parameters to keep 
the compiler happy. Now I've hit my first stack overflow. I assume 
it's due to the fact that I've screwed up the lifetimes and the 
objects live too long although I'm not even sure about that. Now my 
question is: How do I debug this? Is there a way to figure out how 
long objects live? Or how would one go about debugging this?


Oh, if you're interested in the failing code: 
https://github.com/ujh/iomrascalai/pull/46


Cheers,

Urban
--
Freelancer

Available for hire for Ruby, Ruby on Rails, and JavaScript projects

More at http://urbanhafner.com


___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


[rust-dev] Debugging rust for a newbie

2014-07-23 Thread Urban Hafner
Hey there,

I'm still quite new to Rust. Until now I was able to fix all my bugs by
writing tests and/or randomly adding lifetime parameters to keep the
compiler happy. Now I've hit my first stack overflow. I assume it's due to
the fact that I've screwed up the lifetimes and the objects live too long
although I'm not even sure about that. Now my question is: How do I debug
this? Is there a way to figure out how long objects live? Or how would one
go about debugging this?

Oh, if you're interested in the failing code:
https://github.com/ujh/iomrascalai/pull/46

Cheers,

Urban
-- 
Freelancer

Available for hire for Ruby, Ruby on Rails, and JavaScript projects

More at http://urbanhafner.com
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev