From eb990dbf1a8adafbd0c08e6c076a6b89fca6cf70 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sat, 28 Dec 2019 13:49:09 -0600 Subject: [PATCH] openRelevantListing() picks listing or source file --- src/ide/ui.ts | 11 ++++----- src/worker/workermain.ts | 48 ++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/ide/ui.ts b/src/ide/ui.ts index d9627144..761d558d 100644 --- a/src/ide/ui.ts +++ b/src/ide/ui.ts @@ -1107,12 +1107,13 @@ function openRelevantListing(state: EmuState) { if (listings) { var pc = state.c ? (state.c.EPC || state.c.PC) : 0; for (var lstfn in listings) { - //var wndid = current_project.filename2path[lstfn] || lstfn; - var wndid = projectWindows.findWindowWithFilePrefix(lstfn); - //console.log(lstfn,wndid); + var lst = listings[lstfn]; + var file = lst.assemblyfile || lst.sourcefile; + // pick either listing or source file + var wndid = current_project.filename2path[lstfn] || lstfn; + if (file == lst.sourcefile) wndid = projectWindows.findWindowWithFilePrefix(lstfn); + // does this window exist? if (projectWindows.isWindow(wndid)) { - var lst = listings[lstfn]; - var file = lst.sourcefile || lst.assemblyfile; var res = file && file.findLineForOffset(pc, 32); // TODO: const if (res && pc-res.offset < bestscore) { bestid = wndid; diff --git a/src/worker/workermain.ts b/src/worker/workermain.ts index e8b11806..221e8066 100644 --- a/src/worker/workermain.ts +++ b/src/worker/workermain.ts @@ -824,8 +824,10 @@ function setupStdin(fs, code:string) { /* 000000r 1 .segment "CODE" + 000000r 1 .proc _rasterWait: near 000000r 1 ; int main() { return mul2(2); } 000000r 1 .dbg line, "main.c", 3 + 000014r 1 .dbg func, "main", "00", extern, "_main" 000000r 1 A2 00 ldx #$00 */ function parseCA65Listing(code, symbols, params, dbg) { @@ -835,32 +837,33 @@ function parseCA65Listing(code, symbols, params, dbg) { var funcLineMatch = /"(\w+)", (\w+), "(\w+)"/; var insnLineMatch = /^([0-9A-F]+)([r]?)\s+(\d+)\s+([0-9A-Fr ]*)\s*(.*)/; var lines = []; - var linenum = 0; + var linenum = 4; // ca65 listing header, 5 lines // TODO: only does .c functions, not all .s files for (var line of code.split(re_crlf)) { - if (dbg) { - var dbgm = dbgLineMatch.exec(line); - if (dbgm && dbgm[1]) { - var dbgtype = dbgm[4]; - offset = parseInt(dbgm[1], 16); - if (dbgtype == 'line') { - lines.push({ - // TODO: sourcefile - line:parseInt(dbgm[6]), - offset:offset + segofs, - insns:null - }); - } - else if (dbgtype == 'func') { - var funcm = funcLineMatch.exec(dbgm[6]); - if (funcm) { - var funcofs = symbols[funcm[3]]; - if (typeof funcofs === 'number') { - segofs = funcofs - offset; - } + var dbgm = dbgLineMatch.exec(line); + if (dbgm && dbgm[1]) { + var dbgtype = dbgm[4]; + offset = parseInt(dbgm[1], 16); + if (dbgtype == 'func') { + var funcm = funcLineMatch.exec(dbgm[6]); + if (funcm) { + var funcofs = symbols[funcm[3]]; + if (typeof funcofs === 'number') { + segofs = funcofs - offset; + //console.log(funcm[3], funcofs, '-', offset); } } } + } + if (dbg) { + if (dbgm && dbgtype == 'line') { + lines.push({ + // TODO: sourcefile + line:parseInt(dbgm[6]), + offset:offset + segofs, + insns:null + }); + } } else { var linem = insnLineMatch.exec(line); if (linem) linenum++; @@ -883,6 +886,7 @@ function parseCA65Listing(code, symbols, params, dbg) { if (typeof symofs === 'number') { offset = parseInt(linem[1], 16); segofs = symofs - offset; + //console.log(sym, symofs, '-', offset); } } } @@ -1012,6 +1016,7 @@ function linkLD65(step:BuildStep) { var asmlines = parseCA65Listing(lstout, symbolmap, params, false); var srclines = parseCA65Listing(lstout, symbolmap, params, true); putWorkFile(fn, lstout); + // TODO: you have to get rid of all source lines to get asm listing listings[fn] = { asmlines:srclines.length ? asmlines : null, lines:srclines.length ? srclines : asmlines, @@ -2201,6 +2206,7 @@ function linkLWLINK(step:BuildStep) { var asmlines = parseListing(lstout, /^([0-9A-F]+)\s+([0-9A-F]+)\s+[(]\s*(.+?)[)]:(\d+) (.*)/i, 4, 1, 2, 3); var srclines = []; putWorkFile(fn, lstout); + // TODO: you have to get rid of all source lines to get asm listing listings[fn] = { asmlines:srclines.length ? asmlines : null, lines:srclines.length ? srclines : asmlines,