forked from M-Labs/artiq
1
0
Fork 0

Correctly display backtraces that contain inlined functions.

This commit is contained in:
whitequark 2016-02-24 17:44:07 +00:00
parent 442673076f
commit cf41890255
2 changed files with 22 additions and 7 deletions

View File

@ -151,20 +151,31 @@ class Target:
if addresses == []:
return []
# Addresses point one instruction past the jump; offset them back by 1.
offset_addresses = [hex(addr - 1) for addr in addresses]
with RunTool([self.triple + "-addr2line", "--functions", "--inlines",
offset_addresses = [hex(addr) for addr in addresses]
with RunTool([self.triple + "-addr2line", "--addresses", "--functions", "--inlines",
"--exe={library}"] + offset_addresses,
library=library) \
as results:
lines = results["__stdout__"].rstrip().split("\n")
lines = iter(results["__stdout__"].rstrip().split("\n"))
backtrace = []
for function_name, location, address in zip(lines[::2], lines[1::2], addresses):
while True:
try:
address_or_function = next(lines)
except StopIteration:
break
if address_or_function[:2] == "0x":
address = int(address_or_function[2:], 16)
function = next(lines)
else:
address = backtrace[-1][4] # inlined
function = address_or_function
location = next(lines)
filename, line = location.rsplit(":", 1)
if filename == "??":
if filename == "??" or filename == "<synthesized>":
continue
# can't get column out of addr2line D:
backtrace.append((filename, int(line), -1, function_name, address))
backtrace.append((filename, int(line), -1, function, address))
return backtrace
class NativeTarget(Target):

View File

@ -27,6 +27,7 @@ class CoreException:
def __str__(self):
lines = []
lines.append("Core Device Traceback (most recent call last):")
last_address = 0
for (filename, line, column, function, address) in self.traceback:
stub_globals = {"__name__": filename, "__loader__": source_loader}
source_line = linecache.getline(filename, line, stub_globals)
@ -34,8 +35,11 @@ class CoreException:
if address is None:
formatted_address = ""
elif address == last_address:
formatted_address = " (inlined)"
else:
formatted_address = " (RA=0x{:x})".format(address)
last_address = address
filename = filename.replace(artiq_dir, "<artiq>")
if column == -1: