AppleObjCRuntime.h revision 355940
1//===-- AppleObjCRuntime.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 liblldb_AppleObjCRuntime_h_
10#define liblldb_AppleObjCRuntime_h_
11
12#include "llvm/ADT/Optional.h"
13
14#include "AppleObjCTrampolineHandler.h"
15#include "AppleThreadPlanStepThroughObjCTrampoline.h"
16#include "lldb/Target/LanguageRuntime.h"
17#include "lldb/lldb-private.h"
18
19#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
20
21namespace lldb_private {
22
23class AppleObjCRuntime : public lldb_private::ObjCLanguageRuntime {
24public:
25  ~AppleObjCRuntime() override;
26
27  // Static Functions
28  // Note there is no CreateInstance, Initialize & Terminate functions here,
29  // because
30  // you can't make an instance of this generic runtime.
31
32  static char ID;
33
34  bool isA(const void *ClassID) const override {
35    return ClassID == &ID || ObjCLanguageRuntime::isA(ClassID);
36  }
37
38  static bool classof(const LanguageRuntime *runtime) {
39    return runtime->isA(&ID);
40  }
41
42  // These are generic runtime functions:
43  bool GetObjectDescription(Stream &str, Value &value,
44                            ExecutionContextScope *exe_scope) override;
45
46  bool GetObjectDescription(Stream &str, ValueObject &object) override;
47
48  bool CouldHaveDynamicValue(ValueObject &in_value) override;
49
50  bool GetDynamicTypeAndAddress(ValueObject &in_value,
51                                lldb::DynamicValueType use_dynamic,
52                                TypeAndOrName &class_type_or_name,
53                                Address &address,
54                                Value::ValueType &value_type) override;
55
56  TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name,
57                                 ValueObject &static_value) override;
58
59  // These are the ObjC specific functions.
60
61  bool IsModuleObjCLibrary(const lldb::ModuleSP &module_sp) override;
62
63  bool ReadObjCLibrary(const lldb::ModuleSP &module_sp) override;
64
65  bool HasReadObjCLibrary() override { return m_read_objc_library; }
66
67  lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
68                                                  bool stop_others) override;
69
70  // Get the "libobjc.A.dylib" module from the current target if we can find
71  // it, also cache it once it is found to ensure quick lookups.
72  lldb::ModuleSP GetObjCModule();
73
74  // Sync up with the target
75
76  void ModulesDidLoad(const ModuleList &module_list) override;
77
78  void SetExceptionBreakpoints() override;
79
80  void ClearExceptionBreakpoints() override;
81
82  bool ExceptionBreakpointsAreSet() override;
83
84  bool ExceptionBreakpointsExplainStop(lldb::StopInfoSP stop_reason) override;
85
86  lldb::SearchFilterSP CreateExceptionSearchFilter() override;
87
88  static std::tuple<FileSpec, ConstString> GetExceptionThrowLocation();
89
90  lldb::ValueObjectSP GetExceptionObjectForThread(
91      lldb::ThreadSP thread_sp) override;
92
93  lldb::ThreadSP GetBacktraceThreadFromException(
94      lldb::ValueObjectSP thread_sp) override;
95
96  uint32_t GetFoundationVersion();
97
98  virtual void GetValuesForGlobalCFBooleans(lldb::addr_t &cf_true,
99                                            lldb::addr_t &cf_false);
100
101  virtual bool IsTaggedPointer (lldb::addr_t addr) { return false; }
102
103protected:
104  // Call CreateInstance instead.
105  AppleObjCRuntime(Process *process);
106
107  bool CalculateHasNewLiteralsAndIndexing() override;
108
109  static bool AppleIsModuleObjCLibrary(const lldb::ModuleSP &module_sp);
110
111  static ObjCRuntimeVersions GetObjCVersion(Process *process,
112                                            lldb::ModuleSP &objc_module_sp);
113
114  void ReadObjCLibraryIfNeeded(const ModuleList &module_list);
115
116  Address *GetPrintForDebuggerAddr();
117
118  std::unique_ptr<Address> m_PrintForDebugger_addr;
119  bool m_read_objc_library;
120  std::unique_ptr<lldb_private::AppleObjCTrampolineHandler>
121      m_objc_trampoline_handler_up;
122  lldb::BreakpointSP m_objc_exception_bp_sp;
123  lldb::ModuleWP m_objc_module_wp;
124  std::unique_ptr<FunctionCaller> m_print_object_caller_up;
125
126  llvm::Optional<uint32_t> m_Foundation_major;
127};
128
129} // namespace lldb_private
130
131#endif // liblldb_AppleObjCRuntime_h_
132