2011-07-20 06:41:47 +08:00
|
|
|
//===-- SWIG Interface for SBInstructionList --------------------*- C++ -*-===//
|
|
|
|
//
|
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-20 06:41:47 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
namespace lldb {
|
|
|
|
|
2011-07-21 08:48:02 +08:00
|
|
|
%feature("docstring",
|
|
|
|
"Represents a list of machine instructions. SBFunction and SBSymbol have
|
|
|
|
GetInstructions() methods which return SBInstructionList instances.
|
|
|
|
|
2021-01-15 21:43:26 +08:00
|
|
|
SBInstructionList supports instruction (:py:class:`SBInstruction` instance) iteration.
|
|
|
|
For example (see also :py:class:`SBDebugger` for a more complete example), ::
|
2011-07-21 08:48:02 +08:00
|
|
|
|
2021-01-15 21:43:26 +08:00
|
|
|
def disassemble_instructions (insts):
|
|
|
|
for i in insts:
|
|
|
|
print i
|
2011-07-21 08:48:02 +08:00
|
|
|
|
2011-07-21 08:50:54 +08:00
|
|
|
defines a function which takes an SBInstructionList instance and prints out
|
2011-07-21 08:48:02 +08:00
|
|
|
the machine instructions in assembly format."
|
|
|
|
) SBInstructionList;
|
2011-07-20 06:41:47 +08:00
|
|
|
class SBInstructionList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
SBInstructionList ();
|
|
|
|
|
|
|
|
SBInstructionList (const SBInstructionList &rhs);
|
2019-04-19 00:23:33 +08:00
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
~SBInstructionList ();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
size_t
|
|
|
|
GetSize ();
|
|
|
|
|
|
|
|
lldb::SBInstruction
|
|
|
|
GetInstructionAtIndex (uint32_t idx);
|
|
|
|
|
2017-05-04 19:34:42 +08:00
|
|
|
size_t GetInstructionsCount(const SBAddress &start, const SBAddress &end,
|
|
|
|
bool canSetBreakpoint);
|
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
void
|
|
|
|
Clear ();
|
|
|
|
|
|
|
|
void
|
|
|
|
AppendInstruction (lldb::SBInstruction inst);
|
|
|
|
|
|
|
|
void
|
2019-10-15 04:59:57 +08:00
|
|
|
Print (lldb::SBFile out);
|
|
|
|
|
|
|
|
void
|
|
|
|
Print (lldb::FileSP BORROWED);
|
2011-07-20 06:41:47 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
GetDescription (lldb::SBStream &description);
|
2019-04-19 00:23:33 +08:00
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
bool
|
|
|
|
DumpEmulationForAllInstructions (const char *triple);
|
2012-02-01 16:09:32 +08:00
|
|
|
|
2020-01-09 08:13:03 +08:00
|
|
|
STRING_EXTENSION(SBInstructionList)
|
|
|
|
|
2019-12-09 06:46:48 +08:00
|
|
|
#ifdef SWIGPYTHON
|
2012-02-01 16:09:32 +08:00
|
|
|
%pythoncode %{
|
2019-04-03 19:48:38 +08:00
|
|
|
def __iter__(self):
|
|
|
|
'''Iterate over all instructions in a lldb.SBInstructionList
|
|
|
|
object.'''
|
|
|
|
return lldb_iter(self, 'GetSize', 'GetInstructionAtIndex')
|
|
|
|
|
2012-02-01 16:09:32 +08:00
|
|
|
def __len__(self):
|
|
|
|
'''Access len of the instruction list.'''
|
2012-05-12 04:39:42 +08:00
|
|
|
return int(self.GetSize())
|
2012-02-01 16:09:32 +08:00
|
|
|
|
|
|
|
def __getitem__(self, key):
|
2012-06-30 06:00:42 +08:00
|
|
|
'''Access instructions by integer index for array access or by lldb.SBAddress to find an instruction that matches a section offset address object.'''
|
2012-02-01 16:09:32 +08:00
|
|
|
if type(key) is int:
|
|
|
|
# Find an instruction by index
|
|
|
|
if key < len(self):
|
|
|
|
return self.GetInstructionAtIndex(key)
|
|
|
|
elif type(key) is SBAddress:
|
|
|
|
# Find an instruction using a lldb.SBAddress object
|
|
|
|
lookup_file_addr = key.file_addr
|
|
|
|
closest_inst = None
|
|
|
|
for idx in range(self.GetSize()):
|
|
|
|
inst = self.GetInstructionAtIndex(idx)
|
|
|
|
inst_file_addr = inst.addr.file_addr
|
|
|
|
if inst_file_addr == lookup_file_addr:
|
|
|
|
return inst
|
|
|
|
elif inst_file_addr > lookup_file_addr:
|
|
|
|
return closest_inst
|
|
|
|
else:
|
|
|
|
closest_inst = inst
|
2019-04-19 00:23:33 +08:00
|
|
|
return None
|
2012-02-01 16:09:32 +08:00
|
|
|
%}
|
2019-12-09 06:46:48 +08:00
|
|
|
#endif
|
2012-02-01 16:09:32 +08:00
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace lldb
|