1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 245749 In the end, we decided to isolate the threadId to groupId map into the eventProcessor, and not crowd the IMIProcesses interface.

This commit is contained in:
Marc Khouzam 2008-09-15 19:42:12 +00:00
parent 2552eacead
commit 0fb7dec635
9 changed files with 92 additions and 132 deletions

View file

@ -97,12 +97,21 @@ public class GDBProcesses extends MIProcesses {
protected BundleContext getBundleContext() {
return GdbPlugin.getBundleContext();
}
@Override
public void getExecutionData(IThreadDMContext dmc, DataRequestMonitor<IThreadDMData> rm) {
if (dmc instanceof IMIProcessDMContext) {
String pidStr = ((IMIProcessDMContext)dmc).getProcId();
// In our context hierarchy we don't actually use the pid in this version, because in this version,
// we only debug a single process. This means we will not have a proper pid in all cases
// inside the context, so must find it another way. Note that this method is also called to find the name
// of processes to attach to, and in this case, we do have the proper pid.
if (pidStr == null || pidStr.length() == 0) {
MIInferiorProcess inferiorProcess = fGdb.getInferiorProcess();
if (inferiorProcess != null) {
pidStr = inferiorProcess.getPid();
}
}
int pid = -1;
try {
pid = Integer.parseInt(pidStr);
@ -110,7 +119,7 @@ public class GDBProcesses extends MIProcesses {
}
String name = fProcessNames.get(pid);
// If we don't find the name in our list, return the default name of our program
// If we still don't find the name in our list, return the default name of our program
if (name == null) name = fGdb.getExecutablePath().lastSegment();
rm.setData(new MIThreadDMData(name, pidStr));
rm.done();
@ -182,8 +191,7 @@ public class GDBProcesses extends MIProcesses {
// This service version only handles a single process to debug, therefore, we can simply
// create the context describing this process ourselves.
ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(dmc, ICommandControlDMContext.class);
// Get the groupId properly for the case of an attach
String groupId = getExecutionGroupIdFromThread(null);
String groupId = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = createProcessContext(controlDmc, groupId);
IMIExecutionGroupDMContext newGroupDmc = createExecutionGroupContext(procDmc, groupId);
rm.setData(new IContainerDMContext[] {newGroupDmc});
@ -262,21 +270,4 @@ public class GDBProcesses extends MIProcesses {
rm.done();
}
}
@Override
public String getExecutionGroupIdFromThread(String threadId) {
// We need to properly return the groupId based on the pid
// to properly handle the case of an attach. See bug 244749
String groupId = null;
MIInferiorProcess inferiorProcess = fGdb.getInferiorProcess();
if (inferiorProcess != null) {
groupId = inferiorProcess.getPid();
}
if (groupId != null) {
return groupId;
} else {
return super.getExecutionGroupIdFromThread(threadId);
}
}
}

View file

@ -325,8 +325,6 @@ public class GDBProcesses_7_0 extends AbstractDsfService implements IMIProcesses
// A map of process id to process names. It is filled when we get all the processes that are running
private Map<String, String> fProcessNames = new HashMap<String, String>();
// A map of thread id to thread group id. We use this to find out to which threadGroup a thread belongs.
private Map<String, String> fGroupIdMap = new HashMap<String, String>();
private static final String FAKE_THREAD_ID = "0"; //$NON-NLS-1$
@ -683,12 +681,6 @@ public class GDBProcesses_7_0 extends AbstractDsfService implements IMIProcesses
}
}
public String getExecutionGroupIdFromThread(String threadId) {
String groupId = fGroupIdMap.get(threadId);
if (groupId == null) return ""; //$NON-NLS-1$
else return groupId;
}
@DsfServiceEventHandler
public void eventDispatched(final MIThreadGroupCreatedEvent e) {
IProcessDMContext procDmc = e.getDMContext();
@ -752,13 +744,4 @@ public class GDBProcesses_7_0 extends AbstractDsfService implements IMIProcesses
fContainerCommandCache.reset(context);
fThreadCommandCache.reset(context);
}
public void addThreadId(String threadId, String groupId) {
fGroupIdMap.put(threadId, groupId);
}
public void removeThreadId(String threadId) {
fGroupIdMap.remove(threadId);
}
}

View file

@ -53,30 +53,5 @@ public interface IMIProcesses extends IProcesses
*/
IMIExecutionGroupDMContext createExecutionGroupContext(IProcessDMContext processDmc,
String groupId);
/**
* Retrieve the groupId to which this threadId belongs
*
* @param threadId The ID of the thread
* @return The ID of the group to which the specified thread belongs
*/
String getExecutionGroupIdFromThread(String threadId);
/**
* This method should be called when a new thread is created. It allows
* to keep track of the thread to group relationship.
*
* @param threadId The ID of the new thread
* @param groupId The ID of the group to which the new thread belongs
*/
void addThreadId(String threadId, String groupId);
/**
* This method should be called when a thread exits. It is meant
* to remove the thread to group entry.
*
* @param threadId The ID of the thread that exited
*/
void removeThreadId(String threadId);
}

View file

@ -302,7 +302,7 @@ public class MIProcesses extends AbstractDsfService implements IMIProcesses, ICa
private static final String FAKE_THREAD_ID = "0"; //$NON-NLS-1$
// The unique id should be an empty string so that the views know not to display the fake id
private static final String UNIQUE_GROUP_ID = ""; //$NON-NLS-1$
public static final String UNIQUE_GROUP_ID = ""; //$NON-NLS-1$
public MIProcesses(DsfSession session) {
super(session);
@ -553,8 +553,7 @@ public class MIProcesses extends AbstractDsfService implements IMIProcesses, ICa
// This service version only handles a single process to debug, therefore, we can simply
// create the context describing this process ourselves.
ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(dmc, ICommandControlDMContext.class);
// Get the groupId properly for the case of an attach
String groupId = getExecutionGroupIdFromThread(null);
String groupId = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = createProcessContext(controlDmc, groupId);
IMIExecutionGroupDMContext newGroupDmc = createExecutionGroupContext(procDmc, groupId);
rm.setData(new IContainerDMContext[] {newGroupDmc});
@ -606,10 +605,6 @@ public class MIProcesses extends AbstractDsfService implements IMIProcesses, ICa
NOT_SUPPORTED, "Not supported", null)); //$NON-NLS-1$
rm.done();
}
public String getExecutionGroupIdFromThread(String threadId) {
return UNIQUE_GROUP_ID;
}
@DsfServiceEventHandler
public void eventDispatched(IResumedDMEvent e) {
@ -648,15 +643,4 @@ public class MIProcesses extends AbstractDsfService implements IMIProcesses, ICa
public void flushCache(IDMContext context) {
fContainerCommandCache.reset(context);
}
public void addThreadId(String threadId, String groupId) {
// This version of the service does not support multiple
// processes, so there is nothing to do here
}
public void removeThreadId(String threadId) {
// This version of the service does not support multiple
// processes, so there is nothing to do here
}
}

View file

@ -32,6 +32,7 @@ import org.eclipse.dd.dsf.debug.service.command.ICommandControlService.ICommandC
import org.eclipse.dd.dsf.service.DsfServicesTracker;
import org.eclipse.dd.mi.internal.MIPlugin;
import org.eclipse.dd.mi.service.IMIProcesses;
import org.eclipse.dd.mi.service.MIProcesses;
import org.eclipse.dd.mi.service.command.commands.CLICommand;
import org.eclipse.dd.mi.service.command.commands.MIInterpreterExecConsole;
import org.eclipse.dd.mi.service.command.events.MIBreakpointChangedEvent;
@ -123,12 +124,14 @@ public class CLIEventProcessor
String threadId = Integer.toString(++fLastThreadId);
IMIProcesses procService = fServicesTracker.getService(IMIProcesses.class);
String groupId = procService.getExecutionGroupIdFromThread(threadId);
if (procService != null) {
String groupId = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
IContainerDMContext processContainerDmc = procService.createExecutionGroupContext(procDmc, groupId);
MIEvent<?> e = new MIThreadCreatedEvent(processContainerDmc, threadId);
fCommandControl.getSession().dispatchEvent(e, fCommandControl.getProperties());
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
IContainerDMContext processContainerDmc = procService.createExecutionGroupContext(procDmc, groupId);
MIEvent<?> e = new MIThreadCreatedEvent(processContainerDmc, threadId);
fCommandControl.getSession().dispatchEvent(e, fCommandControl.getProperties());
}
}
// For GDB thread exit events, we won't use the events generated by GDB. This event is
@ -173,12 +176,14 @@ public class CLIEventProcessor
if (type != -1) {
// if it was a step instruction set state running
IMIProcesses procService = fServicesTracker.getService(IMIProcesses.class);
String groupId = procService.getExecutionGroupIdFromThread(null);
if (procService != null) {
String groupId = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
IContainerDMContext processContainerDmc = procService.createExecutionGroupContext(procDmc, groupId);
MIEvent<?> event = new MIRunningEvent(processContainerDmc, token, type);
fCommandControl.getSession().dispatchEvent(event, fCommandControl.getProperties());
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
IContainerDMContext processContainerDmc = procService.createExecutionGroupContext(procDmc, groupId);
MIEvent<?> event = new MIRunningEvent(processContainerDmc, token, type);
fCommandControl.getSession().dispatchEvent(event, fCommandControl.getProperties());
}
}
}
@ -188,7 +193,7 @@ public class CLIEventProcessor
*/
private void processSettingChanges(CLICommand<?> cmd) {
String operation = cmd.getOperation().trim();
// In refactoring we are no longer genwerating the token id as
// In refactoring we are no longer generating the token id as
// part of the command. It is passed here and stored away and
// then never really used. So it has just been changed to 0.
processSettingChanges(cmd.getContext(), 0, operation);
@ -197,7 +202,7 @@ public class CLIEventProcessor
private void processSettingChanges(MIInterpreterExecConsole<?> exec) {
String[] operations = exec.getParameters();
if (operations != null && operations.length > 0) {
// In refactoring we are no longer genwerating the token id as
// In refactoring we are no longer generating the token id as
// part of the command. It is passed here and stored away and
// then never really used. So it has just been changed to 0.
processSettingChanges(exec.getContext(), 0, operations[0]);

View file

@ -28,6 +28,7 @@ import org.eclipse.dd.dsf.debug.service.command.ICommandControlService.ICommandC
import org.eclipse.dd.dsf.service.DsfServicesTracker;
import org.eclipse.dd.mi.internal.MIPlugin;
import org.eclipse.dd.mi.service.IMIProcesses;
import org.eclipse.dd.mi.service.MIProcesses;
import org.eclipse.dd.mi.service.command.commands.MIExecContinue;
import org.eclipse.dd.mi.service.command.commands.MIExecFinish;
import org.eclipse.dd.mi.service.command.commands.MIExecNext;
@ -136,7 +137,9 @@ public class MIRunControlEventProcessor
// "reason" ??? still fire a stopped event.
if (events.isEmpty()) {
MIEvent<?> e = createEvent(STOPPED_REASON, exec);
events.add(e);
if (e != null) {
events.add(e);
}
}
for (MIEvent<?> event : events) {
@ -149,7 +152,6 @@ public class MIRunControlEventProcessor
protected MIEvent<?> createEvent(String reason, MIExecAsyncOutput exec) {
String threadId = null;
String groupId = null;
MIResult[] results = exec.getMIResults();
for (int i = 0; i < results.length; i++) {
@ -164,8 +166,11 @@ public class MIRunControlEventProcessor
}
IMIProcesses procService = fServicesTracker.getService(IMIProcesses.class);
groupId = procService.getExecutionGroupIdFromThread(threadId);
if (procService == null) {
return null;
}
String groupId = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
IContainerDMContext processContainerDmc = procService.createExecutionGroupContext(procDmc, groupId);
@ -241,12 +246,14 @@ public class MIRunControlEventProcessor
else { type = MIRunningEvent.CONTINUE; }
IMIProcesses procService = fServicesTracker.getService(IMIProcesses.class);
String groupId = procService.getExecutionGroupIdFromThread(null);
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
IContainerDMContext processContainerDmc = procService.createExecutionGroupContext(procDmc, groupId);
if (procService != null) {
String groupId = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
IContainerDMContext processContainerDmc = procService.createExecutionGroupContext(procDmc, groupId);
fCommandControl.getSession().dispatchEvent(
new MIRunningEvent(processContainerDmc, id, type), fCommandControl.getProperties());
fCommandControl.getSession().dispatchEvent(
new MIRunningEvent(processContainerDmc, id, type), fCommandControl.getProperties());
}
} else if ("exit".equals(state)) { //$NON-NLS-1$
// No need to do anything, terminate() will.
// Send exited?

View file

@ -11,8 +11,10 @@
*******************************************************************************/
package org.eclipse.dd.mi.service.command;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.eclipse.dd.dsf.debug.service.IProcesses.IProcessDMContext;
import org.eclipse.dd.dsf.debug.service.IProcesses.IThreadDMContext;
@ -86,6 +88,11 @@ public class MIRunControlEventProcessor_7_0
private final DsfServicesTracker fServicesTracker;
/**
* A map of thread id to thread group id. We use this to find out to which threadGroup a thread belongs.
*/
private Map<String, String> fGroupIdMap = new HashMap<String, String>();
/**
* Creates the event processor and registers it as listener with the debugger
* control.
@ -142,7 +149,9 @@ public class MIRunControlEventProcessor_7_0
// "reason" ??? still fire a stopped event.
if (events.isEmpty()) {
MIEvent<?> e = createEvent(STOPPED_REASON, exec);
events.add(e);
if (e != null) {
events.add(e);
}
}
for (MIEvent<?> event : events) {
@ -177,30 +186,32 @@ public class MIRunControlEventProcessor_7_0
}
}
}
IMIProcesses procService = fServicesTracker.getService(IMIProcesses.class);
if ("thread-created".equals(miEvent)) { //$NON-NLS-1$
// Update the thread to groupId map with the new groupId
procService.addThreadId(threadId, groupId);
fGroupIdMap.put(threadId, groupId);
} else {
// It was not clear if MI would specify the groupId in the event
// It was not clear if MI would specify the groupId in the thread-exited event
if (groupId == null) {
groupId = procService.getExecutionGroupIdFromThread(threadId);
groupId = fGroupIdMap.get(threadId);
}
procService.removeThreadId(threadId);
fGroupIdMap.remove(threadId);
}
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
IContainerDMContext processContainerDmc = procService.createExecutionGroupContext(procDmc, groupId);
IMIProcesses procService = fServicesTracker.getService(IMIProcesses.class);
MIEvent<?> event = null;
if ("thread-created".equals(miEvent)) { //$NON-NLS-1$
event = new MIThreadCreatedEvent(processContainerDmc, exec.getToken(), threadId);
} else if ("thread-exited".equals(miEvent)) { //$NON-NLS-1$
event = new MIThreadExitEvent(processContainerDmc, exec.getToken(), threadId);
}
fCommandControl.getSession().dispatchEvent(event, fCommandControl.getProperties());
if (procService != null) {
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
IContainerDMContext processContainerDmc = procService.createExecutionGroupContext(procDmc, groupId);
MIEvent<?> event = null;
if ("thread-created".equals(miEvent)) { //$NON-NLS-1$
event = new MIThreadCreatedEvent(processContainerDmc, exec.getToken(), threadId);
} else if ("thread-exited".equals(miEvent)) { //$NON-NLS-1$
event = new MIThreadExitEvent(processContainerDmc, exec.getToken(), threadId);
}
fCommandControl.getSession().dispatchEvent(event, fCommandControl.getProperties());
}
} else if ("thread-group-created".equals(miEvent) || "thread-group-exited".equals(miEvent)) { //$NON-NLS-1$ //$NON-NLS-2$
String groupId = null;
@ -216,8 +227,8 @@ public class MIRunControlEventProcessor_7_0
}
}
if (groupId != null) {
IMIProcesses procService = fServicesTracker.getService(IMIProcesses.class);
IMIProcesses procService = fServicesTracker.getService(IMIProcesses.class);
if (groupId != null && procService != null) {
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
MIEvent<?> event = null;
@ -255,10 +266,13 @@ public class MIRunControlEventProcessor_7_0
}
IMIProcesses procService = fServicesTracker.getService(IMIProcesses.class);
if (procService == null) {
return null;
}
// MI does not currently provide the group-id in these events
if (groupId == null) {
groupId = procService.getExecutionGroupIdFromThread(threadId);
groupId = fGroupIdMap.get(threadId);
}
IProcessDMContext procDmc = procService.createProcessContext(fControlDmc, groupId);
IContainerDMContext processContainerDmc = procService.createExecutionGroupContext(procDmc, groupId);

View file

@ -108,9 +108,9 @@ public class GDBProcessesTest extends BaseTestCase {
*/
fSession.getExecutor().submit(new Runnable() {
public void run() {
String pid = fProcService.getExecutionGroupIdFromThread(null);
String groupId = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = fProcService.createProcessContext(fGdbCtrl.getContext(), pid);
IProcessDMContext procDmc = fProcService.createProcessContext(fGdbCtrl.getContext(), groupId);
fProcService.getExecutionData(procDmc, rm);
}
});
@ -158,7 +158,7 @@ public class GDBProcessesTest extends BaseTestCase {
fProcService.getExecutor().submit(new Runnable() {
public void run() {
String groupId = fProcService.getExecutionGroupIdFromThread(THREAD_ID);
String groupId = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = fProcService.createProcessContext(fGdbCtrl.getContext(), groupId);
IThreadDMContext threadDmc = fProcService.createThreadContext(procDmc, THREAD_ID);
fProcService.getExecutionData(threadDmc, rm);

View file

@ -28,6 +28,7 @@ import org.eclipse.dd.gdb.internal.provisional.service.command.GDBControlDMConte
import org.eclipse.dd.gdb.internal.provisional.service.command.IGDBControl;
import org.eclipse.dd.mi.service.IMIExecutionDMContext;
import org.eclipse.dd.mi.service.IMIProcesses;
import org.eclipse.dd.mi.service.MIProcesses;
import org.eclipse.dd.mi.service.MIRunControl;
import org.eclipse.dd.mi.service.command.events.MIStoppedEvent;
import org.eclipse.dd.mi.service.command.output.MIInfo;
@ -115,7 +116,7 @@ public class MIRunControlTest extends BaseTestCase {
*/
fRunCtrl.getExecutor().submit(new Runnable() {
public void run() {
String pid = fProcService.getExecutionGroupIdFromThread(null);
String pid = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = fProcService.createProcessContext(fGDBCtrl.getContext(), pid);
IContainerDMContext groupDmc = fProcService.createExecutionGroupContext(procDmc, pid);
fRunCtrl.getExecutionContexts(groupDmc, rm);
@ -201,7 +202,7 @@ public class MIRunControlTest extends BaseTestCase {
*/
fRunCtrl.getExecutor().submit(new Runnable() {
public void run() {
String pid = fProcService.getExecutionGroupIdFromThread(null);
String pid = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = fProcService.createProcessContext(fGDBCtrl.getContext(), pid);
IContainerDMContext groupDmc = fProcService.createExecutionGroupContext(procDmc, pid);
fRunCtrl.getExecutionContexts(groupDmc, rmExecutionCtxts);
@ -253,7 +254,7 @@ public class MIRunControlTest extends BaseTestCase {
*/
fRunCtrl.getExecutor().submit(new Runnable() {
public void run() {
String pid = fProcService.getExecutionGroupIdFromThread(null);
String pid = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = fProcService.createProcessContext(fGDBCtrl.getContext(), pid);
IContainerDMContext groupDmc = fProcService.createExecutionGroupContext(procDmc, pid);
fRunCtrl.getExecutionData(fRunCtrl.createMIExecutionContext(groupDmc, 1), rm);
@ -472,7 +473,7 @@ public class MIRunControlTest extends BaseTestCase {
fRunCtrl.getExecutor().submit(new Runnable() {
public void run() {
String pid = fProcService.getExecutionGroupIdFromThread(null);
String pid = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = fProcService.createProcessContext(fGDBCtrl.getContext(), pid);
IContainerDMContext groupDmc = fProcService.createExecutionGroupContext(procDmc, pid);
fRunCtrl.resume(groupDmc, rm);
@ -492,7 +493,7 @@ public class MIRunControlTest extends BaseTestCase {
wait.waitReset();
fRunCtrl.getExecutor().submit(new Runnable() {
public void run() {
String pid = fProcService.getExecutionGroupIdFromThread(null);
String pid = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = fProcService.createProcessContext(fGDBCtrl.getContext(), pid);
IContainerDMContext groupDmc = fProcService.createExecutionGroupContext(procDmc, pid);
@ -547,7 +548,7 @@ public class MIRunControlTest extends BaseTestCase {
wait.waitReset();
fRunCtrl.getExecutor().submit(new Runnable() {
public void run() {
String pid = fProcService.getExecutionGroupIdFromThread(null);
String pid = MIProcesses.UNIQUE_GROUP_ID;
IProcessDMContext procDmc = fProcService.createProcessContext(fGDBCtrl.getContext(), pid);
IContainerDMContext groupDmc = fProcService.createExecutionGroupContext(procDmc, pid);