How do I read the value of all registers with gdb?

Dr.Knowitall picture Dr.Knowitall · Apr 26, 2012 · Viewed 11.1k times · Source

I am debugging a c program in assembly to understand how the gcc complier works. I want to read my $fs segment register so I use x/x $fs, however it tells me it can't access the memory. How can I get a read out on any register which includes segment, general purpose, and control registers on the i386:86_64?

Answer

Gabriel Southern picture Gabriel Southern · Apr 26, 2012

info registers prints out registers values for me which is what you are asking I think:

(gdb) info registers
rax            0x7ffff7731ec8   140737344904904
rbx            0x0  0
rcx            0x0  0
rdx            0x7fffffffd618   140737488344600
rsi            0x7fffffffd608   140737488344584
rdi            0x1  1
rbp            0x0  0x0
rsp            0x7fffffffd528   0x7fffffffd528
r8             0x7ffff7730300   140737344897792
r9             0x7ffff7dec250   140737351959120
r10            0x7fffffffd390   140737488343952
r11            0x7ffff73d0b50   140737341360976
r12            0x400be0 4197344
r13            0x7fffffffd600   140737488344576
r14            0x0  0
r15            0x0  0
rip            0x402330 0x402330 <main>
eflags         0x246    [ PF ZF IF ]
cs             0x33 51
ss             0x2b 43
ds             0x0  0
es             0x0  0
fs             0x0  0
gs             0x0  0
(gdb)