Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* expanding c-macros in gdb
@ 2001-12-05  2:11 Howind Axel, Externer Dienstleister
  2001-12-05  3:40 ` Choi, Jang-Wook
  2001-12-05  3:43 ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Howind Axel, Externer Dienstleister @ 2001-12-05  2:11 UTC (permalink / raw)
  To: 'gdb@sources.redhat.com'

Hello,

we are using gcc/gdb for development in C. The C code uses some
macros for accessing data, for example:

  #define REFP_XYZ(i) xyz_ptr->s_xyz.r_xyz[i].xyz
  ...
  if (REFP_XYZ(a).abc != 0) ...
  ...

Is there a way to make gdb understand that the command
print REFP_XYZ(a).abc is the same as print xyz_ptr->s_xyz.r_xyz[i].xyz.abc?

I have read in the gcc manual that compiling with -g3 stores information
about
all defined macros, so that "Some debuggers support macro expansion when you
use `-g3'."
This does not seem to work with gdb (gcc 2.95.2, gdb 5.0, on HP-UX 10.20).

Then I thought about defining a macro printmac in gdb, but I have not found
a way to
do the expansion. What I'm thinking about is to call a shell- or sed-skript
that does
the expansion and pass the result on to the print command, something like
this
(transform is the name of a sed-script, that does the actual expansion):

  define printmac(arg)
  print `echo $arg | sed -f transform` 

Is something like this possible in gdb? Can I use a hook?

Thanks in advance,

Axel Howind


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: expanding c-macros in gdb
  2001-12-05  2:11 expanding c-macros in gdb Howind Axel, Externer Dienstleister
@ 2001-12-05  3:40 ` Choi, Jang-Wook
  2001-12-05  3:43 ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: Choi, Jang-Wook @ 2001-12-05  3:40 UTC (permalink / raw)
  To: Howind Axel, Externer Dienstleister; +Cc: 'gdb@sources.redhat.com'

Hi, let me tell you my method.

I use gdb through emacs and use emacs shortcut key C-c C-e after set
region for the macro, then emacs expand & show the macro to me.

After that I print the value in gdb.


cjw


On Wed, 5 Dec 2001, Howind Axel, Externer Dienstleister wrote:

> Hello,
>
> we are using gcc/gdb for development in C. The C code uses some
> macros for accessing data, for example:
>
>   #define REFP_XYZ(i) xyz_ptr->s_xyz.r_xyz[i].xyz
>   ...
>   if (REFP_XYZ(a).abc != 0) ...
>   ...
>
> Is there a way to make gdb understand that the command
> print REFP_XYZ(a).abc is the same as print xyz_ptr->s_xyz.r_xyz[i].xyz.abc?
>
> I have read in the gcc manual that compiling with -g3 stores information
> about
> all defined macros, so that "Some debuggers support macro expansion when you
> use `-g3'."
> This does not seem to work with gdb (gcc 2.95.2, gdb 5.0, on HP-UX 10.20).
>
> Then I thought about defining a macro printmac in gdb, but I have not found
> a way to
> do the expansion. What I'm thinking about is to call a shell- or sed-skript
> that does
> the expansion and pass the result on to the print command, something like
> this
> (transform is the name of a sed-script, that does the actual expansion):
>
>   define printmac(arg)
>   print `echo $arg | sed -f transform`
>
> Is something like this possible in gdb? Can I use a hook?
>
> Thanks in advance,
>
> Axel Howind
>
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: expanding c-macros in gdb
  2001-12-05  2:11 expanding c-macros in gdb Howind Axel, Externer Dienstleister
  2001-12-05  3:40 ` Choi, Jang-Wook
@ 2001-12-05  3:43 ` Eli Zaretskii
  2001-12-05  7:45   ` Daniel Jacobowitz
  1 sibling, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2001-12-05  3:43 UTC (permalink / raw)
  To: Howind Axel, Externer Dienstleister; +Cc: 'gdb@sources.redhat.com'


On Wed, 5 Dec 2001, Howind Axel, Externer Dienstleister wrote:

> Is there a way to make gdb understand that the command
> print REFP_XYZ(a).abc is the same as print xyz_ptr->s_xyz.r_xyz[i].xyz.abc?
> 
> I have read in the gcc manual that compiling with -g3 stores information
> about all defined macros, so that "Some debuggers support macro 
> expansion when you use `-g3'."
> This does not seem to work with gdb (gcc 2.95.2, gdb 5.0, on HP-UX 10.20).

Try compiling with -gdwarf-2 or -gstabs+ instead of -g3.  Perhaps that 
would help (I have no idea whether DWARF2 is supported on HP-UX).

>   define printmac(arg)
>   print `echo $arg | sed -f transform` 

You want to invoke cpp, not Sed, I think: macro expansion is not a simple 
text substitution.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: expanding c-macros in gdb
  2001-12-05  3:43 ` Eli Zaretskii
@ 2001-12-05  7:45   ` Daniel Jacobowitz
  2001-12-05  9:27     ` Daniel Berlin
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jacobowitz @ 2001-12-05  7:45 UTC (permalink / raw)
  To: Eli Zaretskii
  Cc: Howind Axel, Externer Dienstleister, 'gdb@sources.redhat.com'

On Wed, Dec 05, 2001 at 01:42:25PM +0200, Eli Zaretskii wrote:
> 
> On Wed, 5 Dec 2001, Howind Axel, Externer Dienstleister wrote:
> 
> > Is there a way to make gdb understand that the command
> > print REFP_XYZ(a).abc is the same as print xyz_ptr->s_xyz.r_xyz[i].xyz.abc?
> > 
> > I have read in the gcc manual that compiling with -g3 stores information
> > about all defined macros, so that "Some debuggers support macro 
> > expansion when you use `-g3'."
> > This does not seem to work with gdb (gcc 2.95.2, gdb 5.0, on HP-UX 10.20).
> 
> Try compiling with -gdwarf-2 or -gstabs+ instead of -g3.  Perhaps that 
> would help (I have no idea whether DWARF2 is supported on HP-UX).

It doesn't (yet).  At least -gdwarf-2 -g3 saves the necessary
information, we just don't use it.

Hopefully I'll have time to tackle this when I'm finished with v3.

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: expanding c-macros in gdb
  2001-12-05  7:45   ` Daniel Jacobowitz
@ 2001-12-05  9:27     ` Daniel Berlin
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Berlin @ 2001-12-05  9:27 UTC (permalink / raw)
  To: Daniel Jacobowitz
  Cc: Eli Zaretskii, Howind Axel, Externer Dienstleister,
	'gdb@sources.redhat.com'



On Wed, 5 Dec 2001, Daniel Jacobowitz wrote:

> On Wed, Dec 05, 2001 at 01:42:25PM +0200, Eli Zaretskii wrote:
> >
> > On Wed, 5 Dec 2001, Howind Axel, Externer Dienstleister wrote:
> >
> > > Is there a way to make gdb understand that the command
> > > print REFP_XYZ(a).abc is the same as print xyz_ptr->s_xyz.r_xyz[i].xyz.abc?
> > >
> > > I have read in the gcc manual that compiling with -g3 stores information
> > > about all defined macros, so that "Some debuggers support macro
> > > expansion when you use `-g3'."
> > > This does not seem to work with gdb (gcc 2.95.2, gdb 5.0, on HP-UX 10.20).
> >
> > Try compiling with -gdwarf-2 or -gstabs+ instead of -g3.  Perhaps that
> > would help (I have no idea whether DWARF2 is supported on HP-UX).
>
> It doesn't (yet).  At least -gdwarf-2 -g3 saves the necessary
> information, we just don't use it.
>
> Hopefully I'll have time to tackle this when I'm finished with v3.
It's pretty simple, just need to integrate cpplib with the c-parser.

>
> --
> Daniel Jacobowitz                           Carnegie Mellon University
> MontaVista Software                         Debian GNU/Linux Developer
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-12-05 17:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-05  2:11 expanding c-macros in gdb Howind Axel, Externer Dienstleister
2001-12-05  3:40 ` Choi, Jang-Wook
2001-12-05  3:43 ` Eli Zaretskii
2001-12-05  7:45   ` Daniel Jacobowitz
2001-12-05  9:27     ` Daniel Berlin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox