summaryrefslogtreecommitdiffstatshomepage
path: root/py/showbc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-13 14:51:56 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-13 14:51:56 +0100
commit73496fbbe4b787a5b4255d6ae98c20255878e012 (patch)
tree4a58715b37c77e3dc951e8930d7defbc01334c39 /py/showbc.c
parentb636d024d2fe950d8dd643c74aa006d1ea88078d (diff)
downloadmicropython-73496fbbe4b787a5b4255d6ae98c20255878e012.tar.gz
micropython-73496fbbe4b787a5b4255d6ae98c20255878e012.zip
py: Fix up source-line calculation.
Should address issue #475.
Diffstat (limited to 'py/showbc.c')
-rw-r--r--py/showbc.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/py/showbc.c b/py/showbc.c
index 25b1b2ffb6..d755d3c96c 100644
--- a/py/showbc.c
+++ b/py/showbc.c
@@ -33,6 +33,7 @@ void mp_byte_code_print(const byte *ip, int len) {
// get code info size
machine_uint_t code_info_size = ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24);
+ const byte *code_info = ip;
ip += code_info_size;
// bytecode prelude: state size and exception stack size; 16 bit uints
@@ -56,6 +57,21 @@ void mp_byte_code_print(const byte *ip, int len) {
ip_start = ip;
}
+ // print out line number info
+ {
+ qstr source_file = code_info[4] | (code_info[5] << 8) | (code_info[6] << 16) | (code_info[7] << 24);
+ qstr block_name = code_info[8] | (code_info[9] << 8) | (code_info[10] << 16) | (code_info[11] << 24);
+ printf("File %s, block %s\n", qstr_str(source_file), qstr_str(block_name));
+ machine_int_t bc = (code_info + code_info_size) - ip;
+ machine_uint_t source_line = 1;
+ printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
+ for (const byte* ci = code_info + 12; *ci; ci++) {
+ bc += *ci & 31;
+ source_line += *ci >> 5;
+ printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
+ }
+ }
+
machine_uint_t unum;
qstr qstr;
while (ip - ip_start < len) {