gdb-6.0a.tar.bz2 中的 a 所代表的意思請見 Making up for a release mistake in GDB versions 6.0 - 6.6 。1)
$ ulimit -a core file size (blocks, -c) 0 $ ulimit -c unlimited
(gdb) info threads
(gdb) thread 2
(gdb) thread apply ID1 ID2 command (gdb) thread apply all command
(gdb) set scheduler-locking off|on|step (gdb) show scheduler-locking
注意! GCC -g 可以調整除錯訊息。
-glevel -ggdblevel -gstabslevel -gcofflevel -gxcofflevel -gvmslevel Request debugging information and also use level to specify how much information. The default level is 2. Level 0 produces no debug information at all. Thus, -g0 negates -g. Level 1 produces minimal information, enough for making backtraces in parts of the program that you don't plan to debug. This includes descriptions of functions and external variables, but no information about local variables and no line numbers. Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expan- sion when you use -g3. -gdwarf-2 does not accept a concatenated debug level, because GCC used to support an option -gdwarf that meant to generate debug information in version 1 of the DWARF format (which is very different from version 2), and it would have been too confusing. That debug format is long obsolete, but the option cannot be changed now. Instead use an additional -glevel option to change the debug level for DWARF2.
# apropos 可以列出所有與其後字串相關的所有命令 (gdb) apropos pending # 再使用 help 進行更深入的查詢 (gdb) help show breakpoint pending # 在 addr 的位址下中斷點,注意加上星號 (gdb) break *addr # 由目前 pc 位址往後翻成組語 (gdb) display /3i $pc # 將 addr1 到 addr2 的區段翻成組語 (gdb) disas addr1 addr2 # 印出某函式的位址 (gdb) p helper_printf $1 = {void ()} 0x5e09fe <helper_printf>
$ gdb (gdb) file a.out (gdb) run < input # 執行 gdb 腳本 $ gdb -x command.gdb 或 $ gdb (gdb) source command.gdb # 改變控制流 $ (gdb) set var gdb = 1 # 回傳指定的值 $ (gdb) return value # 跳過迴圈 $ (gdb) until # 忽略特定 signal (gdb) info signals (gdb) handle SIGUSR2 ignore # 條件斷點 (gdb) break tb_add_jump (gdb) condition 1 n == 2 # 或 (gdb) break function if n == 5
$ gdb --directory=/local/chenwj/temp/tmp/ ~/install/bin/wine64-preloader
(gdb) show path (gdb) show environment
# x86_64 上的 eip 叫 rip # 反組譯目前 pc 位址以後的五條指令 (gdb) x/5i $rip # 每按一次 enter 都會 display 目前 pc 位址以後的五條指令 (gdb) display/5i $rip # 查看當前暫存器的內容 (gdb) info registers
MI 主要應用在 IDE 方面。IDE 透過 MI 介面對 GDB 下指令,某些命令反饋上相對於 CLI 會比較快,如 IDE 透過 dump 指令讀取記憶體視窗 (memory windows),CLI 是以 byte 為單位讀取,MI 是以 block 為單位讀取。
$ gdb --interpreter mi a.exe (gdb) break main &"break main\n" ~"Breakpoint 1 at 0x1004010ed: file hello.cpp, line 9.\n" =breakpoint-created,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00000001004010ed",func="main()",file="hello.cpp",fullname="/home/wjchen/tmp/hello.cpp",line="9",thread-groups=["i1"],times="0",original-location="main"} ^done (gdb)
The GDB and GDB Server communicate via a TCP/IP connection, using the standard GDB remote serial protocol. The GDB supports a standard set of commands like open elf/bin files, reading/writing memory, etc. Beside this, the GDB also supports so called monitor commands which are passed to the GDB Server and interpreted by it, allowing it to implement J-Link specific commands like reading/writing CP15 registers, enabling flash download via J-Link, using Unlimited Flash Breakpoints, enabling semihosting, etc.
--------------------------- ------------------ | TCP/IP | | | | gdb <--------> gdbserver | <---> J-Link <----> | debugee | | | USB JTAG | | | (Host PC) | | (Target Board) | --------------------------- ------------------
Packets starting with ‘q’ are general query packets; packets starting with ‘Q’ are general set packets.
$ sudo apt-get install libusb-1.0-0-dev libhidapi-dev $ cat openocd.cfg source [find interface/cmsis-dap.cfg] source [find target/stm32f4x.cfg] $ sudo openocd -f openocd.cfg
Debug Adapters/Interfaces/Dongles are normally configured through commands in an interface configuration file which is sourced by your openocd.cfg file, or through a command line -f interface/….cfg option.
JTAG transports expose a chain of one or more Test Access Points (TAPs), each of which must be explicitly declared. JTAG supports both debugging and boundary scan testing. Flash programming support is built on top of debug support.
SWD (Serial Wire Debug) is an ARM-specific transport which exposes one Debug Access Point (DAP, which must be explicitly declared. (SWD uses fewer signal wires than JTAG.) SWD is debug-oriented, and does not support boundary scan testing. Flash programming support is built on top of debug support. (Some processors support both JTAG and SWD.)
Note that the order in which TAPs are declared is very important. That declaration order must match the order in the JTAG scan chain, both inside a single chip and between them.
$ configure --build=x86_64-portbld-freebsd8.1 --disable-nls
gdb represents the state of each program execution with an object called an inferior.