views:

33

answers:

2

I use a cross platform toolkit which wraps Objective-C so i do not/can not use XCode. Just the pure command line and plain old makefiles.

I compile my source code with "gcc -Wall -g -O0 " but when running it under gdb control i do not get the stack frames or valid source code lines.

First: What can i do to get this work. Second: How can i use XCode (3.0) giving me a GUI frontend for gdb.

This is what i get when setting a breakpoint and doing a "backtrace" gdb command

0  0x918194a9 in malloc_error_break ()
#1  0x91814497 in szone_error ()
#2  0x9173e523 in szone_free ()
#3  0x9173e38d in free ()
#4  0x000d3c53 in Agui_Paint_Context::checkFontColor ()
#5  0x000b2c81 in Agui_Color_Button::attribute_table ()
#6  0x000e5b2e in Agui_Scroll_Canvas_Scrolling_Mixin::~Agui_Scroll_Canvas_Scrolling_Mixin ()
#7  0x000e8968 in Agui_Scroll_Canvas_Scrolling_Mixin::~Agui_Scroll_Canvas_Scrolling_Mixin ()
#8  0x000e8cd9 in Agui_Scroll_Canvas_Scrolling_Mixin::~Agui_Scroll_Canvas_Scrolling_Mixin ()
#9  0x93325e8f in -[NSApplication sendAction:to:from:] ()
#10 0x93325dcc in -[NSControl sendAction:to:] ()
#11 0x93325c52 in -[NSCell _sendActionFrom:] ()
#12 0x933252ab in -[NSCell trackMouse:inRect:ofView:untilMouseUp:] ()
#13 0x93324afe in -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] ()
#14 0x933243b8 in -[NSControl mouseDown:] ()
#15 0x93322af7 in -[NSWindow sendEvent:] ()
#16 0x932ef6a5 in -[NSApplication sendEvent:] ()
#17 0x0008dc6e in Agui_Attribute_Type_Boolean::~Agui_Attribute_Type_Boolean ()
#18 0x9324cfe7 in -[NSApplication run] ()
#19 0x0008e6b7 in Agui_Attribute_Type_Boolean::~Agui_Attribute_Type_Boolean ()
#20 0x0003faba in ?? ()
#21 0x00073ddd in ?? ()
#22 0x0007c996 in ?? ()
#23 0x00004bb2 in ?? ()
#24 0x00002d76 in ?? ()
(gdb) 

The "Agui_" functions do exist but they are totally wrong. It looks like the file/line association is broken. So i have to fix first before i get any valid GUI support from XCode.

UPDATE: Ok, i was able to setup a project and debug the application from inside XCode but this is not what i really want. The command line debugging still doesn't work even when i changed -g now with -gdwarf-2

A: 

In Xcode just create a legacy makefile project, add the source code to the project, and finally set up a custom executable (under Executables) pointing at your built debug executable.

Paul R
Doesn't work. Setting the breakpoints in the source file does not stop the program.
Lothar
Based on this and what you say in the original question it sounds like some part of your app is not being built with debug symbols enabled (or maybe they are being stripped out at some point) ?
Paul R
I can guarantee that all files are build with "gcc -Wall -g -O0" but the question is if this is enough. From Linux i know that -g is the only required option. Here on MacOSX i have problems.
Lothar
Well all I can tell you is that this approach works for me with legacy projects which are built with a makefile. You just need to make sure that the custom executable is set up correctly, that the source files have the same location as when the executable was built, and that you have -g in your C flags.
Paul R
One other thing to try - set a breakpoint in gdb directly (in the console), e.g. `b main`, then when you hit that, see if it brings up the source file containing main, and then try setting other breakpoints in the source and see if that works.
Paul R
A: 

You do not provide enough information to work out what's going wrong when you try to use GDB directly. A transcript of a gdb session would help (gdb ./foo, breakpoint bar, run, backtrace).

You can debug any already-running process via Xcode by going to Run > Attach to Process > Process ID…. If the problem you're debugging is anywhere within or below main(), you can introduce a call to pause() at the start of main() to hang your process and give you time to attach, then just signal the process to get it to continue.

Far easier would be to do as Paul R. suggests and set up an Xcode project. Xcode can indeed be used to write, build, run, and debug make-based projects. You can always start with an empty project and add the source code and create the build targets yourself. Xcode has built-in support for make-based build targets via its External Target type, but even if it didn't, you could use the Shell Script target to get by.

Jeremy W. Sherman