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. 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 f开发者_如何学Cor 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.
You should be able to follow through your code by using display/i $pc
before starting to si
/ stepi
. 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).
Is your problem really with stepi
? Showing relevant part(s) of your debug session might open your question to better answers.
精彩评论