Difference: CS255Spring09DebugCC1 (1 vs. 8)

Revision 82009-01-28 - BinBao

Line: 1 to 1
 
META TOPICPARENT name="CS255Spring09ProjectHome"

CS255/455 Spring 2009 How to Debug your compiler

  • Build a debuggable compiler
Line: 35 to 35
 
    • p print_generic_stmt(stdout, node, 2) can print the generic form of node if it is a statement node, where 2 is the value of the macro TDF_SLIM;
    • p dump_node(node, 2, stdout) can dump details about node and its children.
Added:
>
>
  • Output gimple tree in c-like form: use option -fdump-tree-gimple
  • Output gimple tree in c-like form after the pass for cs255: use option -fdump-cs255-tree-gimple. This will actually print the gimple tree before and after cs255 transformation.
 

* Set ALLOWTOPICCHANGE = ChenDing, BinBao \ No newline at end of file

Revision 72009-01-27 - BinBao

Line: 1 to 1
 
META TOPICPARENT name="CS255Spring09ProjectHome"
Changed:
<
<

CS255/455 Spring 2008 How to Debug your compiler

>
>

CS255/455 Spring 2009 How to Debug your compiler

 
  • Build a debuggable compiler
Changed:
<
<
Usually if we want to debug a program, we need to turn off all compiler optimizations and add '-g' flag when building the program. To build a debuggable GCC, just configure it normally and then make STAGE1_CFLAGS='-g -O0' all-stage1. However, in our project, at most time we only need to debug our own code, which is supposed to be in a single file cs255.c. So you can just build and install the compiler normally. Then each time after you modify cs255.c, build the compiler with make BOOT_CFLAGS='-O0 -g3'. This will go through the bootstrap steps. To further save compile time, you can go to OBJ_DIR/gcc directory and run make CFLAGS='-O0 -g3'.
>
>
Usually if we want to debug a program, we need to turn off all compiler optimizations and add '-g' flag when building the program. To build a debuggable GCC, just configure it normally and then make STAGE1_CFLAGS='-g -O0' all-stage1. However, in our project, at most time we only need to debug our own code, which is supposed to be in a single file gcc-4.2.2/gcc/cs255.c. So you can just build and install the compiler normally. Then each time after you modify cs255.c, build the compiler with make BOOT_CFLAGS='-O0 -g3'. This will go through the bootstrap steps. To further save compile time, you can go to obj/gcc directory and run make CFLAGS='-O0 -g3'. And don't forget to run make install.
 
  • Underneath gcc
    Actually, gcc you called when you do compilation is just a driver for real compiler cc1, assembler as and linker collect2. Use option -v you can see the exact command sequence. For direct debugging you should run gdb cc1.

Revision 62009-01-27 - BinBao

Line: 1 to 1
 
META TOPICPARENT name="CS255Spring09ProjectHome"

CS255/455 Spring 2008 How to Debug your compiler

  • Build a debuggable compiler
Line: 11 to 11
  After getting the command sequence by using gcc -v, you can write a gdb command file to save the typing when starting gdb. Here is an example of such file (your file location and parameters may be different).
      file /localdisk/bao/gcc/obj/gcc/cc1
      b rest_of_handle_cs255
Changed:
<
<
r -quiet -v ab.c -quiet -dumpbase ab.c -mtune=generic -auxbase-strip ab.o -O2 -version -fcs255 -fdump-tree-gimple -fdump-cs255-tree-gimple -o /tmp/cceaerqF.s
>
>
r -quiet -v ab.c -quiet -dumpbase ab.c -mtune=generic -auxbase-strip ab.o -O2 -version -fcs255 -fdump-tree-gimple -fdump-cs255-tree-gimple -o /tmp/cceaerqF.s
 Let's name this file as gdbfile, and then you can run gdb -x gdbfile to start debugging.

  • Get familiar with gdb commands
Line: 30 to 29
 
    1. gdb --annotate=3 cc1.
    2. gdb has been started, so you can use it normally.
Changed:
<
<
* Dump gimple tree node tree-dump.c.
>
>
  • Dump gimple tree node in gdb
    Definitions of dump functions can be found in tree-dump.c and tree-pretty-print.c. Let node be a gimple tree node,
    • p debug_tree(node) can print some basic information about node;
    • p print_generic_stmt(stdout, node, 2) can print the generic form of node if it is a statement node, where 2 is the value of the macro TDF_SLIM;
    • p dump_node(node, 2, stdout) can dump details about node and its children.
 

Revision 52009-01-27 - BinBao

Line: 1 to 1
 
META TOPICPARENT name="CS255Spring09ProjectHome"

CS255/455 Spring 2008 How to Debug your compiler

  • Build a debuggable compiler
Line: 8 to 8
  Actually, gcc you called when you do compilation is just a driver for real compiler cc1, assembler as and linker collect2. Use option -v you can see the exact command sequence. For direct debugging you should run gdb cc1.

  • Write a gdb command file
Changed:
<
<
After getting the command sequence by using gcc -v, you can write a gdb command file to save the typing when starting gdb. Here is an example of such file (your file location and parameters may be different). Let's name this file as gdbfile, and then you can run gdb -x gdbfile to start debugging.
>
>
After getting the command sequence by using gcc -v, you can write a gdb command file to save the typing when starting gdb. Here is an example of such file (your file location and parameters may be different).
  file /localdisk/bao/gcc/obj/gcc/cc1 b rest_of_handle_cs255 r -quiet -v ab.c -quiet -dumpbase ab.c -mtune=generic -auxbase-strip ab.o -O2 -version -fcs255 -fdump-tree-gimple -fdump-cs255-tree-gimple -o /tmp/cceaerqF.s
Changed:
<
<
>
>
Let's name this file as gdbfile, and then you can run gdb -x gdbfile to start debugging.
 
Deleted:
<
<

 
  • Get familiar with gdb commands
    Refer to gdb documentation on how to set break points, print the current call stack, examine variable values, and so on.
    • break [file:]func_name to set a break point; break [filename:]linenum to set a break point at a line; break ... if cond to stop only when cond evaluates to true; info break to print all breakpoints.
Line: 28 to 26
 
  • Run gdb in Emacs
    A nice feature of running gdb in Emacs is it can link a gdb window and source code window together. Stepping in gdb will move the cursor on the source code window as well. A useful trick is to create a soft link to your cc1 on your test case directory, and then you don't need to change your working directory in gdb back and forth.
Changed:
<
<
    • M-x gdb
    • gdb --annotate=3 cc1.
    • gdb has been started, so you can use it normally.
>
>
    1. M-x gdb
    2. gdb --annotate=3 cc1.
    3. gdb has been started, so you can use it normally.
 
Changed:
<
<
  1. gimple tree
  2. node

  • Dumping gimple-node
>
>
* Dump gimple tree node tree-dump.c.
 

Revision 42009-01-26 - BinBao

Line: 1 to 1
 
META TOPICPARENT name="CS255Spring09ProjectHome"
Changed:
<
<

CS255/455 Spring 2008 How to Debug GCC

>
>

CS255/455 Spring 2008 How to Debug your compiler

 
  • Build a debuggable compiler
    Usually if we want to debug a program, we need to turn off all compiler optimizations and add '-g' flag when building the program. To build a debuggable GCC, just configure it normally and then make STAGE1_CFLAGS='-g -O0' all-stage1. However, in our project, at most time we only need to debug our own code, which is supposed to be in a single file cs255.c. So you can just build and install the compiler normally. Then each time after you modify cs255.c, build the compiler with make BOOT_CFLAGS='-O0 -g3'. This will go through the bootstrap steps. To further save compile time, you can go to OBJ_DIR/gcc directory and run make CFLAGS='-O0 -g3'.
Line: 18 to 18
 
  • Get familiar with gdb commands
Changed:
<
<
Refer to gdb documentation on how to set break points, print the current call stack, and examine variable values. You can modify variable values and call program functions within the debugger, making it a good test environment for trying your coding ideas.
>
>
Refer to gdb documentation on how to set break points, print the current call stack, examine variable values, and so on.
 
    • break [file:]func_name to set a break point; break [filename:]linenum to set a break point at a line; break ... if cond to stop only when cond evaluates to true; info break to print all breakpoints.
    • backtrace or bt to print the current call stack; frame n or f n to select a stack frame.
    • print variable to view variable value.
Added:
>
>
    • watch to set watchpoints and disable, enble or delete these points.
    • You can modify variable values and call program functions within the debugger, making it a good test environment for trying your coding ideas.
    • Some other reference: Debugging with GDB by Stallman, Pesch, Shebs, et al.
 
  • Run gdb in Emacs
Changed:
<
<
M-x gdb file_name , or M-x gdb -x command_file_name if you have set a gdb command file.

  • for other commands see Debugging with GDB by Stallman, Pesch, Shebs, et al.
    • you can set watchpoints and disable, enble or delete these points.
    • you can examine the stack and data and change the value of variables
>
>
A nice feature of running gdb in Emacs is it can link a gdb window and source code window together. Stepping in gdb will move the cursor on the source code window as well. A useful trick is to create a soft link to your cc1 on your test case directory, and then you don't need to change your working directory in gdb back and forth.
    • M-x gdb
    • gdb --annotate=3 cc1.
    • gdb has been started, so you can use it normally.
 
  1. gimple tree
  2. node

Added:
>
>

  • Dumping gimple-node

 * Set ALLOWTOPICCHANGE = ChenDing, BinBao

Revision 32009-01-26 - BinBao

Line: 1 to 1
 
META TOPICPARENT name="CS255Spring09ProjectHome"
Added:
>
>

CS255/455 Spring 2008 How to Debug GCC

 
  • Build a debuggable compiler
Changed:
<
<
Usually if we want to debug a program, we need to close all compiler optimizations and add '-g' flag when building the program. To build a debuggable GCC, just configure the compiler normally and then make STAGE1_CFLAGS='-g -O0' all-stage1.
>
>
Usually if we want to debug a program, we need to turn off all compiler optimizations and add '-g' flag when building the program. To build a debuggable GCC, just configure it normally and then make STAGE1_CFLAGS='-g -O0' all-stage1. However, in our project, at most time we only need to debug our own code, which is supposed to be in a single file cs255.c. So you can just build and install the compiler normally. Then each time after you modify cs255.c, build the compiler with make BOOT_CFLAGS='-O0 -g3'. This will go through the bootstrap steps. To further save compile time, you can go to OBJ_DIR/gcc directory and run make CFLAGS='-O0 -g3'.

  • Underneath gcc
    Actually, gcc you called when you do compilation is just a driver for real compiler cc1, assembler as and linker collect2. Use option -v you can see the exact command sequence. For direct debugging you should run gdb cc1.

  • Write a gdb command file
    After getting the command sequence by using gcc -v, you can write a gdb command file to save the typing when starting gdb. Here is an example of such file (your file location and parameters may be different). Let's name this file as gdbfile, and then you can run gdb -x gdbfile to start debugging.
      file /localdisk/bao/gcc/obj/gcc/cc1
      b rest_of_handle_cs255
      r -quiet -v ab.c -quiet -dumpbase ab.c -mtune=generic -auxbase-strip ab.o -O2 -version -fcs255 -fdump-tree-gimple
        -fdump-cs255-tree-gimple -o /tmp/cceaerqF.s


  • Get familiar with gdb commands
    Refer to gdb documentation on how to set break points, print the current call stack, and examine variable values. You can modify variable values and call program functions within the debugger, making it a good test environment for trying your coding ideas.
    • break [file:]func_name to set a break point; break [filename:]linenum to set a break point at a line; break ... if cond to stop only when cond evaluates to true; info break to print all breakpoints.
    • backtrace or bt to print the current call stack; frame n or f n to select a stack frame.
    • print variable to view variable value.

  • Run gdb in Emacs
    M-x gdb file_name , or M-x gdb -x command_file_name if you have set a gdb command file.

  • for other commands see Debugging with GDB by Stallman, Pesch, Shebs, et al.
    • you can set watchpoints and disable, enble or delete these points.
    • you can examine the stack and data and change the value of variables
 
Deleted:
<
<
  1. Use Emacs and gdb
 
  1. gimple tree
  2. node
Changed:
<
<

>
>
 * Set ALLOWTOPICCHANGE = ChenDing, BinBao

Revision 22009-01-26 - BinBao

Line: 1 to 1
 
META TOPICPARENT name="CS255Spring09ProjectHome"
Changed:
<
<
The procedure
  1. Building
>
>
  • Build a debuggable compiler
    Usually if we want to debug a program, we need to close all compiler optimizations and add '-g' flag when building the program. To build a debuggable GCC, just configure the compiler normally and then make STAGE1_CFLAGS='-g -O0' all-stage1.
 
  1. Use Emacs and gdb
  2. gimple tree
  3. node

Revision 12009-01-26 - BinBao

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="CS255Spring09ProjectHome"
The procedure
  1. Building
  2. Use Emacs and gdb
  3. gimple tree
  4. node


* Set ALLOWTOPICCHANGE = ChenDing, BinBao

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding URCS? Send feedback