Re: GDB: examining the stack
Re: GDB: examining the stack
- Subject: Re: GDB: examining the stack
- From: Jim Ingham <email@hidden>
- Date: Mon, 6 Nov 2006 10:07:30 -0800
Without debug information, it is quite difficult to figure out what
the arguments to functions are in any frame but the lowest frame on
the stack. The calling conventions for the ABI will tell you how the
arguments are passed TO the function (on PPC they are passed in
registers $r3 and up... But these arguments are not in the set that
the ABI guarantees are saved through the calling chain.
Often the function will copy its arguments onto the stack somewhere,
but it isn't in any prescribed place, so it is hard to find
automatically. In general the debug info would tell us where the
arguments were put, but without debug info you would have to go read
the assembly code to find out). To make matters worse, in optimized
code the arguments won't be kept around any longer than they need to
be. So they may be copied to stack space that is reused, they may be
copied to some non-volatile register, or if they aren't needed before
the function call that takes you further down the stack, they may just
be overwritten. So their values may in fact not be recoverable any
longer.
If you have a small set of functions you are watching, it might be
better to do something like:
(gdb) break <function>
(gdb) commands $bpnum
> print (<Arg1 Type>) $r3
> print (<Arg2 type>) $r4
...
> continue
> end
(gdb)
This will slow down the execution of your program, but it might
recover the information you require.
Jim
On Nov 6, 2006, at 3:22 AM, Perrog wrote:
Hi!
I'm trying to fix a retain-release error in my program but I don't
know where the error is. And the stack frame don't give me any hint.
However, if I could examine the arguments on the stack, it would help
me considerably.
For example, the value of "forKeyPath" argument in frame #3 below is
most likely the key path to the object. Or at least, it would be
intresting to se what it is.
#3 -[NSObject(NSKeyValueObserverRegistration)
removeObserver:forKeyPath:]
But how can I check what the value for argument no. 2 in
removeObserver is?
Most likeley the both arguments are not complexer than simple
pointers.
I had in mind to do something like:
(gdb) frame 3
<output cutted>
(gdb) info frame
Stack level 3, frame at 0xbfffcae0:
pc = 0x929e33ec in -[NSObject(NSKeyValueObserverRegistration)
removeObserver:forKeyPath:]; saved pc 0x929e333c
called by frame at 0xbfffcf30, caller of frame at 0xbfffca80
Arglist at 0xbfffcae0, args:
Locals at 0xbfffcae0, Previous frame's sp is 0xbfffcf30
<output cutted>
(gdb) call (void)NSLog(@"%@", (NSString *)0xbfffcae0)
Are there any known tutorial that cover this issue?
I've goggled and searched gdb manual, but could not find it cover this
issue. I've also checked:
http://developer.apple.com/documentation/DeveloperTools/Conceptual/LowLevelABI/Articles/32bitPowerPC.html#//apple_ref/doc/uid/TP40002438-SW19
how to manually compute the value for $sp, but I'm not sure I does
this correctly.
Any help or hints would be appricated.
Thanks in advance.
---
Program received signal: "EXC_BAD_ACCESS".
(gdb) backtrace
#0 0x907bf584 in CFRetain ()
#1 0x929e3724 in _NSKeyValueObservationInfoCreateByRemoving ()
#2 0x929e34fc in -[NSObject(NSKeyValueObserverRegistration)
_removeObserver:forProperty:] ()
#3 0x929e33ec in -[NSObject(NSKeyValueObserverRegistration)
removeObserver:forKeyPath:] ()
#4 0x929e333c in -[NSObject(NSKeyValueObserverRegistration)
removeObserver:forKeyPath:] ()
#5 0x93c3d3f8 in -[NSAutounbinder removeObserver:forKeyPath:] ()
#6 0x9392fe88 in -[NSBinder _updateObservingRegistration:] ()
#7 0x93955aa8 in -[NSBinder breakConnection] ()
#8 0x93bbfb2c in -[NSObject(NSKeyValueBindingCreation) unbind:] ()
#9 0x93c3d298 in -[NSAutounbinder retainBindingTargetAndUnbind] ()
#10 0x93b583e4 in -[NSWindowController release] ()
#11 0x92939968 in NSPopAutoreleasePool ()
#12 0x9296976c in +[NSAutoreleasePool releaseAllPools] ()
#13 0x937ab438 in -[NSApplication _deallocHardCore:] ()
#14 0x937a9fb4 in -[NSApplication terminate:] ()
#15 0x937a7c4c in -[NSApplication sendAction:to:from:] ()
#16 0x938024b8 in -[NSMenu performActionForItemAtIndex:] ()
#17 0x9380223c in -[NSCarbonMenuImpl
performActionWithHighlightingForItemAtIndex:] ()
#18 0x93801ce4 in -[NSMenu performKeyEquivalent:] ()
#19 0x93801930 in -[NSApplication _handleKeyEquivalent:] ()
#20 0x9370b408 in -[NSApplication sendEvent:] ()
#21 0x93702d10 in -[NSApplication run] ()
#22 0x937f387c in NSApplicationMain ()
#23 0x00002c78 in main (argc=1, argv=0xbffff9c0) at /src/MyApp/
main.m:13
(gdb) frame 3
#3 0x929e33ec in -[NSObject(NSKeyValueObserverRegistration)
removeObserver:forKeyPath:] ()
(gdb) info frame
Stack level 3, frame at 0xbfffcae0:
pc = 0x929e33ec in -[NSObject(NSKeyValueObserverRegistration)
removeObserver:forKeyPath:]; saved pc 0x929e333c
called by frame at 0xbfffcf30, caller of frame at 0xbfffca80
Arglist at 0xbfffcae0, args:
Locals at 0xbfffcae0, Previous frame's sp is 0xbfffcf30
Saved registers:
r13 at 0xbfffce54, r14 at 0xbfffce58, r15 at 0xbfffce5c, r16 at
0xbfffce60, r17 at 0xbfffce64, r18 at 0xbfffce68, r19 at 0xbfffce6c,
r20 at 0xbfffce70, r21 at 0xbfffce74, r22 at 0xbfffce78, r23 at
0xbfffce7c, r24 at 0xbfffce80, r25 at 0xbfffce84, r26 at 0xbfffce88,
r27 at 0xbfffce8c, r28 at 0xbfffce90, r29 at 0xbfffce94, r30 at
0xbfffce98, r31 at 0xbfffce9c, f14 at 0xbfffcea0, f15 at 0xbfffcea8,
f16 at 0xbfffceb0, f17 at 0xbfffceb8, f18 at 0xbfffcec0, f19 at
0xbfffcec8, f20 at 0xbfffced0, f21 at 0xbfffced8, f22 at 0xbfffcee0,
f23 at 0xbfffcee8, f24 at 0xbfffcef0, f25 at 0xbfffcef8, f26 at
0xbfffcf00, f27 at 0xbfffcf08, f28 at 0xbfffcf10, f29 at 0xbfffcf18,
f30 at 0xbfffcf20, f31 at 0xbfffcf28, lr at 0xbfffcf38
This function was not called from a signal handler.
The function prologue begins at 0x929e3238.
The function body begins at 0x929e3258.
A stack frame has been allocated.
1104 bytes of integer and floating-point registers have been saved:
0x929e3254 is the stack setup address.
General-purpose registers r13--r31 have been saved at offset
0xffffff24.
Floating-point registers r14--r31 have been saved at offset
0xffffff70.
The link register has been saved at offset 0x8.
(gdb)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden