|
Page 2 of 3 Basics of Working with gdbgdb has a command-line interface similar to a Unix shell. You type a command and then press the Enter key to execute it. If you have never worked with gdb before, begin by executing the help command, which produces the following output: List of classes of commands: aliases -- Aliases of other commands breakpoints -- Making program stop at certain points data -- Examining data files -- Specifying and examining files internals -- Maintenance commands obscure -- Obscure features running -- Running the program stack -- Examining the stack status -- Status inquiries support -- Support facilities tracepoints -- Tracing of program execution without stopping the program user-defined -- User-defined commands Type "help" followed by a class name for a list of commands in that class. Type "help" followed by command name for full documentation. Command name abbreviations are allowed if unambiguous.
The instructions in the preceding output give you a starting point from which you can continue a more in-depth study of gdb. For example, if you want to learn about how to run a program being debugged, execute help running, which in turn gives you the following:
Running the program. List of commands: advance -- Continue the program up to the given location (same form as args for break command) attach -- Attach to a process or file outside of GDB continue -- Continue program being debugged detach -- Detach a process or file previously attached disconnect -- Disconnect from a target finish -- Execute until selected stack frame returns handle -- Specify how to handle a signal info handle -- What debugger does when program gets various signals interrupt -- Interrupt the execution of the debugged program jump -- Continue program being debugged at specified line or address kill -- Kill execution of program being debugged next -- Step program nexti -- Step one instruction run -- Start debugged program set args -- Set argument list to give program being debugged when it is started set environment -- Set environment variable value to give the program set follow-fork-mode -- Set debugger response to a program call of fork or vfork set scheduler-locking -- Set mode for locking scheduler during execution set step-mode -- Set mode of the step operation show args -- Show argument list to give program being debugged when it is started show follow-fork-mode -- Show debugger response to a program call of fork or vfork show scheduler-locking -- Show mode for locking scheduler during execution show step-mode -- Show mode of the step operation signal -- Continue program giving it signal specified by the argument step -- Step program until it reaches a different source line stepi -- Step one instruction exactly target -- Connect to a target machine or process thread -- Use this command to switch between threads thread apply -- Apply a command to a list of threads apply all -- Apply a command to all threads tty -- Set terminal for future runs of program being debugged unset environment -- Cancel environment variable VAR for the program until -- Execute until the program reaches a source line greater than the current Type "help" followed by command name for full documentation. Command name abbreviations are allowed if unambiguous.
Now you have a list of commands, related to running a program, to learn. Suppose you want to learn about the run command. Execute help run. The following output is produced:
Start debugged program. You may specify arguments to give it. Args may include "*", or "[...]"; they are expanded using "sh". Input and output redirection with ">", "<", or ">>" are also allowed. With no arguments, uses arguments last specified (with "run" or "set args"). To cancel previous arguments and run with no arguments, use "set args" without arguments.
Using the preceding method, you can get a full listing of gdb commands and learn about each one. If you prefer reading the manual, it is available at http:://www.gnu.org/ software/gdb/documentation. Table 2-4 is a list of commands that you may find particularly useful when studying the MySQL source. Note the abbreviated version column. Using abbreviated versions significantly speeds up the tasks even if you are a fast typist.
|