1 From de122af5382d8017cae63bdee946206c6c6c23ab Mon Sep 17 00:00:00 2001
2 From: Jan Tojnar <jtojnar@gmail.com>
3 Date: Sat, 24 Dec 2022 20:19:27 +0100
4 Subject: [PATCH 3/4] libbacktrace: Support multiple build id directories
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 gdb supports multiple debug directories separated by colons:
10 https://github.com/bminor/binutils-gdb/blob/fcbfb25dcca625a7f999ec51d48b6fc3a32123c3/gdb/build-id.c#L136-L142
12 This is useful for example when using dwarffs in addition
13 to debug data installed using distribution’s package manager.
15 elf.c | 57 ++++++++++++++++++++++++++++++++++++---------------------
16 1 file changed, 36 insertions(+), 21 deletions(-)
18 diff --git a/elf.c b/elf.c
19 index 8b1189c..65c647a 100644
22 @@ -865,12 +865,12 @@ elf_readlink (struct backtrace_state *state, const char *filename,
23 when the build ID is known is in /usr/lib/debug/.build-id. */
26 -elf_open_debugfile_by_buildid (struct backtrace_state *state,
27 +elf_open_debugfile_by_buildid (const char * const prefix,
28 + struct backtrace_state *state,
29 const char *buildid_data, size_t buildid_size,
30 backtrace_error_callback error_callback,
33 - const char * const prefix = SYSTEM_DEBUG_DIR BUILD_ID_DIR;
34 const size_t prefix_len = strlen (prefix);
35 const char * const suffix = ".debug";
36 const size_t suffix_len = strlen (suffix);
37 @@ -6936,27 +6936,42 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
38 if (buildid_data != NULL)
41 + char debug_directories[strlen(SYSTEM_DEBUG_DIR) + 1];
44 - d = elf_open_debugfile_by_buildid (state, buildid_data, buildid_size,
45 - error_callback, data);
49 + strcpy(debug_directories, SYSTEM_DEBUG_DIR);
51 - elf_release_view (state, &buildid_view, error_callback, data);
52 - if (debuglink_view_valid)
53 - elf_release_view (state, &debuglink_view, error_callback, data);
54 - if (debugaltlink_view_valid)
55 - elf_release_view (state, &debugaltlink_view, error_callback, data);
56 - ret = elf_add (state, "", d, NULL, 0, base_address, error_callback,
57 - data, fileline_fn, found_sym, found_dwarf, NULL, 0,
60 - backtrace_close (d, error_callback, data);
61 - else if (descriptor >= 0)
62 - backtrace_close (descriptor, error_callback, data);
65 + debug_dir = strtok (debug_directories, ":");
66 + while (debug_dir != NULL)
68 + char prefix[strlen(debug_dir) + strlen(BUILD_ID_DIR) + 1];
69 + strcpy(prefix, debug_dir);
70 + strcat(prefix, BUILD_ID_DIR);
72 + d = elf_open_debugfile_by_buildid (prefix, state, buildid_data, buildid_size,
73 + error_callback, data);
79 + elf_release_view (state, &buildid_view, error_callback, data);
80 + if (debuglink_view_valid)
81 + elf_release_view (state, &debuglink_view, error_callback, data);
82 + if (debugaltlink_view_valid)
83 + elf_release_view (state, &debugaltlink_view, error_callback, data);
84 + ret = elf_add (state, "", d, NULL, 0, base_address, error_callback,
85 + data, fileline_fn, found_sym, found_dwarf, NULL, 0,
88 + backtrace_close (d, error_callback, data);
89 + else if (descriptor >= 0)
90 + backtrace_close (descriptor, error_callback, data);
94 + debug_dir = strtok (NULL, ":");
98 if (buildid_view_valid)