2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 11:18:27 +08:00

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:
whitequark 2015-08-10 19:26:00 +03:00
parent c72267ecf5
commit 46476516ba
3 changed files with 19 additions and 2 deletions

View File

@ -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"))

View File

@ -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:

View File

@ -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)