Skip to content

Commit

Permalink
Link to disassembly
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Feb 28, 2024
1 parent bf9b6d0 commit f24faae
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
17 changes: 16 additions & 1 deletion docs/purescript/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ <h3>NuttX Log Parser with PureScript</h3>
<!-- Begin Test: Call PureScript to parse NuttX Logs -->
<script type=module>
// Import Main Module
import { parseException, parseStackDump, explainException } from 'https://lupyuen.github.io/nuttx-purescript-parser/index.js';
import { parseException, parseStackDump, explainException, identifyAddress } from 'https://lupyuen.github.io/nuttx-purescript-parser/index.js';
import * as StringParser_Parser from "https://compile.purescript.org/output/StringParser.Parser/index.js";

// Export the PureScript Functions
window.StringParser_Parser = StringParser_Parser;
window.parseException = parseException;
window.parseStackDump = parseStackDump;
window.explainException = explainException;
window.identifyAddress = identifyAddress;

// Run parseException
console.log('Running parseException...');
Expand Down Expand Up @@ -84,6 +85,20 @@ <h3>NuttX Log Parser with PureScript</h3>
;
console.log({result3});
window.result3 = result3;

// Run identifyAddress
console.log('Running identifyAddress...');
const result4 = identifyAddress('502198ac')
console.log({result4});
window.result4 = result4;

const result5 = identifyAddress('80064a28')
console.log({result5});
window.result5 = result5;

const result6 = identifyAddress('0000000800203b88')
console.log({result6});
window.result6 = result6;
</script>
<!-- End Test -->
</html>
25 changes: 22 additions & 3 deletions docs/purescript/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -1508,19 +1508,24 @@ function parseLog(str) {
// Explain the Exception
if (exception.error === undefined) {
console.log({exception});
const epc = disassemble(exception.epc);
const mtval = disassemble(exception.mtval);
const exception_str = [
"Exception:" + "&nbsp;".repeat(1) + exception.exception,
"MCAUSE:" + "&nbsp;".repeat(4) + exception.mcause,
"EPC:" + "&nbsp;".repeat(7) + exception.epc,
"MTVAL:" + "&nbsp;".repeat(5) + exception.mtval,
"EPC:" + "&nbsp;".repeat(7) + epc,
"MTVAL:" + "&nbsp;".repeat(5) + mtval,
].join("<br>");
parser_output.innerHTML +=
`<p>${exception_str}</p>`;

const explain = explainException(exception.mcause)(exception.epc)(exception.mtval);
console.log({explain});
parser_output.innerHTML +=
`<p>${explain}</p>`;
`<p>${explain}</p>`
.split(exception.epc, 2).join(epc) // Link EPC to Disassembly
.split(exception.mtval, 2).join(mtval) // Link MTVAL to Disassembly
;
}

// Run parseStackDump
Expand Down Expand Up @@ -1548,6 +1553,20 @@ function parseLog(str) {
termbuf = "";
}

// If `addr` is a valid address, return the Disassembly URL.
// Otherwise return `addr`
function disassemble(addr) {
const id = identifyAddress(addr).value0;
if (id === undefined) { return addr; }

const url = `disassemble.html?addr=${addr}`;
return [
`<a href="${url}" target="_blank">`,
addr,
`</a>`,
].join("");
}

// Buffer the last line of the Terminal Output
let termbuf = "";

Expand Down

0 comments on commit f24faae

Please sign in to comment.