tags:

views:

44

answers:

1

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 generate 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?

A: 

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.

Nikolai N Fetissov
again, output redirection is not feasible due to the amount of data that would be generated. For example, on a 2ghz super scalar machine with a modest IPC of 1, storing a char[30] for each machine instruction would consume 120 gigabytes of data per second of normal program execution.Ultimately, I want to be able to create a map of memory addresses that a specific portion of code touches at a specific time point.Manual decoding of the $pc I think would be too much work, but might be worth looking into.
Mark