Skip to content

Commit 4e6ce2d

Browse files
vladzcloudiusxemul
authored andcommitted
scripts/addr2line.py: fix hanging with the new llvm-addr2line version
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 Closes #2611
1 parent 1e75395 commit 4e6ce2d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

scripts/addr2line.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ class Addr2Line:
5454
dummy_pattern = re.compile(
5555
r"(.*0x0000000000000000: \?\? \?\?:0\n)" # addr2line pattern
5656
r"|"
57-
r"(.*0x0: \?\? at .*\n)" # llvm-addr2line pattern
57+
r"(\?\? at \?\?:0\n)" # llvm-addr2line pattern for LLVM 18 and newer
58+
r"|"
59+
r"(,\n)" # llvm-addr2line pattern for LLVM 17 and older
5860
)
5961

6062
def __init__(
@@ -97,7 +99,7 @@ def __init__(
9799
# will just exit. We need to be robust against that. We
98100
# can't just wait on self._addr2line since there is no
99101
# guarantee on what timeout is sufficient.
100-
self._input.write('\n')
102+
self._input.write(',\n')
101103
self._input.flush()
102104
res = self._output.readline()
103105
self._missing = res == ''
@@ -129,9 +131,9 @@ def _read_resolved_address(self):
129131
def __call__(self, address: str):
130132
if self._missing:
131133
return " ".join([self._binary, address, '\n'])
132-
# We print a dummy 0x0 address after the address we are interested in
134+
# We trigger a dummy "invalid" address printout after the address we are interested in
133135
# which we can look for in _read_address
134-
inputline = address + '\n0x0\n'
136+
inputline = address + '\n,\n'
135137
self._parent.debug('Add2Line sending input to stdin:', inputline)
136138
self._input.write(inputline)
137139
self._input.flush()

0 commit comments

Comments
 (0)