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());
}
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) {
/*
*/
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);
}
/**
* 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$
}