Skip to content

Commit 439df9a

Browse files
committed
Report LLDB version and clean up LLDB-MI launch sequence
We use CLI 'version' to replace the MI '-gdb-version' command.
1 parent 2ba5b3d commit 439df9a

6 files changed

Lines changed: 169 additions & 9 deletions

File tree

dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-Vendor: %providerName
55
Bundle-SymbolicName: org.eclipse.cdt.dsf.gdb;singleton:=true
6-
Bundle-Version: 7.1.700.qualifier
6+
Bundle-Version: 7.2.0.qualifier
77
Bundle-Activator: org.eclipse.cdt.dsf.gdb.internal.GdbPlugin
88
Bundle-Localization: plugin
99
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.33.0,4)",

dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 QNX Software Systems and others.
2+
* Copyright (c) 2000, 2025 QNX Software Systems and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -31,6 +31,7 @@
3131
* Marc Khouzam (Ericsson) - Support for -gdb-version (Bug 455408)
3232
* Intel Corporation - Added Reverse Debugging BTrace support
3333
* Samuel Hultgren (STMicroelectronics) - Bug 533771
34+
* John Dallaway - Add CLI version command (#1186)
3435
*******************************************************************************/
3536

3637
package org.eclipse.cdt.dsf.mi.service.command;
@@ -77,6 +78,7 @@
7778
import org.eclipse.cdt.dsf.mi.service.command.commands.CLITraceDump;
7879
import org.eclipse.cdt.dsf.mi.service.command.commands.CLIUnsetEnv;
7980
import org.eclipse.cdt.dsf.mi.service.command.commands.CLIUnsetSubstitutePath;
81+
import org.eclipse.cdt.dsf.mi.service.command.commands.CLIVersion;
8082
import org.eclipse.cdt.dsf.mi.service.command.commands.MIAddInferior;
8183
import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakAfter;
8284
import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakCommands;
@@ -215,6 +217,7 @@
215217
import org.eclipse.cdt.dsf.mi.service.command.output.CLIThreadInfo;
216218
import org.eclipse.cdt.dsf.mi.service.command.output.CLITraceDumpInfo;
217219
import org.eclipse.cdt.dsf.mi.service.command.output.CLITraceInfo;
220+
import org.eclipse.cdt.dsf.mi.service.command.output.CLIVersionInfo;
218221
import org.eclipse.cdt.dsf.mi.service.command.output.MIAddInferiorInfo;
219222
import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakInsertInfo;
220223
import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakListInfo;
@@ -408,6 +411,11 @@ public ICommand<MIInfo> createCLIUnsetSubstitutePath(ISourceLookupDMContext ctx)
408411
return new CLIUnsetSubstitutePath(ctx);
409412
}
410413

414+
/** @since 7.2 */
415+
public ICommand<CLIVersionInfo> createCLIVersion(ICommandControlDMContext ctx) {
416+
return new CLIVersion(ctx);
417+
}
418+
411419
/** @since 4.0 */
412420
public ICommand<MIAddInferiorInfo> createMIAddInferior(ICommandControlDMContext ctx) {
413421
return new MIAddInferior(ctx);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 John Dallaway and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* John Dallaway - Initial implementation (#1186)
13+
*******************************************************************************/
14+
15+
package org.eclipse.cdt.dsf.mi.service.command.commands;
16+
17+
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
18+
import org.eclipse.cdt.dsf.mi.service.command.output.CLIVersionInfo;
19+
import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput;
20+
21+
/**
22+
* CLI 'version' command to report the debugger version where the MI -gdb-version command is not available
23+
*
24+
* @since 7.2
25+
*/
26+
public class CLIVersion extends CLICommand<CLIVersionInfo> {
27+
28+
private static final String VERSION = "version"; //$NON-NLS-1$
29+
30+
public CLIVersion(ICommandControlDMContext ctx) {
31+
super(ctx, VERSION);
32+
}
33+
34+
@Override
35+
public CLIVersionInfo getResult(MIOutput miResult) {
36+
return new CLIVersionInfo(miResult);
37+
}
38+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 John Dallaway and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* John Dallaway - Initial implementation (#1186)
13+
*******************************************************************************/
14+
15+
package org.eclipse.cdt.dsf.mi.service.command.output;
16+
17+
/**
18+
* CLI 'version' command returns the debugger version.
19+
*
20+
* sample output:
21+
*
22+
* (gdb) version
23+
* ~"lldb version 20.1.2\n"
24+
* ^done
25+
*
26+
* @since 7.2
27+
*/
28+
public class CLIVersionInfo extends MIInfo {
29+
30+
private String fFullOutput;
31+
32+
public CLIVersionInfo(MIOutput record) {
33+
super(record);
34+
parse();
35+
}
36+
37+
protected void parse() {
38+
if (isDone()) {
39+
MIOutput out = getMIOutput();
40+
MIOOBRecord[] records = out.getMIOOBRecords();
41+
StringBuilder builder = new StringBuilder();
42+
for (MIOOBRecord rec : records) {
43+
if (rec instanceof MIConsoleStreamOutput) {
44+
MIStreamRecord o = (MIStreamRecord) rec;
45+
builder.append(o.getString());
46+
}
47+
}
48+
fFullOutput = builder.toString();
49+
}
50+
}
51+
52+
public String getFullOutput() {
53+
return fFullOutput;
54+
}
55+
56+
}

llvm/org.eclipse.cdt.llvm.dsf.lldb.core/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-Vendor: %providerName
55
Bundle-SymbolicName: org.eclipse.cdt.llvm.dsf.lldb.core;singleton:=true
6-
Bundle-Version: 1.102.300.qualifier
6+
Bundle-Version: 1.102.400.qualifier
77
Bundle-RequiredExecutionEnvironment: JavaSE-17
88
Bundle-Localization: plugin
99
Require-Bundle: org.eclipse.debug.core;bundle-version="[3.23.0,4)",
10-
org.eclipse.cdt.dsf.gdb;bundle-version="[7.1.500,8)",
10+
org.eclipse.cdt.dsf.gdb;bundle-version="[7.2.0,8)",
1111
org.eclipse.cdt.launch;bundle-version="[11.0.0,12)",
1212
org.eclipse.core.runtime;bundle-version="[3.33.0,4)",
1313
org.eclipse.cdt.dsf;bundle-version="[2.12.200,3)",

llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/launching/LLDBFinalLaunchSequence.java

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,46 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016 Ericsson.
2+
* Copyright (c) 2016, 2025 Ericsson and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
66
* which accompanies this distribution, and is available at
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10+
* Contributors:
11+
* Ericsson - Initial implementation for LLDB
12+
* John Dallaway - Avoid unsupported MI commands (#1186)
1013
*******************************************************************************/
1114

1215
package org.eclipse.cdt.llvm.dsf.lldb.core.internal.launching;
1316

17+
import java.util.ArrayList;
18+
import java.util.Arrays;
19+
import java.util.List;
1420
import java.util.Map;
1521

22+
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
1623
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
1724
import org.eclipse.cdt.dsf.concurrent.RequestMonitorWithProgress;
1825
import org.eclipse.cdt.dsf.gdb.launching.FinalLaunchSequence_7_2;
26+
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
27+
import org.eclipse.cdt.dsf.mi.service.command.output.CLIVersionInfo;
28+
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
1929
import org.eclipse.cdt.dsf.service.DsfSession;
30+
import org.eclipse.cdt.llvm.dsf.lldb.core.internal.LLDBCorePlugin;
31+
import org.eclipse.core.runtime.IStatus;
32+
import org.eclipse.core.runtime.Status;
33+
import org.osgi.framework.BundleContext;
34+
import org.osgi.framework.FrameworkUtil;
2035

2136
/**
2237
* A LLDB-specific launch sequence that was initially created to work around the
2338
* fact that LLDB always has to run in async mode, even in all-stop.
2439
*/
2540
public class LLDBFinalLaunchSequence extends FinalLaunchSequence_7_2 {
2641

42+
private IGDBControl fCommandControl;
43+
2744
/**
2845
* Constructs the {@link LLDBFinalLaunchSequence}.
2946
*
@@ -39,12 +56,53 @@ public LLDBFinalLaunchSequence(DsfSession session, Map<String, Object> attribute
3956
super(session, attributes, rm);
4057
}
4158

42-
@Execute
4359
@Override
44-
public void stepSetNonStop(RequestMonitor requestMonitor) {
45-
// LLDB doesn't support non-stop and target-async cannot be disabled so
46-
// do not do anything in this step
60+
protected String[] getExecutionOrder(String group) {
61+
if (GROUP_TOP_LEVEL.equals(group)) {
62+
List<String> orderList = new ArrayList<>(Arrays.asList(super.getExecutionOrder(GROUP_TOP_LEVEL)));
63+
64+
orderList.add(orderList.indexOf("stepInitializeFinalLaunchSequence_7_2") + 1, //$NON-NLS-1$
65+
"stepInitializeLLDBFinalLaunchSequence"); //$NON-NLS-1$
66+
67+
// Remove or replace steps that are not supported by LLDB-MI
68+
orderList.set(orderList.indexOf("stepGDBVersion"), "stepVersion"); //$NON-NLS-1$ //$NON-NLS-2$
69+
orderList.remove(orderList.indexOf("stepSetNonStop")); //$NON-NLS-1$
70+
orderList.remove(orderList.indexOf("stepSetPrintObject")); //$NON-NLS-1$
71+
72+
return orderList.toArray(new String[orderList.size()]);
73+
}
74+
75+
return null;
76+
}
77+
78+
@Execute
79+
public void stepInitializeLLDBFinalLaunchSequence(RequestMonitor requestMonitor) {
80+
BundleContext bundleContext = FrameworkUtil.getBundle(LLDBFinalLaunchSequence.class).getBundleContext();
81+
DsfServicesTracker tracker = new DsfServicesTracker(bundleContext, getSession().getId());
82+
fCommandControl = tracker.getService(IGDBControl.class);
83+
tracker.dispose();
84+
if (fCommandControl == null) {
85+
requestMonitor.setStatus(
86+
new Status(IStatus.ERROR, LLDBCorePlugin.PLUGIN_ID, -1, "Cannot obtain control service", null)); //$NON-NLS-1$
87+
requestMonitor.done();
88+
return;
89+
}
4790
requestMonitor.done();
4891
}
4992

93+
/**
94+
* Print the version of LLDB reported by LLDB-MI.
95+
*/
96+
@Execute
97+
public void stepVersion(final RequestMonitor requestMonitor) {
98+
fCommandControl.queueCommand(fCommandControl.getCommandFactory().createCLIVersion(fCommandControl.getContext()),
99+
new DataRequestMonitor<CLIVersionInfo>(getExecutor(), requestMonitor) {
100+
@Override
101+
protected void handleCompleted() {
102+
// Accept failures
103+
requestMonitor.done();
104+
}
105+
});
106+
}
107+
50108
}

0 commit comments

Comments
 (0)