Skip to content

Commit ff4fc36

Browse files
committed
Add support for esp-elf-gdb in Arduino ESP32 v2.0.8+
1 parent 349d17e commit ff4fc36

File tree

1 file changed

+60
-21
lines changed

1 file changed

+60
-21
lines changed

src/EspExceptionDecoder.java

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ public String getMenuTitle() {
9797
return "ESP Exception Decoder";
9898
}
9999

100+
private void printLine(String line){
101+
String s = prettyPrintGDBLine(line);
102+
if (s != null)
103+
outputText += s +"\n";
104+
}
105+
106+
private void printLogLine(String line, String color){
107+
outputText += "<b><font color="+color+">"+line+"</font></b>\n";
108+
}
109+
110+
private void printError(String line){
111+
printLogLine(line, "red");
112+
}
113+
100114
// Original code from processing.app.helpers.ProcessUtils.exec()
101115
// Need custom version to redirect STDERR to STDOUT for GDB processing
102116
public static Process execRedirected(String[] command) throws IOException {
@@ -150,19 +164,19 @@ public void run() {
150164
System.err.print((char) c);
151165
reader.close();
152166
} catch (Exception e){
153-
outputArea.setText("<html><font color=red><b>Run Exception:</b> "+e.getMessage()+"</font></html>");
167+
printError("Run Exception: "+e.getMessage());
154168
}
155169
}
156170
};
157171
thread.start();
158172
int res = p.waitFor();
159173
thread.join();
160-
// if(res != 0){
161-
// outputArea.setText("<html><font color=red>Decode Failed</font></html>");
162-
// }
174+
if(res != 0){
175+
printError("Decode Failed");
176+
}
163177
return res;
164178
} catch (Exception e){
165-
outputArea.setText("<html><font color=red><b>Decode Exception:</b> "+e.getMessage()+"</font></html>");
179+
printError("Decode Exception: "+e.getMessage());
166180
}
167181
return -1;
168182
}
@@ -175,12 +189,12 @@ public void run() {
175189
editor.statusError("Decode Failed");
176190
} else {
177191
editor.statusNotice("Decode Success");
178-
outputArea.setText(outputText);
179192
}
180193
} catch (Exception e){
181194
editor.statusError("Decode Exception");
182-
outputArea.setText("<html><font color=red><b>Decode Exception:</b> "+e.getMessage()+"</font></html>");
195+
printError("Decode Exception: "+e.getMessage());
183196
}
197+
outputArea.setText(outputText);
184198
}
185199
};
186200
thread.start();
@@ -291,19 +305,46 @@ private void createAndUpload(){
291305

292306
TargetPlatform platform = BaseNoGui.getTargetPlatform();
293307
String tc = tarch+"-"+target+"-elf";
294-
295-
String gccPath = PreferencesData.get("runtime.tools."+tc+"-gcc.path");
296-
if(gccPath == null){
297-
gccPath = platform.getFolder() + "/tools/"+tc;
298-
}
308+
String tcgdb = tarch+"-esp-elf-gdb";
309+
String tools = platform.getFolder() + "/tools/";
299310

300311
String gdb;
301312
if(PreferencesData.get("runtime.os").contentEquals("windows"))
302313
gdb = tc+"-gdb.exe";
303314
else
304315
gdb = tc+"-gdb";
305316

306-
tool = new File(gccPath + "/bin", gdb);
317+
// Search for GDB
318+
// First check if the GDB package is installed locally (v2.0.8+)
319+
tool = new File(tools + tcgdb + "/bin", gdb);
320+
if (!tool.exists() || !tool.isFile()){
321+
//System.err.println("tools/"+tcgdb+"/bin/"+gdb+" not found");
322+
// Then check if the toolchain is installed locally
323+
tool = new File(tools + tc + "/bin", gdb);
324+
if (!tool.exists() || !tool.isFile()){
325+
//System.err.println("tools/"+tc+"/bin/"+gdb+" not found");
326+
// Then check if the GDB package is installed (v2.0.8+)
327+
String gdbPath = PreferencesData.get("runtime.tools."+tcgdb+".path");
328+
if(gdbPath == null || gdbPath.contentEquals("")){
329+
//System.err.println("runtime.tools."+tcgdb+".path not found");
330+
// Then check if the toolchain is installed
331+
gdbPath = PreferencesData.get("runtime.tools."+tc+"-gcc.path");
332+
}
333+
if(gdbPath == null || gdbPath.contentEquals("")){
334+
//System.err.println("runtime.tools."+tc+"-gcc.path not found");
335+
// If still fails, offer the local toolchain folder
336+
gdbPath = tools+tc;
337+
}
338+
System.err.println("gdbPath: "+gdbPath+"/bin/"+gdb);
339+
tool = new File(gdbPath + "/bin", gdb);
340+
} else {
341+
System.err.println("gdbPath: "+tools+tc+"/bin/"+gdb);
342+
}
343+
} else {
344+
System.err.println("gdbPath: "+tools+tcgdb+"/bin/"+gdb);
345+
}
346+
System.err.println();
347+
307348
if (!tool.exists() || !tool.isFile()) {
308349
System.err.println();
309350
editor.statusError("ERROR: "+gdb+" not found!");
@@ -399,12 +440,6 @@ private String prettyPrintGDBLine(String line) {
399440
return html;
400441
}
401442

402-
private void printLine(String line){
403-
String s = prettyPrintGDBLine(line);
404-
if (s != null)
405-
outputText += s +"\n";
406-
}
407-
408443
public void run() {
409444
createAndUpload();
410445
}
@@ -469,6 +504,7 @@ private void parseStackOrBacktrace(String regexp, boolean multiLine, String stri
469504
}
470505
command[i++] = "-ex";
471506
command[i++] = "q";
507+
System.out.println("\""+String.join("\" \"", command)+"\"");
472508
outputText += "\n<i>Decoding stack results</i>\n";
473509
sysExec(command);
474510
}
@@ -485,6 +521,7 @@ private String decodeFunctionAtAddress( String addr ) {
485521
command[6] = "l *0x" + addr;
486522
command[7] = "-ex";
487523
command[8] = "q";
524+
System.out.println("\""+String.join("\" \"", command)+"\"");
488525

489526
try {
490527
final Process proc = execRedirected(command);
@@ -502,8 +539,10 @@ private String decodeFunctionAtAddress( String addr ) {
502539
}
503540
}
504541
reader.close();
505-
} catch (Exception er) { }
506-
// Something went wrong
542+
} catch (Exception e) {
543+
// Something went wrong
544+
System.err.println("Function Decode Exception: "+e.getMessage());
545+
}
507546
return null;
508547
}
509548

0 commit comments

Comments
 (0)