0
votes

I am trying to use a python script to read from memory through trace32. I've found the following document: https://www2.lauterbach.com/pdf/api_remote.pdf

I managed the following code:

local_buffer = ctypes.POINTER(ctypes.c_uint32)
t32api.T32_ReadMemory(byteAddress=addr, access=0x0, buffer=local_buffer, size=size)
print(local_buffer)

Of course there is an initialization of the t32api object - that works. But the code I pasted here causes the following python error:

Traceback (most recent call last):
  File "<path_to_python_script>", line 599, in <module>
    main()
  File "<path_to_python_script>", line 590, in main
    process()
  File "<path_to_python_script>", line 269, in process
    NumberOfEmpr = read_addr(0xf0083100)
  File "<path_to_python_script>", line 148, in read_addr
    return read_addr_t32(addr, size)
  File "<path_to_python_script>", line 137, in read_addr_t32
    t32api.T32_ReadMemory(byteAddress=addr, access=0x0, buffer=local_buffer, size=size)
OSError: exception: access violation writing 0xXXXXXXXX

Of course 0xXXXXXXXX is a placeholder to some address, I am guessing it is the address of local_buffer.

If anyone knows how to fix this I will be thankful.

1
Here is a guide how to write to memory via the classic remote API from Python: stackoverflow.com/a/47717395/4727717 (Reading goes basically the same way and is briefly shown in the bottom of the answer.)Holger

1 Answers

0
votes

The problem is that the buffer pointer you give to T32_ReadMemory() should not only be a pointer but should be a pointer to existing memory.

So you need to change

local_buffer = ctypes.POINTER(ctypes.c_uint32)
t32api.T32_ReadMemory(byteAddress=addr, access=0x0, buffer=local_buffer, size=size)
print(local_buffer)

to

local_buffer = (ctypes.c_ubyte * size)()
t32api.T32_ReadMemory(byteAddress=addr, access=0x0, buffer=local_buffer, size=size)
print(local_buffer)

Two remarks independent of your problem:

  1. I would suggest to use T32_ReadMemoryObj() instead of T32_ReadMemory().
  2. Check trace32_and_python.pdf. New TRACE32 version include a Python module which you can just import.