简体   繁体   中英

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 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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