Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

x86 64 - How do you access low-byte registers for r8-r15 from gdb in x86-64?

In gdb, I can't seem to access any of the pseudo-registers: r8b, r9b, r10b, r11b, r12b, r13b, r14b, nor r15b (however, r15d and r15w seem to work, and same for sil).

See an example:

section .text
global main

main:
  xor esi, esi
  mov sil, 0x1f
  xor r13d, r13d
  mov r13b, sil
  ret

Running with gdb:

(gdb) p $sil
$1 = -15
(gdb) p $r13 
$2 = 241
(gdb) p $r13b
$3 = void
(gdb) p /x $r13b
$4 = 0x0

I couldn't find anything in the gdb manual, and they aren't printed with the info all-registers command. I'm using GDB 10.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can reference to the low byte of those registers using the l suffix:

r8l, r9l, r10l, r11l, r12l, r13l, r14l, r15l.

(gdb) p $r13l
$1 = -15
(gdb) p /x $r13l
$2 = 0xf1

I couldn't find these aliases documented anywhere, except in their definition in the gdb codebase:

/* Register names for byte pseudo-registers.  */

static const char * const amd64_byte_names[] =
{
  "al", "bl", "cl", "dl", "sil", "dil", "bpl", "spl",
  "r8l", "r9l", "r10l", "r11l", "r12l", "r13l", "r14l", "r15l",
  "ah", "bh", "ch", "dh"
};

Furthermore, there was a bug in the gdb codebase that would print 0 instead of void if a format is specified to the print command, as it happens in the last example. Future versions of gdb should display void if the value that you are printing is not defined.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...