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
1215package 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 ;
1420import java .util .Map ;
1521
22+ import org .eclipse .cdt .dsf .concurrent .DataRequestMonitor ;
1623import org .eclipse .cdt .dsf .concurrent .RequestMonitor ;
1724import org .eclipse .cdt .dsf .concurrent .RequestMonitorWithProgress ;
1825import 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 ;
1929import 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 */
2540public 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