Browse Source

add HTML+JS file to beatify crash reports. Works only with MacOS crash reports at the moment. Feel free to add support for other formats, too. :-)

JSON-156
Roker 1 year ago
parent
commit
3947f51f6d
2 changed files with 128 additions and 0 deletions
  1. +38
    -0
      html/crashview.html
  2. +90
    -0
      html/crashview.js

+ 38
- 0
html/crashview.html View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Crashdump viewer &amp; formatter</title>
<style id="stl">
table,tr,th,td { border:1px solid gray; border-collapse:collapse; vertical-align:top;}
td { padding:2px; }
.log { font-family:monospace; white-space:pre; }
button { padding:5px;}
.enabled { font-weight:900; }
.disabled { text-decoration:line-through; text-decoration-color:red; font-style:italic; }
</style>
</head>
<body>
<noscript>This HTML page requires JavaScript. Sorry.</noscript>
<h1>Crashdump viewer &amp; formatter</h1>
<p id="introtext">
Please paste a crashdump into the textarea below or select one from file.
</p>
<textarea id="dropzone" name=dropzone" cols="80" rows="15" wrap="off" style="white-space:pre;overflow:auto" placeholder="Paste crashdump here…">
</textarea>
<br>
<input type="file" id="crashfile" name="logfile" />
<p>
<output id="list"></output>
<p>
<table id="tbl" style="border:1px solid gray; border-collapse:collapse;"></table>
<script src="crashview.js"></script>
<script>
document.getElementById('crashfile').addEventListener('change', handleFileSelect, false);
document.getElementById('dropzone').addEventListener('change', handleDropzone, false);
</script>
</body>
</html>

+ 90
- 0
html/crashview.js View File

@ -0,0 +1,90 @@
var lineRegEx = /(\d+)\s+(\S+)\s+(0x[0-9a-fA-F]+)\s+(.*)/;
// Beautify the output by replacing overlong C++ symbol names by shorter aliases.
// NOTA BENE: Order of replacements matter!
var replaces =
[
[ /std::__1::allocator/g , "ALLOC" ],
[ /std::__1::basic_string<char, std::__1::char_traits<char>, ALLOC<char> >/g, "STRING"],
[ /std::__1::vector<json_spirit::Pair_impl<json_spirit::Config_vector<STRING > >, ALLOC<json_spirit::Pair_impl<json_spirit::Config_vector<STRING > > > >/g, "JS::VALUE"],
[ /</g , '&lt;' ],
[ />/g , '&gt;' ]
];
function replaceAll(s)
{
replaces.forEach(function(elem)
{
s = s.replace(elem[0], elem[1]);
}
);
return s;
}
function addLogLine(nr, module, address, logline)
{
document.getElementById('tbl').innerHTML +=
'<tr><td align="right">'
+ nr + '</td><td>'
+ module + '</td><td>'
+ address + '</td><td class="log">'
+ replaceAll(logline) + '</td></tr>';
}
function parseData(stringData)
{
var lines = stringData.split('\n');
for(var i=0; i<lines.length; ++i)
{
var l = lines[i];
var m = l.match(lineRegEx);
if(m && m.length==5)
{
var nr = m[1];
var module = m[2];
var address = m[3];
var logline = m[4];
addLogLine(nr, module, address, logline);
}else{
document.getElementById('tbl').innerHTML += '<tr class="th0"><td colspan="4">' + replaceAll(l) + '&nbsp;</td></tr>';
}
}
}
function handleFileSelect(evt)
{
var files = evt.target.files; // FileList object
var file=files[0];
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++)
{
output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
f.size, ' bytes. </li>');
}
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
document.getElementById('tbl').innerHTML = '';
var reader = new FileReader();
reader.onload = function(progressEvent)
{
var stringData = reader.result;
parseData(stringData);
}
reader.readAsText(file, "UTF-8");
}
function handleDropzone()
{
document.getElementById('tbl').innerHTML = '';
parseData( document.getElementById("dropzone").value );
}

Loading…
Cancel
Save