1 //===-- CPPLanguageRuntime.h 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_SOURCE_PLUGINS_LANGUAGERUNTIME_CPLUSPLUS_CPPLANGUAGERUNTIME_H 10 #define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_CPLUSPLUS_CPPLANGUAGERUNTIME_H 11 12 #include <vector> 13 14 #include "llvm/ADT/StringMap.h" 15 16 #include "lldb/Core/PluginInterface.h" 17 #include "lldb/Target/LanguageRuntime.h" 18 #include "lldb/lldb-private.h" 19 20 namespace lldb_private { 21 22 class CPPLanguageRuntime : public LanguageRuntime { 23 public: 24 enum class LibCppStdFunctionCallableCase { 25 Lambda = 0, 26 CallableObject, 27 FreeOrMemberFunction, 28 Invalid 29 }; 30 31 struct LibCppStdFunctionCallableInfo { 32 Symbol callable_symbol; 33 Address callable_address; 34 LineEntry callable_line_entry; 35 lldb::addr_t member__f_pointer_value = 0u; 36 LibCppStdFunctionCallableCase callable_case = 37 LibCppStdFunctionCallableCase::Invalid; 38 }; 39 40 LibCppStdFunctionCallableInfo 41 FindLibCppStdFunctionCallableInfo(lldb::ValueObjectSP &valobj_sp); 42 43 ~CPPLanguageRuntime() override; 44 45 static char ID; 46 47 bool isA(const void *ClassID) const override { 48 return ClassID == &ID || LanguageRuntime::isA(ClassID); 49 } 50 51 static bool classof(const LanguageRuntime *runtime) { 52 return runtime->isA(&ID); 53 } 54 55 lldb::LanguageType GetLanguageType() const override { 56 return lldb::eLanguageTypeC_plus_plus; 57 } 58 59 static CPPLanguageRuntime *Get(Process &process) { 60 return llvm::cast_or_null<CPPLanguageRuntime>( 61 process.GetLanguageRuntime(lldb::eLanguageTypeC_plus_plus)); 62 } 63 64 bool GetObjectDescription(Stream &str, ValueObject &object) override; 65 66 bool GetObjectDescription(Stream &str, Value &value, 67 ExecutionContextScope *exe_scope) override; 68 69 /// Obtain a ThreadPlan to get us into C++ constructs such as std::function. 70 /// 71 /// \param[in] thread 72 /// Current thrad of execution. 73 /// 74 /// \param[in] stop_others 75 /// True if other threads should pause during execution. 76 /// 77 /// \return 78 /// A ThreadPlan Shared pointer 79 lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, 80 bool stop_others) override; 81 82 bool IsAllowedRuntimeValue(ConstString name) override; 83 protected: 84 // Classes that inherit from CPPLanguageRuntime can see and modify these 85 CPPLanguageRuntime(Process *process); 86 87 private: 88 using OperatorStringToCallableInfoMap = 89 llvm::StringMap<CPPLanguageRuntime::LibCppStdFunctionCallableInfo>; 90 91 OperatorStringToCallableInfoMap CallableLookupCache; 92 93 CPPLanguageRuntime(const CPPLanguageRuntime &) = delete; 94 const CPPLanguageRuntime &operator=(const CPPLanguageRuntime &) = delete; 95 }; 96 97 } // namespace lldb_private 98 99 #endif // LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_CPLUSPLUS_CPPLANGUAGERUNTIME_H 100