In gdb's Values From Inferior documentation, there's a second constructor for creating objects within python. It states:
Function:
Value.__init__ (val, type)
This second form of the
gdb.Value
constructor returns agdb.Value
of typetype
where the value contents are taken from the Python buffer object specified byval
. The number of bytes in the Python buffer object must be greater than or equal to the size of type.
My question is, how do I create a buffer object that I can pass into the constructor? For instance, if I wanted to create a string (yes, I know that the first Value constructor can do this, but this is an example) I wrote the following function:
def make_str(self, str):
str += '\0'
s = bytearray(str.encode())
return gdb.Value(s, gdb.lookup_type('char').array(len(str)))
However, when I tried to use it, I got the message:
Python Exception <class 'ValueError'> Size of type is larger than that of buffer object.:
How would I make a buffer object that I could pass into the Value constructor? What would I need to do to generate a Value object?