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

atrn@zeta.org.au (Andy Newman)
1 Aug 1999 23:02:54 -0400

          From comp.compilers

Related articles
[3 earlier articles]
Re: C structure analyzer ("Reflection" in C?) kst@cts.com (Keith Thompson) (1999-07-23)
Re: C structure analyzer ("Reflection" in C?) jerry.pendergraft@endocardial.com (Jerry Pendergraft) (1999-07-28)
Re: C structure analyzer ("Reflection" in C?) norbert@dune.gia.rwth-aachen.de (Norbert Berzen) (1999-07-30)
Re: C structure analyzer ("Reflection" in C?) kst@cts.com (Keith Thompson) (1999-07-30)
Re: C structure analyzer ("Reflection" in C?) dibyendu@mazumdar.demon.co.uk (Dibyendu Majumdar) (1999-07-30)
Re: C structure analyzer ("Reflection" in C?) denne@aps.rwth-aachen.de (Volker Denneberg) (1999-07-30)
Re: C structure analyzer ("Reflection" in C?) atrn@zeta.org.au (1999-08-01)
| List of all articles for this month |

From: atrn@zeta.org.au (Andy Newman)
Newsgroups: comp.compilers
Date: 1 Aug 1999 23:02:54 -0400
Organization: is for the organized.
References: 99-07-063 99-07-150
Keywords: C, tools

The information you want is typically in the debug information
generated by the compilers. I once wrote a program to extract the type
information out of the debug information in the object files generated
by two different compilers and compare them for equivilence. This was
for a shared memory system with two different processors and let us
compare the object code's idea of the structure layouts used in the
comms. code to verify the compilers were doing what we thought they
should be doing with the structure layout (to a degree of course, we
had to trust the debug info). The code read an object file and built a
structure representing the types defined in the debug info. It isn't
hard.


If you have a Unix system with the binutils objdump handy trying doing
an "object --debugging" on an object file with debug symbols. Here's
some snippets of its output from my FreeBSD system,


        typedef long int time_t;
        typedef unsigned int uintptr_t;
        struct _physadr { /* size 4 id 2 */
          int r[1]; /* bitsize 32, bitpos 0 */
        };


        typedef struct _physadr /* id 2 */ *physadr;
        struct flock { /* size 24 id 5 */
          long long int l_start; /* bitsize 64, bitpos 0 */
          long long int l_len; /* bitsize 64, bitpos 64 */
          int l_pid; /* bitsize 32, bitpos 128 */
          short int l_type; /* bitsize 16, bitpos 160 */
          short int l_whence; /* bitsize 16, bitpos 176 */
        };


Chuck in some run-time linking and C can get a little more dynamic.





Post a followup to this message

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