1 //===-- lldb-private-types.h ------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_LLDB_PRIVATE_TYPES_H 10 #define LLDB_LLDB_PRIVATE_TYPES_H 11 12 #include "lldb/lldb-private.h" 13 14 #include "llvm/ADT/ArrayRef.h" 15 #include "llvm/ADT/SmallString.h" 16 17 #include <type_traits> 18 19 namespace llvm { 20 namespace sys { 21 class DynamicLibrary; 22 } 23 } 24 25 namespace lldb_private { 26 class Platform; 27 class ExecutionContext; 28 class RegisterFlags; 29 30 typedef llvm::SmallString<256> PathSmallString; 31 32 typedef llvm::sys::DynamicLibrary (*LoadPluginCallbackType)( 33 const lldb::DebuggerSP &debugger_sp, const FileSpec &spec, Status &error); 34 35 /// Every register is described in detail including its name, alternate name 36 /// (optional), encoding, size in bytes and the default display format. 37 struct RegisterInfo { 38 /// Name of this register, can't be NULL. 39 const char *name; 40 /// Alternate name of this register, can be NULL. 41 const char *alt_name; 42 /// Size in bytes of the register. 43 uint32_t byte_size; 44 /// The byte offset in the register context data where this register's 45 /// value is found. 46 /// This is optional, and can be 0 if a particular RegisterContext does not 47 /// need to address its registers by byte offset. 48 uint32_t byte_offset; 49 /// Encoding of the register bits. 50 lldb::Encoding encoding; 51 /// Default display format. 52 lldb::Format format; 53 /// Holds all of the various register numbers for all register kinds. 54 uint32_t kinds[lldb::kNumRegisterKinds]; // 55 /// List of registers (terminated with LLDB_INVALID_REGNUM). If this value is 56 /// not null, all registers in this list will be read first, at which point 57 /// the value for this register will be valid. For example, the value list 58 /// for ah would be eax (x86) or rax (x64). Register numbers are 59 /// of eRegisterKindLLDB. If multiple registers are listed, the final 60 /// value will be the concatenation of them. 61 uint32_t *value_regs; 62 /// List of registers (terminated with LLDB_INVALID_REGNUM). If this value is 63 /// not null, all registers in this list will be invalidated when the value of 64 /// this register changes. For example, the invalidate list for eax would be 65 /// rax ax, ah, and al. 66 uint32_t *invalidate_regs; 67 /// If not nullptr, a type defined by XML descriptions. 68 /// Register info tables are constructed as const, but this field may need to 69 /// be updated if a specific target OS has a different layout. To enable that, 70 /// this is mutable. The data pointed to is still const, so you must swap a 71 /// whole set of flags for another. 72 mutable const RegisterFlags *flags_type; 73 74 llvm::ArrayRef<uint8_t> data(const uint8_t *context_base) const { 75 return llvm::ArrayRef<uint8_t>(context_base + byte_offset, byte_size); 76 } 77 78 llvm::MutableArrayRef<uint8_t> mutable_data(uint8_t *context_base) const { 79 return llvm::MutableArrayRef<uint8_t>(context_base + byte_offset, 80 byte_size); 81 } 82 }; 83 static_assert(std::is_trivial<RegisterInfo>::value, 84 "RegisterInfo must be trivial."); 85 86 /// Registers are grouped into register sets 87 struct RegisterSet { 88 /// Name of this register set. 89 const char *name; 90 /// A short name for this register set. 91 const char *short_name; 92 /// The number of registers in REGISTERS array below. 93 size_t num_registers; 94 /// An array of register indices in this set. The values in this array are 95 /// *indices* (not register numbers) into a particular RegisterContext's 96 /// register array. For example, if eax is defined at index 4 for a 97 /// particular RegisterContext, eax would be included in this RegisterSet by 98 /// adding the value 4. Not by adding the value lldb_eax_i386. 99 const uint32_t *registers; 100 }; 101 102 /// A type-erased pair of llvm::dwarf::SourceLanguageName and version. 103 struct SourceLanguage { 104 SourceLanguage() = default; 105 SourceLanguage(lldb::LanguageType language_type); 106 SourceLanguage(uint16_t name, uint32_t version) 107 : name(name), version(version) {} 108 SourceLanguage(std::optional<std::pair<uint16_t, uint32_t>> name_vers) 109 : name(name_vers ? name_vers->first : 0), 110 version(name_vers ? name_vers->second : 0) {} 111 operator bool() const { return name > 0; } 112 lldb::LanguageType AsLanguageType() const; 113 llvm::StringRef GetDescription() const; 114 bool IsC() const; 115 bool IsObjC() const; 116 bool IsCPlusPlus() const; 117 uint16_t name = 0; 118 uint32_t version = 0; 119 }; 120 121 struct OptionEnumValueElement { 122 int64_t value; 123 const char *string_value; 124 const char *usage; 125 }; 126 127 using OptionEnumValues = llvm::ArrayRef<OptionEnumValueElement>; 128 129 struct OptionValidator { 130 virtual ~OptionValidator() = default; 131 virtual bool IsValid(Platform &platform, 132 const ExecutionContext &target) const = 0; 133 virtual const char *ShortConditionString() const = 0; 134 virtual const char *LongConditionString() const = 0; 135 }; 136 137 typedef struct type128 { uint64_t x[2]; } type128; 138 typedef struct type256 { uint64_t x[4]; } type256; 139 140 /// Functor that returns a ValueObjectSP for a variable given its name 141 /// and the StackFrame of interest. Used primarily in the Materializer 142 /// to refetch a ValueObject when the ExecutionContextScope changes. 143 using ValueObjectProviderTy = 144 std::function<lldb::ValueObjectSP(ConstString, StackFrame *)>; 145 146 typedef void (*DebuggerDestroyCallback)(lldb::user_id_t debugger_id, 147 void *baton); 148 typedef bool (*CommandOverrideCallbackWithResult)( 149 void *baton, const char **argv, lldb_private::CommandReturnObject &result); 150 } // namespace lldb_private 151 152 #endif // LLDB_LLDB_PRIVATE_TYPES_H 153