avatartwo / avatar2-examples

Examples demonstrating the usage of avatar²
27 stars 14 forks source link

RemoteMemoryRead failed: Failed to read memory! #6

Open bukeyong opened 2 years ago

bukeyong commented 2 years ago

When I try to run qemu_uboot, I run into the following problem:

2022-04-19 02:25:29,050 | avatar.INFO | Initialized Avatar. Output directory is /tmp/myavatar TargetLauncher is starting process "qemu-system-arm" "-M" "versatilepb" "-m" "256M" "-gdb" "tcp:127.0.0.1:1234" "-serial" "tcp:127.0.0.1:2000,server,nowait" "-kernel" "u-boot" "-S" "-nographic" "-monitor" "telnet:127.0.0.1:2001,server,nowait" pulseaudio: set_sink_input_volume() failed pulseaudio: Reason: Invalid argument pulseaudio: set_sink_input_mute() failed pulseaudio: Reason: Invalid argument 2022-04-19 02:25:29,326 | avatar.targets.GDBTarget0.INFO | State changed to TargetStates.STOPPED 2022-04-19 02:25:29,327 | avatar.INFO | Received state update of target GDBTarget0 to TargetStates.STOPPED 2022-04-19 02:25:29,338 | avatar.targets.GDBTarget0.INFO | Connected to Target 2022-04-19 02:25:29,339 | avatar.targets.QemuTarget0.WARNING | No cpu_model specified - are you sure? 2022-04-19 02:25:29,341 | avatar.targets.QemuTarget0.INFO | QEMU process running 2022-04-19 02:25:29,419 | avatar.targets.QemuTarget0.INFO | State changed to TargetStates.STOPPED 2022-04-19 02:25:29,419 | avatar.INFO | Received state update of target QemuTarget0 to TargetStates.STOPPED 2022-04-19 02:25:29,432 | avatar.targets.QemuTarget0.QMPProtocol.INFO | b'{"return": {}, "id": 0}\r\n' 2022-04-19 02:25:29,432 | avatar.targets.QemuTarget0.INFO | Connected to remote target 2022-04-19 02:25:29,432 | avatar.targets.QemuTarget0.RemoteMemoryProtocol.INFO | Successfully connected rmp 2022-04-19 02:25:29,451 | avatar.targets.QemuTarget0.INFO | State changed to TargetStates.RUNNING 2022-04-19 02:25:29,452 | avatar.INFO | Received state update of target QemuTarget0 to TargetStates.RUNNING 2022-04-19 02:25:29,451 | avatar.targets.QemuTarget0.INFO | State changed to TargetStates.BREAKPOINT 2022-04-19 02:25:29,452 | avatar.INFO | Breakpoint hit for Target: QemuTarget0 2022-04-19 02:25:29,452 | avatar.INFO | Received state update of target QemuTarget0 to TargetStates.BREAKPOINT 2022-04-19 02:25:29,452 | avatar.targets.QemuTarget0.INFO | State changed to TargetStates.STOPPED 2022-04-19 02:25:29,452 | avatar.INFO | Received state update of target QemuTarget0 to TargetStates.STOPPED ================== Arrived at clear_bss ========================= 2022-04-19 02:25:29,470 | avatar.ERROR | RemoteMemoryRead failed: Failed to read memory! Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/avatar2.py", line 453, in _handle_remote_memory_read_message mem = range.forwarded_to.read_memory( File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/watchmen.py", line 78, in watchtrigger ret = func(self, *args, *kwargs) File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/targets/target.py", line 35, in check return func(self, args, **kwargs) File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/targets/target.py", line 386, in read_memory return self.protocols.memory.read_memory(address, size, num_words, raw) File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/protocols/gdb.py", line 664, in read_memory raise Exception("Failed to read memory!") Exception: Failed to read memory! 2022-04-19 02:25:29,473 | avatar.targets.QemuTarget0.INFO | State changed to TargetStates.RUNNING 2022-04-19 02:25:29,474 | avatar.INFO | Received state update of target QemuTarget0 to TargetStates.RUNNING 2022-04-19 02:25:29,484 | avatar.targets.QemuTarget0.INFO | State changed to TargetStates.EXITED 2022-04-19 02:25:29,484 | avatar.INFO | Received state update of target QemuTarget0 to TargetStates.EXITED Arrived at main loop, demo is over 2022-04-19 02:25:29,965 | avatar.targets.QemuTarget0.RemoteMemoryProtocol.WARNING | Tried to close/unlink non existent rx_queue 2022-04-19 02:25:29,965 | avatar.targets.QemuTarget0.RemoteMemoryProtocol.WARNING | Tried to close/unlink non existent tx_queue None

mariusmue commented 2 years ago

Hi, this issue was described already here: https://github.com/avatartwo/avatar2-examples/issues/4

Albeit closed, it has the answer for you: Everything worked as expected, you arrive at Arrived at main loop, demo is over .

The issue is in the avatar2 teardown. Have you tried running the script unbuffered (python3 -u qemu_uboot_avatar2.py)? Maybe it fixes at least the race condition between logging and throwing of the exception.

bukeyong commented 2 years ago

It's the same result of running python3 -u qemu_uboot_avatar2.py . But why do I get an error when I try to read the value of memory or register?

mariusmue commented 2 years ago

Heya, taking a second loop at the timestamps, and may indeed be the case that QEMU errors straight-away. Can you retry with the PANDA target for the time being, instead of the qemu target? I think something may have gone wrong during our yearly sync with upstream qemu, resulting into these errors.

rawsample commented 2 years ago

Hi,

There is more debugging info within /tmp/myavatar directory. What is the output of cat /tmp/myavatar/{QemuTarget0_err.txt,QemuTarget0_out.txt}?

bukeyong commented 2 years ago

cat QemuTarget0_err.tx qemu-system-arm: RemoteMemoryRead failed (-1)!

cat QemuTarget0_out.txt Configurable: Adding memory region interrupts (size: 0x1000) at address 0x0 Configurable: Adding memory region init_mem (size: 0x1000) at address 0xfdd000 Configurable: Adding memory region heap (size: 0x22000) at address 0xfde000 Configurable: Adding peripheral[avatar-rmemory] region after_code at address 0x1019000 Configurable: Adding peripheral[pl011] region serial at address 0x101f1000 Configurable: Adding peripheral[avatar-rmemory] region before_code at address 0x1000 Configurable: Adding memory region text_data_bss (size: 0x19000) at address 0x1000000 Configurable: Inserting 0x15144 bytes of data in memory region text_data_bss Configurable: Copying 0x15144 byte of data from file /home/desh0ng/Desktop/bishe/Avatar/avatar2/examples/qemu_uboot/u-boot.bin beginning at offset 0x0 to address 0x1000000 Configurable: Adding peripheral[avatar-rmemory] region after_serial at address 0x101f2000

bukeyong commented 2 years ago

Well, my current goal is to simulate the stm32 development board, so I didn't consider using Panda.

mariusmue commented 2 years ago

Panda is under the hood qemu based, and is currently more used by the avatar2-developers (and, hence, better testing). Additionally, the framework can serve as drop-in for Qemu! Please try:

AVATAR2_QEMU_EXECUTABLE=panda-system-arm python3 qemu_uboot_avatar2.py

(assuming you are in the docker or have panda installed locally.)