dbx User’s GuideDocument Number 007-0906-090
86Chapter 7: Debugging Machine Language Codeaddress / count L value maskExaminescount 32-bit words in increasing addresses; printsthose 32-bit words w
Examining Memory and Disassembling Code87For example, to display 10 disassembled machine instructions starting at thecurrent address of the program co
88Chapter 7: Debugging Machine Language CodeConsider a single-precision floating point array named array. You canexamine the six consecutive elements,
Setting Machine-Level Breakpoints89stopi [expression|variable]Inspects the value before executing each machineinstruction and stops if the value has c
90Chapter 7: Debugging Machine Language CodeIf expression1 is of type pointer, look at the data pointed toand watch until it changes. If expression1 i
Continuing Execution After a Machine-Level Breakpoint91To avoid this problem, use the stopi in command:dbx() stopi in functionxIf you really want to u
92Chapter 7: Debugging Machine Language CodeTracing Execution at the Machine LevelThe tracei command allows you to observe the progress of your progra
Writing Conditional Commands at the Machine Level93tracei [expression|variable] in procedureWhenever the variable changes within the procedure thatyou
94Chapter 7: Debugging Machine Language Codethe specified conditions are met, the command list is executed. If one of thecommands in the list is stop (
Stepping Through Machine Code95The formats of the nexti and stepi commands are:nexti [integer] Executes the specified number of machine instructions,st
xiAbout This GuideThis guide explains how to use the source level debugger, dbx. You can usedbx to debug programs in C, C++, Fortran77, and assembly l
111Appendix AA. dbx CommandsAll dbx commands are listed below along with a brief description. For moreinformation about a command, refer to its descri
112Appendix A: dbx Commands!! Repeats the previous command. If the value of the dbxvariable $repeatmode is set to 1, then entering a carriagereturn at
113alias Lists all existing aliases.alias name Lists the alias definition for name.alias name commandDefines name as an alias for command.alias name “st
114Appendix A: dbx Commandscont in procedureSets a temporary breakpoint to stop execution uponentering the specified procedure, then resumes executionw
115If you specify a signal, then dbx sends the signal to yourprogram. If you do not provide a signal, but your programstopped because dbx caught a sig
116Appendix A: dbx Commandsdisable item [, item ... ]Disables the item(s) listed. The specified breakpoint(s),trace(s), or conditional command(s) no lo
117file [file] Changes the current source file to file. The new file becomesthe current source file, on which you can search, list, andperform other operat
118Appendix A: dbx Commandshelp help Explains how to display the help file in your favorite editor.help section Shows this help section. dbx displays t
119nexti [n] Executes the specified number of machine instructions,stepping over procedures. If you do not provide anargument, nexti executes one line.
xiiAbout This GuideAppendix A, “dbx Commands,” lists and describes all dbx commands.Appendix B, “Predefined Aliases,” lists and describes all predefined
120Appendix A: dbx Commandsrecord output [file]Records all dbx output infile. The default file is a temporarydbx file in the /tmp directory. The name of t
121set Displays a list of predefined and user defined variables.set var = exp Defines (or redefines) the specified dbx variable, setting itsvalue to that o
122Appendix A: dbx Commandsstop expressionInspects the expression. If the expression is type pointer,checks the data being pointed at. Otherwise, chec
123stop at line if expressionEvaluates the expression at the given source line. Stops ifthe expression is true.stop in procedure if expressionEvaluate
124Appendix A: dbx Commandsstopi in procedureSets an unconditional breakpoint to stop execution uponentering the specified procedure (for machine-level
125stopi [expression1|variable] if expression2Tests both conditions before executing each machineinstruction. Stops if both conditions are true.If exp
126Appendix A: dbx Commandssyscall catch [{call | return}]Prints a list of all system calls caught upon entry (call) orreturn (return). If you provide
127trace [expression|variable] in procedureWhenever the variable changes within the procedure, dbxprints the old and new values of that variable.If th
128Appendix A: dbx Commandstracei [expression|variable] at addressPrints the value of the variable whenever your programreaches the specified address.
129unrecord session1 [, session2 ... ]Turns off the specified recording session(s) and closes thefile(s) involved.unrecord all Turns off all recording s
Conventions Used in This GuidexiiiSilicon Graphics offers software options to assist in software development.TheCASEVision/Workshop option provides th
130Appendix A: dbx Commandswhen [expression|variable] in procedure {command-list}Inspects the value at every source line within a givenprocedure. If i
131line of the given procedure. If the value has changed and theexpression is true, executes the command list.If expression1 is of type pointer, look
133Appendix BB. Predefined AliasesTable B-1 lists all predefined dbx aliases. You can override any predefinedalias by redefining it with the alias command
134Appendix B: Predefined Aliasesj status Lists all the currently set stop, trace, and whencommands.l list Lists the next $listwindow lines of source
135ri record input Records to the specified file all the input yougive to dbx. If you do not specify a file, dbxcreates a temporary file. The name of the
136Appendix B: Predefined Aliasesw list $curline-5:10 Lists a window of source code around thecurrent line. This command shows the fourlines before th
137Appendix CC. Predefined dbx VariablesPredefined dbx variables are listed in Table C-1. The predefined variablenames begin with “$” so that they do not
138Appendix C: Predefined dbx Variables$curpc The current program counter.$cursrcline The current source listing line plus one.$debugrld 0 If the valu
139$hexchars 0 If nonzero, outputs characters in hexadecimal,using C format “%x”. This affects char typevariables, including those in structures. Itdo
xivAbout This Guide• Mutually exclusive arguments to a command are enclosed in braces({ ... }) and separated by a pipe character (|). In the first exam
140Appendix C: Predefined dbx Variables$mp_program 0 If 0, dbx treats calls to sproc in the same way asit treats calls to fork. If 1, child processesc
141$pendingtraps 0 Uses no pending traps. If nonzero, allowstraps that cannot be satisfied immediately topend until they can be satisfied. This is usefu
142Appendix C: Predefined dbx Variables$procaddr This variable applies only if you invoke dbxwith the -k option (that is, it is not availableunless yo
143$showbreakaddrs 0 If nonzero, show the address of eachbreakpoint placed in the code each time it isplaced. Removal of the breakpoints is notshown.
145active processwait for, 103, 129adding processes to the process group list, 107, 112addpgrp command, 107, 112addproc command, 100, 112add processes
146Indexbreakpointsprocess groups, 108setting, 3, 60, 121, 122status, 71, 121test clause, 63unconditional, 2, 59variable clause, 61, 62, 63, 64, 89, 1
147Indexcommandsprintf, 39, 41, 119printo, 37, 41, 119printregs, 83, 119printx, 37, 41, 119quit, 12, 119record, 31, 119record input, 29, 30, 119, 138r
148Indexcrashes, diagnosing, 1creating aliases, 25, 113$ctypenames, 44, 137$curevent, 137$curline, 137$curpc, 138current directory, 13current source fi
149Indexdown command, 49, 116DSOs, 6dump command, 52, 116Eedit command, 18, 116, 138edit history list, 24, 117editing files, 18, 116$editor, 18, 24, 11
1Chapter 11. Getting Started With dbxYou can use dbx to trace problems in a program at the source code level,rather than at the machine code level. db
150Indexhistory list, 22editing, 24, 117print, 22HOME environment variable, 10I-I flag, 7, 13-i flag, 7ignore command, 73, 74, 118ignoring signals, 74,
151Indexnexti command, 94, 95, 119numeric constants, 36Oobject files, 13specifying, 8, 117octal input, 36, 140octal output, 36, 83, 140$octin, 36, 140$
152Indexpredefined dbx aliasesS, 135s, 135Si, 135si, 135source, 121, 135t, 135u, 135W, 136w, 136wi, 136predefined dbx variables, 19, 137$addrfmt, 137$ad
153Indexprinto command, 37, 41, 119printregs command, 83, 119$printwhilestep, 141$printwide, 141printx command, 37, 41, 119problemsconfused listing, 4
154Indexrun command, 3, 9, 120running process, wait for, 103, 129running programs, 7, 9, 10, 120Sscope of program variables, 41, 46, 49, 51scripts, 32
155Indexsystem callscatching, 76, 126displaying caught, 77, 126displaying ignored, 77, 126exec, 106execv, 77execve, 77exit, 77fork, 77, 97, 104, 107,
156Indexwhatis command, 45, 129when command, 68, 129wheni command, 93, 94, 131where command, 2, 47, 90, 131which command, 45, 131whichobj command, 6,
We'd Like to Hear From YouAs a user of Silicon Graphics documentation, your comments are importantto us. They help us to better understand your n
2Chapter 1: Getting Started With dbx2. Invoke dbx for the failed program as described in “Invoking dbx” onpage 6. dbx automatically reads in the local
Studying a New Program3problem areas. If your program crashes, first determine which line causes itto crash, then set a breakpoint just before that lin
4Chapter 1: Getting Started With dbx• step executes the next line of the program. If the next line is aprocedure call, step steps down into the proced
5Chapter 22. Running dbxThis chapter explains how to run dbx—specifically, it covers:• “Compiling a Program for Debugging Under dbx”• “Compiling and Li
dbx User’s GuideDocument Number 007-0906-090CONTRIBUTORSWritten by Wendy Ferguson and Ken JonesEdited by Christina CaryProduction by Gloria Ackley, Ka
6Chapter 2: Running dbxCompiling and Linking Programs With Dynamic Shared ObjectsThis section summarizes a few things you need to know if you compile
Invoking dbx7dbx OptionsTable 2-1 lists options you can give to dbx. These options are described indetail later in this chapter.Table 2-1 dbx Command-
8Chapter 2: Running dbxSpecifying Object and Core FilesThe object_file is the name of the executable object file that you want todebug. It provides both
Running Your Program9givenfile [file]If you provide a filename, dbx kills the currently runningprocesses and loads the executable code and debugginginfo
10Chapter 2: Running dbxrerun [run-arguments]The rerun command, without any arguments, repeats thelast run command if applicable. Otherwise rerun iseq
Using Online Help11Using Online HelpThe dbx command help has several options:help shows the supported dbx commandshelp keyword shows information perta
12Chapter 2: Running dbxFor example:(dbx) alias foll "print *(struct list *)$p ; \set $p = (int)((struct list *)($p))->next"Hint: You can
13Chapter 33. Examining Source FilesThis chapter explains how to examine source files under dbx. It describes:• “Specifying Source Directories”• “Chang
14Chapter 3: Examining Source FilesFor example, consider debugging a program called look in /usr/local/bin, thesource for which resides in /usr/local/
Changing Source Files15If you use the use command instead, the current directory is no longercontained in the source directory list:(dbx) use /usr/loc
iiiContentsList of Tables ixAbout This Guide xiWhat This Guide Contains xiWhat You Should Know Before Reading This Guide xiiSuggestions fo
16Chapter 3: Examining Source Filesthe current source file to whatever file contains the source for the procedure(see “Examining the Stack” on page 46 f
Searching Through Source Code17list func Lists $listwindow lines starting at procedure func.list func,exp Lists all source between func and exp, inclu
18Chapter 3: Examining Source Files?[reg_exp] Search backward through the current file from the currentline for the regular expression reg_exp. If dbx
19Chapter 44. Controlling dbxThis chapter describes features of dbx that affect its operation whiledebugging a program. Specifically, this chapter cove
20Chapter 4: Controlling dbxThe commands described in this section apply only to the manipulations ofdbx variables, not program variables. “Displaying
Using the History Feature and the History Editor21Listingdbx VariablesIf you enter the set command without providing any arguments, dbxdisplays (in al
22Chapter 4: Controlling dbxExamining the History Listdbx stores all commands that you enter in the history list. The value of thedbx variable $lines
Using the History Feature and the History Editor23For example:(dbx) next 5Process 22545 (test) stopped at [main:60 ,0x10001150] 60 total += j;(dbx)
24Chapter 4: Controlling dbxThe History EditorThe history editor, hed, lets you use your favorite editor on any or all of thecommands in the current d
Creating and Removing dbx Aliases25If you find that you often create the same aliases in your debugging sessions,you can include their definitions in yo
ivContents3. Examining Source Files 13Specifying Source Directories 13Specifying Source Directories With Arguments 13Specifying Source Direct
26Chapter 4: Controlling dbxof these aliases, dbx simply replaces it with the command for which it is analias. Any arguments that you include on the c
Creating and Removing dbx Aliases27The “p” alias takes four arguments and prints them surrounded by verticalbars (|). For example:(dbx) p(1,2,3,4)|1|2
28Chapter 4: Controlling dbxmember. Because the command is too long to fit onto one line, this exampleuses the backslash character (\) to continue the
Recording and Playing Back dbx Input and Output29Recording InputUse the record input command to start an input recording session. Once youstart an inp
30Chapter 4: Controlling dbxFor example, to stop recording session 4, enter the dbx command:(dbx) unrecord 4To stop all recording sessions, enter:(dbx
Recording and Playing Back dbx Input and Output31review the output file using any IRIX system text viewing command (suchas vi(1)).For example, to recor
32Chapter 4: Controlling dbxExecutingdbx ScriptsYou can create dbx command scripts using an external editor and thenexecute these scripts using the pi
33Chapter 55. Examining and Changing DataThis chapter describes how to examine and change data in your programwhile running it under dbx. Topics cover
34Chapter 5: Examining and Changing Datalanguage precedence. You can also use parentheses to explicitly determinethe order of evaluation.Table 5-1 lis
Using Expressions35To print the address of line 27 in the source file foo.c (assuming that foo.ccontains source that was used to compile the current ob
Contentsv5. Examining and Changing Data 33Using Expressions 33Operators 33Constants 36Numeric Constants 36String Constants 37Printin
36Chapter 5: Examining and Changing DataTable 5-4 lists the Fortran 77 language operators recognized by dbx. Note thatdbx does not recognize Fortran l
Printing Expressions37the dbx variable $hexints to a nonzero value. If you set both $octints and$hexints to nonzero values, $hexints takes precedence.
38Chapter 5: Examining and Changing DataThe variable types are listed in Table 5-5.Examples include:(dbx) pd sc-1(dbx) pd ssh-1(dbx) px sc0xff(dbx) px
Using Data Types and Type Coercion (Casts)39printf string [, exp1 [, exp2, ... ] ]Print the value(s) of the specified expression(s) in the formatspecifi
40Chapter 5: Examining and Changing DataUnder dbx, however, you need to be able to distinguish between differentvariables that may have the same name.
Displaying and Changing Program Variables41The leading dot is useful when a file and a procedure have the same name.For instance, suppose mrx.c contain
42Chapter 5: Examining and Changing Datadbx prints the value of each element in the array:{ [0] struct list { next = (nil) value = 10
Displaying and Changing Program Variables43Suppose a single-precision floating point array is namedfloat_vals. To see thesix consecutive elements beginn
44Chapter 5: Examining and Changing DataConflicts Between Variable Names and KeywordsWhen naming variables in your program, avoid using any dbx keyword
Determining the Scope of Variables45(the default), then C type keywords are treated as dbx keywords; if$ctypenames is set to 0, they are not.Case Sens
viContents6. Controlling Program Execution 59Setting Breakpoints 59Setting Unconditional Breakpoints 60Setting Conditional Breakpoints 60S
46Chapter 5: Examining and Changing DataFor example, to display the type declaration for the variable i, enter:(dbx) whatis iint i;The following examp
Examining the Stack47Printing Stack TracesThe where command prints stack traces. Stack traces show the currentactivation levels (procedures) of a prog
48Chapter 5: Examining and Changing Data{ fooexample(3,4,5); return 0;}int fooexample(int i, int j, int k){ int x = i + j + 3*k;
Examining the Stack49The debugger reports the integer argument-passing registers because thisinformation may be of some value.For example, for the cod
50Chapter 5: Examining and Changing Data(dbx) print i5(dbx) upfoo: 40 r = foo2(i+1);The current activation level is now the procedure foo. As indica
Examining the Stack51The syntax for the func command is:func {activation_level | procedure}Changes the current activation level. If you specify anacti
52Chapter 5: Examining and Changing DataIf you use the func command to go to a function that is not on the activationstack, dbx changes only the curre
Using Interactive Function Calls53To perform a complete dump of the program’s active variables, enter:(dbx) dump .> 0 foo2(i = 5) [“/usr/var/tmp/d
54Chapter 5: Examining and Changing DataFunctions called interactively honor breakpoints. Thus you can debug afunction by setting breakpoints and then
Using Interactive Function Calls55==== interactive function call ====For example, if the procedure foo() is interactively called from main(), yousee t
ContentsviiContinuing Execution After a Machine-Level Breakpoint 91Tracing Execution at the Machine Level 92Writing Conditional Commands at the
56Chapter 5: Examining and Changing Data 5 foo(i = 4) [“/usr/var/tmp/dbx_examples/foo.c”:40,0x100011d4] 6 main(argc = 1, argv = 0xffffffad78) [“/u
C++ Considerations57Referring to C++ FunctionsFor the purpose of dbx debugging, functions in C++ programs fall into threegeneral categories:Member fun
58Chapter 5: Examining and Changing Dataint foo:: bar(int x){ return n + x;}foo::foo(int x){ n = x;}int square(int x){ return x*x;}main(){ foo
59Chapter 66. Controlling Program ExecutionA program typically runs until it exits or encounters an unrecoverable error.You can use dbx, however, to s
60Chapter 6: Controlling Program ExecutionEach breakpoint is assigned a number when you create it. Use this numberto reference a breakpoint in the var
Setting Breakpoints61Stopping If a Variable or Memory Location Has ChangedBy including a variable clause in your stop command, you can cause dbx tosto
62Chapter 6: Controlling Program Executionstop [expression|variable] in procedureInspects the value at every source line within a givenprocedure. Stop
Setting Breakpoints63dbx still needs to use the single-step approach if the stop command containsan expression to watch, such as instop if global == 1
64Chapter 6: Controlling Program ExecutionThe following forms of the stop command combine both the variable and testclauses:stop [expression1|variable
Tracing Program Execution65cont {at | to} lineSets a temporary breakpoint at the specified source line,then resumes execution with the current line. Wh
66Chapter 6: Controlling Program ExecutionThe syntax of the trace command is:trace variable Whenever the specified variable changes, dbx prints the old
Tracing Program Execution67and watch until it changes. If expression1 is not of typepointer, look at the 32 bits at that address (assume theexpression
68Chapter 6: Controlling Program Execution(dbx) trace arg_process.curargProcess 2395: [7] trace .test.arg_process.curarg inarg_processWhen you execute
Writing Conditional Commands69If the expression is of type pointer, look at the data pointedto and watch until it changes. If the expression is not of
70Chapter 6: Controlling Program Executionand watch until it changes. If expression1 is not of typepointer, look at the 32 bits at that address (assum
Managing Breakpoints, Traces, and Conditional Commands71Listing Breakpoints, Traces, and Conditional CommandsThe status command lists all of the break
72Chapter 6: Controlling Program ExecutionThe syntax of the disable command is:disable item [, item ... ]Disables the specified breakpoint(s), trace(s)
Using Signal Processing73Process 22631: [5] when at “/usr/var/tmp/dbx_examples/test.c”:60 { print i, jDeleting Breakpoints, Traces, and Conditional Co
74Chapter 6: Controlling Program ExecutionThe catch and ignore commands have the following syntax:catch {signal | all}Instructsdbx to stop your progra
Using Signal Processing75continues to run. Use the showproc command to see whether the processis still running. Then use the suspend command to stop t
ixList of TablesTable 2-1 dbx Command-Line Options 7Table 5-1 dbx Language Independent Operators 34Table 5-2 C Language Operators Recognized by
76Chapter 6: Controlling Program ExecutionSIGALRM signal to your program. Your program then enters thealarm_handler procedure and stops. You can then
Stopping at System Calls77syscall ignore {call | return} {system_call | all}Clears the breakpoint to stop execution upon entering (call)or returning f
78Chapter 6: Controlling Program ExecutionStepping Through Your ProgramStepping is a process of executing your program for a fixed number of linesand t
Stepping Through Your Program79Stepping Using thestep CommandThe format of the step command is:step [integer] Executes the specified number of lines of
80Chapter 6: Controlling Program ExecutionUsing thereturn CommandIf you step into a procedure and then decide you don’t want to step throughthe rest o
81Chapter 77. Debugging Machine Language CodeThis chapter explains how to debug machine language code by:• “Examining and Changing Register Values”• “
82Chapter 7: Debugging Machine Language CodeFor registers with alternate names, the dbx variable $regstyle controls whichname is displayed when you di
Examining and Changing Register Values83Memory and Disassembling Code” on page 85). If $regstyle is set to 0, thendbx uses the alternate form of the r
84Chapter 7: Debugging Machine Language Codef6=0.0000000e+00 f7=0.0000000e+00 f8=0.0000000e+00f9=0.0000000e+00 f10=0.0000000e+00
Examining Memory and Disassembling Code85assign register = expressionAssigns the value of expression to register. You must precedethe name of the regi
Commenti su questo manuale