2

I am defining a convenience variable in gdb

>set $param = (T_packet*)malloc(sizeof(T_packet))

I can retrieve it via Python

>p = gdb_helper.parse_and_eval("$param")
<gdb.Value at 0x7f30b42f9170>

show the fields of the struct

>python print(p.dereference())

{ID_PACKET = 0 , L_PACKET = 0}

Try to change a field (C equivalent: p->ID_PACKET=1)

p.dereference()["ID_PACKET"] = 1
>"Setting of struct elements is not currently supported"

Is there way to update the value of the field ID_Packet inside p using GDB's Python API?

1 Answer 1

1

There's currently no way to set a value using the Value API. This is just a little hole in gdb (I looked but could not find a bug for this, so perhaps filing one would be a good thing to do).

Meanwhile you can work around it, with a bit of difficulty, using gdb.parse_and_eval. The idea is to get the address of the field in question, then form an expression like *(TYPE *) 0xADDR = VALUE. Alternatively you can write directly to memory using Inferior.write_memory.

Both of these approaches will fail in some situations, for example you cannot write to a register this way, preventing this from working on a structure that's been split apart due to SRA optimization.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.