You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DWARF表路径错误排查:armclang编译后Keil调试无法识别源文件

Why Does armclang Generate Incorrect Source Paths in DWARF Debug Info (Causing Keil Debugging Issues)?

I’ve helped troubleshoot exactly this kind of problem with armclang and Keil before, so let’s break down the most likely causes and fixes based on your scenario:

1. Build System Working Directory & Path Passing Errors

This is the #1 culprit in most cases. If your build tool (Makefile, CMake, or custom script) switches to the build/obj directory to run the compile command, armclang will use that working directory as the base for resolving source file paths.

For example:

  • If you run armclang -g src/main.c -c -o build/obj/main.o from your project root (F:/MyProject/), the DWARF info will correctly record F:/MyProject/src/main.c.
  • But if your build script cd’s into build/obj first and runs armclang -g ../../src/main.c -c -o main.o, armclang will resolve the relative path against the current working directory (build/obj), leading to a mangled absolute path in DWARF (like the F:/MyProject/build/obj\main.c you saw). Mixing Windows-style \ and Unix-style / separators here can make the problem worse.

Fix: Update your build script to run compile commands from the project root, or pass absolute paths to your source files instead of relative ones. For Makefile, you can use $(abspath src/main.c) to ensure the full correct path is passed to armclang.

2. Accidental Use of Path Remapping Flags

armclang supports flags like -fdebug-prefix-map=old-path=new-path to rewrite source paths in DWARF info. If your build system incorrectly sets this flag (e.g., mapping ../src to ./), it will overwrite the actual source path with the build directory path.

Fix: Check your compile flags for any instances of -fdebug-prefix-map or -ffile-prefix-map. If they’re present, verify the mapping logic is correct—remove them entirely if you don’t need path remapping.

3. Windows Path Separator Compatibility Quirks

Windows uses \ as the path separator, but armclang (which has roots in Unix-based toolchains) sometimes handles mixed separators poorly. If your build script passes paths with a mix of / and \ (e.g., src\main.c instead of src/main.c), the compiler may resolve the path incorrectly when generating DWARF info.

Fix: Standardize on / for all paths in your build script. For Makefile, you can use $(subst \,/,$(SOURCE_FILE)) to convert Windows-style paths to Unix-style before passing them to armclang.

4. Missing Keil Debug Path Mapping (Backup Fix)

While you should fix the root cause in the compile step, if you need a temporary workaround, Keil lets you manually map source paths. Go to your project’s Debug Configuration → Source Code Paths, add F:/MyProject/src/ to the list, and Keil will search this directory for source files even if the DWARF path is wrong.


内容的提问来源于stack exchange,提问作者Michał Stroka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:24:22