简体   繁体   English

如何强制 GDB 执行没有符号的代码

[英]How can I force GDB to execute code for which there are no symbols

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.我有一个 C 程序(有充分的理由)分配 memory,将一些代码复制到它,使用 mprotect() 赋予它执行权限,然后调用该代码。 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"无论如何,我需要通过汇编代码(使用 si 命令)单步执行 gdb 但它不会让我 - 它一直说:“没有 function 包含所选帧的程序计数器”

Is there a way to force gdb to execute this code?有没有办法强制 gdb 执行这段代码? Is there another debugger that I should be using instead for this type of thing?我应该使用另一个调试器来代替这种类型的东西吗?

Thanks!谢谢!

Seems like you want the add-symbol-file', or add-symbol-file-from-memory' commands to let gdb know about the code that has been copied to that memory location.似乎您希望add-symbol-file', or add-symbol-file-from-memory' 命令让 gdb 知道已复制到该 memory 位置的代码。

You should be able to follow through your code by using display/i $pc before starting to si / stepi .在开始si / stepi之前,您应该能够使用display/i $pc来完成您的代码。 This tells it to show the disassembly of the current instruction just before printing the prompt each time.这告诉它在每次打印提示之前显示当前指令的反汇编。

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). stepi命令本身不需要任何符号,并且在您描述的场景中应该可以正常工作(尽管我实际上并没有检查它是否确实如此)。

Is your problem really with stepi ?你的问题真的stepi吗? Showing relevant part(s) of your debug session might open your question to better answers.显示调试 session 的相关部分可能会打开您的问题以获得更好的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM