1
play

1 Host/Target A Big Problem with Debuggers gdb can be used to - PDF document

Debuggers A very real interactive debugger: gdb Widely used Debugging Runs on everything A classic implementation (with and without Debuggers) Mostly standard debugger technology Design decisions Runs and


  1. Debuggers • A very real interactive debugger: gdb – Widely used Debugging – Runs on everything – A classic implementation (with and without Debuggers) • Mostly standard debugger technology • Design decisions – Runs and instruments object code – Must map accurately between source/object code – Must deal with many different machines – Must be well-integrated with the compiler Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 2 / 46 gdb Architecture Breakpoints Three major pieces • The fundamental debugging primitive 1. User interface 2. Symbol piece • How does it work? • Mapping from source code to object code constructs – Via an object code rewriting hack • Dump the compile-time information into extra tables in – To stop at line 42, write an invalid opcode at line 42 the object code (at least when debugging is on) • Invalid opcode should be as small as possible • Typically, most compiler optimizations are disabled – Otherwise, we lose track of the position of source lines – Trap resulting fault, recover, and switch to the UI 3. Execution piece • Run object code • Disassemble object code • Manipulate stack frames • Set breakpoints Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 3 / 46 Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 4 / 46 Single Stepping Other Features • To single step: • Based on breakpoints – Set breakpoint at next instruction – Skip over function call – Resume execution – Break on nth execution of a statement – Trap exception, clear breakpoint, repeat • Based on exploiting compile-time information • Or: – Print the call stack – Etc. – Use hardware interpreter – Interpret instructions to the next source statement Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 5 / 46 Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 6 / 46 1

  2. Host/Target A Big Problem with Debuggers • gdb can be used to debug a program on a • Seemingly unavoidable lack of support for remote machine optimized code – gdb runs on the host – Program runs on the target • Makes it difficult to debug “the real thing” – Find compiler bugs • Introduces cross-architecture issues – Find timing-dependent bugs – Find resource/performance bugs • True for any known approach to debuggers Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 7 / 46 Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 8 / 46 Debugger Advantages • Works even if source is not available – Albeit crippled Debugging without Debuggers • Responsive – Interactive experience is good – Scales well with object code size Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 9 / 46 Debugging without Debuggers A Generic Algorithm • Debugging is more than debuggers • How do people solve these problems? • In fact, debuggers are often the last resort • Binary search – Cut the test case in half – Iterate • Two other common problems: – Figuring out which program change caused a bug • Brilliant idea: Why not automate this? – Reducing a test case to a minimal example Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 11 / 46 Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 12 / 46 2

  3. Delta Debugging Example • Find set of changes that cause a program to • Printing the following file causes Mozilla to crash: fail a test case <td align=left valign=top> <SELECT NAME="op sys" MULTIPLE SIZE=7> • Want to find a minimal set of changes that <OPTION VALUE="All">All<OPTION VALUE="Windows 3.1">Windows 3.1<OPTION VALUE="Windows 95">Windows 95<OPTION VALUE="Windows cause failure 98">Windows 98<OPTION VALUE="Windows ME">Windows ME<OPTION VALUE="Windows 2000">Windows 2000<OPTION VALUE="Windows NT">Windows NT<OPTION VALUE="Mac System 7">Mac System 7<OPTION VALUE="Mac System 7.5">Mac System 7.5<OPTION VALUE="Mac System 7.6.1">Mac System 7.6.1<OPTION VALUE="Mac System 8.0">Mac System 8.0<OPTION VALUE="Mac System 8.5">Mac System 8.5<OPTION VALUE="Mac System 8.6">Mac System 8.6<OPTION VALUE="Mac System 9.x">Mac System 9.x<OPTION VALUE="MacOS X">MacOS X<OPTION VALUE="Linux">Linux<OPTION VALUE="BSDI">BSDI<OPTION VALUE="FreeBSD">FreeBSD<OPTION VALUE="NetBSD">NetBSD<OPTION VALUE="OpenBSD">OpenBSD<OPTION VALUE="AIX">AIX<OPTION Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 13 / 46 Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 14 / 46 Example • Now looking at that file it is hard to figure VALUE="BeOS">BeOS<OPTION VALUE="HP-UX">HP-UX<OPTION out what the real cause of the failure is VALUE="IRIX">IRIX<OPTION VALUE="Neutrino">Neutrino<OPTION VALUE="OpenVMS">OpenVMS<OPTION VALUE="OS/2">OS/2<OPTION VALUE="OSF/1">OSF/1<OPTION VALUE="Solaris">Solaris<OPTION VALUE="SunOS">SunOS<OPTION VALUE="other">other</SELECT></td> • It would be very helpful in finding the error <td align=left valign=top> <SELECT NAME="priority" MULTIPLE SIZE=7> if we can simplify the input file and still <OPTION VALUE="--">--<OPTION VALUE="P1">P1<OPTION VALUE="P2">P2<OPTION VALUE="P3">P3<OPTION VALUE="P4">P4<OPTION generate the same failure VALUE="P5">P5</SELECT> </td> <td align=left valign=top> <SELECT NAME="bug severity" MULTIPLE SIZE=7> <OPTION VALUE="blocker">blocker<OPTION VALUE="critical">critical<OPTION VALUE="major">major<OPTION VALUE="normal">normal<OPTION VALUE="minor">minor<OPTION VALUE="trivial">trivial<OPTION VALUE="enhancement">enhancement</SELECT> </tr> </table> Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 15 / 46 Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 16 / 46 Worked Yesterday, Not Today GCC-2.95.2 Crash double bug(double z[], int n) • What are the causes { int i , j ; for GCC crashing? i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] *(z[0]+1.0); } • Yesterday, my program worked. Today, it does not. return z[n]; Why? } – The new release 4.17 of GDB changed 178,000 lines $ gcc-2.95.2 -O bug.c – it no longer integrated properly with DDD (a graphical gcc: Internal error: front-end) program cc1 got fatal signal 11 – How to isolate the change that caused the failure. $ _ Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 17 / 46 Ερευνητικά Θέματα Ανάπτυξης Λογισμικού - Μάθημα 03 18 / 46 3

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend