lttng: Handle unknown line numbers in addr2line output
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Thu, 5 May 2016 02:54:11 +0000 (22:54 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Mon, 9 May 2016 20:11:14 +0000 (16:11 -0400)
addr2line can return "filename.c:?" when it knows a file name
but not its number. Do not attempt to parse "?" as a Long, you
will fail miserably.

Also change the odd/even flip to the start of the loop: the
presence of "continue" statements could skip that operation.

Change-Id: Ia685e91833c6c472decfd3fd21acf7ad70d1ae34
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/72118
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java

index 1d07f566fe7c7cd15e6ff26d7217f6a235ac1130..c2fe8d4e1107a0dbda560881c8290d2503b93bbe 100644 (file)
@@ -149,9 +149,12 @@ public final class FileOffsetMapper {
          * When passing the -f flag, the output alternates between function
          * names and file/line location.
          */
-        boolean oddLine = true;
+        boolean oddLine = false; // We flip at the start, first loop will be odd
         String currentFunctionName = null;
         for (String outputLine : output) {
+            /* Flip the boolean for the following line */
+            oddLine = !oddLine;
+
             // 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$
 
@@ -165,13 +168,18 @@ public final class FileOffsetMapper {
                 if (fileName.equals("??")) { //$NON-NLS-1$
                     continue;
                 }
-                long lineNumber = Long.parseLong(elems[1]);
-
-                callsites.add(new SourceCallsite(fileName, currentFunctionName, lineNumber));
+                try {
+                    long lineNumber = Long.parseLong(elems[1]);
+                    callsites.add(new SourceCallsite(fileName, currentFunctionName, lineNumber));
+
+                } catch (NumberFormatException e) {
+                    /*
+                     * Probably a '?' output, meaning unknown line number.
+                     * Ignore this entry.
+                     */
+                    continue;
+                }
             }
-
-            /* Flip the boolean for the following line */
-            oddLine = !oddLine;
         }
 
         return callsites;
This page took 0.0250860000000001 seconds and 5 git commands to generate.