1//===-- SWIG Interface for SBValueList --------------------------*- 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
10namespace lldb {
11
12%feature("docstring",
13"Represents a collection of SBValues.  Both SBFrame's GetVariables() and
14GetRegisters() return a SBValueList.
15
16SBValueList supports SBValue iteration. For example (from test/lldbutil.py),
17
18def get_registers(frame, kind):
19    '''Returns the registers given the frame and the kind of registers desired.
20
21    Returns None if there's no such kind.
22    '''
23    registerSet = frame.GetRegisters() # Return type of SBValueList.
24    for value in registerSet:
25        if kind.lower() in value.GetName().lower():
26            return value
27
28    return None
29
30def get_GPRs(frame):
31    '''Returns the general purpose registers of the frame as an SBValue.
32
33    The returned SBValue object is iterable.  An example:
34        ...
35        from lldbutil import get_GPRs
36        regs = get_GPRs(frame)
37        for reg in regs:
38            print '%s => %s' % (reg.GetName(), reg.GetValue())
39        ...
40    '''
41    return get_registers(frame, 'general purpose')
42
43def get_FPRs(frame):
44    '''Returns the floating point registers of the frame as an SBValue.
45
46    The returned SBValue object is iterable.  An example:
47        ...
48        from lldbutil import get_FPRs
49        regs = get_FPRs(frame)
50        for reg in regs:
51            print '%s => %s' % (reg.GetName(), reg.GetValue())
52        ...
53    '''
54    return get_registers(frame, 'floating point')
55
56def get_ESRs(frame):
57    '''Returns the exception state registers of the frame as an SBValue.
58
59    The returned SBValue object is iterable.  An example:
60        ...
61        from lldbutil import get_ESRs
62        regs = get_ESRs(frame)
63        for reg in regs:
64            print '%s => %s' % (reg.GetName(), reg.GetValue())
65        ...
66    '''
67    return get_registers(frame, 'exception state')"
68) SBValueList;
69class SBValueList
70{
71public:
72
73    SBValueList ();
74
75    SBValueList (const lldb::SBValueList &rhs);
76
77    ~SBValueList();
78
79    bool
80    IsValid() const;
81
82    void
83    Clear();
84
85    void
86    Append (const lldb::SBValue &val_obj);
87
88    void
89    Append (const lldb::SBValueList& value_list);
90
91    uint32_t
92    GetSize() const;
93
94    lldb::SBValue
95    GetValueAtIndex (uint32_t idx) const;
96
97    lldb::SBValue
98    FindValueObjectByUID (lldb::user_id_t uid);
99    %pythoncode %{
100        def __len__(self):
101            return int(self.GetSize())
102
103        def __getitem__(self, key):
104            count = len(self)
105            #------------------------------------------------------------
106            # Access with "int" to get Nth item in the list
107            #------------------------------------------------------------
108            if type(key) is int:
109                if key < count:
110                    return self.GetValueAtIndex(key)
111            #------------------------------------------------------------
112            # Access with "str" to get values by name
113            #------------------------------------------------------------
114            elif type(key) is str:
115                matches = []
116                for idx in range(count):
117                    value = self.GetValueAtIndex(idx)
118                    if value.name == key:
119                        matches.append(value)
120                return matches
121            #------------------------------------------------------------
122            # Match with regex
123            #------------------------------------------------------------
124            elif isinstance(key, type(re.compile('.'))):
125                matches = []
126                for idx in range(count):
127                    value = self.GetValueAtIndex(idx)
128                    re_match = key.search(value.name)
129                    if re_match:
130                        matches.append(value)
131                return matches
132
133    %}
134
135
136};
137
138} // namespace lldb
139