Reputation: 53
I have a python gdb script which writes to gdb.STDOUT
, and I'd like to capture this value into the value history or a convenience variable so that it's easily referenced.
For example, this script iterates a linked list and dumps the output:
(gdb) list MY_OBJECT Links myObjectList 4
(MY_OBJECT *) 0x80f830198
{ReferenceCount = 1, Flags = 0, Mutex = {Mutex = 0x80f80fe50, State = 1}, Links = {Next = 0x81182f138, Prev = 0x80f80f5a8}}
(MY_OBJECT *) 0x81182f0d8
{ReferenceCount = 6, Flags = 0, Mutex = {Mutex = 0x811815790, State = 1}, Links = {Next = 0x81182f1f8, Prev = 0x80f8301f8}}
(MY_OBJECT *) 0x81182f198
{ReferenceCount = 2, Flags = 0, Mutex = {Mutex = 0x811816830, State = 1}, Links = {Next = 0x80f8302b8, Prev = 0x81182f138}}
(MY_OBJECT *) 0x80f830258
{ReferenceCount = 1, Flags = 0, Mutex = {Mutex = 0x80f8528e0, State = 1}, Links = {Next = 0x80f80f5a8, Prev = 0x81182f1f8}}
Is it possible to write to the gdb value history? Maybe through gdb.parse_and_eval()
?
Upvotes: 0
Views: 229
Reputation: 53
I found out through experimentation that you can execute gdb commands directly from a python api command, and they will be captured into the value history.
So instead of using gdb.write("%s" % myObject)
or print
from python, one can instead do gdb.execute("print %s" % myObject)
which gives the desired side effect.
(gdb) list MY_OBJECT Links myObjectList 4
$1 = {ReferenceCount = 1, Flags = 0, Mutex = {Mutex = 0x80f80fe50, State = 1}, Links = {Next = 0x81182f138, Prev = 0x80f80f5a8}}
$2 = {ReferenceCount = 6, Flags = 0, Mutex = {Mutex = 0x811815790, State = 1}, Links = {Next = 0x81182f1f8, Prev = 0x80f8301f8}}
$3 = {ReferenceCount = 2, Flags = 0, Mutex = {Mutex = 0x811816830, State = 1}, Links = {Next = 0x80f8302b8, Prev = 0x81182f138}}
$4 = {ReferenceCount = 1, Flags = 0, Mutex = {Mutex = 0x80f8528e0, State = 1}, Links = {Next = 0x80f80f5a8, Prev = 0x81182f1f8}}
(gdb) print &$1
$5 = (MY_OBJECT *) 0x80f830198
Upvotes: 1