如何强制GDB执行没有符号的代码
我有一个 C 程序(有充分的理由)分配内存,向其中复制一些代码,使用 mprotect() 赋予它执行权限,然后调用该代码。 是的,我知道这是不可移植且不安全的,但这是有充分理由的。 不管怎样,我需要通过汇编代码(使用 si 命令)使用 gdb 单步执行,但它不允许我——它一直说: “没有函数包含所选帧的程序计数器”
有没有办法强制 gdb 执行此代码?我是否应该使用另一个调试器来代替这种类型的事情?
谢谢!
I have a C program that (for good reason) allocates memory, copies some code to it, uses mprotect() to give it execute privileges, and then calls that code.
Yes I know this is unportable and unsafe, but there's a good reason.
Anyway, I need to single-step with gdb through the assembly code (using si command) but it won't let me -- it keeps saying:
"No function contains program counter for selected frame"
Is there a way to force gdb to execute this code? Is there another debugger that I should be using instead for this type of thing?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎您需要
add-symbol-file' 或
add-symbol-file-from-memory' 命令让 gdb 了解已复制到该内存位置的代码。
Seems like you want the
add-symbol-file', or
add-symbol-file-from-memory' commandsto let gdb know about the code that has been copied to that memory location.
在开始
si
/stepi
之前,您应该能够使用display/i $pc
来跟踪您的代码。这告诉它在每次打印提示之前显示当前指令的反汇编。You should be able to follow through your code by using
display/i $pc
before starting tosi
/stepi
. This tells it to show the disassembly of the current instruction just before printing the prompt each time.stepi
命令本身不需要任何符号,并且应该在您描述的场景中很好工作(尽管我实际上没有检查它是否需要)。您的问题真的与
stepi
有关吗?显示调试会话的相关部分可能会让您的问题得到更好的答案。The
stepi
command itself doesn't require any symbols and should work just fine in the scenario you described (though I haven't actually checked whether it does).Is your problem really with
stepi
? Showing relevant part(s) of your debug session might open your question to better answers.