trace32 using python - use function T32_ReadMemoryObj

332 views Asked by At

A question before the code:

What are the differences between T32_ReadMemory and T32_ReadMemoryObj and in which cases should I prefer one over the other? As far as I can tell from the API PDF the 'Obj' version is more advanced and has more access options and access to 64 bit addresses, but there is no flaw in the regular version so if it works I can use it, am I right?

And for the code:

localBuffer = (ctypes.c_uint8 * size)()

myBufferHandle = ?
myAddressHandle32 = ?

t32api.T32_RequestBufferObj(ctypes.byref(myBufferHandle), 0)
t32api.T32_RequestAddressObjA32(ctypes.byref(myAddressHandle32), addr)

t32api.T32_ReadMemoryObj(myBufferHandle, myAddressHandle32, size)

t32api.T32_CopyDataFromBufferObj(localBuffer, size, myBufferHandle)
t32api.T32_ReleaseBufferObj(ctypes.byref(myBufferHandle))

This is an attempt to "translate" to python the following code example from the remote API PDF: c code example for using T32_ReadMemoryObj

I got stuck in the places marked by question-marks, I don't know how to create trace32 internal types. I looked for a python example and couldn't find any.

1

There are 1 answers

2
dev15 On BEST ANSWER

Yes you are right, you don't need to use T32_ReadMemoryObj(), you can use T32_ReadMemory(). I suggest to use T32_ReadMemoryObj() nonetheless because it's only marginally more complicated to use, but offers full flexibility. The main advantages in my opinion is the better access class management (strings instead of magic numbers) and 64-bit addresses. You might not need these in simple use cases.

Regarding your T32_ReadMemoryObj(): You just need create void pointers. The T32_Request...Obj() functions will create the objects and set the pointer to them.

localBuffer = (ctypes.c_uint8 * size)()

myBufferHandle = ctypes.c_void_p()
myAddressHandle32 = ctypes.c_void_p()

t32api.T32_RequestBufferObj(ctypes.byref(myBufferHandle), 0)
t32api.T32_RequestAddressObjA32(ctypes.byref(myAddressHandle32), addr)

t32api.T32_ReadMemoryObj(myBufferHandle, myAddressHandle32, size)

t32api.T32_CopyDataFromBufferObj(localBuffer, size, myBufferHandle)
t32api.T32_ReleaseBufferObj(ctypes.byref(myBufferHandle))