Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1cd49b35ac58de4fa5260c345b253829e3829f09 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*******************************************************************************
 * Copyright (c) 2016 Ericsson 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
 *******************************************************************************/
package org.eclipse.cdt.dsf.gdb.service;

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.DsfExecutor;
import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext;
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakpoint;
import org.eclipse.cdt.dsf.service.DsfServicesTracker;

/**
 * @since 5.2
 */
public class StartOrRestartProcessSequence_7_12 extends StartOrRestartProcessSequence_7_10 {
	private GDBRunControl_7_12 fReverseService;

	public StartOrRestartProcessSequence_7_12(DsfExecutor executor, IContainerDMContext containerDmc,
			Map<String, Object> attributes, boolean restart, DataRequestMonitor<IContainerDMContext> rm) {
		super(executor, containerDmc, attributes, restart, rm);
	}

	/**
	 * Initialize the members of the StartOrRestartProcessSequence_7_12 class.
	 * This step is mandatory for the rest of the sequence to complete.
	 */
	@Override
	@Execute
	public void stepInitializeBaseSequence(final RequestMonitor rm) {
		super.stepInitializeBaseSequence(new ImmediateRequestMonitor(rm) {
			@Override
			protected void handleSuccess() {
				DsfServicesTracker tracker = new DsfServicesTracker(GdbPlugin.getBundleContext(),
						getContainerContext().getSessionId());
				fReverseService = tracker.getService(GDBRunControl_7_12.class);
				tracker.dispose();
				rm.done();
			}
		});
	}

	@Override
	protected String[] getExecutionOrder(String group) {
		if (GROUP_TOP_LEVEL.equals(group)) {
			// Initialize the list with the base class' steps
			// We need to create a list that we can modify, which is why we create our own ArrayList.
			List<String> orderList = new ArrayList<>(Arrays.asList(super.getExecutionOrder(GROUP_TOP_LEVEL)));

			// Need to insert reverse mode off before ordering the reverse start at a specified location
			orderList.add(orderList.indexOf("stepCreateConsole") + 1, "stepSetReverseOff2"); //$NON-NLS-1$ //$NON-NLS-2$

			// Order the activation of reverse debugging before starting the program, it will be executed once the
			// program stops at the specified location.
			orderList.add(orderList.indexOf("stepSetReverseOff2") + 1, "stepSetReverseModeAtLocation"); //$NON-NLS-1$ //$NON-NLS-2$

			return orderList.toArray(new String[orderList.size()]);
		}

		return null;
	}

	@Execute
	public void stepSetReverseOff2(RequestMonitor rm) {
		super.stepSetReverseOff(rm);
	}

	/**
	 * Request the enabling of reverse debugging, it will be applied once the program
	 * stops at the breakpoint inserted for reverse debugging
	 */
	@Execute
	public void stepSetReverseModeAtLocation(final RequestMonitor rm) {
		MIBreakpoint bp = getBreakPointForReverse();
		if (getReverseEnabled() && fReverseService != null && bp != null) {
			// Order to continue execution if there is no user break point inserted at main
			fReverseService.enableReverseModeAtBpLocation(getContainerContext(), getReverseMode(), bp,
					!getUserBreakpointIsOnMain());
		}
		rm.done();
	}

	/*
	 * We have scheduled the start of reverse debug, so we shall skip this method from super class
	 */
	@Override
	@Execute
	public void stepSetReverseMode(RequestMonitor rm) {
		rm.done();
	}

	/*
	 * We have scheduled the start of reverse debug, so we shall skip this method from super class
	 */
	@Override
	@Execute
	public void stepEnableReverse(RequestMonitor rm) {
		rm.done();
	}

	/*
	 * The order to continue or not has been included with the order to start reverse debugging at a specific location
	 * so we shall skip this method from super class
	 */
	@Override
	@Execute
	public void stepContinue(RequestMonitor rm) {
		rm.done();
	}

}

Back to the top