Skip to content

Commit f9cb996

Browse files
committed
Merge pull request #103 from sukidog/issue102_pyocd
Fix issue #102. Do not prevent user from relying on gdbserver in PATH…
2 parents 7dd126f + be0eb3a commit f9cb996

File tree

1 file changed

+30
-1
lines changed
  • ilg.gnuarmeclipse.debug.gdbjtag.pyocd/src/ilg/gnuarmeclipse/debug/gdbjtag/pyocd/ui

1 file changed

+30
-1
lines changed

ilg.gnuarmeclipse.debug.gdbjtag.pyocd/src/ilg/gnuarmeclipse/debug/gdbjtag/pyocd/ui/TabDebugger.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import ilg.gnuarmeclipse.debug.gdbjtag.pyocd.PyOCD;
3232

3333
import java.io.File;
34+
import java.io.IOException;
3435
import java.util.ArrayList;
3536
import java.util.Collections;
3637
import java.util.LinkedHashSet;
@@ -803,6 +804,13 @@ private void overrideTargetChanged() {
803804
fGdbServerTargetName.setEnabled(enabled);
804805
}
805806

807+
/**
808+
* Resolve the string in the gdbserver field and validate it. Return the
809+
* result if valid, otherwise return null.
810+
*
811+
* @return an absolute path, relative path or just the name of the
812+
* executable (if it's in PATH)
813+
*/
806814
private String getPyOCDExecutablePath() {
807815
String path = null;
808816

@@ -824,10 +832,31 @@ private String getPyOCDExecutablePath() {
824832
if (Activator.getInstance().isDebugging()) {
825833
System.out.printf("pyOCD resolved path = %s\n", path);
826834
}
835+
827836
// Validate path.
837+
828838

839+
// First check using the most efficient means: see if the file
840+
// exists. If it does, that's good enough.
829841
File file = new File(path);
830-
if (!file.exists() || file.isDirectory()) {
842+
if (!file.exists()) {
843+
// Support pyOCD being in PATH and specified sans path (issue# 102)
844+
try {
845+
Process process = Runtime.getRuntime().exec(path + " --version");
846+
// If no exception, then it's an executable in PATH
847+
try {
848+
process.waitFor();
849+
} catch (InterruptedException e) {
850+
// No harm, no foul
851+
}
852+
} catch (IOException e) {
853+
if (Activator.getInstance().isDebugging()) {
854+
System.out.printf("pyOCD path is invalid\n");
855+
}
856+
return null;
857+
}
858+
}
859+
else if (file.isDirectory()) {
831860
// TODO: Use java.nio.Files when we move to Java 7 to also check
832861
// that file is executable
833862
if (Activator.getInstance().isDebugging()) {

0 commit comments

Comments
 (0)