diff options
Diffstat (limited to 'include/lldb/Utility')
-rw-r--r-- | include/lldb/Utility/CleanUp.h | 5 | ||||
-rw-r--r-- | include/lldb/Utility/Iterable.h | 5 | ||||
-rw-r--r-- | include/lldb/Utility/ProcessStructReader.h | 100 | ||||
-rw-r--r-- | include/lldb/Utility/RegisterNumber.h | 69 | ||||
-rw-r--r-- | include/lldb/Utility/StringLexer.h | 17 |
5 files changed, 191 insertions, 5 deletions
diff --git a/include/lldb/Utility/CleanUp.h b/include/lldb/Utility/CleanUp.h index 9dd3ca5fe12b3..9ffe5de27df19 100644 --- a/include/lldb/Utility/CleanUp.h +++ b/include/lldb/Utility/CleanUp.h @@ -11,6 +11,7 @@ #define liblldb_CleanUp_h_ #include "lldb/lldb-public.h" +#include <functional> namespace lldb_utility { @@ -57,7 +58,7 @@ class CleanUp { public: typedef T value_type; - typedef R (*CallbackType)(value_type); + typedef std::function<R(value_type)> CallbackType; //---------------------------------------------------------------------- // Constructor that sets the current value only. No values are @@ -188,7 +189,7 @@ class CleanUp2 { public: typedef T value_type; - typedef R (*CallbackType)(value_type, A0); + typedef std::function<R(value_type,A0)> CallbackType; //---------------------------------------------------------------------- // Constructor that sets the current value only. No values are diff --git a/include/lldb/Utility/Iterable.h b/include/lldb/Utility/Iterable.h index 17335373e72d8..17c8cf4d23193 100644 --- a/include/lldb/Utility/Iterable.h +++ b/include/lldb/Utility/Iterable.h @@ -25,6 +25,11 @@ template <typename I, typename E> E vector_adapter(I &iter) return *iter; } +template <typename I, typename E> E list_adapter(I &iter) +{ + return *iter; +} + template <typename C, typename E, E (*A)(typename C::const_iterator &)> class AdaptedConstIterator { public: diff --git a/include/lldb/Utility/ProcessStructReader.h b/include/lldb/Utility/ProcessStructReader.h new file mode 100644 index 0000000000000..7b05d93151aa3 --- /dev/null +++ b/include/lldb/Utility/ProcessStructReader.h @@ -0,0 +1,100 @@ +//===---------------------ProcessStructReader.h ------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef utility_ProcessStructReader_h_ +#define utility_ProcessStructReader_h_ + +#include "lldb/lldb-defines.h" +#include "lldb/lldb-types.h" + +#include "lldb/Core/ConstString.h" +#include "lldb/Core/DataExtractor.h" +#include "lldb/Core/Error.h" +#include "lldb/Symbol/ClangASTType.h" +#include "lldb/Target/Process.h" + +#include <initializer_list> +#include <map> +#include <string> + +namespace lldb_private { + class ProcessStructReader + { + protected: + struct FieldImpl + { + ClangASTType type; + size_t offset; + size_t size; + }; + + std::map<ConstString, FieldImpl> m_fields; + DataExtractor m_data; + lldb::ByteOrder m_byte_order; + size_t m_addr_byte_size; + + public: + ProcessStructReader (Process *process, lldb::addr_t base_addr, ClangASTType struct_type) + { + if (!process) + return; + if (base_addr == 0 || base_addr == LLDB_INVALID_ADDRESS) + return; + m_byte_order = process->GetByteOrder(); + m_addr_byte_size = process->GetAddressByteSize(); + + for (size_t idx = 0; idx < struct_type.GetNumFields(); idx++) + { + std::string name; + uint64_t bit_offset; + uint32_t bitfield_bit_size; + bool is_bitfield; + ClangASTType field_type = struct_type.GetFieldAtIndex(idx,name,&bit_offset,&bitfield_bit_size,&is_bitfield); + // no support for bitfields in here (yet) + if (is_bitfield) + return; + auto size = field_type.GetByteSize(); + // no support for things larger than a uint64_t (yet) + if (size > 8) + return; + ConstString const_name = ConstString(name.c_str()); + size_t byte_index = static_cast<size_t>(bit_offset / 8); + m_fields[const_name] = FieldImpl{field_type, byte_index, static_cast<size_t>(size)}; + } + size_t total_size = struct_type.GetByteSize(); + lldb::DataBufferSP buffer_sp(new DataBufferHeap(total_size,0)); + Error error; + process->ReadMemoryFromInferior(base_addr, + buffer_sp->GetBytes(), + total_size, + error); + if (error.Fail()) + return; + m_data = DataExtractor(buffer_sp,m_byte_order,m_addr_byte_size); + } + + template<typename RetType> + RetType + GetField (ConstString name, RetType fail_value = RetType()) + { + auto iter = m_fields.find(name), end = m_fields.end(); + if (iter == end) + return fail_value; + auto size = iter->second.size; + if (sizeof(RetType) < size) + return fail_value; + lldb::offset_t offset = iter->second.offset; + if (offset + size > m_data.GetByteSize()) + return fail_value; + return (RetType)(m_data.GetMaxU64(&offset, size)); + } + }; +} + +#endif // utility_ProcessStructReader_h_ diff --git a/include/lldb/Utility/RegisterNumber.h b/include/lldb/Utility/RegisterNumber.h new file mode 100644 index 0000000000000..89d52fd4a967a --- /dev/null +++ b/include/lldb/Utility/RegisterNumber.h @@ -0,0 +1,69 @@ +//===-- RegisterNumber.h ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_RegisterNumber_h +#define liblldb_RegisterNumber_h + +#include "lldb/lldb-private.h" +#include <map> + +//-------------------------------------------------------------------- +/// A class to represent register numbers, and able to convert between +/// different register numbering schemes that may be used in a single +/// debug session. +//-------------------------------------------------------------------- + +class RegisterNumber { +public: + RegisterNumber (lldb_private::Thread &thread, lldb::RegisterKind kind, uint32_t num); + + // This constructor plus the init() method below allow for the placeholder + // creation of an invalid object initially, possibly to be filled in. It + // would be more consistent to have three Set* methods to set the three + // data that the object needs. + RegisterNumber (); + + void + init (lldb_private::Thread &thread, lldb::RegisterKind kind, uint32_t num); + + const RegisterNumber & + operator = (const RegisterNumber &rhs); + + bool + operator == (RegisterNumber &rhs); + + bool + operator != (RegisterNumber &rhs); + + bool + IsValid () const; + + uint32_t + GetAsKind (lldb::RegisterKind kind); + + uint32_t + GetRegisterNumber () const; + + lldb::RegisterKind + GetRegisterKind () const; + + const char * + GetName (); + +private: + typedef std::map<lldb::RegisterKind, uint32_t> Collection; + + lldb::RegisterContextSP m_reg_ctx_sp; + uint32_t m_regnum; + lldb::RegisterKind m_kind; + Collection m_kind_regnum_map; + const char *m_name; +}; + +#endif // liblldb_RegisterNumber_h diff --git a/include/lldb/Utility/StringLexer.h b/include/lldb/Utility/StringLexer.h index 42c169c5cf940..ae6b393b0eb68 100644 --- a/include/lldb/Utility/StringLexer.h +++ b/include/lldb/Utility/StringLexer.h @@ -10,8 +10,9 @@ #ifndef utility_StringLexer_h_ #define utility_StringLexer_h_ -#include <string> +#include <initializer_list> #include <list> +#include <string> namespace lldb_utility { @@ -27,12 +28,19 @@ public: StringLexer (const StringLexer& rhs); + // These APIs are not bounds-checked. Use HasAtLeast() if you're not sure. Character Peek (); bool NextIf (Character c); + std::pair<bool, Character> + NextIf (std::initializer_list<Character> cs); + + bool + AdvanceIf (const std::string& token); + Character Next (); @@ -42,8 +50,12 @@ public: bool HasAny (Character c); + std::string + GetUnlexed (); + + // This will assert if there are less than s characters preceding the cursor. void - PutBack (Character c); + PutBack (Size s); StringLexer& operator = (const StringLexer& rhs); @@ -51,7 +63,6 @@ public: private: std::string m_data; Position m_position; - std::list<Character> m_putback_data; void Consume(); |