save gdb display to a variable
Is there a way to store the output of the last command in gdb to a string? What I would like to do is store the address information of selected machine level instructions. Redirecting the output is not a solution as it would gene开发者_如何学JAVArate too much output. A simulator would also be a solution, but I'd like to see if it would be possible with gdb as I only want the analysis on a small chunk of code.
So I would need something like this:
(gdb) display/i $pc
(gdb) 1: x/i $pc 0x100000d2e <main+61>: jle 0x100000d02 <main+17
(gdb) set $foo = ??? somehow set this to display line 1
(gdb) call myFunc($foo)
(I excluded the looping controls to keep the example simple)
Or would there be another way of doing this?
Not possible as far as I know, which is kind of surprising considering all the Lisp background of the author :) You'd need either redirection (grep
, sed
, and awk
make wonders on large files, and there's always perl
), or your own instruction decoding based on $pc
, which I assume is not an option.
Then I don't really understand what you are trying to do. Figure out jump targets? Relocation correctness? What is that you don't know about the code until the runtime? More details can probably point into better direction.
Edit:
Just some links - haven't tried it yet - you might want to play with script-extension
setting and see if you can make Python command files work for you:
see Extending GDB and Python in GDB.
精彩评论