How to find out the value of all registers with gdb?

I am debugging the c program in the assembly to understand how gcc-complier works. I want to read the register of the $ fs segments, so I use x / x $ fs, however it tells me that it cannot access memory. How can I get information about any register that includes segment, general purpose, and control registers on i386: 86_64?

+6
source share
3 answers

info registers prints for me the values ​​of the registers you are asking about, 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) 
+11
source
 info all-registers 

gives you all register values, including the FPU register stack, xmm registers.

 (gdb) i all-r rax 0x2aaaaace62ce 46912498459342 rbx 0x2aab18e71290 46914345570960 rcx 0x2aaab2020d60 46912619285856 rdx 0xffffffffffd934ee -2542354 rsi 0x2aab18ec7a40 46914345925184 rdi 0xa 10 rbp 0x2aab18e6f000 0x2aab18e6f000 rsp 0x2aab18e6f000 0x2aab18e6f000 r8 0xe 14 r9 0x2aab18eb1f08 46914345836296 r10 0x2aaab9085000 46912737136640 r11 0x0 0 r12 0x2aab18ec7170 46914345922928 r13 0x477f3280 1199518336 r14 0x7 7 r15 0x2aaada787000 46913298132992 rip 0x2aaaaae3b18e 0x2aaaaae3b18e <flt_fadd+4> eflags 0x283 643 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0 st0 10 (raw 0x4002a000000000000000) st1 3 (raw 0x4000c000000000000000) st2 0 (raw 0x00000000000000000000) st3 0 (raw 0x00000000000000000000) st4 0 (raw 0x00000000000000000000) st5 0 (raw 0x00000000000000000000) st6 0 (raw 0x00000000000000000000) st7 0 (raw 0x00000000000000000000) fctrl 0x137f 4991 fstat 0x7000 28672 ftag 0xc0 192 fiseg 0xaae3afe5 -1427918875 fioff 0x2aaa 10922 foseg 0x18e6ee48 417787464 fooff 0x2aab 10923 fop 0x704 1796 xmm0 {f = {0x0, 0x6, 0x0, 0x0}} {f = {0, 6.48876953, 0, 0}} xmm1 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm2 {f = {0x0, 0x1c0, 0x0, 0x0}} {f = {0, 448, 0, 0}} xmm3 {f = {0x0, 0x1, 0x0, 0x0}} {f = {0, 1.75, 0, 0}} xmm4 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm5 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm6 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm7 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm8 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm9 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm10 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm11 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm12 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm13 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm14 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} xmm15 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}} mxcsr 0x1fa0 8096 
+9
source

You should use p and set commands to read / set registers. Register names are different for each machine; use the information registers to see the names used on your computer. See the GDB manual section for more details.

To print the value of the register $fs , you can do this:

 (gdb) p/x $fs $1 = 0x0 

The x command performs a memory check. However, there are times when you cannot do this. For example, if the memory indicated by the address is protected. Therefore, if you try to check the memory at virtual address 0x0 , gdb explicitly refuses to do this, for example:

 (gdb) x/x $fs 0x0: Cannot access memory at address 0x0 

Hope this helps. Good luck

+3
source

Source: https://habr.com/ru/post/914176/


All Articles