Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.

Similar presentations


Presentation on theme: "Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1."— Presentation transcript:

1 Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1

2 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Build a cross debugger and learn how to do source-level remote debugging with GDB. 2014/11/4/ 28 2

3 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Host System  Windows XP  Build System  VirtualBox + Ubuntu 8.04  Target System  Creator XScale PXA270  Software  GNU Debugger  Test program foo  Red Hat GDB GUI (insight)  Buggy Program pi-agm  You can find all software on CSL Course Software.CSL Course Software 2014/11/4/ 28 3

4 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  How do you debug?  Human brain compiler  printf printf printf …  GDB - GNU Debugger  Allows you to see what is going on inside your program while it is executing.  Start your program, specifying anything that might affect its behavior.  Make your program stop on specified conditions.  Examine what has happened, when your program has stopped.  Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another. 2014/11/4/ 28 4

5 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Step 1: download GDB source codes. (gdb-6.6a.tar.gz)  Step 2: extract the source codes.  Step 3: set configuration options (check Lab4’s arm-elf-* toolchain path in PATH).  % cd gdb-6.6  %./configure --target=arm-elf --prefix=$HOME/ --enable-sim  We configure --enable-sim to build a simulator for ARM.  We recommend to place cross-debugger and cross-toolchain in the same directory, but it is optional. 2014/11/4/ 28 5

6 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Step 4: compile cross-debugger.  % make  It needs libncurses5-dev package when compiling.  Step 5: install cross-debugger.  % make install  Test your cross-debugger.  % arm-elf-gdb -version 2014/11/4/ 28 6

7 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  (gdb) file [executable_name]  (gdb) target [mode]  (gdb) load [executable_name]  (gdb) break [line_number]  (gdb) run  (gdb) next  (gdb) step  (gdb) print [expression]  (gdb) where  (gdb) quit  (gdb) help 2014/11/4/ 28 7 Setting the break point Start execution Next Step in Print the value Print the backtrace of the stack frame Use sim/remote as the mode

8 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  GDB Documentation:  http://www.gnu.org/software/gdb/documentation/ http://www.gnu.org/software/gdb/documentation/  GDB User Manual:  http://sourceware.org/gdb/current/onlinedocs/gdb/ http://sourceware.org/gdb/current/onlinedocs/gdb/  GDB basic command:  http://en.wikibooks.org/wiki/GCC_Debugging/gdb http://en.wikibooks.org/wiki/GCC_Debugging/gdb  Use the help command in GDB interactive shell.  (gdb) help  Tips:  GDB provide history & auto-complete facility.  You can use the kill command to kill current debugging process and reload it by the file command. 2014/11/4/ 28 8

9 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Step 1: download test program. (foo.c)  Step 2: compile the test program.  % arm-elf-gcc foo.c -g -static -o foo1  -g : add debug symbol into the executable.  -static : build the executable with static library.  Step 3: connect to simulator.  % arm-elf-gdb foo1  (gdb) target sim  Step 4: download file from the host to the target (simulator).  (gdb) load foo1  Step 5: set breakpoint at line 7.  (gdb) break 7 2014/11/4/ 28 9

10 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Step 6: execute the program.  (gdb) run  Now, you can use info, print, etc. commands in GDB to debug your program. For example, if we want to watch the variables b and c in foo.c.  (gdb) print c  (gdb) print b  (gdb) print &b  Recall the line 6 in foo.c.  c = &b;  Since we set the breakpoint at line7, the result in GDB shows that c = &b = 0x1fffe0. 2014/11/4/ 28 10

11 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Now, we will cross-compile a cross-debugger to do remote debugging on PXA270 from the same GDB source codes.  Step 1: delete all temporary files in GDB source codes.  % cd gdb-6.6  % make distclean  Step 2: set configuration options.  %./configure --target=arm-unknown-linux-gnu --prefix=$HOME/  Step 3: compile cross-debugger.  % make 2014/11/4/ 28 11

12 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Step 4: install cross-debugger.  % make install  Test.  % arm-unknown-linux-gnu-gdb -version 2014/11/4/ 28 12

13 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  To do remote debugging, we need to build a server for GDB on PXA270.  Step 1: set configuration options.  % cd gdb-6.6/gdb/gdbserver  % CFLAGS="-g -O2 -static"./configure --host=arm-unknown-linux-gnu --target=arm-unknown-linux-gnu  Step 2: compile the gdbserver.  % make 2014/11/4/ 28 13

14 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  The resulting gdbserver is the program we want.  You can use file to check the executable. 2014/11/4/ 28 14

15 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  To do remote debugging, we can build a LAN environment.  Please check the network configuration as below figure.  Target system (PXA270): 192.168.0.100  Host system (Windows XP): 192.168.0.101  Build system (Ubuntu 8.04): 192.168.0.10  Recall in Lab2, we have configured the network of all systems. 2014/11/4/ 28 15 GDB Server GDB Client ethernet cable Target System Host System 192.168.0.100 192.168.0.10 192.168.0.101 Build System

16 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Step 1: compile test program.  % arm-unknown-linux-gnu-gcc foo.c -g -static -o foo2  Step 2: copy gdbserver & foo2 to Linux on PXA270.  Do not forget to change permission of these executable.  Step 3: execute gdbserver with port 1234 on PXA270.  $./gdbserver :1234 foo2 2014/11/4/ 28 16

17 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Step 4: connect to target from build system.  % arm-unknown-linux-gnu-gdb foo2  (gdb) target remote :1234 2014/11/4/ 28 17 Target System Build System

18 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Step 5: now, you can follow previous slides to set breakpoints for debugging, e.g., set to line 7.  (gdb) break 7  Step 6: continue executing the program.  (gdb) continue  You must use the “ continue ” command instead of the “ run ” command in GDB remote debugging because the program is already running on the remote system when you set remote target.  If you type “ run ”, GDB is attempting to run the program itself, thus dropping the existing target setting, i.e. connection.  Running the ARM executable on the i386 machine tends to yield the don’t know how to run error. 2014/11/4/ 28 18

19 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  As slide10 does, if we want to watch the variables b and c, the print command can help you.slide10  You can see that c = &b = 0xbe896ce0 on PXA270.  The root filesystem is the 20M one. 2014/11/4/ 28 19

20 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Insight is a graphical user interface to GDB written in Tcl/Tk by people working at Red Hat.  http://sources.redhat.com/insight/ http://sources.redhat.com/insight/  You can follow previous slides to compile insight (insight-6.6.tar.bz2) by both arm-elf-* and arm-unknown-linux-gnu-* toolchains.  You should install libx11-dev package before compiling.  % arm-elf-insight -version 2014/11/4/ 28 20

21 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  There are three modes of insight:  command-line mode:  % arm-elf-insight -nw  Text-based UI mode:  % arm-elf-insight -tui 2014/11/4/ 28 21 command-line mode (like GDB) text-based UI mode

22 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  GUI mode:  % arm-elf-insight  “File”  “Open”  Choose your executable, e.g., foo1.  “Run”  “Connect to target”  Choose your target, e.g., simulator.  Click the source codes to set breakpoints.  “Run”  “Run” 2014/11/4/ 28 22 breakpoint

23 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  “View” can help you see related debug information.  Please refer to http://sources.redhat.com/insight/index.php for more information.http://sources.redhat.com/insight/index.php 2014/11/4/ 28 23 local variables console registers

24 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  You also can follow previous slides to do remote debugging by insight.  % arm-unknown-linux-gnu-insight foo2  “Run”  “Connect to target”  Target  GDBServer/TCP  Hostname   Port  1234  Now, you can start to debug.  Do not forget to use continue to execute. 2014/11/4/ 28 24 continue

25 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Step 1: download the test program (pi-agm.tar.gz).  The program is used to compute digits of.  Step 2: try to cross-compile the program for PXA270.  Please compile with “ntt-gen” configuration.  i.e., type “ make ntt-gen ” in the directory pi-agm/src.  Do not forget to change your compiler and add -static and -g flags.  Step 3: transfer the resulting binary pi-agm and configuration pi.ini to PXA270.  Step 4: execute the binary.  $./pi-agm 2014/11/4/ 28 25

26 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  However, we will get negative execution time from the results.  Please use GDB to find why we get the negative execution time and try to fix it. 2014/11/4/ 28 26 ?

27 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  GNU DDD is a graphical front-end for command-line debuggers such as GDB, DBX, WDB, Ladebug, JDB, XDB, the Perl debugger, the bash debugger bashdb, the GNU Make debugger remake, or the Python debugger pydb. GNU DDD GDBDBXLadebugthe Perl debuggerbashdbremakepydb  We do not ask you to use this GUI, and you can try it by yourself. 2014/11/4/ 28 27

28 Lab 9 Department of Computer Science and Information Engineering National Taiwan University  Show how you find and correct the bug of pi-agm. 2014/11/4/ 28 28


Download ppt "Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1."

Similar presentations


Ads by Google