This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Global object constructors
- To: briareos at lokigames dot com
- Subject: Re: Global object constructors
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Wed, 3 Nov 1999 22:53:00 +0100
- CC: gcc at gcc dot gnu dot org
- References: <19991103105042.C2424@namaste.lokigames-lan.com>
> Is anyone aware of any facilities, or recommended techniques, for
> debugging global object constructors? Assume you have 500k of source
> code that you have been given, and must identify a problem causing
> heap corruption before main() is called. Ideally I'd like to be able
> to walk the global constructor list and thus find the objects and
> place appropriate checks in their constructors. I've been playing with
> __static_initializers_and_destructors_0, but gdb gives all sorts of
> spurious information from it. Identifying the global objects manually
> by browinsg source files is tedious at best.
>
> Any information is greatly appreciated,
As a starting point, please share with us what platform you are
working on. Assuming it is ELFish, here is how you could approach the
problem:
- set a break point on __do_global_ctors_aux. Unfortunately, in the
presence of shared libraries, you have more than one of those. In
that case:
- either link statically, or
- using nm, find the address of the copy of __do_global_ctors_aux
that you want to investigate. This works best for the main
executable, because there won't be relocations. In gdb, do
something like
b *0x08048440
- read the code of __do_global_ctors_aux to see what it does. Even
better, compile it with -g :-(
- Singe-step through that, with instruction steps (si). This will
eventually get into
__static_initializers_and_destructors_0. Single-step through that,
too, until you see that source information is fine.
- When you leave a destructor, make sure you continue on a
per-instruction basis, as line-wise stepping in these functions does
not work.
Hope this helps,
Martin