View memory content with gdb
"Mahmood Naderan via gdb" <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, With a simple strcpy code for copying an array, I want to view the memory map with gdb. However, the result I see is not what I expect. The code is char buffer[10]; strcpy( buffer, argv[ 1 ] ); and I compiled with gcc - g -fno-stack-protector -o myco myco.c I ran gdb commands to 1) set breakpoint, 2) run with an argument "aaaaaaaaaa", 3) check register content to find the memory location, 3) view memory content, 4) continue to copy the argument to memory and 5) view memory content. I expected to see the ascii code of 'a' multiple times. But I didn't see that. Please see the full output below: (gdb) break 1 Breakpoint 1 at 0x6bf: file myco.c, line 1. (gdb) run aaaaaaaaaa Starting program: /home/mahmood/myco aaaaaaaaaa Breakpoint 1, main (argc=2, argv=0x7fffffffdf28) at myco.c:6 6 strcpy( buffer, argv[ 1 ] ); (gdb) disas main Dump of assembler code for function main: 0x00005555555546b0 <+0>: push %rbp 0x00005555555546b1 <+1>: mov %rsp,%rbp 0x00005555555546b4 <+4>: sub $0x20,%rsp 0x00005555555546b8 <+8>: mov %edi,-0x14(%rbp) 0x00005555555546bb <+11>: mov %rsi,-0x20(%rbp) => 0x00005555555546bf <+15>: mov -0x20(%rbp),%rax 0x00005555555546c3 <+19>: add $0x8,%rax 0x00005555555546c7 <+23>: mov (%rax),%rdx 0x00005555555546ca <+26>: lea -0xa(%rbp),%rax 0x00005555555546ce <+30>: mov %rdx,%rsi 0x00005555555546d1 <+33>: mov %rax,%rdi 0x00005555555546d4 <+36>: callq 0x555555554560 <strcpy@plt> 0x00005555555546d9 <+41>: mov $0x0,%eax 0x00005555555546de <+46>: leaveq 0x00005555555546df <+47>: retq End of assembler dump. (gdb) info registers rsp rsp 0x7fffffffde20 0x7fffffffde20 (gdb) x/-20x 0x7fffffffde20 0x7fffffffddd0: 0x00000000 0x00000000 0x00000002 0x00000000 0x7fffffffdde0: 0xffffdf40 0x00007fff 0xffffde60 0x00007fff 0x7fffffffddf0: 0xf7ffe150 0x00007fff 0x00000000 0x00000000 0x7fffffffde00: 0x00000001 0x00000000 0x5555472d 0x00005555 0x7fffffffde10: 0x00000000 0x00000000 0x00000000 0x00000000 (gdb) step __strcpy_ssse3 () at ../sysdeps/x86_64/multiarch/strcpy-ssse3.S:32 32 ../sysdeps/x86_64/multiarch/strcpy-ssse3.S: No such file or directory. (gdb) x/-20x 0x7fffffffde20 0x7fffffffddd0: 0x00000000 0x00000000 0x00000002 0x00000000 0x7fffffffdde0: 0xffffdf40 0x00007fff 0xffffde60 0x00007fff 0x7fffffffddf0: 0xf7ffe150 0x00007fff 0x00000000 0x00000000 0x7fffffffde00: 0x00000001 0x00000000 0x5555472d 0x00005555 0x7fffffffde10: 0x00000000 0x00000000 0x555546d9 0x00005555 (gdb) The last line starts at 0x7fffffffde10 and ends with 0x7fffffffde1F (one address less than rsp). Why I don't see ascii code of 'a' 10 times? Any idea? Regards, Mahmood