Re: View memory content with gdb

"Mahmood Naderan via gdb" <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
>Firstly, why are you examining data just _outside_ the stack? These
>data would be overwritten by any function called by `main`, while the
>arguments should be retained until `main` returns. So, the arguments
>must either be somewhere _inside_ the stack, or far from the stack
>(e.g. heap).


It isn't outside of the stack. According to the disas

Dump of assembler code for function main:
   0x00005555555546b0 <+0>:    push   %rbp
   0x00005555555546b1 <+1>:    mov    %rsp,%rbp
   0x00005555555546b4 <+4>:    sub    $0x20,%rsp
...


it is reserving 32 addresses below the rsp. That should be the place of buffer. Isn't that?




>You can get actual
>value of `argv[1]` pointer by simply using `p argv[1]` command (if you
>compiled your program with -g flag).

(gdb) break 1
Breakpoint 1 at 0x6bf: file mico.c, line 1.
(gdb) run aaaaaaaaa
Starting program: /home/mahmood/mico aaaaaaaaa

Breakpoint 1, main (argc=2, argv=0x7fffffffdf58) at mico.c:6
6      strcpy( buffer, argv[ 1 ] );
(gdb) p argv[1]
$1 = 0x7fffffffe302 "aaaaaaaaa"



I think $1 is the location of "aaaaaaaaaa" in the memory as supplied by the command line. However, that is not the destination. I am actually trying to copy from a source ($1) to a destination. The destination is the location of buffer and according to the disas, it is 32 bytes below the rsp. Since the stack grows downward, it makes sense.






>You've only, by using `step` command,>entered _into_ the `strcpy` function – note the `__strcpy_ssse3`
>becoming the current function after your `step` command.


I tried from scratch. I set two breakpoints in the first and third lines. However, it seems that it doesn't stop at the second breakpoint.

(gdb) list
1    #include <stdio.h>
2    #include <string.h>
3    int main( int argc, char **argv )
4    {
5      char buffer[10];
6      strcpy( buffer, argv[ 1 ] );
7      return 0;
8    }
(gdb) break 1
Breakpoint 1 at 0x6bf: file mico.c, line 1.
(gdb) break 3
Note: breakpoint 1 also set at pc 0x6bf.
Breakpoint 2 at 0x6bf: file vuln.c, line 3.
(gdb) run aaaaaaaaaa
Starting program: /home/mahmood/mico aaaaaaaaaa

Breakpoint 1, main (argc=2, argv=0x7fffffffdf58) at mico.c:6
6      strcpy( buffer, argv[ 1 ] );
(gdb) continue
Continuing.
[Inferior 1 (process 6899) exited normally]



So, how can I step over the stdcpy line?
Thanks for the help.




Regards,
Mahmood
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.