LLDB mainline
GNUstepObjCRuntime.cpp
Go to the documentation of this file.
1//===-- GNUstepObjCRuntime.cpp --------------------------------------------===//
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
10
11#include "lldb/Core/Module.h"
15#include "lldb/Target/Process.h"
16#include "lldb/Target/Target.h"
20
21using namespace lldb;
22using namespace lldb_private;
23
25
27
30 GetPluginNameStatic(), "GNUstep Objective-C Language Runtime - libobjc2",
32}
33
37
38static bool CanModuleBeGNUstepObjCLibrary(const ModuleSP &module_sp,
39 const llvm::Triple &TT) {
40 if (!module_sp)
41 return false;
42 const FileSpec &module_file_spec = module_sp->GetFileSpec();
43 if (!module_file_spec)
44 return false;
45 llvm::StringRef filename = module_file_spec.GetFilename();
46 if (TT.isOSBinFormatELF())
47 return filename.starts_with("libobjc.so");
48 if (TT.isOSWindows())
49 return filename == "objc.dll";
50 return false;
51}
52
54 const llvm::Triple &TT) {
55 std::lock_guard<std::recursive_mutex> guard(modules.GetMutex());
56 size_t num_modules = modules.GetSize();
57 for (size_t i = 0; i < num_modules; i++) {
58 auto mod = modules.GetModuleAtIndex(i);
60 return true;
61 }
62 return false;
63}
64
66 LanguageType language) {
67 if (language != eLanguageTypeObjC)
68 return nullptr;
69 if (!process)
70 return nullptr;
71
72 Target &target = process->GetTarget();
73 const llvm::Triple &TT = target.GetArchitecture().GetTriple();
74 if (TT.getVendor() == llvm::Triple::VendorType::Apple)
75 return nullptr;
76
77 const ModuleList &images = target.GetImages();
79 return nullptr;
80
81 if (TT.isOSBinFormatELF()) {
82 SymbolContextList eh_pers;
83 RegularExpression regex("__gnustep_objc[x]*_personality_v[0-9]+");
85 if (eh_pers.GetSize() == 0)
86 return nullptr;
87 } else if (TT.isOSWindows()) {
88 SymbolContextList objc_mandatory;
89 images.FindSymbolsWithNameAndType(ConstString("__objc_load"),
90 eSymbolTypeCode, objc_mandatory);
91 if (objc_mandatory.GetSize() == 0)
92 return nullptr;
93 }
94
95 return new GNUstepObjCRuntime(process);
96}
97
99
104
106 ValueObject &valobj) {
107 return llvm::createStringError(
108 "LLDB's GNUStep runtime does not support object description");
109}
110
111llvm::Error
113 ExecutionContextScope *exe_scope) {
114 return llvm::createStringError(
115 "LLDB's GNUStep runtime does not support object description");
116}
117
119 static constexpr bool check_cxx = false;
120 static constexpr bool check_objc = true;
121 return in_value.GetCompilerType().IsPossibleDynamicType(nullptr, check_cxx,
122 check_objc);
123}
124
126 ValueObject &in_value, DynamicValueType use_dynamic,
127 TypeAndOrName &class_type_or_name, Address &address,
128 Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
129 return false;
130}
131
134 ValueObject &static_value) {
135 CompilerType static_type(static_value.GetCompilerType());
136 Flags static_type_flags(static_type.GetTypeInfo());
137
138 TypeAndOrName ret(type_and_or_name);
139 if (type_and_or_name.HasType()) {
140 // The type will always be the type of the dynamic object. If our parent's
141 // type was a pointer, then our type should be a pointer to the type of the
142 // dynamic object. If a reference, then the original type should be
143 // okay...
144 CompilerType orig_type = type_and_or_name.GetCompilerType();
145 CompilerType corrected_type = orig_type;
146 if (static_type_flags.AllSet(eTypeIsPointer))
147 corrected_type = orig_type.GetPointerType();
148 ret.SetCompilerType(corrected_type);
149 } else {
150 // If we are here we need to adjust our dynamic type name to include the
151 // correct & or * symbol
152 std::string corrected_name(type_and_or_name.GetName().GetCString());
153 if (static_type_flags.AllSet(eTypeIsPointer))
154 corrected_name.append(" *");
155 // the parent type should be a correctly pointer'ed or referenc'ed type
156 ret.SetCompilerType(static_type);
157 ret.SetName(corrected_name.c_str());
158 }
159 return ret;
160}
161
164 bool catch_bp, bool throw_bp) {
165 BreakpointResolverSP resolver_sp;
166
167 if (throw_bp)
168 resolver_sp = std::make_shared<BreakpointResolverName>(
169 bkpt, "objc_exception_throw", eFunctionNameTypeBase,
171 /*offset_is_insn_count = */ false, eLazyBoolNo);
172
173 return resolver_sp;
174}
175
176llvm::Expected<std::unique_ptr<UtilityFunction>>
178 ExecutionContext &exe_ctx) {
179 // TODO: This function is supposed to check whether an ObjC selector is
180 // present for an object. Might be implemented similar as in the Apple V2
181 // runtime.
182 const char *function_template = R"(
183 extern "C" void
184 %s(void *$__lldb_arg_obj, void *$__lldb_arg_selector) {}
185 )";
186
187 char empty_function_code[2048];
188 int len = ::snprintf(empty_function_code, sizeof(empty_function_code),
189 function_template, name.c_str());
190
191 assert(len < (int)sizeof(empty_function_code));
193
194 return GetTargetRef().CreateUtilityFunction(empty_function_code, name,
195 eLanguageTypeC, exe_ctx);
197
200 bool stop_others) {
201 // TODO: Implement this properly to avoid stepping into things like PLT stubs
202 return nullptr;
203}
204
206 // TODO: Support lazily named and dynamically loaded Objective-C classes
207}
208
210 const llvm::Triple &TT = GetTargetRef().GetArchitecture().GetTriple();
211 return CanModuleBeGNUstepObjCLibrary(module_sp, TT);
212}
213
214bool GNUstepObjCRuntime::ReadObjCLibrary(const ModuleSP &module_sp) {
215 assert(m_objc_module_sp == nullptr && "Check HasReadObjCLibrary() first");
216 m_objc_module_sp = module_sp;
217
218 // Right now we don't use this, but we might want to check for debugger
219 // runtime support symbols like 'gdb_object_getClass' in the future.
220 return true;
221}
222
223void GNUstepObjCRuntime::ModulesDidLoad(const ModuleList &module_list) {
224 ReadObjCLibraryIfNeeded(module_list);
225}
static bool ScanForGNUstepObjCLibraryCandidate(const ModuleList &modules, const llvm::Triple &TT)
static bool CanModuleBeGNUstepObjCLibrary(const ModuleSP &module_sp, const llvm::Triple &TT)
#define LLDB_PLUGIN_DEFINE(PluginName)
A section + offset based address class.
Definition Address.h:62
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:465
Generic representation of a type in a programming language.
bool IsPossibleDynamicType(CompilerType *target_type, bool check_cplusplus, bool check_objc) const
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition FileSpec.h:56
llvm::StringRef GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:248
A class to manage flags.
Definition Flags.h:22
bool AllSet(ValueType mask) const
Test if all bits in mask are 1 in the current flags.
Definition Flags.h:83
bool CouldHaveDynamicValue(ValueObject &in_value) override
bool GetDynamicTypeAndAddress(ValueObject &in_value, lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name, Address &address, Value::ValueType &value_type, llvm::ArrayRef< uint8_t > &local_buffer) override
This call should return true if it could set the name and/or the type Sets address to the address of ...
llvm::Expected< std::unique_ptr< UtilityFunction > > CreateObjectChecker(std::string name, ExecutionContext &exe_ctx) override
TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, ValueObject &static_value) override
static lldb_private::LanguageRuntime * CreateInstance(Process *process, lldb::LanguageType language)
bool ReadObjCLibrary(const lldb::ModuleSP &module_sp) override
bool IsModuleObjCLibrary(const lldb::ModuleSP &module_sp) override
static llvm::StringRef GetPluginNameStatic()
lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, bool stop_others) override
llvm::Error GetObjectDescription(Stream &str, Value &value, ExecutionContextScope *exe_scope) override
lldb::BreakpointResolverSP CreateExceptionResolver(const lldb::BreakpointSP &bkpt, bool catch_bp, bool throw_bp) override
void ModulesDidLoad(const ModuleList &module_list) override
Called when modules have been loaded in the process.
A collection class for Module objects.
Definition ModuleList.h:139
std::recursive_mutex & GetMutex() const
Definition ModuleList.h:266
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
void FindSymbolsWithNameAndType(llvm::StringRef name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
void FindSymbolsMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
size_t GetSize() const
Gets the size of the module list.
void ReadObjCLibraryIfNeeded(const ModuleList &module_list)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
Definition Process.h:370
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1271
Target & GetTargetRef()
Definition Runtime.h:23
A stream class that can stream formatted output to a file.
Definition Stream.h:28
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
llvm::Expected< std::unique_ptr< UtilityFunction > > CreateUtilityFunction(std::string expression, std::string name, lldb::LanguageType language, ExecutionContext &exe_ctx)
Creates and installs a UtilityFunction for the given language.
Definition Target.cpp:2948
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1295
const ArchSpec & GetArchitecture() const
Definition Target.h:1337
Sometimes you can find the name of the type corresponding to an object, but we don't have debug infor...
void SetName(ConstString type_name)
ConstString GetName() const
void SetCompilerType(CompilerType compiler_type)
CompilerType GetCompilerType()
ValueType
Type that describes Value::m_value.
Definition Value.h:42
#define UNUSED_IF_ASSERT_DISABLED(x)
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::BreakpointResolver > BreakpointResolverSP
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Module > ModuleSP