From 1da28b13e6d9d7d5dd4f7b83ae6bc765417c0189 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Wed, 4 May 2016 22:54:11 -0400 Subject: [PATCH] lttng: Handle unknown line numbers in addr2line output 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 Reviewed-on: https://git.eclipse.org/r/72118 Reviewed-by: Hudson CI Reviewed-by: Marc-Andre Laperle Tested-by: Marc-Andre Laperle --- .../analysis/debuginfo/FileOffsetMapper.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java index 1d07f566fe..c2fe8d4e11 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/debuginfo/FileOffsetMapper.java @@ -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; -- 2.34.1