GDB's entry and exit

Source: Internet
Author: User
Tags gdb debugger
Enter and exit GDB

This section discusses how to start and exit gdb. Mainly include: input ' gdb ' into the GDB debugger input quit or press ctrl-d exit call GDB: How to start GDB exit GdB: How to exit gdb Shell script command: How to save the output in GDB using the shell command: How to save the output of GDB to a file

2.1 Calling GdB

Start the GDB debugger by running GDB. Once run, GdB reads the command from the terminal until GDB exits.

GDB supports a variety of options and parameters to customize the GDB debugging environment. The command-line options we discussed here cover a variety of situations, and some options may not be supported on some platforms.

GDB's longest startup is to add a parameter indicating the executable program that will be debugged: [c-sharp] view plain copy gdb programs

You can also specify executable programs and core dump files as their parameters: [c-sharp] view plain copy gdb program core

If we want to debug a running program, we can also replace the second parameter in the top command with the process ID number: [c-sharp] view plain copy gdb 1234

This way, GDB adheres to the process number 1234 process (unless you happen to have a file called 1234; then GDB first thinks it's a core dump file and then tries to load it). In the top command, the second parameter is an advanced feature that requires a full operating system platform support; When you use GDB to connect to a bare board as a remote debugger, the board may not have the concept of a process and cannot get a core dump file. At this point, GDB warns you that the process cannot be attached or that the core dump file cannot be read.

You want GDB to stop the parameter parsing and pass the arguments in to the program that will be debugged. The "--args" argument can do it to prevent GDB from parsing command-line arguments: [c-sharp] view plain copy gdb--args gcc-o2-c foo.c

The command above runs GDB to debug gcc, and the parameter '-o2-c foo.c ' is passed into the GCC program (see Debugger parameters).

If you do not want GDB to print licensing information at startup, you can use the-silent parameter: [c-sharp] view plain copy gdb-silent

For more gdb startup information, type "GDB--help" or "gdb-h" view. All GDB parameters are sequentially processed, and the processing order can be changed by using the '-X ' parameter. File options: Select File mode option: Select mode startup process: What did GDB do when it started

2.1.1 File parameter selection

When GDB starts, any parameter in the command line, in addition to the options, is considered to be a debugger and core dump file parameter (or process ID number). This is the same as using the '-se ' and ' C ' (or '-P ') options to specify each effect. (In fact, GDB associates the first parameter it reads into the '-se ' option, and the second parameter that is not associated with any option is associated with the '-C '/'-P ' option.) If the second parameter is not associated with any option with the '. ' At the beginning, GDB will think that this parameter is a process number and then try to attach it and try to open it as a dump file if it fails. If you happen to have a '. ' At the beginning of the core dump file, adding the './' prefix prevents GDB from treating it as an entry number. such as:./12345.

If GDB is configured, there is no support for reading of core dump files, such as on some embedded platforms. Then it complains that there are two parameters and ignores the second argument.

Many options have long and short parameters, and the following list describes their relationships. As long as you can distinguish between options, GDB also allows you to enter a subset of option names, such as--help, in the long parameter form, and we only enter-hel. (If you like, you can also use '-' instead of '-', so we only list some common situations here)

-symbols file

-S file

Reads the symbol table from file.

-exec file

-E File

Specifies that file files are to be debugged or used in conjunction with core dump files to examine the data. GDB does not read the symbol table from inside it.

-se file

Specifies that files file is to be debugged and read from the symbol table.

-core file

-C file

Specifies that files file is a core dump file.

-pid number

-P Number

A process that hooks up the process number, just like the attach command.

-command file

-X File

Executes the GDB command in files file. Reference command file.

-eval-command command

-ex command

Executes a GDB command.

This option is often used to execute multiple commands more than once, and allows the insertion of '-command '. [C-sharp] view plain copy gdb-ex ' target sim '-ex ' Load '/-x setbreakpoints-ex ' run ' a.out

-directory Directory

-D Directory

Add a search path for source files and scripts.

-R

-readnow

By default, GDB reads only a handful of the required entry symbol information when it starts, and then reads the symbol continuously as needed. This option forces gdb to read all symbols of each symbol file as soon as it starts, which, although slow to start, will be quicker to follow.

2.1.2 Selection Mode

GDB has a variety of alternative working modes--for example, batch mode or mute mode.

-nx

-N

Does not perform any of the commands in the initialization file. Typically, when gdb finishes processing command-line options and parameters, the commands in the initialization file are executed. Reference command file.

-quiet

-silent

-Q

"Quiet". Without printing quotes and copyright information, this information is also blocked in batch mode.

-batch

Run batch mode. Executes the command file specified by the '-X ' option (if there is no '-n ' option mask, also includes initialization file), and the GDB exit value is 0 after success. If an error occurs during execution, the exit value is Non-zero.

Batch mode can be useful when you think of GDB as a filter. For example, to download and execute a program on another computer. To make this way more useful, this message

Program exited normally.

(This message is generally displayed, regardless of when the program running under GDB control is finished), is not displayed when running batch mode.

-batch-silent

Run in batch mode, much like '-batch ' mode, but it's completely quiet. All GDB output to stdout is prohibited (stderr is not affected). This is quieter than '-silent ', which is of little use in an interactive session.
For example, this option is especially useful when using a target system platform that gives information about ' Loading section '. (not seen, estimated correlation section information more)

Note that this option also masks this information for system platforms that print out information through GDB (rather than directly to standard output).

-return-child-ersult

GDB's return code will be the return code for the subprocess (the subprocess refers to the process being debugged). The following is an exception: GDB does not exit normally. For example, due to an incorrect parameter or an internal error. In this case, the exit code is the same as when there is no '-return-child-result '. The user exits with an explicit value. For example, ' Quit 1 '. The child process has never been run, or has not been terminated. In this case, the exit code is-1.

This option is useful when used in conjunction with '-batch ' or '-batch-silent ' when GDB is a remote program loader or emulator interface.

-nowindows

-nw

"No Window". If GDB has a built-in image user interface (GUI) when compiling, this option tells GDB to use only the command-line interface. If no GUI is available, this option does not work.

-windows

-W

If GDB includes a GUI, this option requires GDB to use it whenever possible.

-CD Directory

Instead of the current directory, use directory as its working directory while GDB is running.

-fullname

-F

When you call gdb in the GNU Emacs Editor, Emacs sets this option so that GDB displays stack frame information in a standard, recognizable format that is displayed each time GDB triggers a breakpoint. This format looks like it starts with a 2 '/032 ' character, followed by a colon-delimited filename, line number, and character position string, and then ends with a newline. EMACS-TO-GDB program Interface to two "/032" as the stack frame printing source code logo.

-epoch

This option is set when you call GDB in Epoch Emacs-gdb. It tells GdB to modify its print function so that epoch displays the value of the expression in a separate window.

-annotate level

This option sets the annotation level within GDB, as it does with the ' Set annotate level ' (reference annotation). The annotation level controls how much/less information is attached to the GDB print prompt, expression values, source code, and other output information. Level 0 is a regular level and level 1 is for GNU Emacs when calling GdB, Level 3 represents the most output annotation information that can be used to accommodate any program that wants to control gdb output. Level 2 is no longer in use.

This annotation mechanism has largely been replaced by GDB/MI (see Gdb/mi interface).

--args

Change GDB's parsing of the command line so that parameters that follow the executable file are processed as command-line arguments passed to the executable file. This option prevents the option processing.

-baud bps

Sets the Shuchong rate (baud rate or number of bits per second) of any serial port that GDB uses for remote debugging.

-L Timeout

Sets the timeout (in seconds) for any traffic that GDB uses for remote debugging.

-T Device

Use device as your standard input and output for your program.

-tui

Activates the text user action interface (the Interface) at startup. The interface operates a plurality of text interface windows on the terminal, displaying code, displaying assembly code, register value, and gdb command Output window (reference gdb text user interface).

The text user interface is also activated when the ' Gdbtui ' program is started. But do not use this parameter when you start gdb in GNU Emacs (refer to using GDB in GNU Emacs).

-interpreter Interp

Use the interpreter Interp as the interface for a control program or device. This option is used by GDB as a backend and it communicates with the program settings. See the command Interpretation section.

'--interpreter=mi ' (or '--interpreter=mi2 ') enables GDB to use the Gdb/mi interfaces contained in the GDB6.0 version (see the Gdb/mi Interface section), and the 5.3 version and previous versions contain the Gdb/mi interface and the '- Interpreter=mi1 ' has been abandoned.

-write

Open the executable and core files so that they can be read and writable. This is the same as the ' Set write on ' command in GDB (see Modifying the program section <

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.