Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: oZZ on February 11, 2007, 12:32:07 am

Title: GDB Pause
Post by: oZZ on February 11, 2007, 12:32:07 am
Is there a way in C::B to pause an application running inside gdb to get the stack trace?

I can't even do it from the command line since control-C doesn't get passed from gdb to the application (in cmd.exe).  In other shells (rxvt/sh and bash) ctrl-c halts gdb itself.

I can get a stacktrace via procexp (XP version), but the symbols don't load correctly, so it's not exactly relevant.

I've seen posts on here of people who have gotten stacktraces of hanging (not crashed) apps, so I know there's a way.

Thanks
-Shawn.
Title: Re: GDB Pause
Post by: Pecan on February 11, 2007, 02:40:25 am
Is there a way in C::B to pause an application running inside gdb to get the stack trace?

I can't even do it from the command line since control-C doesn't get passed from gdb to the application (in cmd.exe).  In other shells (rxvt/sh and bash) ctrl-c halts gdb itself.

I can get a stacktrace via procexp (XP version), but the symbols don't load correctly, so it's not exactly relevant.

I've seen posts on here of people who have gotten stacktraces of hanging (not crashed) apps, so I know there's a way.

Thanks
-Shawn.

Put an asm("int3"); statement in the program at the point you want to see the backtrace.
Run it under GDB or the CB debugger. You'll get a trap (sigint) at that instruction.

You can also make it conditional, eg, if (i<0) asm("int3");

From the point of the sigint, you can backtrace, step, continue, etc.

Be sure to remove it for release. A lot of us forget to take 'em out, and they cause real grief.
Title: Re: GDB Pause
Post by: oZZ on February 11, 2007, 03:35:28 am
The problem is I don't know when I want to see the backtrace.  It's going into an infinite loop somewhere and I want to break when its in the loop.
Title: Re: GDB Pause
Post by: Pecan on February 11, 2007, 04:11:06 am
The problem is I don't know when I want to see the backtrace.  It's going into an infinite loop somewhere and I want to break when its in the loop.

That is not possible under windows AFAIK.
Title: Re: GDB Pause
Post by: oZZ on February 11, 2007, 04:28:39 am
Wow.. windows sucks ;)

Thanks for the help though!