mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
[303503] Cannot rely on a GDB command to know the list of processes being debugged, because GDB is not available when the program is running. We can use =thread-group-created and =thread-group-exited events to keep our own list instead.
This commit is contained in:
parent
d8ba081c40
commit
657ecd8e53
1 changed files with 24 additions and 25 deletions
|
@ -393,7 +393,10 @@ public class GDBProcesses_7_0 extends AbstractDsfService
|
||||||
// debugging a process, and removed when we stop.
|
// debugging a process, and removed when we stop.
|
||||||
// This allows us to make sure that if a pid is re-used, we will not use an
|
// This allows us to make sure that if a pid is re-used, we will not use an
|
||||||
// old name for it. Bug 275497
|
// old name for it. Bug 275497
|
||||||
private Map<String, String> fDebuggedProcessNames = new HashMap<String, String>();
|
// This map also serves as a list of processes we are currently debugging.
|
||||||
|
// This is important because we cannot always ask GDB for the list, since it may
|
||||||
|
// be running at the time. Bug 303503
|
||||||
|
private Map<String, String> fDebuggedProcessesAndNames = new HashMap<String, String>();
|
||||||
|
|
||||||
private static final String FAKE_THREAD_ID = "0"; //$NON-NLS-1$
|
private static final String FAKE_THREAD_ID = "0"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -561,10 +564,15 @@ public class GDBProcesses_7_0 extends AbstractDsfService
|
||||||
// I haven't found a good way to get the pid yet, so let's not show it.
|
// I haven't found a good way to get the pid yet, so let's not show it.
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
name = fDebuggedProcessNames.get(id);
|
name = fDebuggedProcessesAndNames.get(id);
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
// We don't have the name in our map. Should not happen.
|
// We don't have the name in our map. Should not happen.
|
||||||
name = "Unknown name"; //$NON-NLS-1$
|
name = "Unknown name"; //$NON-NLS-1$
|
||||||
|
} else if (name.length() == 0) {
|
||||||
|
// Return the default name of our program.
|
||||||
|
IGDBBackend backend = getServicesTracker().getService(IGDBBackend.class);
|
||||||
|
name = backend.getProgramPath().toOSString();
|
||||||
|
fDebuggedProcessesAndNames.put(id, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rm.setData(new MIThreadDMData(name, id));
|
rm.setData(new MIThreadDMData(name, id));
|
||||||
|
@ -720,15 +728,14 @@ public class GDBProcesses_7_0 extends AbstractDsfService
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
fContainerCommandCache.execute(
|
IMIContainerDMContext[] containerDmcs = new IMIContainerDMContext[fDebuggedProcessesAndNames.size()];
|
||||||
new MIListThreadGroups(controlDmc),
|
int i = 0;
|
||||||
new DataRequestMonitor<MIListThreadGroupsInfo>(getExecutor(), rm) {
|
for (String groupId : fDebuggedProcessesAndNames.keySet()) {
|
||||||
@Override
|
IProcessDMContext processDmc = createProcessContext(controlDmc, groupId);
|
||||||
protected void handleSuccess() {
|
containerDmcs[i++] = createContainerContext(processDmc, groupId);
|
||||||
rm.setData(makeContainerDMCs(controlDmc, getData().getGroupList()));
|
}
|
||||||
rm.done();
|
rm.setData(containerDmcs);
|
||||||
}
|
rm.done();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,16 +761,6 @@ public class GDBProcesses_7_0 extends AbstractDsfService
|
||||||
return executionDmcs;
|
return executionDmcs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMIContainerDMContext[] makeContainerDMCs(ICommandControlDMContext controlDmc, IThreadGroupInfo[] groups) {
|
|
||||||
IMIContainerDMContext[] containerDmcs = new IMIContainerDMContext[groups.length];
|
|
||||||
for (int i = 0; i < groups.length; i++) {
|
|
||||||
String groupId = groups[i].getGroupId();
|
|
||||||
IProcessDMContext procDmc = createProcessContext(controlDmc, groupId);
|
|
||||||
containerDmcs[i] = createContainerContext(procDmc, groupId);
|
|
||||||
}
|
|
||||||
return containerDmcs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getRunningProcesses(IDMContext dmc, final DataRequestMonitor<IProcessDMContext[]> rm) {
|
public void getRunningProcesses(IDMContext dmc, final DataRequestMonitor<IProcessDMContext[]> rm) {
|
||||||
final ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(dmc, ICommandControlDMContext.class);
|
final ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(dmc, ICommandControlDMContext.class);
|
||||||
|
@ -935,6 +932,8 @@ public class GDBProcesses_7_0 extends AbstractDsfService
|
||||||
|
|
||||||
if (groupId != null) {
|
if (groupId != null) {
|
||||||
if ("thread-group-created".equals(miEvent)) { //$NON-NLS-1$
|
if ("thread-group-created".equals(miEvent)) { //$NON-NLS-1$
|
||||||
|
fDebuggedProcessesAndNames.put(groupId, ""); //$NON-NLS-1$
|
||||||
|
|
||||||
// GDB is debugging a new process. Let's fetch its name and remember it.
|
// GDB is debugging a new process. Let's fetch its name and remember it.
|
||||||
final String finalGroupId = groupId;
|
final String finalGroupId = groupId;
|
||||||
fListThreadGroupsAvailableCache.execute(
|
fListThreadGroupsAvailableCache.execute(
|
||||||
|
@ -950,13 +949,16 @@ public class GDBProcesses_7_0 extends AbstractDsfService
|
||||||
if (isSuccess()) {
|
if (isSuccess()) {
|
||||||
for (IThreadGroupInfo groupInfo : getData().getGroupList()) {
|
for (IThreadGroupInfo groupInfo : getData().getGroupList()) {
|
||||||
if (groupInfo.getPid().equals(finalGroupId)) {
|
if (groupInfo.getPid().equals(finalGroupId)) {
|
||||||
fDebuggedProcessNames.put(groupInfo.getPid(), groupInfo.getName());
|
fDebuggedProcessesAndNames.put(finalGroupId, groupInfo.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if ("thread-group-exited".equals(miEvent)) { //$NON-NLS-1$
|
} else if ("thread-group-exited".equals(miEvent)) { //$NON-NLS-1$
|
||||||
|
// GDB is no longer debugging this process. Remove it from our list.
|
||||||
|
fDebuggedProcessesAndNames.remove(groupId);
|
||||||
|
|
||||||
// Remove any entries for that group from our thread to group map
|
// Remove any entries for that group from our thread to group map
|
||||||
// When detaching from a group, we won't have received any thread-exited event
|
// When detaching from a group, we won't have received any thread-exited event
|
||||||
// but we don't want to keep those entries.
|
// but we don't want to keep those entries.
|
||||||
|
@ -968,9 +970,6 @@ public class GDBProcesses_7_0 extends AbstractDsfService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GDB is no longer debugging this process. Remove its name.
|
|
||||||
fDebuggedProcessNames.remove(groupId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue