Running and debugging programs in GDB

Source: Internet
Author: User
Keywords GDB run debug program view
Tags code debug debug program debugging directory environment file files

When GDB is started with gdb <program>, GDB searches for the <program> source files in the path path and in the current directory. To verify that GDB is reading the source file, use the L or List command to see if GDB can list the source code.

In GDB, run the program using the R or Run command. Program running, you may need to set the following four aspects.

1. Operating parameters of the program.

Set args can specify Run-time parameters. (such as: Set args 10 20 30 40 50)
Show args command to see the set of run parameters.

2. Operating environment.

Path <dir> program run paths.
Show paths view the running path of the program.
Set environnement varhttp://www.aliyun.com/zixun/aggregation/11696.html ">name [=value] Sets the environment variable. such as: Set env User=hchen
Show environnement [varname] view environment variables.

3. Working directory.

CD <dir> equivalent to Shell's CD command.
PWD Displays the current directory.

4, the program input and output.

Info Terminal shows the mode of the terminal used by your program.
Use the redirect Control program output. such as: Run > outfile
A TTY command can refer to a terminal device that writes input and output. such as: Tty/dev/ttyb

To debug a running program

Two ways:

Under UNIX, use PS to view the PID (process ID) of the running program, and then hook up the running program with the GDB <program> PID format.
First, using GDB <program> Association on the source code, and GDB, in gdb, using the Attach command to hook up the process of PID. and detach to cancel the hook process.

Related Article

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.