git.iko.soy/typeable/nixpkgs
on master help sign in
gdb: Look for .build-id files in NIX_DEBUG_INFO_DIRS

This allows us to provide a setup hook that makes debug outputs findable by gdb.

commit5b0915289894e5312b9137ca9759d1fc9ccbe25e authorEelco Dolstra <edolstra@gmail.com> dateFri 28 Jul 2017, 13:51 (9 years ago) parent07ab4d2
2 files changed+83
pkgs/development/tools/misc/gdb/debug-info-from-env.patch+81 pkgs/development/tools/misc/gdb/default.nix+2
pkgs/development/tools/misc/gdb/debug-info-from-env.patchnew file+81
@@ -0,0 +1,81 @@
1+Look up .build-id files relative to the directories in the
2+colon-separated environment variable NIX_DEBUG_INFO_DIRS, in addition
3+to the existing debug-file-directory setting.
4+
5+diff -ru --exclude '*gcore' --exclude '*pdtrace' gdb-8.0-orig/gdb/build-id.c gdb-8.0/gdb/build-id.c
6+--- gdb-8.0-orig/gdb/build-id.c 2017-06-04 17:51:26.000000000 +0200
7++++ gdb-8.0/gdb/build-id.c 2017-07-28 13:18:10.797375927 +0200
8+@@ -67,8 +67,8 @@
9+
10+ /* See build-id.h. */
11+
12+-gdb_bfd_ref_ptr
13+-build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
14++static gdb_bfd_ref_ptr
15++build_id_to_debug_bfd_in (const char *directories, size_t build_id_len, const bfd_byte *build_id)
16+ {
17+ char *link, *debugdir;
18+ VEC (char_ptr) *debugdir_vec;
19+@@ -78,7 +78,7 @@
20+ int alloc_len;
21+
22+ /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
23+- alloc_len = (strlen (debug_file_directory)
24++ alloc_len = (strlen (directories)
25+ + (sizeof "/.build-id/" - 1) + 1
26+ + 2 * build_id_len + (sizeof ".debug" - 1) + 1);
27+ link = (char *) alloca (alloc_len);
28+@@ -86,7 +86,7 @@
29+ /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
30+ cause "/.build-id/..." lookups. */
31+
32+- debugdir_vec = dirnames_to_char_ptr_vec (debug_file_directory);
33++ debugdir_vec = dirnames_to_char_ptr_vec (directories);
34+ back_to = make_cleanup_free_char_ptr_vec (debugdir_vec);
35+
36+ for (ix = 0; VEC_iterate (char_ptr, debugdir_vec, ix, debugdir); ++ix)
37+@@ -137,6 +137,30 @@
38+ return abfd;
39+ }
40+
41++gdb_bfd_ref_ptr
42++build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
43++{
44++ gdb_bfd_ref_ptr abfd = build_id_to_debug_bfd_in(debug_file_directory, build_id_len, build_id);
45++
46++ if (abfd != NULL)
47++ return abfd;
48++
49++ static int init = 0;
50++ static char *env_var;
51++ if (!init)
52++ {
53++ env_var = getenv("NIX_DEBUG_INFO_DIRS");
54++ init = 1;
55++ }
56++
57++ if (env_var)
58++ {
59++ abfd = build_id_to_debug_bfd_in(env_var, build_id_len, build_id);
60++ }
61++
62++ return abfd;
63++}
64++
65+ /* See build-id.h. */
66+
67+ char *
68+diff -ru --exclude '*gcore' --exclude '*pdtrace' gdb-8.0-orig/gdb/symfile.c gdb-8.0/gdb/symfile.c
69+--- gdb-8.0-orig/gdb/symfile.c 2017-06-04 17:51:27.000000000 +0200
70++++ gdb-8.0/gdb/symfile.c 2017-07-28 12:54:05.401586174 +0200
71+@@ -1415,8 +1415,8 @@
72+ struct cmd_list_element *c, const char *value)
73+ {
74+ fprintf_filtered (file,
75+- _("The directory where separate debug "
76+- "symbols are searched for is \"%s\".\n"),
77++ _("The directories where separate debug "
78++ "symbols are searched for are \"%s\".\n"),
79+ value);
80+ }
81+
pkgs/development/tools/misc/gdb/default.nix+2
@@ -32,6 +32,8 @@ stdenv.mkDerivation rec {
3232 sha256 = "1vplyf8v70yn0rdqjx6awl9nmfbwaj5ynwwjxwa71rhp97z4z8pn";
3333 };
3434
35+ patches = [ ./debug-info-from-env.patch ];
36+
3537 nativeBuildInputs = [ pkgconfig texinfo perl ]
3638 # TODO(@Ericson2314) not sure if should be host or target
3739 ++ stdenv.lib.optional targetPlatform.isHurd mig;