Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaha El Kassaby2018-05-02 19:52:39 +0000
committerJonah Graham2019-11-25 17:01:21 +0000
commit949efc65727a2db644b0436f4df3a203a904fceb (patch)
tree4ab0c044275a35dd19c59c3c1767f385e9c5afaf /dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command
parent7e267a47915bb79d384528be5be713e6fd3c10fd (diff)
downloadorg.eclipse.cdt-949efc65727a2db644b0436f4df3a203a904fceb.tar.gz
org.eclipse.cdt-949efc65727a2db644b0436f4df3a203a904fceb.tar.xz
org.eclipse.cdt-949efc65727a2db644b0436f4df3a203a904fceb.zip
Bug 530443: Add support for "info sources" MI equivalent
*Implementation of -file-list-exec-source-files MI command. *Add new Debug Sources view with tree-like structure Change-Id: I6e734799712c059c8e53aa882777dfebd85aa0d5 Also-by: Jonah Graham <jonah@kichwacoders.com> Signed-off-by: Baha El Kassaby <baha.elkassaby@gmail.com>
Diffstat (limited to 'dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command')
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java7
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIFileListExecSourceFiles.java39
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MiSourceFilesInfo.java164
3 files changed, 210 insertions, 0 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java
index a1aef544584..7e1287d02db 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java
@@ -120,6 +120,7 @@ import org.eclipse.cdt.dsf.mi.service.command.commands.MIExecUncall;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIExecUntil;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIFileExecAndSymbols;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIFileExecFile;
+import org.eclipse.cdt.dsf.mi.service.command.commands.MIFileListExecSourceFiles;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIFileSymbolFile;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBExit;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSet;
@@ -254,6 +255,7 @@ import org.eclipse.cdt.dsf.mi.service.command.output.MIVarSetFormatInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIVarShowAttributesInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIVarShowFormatInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIVarUpdateInfo;
+import org.eclipse.cdt.dsf.mi.service.command.output.MiSourceFilesInfo;
/**
* Factory to create MI/CLI commands.
@@ -739,6 +741,11 @@ public class CommandFactory {
return new MIFileExecFile(dmc);
}
+ /** @since 5.8*/
+ public ICommand<MiSourceFilesInfo> createMiFileListExecSourceFiles(IDMContext ctx) {
+ return new MIFileListExecSourceFiles(ctx);
+ }
+
public ICommand<MIInfo> createMIFileSymbolFile(ICommandControlDMContext dmc, String file) {
return new MIFileSymbolFile(dmc, file);
}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIFileListExecSourceFiles.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIFileListExecSourceFiles.java
new file mode 100644
index 00000000000..c58b4e41e6a
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIFileListExecSourceFiles.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2017, 2018 Kichwa Coders and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Jonah Graham (Kichwa Coders) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.mi.service.command.commands;
+
+import org.eclipse.cdt.dsf.datamodel.IDMContext;
+import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput;
+import org.eclipse.cdt.dsf.mi.service.command.output.MiSourceFilesInfo;
+
+/**
+ *
+ * -file-list-exec-source-files
+ *
+ * Returns the list of source files for the current execution context. It
+ * outputs both filename and full (absolute path) file name of a source file.
+ *
+ * @since 5.8
+ */
+public class MIFileListExecSourceFiles extends MICommand<MiSourceFilesInfo> {
+
+ public MIFileListExecSourceFiles(IDMContext ctx) {
+ super(ctx, "-file-list-exec-source-files"); //$NON-NLS-1$
+ }
+
+ @Override
+ public MiSourceFilesInfo getResult(MIOutput out) {
+ return new MiSourceFilesInfo(out);
+ }
+} \ No newline at end of file
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MiSourceFilesInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MiSourceFilesInfo.java
new file mode 100644
index 00000000000..f1441cfde0a
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MiSourceFilesInfo.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2017, 2018 Kichwa Coders and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Jonah Graham (Kichwa Coders) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.mi.service.command.output;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Example output is:
+ *
+ * <pre>
+ * (gdb) -file-list-exec-source-files
+ * ^done,files=[{file=foo.c,fullname=/home/foo.c},
+ * {file=/home/bar.c,fullname=/home/bar.c},
+ * {file=gdb_could_not_find_fullpath.c}]
+ * </pre>
+ *
+ * @since 5.8
+ */
+public class MiSourceFilesInfo extends MIInfo {
+
+ private SourceFileInfo[] sourceFileInfos;
+
+ public MiSourceFilesInfo(MIOutput record) {
+ super(record);
+ parse();
+ if (sourceFileInfos == null) {
+ sourceFileInfos = new SourceFileInfo[0];
+ }
+ }
+
+ /**
+ * Returns array of source files infos
+ *
+ * @return
+ */
+ public SourceFileInfo[] getSourceFiles() {
+ return sourceFileInfos;
+ }
+
+ private void parse() {
+ if (isDone()) {
+ MIOutput out = getMIOutput();
+ MIResultRecord rr = out.getMIResultRecord();
+ if (rr != null) {
+ MIResult[] results = rr.getMIResults();
+ for (int i = 0; i < results.length; i++) {
+ String var = results[i].getVariable();
+ if (var.equals("files")) { //$NON-NLS-1$
+ MIValue value = results[i].getMIValue();
+ if (value instanceof MIList) {
+ parseResults((MIList) value);
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ private void parseResults(MIList list) {
+ MIValue[] miValues = list.getMIValues();
+ List<SourceFileInfo> infos = new LinkedList<>();
+ if (miValues != null) {
+ for (MIValue miValue : miValues) {
+ if (miValue instanceof MITuple) {
+ MITuple miTuple = (MITuple) miValue;
+ SourceFileInfo info = new SourceFileInfo();
+ info.parse(miTuple.getMIResults());
+ infos.add(info);
+ }
+ }
+ }
+ sourceFileInfos = infos.toArray(new SourceFileInfo[infos.size()]);
+ }
+
+ public static class SourceFileInfo {
+ private String file;
+ private String fullname;
+
+ public void setFile(String file) {
+ this.file = file;
+ }
+
+ public String getFile() {
+ return file;
+ }
+
+ public void setFullName(String fullname) {
+ this.fullname = fullname;
+ }
+
+ public String getFullName() {
+ return fullname;
+ }
+
+ private void parse(MIResult[] results) {
+ for (MIResult result : results) {
+ String variable = result.getVariable();
+ MIValue miVal = result.getMIValue();
+ if (!(miVal instanceof MIConst)) {
+ continue;
+ }
+ String value = ((MIConst) miVal).getCString();
+ switch (variable) {
+ case "file": //$NON-NLS-1$
+ file = value;
+ break;
+ case "fullname": //$NON-NLS-1$
+ fullname = value;
+ break;
+ }
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((file == null) ? 0 : file.hashCode());
+ result = prime * result + ((fullname == null) ? 0 : fullname.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SourceFileInfo other = (SourceFileInfo) obj;
+ if (file == null) {
+ if (other.file != null)
+ return false;
+ } else if (!file.equals(other.file))
+ return false;
+ if (fullname == null) {
+ if (other.fullname != null)
+ return false;
+ } else if (!fullname.equals(other.fullname))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "SourceFileInfo [file=" + file + ", fullname=" + fullname + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ }
+}

Back to the top