Reputation: 118
I'm trying to attach gdb
to a program started by socat
like this:
socat TCP-LISTEN:5678,reuseaddr,fork EXEC:./test
In another terminal,
sudo gdb
attach `pidof socat`
br *0x080487D4
when execute continue
command in gdb, it shows error like this:
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x80487d4
Command aborted.
0x080487D4 is in .text
of test
program. The follow-fork-mode
of gdb is child
, I have searched online but still can't solve it.
I debugged program successfully like this way a month ago, and don't know why it doesn't work now. But it's ok if debug the program directly using gdb like this:
gdb -q ./test
However, the way above doesn't meet my needs.
Through debugging, I think gdb
expects that address is a valid address in the socat
rather then test
program. So how can I set breakpoints in test
program? Without breakpoints in test
program, it will run directly to the end when execute continue
command. Setting breakpoints in socat
program is useless.
Any advice? Thanks in advance.
Upvotes: 4
Views: 2795
Reputation: 118
I have figured out how to set breakpoints in test
program.
When start test
program using socat
, it won't fork a test
process until a socket connection comes. So trying to set breakpoints directly in test
program fails.
I use a tool(for my purpose, choose pwntools
) to connect to it and suspend it ,then use gdb
to attach to the forked test
process. Next, I can debug normally.
Any better ideas? Thanks in advance.
Upvotes: 2