0

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!

Badmanchild
  • 990
  • 9
  • 18

3 Answers3

1

Seems like you want the add-symbol-file', oradd-symbol-file-from-memory' commands to let gdb know about the code that has been copied to that memory location.

matt
  • 5,364
  • 1
  • 25
  • 25
1

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.

Matthew Slattery
  • 45,290
  • 8
  • 103
  • 119
0

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.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362