Open
Conversation
29cf91a to
b38ee74
Compare
13 tasks
jtojnar
commented
Dec 24, 2022
| SEARCH='^#define SYSTEM_BUILD_ID_DIR.*$$'; \ | ||
| REPLACE="#define SYSTEM_BUILD_ID_DIR \"$(TEST_BUILD_ID_DIR)\""; \ | ||
| SEARCH='^#define BUILD_ID_DIR.*$$'; \ | ||
| REPLACE='\0\n#undef SYSTEM_DEBUG_DIR\n#define SYSTEM_DEBUG_DIR "$(TEST_DEBUG_DIR)"'; \ |
Author
There was a problem hiding this comment.
Ideally, we would be able to just use -D flag here but I tried the following
--- a/Makefile.am
+++ b/Makefile.am
@@ -144,12 +144,9 @@ libbacktrace_elf_for_test_la_LIBADD = $(BACKTRACE_FILE) elf_for_test.lo \
$(VIEW_FILE) $(ALLOC_FILE)
elf_for_test.c: elf.c
- SEARCH='^#define BUILD_ID_DIR.*$$'; \
- REPLACE='\0\n#undef SYSTEM_DEBUG_DIR\n#define SYSTEM_DEBUG_DIR "$(TEST_DEBUG_DIR)"'; \
- $(SED) "s%$$SEARCH%$$REPLACE%" \
- $< \
- > $@.tmp
- mv $@.tmp $@
+ cp $< $@
+
+libbacktrace_elf_for_test_la_CFLAGS = -USYSTEM_DEBUG_DIR -DSYSTEM_DEBUG_DIR=\"$(TEST_DEBUG_DIR)\"
endif HAVE_OBJCOPY_DEBUGLINK
endif HAVE_ELFwithout success and autotools are just too confusing to me.
libbacktrace_elf_for_test_la_CFLAGS does not seem to affect the compilation of elf_for_test.lo (it still gets -DSYSTEM_DEBUG_DIR from AM_CFLAGS) and it only appears when linking the objects into libbacktrace_elf_for_test.la:
cp elf.c elf_for_test.c /nix/store/4xw8n979xpivdc46a9ndcvyhwgif00hz-bash-5.1-p16/bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -funwind-tables -frandom-seed=elf_for_test.lo -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -DSYSTEM_DEBUG_DIR=\"/nix/store/dkpyi2cxvjxk74l2pjighshbzncy2hmy-libbacktrace-unstable-2022-12-16/lib/debug\" -g -O2 -c -o elf_for_test.lo elf_for_test.c libtool: compile: gcc -DHAVE_CONFIG_H -I. -funwind-tables -frandom-seed=elf_for_test.lo -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -DSYSTEM_DEBUG_DIR=\"/nix/store/dkpyi2cxvjxk74l2pjighshbzncy2hmy-libbacktrace-unstable-2022-12-16/lib/debug\" -g -O2 -c elf_for_test.c -fPIC -DPIC -o .libs/elf_for_test.o /nix/store/4xw8n979xpivdc46a9ndcvyhwgif00hz-bash-5.1-p16/bin/bash ./libtool --tag=CC --mode=link gcc -USYSTEM_DEBUG_DIR -DSYSTEM_DEBUG_DIR=\"/build/libbacktrace/usr/lib/debug\" -g -O2 -o libbacktrace_elf_for_test.la libbacktrace_elf_for_test_la-atomic.lo libbacktrace_elf_for_test_la-dwarf.lo libbacktrace_elf_for_test_la-fileline.lo libbacktrace_elf_for_test_la-posix.lo libbacktrace_elf_for_test_la-print.lo libbacktrace_elf_for_test_la-sort.lo libbacktrace_elf_for_test_la-state.lo backtrace.lo simple.lo elf_for_test.lo mmapio.lo mmap.lo libtool: link: ar cr .libs/libbacktrace_elf_for_test.a .libs/libbacktrace_elf_for_test_la-atomic.o .libs/libbacktrace_elf_for_test_la-dwarf.o .libs/libbacktrace_elf_for_test_la-fileline.o .libs/libbacktrace_elf_for_test_la-posix.o .libs/libbacktrace_elf_for_test_la-print.o .libs/libbacktrace_elf_for_test_la-sort.o .libs/libbacktrace_elf_for_test_la-state.o .libs/backtrace.o .libs/simple.o .libs/elf_for_test.o .libs/mmapio.o .libs/mmap.o libtool: link: ranlib .libs/libbacktrace_elf_for_test.a
On platforms that do not use FHS like NixOS or GNU Guix, the build-id directories are not under `/usr/lib/debug`. Let’s add `--with-separate-debug-dir` configure flag so that the path can be changed. The same flag is supported by gdb: https://github.com/bminor/binutils-gdb/blob/095f84c7e3cf85cd68c657c46b80be078f336bc9/gdb/configure.ac#L113-L115
gdb supports multiple debug directories separated by colons: https://github.com/bminor/binutils-gdb/blob/fcbfb25dcca625a7f999ec51d48b6fc3a32123c3/gdb/build-id.c#L136-L142 This is useful for example when using dwarffs in addition to debug data installed using distribution’s package manager.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On platforms that do not use FHS like NixOS or GNU Guix, the build-id directories are not under
/usr/lib/debug.Let’s add
--with-separate-debug-dirconfigure flag so that the path can be changed. The same flag is supported by gdbAnd just like gdb, let’s make it accept multiple debug directories separated by colons. This is useful for example when using dwarffs in addition to debug data installed using distribution’s package manager.