From 7479f4ddcf9ff0d80c4009cf9a2005022cfb9b77 Mon Sep 17 00:00:00 2001 From: John Dallaway Date: Fri, 6 Jun 2025 14:22:45 +0100 Subject: [PATCH] Report LLDB version and clean up LLDB-MI launch sequence We use CLI 'version' to replace the MI '-gdb-version' command. --- .../META-INF/MANIFEST.MF | 2 +- .../mi/service/command/CommandFactory.java | 10 ++- .../service/command/commands/CLIVersion.java | 38 +++++++++++ .../command/output/CLIVersionInfo.java | 56 +++++++++++++++ .../META-INF/MANIFEST.MF | 4 +- .../launching/LLDBFinalLaunchSequence.java | 68 +++++++++++++++++-- 6 files changed, 169 insertions(+), 9 deletions(-) create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/CLIVersion.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/CLIVersionInfo.java diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF b/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF index 097da978946..b48a0e54176 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.cdt.dsf.gdb;singleton:=true -Bundle-Version: 7.1.700.qualifier +Bundle-Version: 7.2.0.qualifier Bundle-Activator: org.eclipse.cdt.dsf.gdb.internal.GdbPlugin Bundle-Localization: plugin Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.33.0,4)", 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 e004b76cc62..3ca89a36e2f 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 QNX Software Systems and others. + * Copyright (c) 2000, 2025 QNX Software Systems and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -31,6 +31,7 @@ * Marc Khouzam (Ericsson) - Support for -gdb-version (Bug 455408) * Intel Corporation - Added Reverse Debugging BTrace support * Samuel Hultgren (STMicroelectronics) - Bug 533771 + * John Dallaway - Add CLI version command (#1186) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command; @@ -77,6 +78,7 @@ import org.eclipse.cdt.dsf.mi.service.command.commands.CLITrace; import org.eclipse.cdt.dsf.mi.service.command.commands.CLITraceDump; import org.eclipse.cdt.dsf.mi.service.command.commands.CLIUnsetEnv; import org.eclipse.cdt.dsf.mi.service.command.commands.CLIUnsetSubstitutePath; +import org.eclipse.cdt.dsf.mi.service.command.commands.CLIVersion; import org.eclipse.cdt.dsf.mi.service.command.commands.MIAddInferior; import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakAfter; import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakCommands; @@ -215,6 +217,7 @@ import org.eclipse.cdt.dsf.mi.service.command.output.CLIShowEndianInfo; import org.eclipse.cdt.dsf.mi.service.command.output.CLIThreadInfo; import org.eclipse.cdt.dsf.mi.service.command.output.CLITraceDumpInfo; import org.eclipse.cdt.dsf.mi.service.command.output.CLITraceInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.CLIVersionInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIAddInferiorInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakInsertInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakListInfo; @@ -408,6 +411,11 @@ public class CommandFactory { return new CLIUnsetSubstitutePath(ctx); } + /** @since 7.2 */ + public ICommand createCLIVersion(ICommandControlDMContext ctx) { + return new CLIVersion(ctx); + } + /** @since 4.0 */ public ICommand createMIAddInferior(ICommandControlDMContext ctx) { return new MIAddInferior(ctx); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/CLIVersion.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/CLIVersion.java new file mode 100644 index 00000000000..95a8e2e6e44 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/CLIVersion.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2025 John Dallaway 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: + * John Dallaway - Initial implementation (#1186) + *******************************************************************************/ + +package org.eclipse.cdt.dsf.mi.service.command.commands; + +import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; +import org.eclipse.cdt.dsf.mi.service.command.output.CLIVersionInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput; + +/** + * CLI 'version' command to report the debugger version where the MI -gdb-version command is not available + * + * @since 7.2 + */ +public class CLIVersion extends CLICommand { + + private static final String VERSION = "version"; //$NON-NLS-1$ + + public CLIVersion(ICommandControlDMContext ctx) { + super(ctx, VERSION); + } + + @Override + public CLIVersionInfo getResult(MIOutput miResult) { + return new CLIVersionInfo(miResult); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/CLIVersionInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/CLIVersionInfo.java new file mode 100644 index 00000000000..700a89d78be --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/CLIVersionInfo.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2025 John Dallaway 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: + * John Dallaway - Initial implementation (#1186) + *******************************************************************************/ + +package org.eclipse.cdt.dsf.mi.service.command.output; + +/** + * CLI 'version' command returns the debugger version. + * + * sample output: + * + * (gdb) version + * ~"lldb version 20.1.2\n" + * ^done + * + * @since 7.2 + */ +public class CLIVersionInfo extends MIInfo { + + private String fFullOutput; + + public CLIVersionInfo(MIOutput record) { + super(record); + parse(); + } + + protected void parse() { + if (isDone()) { + MIOutput out = getMIOutput(); + MIOOBRecord[] records = out.getMIOOBRecords(); + StringBuilder builder = new StringBuilder(); + for (MIOOBRecord rec : records) { + if (rec instanceof MIConsoleStreamOutput) { + MIStreamRecord o = (MIStreamRecord) rec; + builder.append(o.getString()); + } + } + fFullOutput = builder.toString(); + } + } + + public String getFullOutput() { + return fFullOutput; + } + +} diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/META-INF/MANIFEST.MF b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/META-INF/MANIFEST.MF index 44366dd20d4..102a222ffcb 100644 --- a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/META-INF/MANIFEST.MF +++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/META-INF/MANIFEST.MF @@ -3,11 +3,11 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.cdt.llvm.dsf.lldb.core;singleton:=true -Bundle-Version: 1.102.300.qualifier +Bundle-Version: 1.102.400.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-Localization: plugin Require-Bundle: org.eclipse.debug.core;bundle-version="[3.23.0,4)", - org.eclipse.cdt.dsf.gdb;bundle-version="[7.1.500,8)", + org.eclipse.cdt.dsf.gdb;bundle-version="[7.2.0,8)", org.eclipse.cdt.launch;bundle-version="[11.0.0,12)", org.eclipse.core.runtime;bundle-version="[3.33.0,4)", org.eclipse.cdt.dsf;bundle-version="[2.12.200,3)", diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/launching/LLDBFinalLaunchSequence.java b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/launching/LLDBFinalLaunchSequence.java index 674970bc62e..8ad88ffa9a5 100644 --- a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/launching/LLDBFinalLaunchSequence.java +++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/launching/LLDBFinalLaunchSequence.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Ericsson. + * Copyright (c) 2016, 2025 Ericsson and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,16 +7,31 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 + * Contributors: + * Ericsson - Initial implementation for LLDB + * John Dallaway - Avoid unsupported MI commands (#1186) *******************************************************************************/ package org.eclipse.cdt.llvm.dsf.lldb.core.internal.launching; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Map; +import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitorWithProgress; import org.eclipse.cdt.dsf.gdb.launching.FinalLaunchSequence_7_2; +import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; +import org.eclipse.cdt.dsf.mi.service.command.output.CLIVersionInfo; +import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.cdt.llvm.dsf.lldb.core.internal.LLDBCorePlugin; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; /** * A LLDB-specific launch sequence that was initially created to work around the @@ -24,6 +39,8 @@ import org.eclipse.cdt.dsf.service.DsfSession; */ public class LLDBFinalLaunchSequence extends FinalLaunchSequence_7_2 { + private IGDBControl fCommandControl; + /** * Constructs the {@link LLDBFinalLaunchSequence}. * @@ -39,12 +56,53 @@ public class LLDBFinalLaunchSequence extends FinalLaunchSequence_7_2 { super(session, attributes, rm); } - @Execute @Override - public void stepSetNonStop(RequestMonitor requestMonitor) { - // LLDB doesn't support non-stop and target-async cannot be disabled so - // do not do anything in this step + protected String[] getExecutionOrder(String group) { + if (GROUP_TOP_LEVEL.equals(group)) { + List orderList = new ArrayList<>(Arrays.asList(super.getExecutionOrder(GROUP_TOP_LEVEL))); + + orderList.add(orderList.indexOf("stepInitializeFinalLaunchSequence_7_2") + 1, //$NON-NLS-1$ + "stepInitializeLLDBFinalLaunchSequence"); //$NON-NLS-1$ + + // Remove or replace steps that are not supported by LLDB-MI + orderList.set(orderList.indexOf("stepGDBVersion"), "stepVersion"); //$NON-NLS-1$ //$NON-NLS-2$ + orderList.remove(orderList.indexOf("stepSetNonStop")); //$NON-NLS-1$ + orderList.remove(orderList.indexOf("stepSetPrintObject")); //$NON-NLS-1$ + + return orderList.toArray(new String[orderList.size()]); + } + + return null; + } + + @Execute + public void stepInitializeLLDBFinalLaunchSequence(RequestMonitor requestMonitor) { + BundleContext bundleContext = FrameworkUtil.getBundle(LLDBFinalLaunchSequence.class).getBundleContext(); + DsfServicesTracker tracker = new DsfServicesTracker(bundleContext, getSession().getId()); + fCommandControl = tracker.getService(IGDBControl.class); + tracker.dispose(); + if (fCommandControl == null) { + requestMonitor.setStatus( + new Status(IStatus.ERROR, LLDBCorePlugin.PLUGIN_ID, -1, "Cannot obtain control service", null)); //$NON-NLS-1$ + requestMonitor.done(); + return; + } requestMonitor.done(); } + /** + * Print the version of LLDB reported by LLDB-MI. + */ + @Execute + public void stepVersion(final RequestMonitor requestMonitor) { + fCommandControl.queueCommand(fCommandControl.getCommandFactory().createCLIVersion(fCommandControl.getContext()), + new DataRequestMonitor(getExecutor(), requestMonitor) { + @Override + protected void handleCompleted() { + // Accept failures + requestMonitor.done(); + } + }); + } + }