@@ -97,6 +97,20 @@ public String getMenuTitle() {
97
97
return "ESP Exception Decoder" ;
98
98
}
99
99
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
+
100
114
// Original code from processing.app.helpers.ProcessUtils.exec()
101
115
// Need custom version to redirect STDERR to STDOUT for GDB processing
102
116
public static Process execRedirected (String [] command ) throws IOException {
@@ -150,19 +164,19 @@ public void run() {
150
164
System .err .print ((char ) c );
151
165
reader .close ();
152
166
} catch (Exception e ){
153
- outputArea . setText ( "<html><font color=red><b> Run Exception:</b> " +e .getMessage ()+ "</font></html>" );
167
+ printError ( " Run Exception: " +e .getMessage ());
154
168
}
155
169
}
156
170
};
157
171
thread .start ();
158
172
int res = p .waitFor ();
159
173
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
+ }
163
177
return res ;
164
178
} catch (Exception e ){
165
- outputArea . setText ( "<html><font color=red><b> Decode Exception:</b> " +e .getMessage ()+ "</font></html>" );
179
+ printError ( " Decode Exception: " +e .getMessage ());
166
180
}
167
181
return -1 ;
168
182
}
@@ -175,12 +189,12 @@ public void run() {
175
189
editor .statusError ("Decode Failed" );
176
190
} else {
177
191
editor .statusNotice ("Decode Success" );
178
- outputArea .setText (outputText );
179
192
}
180
193
} catch (Exception e ){
181
194
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 ());
183
196
}
197
+ outputArea .setText (outputText );
184
198
}
185
199
};
186
200
thread .start ();
@@ -291,19 +305,46 @@ private void createAndUpload(){
291
305
292
306
TargetPlatform platform = BaseNoGui .getTargetPlatform ();
293
307
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/" ;
299
310
300
311
String gdb ;
301
312
if (PreferencesData .get ("runtime.os" ).contentEquals ("windows" ))
302
313
gdb = tc +"-gdb.exe" ;
303
314
else
304
315
gdb = tc +"-gdb" ;
305
316
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
+
307
348
if (!tool .exists () || !tool .isFile ()) {
308
349
System .err .println ();
309
350
editor .statusError ("ERROR: " +gdb +" not found!" );
@@ -399,12 +440,6 @@ private String prettyPrintGDBLine(String line) {
399
440
return html ;
400
441
}
401
442
402
- private void printLine (String line ){
403
- String s = prettyPrintGDBLine (line );
404
- if (s != null )
405
- outputText += s +"\n " ;
406
- }
407
-
408
443
public void run () {
409
444
createAndUpload ();
410
445
}
@@ -469,6 +504,7 @@ private void parseStackOrBacktrace(String regexp, boolean multiLine, String stri
469
504
}
470
505
command [i ++] = "-ex" ;
471
506
command [i ++] = "q" ;
507
+ System .out .println ("\" " +String .join ("\" \" " , command )+"\" " );
472
508
outputText += "\n <i>Decoding stack results</i>\n " ;
473
509
sysExec (command );
474
510
}
@@ -485,6 +521,7 @@ private String decodeFunctionAtAddress( String addr ) {
485
521
command [6 ] = "l *0x" + addr ;
486
522
command [7 ] = "-ex" ;
487
523
command [8 ] = "q" ;
524
+ System .out .println ("\" " +String .join ("\" \" " , command )+"\" " );
488
525
489
526
try {
490
527
final Process proc = execRedirected (command );
@@ -502,8 +539,10 @@ private String decodeFunctionAtAddress( String addr ) {
502
539
}
503
540
}
504
541
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
+ }
507
546
return null ;
508
547
}
509
548
0 commit comments