forked from M-Labs/artiq
ARTIQException: tell linecache where to look for runtime sources.
Runtime sources can appear in the backtrace when artiq_raise_from_c is used.
This commit is contained in:
parent
c72267ecf5
commit
46476516ba
|
@ -0,0 +1,13 @@
|
|||
import os
|
||||
|
||||
class SourceLoader:
|
||||
def __init__(self, runtime_root):
|
||||
self.runtime_root = runtime_root
|
||||
|
||||
def get_source(self, filename):
|
||||
print(os.path.join(self.runtime_root, filename))
|
||||
with open(os.path.join(self.runtime_root, filename)) as f:
|
||||
return f.read()
|
||||
|
||||
artiq_root = os.path.join(os.path.dirname(__file__), "..", "..")
|
||||
source_loader = SourceLoader(os.path.join(artiq_root, "soc", "runtime"))
|
|
@ -6,6 +6,8 @@ import linecache, re
|
|||
from collections import namedtuple
|
||||
from functools import wraps
|
||||
|
||||
# for runtime files in backtraces
|
||||
from artiq.coredevice.runtime import source_loader
|
||||
|
||||
|
||||
__all__ = ["int64", "round64",
|
||||
|
@ -312,7 +314,8 @@ class ARTIQException(Exception):
|
|||
|
||||
lines.append("Core Device Traceback (most recent call last):")
|
||||
for (filename, line, column, function, address) in self.traceback:
|
||||
source_line = linecache.getline(filename, line)
|
||||
stub_globals = {"__name__": filename, "__loader__": source_loader}
|
||||
source_line = linecache.getline(filename, line, stub_globals)
|
||||
indentation = re.search(r"^\s*", source_line).end()
|
||||
|
||||
if address is None:
|
||||
|
|
|
@ -40,7 +40,8 @@ void __artiq_reraise(void)
|
|||
.param = { exnparam0, exnparam1, exnparam2 }, \
|
||||
.file = __FILE__, \
|
||||
.line = __LINE__, \
|
||||
.column = 0 \
|
||||
.column = -1, \
|
||||
.function = __func__, \
|
||||
}; \
|
||||
__artiq_raise(&exn); \
|
||||
} while(0)
|
||||
|
|
Loading…
Reference in New Issue