Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom debug dirs #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

jtojnar
Copy link

@jtojnar jtojnar commented Dec 24, 2022

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

And 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.

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)"'; \
Copy link
Author

@jtojnar jtojnar Dec 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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%" \
-		$< \
-		> [email protected]
-	mv [email protected] $@
+	cp $< $@
+
+libbacktrace_elf_for_test_la_CFLAGS = -USYSTEM_DEBUG_DIR -DSYSTEM_DEBUG_DIR=\"$(TEST_DEBUG_DIR)\"
 
 endif HAVE_OBJCOPY_DEBUGLINK
 endif HAVE_ELF

without 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant