]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdArgValThreadGrp.cpp
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdArgValThreadGrp.cpp
1 //===-- MICmdArgValThreadGrp.cpp --------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //++
11 // File:        MICmdArgValThreadGrp.cpp
12 //
13 // Overview:    CMICmdArgValThreadGrp implementation.
14 //
15 // Environment: Compilers:  Visual C++ 12.
16 //                          gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 //              Libraries:  See MIReadmetxt.
18 //
19 // Copyright:   None.
20 //--
21
22 // In-house headers:
23 #include "MICmdArgValThreadGrp.h"
24 #include "MICmdArgContext.h"
25
26 //++ ------------------------------------------------------------------------------------
27 // Details: CMICmdArgValThreadGrp constructor.
28 // Type:    Method.
29 // Args:    None.
30 // Return:  None.
31 // Throws:  None.
32 //--
33 CMICmdArgValThreadGrp::CMICmdArgValThreadGrp(void)
34     : m_nThreadGrp(0)
35 {
36 }
37
38 //++ ------------------------------------------------------------------------------------
39 // Details: CMICmdArgValThreadGrp constructor.
40 // Type:    Method.
41 // Args:    vrArgName       - (R) Argument's name to search by.
42 //          vbMandatory     - (R) True = Yes must be present, false = optional argument.
43 //          vbHandleByCmd   - (R) True = Command processes *this option, false = not handled.
44 // Return:  None.
45 // Throws:  None.
46 //--
47 CMICmdArgValThreadGrp::CMICmdArgValThreadGrp(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd)
48     : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd)
49     , m_nThreadGrp(0)
50 {
51 }
52
53 //++ ------------------------------------------------------------------------------------
54 // Details: CMICmdArgValThreadGrp destructor.
55 // Type:    Overridden.
56 // Args:    None.
57 // Return:  None.
58 // Throws:  None.
59 //--
60 CMICmdArgValThreadGrp::~CMICmdArgValThreadGrp(void)
61 {
62 }
63
64 //++ ------------------------------------------------------------------------------------
65 // Details: Parse the command's argument options string and try to extract the value *this
66 //          argument is looking for.
67 // Type:    Overridden.
68 // Args:    vwArgContext    - (RW) The command's argument options string.
69 // Return:  MIstatus::success - Functional succeeded.
70 //          MIstatus::failure - Functional failed.
71 // Throws:  None.
72 //--
73 bool
74 CMICmdArgValThreadGrp::Validate(CMICmdArgContext &vwArgContext)
75 {
76     if (vwArgContext.IsEmpty())
77         return MIstatus::success;
78
79     if (vwArgContext.GetNumberArgsPresent() == 1)
80     {
81         const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse());
82         if (IsArgThreadGrp(rArg) && ExtractNumber(rArg))
83         {
84             m_bFound = true;
85             m_bValid = true;
86             m_argValue = GetNumber();
87             vwArgContext.RemoveArg(rArg);
88             return MIstatus::success;
89         }
90         else
91             return MIstatus::failure;
92     }
93
94     // More than one option...
95     const CMIUtilString::VecString_t vecOptions(vwArgContext.GetArgs());
96     CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
97     while (it != vecOptions.end())
98     {
99         const CMIUtilString &rArg(*it);
100         if (IsArgThreadGrp(rArg) && ExtractNumber(rArg))
101         {
102             m_bFound = true;
103
104             if (vwArgContext.RemoveArg(rArg))
105             {
106                 m_bValid = true;
107                 m_argValue = GetNumber();
108                 return MIstatus::success;
109             }
110             else
111                 return MIstatus::failure;
112         }
113
114         // Next
115         ++it;
116     }
117
118     return MIstatus::failure;
119 }
120
121 //++ ------------------------------------------------------------------------------------
122 // Details: Examine the string and determine if it is a valid string type argument.
123 // Type:    Method.
124 // Args:    vrTxt   - (R) Some text.
125 // Return:  bool    - True = yes valid arg, false = no.
126 // Throws:  None.
127 //--
128 bool
129 CMICmdArgValThreadGrp::IsArgThreadGrp(const CMIUtilString &vrTxt) const
130 {
131     // Look for i1 i2 i3....
132     const MIint nPos = vrTxt.find_first_of("i");
133     if (nPos != 0)
134         return false;
135
136     const CMIUtilString strNum = vrTxt.substr(1).c_str();
137     if (!strNum.IsNumber())
138         return false;
139
140     return true;
141 }
142
143 //++ ------------------------------------------------------------------------------------
144 // Details: Extract the thread group number from the thread group argument.
145 // Type:    Method.
146 // Args:    vrTxt   - (R) Some text.
147 // Return:  MIstatus::success - Functional succeeded.
148 //          MIstatus::failure - Functional failed.
149 // Throws:  None.
150 //--
151 bool
152 CMICmdArgValThreadGrp::ExtractNumber(const CMIUtilString &vrTxt)
153 {
154     const CMIUtilString strNum = vrTxt.substr(1).c_str();
155     MIint64 nNumber = 0;
156     bool bOk = strNum.ExtractNumber(nNumber);
157     if (bOk)
158     {
159         m_nThreadGrp = static_cast<MIuint>(nNumber);
160     }
161
162     return bOk;
163 }
164
165 //++ ------------------------------------------------------------------------------------
166 // Details: Retrieve the thread group ID found in the argument.
167 // Type:    Method.
168 // Args:    None.
169 // Return:  MIuint - Thread group ID.
170 // Throws:  None.
171 //--
172 MIuint
173 CMICmdArgValThreadGrp::GetNumber(void) const
174 {
175     return m_nThreadGrp;
176 }