Skip to content

Commit

Permalink
ARTIQException: tell linecache where to look for runtime sources.
Browse files Browse the repository at this point in the history
Runtime sources can appear in the backtrace when
artiq_raise_from_c is used.
  • Loading branch information
whitequark committed Aug 10, 2015
1 parent c72267e commit 4647651
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
13 changes: 13 additions & 0 deletions artiq/coredevice/runtime.py
Original file line number Diff line number Diff line change
@@ -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"))
5 changes: 4 additions & 1 deletion artiq/language/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from collections import namedtuple
from functools import wraps

# for runtime files in backtraces
from artiq.coredevice.runtime import source_loader


__all__ = ["int64", "round64",
Expand Down Expand Up @@ -312,7 +314,8 @@ def __str__(self):

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:
Expand Down
3 changes: 2 additions & 1 deletion soc/runtime/artiq_personality.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4647651

Please sign in to comment.