在嵌入式设备上如何本机调试 bazel build 生成的可执行文件

问题描述 投票:0回答:1

Bazel 使用交叉编译器工具链构建一段简单的代码 hello-world,并确认生成的可执行二进制文件包含

debug info
,

$ file bazel-bin/examples/hello_world/hello_world
bazel-bin/examples/hello_world/hello_world: ELF 64-bit LSB executable, ARM aarch64,   
version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1,    
for GNU/Linux 3.7.0, with debug_info, not stripped

然后将可执行二进制文件 scp 到目标嵌入式设备的 /app/bin 目录下,并将整个源代码目录

examples(sub-directory includes hello_world/hello_world.cpp)
复制到 /app/bin 下的设备,现在运行 GDB 进行本机单步调试,并设置首先查看源代码的目录,以确保 gdb 能够找到源代码,但仍然不会显示源代码。

$ gdb hello_world
Reading symbols from hello_world...
(gdb) set directories /app/bin/examples/hello_world 
Source directories searched: /app/bin/examples/hello_world:$cdir:$cwd  
(gdb) b main
Breakpoint 1 at 0x40497c
(gdb) l
1       ../sysdeps/aarch64/start.S: No such file or directory.
(gdb) r
Starting program: /app/bin/hello_world
Python Exception <class 'NameError'> Installation error: gdb._execute_unwinders function is missing: 
Breakpoint 1, 0x000000000040497c in main ()
(gdb) l
1       in ../sysdeps/aarch64/start.S
(gdb) n 
Single stepping until exit from function main.
which has no line number information.
......

Single stepping until exit from function main. which has no line number information
,这表明我正在尝试调试没有调试信息的可执行文件,但我已经确认它确实包含调试信息。那么,到底出了什么问题?

c++ debugging gdb cross-compiling bazel
1个回答
0
投票

确认生成的可执行二进制文件包含调试信息

... with debug_info, not stripped

并没有实际确认任何有用的东西——它只是说存在一些调试信息。但该调试信息可能来自

crt0.o
而不是来自您的任何来源。

确实是这一行:

Breakpoint 1, 0x000000000040497c in main ()

告诉我们您没有

main
的调试信息。

您可以使用

readelf -WS /app/bin/hello_world
并查找
.debug_info
部分的大小。很有可能尺寸真的很小。


Bazel 构建一段简单的代码 hello-world

您使用了哪些命令行标志?特别是,你用过

-c dbg
吗?

如果没有,那可能是你的问题。 文档

© www.soinside.com 2019 - 2024. All rights reserved.