Re: C structure analyzer ("Reflection" in C?)

"Jan Gray" <>
20 Jul 1999 01:14:56 -0400

          From comp.compilers

Related articles
C structure analyzer ("Reflection" in C?) (1999-07-19)
Re: C structure analyzer ("Reflection" in C?) (Jan Gray) (1999-07-20)
Re: C structure analyzer ("Reflection" in C?) (1999-07-21)
Re: C structure analyzer ("Reflection" in C?) (Keith Thompson) (1999-07-23)
Re: C structure analyzer ("Reflection" in C?) (Jerry Pendergraft) (1999-07-28)
Re: C structure analyzer ("Reflection" in C?) (Norbert Berzen) (1999-07-30)
Re: C structure analyzer ("Reflection" in C?) (Keith Thompson) (1999-07-30)
Re: C structure analyzer ("Reflection" in C?) (Dibyendu Majumdar) (1999-07-30)
[2 later articles]
| List of all articles for this month |

From: "Jan Gray" <>
Newsgroups: comp.compilers
Date: 20 Jul 1999 01:14:56 -0400
Organization: Compilers Central
References: 99-07-063
Keywords: C, tools, comment wrote in message 99-07-063...
> Does anybody know of a tool that I could use that converts the C
>structure definitions into some other source file that has each data
>member name, byte offset, size etc so that I could make a program to
>dynamically compose these "structures"?

> The annoying thing is, I know that somewhere in VC++ it has all
>of this and more because you can browse all of the data structures in
>a program from within the debugger.
> Does anyone know of a way to get VC++ to dump this information
>into some sort of "C source" file that can be included elsewhere?

I don't know, but here's some VC++-specific background and ideas.

By default, a "debug" VC++ build compiles -Zi, which reposits the
compiland's type, symbol, address, etc. debug information in a .pdb
(program database) file, which is then used for many purposes,
including debugging. But (as far as I know) the pdb interfaces are

Instead, compile with the -Z7 flag, which emits old-fashioned MS C7.0
style CodeView debug records into your object file or executable.
Then open this COFF file, find the debug info, and read the symbol and
type records. There you'll find LF_STRUCTURE type records for your
structure definitions, including field names, type indices, and field
offsets. Then recover the types themselves by walking the type graph
using the type indices. But that's a lot of fiddly work. See for the CodeView
info spec.

Also check out the Microsoft Research Semantics-Based Tools Group's
AST toolkit.

"The goal of the AST ToolKit project is to provide product development
groups with a public API to a C++ program's parse tree, symbol table,
and types, as well as to provide us with an infrastructure for our own
research using product groups' code bases."

See for more information.

Jan Gray
[I suspect it'd be easier to write some perl programs that understand
just enough C to process the structure declarations in the source than
to grovel through the COFF symbols. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.