Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 314628 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/cdt/dsf/mi/service/IMIRunControl.java (-1 / +1 lines)
Lines 28-34 Link Here
28
	 * to receive commands.  Once the specified steps are executed, the target should be
28
	 * to receive commands.  Once the specified steps are executed, the target should be
29
	 * returned to its original availability.
29
	 * returned to its original availability.
30
	 * 
30
	 * 
31
	 * This can is of value for breakpoints commands; e.g., breakpoints need to be inserted
31
	 * This is of value for breakpoints commands; e.g., breakpoints need to be inserted
32
	 * even when the target is running, so this call would suspend the target, insert the
32
	 * even when the target is running, so this call would suspend the target, insert the
33
	 * breakpoint, and resume the target again.
33
	 * breakpoint, and resume the target again.
34
	 * 
34
	 * 
(-)src/org/eclipse/cdt/dsf/mi/service/MIRunControl.java (-11 / +31 lines)
Lines 908-924 Link Here
908
	/**
908
	/**
909
	 * @since 3.0
909
	 * @since 3.0
910
	 */
910
	 */
911
	public void executeWithTargetAvailable(IDMContext ctx, Sequence.Step[] steps, RequestMonitor rm) {
911
	public void executeWithTargetAvailable(IDMContext ctx, Sequence.Step[] steps, final RequestMonitor rm) {
912
		Vector<Step> totalStepsVector = new Vector<Step>();
912
		Vector<Step> totalStepsVector = new Vector<Step>();
913
		totalStepsVector.add(new IsTargetAvailableStep(ctx));
913
		totalStepsVector.add(new IsTargetAvailableStep(ctx));
914
		totalStepsVector.add(new MakeTargetAvailableStep());
914
		totalStepsVector.add(new MakeTargetAvailableStep());
915
		for (Step step : steps) {
915
		for (Step step : steps) {
916
			totalStepsVector.add(step);
916
			totalStepsVector.add(step);
917
		}
917
		}
918
		totalStepsVector.add(new RestoreTargetStateStep());
918
		
919
		// This RM makes sure that even if the sequence fails, we restore
920
		// the target if necessary (bug 314628)
921
		RequestMonitor cleanupRm = new RequestMonitor(getExecutor(), rm) {
922
			@Override
923
			protected void handleCompleted() {
924
				// Pass the status from the sequence the actual rm
925
				rm.setStatus(getStatus());
926
				restoreTargetState(new RequestMonitor(getExecutor(), rm));
927
			}
928
		};
919
		
929
		
920
		final Step[] totalSteps = totalStepsVector.toArray(new Step[totalStepsVector.size()]);
930
		final Step[] totalSteps = totalStepsVector.toArray(new Step[totalStepsVector.size()]);
921
		getExecutor().execute(new Sequence(getExecutor(), rm) {
931
		getExecutor().execute(new Sequence(getExecutor(), cleanupRm) {
922
			@Override public Step[] getSteps() { return totalSteps; }
932
			@Override public Step[] getSteps() { return totalSteps; }
923
		});
933
		});
924
	}
934
	}
Lines 934-941 Link Here
934
	 * and https://bugs.eclipse.org/bugs/show_bug.cgi?id=282273
944
	 * and https://bugs.eclipse.org/bugs/show_bug.cgi?id=282273
935
	 * 
945
	 * 
936
	 * ******************************************************************************/
946
	 * ******************************************************************************/
937
	private IContainerDMContext fContainerDmc  = null;
947
	private IContainerDMContext fContainerDmc;
938
	private boolean fTargetAvailable = false;
948
	private boolean fTargetAvailable;
949
	private boolean fMustResumeTarget;
939
950
940
	/**
951
	/**
941
	 * Returns whether the target is available to perform operations
952
	 * Returns whether the target is available to perform operations
Lines 1002-1026 Link Here
1002
				suspend(getContextToSuspend(), 
1013
				suspend(getContextToSuspend(), 
1003
						new RequestMonitor(getExecutor(), rm) {
1014
						new RequestMonitor(getExecutor(), rm) {
1004
					@Override
1015
					@Override
1016
					protected void handleSuccess() {
1017
						fMustResumeTarget = true;
1018
						super.handleSuccess();
1019
					}
1020
					@Override
1005
					protected void handleFailure() {
1021
					protected void handleFailure() {
1006
						// We weren't able to suspend, so abort the operation
1022
						// We weren't able to suspend, so abort the operation
1007
						fDisableNextSignalEvent = false;
1023
						fDisableNextSignalEvent = false;
1024
						fMustResumeTarget = false;
1008
						super.handleFailure();
1025
						super.handleFailure();
1009
					};
1026
					};
1010
				});
1027
				});
1011
			} else {
1028
			} else {
1029
				fMustResumeTarget = false;
1012
				rm.done();
1030
				rm.done();
1013
			}
1031
			}
1014
		}
1032
		}
1015
	};
1033
	};
1016
1034
1017
	/**
1035
	/**
1036
	 * This method is called outside of the sequence to make sure
1037
	 * we properly restore the target state.
1038
	 * 
1018
	 * @since 3.0
1039
	 * @since 3.0
1019
	 */
1040
	 */
1020
	protected class RestoreTargetStateStep extends Sequence.Step {
1041
	protected void restoreTargetState(RequestMonitor rm) {
1021
		@Override
1042
			if (fMustResumeTarget) {
1022
		public void execute(final RequestMonitor rm) {
1023
			if (!isTargetAvailable()) {
1024
				assert fDisableNextRunningEvent == false;
1043
				assert fDisableNextRunningEvent == false;
1025
				fDisableNextRunningEvent = true;
1044
				fDisableNextRunningEvent = true;
1026
				
1045
				
Lines 1031-1036 Link Here
1031
						new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
1050
						new DataRequestMonitor<MIInfo>(getExecutor(), rm) {
1032
							@Override
1051
							@Override
1033
							protected void handleSuccess() {
1052
							protected void handleSuccess() {
1053
								fMustResumeTarget = false;
1034
								fSilencedSignalEvent = null;
1054
								fSilencedSignalEvent = null;
1035
								super.handleSuccess();
1055
								super.handleSuccess();
1036
							}
1056
							}
Lines 1039-1045 Link Here
1039
							protected void handleFailure() {
1059
							protected void handleFailure() {
1040
								// Darn, we're unable to restart the target.  Must cleanup!
1060
								// Darn, we're unable to restart the target.  Must cleanup!
1041
								fDisableNextRunningEvent = false;
1061
								fDisableNextRunningEvent = false;
1042
								
1062
								fMustResumeTarget = false;
1063
1043
								// We must also sent the Stopped event that we had kept silent
1064
								// We must also sent the Stopped event that we had kept silent
1044
								if (fSilencedSignalEvent != null) {
1065
								if (fSilencedSignalEvent != null) {
1045
									eventDispatched(fSilencedSignalEvent);
1066
									eventDispatched(fSilencedSignalEvent);
Lines 1058-1064 Link Here
1058
				rm.done();
1079
				rm.done();
1059
			}
1080
			}
1060
		}
1081
		}
1061
	 };
1062
1082
1063
	/**
1083
	/**
1064
	 * {@inheritDoc}
1084
	 * {@inheritDoc}
(-)src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java (+48 lines)
Lines 1238-1243 Link Here
1238
				   ((MIBreakpointHitEvent)event).getNumber() == ref.getReference());
1238
				   ((MIBreakpointHitEvent)event).getNumber() == ref.getReference());
1239
	}
1239
	}
1240
	
1240
	
1241
	// ------------------------------------------------------------------------
1242
	// insertInvalidBreakpoint_WhileTargetRunning
1243
	// Set an invalid breakpoint while the target is running, then set a valid
1244
	// breakpoint and make sure the second breakpoints eventually gets hit.
1245
	//
1246
	// We had a problem where an invalid breakpoint set when the target was running
1247
	// would leave us in a bad state (Bug 314628)
1248
	// ------------------------------------------------------------------------
1249
	@Test
1250
	public void insertInvalidBreakpoint_WhileTargetRunning() throws Throwable {
1251
1252
		// Create a line breakpoint
1253
		Map<String, Object> breakpoint = new HashMap<String, Object>();
1254
		breakpoint.put(BREAKPOINT_TYPE_TAG, BREAKPOINT_TAG);
1255
		breakpoint.put(FILE_NAME_TAG, "Bad file name");
1256
		breakpoint.put(LINE_NUMBER_TAG, LINE_NUMBER_5);
1257
1258
		// Run the program. It will make a two second sleep() call, during which time... 
1259
		SyncUtil.resume();
1260
1261
		// ...we install the bad breakpoint and check that it failed
1262
		insertBreakpoint(fBreakpointsDmc, breakpoint);
1263
		assertTrue(fWait.getMessage(), !fWait.isOK());
1264
1265
		// Now install a proper breakpoint an see that it hits without having to resume
1266
		// the target.  This will show that the target was still properly running.
1267
		breakpoint.put(FILE_NAME_TAG, SOURCE_FILE);
1268
		MIBreakpointDMContext ref = (MIBreakpointDMContext) insertBreakpoint(fBreakpointsDmc, breakpoint);
1269
1270
		// Wait for breakpoint to hit.
1271
		MIStoppedEvent event = waitForBreakpointEventsAfterBreakpointOperationWhileTargetRunning(true, 2);
1272
		
1273
    	// Ensure the correct BreakpointEvent was received
1274
		MIBreakpointDMData breakpoint1 = (MIBreakpointDMData) getBreakpoint(ref);
1275
		assertTrue("BreakpointEvent problem: expected " + 2 + " BREAKPOINT event(s), received "
1276
				+ fBreakpointEventCount, fBreakpointEventCount == 2);
1277
		assertTrue("BreakpointEvent problem: expected " + 1 + " BREAKPOINT_HIT event(s), received "
1278
				+ getBreakpointEventCount(BP_HIT), getBreakpointEventCount(BP_HIT) == 1);
1279
		assertTrue("BreakpointService problem: breakpoint mismatch",
1280
				fBreakpointRef == breakpoint1.getNumber());
1281
		clearEventCounters();
1282
		
1283
		assertTrue("Did not stop because of breakpoint, but stopped because of: " +
1284
				event.getClass().getCanonicalName(), event instanceof MIBreakpointHitEvent);
1285
		assertTrue("Did not stop because of the correct breakpoint at line " + LINE_NUMBER_5,
1286
				   ((MIBreakpointHitEvent)event).getNumber() == ref.getReference());
1287
	}
1288
	
1241
	///////////////////////////////////////////////////////////////////////////
1289
	///////////////////////////////////////////////////////////////////////////
1242
	// Add Watchpoint tests
1290
	// Add Watchpoint tests
1243
	///////////////////////////////////////////////////////////////////////////
1291
	///////////////////////////////////////////////////////////////////////////

Return to bug 314628