开发者

Debugging MacOSX Cocoa applications with command line gdb (without XCode)

I use a cross platform 开发者_StackOverflowtoolkit 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜