473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Finding static constructors with possible out-of-order initialization


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
2 1291
(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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: A J Le Couteur Bisson | last post by:
Could someone please confirm that static class constructors are only called at the first use of a non-static constructor on the class, or am I doing something wrong? If this is indeed the case...
7
by: Mike P | last post by:
I have a class with a dozen+ properties, some of which will be set a value, and some not, depending on the constructor called. I also have a method which has only one overload and all of the...
3
by: Jordan S. | last post by:
Just learning OOP here... Does it make sense to have a constructor in a static class? Say I have a class with a constructor and then mark that class as static; will it (the default constructor) get...
3
by: Adam | last post by:
What happens if one thread is executing a static constructor and another thread starts. Does the second thread block until the first is done in the static constructor? I want to make sure all my...
4
by: Siegfried Heintze | last post by:
Can one declare static constructors in VB like one can in C#? In C#, static constructors execute once before any instances have been created. Thanks, Siegfried
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.