Skip to content

Commit

Permalink
[FTB] Add line_no to trace parsing exception.
Browse files Browse the repository at this point in the history
This allows callers to cut the trace at this line in case the error
buffer is unreliable.
  • Loading branch information
jschwartzentruber committed Nov 15, 2023
1 parent 53a8dc5 commit 329149b
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions FTB/Signatures/CrashInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ def int64(val):
return val


class TraceParsingError(RuntimeError):
__slots__ = ("line_no",)

def __init__(self, *args, **kwds):
self.line_no = kwds.pop("line_no")
super().__init__(*args, **kwds)


class CrashInfo(metaclass=ABCMeta):
"""
Abstract base class that provides a method to instantiate the right sub class.
Expand Down Expand Up @@ -681,7 +689,7 @@ def __init__(self, stdout, stderr, configuration, crashData=None):

expectedIndex = 0
reportFound = False
for traceLine in asanOutput:
for line_no, traceLine in enumerate(asanOutput):
if not reportFound or self.crashAddress is None:
match = re.search(asanCrashAddressPattern, traceLine)
if match is not None:
Expand Down Expand Up @@ -712,9 +720,10 @@ def __init__(self, stdout, stderr, configuration, crashData=None):
expectedIndex = 0

if not expectedIndex == index:
raise RuntimeError(
raise TraceParsingError(
f"Fatal error parsing ASan trace (Index mismatch, got index {index}"
f" but expected {expectedIndex})"
f" but expected {expectedIndex})",
line_no=line_no,
)

component = None
Expand Down Expand Up @@ -885,7 +894,7 @@ def __init__(self, stdout, stderr, configuration, crashData=None):
lsanPatternSeen = False

expectedIndex = 0
for traceLine in lsanOutput:
for line_no, traceLine in enumerate(lsanOutput):
if not lsanErrorPattern:
if lsanErrorPattern in traceLine:
lsanPatternSeen = True
Expand All @@ -896,9 +905,10 @@ def __init__(self, stdout, stderr, configuration, crashData=None):
continue

if expectedIndex != index:
raise RuntimeError(
raise TraceParsingError(
f"Fatal error parsing LSan trace (Index mismatch, got index {index}"
f" but expected {expectedIndex})"
f" but expected {expectedIndex})",
line_no=line_no,
)

component = None
Expand Down Expand Up @@ -972,7 +982,7 @@ def __init__(self, stdout, stderr, configuration, crashData=None):
ubsanPatternSeen = False

expectedIndex = 0
for traceLine in ubsanOutput:
for line_no, traceLine in enumerate(ubsanOutput):
if not ubsanPatternSeen:
if re.search(ubsanErrorPattern, traceLine) is not None:
ubsanPatternSeen = True
Expand All @@ -983,9 +993,10 @@ def __init__(self, stdout, stderr, configuration, crashData=None):
continue

if expectedIndex != index:
raise RuntimeError(
"Fatal error parsing UBSan trace (Index mismatch, got index "
f"{index} but expected {expectedIndex})"
raise TraceParsingError(
f"Fatal error parsing UBSan trace (Index mismatch, got index "
f"{index} but expected {expectedIndex})",
line_no=line_no,
)

component = None
Expand Down Expand Up @@ -1073,7 +1084,7 @@ def __init__(self, stdout, stderr, configuration, crashData=None):

pastFrames = False

for traceLine in gdbOutput:
for line_no, traceLine in enumerate(gdbOutput):
# Do a very simple check for a frame number in combination with pending
# buffer content. If we detect this constellation, then it's highly likely
# that we have a valid trace line but no pattern that fits it. We need
Expand Down Expand Up @@ -1154,7 +1165,10 @@ def __init__(self, stdout, stderr, configuration, crashData=None):
file=sys.stderr,
)
print(os.linesep.join(gdbOutput), file=sys.stderr)
raise RuntimeError("Fatal error parsing GDB trace")
raise TraceParsingError(
"Fatal error parsing GDB trace",
line_no=line_no,
)

# This is a workaround for GDB throwing an error while resolving
# function arguments in the trace and aborting. We try to remove the
Expand Down Expand Up @@ -1910,10 +1924,12 @@ def __init__(self, stdout, stderr, configuration, crashData=None):
expectedIndex = 0

if not expectedIndex == index:
raise RuntimeError(
f"Fatal error parsing TSan trace (Index mismatch, got index {index}"
f" but expected {expectedIndex})"
print(
f"Error parsing TSan trace (Index mismatch, got index {index} but "
f"expected {expectedIndex})",
file=sys.stderr,
)
break

component = None
if len(parts) > 2:
Expand Down

3 comments on commit 329149b

@community-tc-integration
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

InterpreterError at template.tasks[5][0].payload.env["PYPI_SECRET"]: unknown context value pypi

@community-tc-integration
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

InterpreterError at template.tasks[5][0].payload.env["PYPI_SECRET"]: unknown context value pypi

@community-tc-integration
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

InterpreterError at template.tasks[5][0].payload.env["PYPI_SECRET"]: unknown context value pypi

Please sign in to comment.