From 46476516ba6d35640d293148b1a229eb74a9e7a5 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 10 Aug 2015 19:26:00 +0300 Subject: [PATCH] ARTIQException: tell linecache where to look for runtime sources. Runtime sources can appear in the backtrace when artiq_raise_from_c is used. --- artiq/coredevice/runtime.py | 13 +++++++++++++ artiq/language/core.py | 5 ++++- soc/runtime/artiq_personality.h | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 artiq/coredevice/runtime.py diff --git a/artiq/coredevice/runtime.py b/artiq/coredevice/runtime.py new file mode 100644 index 000000000..a9d74b63d --- /dev/null +++ b/artiq/coredevice/runtime.py @@ -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")) diff --git a/artiq/language/core.py b/artiq/language/core.py index b0d556969..8ad224f51 100644 --- a/artiq/language/core.py +++ b/artiq/language/core.py @@ -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: diff --git a/soc/runtime/artiq_personality.h b/soc/runtime/artiq_personality.h index 11a10b2b9..9e7ddce3e 100644 --- a/soc/runtime/artiq_personality.h +++ b/soc/runtime/artiq_personality.h @@ -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)