From 7d0403032250c8985ae99a96af7bcd9190ad654b Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 13 Jan 2018 14:33:50 +0100 Subject: [PATCH] Additional fix for gnu debug alt file resolving. Also handle the case where the symlink itself contains a relative path. Then we need to add the symlink dir before it. https://bugs.kde.org/show_bug.cgi?id=387773 --- coregrind/m_debuginfo/readelf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c index c19ff212b7..70c28e6292 100644 --- a/coregrind/m_debuginfo/readelf.c +++ b/coregrind/m_debuginfo/readelf.c @@ -1582,6 +1582,24 @@ static HChar* readlink_path (const HChar *path) return NULL; } + if (buf[0] == '/') + return buf; + + /* Relative path, add link dir. */ + HChar *linkdirptr; + SizeT linkdir_len = VG_(strlen)(path); + if ((linkdirptr = VG_(strrchr)(path, '/')) != NULL) + linkdir_len -= VG_(strlen)(linkdirptr + 1); + + SizeT buflen = VG_(strlen)(buf); + SizeT needed = linkdir_len + buflen + 1; + if (bufsiz < needed) + buf = ML_(dinfo_realloc)("readlink_path.linkdir", buf, needed); + + VG_(memmove)(buf + linkdir_len, buf, buflen); + VG_(memcpy)(buf, path, linkdir_len); + buf[needed - 1] = '\0'; + return buf; } -- 2.47.2