开发者

set a breakpoint, when called: return and continue

开发者 https://www.devze.com 2023-02-24 01:35 出处:网络
I know how to do this in gdb. I\'d attach, and follow with: break myfunction c开发者_运维百科ommands

I know how to do this in gdb. I'd attach, and follow with:

break myfunction

c开发者_运维百科ommands

return
cont
end

cont

I'm wondering if there's a way of doing this in c? I already have my code working for reading memory addresses and writing to memory addresses. And it automatically finds the pid and does related stuff. I'm stuck with implementing that use of breakpoints.


If you are talking about some sort of hand-written debugger, you can use IP value to set a breakpoint; Literally, when IP hits some certain value, you stop the program being debugged and perform some routine (for example, heading away to debugger process). To use function names, you should use symbol tables like it is done in GDB.


It's not quite clear what you are trying to achieve.

The GDB sequence you've show will simply make myfunction immediately return.

Assuming you want your mini-debugger to have the same effect, simply write the opcode for ret (0xC3 on x86) to the address of myfunction; no need to do the breakpoint at all.

0

精彩评论

暂无评论...
验证码 换一张
取 消