From 8ba299b4eefeaefaa719704a22d537ab2c2b5ac6 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 22 Jan 2018 19:13:15 -0800 Subject: [PATCH] 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. --- src/EspExceptionDecoder.java | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/EspExceptionDecoder.java b/src/EspExceptionDecoder.java index a9c6428..516a916 100644 --- a/src/EspExceptionDecoder.java +++ b/src/EspExceptionDecoder.java @@ -382,9 +382,54 @@ private void parseText(){ sysExec(command); } + private void parseAlloc() { + String content = inputArea.getText(); + Pattern p = Pattern.compile("last failed alloc call: 40[0-2](\\d|[-A-F]){5}\\((\\d)+\\)"); + Matcher m = p.matcher(content); + if (m.find()) { + String fs = content.substring(m.start(), m.end()); + Pattern p2 = Pattern.compile("40[0-2](\\d|[A-F]){5}\\b"); + Matcher m2 = p2.matcher(fs); + if (m2.find()) { + String addr = fs.substring(m2.start(), m2.end()); + Pattern p3 = Pattern.compile("\\((\\d)+\\)"); + Matcher m3 = p3.matcher(fs); + if (m3.find()) { + String size = fs.substring(m3.start()+1, m3.end()-1); + + String command[] = new String[5]; + command[0] = tool.getAbsolutePath(); + command[1] = "-aipfC"; + command[2] = "-e"; + command[3] = elf.getAbsolutePath(); + command[4] = addr; + + try { + final Process proc = ProcessUtils.exec(command); + InputStreamReader reader = new InputStreamReader(proc.getInputStream()); + int c; + String line = ""; + while ((c = reader.read()) != -1){ + if((char)c == '\r') + continue; + if((char)c == '\n' && line != ""){ + outputText += "Memory allocation of " + size + " bytes failed at " + line + "\n"; + break; + } else { + line += (char)c; + } + } + reader.close(); + } catch (Exception er) { } + } + } + } + } + private void runParser(){ outputText = "
\n";
     parseException();
+    parseAlloc();
     parseText();
   }