gdb调试有管道的命令行

以pcre2调试为例

1
2
3
4
5
6
7
8
9
#!/bin/sh
 
cd `pwd`/installed/bin
 
mkfifo /tmp/pcre
echo "<h1>hello</h1>" > /tmp/pcre &
 
gdb ./pcre2grep -ex 'b main' -ex 'r -o "<.*>" < /tmp/pcre'
rm /tmp/pcre

refer to:
http://www.voidcn.com/article/p-migwptlv-bsq.html

in gdb tui mode scroll the command window

Use cgdb instead.

Let GDBW denote the command window,
let SRCW denote the source window
let TTYW denote the input window.

Cgdb basic usage

1
2
3
4
5
6
ESC key in GDBW: switch to SRCW
i key in SRCW: switch to GDBW
T key in SRCW: switch on/off TTYW
PgUp/PgDn key in GDBW: scroll GDBW
PgUp/PgDn key in SRCW: scroll SRCW
-/= in SRCW: decrease/increase SRCW size

Patch: GDBW output is truncated.
cgdb/scroller.cpp:146
https://github.com/cgdb/cgdb/pull/269

refer to:
https://github.com/cgdb/cgdb/blob/master/doc/cgdb.texi

gdb备忘录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
save breakpoints file-name-to-save
source file-name-to-save
dprintf /dir/to/file.c:2368,"err is %d\n",err
x /8xw key
info files
info source
info variables
info locals
info args
set python print-stack full
dump binary memory ./file_path_to_save $from_addr $to_addr
cond 1 $rdi==0x0
thread apply all bt
set print elements 0
set follow-fork-mode [parent|child]
 
set logging file <file name>
set logging on
info functions
set logging off

refer to:
https://www.wenjiangs.com/doc/gdb-save-breakpoints
https://gist.github.com/nmcv/212250dc8eb865a5282e

vim gdb调试可视化

先安装gvim

1
sudo apt install vim-gtk3

再下载最新clewn

1
http://clewn.sourceforge.net

比如clewn-1.15.tar.gz

1
2
3
4
5
6
7
apt install libncurses-dev
apt install libreadline-dev
tar xaf clewn-1.15.tar.gz
cd clewn-1.15
./configure
make
make install

获取要调试程序的pid,比如98747

1
clewn -ga "-p 98747"

在原命令行中打断点再继续,当被调试程序命中断点后,gvim中会同步源码到断点处。

refer to:
http://clewn.sourceforge.net/doc.html