"With the GDB debugger (II)"

Disclaimer: This article is CSDN blogger original article "haoel", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/haoel/article/details/2879

 

GDB commands overview
-------

  After starting gdb, you will be brought into the gdb debugging environment, you can use the gdb debugger command to start up, gdb commands can use the help command to view, as follows:

 

 

 

 

 

   gdb commands a lot, gdb put it into a number of categories. Example except a help command gdb command type, if the command depends on the type, can help <class> command, such as: help breakpoints, all commands to set breakpoints. You can also directly help <command> to view the help command.

  gdb, the input command, you can not play the whole command, only the first few characters of a command to play on it, of course, the first few characters of the command should be marked with a unique command in Linux, you can knock hit the TAB key twice to pad the full name of the command, if there are repeated, then gdb will come out of its cases.

  Example 1: upon entering a function func, set a breakpoint. You can knock break func, or is directly b func

  (gdb) b func

  Breakpoint 1 at 0x8048458: file hello.c, line 10.

 

  Example Two: Knock b press the TAB key twice, you will see that all starts with the b command:

  (gdb) b

  backtrace  break      bt

 

  Example Three: just remember the prefix function, it can be:

  (Gdb) b make_ <press the TAB key>

  (Once again press the TAB key, you'll see :)

  make_a_section_from_file

  make_abs_section

  make_blockvector

  make_cleanup 

  GDB all the functions that begin to make out all the cases you see.

 

  Example Four: When debugging C ++ programs, you can have the same function name. Such as:

  (gdb) b 'bubble( M-?

  bubble(double,double)    bubble(int,int)

  (gdb) b 'bubble(

  You can view all of overloaded functions and parameters in C ++. (Note: M- and "press the TAB key twice" is a meaning?)

 

  To exit gdb, only for short hair quit or q command on the line.

 

 

GDB running UNIX shell program

  In gdb environment, you can run the UNIX shell command gdb use of shell commands to complete:

  shell <command string>

  Call the UNIX shell to execute <command string>, UNIX shell environment variable SHELL defined will be used to execute <command string>, if the SHELL is not defined, then use the standard UNIX shell: / bin / sh. (Command.com or using cmd.exe in Windows)

  There is a gdb commands make:

  make <make-args>

  You can make command in gdb to re-build their own procedures. This command is equivalent to "shell make <make-args>".

 

Run the program in GDB

  When to gdb <program> way to start gdb, gdb will search the current directory and path PATH <program> source files. To verify gdb read source file, or list command l may be used to see if the source code is listed gdb energy.

  In gdb, run the program using r or run command. Run the program, you may need to set the following four aspects of the matter.

1, the program operating parameters

  set args parameter to specify runtime. (Eg: set args 10 20 30 40 50)

  show args command to view a good set of operating parameters.

2, the operating environment

  path <dir> path may be set to run the program.

  show paths to view the running path of the program.

  set environment varname [= value] set environment variables. Such as: set env USER = hchen

  show environment [varname] viewing environment variable.

3, the working directory

  cd <dir> cd command corresponding to the shell.

  pwd Displays the current directory.

4, the input output program

  info terminal display mode to use your terminal program

  A control program output redirection. Such as: run> outfile

  tty either write command input and output terminals. Such as: tty / dev / ttyb

 

Debugger is already running

Two ways:

  1, view running programs with ps under UNIX PID (process ID), and then use gdb <program> PID format mount a running program.

  2, first with gdb <program> on the associated source code, and gdb, gdb with the attach command to mount the PID of the process. And to unmount process with detach.

Pause / resume running

  Debugger to halt the program is a must, GDB can easily suspend operation of the program. You can set the program in which line stopped, and under what conditions stopped, stopped to receive any signal at the time and so on. So that you see the run-time variables, as well as the process runs.

  When the process is stopped gdb, you can use the info program to see whether the program is running, a process ID, the reason being suspended.

  In gdb, we can have a pause following ways: a breakpoint (BreakPoint), observation point (WatchPoint), capture points (CatchPoint), signal (Signals), the thread to stop (Thread Stops). If you want to run the recovery program, or you can continue to use c command.

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/zhuangquan/p/11910821.html
Recommended