valgrind: Search NIX_DEBUG_INFO_DIRS for debug info

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg
2022-02-16 23:15:10 -08:00
parent 23d785aa6f
commit be85a55485
2 changed files with 37 additions and 0 deletions
@@ -0,0 +1,31 @@
diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c
index c586e3f33..e3bb1717f 100644
--- a/coregrind/m_debuginfo/readelf.c
+++ b/coregrind/m_debuginfo/readelf.c
@@ -1508,13 +1508,25 @@ DiImage* find_debug_file( struct _DebugInfo* di,
HChar* debugpath = NULL; /* where we found it */
if (buildid != NULL) {
+ const HChar *dir = VG_(getenv)("NIX_DEBUG_INFO_DIRS");
debugpath = ML_(dinfo_zalloc)("di.fdf.1",
- VG_(strlen)(buildid) + 33);
+ VG_(strlen)(buildid) + 33 +
+ (dir ? VG_(strlen)(dir) : 0));
VG_(sprintf)(debugpath, "/usr/lib/debug/.build-id/%c%c/%s.debug",
buildid[0], buildid[1], buildid + 2);
dimg = open_debug_file(debugpath, buildid, 0, rel_ok, NULL);
+
+ while (!dimg && dir) {
+ const HChar *sep = VG_(strchr)(dir, ':');
+ Int size = sep ? sep - dir : VG_(strlen)(dir);
+ VG_(sprintf)(debugpath, "%.*s/.build-id/%c%c/%s.debug",
+ size, dir, buildid[0], buildid[1], buildid + 2);
+ dimg = open_debug_file(debugpath, buildid, 0, rel_ok, NULL);
+ dir = sep ? sep + 1 : NULL;
+ }
+
if (!dimg) {
ML_(dinfo_free)(debugpath);
debugpath = NULL;
@@ -1,6 +1,7 @@
{ lib, stdenv, fetchurl, fetchpatch
, autoreconfHook, perl
, gdb, cctools, xnu, bootstrap_cmds
, setupDebugInfoDirs
}:
stdenv.mkDerivation rec {
@@ -19,6 +20,7 @@ stdenv.mkDerivation rec {
url = "https://bugsfiles.kde.org/attachment.cgi?id=143535";
sha256 = "036zyk30rixjvpylw3c7n171n4gpn6zcp7h6ya2dz4h5r478l9i6";
})
./debug-info-from-env.patch
];
outputs = [ "out" "dev" "man" "doc" ];
@@ -32,6 +34,10 @@ stdenv.mkDerivation rec {
# Perl is also a native build input.
nativeBuildInputs = [ autoreconfHook perl ];
# Not propagatedNativeBuildInputs because of
# https://github.com/NixOS/nixpkgs/issues/64992.
propagatedBuildInputs = [ setupDebugInfoDirs ];
enableParallelBuilding = true;
separateDebugInfo = stdenv.isLinux;