Avoid headache while trying to make gdb interrupting at breakpoints in c-tors ...

Mario Scalas mario.scalas at libero.it
Thu May 8 16:45:10 UTC 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

... you just cannot stop there! At least this is true for plugins (but seems 
not limited to them) ... and, no, it is not gideon's (debuggerpart) fault but 
a gdb one (affects the 5.3 too).

Gdb will simply skip breakpoints set in c-tors! I've forund confirmation about 
this on this post: http://sources.redhat.com/ml/gdb/2003-01/msg00192.html
after I asked yesterday to jbb (who confirms it) on #kdevelop. Here it is an 
extract of the channel log (hey, they are useful sometimes ;) :

<snip>
[23:19:55] <marioS> jbb: have you a recent gideon at hand? The debugger behave 
strangely here ...
[23:19:57] <roberto> jbb: yeah!! we have made a lot of progress
[23:20:08]  Signoff: annma (Remote closed the connection)
[23:20:15] <jbb> marioS: oh - can you describe
[23:20:36] <marioS> the debuggere simply skips the breakpoints (well some of 
them)
[23:20:55] <marioS> they are set since the icon is red and I can see the 
messages of the output window
[23:20:55] <jbb> I'm bringing my system uptoday atm
[23:21:17] <jbb> marioS: try doing the same when running gdb at the command 
line
[23:21:36] <jbb> marioS: I bet gdb will skip even then
[23:22:06] <jbb> marioS: a couple of issues here -
[23:22:30] <marioS> argghhh: I'm not so proficient in using gdb by command 
line here and the bp I'm speaking about is a plugin ;)
[23:22:35] <jbb> marioS: optimised code (-O2) can show this behaviour
[23:22:48] <marioS> gdb: -O0 -g3 here
[23:23:06] <marioS> (well, it seems -O2 -O0 -g3 ...)
[23:24:03] <jbb> marioS: hmmm - don't know which is used (-O2 or -O0) - see if 
you can get rid of the -O2
[23:24:13] <jbb> marioS: then there are bugs in gdb
[23:24:36] <jbb> marioS: particular in stopping in constructors in shared 
libraries
[23:25:06] <marioS> jbb: it is proper my case! I cannot stop in AppWizard 
c-tor!!!
[23:25:18] <marioS> so I'm doomed!!!
[23:25:29]  Signoff: roberto ("Client exiting")
[23:25:42] <jbb> nope - set brkpoint before construction
[23:26:03] <jbb> and step into c-tor
[23:26:05] <marioS> and the I can go instruction by instruction?
[23:26:06]  roberto (~roberto at host103-78.pool80181.interbusiness.it) has 
joined channel #kdevelop
[23:26:29] <jbb> It's a pain - I know but the only way I found to get around 
the prob
[23:27:08] <jbb> marioS: It should work (crosses fingers :-)
[23:27:27] <marioS> jbb: I'm using gdb 5.3: is it buggy too?
[23:27:37] <jbb> marioS: for c++ - yes
[23:28:13] <jbb> marioS: but try at the command line anyway
[23:28:51] <jbb> marioS: it's handy to be able to drive gdb just a little
[23:30:00] <jbb> marioS: sometime you might need to fall back on kdebug print 
statements :((
[23:30:28] <marioS> jbb: Arghhhh!!! You are right!!!! If I set the bp before 
creating the object than it works!!!!
[23:30:38] <jbb> marioS: :-))
[23:30:51]  dave (~dmcglone at d14-69-109-37.col.wideopenwest.com) has joined 
channel #kdevelop
[23:31:00] -> -#kdevelop- : but marioS is happy since he now knows how to do 
:)
<snip>

So the solution I've found so far are:
1) Set a bp on any istruction which is _before_ the c-tor call;
2) Create a private function in which to put the code you would put in the 
c-tor, make it called in the c-tor and set bp in the function;
3) Say goodbye to breakpoints and use printf or kdDebug (roberto's way of life 
:)

I've not tested the other solutions as explained in the linked post (use full 
constructor's signature when piloting gdb by command line: the same post says 
that you cannot set breakpoints neither in the destructor). Anybody 
interested in playing with it? ;)

Good luck with debugger,
Mario.

Ps: I've posted this hoping to avoid somebody's else headache ... and 
eventually get feedback :)

- -- 
Mario Scalas <mario dot scalas at libero dot it>
Miser miser! Modo niger et ustus fortiter.
homepage: http://digilander.iol.it/zakuteam
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+uokrkfH25fNf4bcRAud2AKCavCUiiv13bY/h56/fRKd8yNle0QCfTG7w
MPEPuuFEfq2KBcerzeOtWyo=
=xo3o
-----END PGP SIGNATURE-----





More information about the KDevelop-devel mailing list