Always pass false for exe in elf_add call.
authorAdrian Băcîrcea <adrian.bacircea@gmail.com>
Sun, 25 Oct 2015 15:53:33 +0000 (17:53 +0200)
committerMilian Wolff <milian.wolff@kdab.com>
Mon, 26 Oct 2015 10:17:24 +0000 (11:17 +0100)
Basically, if you pass the isExe flag to elf_add, libbacktrace will
see that it's an ET_DYN executable which means that the sections
can be relocated on load so it will defer to dl_iterate_phdr to get
the real addresses. It will do that only when you call
backtrace_pcinfo which, behind the scenes, ends up calling
backtrace_initialize and that will do the dl_iterate_phdr for the
executable which is wrong since the executable we want to get the
symbols on is not the current one (which is heaptrack_interpret) and
we already get the base addresses correctly from the main process
through the pipe. So there's no need to ever pass isExe = true.

heaptrack_interpret.cpp

index 931d81b..b018eb0 100644 (file)
@@ -274,7 +274,7 @@ struct AccumulatedTraceData
      * Prevent the same file from being initialized multiple times.
      * This drastically cuts the memory consumption down
      */
-    backtrace_state* findBacktraceState(const string& fileName, uintptr_t addressStart, bool isExe)
+    backtrace_state* findBacktraceState(const string& fileName, uintptr_t addressStart)
     {
         if (boost::algorithm::starts_with(fileName, "linux-vdso.so")) {
             // prevent warning, since this will always fail
@@ -306,7 +306,7 @@ struct AccumulatedTraceData
                 int foundSym = 0;
                 int foundDwarf = 0;
                 auto ret = elf_add(state, descriptor, addressStart, errorHandler, &data,
-                                   &state->fileline_fn, &foundSym, &foundDwarf, isExe);
+                                   &state->fileline_fn, &foundSym, &foundDwarf, false);
                 if (ret && foundSym) {
                     state->syminfo_fn = &elf_syminfo;
                 }
@@ -351,8 +351,7 @@ int main(int /*argc*/, char** /*argv*/)
             if (fileName == "-") {
                 data.clearModules();
             } else {
-                const bool isExe = (fileName == "x");
-                if (isExe) {
+                if (fileName == "x") {
                     fileName = exe;
                 }
                 const auto moduleIndex = data.intern(fileName);
@@ -361,7 +360,7 @@ int main(int /*argc*/, char** /*argv*/)
                     cerr << "failed to parse line: " << reader.line() << endl;
                     return 1;
                 }
-                auto state = data.findBacktraceState(fileName, addressStart, isExe);
+                auto state = data.findBacktraceState(fileName, addressStart);
                 uintptr_t vAddr = 0;
                 uintptr_t memSize = 0;
                 while ((reader >> vAddr) && (reader >> memSize)) {