1 / 31

第三单元 dbx 调试器

第三单元 dbx 调试器. What is This Unit is About.

marie
Download Presentation

第三单元 dbx 调试器

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. 第三单元 dbx调试器 中山大学-AIX应用程序开发

  2. What is This Unit is About AIX supports several debuggers. The widely used ones are the popular UNIX debugger dbx and the GUI style debugger idebug. This unit introduces these two debuggers, as well as providing instructions on how to use them to debug simple C programs. A number of other potentially useful debugging tools are brought to the students' attention. The lab exercise provides a buggy program to debug using the student's choice of debuggers.

  3. What You Should Be Able to Do(1) After completing this unit, you should be able to: Compile a program in such a way as to allow easy debugging Create a core dump with programming statements or hardware signals Use dbx and idebug to Find the line that caused a program crash Navigate through source code Display and change variable values Manage breakpoints Know about some of the other AIX facilities that can be used to debug programs

  4. How You Will Check Your Progress You can check your progress by completing Lab exercise 2

  5. References • AIX 5L Differences Guide, Version 5.1 Edition (SG24-5765-01) • AIX 5L Implementation Differences (AU37)

  6. Unit Objectives After completing this unit, you should be able to: Compile a program in such a way as to allow easy debugging Create a core dump with programming statements or hardware signals Use dbx and idebug to - Find the line that caused a program crash - Navigate through source code - Display and change variable values - Manage breakpoints Know about some of the other AIX facilities that can be used to debug programs

  7. 3.1 The dbx Debugger Unit 3. The dbx Debugger

  8. Introduction to dbx

  9. Using the dbx Debugger

  10. Compiling for the debugger During the debugging phase of program development, use the –g option when compiling with cc Adds more information about variables and statements to the final executable (symbol table) Especially useful for dbx Do not use the –O flag during compilation for debugging $ cc -g myprog.c -o myprog

  11. Creating core dump

  12. Core File Naming Conventions Core files can be created with an unique name. Set shell variable CORE_NAMING=yes Export CORE_NAMING variable. Core file created in the name format core.pid.ddhhmmss.

  13. Contents of Core File Core header Idinfo structures mstsave structures Default user stack Default data area Memory mapped regions Vm_info structures

  14. Invoking dbx General syntax: dbx [options] [object_file] [core_file] Example:dbx myprog Conditional debugging: dbx –r [options] [object_file] [command_arguments] Example:dbx –r myprog Attach to a running process: dbx -a pid

  15. 3.2 dbx Subcommands Unit 3. The dbx Debugger

  16. dbx Subcommands List of all subcommands and topics avaiable: Help Divided by functionality Commonly –used subcommands Topics Startup Execution Breakpoints Files Data Machine debugging Environment Threads Expressions Scope Set-variables Usage

  17. Debugging options

  18. Displaying Files (dbx) list 1 # include <stdio.h> 2 3 main() 4{ 5 int x = 20; 6 inty=5; 7 int z; 8 printf("\n\n This is a sample program that does basic arithmetic operations on two integer variables\n\n"); 9 printf("Value of x = %d\n",x); 10 printf("Value of y = %d\n",y); (dbx) list 15,17 15 z = mul_int(x,y); 16 printf("\nMultiplication :x*y= %d\n",z); 17 z = div_int(x,y); Syntax: list[starting source_line_number[,ending source_line_number]] list procedure

  19. Moving between Files and Procedures (dbx) file sample.c (dbx) file functions.c (dbx) list 1 # include<stdio.h> 2 3 int add_int(int,int); 4 int sub_int(int,int); (dbx) func main (dbx) func add_int (dbx) list 11 i = num1 + num2; 12 return(i); 13 } 14 Syntax: file [file_name] func [function_name]

  20. The dbx Stack Trace and String Search (dbx)_ (dbx) where add_int(num1 = 20, num2 = 5), line 11 in "functions.c" main(), line 11 in "sample.c" (dbx)_ (dbx)file sample.c (dbx)/main 3 main() Syntax: where [>file_name] String search options: /string Search forward to next occurrence of string ?string Search backward for next occurrence of string

  21. Displaying variables (dbx) print 5+12 17 (dbx) print num1 20 (dbx) _ • Syntax: • print expression • print variable

  22. Displaying variables(2 of 3) Display with $pretty=”verbose”; Normal display: (dbx) _ (dbx) p d (i = 75, c = 'V', iptr = 0x2ff22b80) Display with $pretty=”on” (dbx) set $pretty="on" (dbx) p d { i=75 c = 'V' iptr = 0x2ff22b80 } Display with $pretty=”verbose”; (dbx) set $pretty="verbose" (dbx) p d i=75 c = 'V' iptr = 0x2ff22b80

  23. Displaying Variables(3 of3) (dbx) dump add_int(num1 = 20, num2 = 5), line 11 in "functions.c" i=0 (dbx) _ (dbx) dump main main(), line 11 in "sample.c" x=20 z=0 y=5 (dbx) Syntax: dump[procedure] [> filename]

  24. Change Variables (dbx) _ (dbx) assign y=10 (dbx) assign x=y (dbx) assign y=1+1 (dbx) print x 10 (dbx) print y 2 (dbx) _y=5 (dbx) Syntax: assignvariable = expression Note: Program must be stopped before assign can be used.

  25. Running a Program (dbx) run This is a sample program that does basic arithmetic operations on two integer variables. Value ofx=20 Value ofy=5 Addition :x+y=25 Subtraction :x-y=15 Multiplication :x*y=100 Division :x/y=4 execution completed (dbx) _ Syntax: run[args] [<filename] [>filename] rerun

  26. Using Breakpoints Breakpoints cause the executing program to stop at a desired line number, procedure, or under certain variable conditions. Setting break points: stop at source_line_number [ if condition ] • Stops when source_line_number is reached stop in procedure [ if condition ] • Stops when procedure is called stop if condition • Stops if condition is true stop variable[ if condition ] • Stops whenever variable changes value

  27. Using Breakpoints(2 of 2) (dbx) status [6] stop in main [8] stop at "functions.c":18 [9] stop ifx>100 [10] stop y in main ifx<y (dbx) _ (dbx) delete 10 (dbx) status [6] stop in main [8] stop at "functions.c":18 [9] stop ifx>100 (dbx) (dbx) file functions.c (dbx) clear 18 (dbx)dump [6] stop in main [9] stop ifx>100 Syntax: status[ > filename ] delete all (or) deleteevent_number [event_number] […] clearline_number

  28. Continuing Execution (dbx) stop in main [2] stop in main (dbx) run [2] stopped in main at line 5 in file "sample.c" 5 int x = 20; (dbx) next stopped in main at line 7 in file "sample.c" 8 inty=5; (dbx)stop at 12 [5] stop at "sample.c":12 (dbx) cont [5] stopped in main at line 12 in file "sample.c" 14 z = add_int(x,y); (dbx)step stopped in add_int at line 11 in file "functions.c" 11 i = num1 + num2; Syntax: cont step next

  29. Tracing To have information displayed while program is executing, use these commands: trace [in procedure] [if condition] trace source_line_number [if condition] trace variable [in procedure] [if condition] Examples: To trace each call to the printf procedure, run: trace printf To trace changes to the variable x within main, run: trace x in main To display a message each time a procedure sub is called, run: trace mul_int

  30. Other dbx commands Other dbx commands To escape to a shell under dbx, run: sh [command] To edit the current source file, run: edit [procedure | file] To create dbx command aliases, run: alias name command_string To release an alias, run: unalias name To enable or disable multiprocess debugging, run: multproc [on | off]

  31. Thank You !

More Related