1. Memory view command x.
x/x with hexadecimal output
X/D Output in decimal
X/C output with single character
X/i Disassembly – Typically, we will usex/10i $ip-20 来查看当前的汇编($ip是指令寄存器)
X/S output as a string
(GDB) x/10i main 0X80483BB <main>:Push%ebp 0X80483BC <main+1:mov%esp,%ebp 0x80483be <main+3: and$0xfffffff0,%esp 0x80483c1 <main+6:Sub$0x20,%esp 0x80483c4 <main+9: Movl $0x0,0x1c (%ESP) 0x80483cc <main+ -: Movl $0x5, (%ESP) = 0x80483d3 <main+ -:Pager0x8048394 <fact> 0x80483d8 <main+ in:mov%eax,0x1c (%ESP) 0x80483dc <main+ -:mov0x1c (%ESP),%eax 0x80483e0 <main+Panax Notoginseng:Leave
2. Memory Breakpoint Break
Break *ADDR indicates that the point is interrupted at address addr.
(GDB) disassemble maindump of assembler code for functionMain:0X080483BB <+0:Push%ebp 0X080483BC <+1:mov%esp,%ebp 0x080483be <+3: and$0xfffffff0,%esp 0x080483c1 <+6:Sub$0x20,%esp 0x080483c4 <+9: Movl $0x0,0x1c (%ESP) 0x080483cc <+ -: Movl $0x5, (%ESP) 0x080483d3 <+ -:Pager0x8048394 <fact> 0x080483d8 <+ in:mov%eax,0x1c (%ESP) 0x080483dc <+ -:mov0x1c (%ESP),%eax 0x080483e0 <+Panax Notoginseng:Leave0x080483e1 <+ -:retEnd of Assembler dump. (gdb) b *0x080483d3 Breakpoint1At 0X80483D3:FileTest. C, Line -. (GDB) runstartingProgram :/mnt/hgfs/share/csapp/a. outBreakpoint1, 0X080483D3inchMain () atTest.C: - -c = Fact (5);
3. Print Register
You can use info registers to view all registers:
(GDB) Info registers eax 0XBFFFF6C4-1073744188ecx 0x6400d69f1677776543edx 0x11ebx 0x288ff42658292esp 0xbffff5f0 0xbffff5f0ebp 0xbffff618 0xbffff618esi 0x00EDI 0x00eip 0x80483c4 0x80483c4 <main+9>eflags 0x286 [PF SF IF]cs 0x73 theSS 0x7b123DS 0x7b123es 0x7b123FS 0x00GS 0x33Wuyi
or print the value of the EBP register using the p/x $EBP
(GDB) p/x $EBP $ 2 = 0xbffff618
4, set the observation point
When we need to focus on the value of EBP after each execution, you can set the observer point with display
(gdb) display $EBP 1 : $EBP = (void *) 0xbffff618 (gdb) Si - c = Fact (5); 1 : $EBP = (void *) 0xbffff618 (gdb) si0x080483d3 - c = Fact (5); 1: $EBP = (void *) 0xbffff618
GDB compilation Debug Tips