Hello
I'm trying to find a workflow for remote debugging an application on my device (STM32MP1 based). The device runs an image created with yoco (kirkstone).
Thanks to these threads:
https://users.rust-lang.org/t/linker-gcc-sysroot/28138/5
https://stackoverflow.com/questions/68888706/remote-debug-of-rust-program-in-visual-studio-code
...I was able to cross compile my application using the toolchain build with yocto. I can copy the binary to the device and it runs just fine. However, when I try debugging, VS Code shows only assembly code and the application does not run at all when hitting continue. It just stops at what VSCode identifies as "Source location: /usr/src/debug/glibc/2.35-r0/git/sysdeps/arm/start.S:79"
; id = {0x00000aff}, range = [0x0000000000004200-0x0000000000004234), name="_start"
; Source location: /usr/src/debug/glibc/2.35-r0/git/sysdeps/arm/start.S:79
00404200: 4F F0 00 0B mov.w r11, #0x0
00404204: 4F F0 00 0E mov.w lr, #0x0
00404208: 02 BC pop {r1}
0040420A: 6A 46 mov r2, sp
0040420C: 04 B4 push {r2}
...
I use gdbserver on the device:
gdbserver *:177777 helloworld
In VSCode I use lldb with the following launch task:
{
"type": "lldb",
"request": "custom",
"name": "Remote debug executable 'helloworld'",
"targetCreateCommands": ["target create ${workspaceFolder}/target/armv7-unknown-linux-gnueabihf/debug/helloworld"],
"processCreateCommands": ["gdb-remote 192.168.0.192:17777"]
}
Further, I noticed that the application can't even be debugged locally on the device itself. I can start and run it using gdb:
root@stm32mp1:~# gdb helloworld
GNU gdb (GDB) 11.2
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "arm-poky-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from helloworld...
warning: Unsupported auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/root/helloworld.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) r
Starting program: /home/root/helloworld
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
Hello,
world!
123
[Inferior 1 (process 366) exited normally]
It runs as expected. However, as soon as I set a breakpoint and execution hits it, gdb is no longer able to continue after that. I get an 'illegal instruction' message:
gdb) b 4
Breakpoint 1 at 0x404604: file src/main.rs, line 4.
(gdb) r
Starting program: /home/root/helloworld
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
Hello,
Breakpoint 1, helloworld::main () at src/main.rs:4
4 src/main.rs: No such file or directory.
(gdb) c
Continuing.
Program received signal SIGILL, Illegal instruction.
0x00404d5e in core::option::Option::unwrap<std::sync::once_lock::{impl#0}::initialize::{closure_env#0}<std::sys_common::remutex::ReentrantMutex<core::cell::RefCell<std::io::buffered::linewriter::LineWriter<std::io::stdio::StdoutRaw>>>, std::sync::once_lock::{impl#0}::get_or_init::{closure_env#0}<std::sys_common::remutex::ReentrantMutex<core::cell::RefCell<std::io::buffered::linewriter::LineWriter<std::io::stdio::StdoutRaw>>>, std::io::stdio::stdout::{closure_env#0}>, !>> () at library/core/src/option.rs:775
775 library/core/src/option.rs: No such file or directory.
Any idea what causes this and how I can fix it? Missing libraries? Issue with the cross compilation (but then, why does it run without debugging)?