🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #450

Re: Tracing method calls in gdb (SUMMARY)

#450
From: Dave Griffiths
Date: Wed, 05 Aug 1992 18:10
67 lines
2403 bytes
In article <1992Jul31.235937.450@prim> prim!dave@germany.eu.net (Dave Griffiths) writes:
>I find that quite often I would like to trace the methods that are being
>called during execution of a program. Has anybody got a gdb script that
>will do this? Presumably it's possible to put a break into something like
>objc_msgSend() that will print the object name and method and then continue?
>

The only replies I got were from other people also expressing an interest in
how to do it, so I figured it out myself (see below). This is for version
2.0 of the OS. You have to disassemble objc_msgSend() and objc_msgSendSuper()
to find the calls to "jmp (a0)" if you're running some other version and it
doesn't work.

However, the results weren't as useful as I'd hoped. For one thing, it runs
soooooo SLOWLY! Mainly I suppose because you're switching back and forth
between the two processes. Conditional breaks don't help for the same
reason. Secondly, the simplest of operations results in trillions of method
calls! Ploughing through them is quite a chore. It would be nice to have
some way of showing the stack depth and then you could indent the output
accordingly to make it more readable. Couldn't think of an easy way to do
it though. (You could increment a convenience variable on input, set a
break at the return address and decrement it on return, but how to remove
the return break without messing up recursion?).

Anyway if anyone wants to play, here it is:

break *(&objc_msgSend + 46)
commands 1
silent
x/i $a0
cont
end
break *(&objc_msgSend + 104)
commands 2
silent
x/i $a0
cont
end
break *(&objc_msgSend + 180)
commands 3
silent
x/i $a0
cont
end
break *(&objc_msgSendSuper + 50)
commands 4
silent
x/i $a0
cont
end
break *(&objc_msgSendSuper + 102)
commands 5
silent
x/i $a0
cont
end
break *(&objc_msgSendSuper + 166)
commands 6
silent
x/i $a0
cont
end

This assumes that these are the first breakpoints you have set (I put
the script into .gdbinit).

Dave Griffiths
Technical Details
Message-ID: <1992Aug5.181038.583@prim>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!unido!prim!dave
References: <1992Jul31.235937.450@prim>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!unido!prim!dave
From: prim!dave@germany.eu.net (Dave Griffiths)
Newsgroups: comp.sys.next.programmer
Subject: Re: Tracing method calls in gdb (SUMMARY)
Message-ID: <1992Aug5.181038.583@prim>
Date: 5 Aug 92 18:10:38 GMT
References: <1992Jul31.235937.450@prim>
Organization: Primitive Software Ltd.
Lines: 67