lttng.ust: Implement a symbol provider for LTTng-UST traces
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / analysis / debuginfo / UstDebugInfoBinaryAspect.java
index c2fc6206bbf8dc6ea841d2fe1149d32672bb4746..4bb345e2dd3310f283c8f4ced7a3e24695057350 100644 (file)
@@ -53,8 +53,9 @@ public class UstDebugInfoBinaryAspect implements ITmfEventAspect<BinaryCallsite>
         if (!(event.getTrace() instanceof LttngUstTrace)) {
             return null;
         }
+        LttngUstTrace trace = (LttngUstTrace) event.getTrace();
 
-        ILttngUstEventLayout layout = ((LttngUstTrace) event.getTrace()).getEventLayout();
+        ILttngUstEventLayout layout = trace.getEventLayout();
 
         /* We need both the vpid and ip contexts */
         ITmfEventField vpidField = event.getContent().getField(layout.contextVpid());
@@ -64,13 +65,33 @@ public class UstDebugInfoBinaryAspect implements ITmfEventAspect<BinaryCallsite>
         }
         Long vpid = (Long) vpidField.getValue();
         Long ip = (Long) ipField.getValue();
+        long ts = event.getTimestamp().toNanos();
 
+        return getBinaryCallsite(trace, vpid.intValue(), ts, ip.longValue());
+    }
+
+    /**
+     * Get the binary callsite (which means binary file and offset in this file)
+     * corresponding to the given instruction pointer, for the given PID and
+     * timetamp.
+     *
+     * @param trace
+     *            The trace, from which we will get the debug info analysis
+     * @param pid
+     *            The PID for which we want the symbol
+     * @param ts
+     *            The timestamp of the query
+     * @param ip
+     *            The instruction pointer address
+     * @return The {@link BinaryCallsite} object with the relevant information
+     */
+    public static @Nullable BinaryCallsite getBinaryCallsite(LttngUstTrace trace, int pid, long ts, long ip) {
         /*
          * First match the IP to the correct binary or library, by using the
          * UstDebugInfoAnalysis.
          */
         UstDebugInfoAnalysisModule module =
-                TmfTraceUtils.getAnalysisModuleOfClass(event.getTrace(),
+                TmfTraceUtils.getAnalysisModuleOfClass(trace,
                         UstDebugInfoAnalysisModule.class, UstDebugInfoAnalysisModule.ID);
         if (module == null) {
             /*
@@ -79,27 +100,29 @@ public class UstDebugInfoBinaryAspect implements ITmfEventAspect<BinaryCallsite>
              */
             return null;
         }
-        long ts = event.getTimestamp().getValue();
-        UstDebugInfoLoadedBinaryFile file = module.getMatchingFile(ts, vpid, ip);
+        UstDebugInfoLoadedBinaryFile file = module.getMatchingFile(ts, pid, ip);
         if (file == null) {
             return null;
         }
 
+        /* Apply the path prefix defined by the trace, if any */
+        String fullPath = (trace.getSymbolProviderConfig().getActualRootDirPath() + file.getFilePath());
+
         long offset;
-        if (isPIC(file)) {
-            offset = (ip.longValue() - file.getBaseAddress());
+        if (isPIC(fullPath)) {
+            offset = (ip - file.getBaseAddress());
         } else {
             /*
              * In the case of the object being the main binary (loaded at a very
              * low address), we must pass the actual ip address to addr2line.
              */
-            offset = ip.longValue();
+            offset = ip;
         }
 
         // TODO If the binary is present on the current file system, we could
         // try to get the symbol name from it.
 
-        return new BinaryCallsite(file.getFilePath(), EMPTY_STRING, offset);
+        return new BinaryCallsite(fullPath, EMPTY_STRING, offset);
     }
 
     /**
@@ -107,13 +130,12 @@ public class UstDebugInfoBinaryAspect implements ITmfEventAspect<BinaryCallsite>
      * or not. This indicates if addr2line considers the addresses as absolute
      * addresses or as offsets.
      */
-    private static boolean isPIC(UstDebugInfoLoadedBinaryFile file) {
+    private static boolean isPIC(String filePath) {
         /*
          * Ghetto binary/library identification for now. It would be possible to
          * parse the ELF binary to check if it is position-independent
          * (-fPIC/-fPIE) or not.
          */
-        String filePath = file.getFilePath();
         return (filePath.endsWith(".so") || filePath.contains(".so.")); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
This page took 0.042216 seconds and 5 git commands to generate.