Skip to content

Commit

Permalink
scripts/addr2line.py: fix hanging with the new llvm-addr2line version
Browse files Browse the repository at this point in the history
addr2line.py invokes "addr2line" tool in a "server" mode where addresses
are fed via stdin. It intentionally makes a corresponding "addr2line" tool generate a
known "invalid address" pattern at the end of each address decoding by feeding
it a "0x0" address in order to denote the end of it because a single address can be decoded
into multiple lines due to inlining.

The above strategy assumes that 0x0 address is always going to be interpreted as an invalid one by
both add2line and by llvm-addr2line.

However, at least llvm-addr2line 18.1.3 doesn't always interpret it this way.
On the other hand an empty line does always generate an expected (invalid address)
output.

On top of that it looks like a new llvm-addr2line changed the "invalid address" pattern
format.

This patch adds a new "invalid input" pattern to a dummy_pattern and
changes the way we generate such an output by pushing line that only has a ',' charachter instead of a
0x0 address.

Ref #2609
  • Loading branch information
vladzcloudius committed Jan 9, 2025
1 parent ff24926 commit 2ef2f46
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/addr2line.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ class Addr2Line:
dummy_pattern = re.compile(
r"(.*0x0000000000000000: \?\? \?\?:0\n)" # addr2line pattern
r"|"
r"(.*0x0: \?\? at .*\n)" # llvm-addr2line pattern
r"(.*0x0: \?\? at .*\n)" # llvm-addr2line patterns
r"|"
r"(\?\? at \?\?:0\n)"
r"|"
r"(,\n)"
)

def __init__(
Expand Down Expand Up @@ -97,7 +101,7 @@ def __init__(
# will just exit. We need to be robust against that. We
# can't just wait on self._addr2line since there is no
# guarantee on what timeout is sufficient.
self._input.write('\n')
self._input.write(',\n')
self._input.flush()
res = self._output.readline()
self._missing = res == ''
Expand Down Expand Up @@ -129,9 +133,9 @@ def _read_resolved_address(self):
def __call__(self, address: str):
if self._missing:
return " ".join([self._binary, address, '\n'])
# We print a dummy 0x0 address after the address we are interested in
# We trigger a dummy "invalid" address printout after the address we are interested in
# which we can look for in _read_address
inputline = address + '\n0x0\n'
inputline = address + '\n,\n'
self._parent.debug('Add2Line sending input to stdin:', inputline)
self._input.write(inputline)
self._input.flush()
Expand Down

0 comments on commit 2ef2f46

Please sign in to comment.