linux的gdb命令bt,Linux 程序调式命令 GDB 概述

1 GDB 概述

一般来说,GDB主要帮助你完成下面四个方面的功能:

https://www.cndba.cn/dave/article/3731https://www.cndba.cn/dave/article/3731

1、启动你的程序,可以按照你的自定义的要求随心所欲的运行程序。

2、可让被调试的程序在你所指定的调置的断点处停住。(断点可以是条件表达式)

3、当程序被停住时,可以检查此时你的程序中所发生的事。

4、你可以改变你的程序,将一个BUG产生的影响修正从而测试其他BUG。

GDB主要来调试C/C++语言写的程序,当然也就可以调试其他语言程序。

gdb使用shell命令gdb来调用,一旦开始,就从终端读取命令直到gdb退出。可以不带任何参数或选项执行gdb命令,但是最常用的启动gdb的方式是带一个或者两个参数,指定一个可执行文件来作为参数:https://www.cndba.cn/dave/article/3731

gdb program (gdb+可执行文件名称)

也可以在gdb文件后面指定可执行文件 和 core文件的名称:

https://www.cndba.cn/dave/article/3731

gdb program core(gdb + 可执行文件 +core文件)

也可以指定一个进程id作为第二个参数,如果你想调试一个正在运行的程序:

gdb program 1234(gdb进程名+进程id)

会附件gdb到进程1234上(除非有一个文件名“1234”;GDB首先检查core文件)

https://www.cndba.cn/dave/article/3731

相关参数列表

命令

命令缩写

命令说明

list

l

显示多行源代码

break

b

设置断点,程序运行到断点的位置会停下来

info

i

描述程序的状态

run

r

开始运行程序

display

disp

跟踪查看某个变量,每次停下来都显示它的值

step

s

执行下一条语句,如果该语句为函数调用,则进入函数执行其中的第一条语句

next

n

执行下一条语句,如果该语句为函数调用,不会进入函数内部执行(即不会一步步地调试函数内部语句)

print

p

打印内部变量值

continue

c

继续程序的运行,直到遇到下一个断点

set var name=v

设置变量的值

start

st

开始执行程序,在main函数的第一条语句前面停下来

file

装入需要调试的程序

kill

k

终止正在调试的程序

watch

监视变量值的变化

backtrace

bt

产看函数调用信息(堆栈)

frame

f

查看栈帧

quit

q

退出GDB环境

2 GDB 命令帮助

直接在操作系统层面执行help 查看:https://www.cndba.cn/dave/article/3731https://www.cndba.cn/dave/article/3731

https://www.cndba.cn/dave/article/3731

[dave@www.cndba.cn bin]$ gdb -help

This is the GNU debugger. Usage:

gdb [options] [executable-file [core-file or process-id]]

gdb [options] --args executable-file [inferior-arguments ...]

gdb [options] [--python|-P] script-file [script-arguments ...]

Options:

--args Arguments after executable-file are passed to inferior

-b BAUDRATE Set serial port baud rate used for remote debugging.

--batch Exit after processing options.

--batch-silent As for --batch, but suppress all gdb stdout output.

--return-child-result

GDB exit code will be the child's exit code.

--cd=DIR Change current directory to DIR.

--command=FILE, -x Execute GDB commands from FILE.

--eval-command=COMMAND, -ex

Execute a single GDB command.

May be used multiple times and in conjunction

with --command.

--core=COREFILE Analyze the core dump COREFILE.

--pid=PID Attach to running process PID.

--dbx DBX compatibility mode.

--directory=DIR Search for source files in DIR.

--epoch Output information used by epoch emacs-GDB interface.

--exec=EXECFILE Use EXECFILE as the executable.

--fullname Output information used by emacs-GDB interface.

--help Print this message.

--interpreter=INTERP

Select a specific interpreter / user interface

-l TIMEOUT Set timeout in seconds for remote debugging.

--nw Do not use a window interface.

--nx Do not read .gdbinit file.

--python, -P Following argument is Python script file; remaining

arguments are passed to script.

--quiet Do not print version number on startup.

--readnow Fully read symbol files on first access.

--readnever Do not read symbol files.

--se=FILE Use FILE as symbol file and executable file.

--symbols=SYMFILE Read symbols from SYMFILE.

--tty=TTY Use TTY for input/output by the program being debugged.

--tui Use a terminal user interface.

--version Print version information and then exit.

-w Use a window interface.

--write Set writing into executable and core files.

--xdb XDB compatibility mode.

At startup, GDB reads the following init files and executes their commands:

For more information, type "help" from within GDB, or consult the

GDB manual (available as on-line info or a printed manual).

Report bugs to "".

[dave@www.cndba.cn bin]$

(gdb) help

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 all" for the list of all commands.

Type "help" followed by command name for full documentation.

Type "apropos word" to search for commands related to "word".

Command name abbreviations are allowed if unambiguous.

(gdb) help all

Command class: aliases

ni -- Step one instruction

rc -- Continue program being debugged but run it in reverse

rni -- Step backward one instruction

rsi -- Step backward exactly one instruction

si -- Step one instruction exactly

stepping -- Specify single-stepping behavior at a tracepoint

tp -- Set a tracepoint at specified line or function

tty -- Set terminal for future runs of program being debugged

where -- Print backtrace of all stack frames

ws -- Specify single-stepping behavior at a tracepoint

Command class: breakpoints

awatch -- Set a watchpoint for an expression

break -- Set breakpoint at specified line or function

catch -- Set catchpoints to catch events

catch assert -- Catch failed Ada assertions

catch catch -- Catch an exception

catch exception -- Catch Ada exceptions

catch exec -- Catch calls to exec

catch fork -- Catch calls to fork

catch syscall -- Catch system calls by their names and/or numbers

catch throw -- Catch an exception

catch vfork -- Catch calls to vfork

clear -- Clear breakpoint at specified line or function

commands -- Set commands to be executed when a breakpoint is hit

condition -- Specify breakpoint number N to break only if COND is true

delete -- Delete some breakpoints or auto-display expressions

delete bookmark -- Delete a bookmark from the bookmark list

delete breakpoints -- Delete some breakpoints or auto-display expressions

delete checkpoint -- Delete a checkpoint (experimental)

delete display -- Cancel some expressions to be displayed when program stops

delete mem -- Delete memory region

---Type to continue, or q to quit---

delete tracepoints -- Delete specified tracepoints

delete tvariable -- Delete one or more trace state variables

disable -- Disable some breakpoints

disable breakpoints -- Disable some breakpoints

disable display -- Disable some expressions to be displayed when program stops

disable mem -- Disable memory region

disable tracepoints -- Disable specified tracepoints

enable -- Enable some breakpoints

enable breakpoints -- Enable some breakpoints

enable breakpoints delete -- Enable breakpoints and delete when hit

enable breakpoints once -- Enable breakpoints for one hit

enable delete -- Enable breakpoints and delete when hit

enable display -- Enable some expressions to be displayed when program stops

enable mem -- Enable memory region

enable once -- Enable breakpoints for one hit

enable tracepoints -- Enable specified tracepoints

ftrace -- Set a fast tracepoint at specified line or function

hbreak -- Set a hardware assisted breakpoint

ignore -- Set ignore-count of breakpoint number N to COUNT

rbreak -- Set a breakpoint for all functions matching REGEXP

rwatch -- Set a read watchpoint for an expression

save -- Save breakpoint definitions as a script

save breakpoints -- Save current breakpoint definitions as a script

save gdb-index -- Save a

save tracepoints -- Save current tracepoint definitions as a script

strace -- Set a static tracepoint at specified line

tbreak -- Set a temporary breakpoint

tcatch -- Set temporary catchpoints to catch events

tcatch assert -- Catch failed Ada assertions

tcatch catch -- Catch an exception

tcatch exception -- Catch Ada exceptions

tcatch exec -- Catch calls to exec

tcatch fork -- Catch calls to fork

tcatch syscall -- Catch system calls by their names and/or numbers

tcatch throw -- Catch an exception

tcatch vfork -- Catch calls to vfork

---Type to continue, or q to quit---

thbreak -- Set a temporary hardware assisted breakpoint

trace -- Set a tracepoint at specified line or function

watch -- Set a watchpoint for an expression

……

(gdb)

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值