Ghetto Introspection

I’m looking to write a clang plugin that enables me to do some basic introspection in C. Specifically, I want to be able to get a struct’s name, and iterate over the fields of a struct to get the field’s name and value. I was thinking of adding a “meta” field to every struct during compilation which would look something like the following:

typedef struct {
const char *name;
size_t nfields;
struct {
const char *name;
off_t offset;
size_t size;
} fields[nfields];
} struct_meta_t;

After having dug through some of clang’s sources and doxygen docs, I had originally thought I could add an ASTConsumer which adds the struct, but from what I can tell, Sema generates the errors for invalid struct member access… which is run during AST generation. So I figure I’d need to plug into Sema somehow. Unfortunately, your parser library documentation (

With that said, my question to you all is this. Is this the right way to go about it? And if so, can someone give me a parser library primer / tips on how to get started learning it?