Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Test file for GDB preprocessor macro support
@ 2002-03-16 22:28 Jim Blandy
  2002-03-17  9:07 ` Daniel Berlin
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Blandy @ 2002-03-16 22:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: gcc


Since GCC doesn't emit Dwarf 2 macro information, you have to edit it
into the assembly file by hand.  Compile the following source file
with "gcc -gdwarf-2 -dA -S test.c":

----
#include <stdio.h>
#include <stdlib.h>


void
foo ()
{
  printf ("Nice to meet you!\n");
}


int
main (int argc, char **argv)
{
  printf ("Hello, world!\n");
  foo ();
  return 0;
}
---

Now, add the following to the end of test.s:

        .section        .debug_macinfo
        .byte   3       # DW_MACINFO_start_file
        .byte   0       # line number
        .byte   1       # file 1: test.c
        .byte   1       # DW_MACINFO_define
        .byte   2       # line 2
        .ascii  "FOO 12<\0"
        .byte   1       # DW_MACINFO_define
        .byte   3       # line 3
        .ascii  "BAR(arg1,arg2) (arg1<arg2)\0"
	.byte   3       # DW_MACINFO_start_file
        .byte   4       # line 4
        .byte   5       # file 5: /usr/include/stdio.h
        .byte   2       # DW_MACINFO_undef
        .byte   1       # line 1
        .ascii  "FOO\0"
        .byte   1       # DW_MACINFO_define
        .byte   2       # line 2
        .ascii  "FOO(a,b) (a-b)\0"
        .byte   4       # DW_MACINFO_end_file
        .byte   1       # DW_MACINFO_define
        .byte   5       # line 5
        .ascii  "smootz() 42\0"
        .byte   2       # DW_MACINFO_undef
        .byte   10      # line 10
        .ascii  "smootz\0"
        .byte   1       # DW_MACINFO_define
        .byte   11      # line 11
        .ascii  "smootz(a) a+42\0"
        .byte   1       # DW_MACINFO_define
        .byte   12      # line 12
        .ascii  "main_only this macro is only defined for main\0"
        .byte   4       # DW_MACINFO_end_file
        .byte   0       # end of macro information

Assemble that into an executable, with the command "gcc test.s -o
test".  Now, GDB should be able to find the macro info, once you're at
a source line where the macros are in scope:

Starting program: /rigel/jimb/cygnus/pentium3/sourceware/gdb/main/native/build/gdb/gdb -nw macros3
GNU gdb 2002-03-14-cvs
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) break main
Breakpoint 1 at 0x8048426: file test.c, line 15.
(gdb) break foo
Breakpoint 2 at 0x8048406: file test.c, line 8.
(gdb) run
Starting program: /home/jimb/gdb/macros/play/macros3 

Breakpoint 1, main (argc=1, argv=0xbfffd014) at test.c:15
15	  printf ("Hello, world!\n");
(gdb) show macro smootz
Defined at /home/jimb/gdb/macros/play/test.c:11
#define smootz(a) a+42
(gdb) 


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

* Re: Test file for GDB preprocessor macro support
  2002-03-16 22:28 Test file for GDB preprocessor macro support Jim Blandy
@ 2002-03-17  9:07 ` Daniel Berlin
  2002-03-17 21:45   ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Berlin @ 2002-03-17  9:07 UTC (permalink / raw)
  To: Jim Blandy; +Cc: gdb-patches, gcc


On Sunday, March 17, 2002, at 01:28 AM, Jim Blandy wrote:

>
> Since GCC doesn't emit Dwarf 2 macro information, you have to edit it
> into the assembly file by hand.  Compile the following source file
> with "gcc -gdwarf-2 -dA -S test.c":
Once again, we *do* generate it.

add -g3 after -gdwarf-2, and you'll get macro info.

>
> ----
> #include <stdio.h>
> #include <stdlib.h>
>
>
> void
> foo ()
> {
>   printf ("Nice to meet you!\n");
> }
>
>
> int
> main (int argc, char **argv)
> {
>   printf ("Hello, world!\n");
>   foo ();
>   return 0;
> }
> ---
>
> Now, add the following to the end of test.s:
>
>         .section        .debug_macinfo
>         .byte   3       # DW_MACINFO_start_file
>         .byte   0       # line number
>         .byte   1       # file 1: test.c
>         .byte   1       # DW_MACINFO_define
>         .byte   2       # line 2
>         .ascii  "FOO 12<\0"
>         .byte   1       # DW_MACINFO_define
>         .byte   3       # line 3
>         .ascii  "BAR(arg1,arg2) (arg1<arg2)\0"
> 	.byte   3       # DW_MACINFO_start_file
>         .byte   4       # line 4
>         .byte   5       # file 5: /usr/include/stdio.h
>         .byte   2       # DW_MACINFO_undef
>         .byte   1       # line 1
>         .ascii  "FOO\0"
>         .byte   1       # DW_MACINFO_define
>         .byte   2       # line 2
>         .ascii  "FOO(a,b) (a-b)\0"
>         .byte   4       # DW_MACINFO_end_file
>         .byte   1       # DW_MACINFO_define
>         .byte   5       # line 5
>         .ascii  "smootz() 42\0"
>         .byte   2       # DW_MACINFO_undef
>         .byte   10      # line 10
>         .ascii  "smootz\0"
>         .byte   1       # DW_MACINFO_define
>         .byte   11      # line 11
>         .ascii  "smootz(a) a+42\0"
>         .byte   1       # DW_MACINFO_define
>         .byte   12      # line 12
>         .ascii  "main_only this macro is only defined for main\0"
>         .byte   4       # DW_MACINFO_end_file
>         .byte   0       # end of macro information
>
> Assemble that into an executable, with the command "gcc test.s -o
> test".  Now, GDB should be able to find the macro info, once you're at
> a source line where the macros are in scope:
>
> Starting program: 
> /rigel/jimb/cygnus/pentium3/sourceware/gdb/main/native/build/gdb/gdb 
> -nw macros3
> GNU gdb 2002-03-14-cvs
> Copyright 2002 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and 
> you are
> welcome to change it and/or distribute copies of it under certain 
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for 
> details.
> This GDB was configured as "i686-pc-linux-gnu"...
> (gdb) break main
> Breakpoint 1 at 0x8048426: file test.c, line 15.
> (gdb) break foo
> Breakpoint 2 at 0x8048406: file test.c, line 8.
> (gdb) run
> Starting program: /home/jimb/gdb/macros/play/macros3
>
> Breakpoint 1, main (argc=1, argv=0xbfffd014) at test.c:15
> 15	  printf ("Hello, world!\n");
> (gdb) show macro smootz
> Defined at /home/jimb/gdb/macros/play/test.c:11
> #define smootz(a) a+42
> (gdb)


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

* Re: Test file for GDB preprocessor macro support
  2002-03-17  9:07 ` Daniel Berlin
@ 2002-03-17 21:45   ` Eli Zaretskii
  0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2002-03-17 21:45 UTC (permalink / raw)
  To: Daniel Berlin; +Cc: Jim Blandy, gdb-patches, gcc


On Sun, 17 Mar 2002, Daniel Berlin wrote:

> add -g3 after -gdwarf-2, and you'll get macro info.

Or just use -ggdb3 (assuming -ggdb is set up to DTRT), right?


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

end of thread, other threads:[~2002-03-18  5:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-16 22:28 Test file for GDB preprocessor macro support Jim Blandy
2002-03-17  9:07 ` Daniel Berlin
2002-03-17 21:45   ` Eli Zaretskii

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