Skip to content

Commit 8ba299b

Browse files
Add optional, automatic OOM logger parsing
An updated ESP8266 panic function can print out the calling function/line and size requested for the last malloc/realloc/calloc/new allocation that failed, without the overhead of full the OOM stack. Add parsing for this line, when present, and output the function, file, line, and amount of memory requested to the display. When not present, do nothing different.
1 parent 2a89b34 commit 8ba299b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/EspExceptionDecoder.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,54 @@ private void parseText(){
382382
sysExec(command);
383383
}
384384

385+
private void parseAlloc() {
386+
String content = inputArea.getText();
387+
Pattern p = Pattern.compile("last failed alloc call: 40[0-2](\\d|[-A-F]){5}\\((\\d)+\\)");
388+
Matcher m = p.matcher(content);
389+
if (m.find()) {
390+
String fs = content.substring(m.start(), m.end());
391+
Pattern p2 = Pattern.compile("40[0-2](\\d|[A-F]){5}\\b");
392+
Matcher m2 = p2.matcher(fs);
393+
if (m2.find()) {
394+
String addr = fs.substring(m2.start(), m2.end());
395+
Pattern p3 = Pattern.compile("\\((\\d)+\\)");
396+
Matcher m3 = p3.matcher(fs);
397+
if (m3.find()) {
398+
String size = fs.substring(m3.start()+1, m3.end()-1);
399+
400+
String command[] = new String[5];
401+
command[0] = tool.getAbsolutePath();
402+
command[1] = "-aipfC";
403+
command[2] = "-e";
404+
command[3] = elf.getAbsolutePath();
405+
command[4] = addr;
406+
407+
try {
408+
final Process proc = ProcessUtils.exec(command);
409+
InputStreamReader reader = new InputStreamReader(proc.getInputStream());
410+
int c;
411+
String line = "";
412+
while ((c = reader.read()) != -1){
413+
if((char)c == '\r')
414+
continue;
415+
if((char)c == '\n' && line != ""){
416+
outputText += "Memory allocation of " + size + " bytes failed at " + line + "\n";
417+
break;
418+
} else {
419+
line += (char)c;
420+
}
421+
}
422+
reader.close();
423+
} catch (Exception er) { }
424+
}
425+
}
426+
}
427+
}
428+
385429
private void runParser(){
386430
outputText = "<html><pre>\n";
387431
parseException();
432+
parseAlloc();
388433
parseText();
389434
}
390435

0 commit comments

Comments
 (0)