tests: Add Makefile to build debug-info test artifacts
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 9 May 2019 19:32:26 +0000 (19:32 +0000)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 6 Jun 2019 19:04:56 +0000 (15:04 -0400)
The current documentation on building the debug info test artifacts is
missing some important details, add a Makefile to make the process more
repoducible.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Change-Id: I188ce56bbe4d446e8959e18d2f4c50b8a82a4cb0
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1343
Tested-by: jenkins
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
tests/debug-info-data/Makefile [new file with mode: 0644]
tests/debug-info-data/README.md

diff --git a/tests/debug-info-data/Makefile b/tests/debug-info-data/Makefile
new file mode 100644 (file)
index 0000000..2820805
--- /dev/null
@@ -0,0 +1,50 @@
+BUILD_ID_PREFIX=cd
+BUILD_ID_SUFFIX=d98cdd87f7fe64c13b6daad553987eafd40cbb
+BUILD_ID=$(BUILD_ID_PREFIX)$(BUILD_ID_SUFFIX)
+
+BUILD_DIR ?= build
+
+OBJS=$(BUILD_DIR)/dwarf_full/libhello_so \
+     $(BUILD_DIR)/elf_only/libhello_so \
+     $(BUILD_DIR)/build_id/libhello_so \
+     $(BUILD_DIR)/debug_link/libhello_so
+
+all: $(OBJS)
+
+%.o: %.c
+       $(CC) -gdwarf -fdebug-prefix-map=$(CURDIR)=. -fPIC -c -I. -o $@ $<
+
+# Master copy: ELF with DWARF and build-id
+$(BUILD_DIR)/dwarf_full/libhello_so: tp.o libhello.o
+       mkdir -p $(@D)
+       $(CC) -shared -gdwarf -llttng-ust -ldl -Wl,-soname,libhello.so -Wl,--build-id=0x$(BUILD_ID) -o $@ $^
+
+# ELF only, no debug symbols, no build-d
+$(BUILD_DIR)/elf_only/libhello_so: $(BUILD_DIR)/dwarf_full/libhello_so
+       mkdir -p $(@D)
+       objcopy -g $< $@.tmp
+       objcopy --remove-section=.note.gnu.build-id $@.tmp
+       mv $@.tmp $@
+
+# ELF with external build-id DWARF
+$(BUILD_DIR)/build_id/libhello_so: $(BUILD_DIR)/dwarf_full/libhello_so
+       mkdir -p $(@D)/.build-id/$(BUILD_ID_PREFIX)
+       objcopy --only-keep-debug $< $(@D)/.build-id/$(BUILD_ID_PREFIX)/$(BUILD_ID_SUFFIX).debug
+       objcopy -g $< $@
+
+# ELF with external debug link DWARF
+$(BUILD_DIR)/debug_link/libhello_so: $(BUILD_DIR)/dwarf_full/libhello_so
+       mkdir -p $(@D)
+       objcopy --remove-section=.note.gnu.build-id $< $@.tmp
+       objcopy --only-keep-debug $@.tmp $(@D)/libhello_so.debug
+       objcopy -g $@.tmp
+       cd $(@D) && objcopy --add-gnu-debuglink=libhello_so.debug $(@F).tmp
+       mv $@.tmp $@
+
+clean:
+       rm -f *.o
+
+dist-clean: clean
+       rm -rf $(BUILD_DIR)
+
+.PHONY: all clean dist-clean
index 1c45c505436514dd5f341eebd5a3e6a9e459e986..1912194a2c5d991bfab99e8c8e4fc4fcaf3194ce 100644 (file)
@@ -8,12 +8,12 @@ files used to generate them.
 
 The generated files are:
 
-* `libhello_so` (ELF and DWARF)
-* `libhello_elf_so` (ELF only)
-* `libhello_build_id_so` (ELF with separate DWARF via build ID)
-* `libhello_debug_link_so` (ELF with separate DWARF via debug link)
-* `libhello_debug_link_so.debug` (DWARF for debug link)
-* `.build-id/cd/d98cdd87f7fe64c13b6daad553987eafd40cbb.debug` (DWARF for build ID)
+* `ARCH/dwarf_full/libhello_so` (ELF and DWARF)
+* `ARCH/elf_only/libhello_so` (ELF only)
+* `ARCH/build_id/libhello_so` (ELF with separate DWARF via build ID)
+* `ARCH/build_id/.build-id/cd/d98cdd87f7fe64c13b6daad553987eafd40cbb.debug` (DWARF for build ID)
+* `ARCH/debug_link/libhello_so` (ELF with separate DWARF via debug link)
+* `ARCH/debug_link/libhello_so.debug` (DWARF for debug link)
 
 We use a suffix of "_so" instead of ".so" since some distributions
 build systems will consider ".so" files as artifacts from a previous
@@ -26,42 +26,42 @@ All files are generated from the four (4) following source files:
 * tp.c
 * tp.h
 
-The generated executables were built using a GNU toolchain on an
-x86_64 machine.
+The generated executables were built using a native GNU toolchain on either
+Ubuntu 16.04 or 18.04 depending on the architecture.
 
-To regenerate them, you can use follow these steps:
+To regenerate them, you can use the included Makefile or follow these steps:
 
-## ELF and DWARF
+## Generate the object files
 
-    $ gcc -g -fPIC -c -I. tp.c libhello.c
-    $ gcc -shared -g -llttng-ust -ldl -Wl,-soname,libhello.so -o libhello_so tp.o libhello.o
+    $ gcc -gdwarf -fdebug-prefix-map=$(pwd)=. -fPIC -c -I. tp.c libhello.c
+
+## Combined ELF and DWARF
+
+    $ build_id_prefix=cd
+    $ build_id_suffix=d98cdd87f7fe64c13b6daad553987eafd40cbb
+    $ build_id="$build_id_prefix$build_id_suffix"
+    $ mkdir dwarf_full
+    $ gcc -shared -g -llttng-ust -ldl -Wl,-soname,libhello.so -Wl,--build-id=0x$build_id -o dwarf_full/libhello_so tp.o libhello.o
 
 ## ELF only
 
-    $ gcc -fPIC -c -I. tp.c libhello.c
-    $ gcc -shared -llttng-ust -ldl -Wl,-soname,libhello_elf.so -o libhello_elf_so tp.o libhello.o
+    $ mkdir elf_only
+    $ objcopy -g dwarf_full/libhello_so elf_only/libhello_so
+    $ objcopy --remove-section=.note.gnu.build-id elf_only/libhello_so
 
 ## ELF and DWARF with Build ID
 
-    $ gcc -g -fPIC -c -I. tp.c libhello.c
-    $ gcc -shared -g -llttng-ust -ldl -Wl,-soname,libhello_build_id.so -Wl,--build-id=sha1 -o libhello_build_id_so tp.o libhello.o
-    $ mkdir -p .build-id/cd/
-    $ objcopy --only-keep-debug libhello_build_id_so .build-id/cd/d98cdd87f7fe64c13b6daad553987eafd40cbb.debug
-    $ strip -g libhello_build_id_so
-
-The build ID might not be the same once the executable is regenerated
-on your system, so adjust the values in the directory and file names
-accordingly. Refer to the GDB documentation for more information:
-https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
+    $ mkdir -p build_id/.build-id/$build_id_prefix
+    $ objcopy --only-keep-debug dwarf_full/libhello_so build_id/.build-id/$build_id_prefix/$build_id_suffix.debug
+    $ objcopy -g dwarf_full/libhello_so build_id/libhello_so
 
 ##  ELF and DWARF with Debug Link
 
-    $ gcc -g -fPIC -c -I. tp.c libhello.c
-    $ gcc -shared -g -llttng-ust -ldl -Wl,-soname,libhello_debug_link.so -o libhello_debug_link_so tp.o libhello.o
-
-    $ objcopy --only-keep-debug libhello_debug_link_so libhello_debug_link_so.debug
-    $ strip -g libhello_debug_link_so
-    $ objcopy --add-gnu-debuglink=libhello_debug_link_so.debug libhello_debug_link_so
+    $ mkdir debug_link
+    $ objcopy --remove-section=.note.gnu.build-id dwarf_full/libhello_so debug_link/libhello_so
+    $ objcopy --only-keep-debug debug_link/libhello_so debug_link/libhello_so.debug
+    $ objcopy -g debug_link/libhello_so
+    $ cd debug_link && objcopy --add-gnu-debuglink=libhello_so.debug libhello_so && cd ..
 
 
 Test program
This page took 0.027328 seconds and 4 git commands to generate.