lttng.ust: Retrieve the function name when calling addr2line
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Tue, 5 Apr 2016 22:19:51 +0000 (18:19 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Wed, 20 Apr 2016 22:34:35 +0000 (18:34 -0400)
Add the -f flag to also query function/symbol names. This will
allow us to populate the "function name" field of the generated
callsite objects, which in turn will populate the Callstack View
appropriately.

Also pass the -C flag, which demangles C++ function names, without
apparantly affecting native names.

Change-Id: Ife6e8581347ab2f94558e258dc350a4c1b04c3fa
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/69971
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Hudson CI
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java

index 838fa727384df6cd2f2c66f373215b87b0c48f30..26c01fc35756ab13a18f54208e59142076895c5b 100644 (file)
@@ -59,27 +59,42 @@ public final class FileOffsetMapper {
     private static @Nullable Iterable<TmfCallsite> getCallsiteFromOffsetWithAddr2line(File file, long offset) {
         List<TmfCallsite> callsites = new LinkedList<>();
 
-        // FIXME Could eventually use CDT's Addr2line class once it imlements --inlines
+        // FIXME Could eventually use CDT's Addr2line class once it implements --inlines
         List<String> output = getOutputFromCommand(Arrays.asList(
-                ADDR2LINE_EXECUTABLE, "-i", "-e", file.toString(), "0x" + Long.toHexString(offset)));  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+                ADDR2LINE_EXECUTABLE, "-i", "-f", "-C", "-e", file.toString(), "0x" + Long.toHexString(offset)));  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
 
         if (output == null) {
             /* Command returned an error */
             return null;
         }
 
+        /*
+         * When passing the -f flag, the output alternates between function
+         * names and file/line location.
+         */
+        boolean oddLine = true;
+        String currentFunctionName = null;
         for (String outputLine : output) {
             // Remove discriminator part, for example: /build/buildd/glibc-2.21/elf/dl-object.c:78 (discriminator 8)
             outputLine = outputLine.replaceFirst(DISCRIMINATOR, "").trim(); //$NON-NLS-1$
 
-            String[] elems = outputLine.split(":"); //$NON-NLS-1$
-            String fileName = elems[0];
-            if (fileName.equals("??")) { //$NON-NLS-1$
-                continue;
+            if (oddLine) {
+                /* This is a line indicating the function name */
+                currentFunctionName = outputLine;
+            } else {
+                /* This is a line indicating a call site */
+                String[] elems = outputLine.split(":"); //$NON-NLS-1$
+                String fileName = elems[0];
+                if (fileName.equals("??")) { //$NON-NLS-1$
+                    continue;
+                }
+                long lineNumber = Long.parseLong(elems[1]);
+
+                callsites.add(new TmfCallsite(fileName, currentFunctionName, lineNumber));
             }
-            long lineNumber = Long.parseLong(elems[1]);
 
-            callsites.add(new TmfCallsite(fileName, null, lineNumber));
+            /* Flip the boolean for the following line */
+            oddLine = !oddLine;
         }
 
         return callsites;
This page took 0.02525 seconds and 5 git commands to generate.