Prior to GCC 5 (1), I don't know of a way to run arbitrary machine code unless you actually enter the machine code into memory and then run it.
If you want to run code that's already in memory, you can just set the instruction pointer to the start, a breakpoint at the end, then go. Then, after the breakpoint, change the instruction pointer back to its original value.
But I can't actually see the use case for this. That doesn't mean there isn't one, just that anything you can do by running code, you can also achieve by directly modifying the registers, flags, memory and so forth.
For example, the command:
info registers
will dump the current values of the registers while:
set $eax = 42
will change the eax
register to 42
.
You can also change memory in this way:
set *((char*)0xb7ffeca0) = 4
This writes a single byte to memory location 0xb7ffeca0
and you can also use that same method to store wider data types.
(1) GCC 5 allows you to compile and execute arbitrary code with the compile code
command, as documented here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…