在 gdb 中使用 xb 命令解决长度限制

Resolve length limit with xb command in gdb

我需要在 xb 命令中复制十六进制字节,但 gdb 将它们打印成多行,我不得不从输出中删除内存地址

(gdb) x/20xb 0x00007ffff7e84000
0x7ffff7e84000 <opendir>:   0xf3    0x0f    0x1e    0xfa    0x41    0x55    0x41    0x54
0x7ffff7e84008 <opendir+8>: 0x55    0x53    0x48    0x81    0xec    0xa8    0x00    0x00
0x7ffff7e84010 <opendir+16>:    0x00    0x64    0x48    0x8b

尝试了 set width unlimited 但没有用。

我该怎么办?

编辑

测试时的完整会话使用俄语的解决方案:

# gdb /bin/ls
Reading symbols from /bin/ls...
(No debugging symbols found in /bin/ls)
(gdb) b opendir
Breakpoint 1 at 0x4870
(gdb) r
Starting program: /usr/bin/ls
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x00007ffff7e84000 in opendir () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) define xb
Type commands for definition of "xb".
End with a line saying just "end".
> set var $j = 0
>  while $j < $arg1
 >   printf "0x%02x ", (char *) $arg0[$j++]
 >  end
> printf "\n"
>end
(gdb) xb 0x00007ffff7e84000 20
cannot subscript something of type `long'
(gdb)

测试程序:

int main()
{
  char buf[] = "abcdefghijklmopqrstuvwxyz";
  return 0;
}
gcc -g t.c

cat > xb.txt <<'EOF'
define xb
 set var $j = 0
  while $j < $arg1
   printf "0x%02x ", ((char *) $arg0)[$j++] & 0xFF
  end
 printf "\n"
end
EOF

gdb -q -x xb.txt ./a.out
Reading symbols from ./a.out...

(gdb) start
Temporary breakpoint 1 at 0x1129: file t.c, line 3.
Starting program: /tmp/a.out

Temporary breakpoint 1, main () at t.c:3
3         char buf[] = "abcdefghijklmnopqrstuvwxyz";
(gdb) n
4         return 0;

(gdb) x/16bx buf
0x7fffffffdad0: 0x61    0x62    0x63    0x64    0x65    0x66    0x67    0x68
0x7fffffffdad8: 0x69    0x6a    0x6b    0x6c    0x6d    0x6e    0x6f    0x70

(gdb) xb buf 16
0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f 0x70

(gdb) xb buf 27
0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f 0x70 0x71 0x72 0x73 0x74 0x75 0x76 0x77 0x78 0x79 0x7a 0x00