callstack: Add PID to called functions

The function created from the segment store methods should also contain
the PID, since this data is necessary to resolve the function name.

Also, the name of a function now tries to resolve the symbol instead of
returning the symbol address as a string.

Change-Id: I2d8a15a84470e86b688710dd598c1a4c2695e6cf
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/146754
Tested-by: CI Bot
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/146824
diff --git a/callstack/org.eclipse.tracecompass.incubator.callstack.core/src/org/eclipse/tracecompass/incubator/callstack/core/instrumented/statesystem/CallStackSeries.java b/callstack/org.eclipse.tracecompass.incubator.callstack.core/src/org/eclipse/tracecompass/incubator/callstack/core/instrumented/statesystem/CallStackSeries.java
index f22ee4a..466fb67 100644
--- a/callstack/org.eclipse.tracecompass.incubator.callstack.core/src/org/eclipse/tracecompass/incubator/callstack/core/instrumented/statesystem/CallStackSeries.java
+++ b/callstack/org.eclipse.tracecompass.incubator.callstack.core/src/org/eclipse/tracecompass/incubator/callstack/core/instrumented/statesystem/CallStackSeries.java
@@ -649,7 +649,8 @@
     @Override
     public Iterable<ISegment> getIntersectingElements(long start, long end) {
         ITmfStateSystem stateSystem = fRootGroup.getStateSystem();
-        long startTime = Math.max(start - 1, stateSystem.getStartTime());
+        // Start can be Long.MIN_VALUE, we need to avoid underflow
+        long startTime = Math.max(Math.max(1, start) - 1, stateSystem.getStartTime());
         long endTime = Math.min(end, stateSystem.getCurrentEndTime());
         if (startTime > endTime) {
             return Collections.emptyList();
@@ -664,10 +665,14 @@
                     throw new NullPointerException("The quark was in that map in the first place, there must be a callstack to go with it!"); //$NON-NLS-1$
                 }
                 HostThread hostThread = callstack.getHostThread(interval.getStartTime());
+
+                int pid = -1 ;
                 if (hostThread == null) {
                     hostThread = new HostThread(StringUtils.EMPTY, IHostModel.UNKNOWN_TID);
+                } else {
+                    pid = ModelManager.getModelFor(hostThread.getHost()).getProcessId(hostThread.getTid(), interval.getStartTime());
                 }
-                return CalledFunctionFactory.create(interval.getStartTime(), interval.getEndTime() + 1, interval.getValue(), -1, hostThread.getTid(),
+                return CalledFunctionFactory.create(interval.getStartTime(), interval.getEndTime() + 1, interval.getValue(), pid, hostThread.getTid(),
                         null, ModelManager.getModelFor(hostThread.getHost()));
             };
             return Iterables.transform(query2d, fct);
diff --git a/callstack/org.eclipse.tracecompass.incubator.callstack.core/src/org/eclipse/tracecompass/incubator/internal/callstack/core/instrumented/callgraph/AbstractCalledFunction.java b/callstack/org.eclipse.tracecompass.incubator.callstack.core/src/org/eclipse/tracecompass/incubator/internal/callstack/core/instrumented/callgraph/AbstractCalledFunction.java
index 84b1df9..d9eef31 100644
--- a/callstack/org.eclipse.tracecompass.incubator.callstack.core/src/org/eclipse/tracecompass/incubator/internal/callstack/core/instrumented/callgraph/AbstractCalledFunction.java
+++ b/callstack/org.eclipse.tracecompass.incubator.callstack.core/src/org/eclipse/tracecompass/incubator/internal/callstack/core/instrumented/callgraph/AbstractCalledFunction.java
@@ -17,6 +17,7 @@
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.incubator.analysis.core.model.IHostModel;
+import org.eclipse.tracecompass.incubator.callstack.core.callgraph.SymbolAspect;
 import org.eclipse.tracecompass.incubator.callstack.core.instrumented.ICalledFunction;
 import org.eclipse.tracecompass.segmentstore.core.ISegment;
 import org.eclipse.tracecompass.segmentstore.core.SegmentComparators;
@@ -91,7 +92,7 @@
 
     @Override
     public String getName() {
-        return NonNullUtils.nullToEmptyString(getSymbol().toString());
+        return NonNullUtils.nullToEmptyString(SymbolAspect.SYMBOL_ASPECT.resolve(this));
     }
 
     /**