Simple GDB case

to be added...
 
gdb a.out
 
[Inferior 1 (process 9718) exited with code 05]
(gdb) list
Line number 15 out of range; t.c has 14 lines.
(gdb) list 1
1       #include
2       char foo(char *s)
3       {
4         char *c=s;
5         return *(c+2);
6       }
7       int main()
8       {
9         char arr[5]="abc\n";
10        char b=foo(arr);
(gdb) 
11        printf("%c\n",b);
12        printf("%s\n",arr);
13
14      }
(gdb) disass /m
Dump of assembler code for function main:
8       {
   0x08048449 <+0>:     push   ?p
   0x0804844a <+1>:     mov    %esp,?p
   0x0804844c <+3>:     and    $0xfffffff0,%esp
   0x0804844f <+6>:     sub    $0x20,%esp
 
9         char arr[5]="abc\n";
   0x08048452 <+9>:     movl   $0xa636261,0x1a(%esp)
   0x0804845a <+17>:    movb   $0x0,0x1e(%esp)
 
10        char b=foo(arr);
=> 0x0804845f <+22>:    lea    0x1a(%esp),?x //eip 
   0x08048463 <+26>:    mov    ?x,(%esp)
   0x08048466 <+29>:    call   0x8048434
   0x0804846b <+34>:    mov    %al,0x1f(%esp)
(gdb) info registers esp
esp            0xbfffefb0       0xbfffefb0
#another shell
johv@linux-8f1f:~> echo $((0xbfffefb0+0x1a))
3221221322
 
johv@linux-8f1f:~> echo ‘obase=16;base=10;3221221322‘ | bc
BFFFEFCA
(gdb) x /s 0xbfffefca
0xbfffefca:      "abc\n" //find the "abc\n"
(gdb) 
 
gdb) help catch
Set catchpoints to catch events.
 
List of catch subcommands:
 
catch assert -- Catch failed Ada assertions
catch catch -- Catch an exception
catch exception -- Catch Ada exceptions
catch exec -- Catch calls to exec
catch fork -- Catch calls to fork
catch syscall -- Catch system calls by their names and/or numbers
catch throw -- Catch an exception
catch vfork -- Catch calls to vfork
 
Type "help catch" followed by catch subcommand name for 
full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.
(gdb) 
(gdb) info breakpoints 
Num     Type           Disp Enb Address    What
7       breakpoint     keep y   0x08048440 in foo 
                                           at t.c:5
        breakpoint already hit 1 time
8       catchpoint     keep y              syscall "" 
9       breakpoint     keep y    exception catch
10      catchpoint     keep y              fork
(gdb) disable breakpoints 7
(gdb) 
condition

Simple GDB case,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。