1 / 29

Computer System Laboratory

Computer System Laboratory. Lab7 - Debugging I. Experimental Goal. Build a cross debugger and learn how to do source-level remote debugging with GDB. Environment. Host System Windows XP Build System VirtualBox + Ubuntu 8.04 Target System Creator XScale PXA270 Software GNU Debugger

more
Download Presentation

Computer System Laboratory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer System Laboratory Lab7 - Debugging I

  2. Experimental Goal • Build a cross debugger and learn how to do source-level remote debugging with GDB. / 29

  3. Environment • Host System • Windows XP • Build System • VirtualBox + Ubuntu 8.04 • Target System • Creator XScale PXA270 • Software • GNU Debugger • Compiled toolchain • Test programs • Red Hat GDB GUI (insight) • You can download all software from RSWiki CSL Course Software / 29

  4. Introduction to GDB • How do you debug? • Human brain compiler • printfprintfprintf… • 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. / 29

  5. Cross-Debugger Simulator Compilation (1/2) • Step1: download GDB source codes. (gdb-6.6a.tar.gz) • Step2: extract the source codes. • Step3: set configuration options (check Lab3’s arm-elf-* toolchain path in PATH). • % cd gdb-6.6 • % ./configure --target=arm-elf --prefix=$HOME/<arm-elf –* toolchain path> --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. / 29

  6. Cross-Debugger Simulator Compilation (2/2) • Step4: compile cross-debugger. • % make -j4 • Step5: install cross-debugger. • % make -j4 install • Test your cross-debugger. • % arm-elf-gdb -version / 29

  7. Basic Commands of GDB • (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 Use sim/remote as the mode Setting the break point Start execution Next Step in Print the value Print the backtrace of the stack frame / 29

  8. GDB References • GDB Documentation: • http://www.gnu.org/software/gdb/documentation/ • GDB User Manual: • http://sourceware.org/gdb/current/onlinedocs/gdb/ • GDB basic command: • http://en.wikibooks.org/wiki/GCC_Debugging/gdb • Use the help command in GDB interactive shell. • (gdb) help • Tip: • GDB provide history & auto-complete facility. You can use the kill command to kill current debugging process and reload it by the file command. / 29

  9. Verify the Simulator Debugging (1/2) • Step1: download test program. (foo.c) • Step2: compile the test program. • % arm-elf-gccfoo.c -g -static -o foo1 • -g: add debug symbol into the executable. • -static: build the executable with static library. • Step3: connect to simulator. • % arm-elf-gdb foo1 • (gdb) target sim • Step4: download file from the host to the target (simulator). • (gdb) load foo1 • Step5: set breakpoint at line 7. • (gdb) break 7 / 29

  10. Verify the Simulator Debugging (2/2) • Step6: 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. / 29

  11. Cross-Debugger Compilation (1/2) • Now, we will cross-compile a cross-debugger to do remote debugging on PXA270 from the same GDB source codes. • Step1: delete all temporary files in GDB source codes. • % cd gdb-6.6 • % make distclean • Step2: set configuration options. • % ./configure --target=arm-unknown-linux-gnu --prefix=$HOME/<arm-unknown-linux-gnu–* toolchain path> • Step3: compile cross-debugger. • % make -j4 / 29

  12. Cross-Debugger Compilation (2/2) • Step4: install cross-debugger. • % make -j4 install • Test. • % arm-unknown-linux-gnu-gdb -version / 29

  13. GDBserver Compilation (1/2) • To do remote debugging, we need to build a server for GDB on PXA270. • Step1: set configuration options. • % cd gdb-6.6/gdb/gdbserver • % CFLAGS="-g -O2 -static" ./configure --host=arm-unknown-linux-gnu --target=arm-unknown-linux-gnu • Step2: compile the gdbserver. • % make -j4 / 29

  14. GDBserver Compilation (2/2) • The resulting gdbserver is the program we want. • You can use file to check the executable. / 29

  15. Set Network Environment (1/2) • To do remote debugging, we can build LAN environment. • You can follow the network configuration as below figure. • Target system (PXA270): 192.168.0.100 • Host system (Windows XP): 192.168.0.10 • Build system (Ubuntu 8.04): 192.168.0.101 • Recall in Lab2, we have configured the network of target system and host system, now we only need to configure build system. ethernetcable GDB Client GDB Server 192.168.0.10 192.168.0.100 Host System Target System Build System 192.168.0.101 / 29

  16. Set Network Environment (2/2) • Step1: configure Ubuntu IP (build system). • % sudo vim /etc/network/interfaces auto eth0 iface eth0 inet static address <build-system-ip> netmask 255.255.255.0 gateway <host-system-ip> • % sudo /etc/init.d/networking restart • Step2: configure virtual machine network setting. • “裝置”  “網路卡” “網路” • “附加到” “橋接介面卡” • Please configure correct network interface in“名稱”, i.e., the network interface connected to PXA270. • Note that the network will be disconnected in build system after this configuration. If you want to reconnect to WAN, you can use dhclient command to get new DHCP address. / 29

  17. Verify the Remote Debugging (1/4) • Step1: compile test program. • % arm-unknown-linux-gnu-gccfoo.c -g -static -o foo2 • Step2: copy gdbserver& foo2 to Linux on PXA270. • You can refer to Lab2 to transfer files to Linux. • Do not forget to change permission of these executable. • Step3: execute gdbserver with port 1234 on PXA270. • $ ./gdbserver<build-system-ip>:1234 foo2 / 29

  18. Verify the Remote Debugging (2/4) • Step4: connect to target from build system. • % arm-unknown-linux-gnu-gdb foo2 • (gdb) target remote <target-system-ip>:1234 Target System Build System / 29

  19. Verify the Remote Debugging (3/4) • Step5: now, you can follow previous slides to set breakpoints for debugging, e.g. set to line 7. • (gdb) break 7 • Step6: 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. / 29

  20. Verify the Remote Debugging (4/4) • As slide10 does, if we want to watch the variables b and c, the print command can help you. • You can see that c = &b = 0xbe896ce0 on PXA270. • The root filesystem is the 20M one. / 29

  21. The GDB GUI – Insight (1/5) • Insight is a graphical user interface to GDB written in Tcl/Tk by people working at Red Hat. • 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 / 29

  22. The GDB GUI –Insight (2/5) • There are three modes of insight: • command-line mode: • % arm-elf-insight -nw • Text-based UI mode: • % arm-elf-insight -tui text-based UI mode command-line mode (like GDB) / 29

  23. The GDB GUI – Insight (3/5) • GUI mode: • % arm-elf-insight • “Run” “Connect to target” • Choose your target, e.g., simulator. • “File” “Open” • Choose your executable, e.g., foo1. • Click the source codes to set breakpoints. • “Run” “Run” breakpoint / 29

  24. The GDB GUI – Insight (4/5) • “View” can help you see related debug information. • Please refer to http://sources.redhat.com/insight/index.phpfor more information. local variables console registers / 29

  25. The GDB GUI – Insight (5/5) • 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 192.168.0.100 • Port 1234 • Now, you can start to debug. • Do not forget to use continue to execute. continue / 29

  26. Debug Program (1/2) • Step1: download the test program (pi-agm.tar.gz). • The program is used to compute digits of 𝜋. • Step2: 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. • Step3: transfer the resulting binary pi-agm and configuration pi.ini to PXA270. • Step4: execute the binary. • $ ./pi-agm / 29

  27. Debug Program (2/2) • 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. ? / 29

  28. Another GUI: GDB DDD (Optional) • 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. • We do not ask you use this GUI, and you can try it by yourself. / 29

  29. Lab Requirement & Bonus • Show how you find and correct the bug of pi-agm. • Bonus:Answer the question of lab7 on RSWiki CSL course website.Write it in your report. • Please send your report to both TAs. • csiedatou@gmail.com, meenchen79@gmail.com • Please use this title format: [CSL] G# Lab# Ver# • E.g., [CSL] G13 Lab7 Ver1 / 29

More Related