Skip to content

Commit

Permalink
uftrace: fix symbol provider to not fix false negatives
Browse files Browse the repository at this point in the history
The symbol provider now returns null when it cannot resolve rather
than returning a string address. This allows chaining of symbol
resolvers.

It is also made into a static class so that it is easier to debug.

Signed-off-by: Matthew Khouzam <[email protected]>
Change-Id: Ifdfb7877f623c5e96feae0138308544ad4c0ab81
  • Loading branch information
MatthewKhouzam committed Aug 28, 2024
1 parent 84c3caf commit 992d620
Showing 1 changed file with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class Uftrace extends TmfTrace implements ITmfPropertiesProvider,

private long fSize;

private final ISymbolProvider fSymbolProvider = new UfTraceSymbolProvider();
private final ISymbolProvider fSymbolProvider = new UfTraceSymbolProvider(this);

private final @NonNull TidAspect fTidAspect = new TidAspect();
private final @NonNull PidAspect fPidAspect = new PidAspect();
Expand Down Expand Up @@ -222,10 +222,10 @@ public void initTrace(IResource resource, String path, Class<? extends ITmfEvent
} else if (name.endsWith(".map")) { //$NON-NLS-1$
MapParser create = MapParser.create(child);
if (create != null) {
fMap.put(create.getSessionId(), create);
getMap().put(create.getSessionId(), create);
}
} else if (name.endsWith(".sym")) { //$NON-NLS-1$
fSyms.put(name.substring(0, name.length() - 4), SymParser.parse(child));
getSyms().put(name.substring(0, name.length() - 4), SymParser.parse(child));
} else if (name.equals("task.txt")) { //$NON-NLS-1$
fTasks = new TaskParser(child);
} else if (name.equals("info")) { //$NON-NLS-1$
Expand Down Expand Up @@ -372,7 +372,7 @@ public final class PidAspect extends LinuxPidAspect {
if (event.getContent().getValue() instanceof DatEvent) {
DatEvent datEvent = (DatEvent) event.getContent().getValue();
int tid = datEvent.getTid();
return fTasks.getPid(tid);
return getTasks().getPid(tid);
}
return null;
}
Expand All @@ -390,7 +390,7 @@ public final class ExecAspect extends ProcessNameAspect {
if (event.getContent().getValue() instanceof DatEvent) {
DatEvent datEvent = (DatEvent) event.getContent().getValue();
int tid = datEvent.getTid();
return fTasks.getExecName(tid);
return getTasks().getExecName(tid);
}
return null;
}
Expand Down Expand Up @@ -468,37 +468,58 @@ public TaskParser getTasks() {
return fTidAspect;
}

/**
* @return the syms
*/
private Map<String, SymParser> getSyms() {
return fSyms;
}

/**
* @return the map
*/
private Map<Long, MapParser> getMap() {
return fMap;
}

/**
* overly complicated, should clean up
*
* @author Matthew Khouzam
*
*/
private class UfTraceSymbolProvider implements ISymbolProvider {
private static class UfTraceSymbolProvider implements ISymbolProvider {

private Uftrace fTrace;

public UfTraceSymbolProvider(Uftrace trace) {
fTrace = trace;
}

@Override
public TmfResolvedSymbol getSymbol(int tid, long timestamp, long address) {
String execName = fTasks.getExecName(tid);
String execName = fTrace.getTasks().getExecName(tid);
if (execName == null) {
return new TmfResolvedSymbol(address, "0x" + Long.toHexString(address)); //$NON-NLS-1$
return null;
}
Long session = fTasks.getSessName(tid);
Long session = fTrace.getTasks().getSessName(tid);
if (session == null) {
return new TmfResolvedSymbol(address, "0x" + Long.toHexString(address)); //$NON-NLS-1$
return null;
}
MapParser mapParser = fMap.get(session);
MapParser mapParser = fTrace.getMap().get(session);
if (mapParser == null) {
return new TmfResolvedSymbol(address, "0x" + Long.toHexString(address)); //$NON-NLS-1$
return null;
}
Entry<Long, MapEntry> key = mapParser.getData().floorEntry(address);
if (key == null) {
return new TmfResolvedSymbol(address, "0x" + Long.toHexString(address)); //$NON-NLS-1$
return null;
}
long offset = address - key.getValue().getAddrLow();
String pathName = key.getValue().getPathName();
String substring = pathName.substring(pathName.lastIndexOf(File.separator) + 1);
SymParser sym = fSyms.get(substring);
SymParser sym = fTrace.getSyms().get(substring);
if (sym == null) {
return new TmfResolvedSymbol(address, pathName + ":0x" + Long.toHexString(address)); //$NON-NLS-1$
return null;
}
Entry<Long, Symbol> floorEntry = sym.getMap().floorEntry(offset);
if (floorEntry != null) {
Expand All @@ -508,13 +529,13 @@ public TmfResolvedSymbol getSymbol(int tid, long timestamp, long address) {
return new TmfResolvedSymbol(address, name);
}
}
return new TmfResolvedSymbol(address, "0x" + Long.toHexString(address)); //$NON-NLS-1$
return null;
}

/* needed for ISymbolProvider */
@Override
public @NonNull ITmfTrace getTrace() {
return (ITmfTrace) this;
return fTrace;
}

@Override
Expand All @@ -524,7 +545,7 @@ public void loadConfiguration(@Nullable IProgressMonitor monitor) {

@Override
public @Nullable TmfResolvedSymbol getSymbol(long address) {
return getSymbol(Iterables.getFirst(fTasks.getTids(), -1), 0, address);
return getSymbol(Iterables.getFirst(fTrace.getTasks().getTids(), -1), 0, address);
}

}
Expand Down

0 comments on commit 992d620

Please sign in to comment.