Here is the program which gdb
is attached to:
prog.c
#include <stdio.h>
void dummy(char* s)
{
}
int main()
{
char buf[512];
scanf("%s", buf);
printf("%s\n", buf);
dummy(buf);
return 0;
}
It is compiled with:
gcc prog.c o prog
This is the script which drives the program:
from pwn import *
p = process("./prog")
raw_input('>>')
p.sendline('A')
Here's the sequence of operation I perform:
- Run the script in one bash tab. It launches
prog
- In another bash tab:
sudo gdb -p `pgrep prog`
.gdb
attaches itself to the running process - Set a breakpoint on
dummy
call ingdb
:b dummy
- Press
c
ingdb
to continue - Hit Enter in the script to continue
gdb
gives up by saying:0x000056446a5af764 <dummy+4>: Cannot access memory at address 0x56446a5af764
If instead of feeding the input programmatically, I launch the program manually, attach gdb and feed the input myself, the breakpoint is correctly hit.
What is the problem in the script?