From d2ba7a5b346d568eb26a84666b15c2a944dea8fc Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 2 Feb 2012 14:16:14 -0500 Subject: [PATCH] Bug 370375: [attach] List of processes returned by GDB 7.4 is not parsed properly --- .../ui/launching/ProcessPrompter.java | 10 ++++++- .../output/MIListThreadGroupsInfo.java | 27 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java index 19a46e5335b..764b2409a07 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java @@ -91,7 +91,15 @@ public class ProcessPrompter implements IStatusHandler { @Override public String getText(Object element) { IProcessExtendedInfo info = (IProcessExtendedInfo)element; - IPath path = new Path(info.getName()); + // Sometimes, if we are not getting the list of processes from GDB, + // we use CCorePlugin.getDefault().getProcessList(); which returns + // the process and its arguments. If the arguments contain a / + // we will get confused when using path.lastSegment(), so, + // let's only keep the name to be sure + String name = info.getName(); + name = name.split("\\s", 2)[0]; //$NON-NLS-1$ + + IPath path = new Path(name); StringBuffer text = new StringBuffer(path.lastSegment()); String owner = info.getOwner(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIListThreadGroupsInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIListThreadGroupsInfo.java index 5d085f1906f..9c263abea52 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIListThreadGroupsInfo.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIListThreadGroupsInfo.java @@ -232,8 +232,31 @@ public class MIListThreadGroupsInfo extends MIInfo { name = matcher.group(1); } else { // If we didn't get the form "name: " then we expect to have the form - // "/usr/sbin/dhcdbd --system" - name = desc.split("\\s", 2)[0]; //$NON-NLS-1$ + // "/usr/sbin/dhcdbd --system" + // or (starting with GDB 7.4) + // "[migration/0]" where the integer represents the core, if the process + // has an instance of many cores + // "[kacpid]" when the process only runs on one core + // "[async/mgr]" + // "[jbd2/dm-1-8]" + // The brackets indicate that the startup parameters are not available + // We handle this case by removing the brackets and the core indicator + // since GDB already tells us the core separately. + if (desc.length() > 0 && desc.charAt(0) == '[') { + // Remove brackets + name = desc.substring(1, desc.length()-1); + + // Look for [name/coreNum] pattern to remove /coreNum + pattern = Pattern.compile("(.+?)(/\\d+)", Pattern.MULTILINE); //$NON-NLS-1$ + matcher = pattern.matcher(name); + if (matcher.find()) { + // Found a pattern /coreNum, so ignore it + name = matcher.group(1); + } + // else, no /coreNum pattern, so the name is correct already + } else { + name = desc.split("\\s", 2)[0]; //$NON-NLS-1$ + } } return name;