This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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]

Re: Test file for GDB preprocessor macro support



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)


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