traceEvent: Pop up to last function in stack with name

When a stack has elements of the same name and there is an end event, it
should pop up to the deepest element in the stack with that name, not
the first one.

Change-Id: Id33a37bcb4719d3b2dd32189454ffd3b6a8ca6ae
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/166756
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
diff --git a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/analysis/callstack/TraceEventCallStackProvider.java b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/analysis/callstack/TraceEventCallStackProvider.java
index e434422..696d41a 100644
--- a/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/analysis/callstack/TraceEventCallStackProvider.java
+++ b/tracetypes/org.eclipse.tracecompass.incubator.traceevent.core/src/org/eclipse/tracecompass/incubator/internal/traceevent/core/analysis/callstack/TraceEventCallStackProvider.java
@@ -513,7 +513,7 @@
             int quark = ss.getQuarkAbsoluteAndAdd(PROCESSES, pName, threadName, InstrumentedCallStackAnalysis.CALL_STACK);
             // The function to end is not necessarily the tip of the stack. Unstack up to function name
             List<Object> callStack = getCallStack(ss, quark);
-            int indexOf = callStack.indexOf(functionExitName);
+            int indexOf = callStack.lastIndexOf(functionExitName);
             // Function not found, just unstack the last one?
             if (indexOf < 0) {
                 if (functionExitName.equals(TraceEventField.UNKNOWN_EXIT_EVENT) || functionExitName.equals(TraceEventField.UNKNOWN_DURATION_EXIT_EVENT)) {