2011-07-19 03:15:22 +08:00
|
|
|
//===-- SWIG Interface for SBValueList --------------------------*- C++ -*-===//
|
2011-07-19 03:08:30 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-07-19 03:08:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace lldb {
|
|
|
|
|
|
|
|
%feature("docstring",
|
2021-01-15 21:43:26 +08:00
|
|
|
"Represents a collection of SBValues. Both :py:class:`SBFrame.GetVariables()` and
|
|
|
|
:py:class:`SBFrame.GetRegisters()` return a SBValueList.
|
|
|
|
|
|
|
|
SBValueList supports :py:class:`SBValue` iteration. For example (from test/lldbutil.py),::
|
|
|
|
|
|
|
|
def get_registers(frame, kind):
|
|
|
|
'''Returns the registers given the frame and the kind of registers desired.
|
|
|
|
|
|
|
|
Returns None if there's no such kind.
|
|
|
|
'''
|
|
|
|
registerSet = frame.GetRegisters() # Return type of SBValueList.
|
|
|
|
for value in registerSet:
|
|
|
|
if kind.lower() in value.GetName().lower():
|
|
|
|
return value
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_GPRs(frame):
|
|
|
|
'''Returns the general purpose registers of the frame as an SBValue.
|
|
|
|
|
|
|
|
The returned SBValue object is iterable. An example:
|
|
|
|
...
|
|
|
|
from lldbutil import get_GPRs
|
|
|
|
regs = get_GPRs(frame)
|
|
|
|
for reg in regs:
|
|
|
|
print('%s => %s' % (reg.GetName(), reg.GetValue()))
|
|
|
|
...
|
|
|
|
'''
|
|
|
|
return get_registers(frame, 'general purpose')
|
|
|
|
|
|
|
|
def get_FPRs(frame):
|
|
|
|
'''Returns the floating point registers of the frame as an SBValue.
|
|
|
|
|
|
|
|
The returned SBValue object is iterable. An example:
|
|
|
|
...
|
|
|
|
from lldbutil import get_FPRs
|
|
|
|
regs = get_FPRs(frame)
|
|
|
|
for reg in regs:
|
|
|
|
print('%s => %s' % (reg.GetName(), reg.GetValue()))
|
|
|
|
...
|
|
|
|
'''
|
|
|
|
return get_registers(frame, 'floating point')
|
|
|
|
|
|
|
|
def get_ESRs(frame):
|
|
|
|
'''Returns the exception state registers of the frame as an SBValue.
|
|
|
|
|
|
|
|
The returned SBValue object is iterable. An example:
|
|
|
|
...
|
|
|
|
from lldbutil import get_ESRs
|
|
|
|
regs = get_ESRs(frame)
|
|
|
|
for reg in regs:
|
|
|
|
print('%s => %s' % (reg.GetName(), reg.GetValue()))
|
|
|
|
...
|
|
|
|
'''
|
|
|
|
return get_registers(frame, 'exception state')
|
|
|
|
"
|
2011-07-19 04:13:38 +08:00
|
|
|
) SBValueList;
|
2011-07-19 03:08:30 +08:00
|
|
|
class SBValueList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
SBValueList ();
|
|
|
|
|
|
|
|
SBValueList (const lldb::SBValueList &rhs);
|
|
|
|
|
|
|
|
~SBValueList();
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsValid() const;
|
Add "operator bool" to SB APIs
Summary:
Our python version of the SB API has (the python equivalent of)
operator bool, but the C++ version doesn't.
This is because our python operators are added by modify-python-lldb.py,
which performs postprocessing on the swig-generated interface files.
In this patch, I add the "operator bool" to all SB classes which have an
IsValid method (which is the same logic used by modify-python-lldb.py).
This way, we make the two interfaces more constent, and it allows us to
rely on swig's automatic syntesis of python __nonzero__ methods instead
of doing manual fixups.
Reviewers: zturner, jingham, clayborg, jfb, serge-sans-paille
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D58792
llvm-svn: 355824
2019-03-11 21:58:46 +08:00
|
|
|
|
|
|
|
explicit operator bool() const;
|
2019-04-19 00:23:33 +08:00
|
|
|
|
|
|
|
void
|
2011-12-20 04:39:44 +08:00
|
|
|
Clear();
|
2011-07-19 03:08:30 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
Append (const lldb::SBValue &val_obj);
|
|
|
|
|
|
|
|
void
|
|
|
|
Append (const lldb::SBValueList& value_list);
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
GetSize() const;
|
|
|
|
|
|
|
|
lldb::SBValue
|
|
|
|
GetValueAtIndex (uint32_t idx) const;
|
|
|
|
|
|
|
|
lldb::SBValue
|
|
|
|
FindValueObjectByUID (lldb::user_id_t uid);
|
2019-04-19 00:23:33 +08:00
|
|
|
|
2014-11-22 05:45:03 +08:00
|
|
|
lldb::SBValue
|
2014-11-22 06:23:08 +08:00
|
|
|
GetFirstValueByName (const char* name) const;
|
2019-04-19 00:23:33 +08:00
|
|
|
|
2020-01-09 12:56:11 +08:00
|
|
|
%extend {
|
|
|
|
%nothreadallow;
|
|
|
|
std::string lldb::SBValueList::__str__ (){
|
|
|
|
lldb::SBStream description;
|
|
|
|
const size_t n = $self->GetSize();
|
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
for (size_t i=0; i<n; ++i)
|
|
|
|
$self->GetValueAtIndex(i).GetDescription(description);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
description.Printf("<empty> lldb.SBValueList()");
|
|
|
|
}
|
|
|
|
const char *desc = description.GetData();
|
|
|
|
size_t desc_len = description.GetSize();
|
|
|
|
if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r'))
|
|
|
|
--desc_len;
|
|
|
|
return std::string(desc, desc_len);
|
|
|
|
}
|
|
|
|
%clearnothreadallow;
|
|
|
|
}
|
|
|
|
|
2019-12-09 06:46:48 +08:00
|
|
|
#ifdef SWIGPYTHON
|
2012-02-03 15:02:37 +08:00
|
|
|
%pythoncode %{
|
2019-04-03 19:48:38 +08:00
|
|
|
def __iter__(self):
|
|
|
|
'''Iterate over all values in a lldb.SBValueList object.'''
|
|
|
|
return lldb_iter(self, 'GetSize', 'GetValueAtIndex')
|
|
|
|
|
2012-02-03 15:02:37 +08:00
|
|
|
def __len__(self):
|
2012-05-12 04:39:42 +08:00
|
|
|
return int(self.GetSize())
|
|
|
|
|
2012-02-03 15:02:37 +08:00
|
|
|
def __getitem__(self, key):
|
|
|
|
count = len(self)
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# Access with "int" to get Nth item in the list
|
|
|
|
#------------------------------------------------------------
|
|
|
|
if type(key) is int:
|
|
|
|
if key < count:
|
|
|
|
return self.GetValueAtIndex(key)
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# Access with "str" to get values by name
|
|
|
|
#------------------------------------------------------------
|
|
|
|
elif type(key) is str:
|
|
|
|
matches = []
|
|
|
|
for idx in range(count):
|
|
|
|
value = self.GetValueAtIndex(idx)
|
|
|
|
if value.name == key:
|
|
|
|
matches.append(value)
|
|
|
|
return matches
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# Match with regex
|
|
|
|
#------------------------------------------------------------
|
|
|
|
elif isinstance(key, type(re.compile('.'))):
|
|
|
|
matches = []
|
|
|
|
for idx in range(count):
|
|
|
|
value = self.GetValueAtIndex(idx)
|
|
|
|
re_match = key.search(value.name)
|
|
|
|
if re_match:
|
|
|
|
matches.append(value)
|
|
|
|
return matches
|
|
|
|
|
|
|
|
%}
|
2019-12-09 06:46:48 +08:00
|
|
|
#endif
|
2012-02-03 15:02:37 +08:00
|
|
|
|
|
|
|
|
2011-07-19 03:08:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace lldb
|