This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

solution: expanding c-macros in gdb


Hello,

finally it works. Thanks to everyone who answered.

Compiling with -gdwarf-2 or -gstabs+ as suggested didn't work on HP-UX.

In case anybody else is interested, I'll give a short description
of what I have done.

First, I made a script, that extracts all macro definitions from
our headers (using gcc -E -dM) and stores the information
in a file called expand.mac. Then, I wrote a second script that actually
calls the preprocessor as suggested by Eli Zaretskii to expand
macros and then outputs a gdb command like this:

  #!/bin/sh
  INFILE=$HOME/.expand.c
  OUTFILE=$HOME/.expand.tmp
  MACFILE=expand.mac
  echo $2 > $INFILE
  gcc -E -P -include $MACFILE $INFILE -o $OUTFILE 2> /dev/null
  echo "$1 \c" ; sed -n -e"/./p" $OUTFILE

This file is called with two commands: the gdb command to be
run and the expression to be expanded. example:

given the macro
  #define REX_XYZ(idx) s_xyz.r_xyz[idx].xyz
calling the script like this
    expand.sh print REF_XYZ(i).abc
will give the result
    print s_xyz.r_xyz[i].xyz.abc

Now in my .gdbinit, I added these:

  define print
  printf "$arg0 = "
  shell expand.sh output '$arg0' > .expand.gdb
  source .expand.gdb
  echo \n
  end

Like this, whenever I type "print <expr>", the preprocessor is called
to do the macro expansion. The reason for using another command
name like i.e. mprint is that now, I can for example use DDD's right-click
context menu to inspect expressions containing macros.

This is perhaps not an elegant approach, but it works and is
acceptable for our needs. Perhaps it is of use for someone else, too.

Thanks once again to all who helped me.

Axel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]