Siegfried wrote:
Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.
Varios Microsoft specific extensions to their C++ compiler allows one
to do the same (I'm thinking of both the COM extentions as wells as the
managed extensions).
I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?
have a look at the objdump(1) sources which reads symbols from gcc
generated object files.
but i don't think you will be able to get the information that you need
from the object files, as these linker input files do not necessarily
contain the original C++ object layout in processable form.
you will need C++ parser output to get full identifier information for
C++ source files.
if you don't want to use a full-blown C++ parser implementation, for
example the wrapper/interface generator tool swig has a mode to output
a XML or lisp s-expression formatted abstract syntax tree for given
source files. this gives you parseable data to further work with.
see
http://www.swig.org
-- peter