From c88706272bc45cc539e018cf2f9bf83ef1f327d0 Mon Sep 17 00:00:00 2001 From: Pawel Piech Date: Thu, 18 Sep 2008 22:36:52 +0000 Subject: [PATCH] [247362] - [commands] -thread-info parsing not consistent with existing API. --- .../provisional/service/GDBProcesses_7_0.java | 6 +- .../service/command/output/IThreadFrame.java | 26 ---- .../service/command/output/IThreadInfo.java | 24 --- .../mi/service/command/output/MIThread.java | 139 ++++++++++++++++++ .../command/output/MIThreadInfoInfo.java | 99 +------------ .../service/command/output/ThreadFrame.java | 49 ------ .../mi/service/command/output/ThreadInfo.java | 47 ------ 7 files changed, 148 insertions(+), 242 deletions(-) delete mode 100644 plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/IThreadFrame.java delete mode 100644 plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/IThreadInfo.java create mode 100644 plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/MIThread.java delete mode 100644 plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/ThreadFrame.java delete mode 100644 plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/ThreadInfo.java diff --git a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/GDBProcesses_7_0.java b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/GDBProcesses_7_0.java index 964645ba381..524e5b002a4 100644 --- a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/GDBProcesses_7_0.java +++ b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/GDBProcesses_7_0.java @@ -50,9 +50,9 @@ import org.eclipse.dd.mi.service.command.commands.MITargetDetach; import org.eclipse.dd.mi.service.command.commands.MIThreadInfo; import org.eclipse.dd.mi.service.command.events.MIThreadGroupCreatedEvent; import org.eclipse.dd.mi.service.command.events.MIThreadGroupExitedEvent; -import org.eclipse.dd.mi.service.command.output.IThreadInfo; import org.eclipse.dd.mi.service.command.output.MIInfo; import org.eclipse.dd.mi.service.command.output.MIListThreadGroupsInfo; +import org.eclipse.dd.mi.service.command.output.MIThread; import org.eclipse.dd.mi.service.command.output.MIThreadInfoInfo; import org.eclipse.dd.mi.service.command.output.MIListThreadGroupsInfo.IThreadGroupInfo; import org.osgi.framework.BundleContext; @@ -453,7 +453,7 @@ public class GDBProcesses_7_0 extends AbstractDsfService implements IMIProcesses protected void handleSuccess() { IThreadDMData threadData = new MIThreadDMData("", ""); //$NON-NLS-1$ //$NON-NLS-2$ if (getData().getThreadList().length != 0) { - IThreadInfo thread = getData().getThreadList()[0]; + MIThread thread = getData().getThreadList()[0]; if (thread.getThreadId().equals(threadDmc.getId())) { threadData = new MIThreadDMData("", thread.getOsId()); //$NON-NLS-1$ } @@ -590,7 +590,7 @@ public class GDBProcesses_7_0 extends AbstractDsfService implements IMIProcesses // } } - private IExecutionDMContext[] makeExecutionDMCs(IContainerDMContext containerDmc, IThreadInfo[] threadInfos) { + private IExecutionDMContext[] makeExecutionDMCs(IContainerDMContext containerDmc, MIThread[] threadInfos) { final IProcessDMContext procDmc = DMContexts.getAncestorOfType(containerDmc, IProcessDMContext.class); if (threadInfos.length == 0) { diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/IThreadFrame.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/IThreadFrame.java deleted file mode 100644 index 1bff9fc61ba..00000000000 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/IThreadFrame.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Ericsson and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ericsson - Initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.mi.service.command.output; - -import java.math.BigInteger; - -/** - * @since 1.1 - */ -public interface IThreadFrame { - int getStackLevel(); - BigInteger getAddress(); - String getFucntion(); - Object[] getArgs(); - String getFileName(); - String getFullName(); - int getLineNumber(); -} diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/IThreadInfo.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/IThreadInfo.java deleted file mode 100644 index a4b7804ee8d..00000000000 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/IThreadInfo.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Ericsson and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ericsson - Initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.mi.service.command.output; - - -/** - * @since 1.1 - */ -public interface IThreadInfo { - String getThreadId(); - String getTargetId(); - String getOsId(); - IThreadFrame getTopFrame(); - String getDetails(); - String getState(); -} diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/MIThread.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/MIThread.java new file mode 100644 index 00000000000..b7ac0c81715 --- /dev/null +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/MIThread.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2008 Ericsson and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ericsson - Initial API and implementation + * Wind River Systems - refactored to match pattern in package + *******************************************************************************/ +package org.eclipse.dd.mi.service.command.output; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.dd.dsf.concurrent.Immutable; + +/** + * GDB/MI Thread tuple parsing. + * + * @since 1.1 + */ +@Immutable +public class MIThread { + + final private String fThreadId; + final private String fTargetId; + final private String fOsId; + final private String fParentId; + final private MIFrame fTopFrame; + final private String fDetails; + final private String fState; + + private MIThread(String threadId, String targetId, String osId, String parentId, + MIFrame topFrame, String details, String state) { + fThreadId = threadId; + fTargetId = targetId; + fOsId = osId; + fParentId = parentId; + fTopFrame = topFrame; + fDetails = details; + fState = state; + } + + public String getThreadId() { return fThreadId; } + public String getTargetId() { return fTargetId; } + public String getOsId() { return fOsId; } + public String getParentId() { return fParentId; } + public MIFrame getTopFrame() { return fTopFrame; } + public String getDetails() { return fDetails; } + public String getState() { return fState; } + + public static MIThread parse(MITuple tuple) { + MIResult[] results = tuple.getMIResults(); + + String threadId = null; + String targetId = null; + String osId = null; + String parentId = null; + MIFrame topFrame = null; + String state = null; + String details = null; + + for (int j = 0; j < results.length; j++) { + MIResult result = results[j]; + String var = result.getVariable(); + if (var.equals("id")) { //$NON-NLS-1$ + MIValue val = results[j].getMIValue(); + if (val instanceof MIConst) { + threadId = ((MIConst) val).getCString().trim(); + } + } + else if (var.equals("target-id")) { //$NON-NLS-1$ + MIValue val = results[j].getMIValue(); + if (val instanceof MIConst) { + targetId = ((MIConst) val).getCString().trim(); + osId = parseOsId(targetId); + parentId = parseParentId(targetId); + } + } + else if (var.equals("frame")) { //$NON-NLS-1$ + MITuple val = (MITuple)results[j].getMIValue(); + topFrame = new MIFrame(val); + } + else if (var.equals("state")) { //$NON-NLS-1$ + MIValue val = results[j].getMIValue(); + if (val instanceof MIConst) { + state = ((MIConst) val).getCString().trim(); + } + } + else if (var.equals("details")) { //$NON-NLS-1$ + MIValue val = results[j].getMIValue(); + if (val instanceof MIConst) { + details = ((MIConst) val).getCString().trim(); + } + } + } + + return new MIThread(threadId, targetId, osId, parentId, topFrame, details, state); + } + + private static Pattern fgOsIdPattern1 = Pattern.compile("(Thread\\s*)(0x[0-9a-fA-F]+|-?\\d+)(\\s*\\(LWP\\s*)(\\d*)", 0); //$NON-NLS-1$ + private static Pattern fgOsIdPattern2 = Pattern.compile("(Thread\\s*)(0x[0-9a-fA-F]+|-?\\d+)(\\s*\\(LWP\\s*)(\\d*)", 0); //$NON-NLS-1$ + + private static String parseOsId(String str) { + // General format: + // "Thread 0xb7c8ab90 (LWP 7010)" + // "Thread 162.32942" + + Matcher matcher = fgOsIdPattern1.matcher(str); + if (matcher.find()) { + return matcher.group(4); + } + + matcher = fgOsIdPattern2.matcher(str); + if (matcher.find()) { + return matcher.group(1); + } + + return null; + } + + private static Pattern fgIdPattern = Pattern.compile("Thread\\s*(\\d+)\\.\\d+", 0); //$NON-NLS-1$ + + private static String parseParentId(String str) { + // General format: + // "Thread 0xb7c8ab90 (LWP 7010)" + // "Thread 162.32942" + + Matcher matcher = fgIdPattern.matcher(str); + if (matcher.find()) { + return matcher.group(1); + } + + return null; + } + +} diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/MIThreadInfoInfo.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/MIThreadInfoInfo.java index b846528b0f5..8ef3ff6303f 100644 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/MIThreadInfoInfo.java +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/MIThreadInfoInfo.java @@ -7,12 +7,11 @@ * * Contributors: * Ericsson - Initial API and implementation + * Wind River Systems - refactored to match pattern in package *******************************************************************************/ package org.eclipse.dd.mi.service.command.output; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * GDB/MI thread list parsing. @@ -75,7 +74,7 @@ import java.util.regex.Pattern; public class MIThreadInfoInfo extends MIInfo { private String fCurrentThread = null; - private IThreadInfo[] fThreadList = null; + private MIThread[] fThreadList = null; public MIThreadInfoInfo(MIOutput out) { super(out); @@ -86,7 +85,7 @@ public class MIThreadInfoInfo extends MIInfo { return fCurrentThread; } - public IThreadInfo[] getThreadList() { + public MIThread[] getThreadList() { return fThreadList; } @@ -116,7 +115,7 @@ public class MIThreadInfoInfo extends MIInfo { } } if (fThreadList == null) { - fThreadList = new IThreadInfo[0]; + fThreadList = new MIThread[0]; } } @@ -126,97 +125,11 @@ public class MIThreadInfoInfo extends MIInfo { // id="n",target-id="Thread 162.32942",details="...",frame={...},state="stopped" private void parseThreads(MIList list) { MIValue[] values = list.getMIValues(); - fThreadList = new IThreadInfo[values.length]; + fThreadList = new MIThread[values.length]; for (int i = 0; i < values.length; i++) { - MITuple value = (MITuple) values[i]; - MIResult[] results = value.getMIResults(); - - String threadId = null; - String targetId = null; - String osId = null; - String parentId = null; - ThreadFrame topFrame = null; - String state = null; - String details = null; - - for (int j = 0; j < results.length; j++) { - MIResult result = results[j]; - String var = result.getVariable(); - if (var.equals("id")) { //$NON-NLS-1$ - MIValue val = results[j].getMIValue(); - if (val instanceof MIConst) { - threadId = ((MIConst) val).getCString().trim(); - } - } - else if (var.equals("target-id")) { //$NON-NLS-1$ - MIValue val = results[j].getMIValue(); - if (val instanceof MIConst) { - targetId = ((MIConst) val).getCString().trim(); - osId = parseOsId(targetId); - parentId = parseParentId(targetId); - } - } - else if (var.equals("frame")) { //$NON-NLS-1$ - MIValue val = results[j].getMIValue(); - topFrame = parseFrame(val); - } - else if (var.equals("state")) { //$NON-NLS-1$ - MIValue val = results[j].getMIValue(); - if (val instanceof MIConst) { - state = ((MIConst) val).getCString().trim(); - } - } - else if (var.equals("details")) { //$NON-NLS-1$ - MIValue val = results[j].getMIValue(); - if (val instanceof MIConst) { - details = ((MIConst) val).getCString().trim(); - } - } - } - - fThreadList[i] = new ThreadInfo(threadId, targetId, osId, parentId, topFrame, details, state); + fThreadList[i] = MIThread.parse((MITuple) values[i]); } } - - // General format: - // "Thread 0xb7c8ab90 (LWP 7010)" - // "Thread 162.32942" - private String parseOsId(String str) { - Pattern pattern = Pattern.compile("(Thread\\s*)(0x[0-9a-fA-F]+|-?\\d+)(\\s*\\(LWP\\s*)(\\d*)", 0); //$NON-NLS-1$ - Matcher matcher = pattern.matcher(str); - if (matcher.find()) { - return matcher.group(4); - } - - pattern = Pattern.compile("Thread\\s*\\d+\\.(\\d+)", 0); //$NON-NLS-1$ - matcher = pattern.matcher(str); - if (matcher.find()) { - return matcher.group(1); - } - - return null; - } - - // General format: - // "Thread 0xb7c8ab90 (LWP 7010)" - // "Thread 162.32942" - private String parseParentId(String str) { - Pattern pattern = Pattern.compile("Thread\\s*(\\d+)\\.\\d+", 0); //$NON-NLS-1$ - Matcher matcher = pattern.matcher(str); - if (matcher.find()) { - return matcher.group(1); - } - - return null; - } - - // General format: - // level="0",addr="0x08048bba",func="func",args=[...],file="file.cc",fullname="/path/file.cc",line="26" - private ThreadFrame parseFrame(MIValue val) { - // TODO Auto-generated method stub - return null; - } - } diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/ThreadFrame.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/ThreadFrame.java deleted file mode 100644 index 516e7b8a69b..00000000000 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/ThreadFrame.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Ericsson and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ericsson - Initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.mi.service.command.output; - -import java.math.BigInteger; - -import org.eclipse.dd.dsf.concurrent.Immutable; - -/** - * @since 1.1 - */ -@Immutable -public class ThreadFrame implements IThreadFrame { - final private int fStackLevel; - final private BigInteger fAddress; - final private String fFunction; - final private Object[] fArgs; - final private String fFileName; - final private String fFullName; - final private int fLineNumber; - - public ThreadFrame(int stackLevel, BigInteger address, String function, - Object[] args, String file, String fullName, int line) - { - fStackLevel = stackLevel; - fAddress = address; - fFunction = function; - fArgs = args; - fFileName = file; - fFullName = fullName; - fLineNumber = line; - } - - public int getStackLevel() { return fStackLevel; } - public BigInteger getAddress() { return fAddress; } - public String getFucntion() { return fFunction; } - public Object[] getArgs() { return fArgs; } - public String getFileName() { return fFileName; } - public String getFullName() { return fFullName; } - public int getLineNumber() { return fLineNumber; } -} diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/ThreadInfo.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/ThreadInfo.java deleted file mode 100644 index 5b671f9d06a..00000000000 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/output/ThreadInfo.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Ericsson and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ericsson - Initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.mi.service.command.output; - -import org.eclipse.dd.dsf.concurrent.Immutable; - -/** - * @since 1.1 - */ -@Immutable -public class ThreadInfo implements IThreadInfo { - - final private String fThreadId; - final private String fTargetId; - final private String fOsId; - final private String fParentId; - final private IThreadFrame fTopFrame; - final private String fDetails; - final private String fState; - - public ThreadInfo(String threadId, String targetId, String osId, String parentId, - IThreadFrame topFrame, String details, String state) { - fThreadId = threadId; - fTargetId = targetId; - fOsId = osId; - fParentId = parentId; - fTopFrame = topFrame; - fDetails = details; - fState = state; - } - - public String getThreadId() { return fThreadId; } - public String getTargetId() { return fTargetId; } - public String getOsId() { return fOsId; } - public String getParentId() { return fParentId; } - public IThreadFrame getTopFrame() { return fTopFrame; } - public String getDetails() { return fDetails; } - public String getState() { return fState; } -}