This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: New GCC extension hint
kazu@cs.umass.edu (Kazu Hirata) wrote on 04.01.04 in <20040104.164209.89022544.kazu@cs.umass.edu>:
> > Main idea is this:
> >
> > __VALUE__(var, style)
> >
> > Where __VALUE__ acts like macro that examines variable "var"
> > and returns styled string.
>
> Not exactly the same as your definition of __VALUE__, but would the
> following work for you?
>
> #include <stdio.h>
>
> #define STRINGIFY(X) #X
>
> #define SHOW_VAR(X) printf ("%s = %d\n", STRINGIFY(X), (X))
>
> int
> main ()
> {
> int a = 123;
> SHOW_VAR (a);
> return 0;
> }
Well, that does a fairly poor job - there's certainly no automatic value
formatting of any kind.
I've done something closer in Objective-C using @encode(). That took quite
a bit more code, of course; and I believe the mapping isn't quite
complete, though I could be mistaken.
I suspect if such a mechanism were newly designed today, it would probably
use the debug info (that's how gdb does it, after all).
Hmm.
How hard would it be to have a sort of generic interface to the debug info
that is attached to the currently running executable? Would you need
libbfd, or could you get away with something simpler? Perhaps if you
restricted yourself to ELF/Dwarf-2 targets? There are all manner of useful
tricks you could do with that ...
MfG Kai