By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,822 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

Finding static constructors with possible out-of-order initialization

P: n/a

How do I find all static global objects and thereby
all initializors called before main()? The source I
work on is too large for this to be obvious. I would
like to search for *any* possible out-of-order
initializers in a large body of code.

I have tried looking at the assembly and nm output,
but it is not obvious (to me) in C++ how exactly
the linker groups all constructors into something
that would be called before main(). (assuming this
is how it works.)

Is it possible to get this information using nm,
objdump, etc. from the executable?

Note again that the source is far to large to
be able perform any kind of manual modifications
or searches.

The URL:

http://www.parashift.com/c++-faq-lite/ctors.html

explains the "static initialization order fiasco"
that I am trying to find instances of.

-paul
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
(excuse a possible duplicate post, my mail is misbehaving...)

Paul,

just an idea, you will need to fill in some blanks.

Add your own static object into the code and put a breakpoint in
the constructor. Run the debugger and wait for the break. This works
on VC++, you can see the call stack. I believe C++ implementations generate
a list of statically initialized objects and these are processed before you
get
to the main() function call. You should be able to see the function names
which
trigger the processing of this list. You'll have to do a bit of detective
work now,
and figure out how to step through this code, you might need to link in with
a
special debug enabled library, depending on the platform you are working
with.
I'm more familar with VC++, I've debugged a similar problem in my past ok.

hope that helps.

dave


Jul 22 '05 #2

P: n/a

hmmmm - this is a good idea

thanx

-paul

just an idea, you will need to fill in some blanks.

Add your own static object into the code and put a breakpoint in
the constructor. Run the debugger and wait for the break. This works
[...]

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.