[llvm] [llvm-objdump] Add --substitute-path and --source-dir for --source (PR #201096)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 10 01:18:10 PDT 2026
================
@@ -49,19 +49,46 @@
; RUN: --substitute-path /wron /nowhere \
; RUN: --substitute-path /wrong %/p %t.o | \
; RUN: FileCheck %s --check-prefix=SOURCE
+
+; Empty <to> strips the matched prefix (GDB allows this); use --source-dir to
+; resolve the resulting relative path.
+; RUN: echo '--substitute-path' > %t-empty-to.rsp
+; RUN: echo '/wrong' >> %t-empty-to.rsp
+; RUN: echo '""' >> %t-empty-to.rsp
+; RUN: llvm-objdump --no-print-imm-hex -d --source @%t-empty-to.rsp \
+; RUN: --source-dir %/p/Inputs %t.o | FileCheck %s --check-prefix=SOURCE
+
+; Empty <to> without --source-dir: relative path is not resolved; warn once, no crash.
+; RUN: llvm-objdump --no-print-imm-hex -d --source @%t-empty-to.rsp %t.o 2>&1 | \
+; RUN: FileCheck %s --check-prefix=SOURCE-EMPTY-TO -DFILE=%t.o
+
+; Empty <from> is rejected (use a response file so the shell does not drop "").
+; RUN: echo '--substitute-path' > %t-empty-from.rsp
+; RUN: echo '""' >> %t-empty-from.rsp
+; RUN: echo '%/p' >> %t-empty-from.rsp
+; RUN: not llvm-objdump @%t-empty-from.rsp %t.o 2>&1 | \
+; RUN: FileCheck %s --check-prefix=SUBST-ERR-FROM
+
+; SUBST-ERR-FROM: llvm-objdump{{.*}}: error: --substitute-path: <from> must not be empty
+
; LINE: <foo>:
; LINE-NEXT: ; foo():
-; LINE-NEXT: ; {{.*}}source-path.c:2
+; LINE-NEXT: ; {{.*}}source-interleave-x86_64.c:2
; LINE-NEXT: pushq
-; LINE: ; {{.*}}source-path.c:3
+; LINE: ; {{.*}}source-interleave-x86_64.c:3
; LINE-NEXT: movq
; LINE-NEXT: movl
; LINE-NEXT: popq
; LINE-NEXT: retq
-; SOURCE-MISSING: warning: '[[FILE]]': failed to find source {{[/\\]}}wrong{{[/\\]}}Inputs{{[/\\]}}source-path.c
+; SOURCE-MISSING: warning: '[[FILE]]': failed to find source {{[/\\]}}wrong{{[/\\]}}Inputs{{[/\\]}}source-interleave-x86_64.c
+
+; SOURCE-MISSING-SUBST: warning: '[[FILE]]': failed to find source {{[/\\]}}nowhere{{[/\\]}}Inputs{{[/\\]}}source-interleave-x86_64.c
-; SOURCE-MISSING-SUBST: warning: '[[FILE]]': failed to find source {{[/\\]}}nowhere{{[/\\]}}Inputs{{[/\\]}}source-path.c
+; SOURCE-EMPTY-TO: <foo>:
+; SOURCE-EMPTY-TO: warning: '[[FILE]]': failed to find source {{.*}}Inputs{{[/\\]}}source-interleave-x86_64.c
----------------
VladimirMedic wrote:
You are right. The source path recorded in object file is /wrong/Inputs\source-interleave-x86_64.c, so substituting /wrong with "" leaves Inputs\source-interleave-x86_64.c. {{.*}} would accept anything before Inputs which is wrong.
https://github.com/llvm/llvm-project/pull/201096
More information about the llvm-commits
mailing list