~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIListThreadGroupsInfo.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2008 Ericsson and others.
3
 
 * All rights reserved. This program and the accompanying materials
4
 
 * are made available under the terms of the Eclipse Public License v1.0
5
 
 * which accompanies this distribution, and is available at
6
 
 * http://www.eclipse.org/legal/epl-v10.html
7
 
 *
8
 
 * Contributors:
9
 
 *     Ericsson - Initial API and implementation
10
 
 *******************************************************************************/
11
 
 
12
 
package org.eclipse.cdt.dsf.mi.service.command.output;
13
 
 
14
 
import java.util.regex.Matcher;
15
 
import java.util.regex.Pattern;
16
 
 
17
 
import org.eclipse.cdt.dsf.concurrent.Immutable;
18
 
 
19
 
/**
20
 
 * GDB/MI thread group parsing.
21
 
 * 
22
 
 *  The description field can be different depending on the target we are connected to.
23
 
 *
24
 
 *  -list-thread-groups --available:
25
 
 *  ^done,groups=[{id="161",type="process",description="name: JIM_InstallerProcess, type 555481, locked: N, system: N, state: Idle"},
26
 
 *                {id="162",type="process",description="name: JIM_TcpSetupHandlerProcess, type 555505, locked: N, system: N, state: Idle"},
27
 
 *                {id="165",type="process",description="name: JUnitProcess2_PT, type 1094608, locked: N, system: N, state: Idle"},
28
 
 *                {id="166",type="process",description="name: JUnitProcess_PT, type 1094605, locked: N, system: N, state: Idle"}]
29
 
 *
30
 
 *                {id="3602",type="process",description="/usr/sbin/dhcdbd --system",user="root"}
31
 
 *  -list-thread-groups: 
32
 
 *  ^done,groups=[{id="162",type="process",pid="162"}]
33
 
 *
34
 
 *  list-thread-groups GROUPID, in the case of a running thread or a stopped thread:
35
 
 *  ^done,threads=[{id="1",target-id="Thread 162.32942",details="JUnitProcess_PT (Ready) 1030373359 44441",frame={level="0",addr="0x00000000",func="??",args=[]},state="stopped"}]
36
 
 *  ^done,threads=[{id="1",target-id="Thread 162.32942",details="JUnitProcess_PT Idle 981333916 42692",state="running"}]
37
 
 * @since 1.1
38
 
 */
39
 
public class MIListThreadGroupsInfo extends MIInfo {
40
 
        
41
 
        public interface IThreadGroupInfo {
42
 
                String getGroupId();
43
 
                String getPid();
44
 
                String getName();
45
 
                String getDesciption();
46
 
        }
47
 
        
48
 
        @Immutable
49
 
        private static class ThreadGroupInfo implements IThreadGroupInfo {
50
 
                final String fGroupId;
51
 
                final String fDescription;
52
 
                final String fName;
53
 
                
54
 
                public ThreadGroupInfo(String id, String description) {
55
 
                        fGroupId = id;
56
 
                        fDescription = description;
57
 
 
58
 
                        fName = parseName(fDescription);
59
 
                }
60
 
                
61
 
                private static String parseName(String desc) {
62
 
                        String name = ""; //$NON-NLS-1$
63
 
 
64
 
                        // Find the string "name: " followed by the smallest set of characters that
65
 
                        // is followed by a comma, or by the end of the line.
66
 
                        Pattern pattern = Pattern.compile("name: (.*?)(, |$)", Pattern.MULTILINE); //$NON-NLS-1$
67
 
                Matcher matcher = pattern.matcher(desc);
68
 
                if (matcher.find()) {
69
 
                        name = matcher.group(1);
70
 
                } else {
71
 
                        // If we didn't get the form "name: " then we expect to have the form
72
 
                        // "/usr/sbin/dhcdbd --system"
73
 
                        name = desc.split("\\s", 2)[0]; //$NON-NLS-1$
74
 
                }
75
 
 
76
 
                        return name;
77
 
                }
78
 
                
79
 
                public String getGroupId() { return fGroupId; }
80
 
                public String getPid() { return fGroupId; }
81
 
 
82
 
                public String getName() { return fName; }
83
 
 
84
 
                public String getDesciption() { return fDescription; }
85
 
        }
86
 
        
87
 
        
88
 
        private IThreadGroupInfo[] fGroupList;
89
 
        private MIThreadInfoInfo fThreadInfo;
90
 
        
91
 
    public MIListThreadGroupsInfo(MIOutput out) {
92
 
        super(out);
93
 
        parse();
94
 
        }
95
 
        
96
 
        public IThreadGroupInfo[] getGroupList() { return fGroupList; }
97
 
        public MIThreadInfoInfo getThreadInfo() { return fThreadInfo; }
98
 
        
99
 
        private void parse() {
100
 
                if (isDone()) {
101
 
                        MIOutput out = getMIOutput();
102
 
                        MIResultRecord rr = out.getMIResultRecord();
103
 
                        if (rr != null) {
104
 
                                MIResult[] results =  rr.getMIResults();
105
 
                                for (int i = 0; i < results.length; i++) {
106
 
                                        String var = results[i].getVariable();
107
 
                                        if (var.equals("groups")) { //$NON-NLS-1$
108
 
                                                MIValue val = results[i].getMIValue();
109
 
                                                if (val instanceof MIList) {
110
 
                                                        parseGroups((MIList)val);
111
 
                                                }
112
 
                                        } else if (var.equals("threads")) { //$NON-NLS-1$
113
 
                                                // Re-use the MIThreadInfoInfo parsing
114
 
                                                fThreadInfo = new MIThreadInfoInfo(out);
115
 
                                        }
116
 
                                }
117
 
                        }
118
 
                }
119
 
                if (fGroupList == null) {
120
 
                        fGroupList = new IThreadGroupInfo[0];
121
 
                }
122
 
                if (fThreadInfo == null) {
123
 
                        fThreadInfo = new MIThreadInfoInfo(null);
124
 
                }
125
 
        }
126
 
 
127
 
        private void parseGroups(MIList list) {
128
 
                MIValue[] values = list.getMIValues();
129
 
                fGroupList = new IThreadGroupInfo[values.length];
130
 
                for (int i = 0; i < values.length; i++) {
131
 
                        MIResult[] results = ((MITuple)values[i]).getMIResults();
132
 
                        String id = "", desc = "";//$NON-NLS-1$//$NON-NLS-2$
133
 
                        
134
 
                        for (MIResult result : results) {
135
 
                                String var = result.getVariable();
136
 
                                if (var.equals("id")) { //$NON-NLS-1$
137
 
                                        MIValue value = result.getMIValue();
138
 
                                        if (value instanceof MIConst) {
139
 
                                                String str = ((MIConst)value).getCString();
140
 
                                                id = str.trim();
141
 
                                        }
142
 
                                } else if (var.equals("description")) { //$NON-NLS-1$
143
 
                                        MIValue value = result.getMIValue();
144
 
                                        if (value instanceof MIConst) {
145
 
                                                String str = ((MIConst)value).getCString();
146
 
                                                desc = str.trim();
147
 
 
148
 
                                        }
149
 
                                }
150
 
                        }
151
 
                        fGroupList[i] = new ThreadGroupInfo(id, desc);
152
 
                }
153
 
        }
154
 
}