LLDB  mainline
IRDynamicChecks.cpp
Go to the documentation of this file.
1 //===-- IRDynamicChecks.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 
9 #include "llvm/IR/Constants.h"
10 #include "llvm/IR/DataLayout.h"
11 #include "llvm/IR/Function.h"
12 #include "llvm/IR/Instructions.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/IR/Value.h"
15 #include "llvm/Support/raw_ostream.h"
16 
17 #include "IRDynamicChecks.h"
18 
21 #include "lldb/Target/Process.h"
22 #include "lldb/Target/StackFrame.h"
23 #include "lldb/Target/Target.h"
25 #include "lldb/Utility/Log.h"
26 
28 
29 using namespace llvm;
30 using namespace lldb_private;
31 
32 static char ID;
33 
34 #define VALID_POINTER_CHECK_NAME "_$__lldb_valid_pointer_check"
35 #define VALID_OBJC_OBJECT_CHECK_NAME "$__lldb_objc_object_check"
36 
37 static const char g_valid_pointer_check_text[] =
38  "extern \"C\" void\n"
39  "_$__lldb_valid_pointer_check (unsigned char *$__lldb_arg_ptr)\n"
40  "{\n"
41  " unsigned char $__lldb_local_val = *$__lldb_arg_ptr;\n"
42  "}";
43 
44 ClangDynamicCheckerFunctions::ClangDynamicCheckerFunctions()
45  : DynamicCheckerFunctions(DCF_Clang) {}
46 
48 
50  DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) {
51  auto utility_fn_or_error = exe_ctx.GetTargetRef().CreateUtilityFunction(
53  lldb::eLanguageTypeC, exe_ctx);
54  if (!utility_fn_or_error) {
55  llvm::consumeError(utility_fn_or_error.takeError());
56  return false;
57  }
58  m_valid_pointer_check = std::move(*utility_fn_or_error);
59 
60  if (Process *process = exe_ctx.GetProcessPtr()) {
61  ObjCLanguageRuntime *objc_language_runtime =
62  ObjCLanguageRuntime::Get(*process);
63 
64  if (objc_language_runtime) {
65  auto utility_fn_or_error = objc_language_runtime->CreateObjectChecker(
67  if (!utility_fn_or_error) {
68  llvm::consumeError(utility_fn_or_error.takeError());
69  return false;
70  }
71  m_objc_object_check = std::move(*utility_fn_or_error);
72  }
73  }
74 
75  return true;
76 }
77 
79  Stream &message) {
80  // FIXME: We have to get the checkers to know why they scotched the call in
81  // more detail,
82  // so we can print a better message here.
83  if (m_valid_pointer_check && m_valid_pointer_check->ContainsAddress(addr)) {
84  message.Printf("Attempted to dereference an invalid pointer.");
85  return true;
86  } else if (m_objc_object_check &&
87  m_objc_object_check->ContainsAddress(addr)) {
88  message.Printf("Attempted to dereference an invalid ObjC Object or send it "
89  "an unrecognized selector");
90  return true;
91  }
92  return false;
93 }
94 
95 static std::string PrintValue(llvm::Value *V, bool truncate = false) {
96  std::string s;
97  raw_string_ostream rso(s);
98  V->print(rso);
99  rso.flush();
100  if (truncate)
101  s.resize(s.length() - 1);
102  return s;
103 }
104 
105 /// \class Instrumenter IRDynamicChecks.cpp
106 /// Finds and instruments individual LLVM IR instructions
107 ///
108 /// When instrumenting LLVM IR, it is frequently desirable to first search for
109 /// instructions, and then later modify them. This way iterators remain
110 /// intact, and multiple passes can look at the same code base without
111 /// treading on each other's toes.
112 ///
113 /// The Instrumenter class implements this functionality. A client first
114 /// calls Inspect on a function, which populates a list of instructions to be
115 /// instrumented. Then, later, when all passes' Inspect functions have been
116 /// called, the client calls Instrument, which adds the desired
117 /// instrumentation.
118 ///
119 /// A subclass of Instrumenter must override InstrumentInstruction, which
120 /// is responsible for adding whatever instrumentation is necessary.
121 ///
122 /// A subclass of Instrumenter may override:
123 ///
124 /// - InspectInstruction [default: does nothing]
125 ///
126 /// - InspectBasicBlock [default: iterates through the instructions in a
127 /// basic block calling InspectInstruction]
128 ///
129 /// - InspectFunction [default: iterates through the basic blocks in a
130 /// function calling InspectBasicBlock]
132 public:
133  /// Constructor
134  ///
135  /// \param[in] module
136  /// The module being instrumented.
137  Instrumenter(llvm::Module &module,
138  std::shared_ptr<UtilityFunction> checker_function)
139  : m_module(module), m_checker_function(checker_function),
140  m_i8ptr_ty(nullptr), m_intptr_ty(nullptr) {}
141 
142  virtual ~Instrumenter() = default;
143 
144  /// Inspect a function to find instructions to instrument
145  ///
146  /// \param[in] function
147  /// The function to inspect.
148  ///
149  /// \return
150  /// True on success; false on error.
151  bool Inspect(llvm::Function &function) { return InspectFunction(function); }
152 
153  /// Instrument all the instructions found by Inspect()
154  ///
155  /// \return
156  /// True on success; false on error.
157  bool Instrument() {
158  for (InstIterator ii = m_to_instrument.begin(),
159  last_ii = m_to_instrument.end();
160  ii != last_ii; ++ii) {
161  if (!InstrumentInstruction(*ii))
162  return false;
163  }
164 
165  return true;
166  }
167 
168 protected:
169  /// Add instrumentation to a single instruction
170  ///
171  /// \param[in] inst
172  /// The instruction to be instrumented.
173  ///
174  /// \return
175  /// True on success; false otherwise.
176  virtual bool InstrumentInstruction(llvm::Instruction *inst) = 0;
177 
178  /// Register a single instruction to be instrumented
179  ///
180  /// \param[in] inst
181  /// The instruction to be instrumented.
182  void RegisterInstruction(llvm::Instruction &inst) {
183  m_to_instrument.push_back(&inst);
184  }
185 
186  /// Determine whether a single instruction is interesting to instrument,
187  /// and, if so, call RegisterInstruction
188  ///
189  /// \param[in] i
190  /// The instruction to be inspected.
191  ///
192  /// \return
193  /// False if there was an error scanning; true otherwise.
194  virtual bool InspectInstruction(llvm::Instruction &i) { return true; }
195 
196  /// Scan a basic block to see if any instructions are interesting
197  ///
198  /// \param[in] bb
199  /// The basic block to be inspected.
200  ///
201  /// \return
202  /// False if there was an error scanning; true otherwise.
203  virtual bool InspectBasicBlock(llvm::BasicBlock &bb) {
204  for (llvm::BasicBlock::iterator ii = bb.begin(), last_ii = bb.end();
205  ii != last_ii; ++ii) {
206  if (!InspectInstruction(*ii))
207  return false;
208  }
209 
210  return true;
211  }
212 
213  /// Scan a function to see if any instructions are interesting
214  ///
215  /// \param[in] f
216  /// The function to be inspected.
217  ///
218  /// \return
219  /// False if there was an error scanning; true otherwise.
220  virtual bool InspectFunction(llvm::Function &f) {
221  for (llvm::Function::iterator bbi = f.begin(), last_bbi = f.end();
222  bbi != last_bbi; ++bbi) {
223  if (!InspectBasicBlock(*bbi))
224  return false;
225  }
226 
227  return true;
228  }
229 
230  /// Build a function pointer for a function with signature void
231  /// (*)(uint8_t*) with a given address
232  ///
233  /// \param[in] start_address
234  /// The address of the function.
235  ///
236  /// \return
237  /// The function pointer, for use in a CallInst.
238  llvm::FunctionCallee BuildPointerValidatorFunc(lldb::addr_t start_address) {
239  llvm::Type *param_array[1];
240 
241  param_array[0] = const_cast<llvm::PointerType *>(GetI8PtrTy());
242 
243  ArrayRef<llvm::Type *> params(param_array, 1);
244 
245  FunctionType *fun_ty = FunctionType::get(
246  llvm::Type::getVoidTy(m_module.getContext()), params, true);
247  PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
248  Constant *fun_addr_int =
249  ConstantInt::get(GetIntptrTy(), start_address, false);
250  return {fun_ty, ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty)};
251  }
252 
253  /// Build a function pointer for a function with signature void
254  /// (*)(uint8_t*, uint8_t*) with a given address
255  ///
256  /// \param[in] start_address
257  /// The address of the function.
258  ///
259  /// \return
260  /// The function pointer, for use in a CallInst.
261  llvm::FunctionCallee BuildObjectCheckerFunc(lldb::addr_t start_address) {
262  llvm::Type *param_array[2];
263 
264  param_array[0] = const_cast<llvm::PointerType *>(GetI8PtrTy());
265  param_array[1] = const_cast<llvm::PointerType *>(GetI8PtrTy());
266 
267  ArrayRef<llvm::Type *> params(param_array, 2);
268 
269  FunctionType *fun_ty = FunctionType::get(
270  llvm::Type::getVoidTy(m_module.getContext()), params, true);
271  PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
272  Constant *fun_addr_int =
273  ConstantInt::get(GetIntptrTy(), start_address, false);
274  return {fun_ty, ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty)};
275  }
276 
277  PointerType *GetI8PtrTy() {
278  if (!m_i8ptr_ty)
279  m_i8ptr_ty = llvm::Type::getInt8PtrTy(m_module.getContext());
280 
281  return m_i8ptr_ty;
282  }
283 
284  IntegerType *GetIntptrTy() {
285  if (!m_intptr_ty) {
286  llvm::DataLayout data_layout(&m_module);
287 
288  m_intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
289  data_layout.getPointerSizeInBits());
290  }
291 
292  return m_intptr_ty;
293  }
294 
295  typedef std::vector<llvm::Instruction *> InstVector;
296  typedef InstVector::iterator InstIterator;
297 
298  InstVector m_to_instrument; ///< List of instructions the inspector found
299  llvm::Module &m_module; ///< The module which is being instrumented
300  std::shared_ptr<UtilityFunction>
301  m_checker_function; ///< The dynamic checker function for the process
302 
303 private:
304  PointerType *m_i8ptr_ty;
305  IntegerType *m_intptr_ty;
306 };
307 
309 public:
310  ValidPointerChecker(llvm::Module &module,
311  std::shared_ptr<UtilityFunction> checker_function)
312  : Instrumenter(module, checker_function),
313  m_valid_pointer_check_func(nullptr) {}
314 
315  ~ValidPointerChecker() override = default;
316 
317 protected:
318  bool InstrumentInstruction(llvm::Instruction *inst) override {
320 
321  LLDB_LOGF(log, "Instrumenting load/store instruction: %s\n",
322  PrintValue(inst).c_str());
323 
324  if (!m_valid_pointer_check_func)
325  m_valid_pointer_check_func =
326  BuildPointerValidatorFunc(m_checker_function->StartAddress());
327 
328  llvm::Value *dereferenced_ptr = nullptr;
329 
330  if (llvm::LoadInst *li = dyn_cast<llvm::LoadInst>(inst))
331  dereferenced_ptr = li->getPointerOperand();
332  else if (llvm::StoreInst *si = dyn_cast<llvm::StoreInst>(inst))
333  dereferenced_ptr = si->getPointerOperand();
334  else
335  return false;
336 
337  // Insert an instruction to cast the loaded value to int8_t*
338 
339  BitCastInst *bit_cast =
340  new BitCastInst(dereferenced_ptr, GetI8PtrTy(), "", inst);
341 
342  // Insert an instruction to call the helper with the result
343 
344  llvm::Value *arg_array[1];
345 
346  arg_array[0] = bit_cast;
347 
348  llvm::ArrayRef<llvm::Value *> args(arg_array, 1);
349 
350  CallInst::Create(m_valid_pointer_check_func, args, "", inst);
351 
352  return true;
353  }
354 
355  bool InspectInstruction(llvm::Instruction &i) override {
356  if (dyn_cast<llvm::LoadInst>(&i) || dyn_cast<llvm::StoreInst>(&i))
357  RegisterInstruction(i);
358 
359  return true;
360  }
361 
362 private:
363  llvm::FunctionCallee m_valid_pointer_check_func;
364 };
365 
367 public:
368  ObjcObjectChecker(llvm::Module &module,
369  std::shared_ptr<UtilityFunction> checker_function)
370  : Instrumenter(module, checker_function),
371  m_objc_object_check_func(nullptr) {}
372 
373  ~ObjcObjectChecker() override = default;
374 
376  eMsgSend = 0,
380  eMsgSend_stret
381  };
382 
383  std::map<llvm::Instruction *, msgSend_type> msgSend_types;
384 
385 protected:
386  bool InstrumentInstruction(llvm::Instruction *inst) override {
387  CallInst *call_inst = dyn_cast<CallInst>(inst);
388 
389  if (!call_inst)
390  return false; // call_inst really shouldn't be nullptr, because otherwise
391  // InspectInstruction wouldn't have registered it
392 
393  if (!m_objc_object_check_func)
394  m_objc_object_check_func =
395  BuildObjectCheckerFunc(m_checker_function->StartAddress());
396 
397  // id objc_msgSend(id theReceiver, SEL theSelector, ...)
398 
399  llvm::Value *target_object;
400  llvm::Value *selector;
401 
402  switch (msgSend_types[inst]) {
403  case eMsgSend:
404  case eMsgSend_fpret:
405  // On arm64, clang uses objc_msgSend for scalar and struct return
406  // calls. The call instruction will record which was used.
407  if (call_inst->hasStructRetAttr()) {
408  target_object = call_inst->getArgOperand(1);
409  selector = call_inst->getArgOperand(2);
410  } else {
411  target_object = call_inst->getArgOperand(0);
412  selector = call_inst->getArgOperand(1);
413  }
414  break;
415  case eMsgSend_stret:
416  target_object = call_inst->getArgOperand(1);
417  selector = call_inst->getArgOperand(2);
418  break;
419  case eMsgSendSuper:
420  case eMsgSendSuper_stret:
421  return true;
422  }
423 
424  // These objects should always be valid according to Sean Calannan
425  assert(target_object);
426  assert(selector);
427 
428  // Insert an instruction to cast the receiver id to int8_t*
429 
430  BitCastInst *bit_cast =
431  new BitCastInst(target_object, GetI8PtrTy(), "", inst);
432 
433  // Insert an instruction to call the helper with the result
434 
435  llvm::Value *arg_array[2];
436 
437  arg_array[0] = bit_cast;
438  arg_array[1] = selector;
439 
440  ArrayRef<llvm::Value *> args(arg_array, 2);
441 
442  CallInst::Create(m_objc_object_check_func, args, "", inst);
443 
444  return true;
445  }
446 
447  static llvm::Function *GetFunction(llvm::Value *value) {
448  if (llvm::Function *function = llvm::dyn_cast<llvm::Function>(value)) {
449  return function;
450  }
451 
452  if (llvm::ConstantExpr *const_expr =
453  llvm::dyn_cast<llvm::ConstantExpr>(value)) {
454  switch (const_expr->getOpcode()) {
455  default:
456  return nullptr;
457  case llvm::Instruction::BitCast:
458  return GetFunction(const_expr->getOperand(0));
459  }
460  }
461 
462  return nullptr;
463  }
464 
465  static llvm::Function *GetCalledFunction(llvm::CallInst *inst) {
466  return GetFunction(inst->getCalledOperand());
467  }
468 
469  bool InspectInstruction(llvm::Instruction &i) override {
471 
472  CallInst *call_inst = dyn_cast<CallInst>(&i);
473 
474  if (call_inst) {
475  const llvm::Function *called_function = GetCalledFunction(call_inst);
476 
477  if (!called_function)
478  return true;
479 
480  std::string name_str = called_function->getName().str();
481  const char *name_cstr = name_str.c_str();
482 
483  LLDB_LOGF(log, "Found call to %s: %s\n", name_cstr,
484  PrintValue(call_inst).c_str());
485 
486  if (name_str.find("objc_msgSend") == std::string::npos)
487  return true;
488 
489  if (!strcmp(name_cstr, "objc_msgSend")) {
490  RegisterInstruction(i);
491  msgSend_types[&i] = eMsgSend;
492  return true;
493  }
494 
495  if (!strcmp(name_cstr, "objc_msgSend_stret")) {
496  RegisterInstruction(i);
497  msgSend_types[&i] = eMsgSend_stret;
498  return true;
499  }
500 
501  if (!strcmp(name_cstr, "objc_msgSend_fpret")) {
502  RegisterInstruction(i);
503  msgSend_types[&i] = eMsgSend_fpret;
504  return true;
505  }
506 
507  if (!strcmp(name_cstr, "objc_msgSendSuper")) {
508  RegisterInstruction(i);
509  msgSend_types[&i] = eMsgSendSuper;
510  return true;
511  }
512 
513  if (!strcmp(name_cstr, "objc_msgSendSuper_stret")) {
514  RegisterInstruction(i);
515  msgSend_types[&i] = eMsgSendSuper_stret;
516  return true;
517  }
518 
519  LLDB_LOGF(log,
520  "Function name '%s' contains 'objc_msgSend' but is not handled",
521  name_str.c_str());
522 
523  return true;
524  }
525 
526  return true;
527  }
528 
529 private:
530  llvm::FunctionCallee m_objc_object_check_func;
531 };
532 
534  ClangDynamicCheckerFunctions &checker_functions, const char *func_name)
535  : ModulePass(ID), m_func_name(func_name),
536  m_checker_functions(checker_functions) {}
537 
539 
540 bool IRDynamicChecks::runOnModule(llvm::Module &M) {
542 
543  llvm::Function *function = M.getFunction(StringRef(m_func_name));
544 
545  if (!function) {
546  LLDB_LOGF(log, "Couldn't find %s() in the module", m_func_name.c_str());
547 
548  return false;
549  }
550 
553 
554  if (!vpc.Inspect(*function))
555  return false;
556 
557  if (!vpc.Instrument())
558  return false;
559  }
560 
563 
564  if (!ooc.Inspect(*function))
565  return false;
566 
567  if (!ooc.Instrument())
568  return false;
569  }
570 
571  if (log && log->GetVerbose()) {
572  std::string s;
573  raw_string_ostream oss(s);
574 
575  M.print(oss, nullptr);
576 
577  oss.flush();
578 
579  LLDB_LOGF(log, "Module after dynamic checks: \n%s", s.c_str());
580  }
581 
582  return true;
583 }
584 
585 void IRDynamicChecks::assignPassManager(PMStack &PMS, PassManagerType T) {}
586 
588  return PMT_ModulePassManager;
589 }
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
ValidPointerChecker::InspectInstruction
bool InspectInstruction(llvm::Instruction &i) override
Determine whether a single instruction is interesting to instrument, and, if so, call RegisterInstruc...
Definition: IRDynamicChecks.cpp:355
ObjcObjectChecker::msgSend_types
std::map< llvm::Instruction *, msgSend_type > msgSend_types
Definition: IRDynamicChecks.cpp:383
llvm
Definition: Debugger.h:49
lldb_private::Log::GetVerbose
bool GetVerbose() const
Definition: Log.cpp:276
ValidPointerChecker::m_valid_pointer_check_func
llvm::FunctionCallee m_valid_pointer_check_func
Definition: IRDynamicChecks.cpp:363
ObjcObjectChecker::ObjcObjectChecker
ObjcObjectChecker(llvm::Module &module, std::shared_ptr< UtilityFunction > checker_function)
Definition: IRDynamicChecks.cpp:368
lldb_private::ClangDynamicCheckerFunctions::~ClangDynamicCheckerFunctions
virtual ~ClangDynamicCheckerFunctions()
Destructor.
lldb_private::ObjCLanguageRuntime
Definition: ObjCLanguageRuntime.h:34
lldb_private::ExecutionContext::GetProcessPtr
Process * GetProcessPtr() const
Returns a pointer to the process object.
Definition: ExecutionContext.cpp:208
VALID_OBJC_OBJECT_CHECK_NAME
#define VALID_OBJC_OBJECT_CHECK_NAME
Definition: IRDynamicChecks.cpp:35
ObjcObjectChecker::eMsgSendSuper
@ eMsgSendSuper
Definition: IRDynamicChecks.cpp:377
lldb_private::ObjCLanguageRuntime::Get
static ObjCLanguageRuntime * Get(Process &process)
Definition: ObjCLanguageRuntime.h:213
lldb_private::ClangDynamicCheckerFunctions::DoCheckersExplainStop
bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message) override
Definition: IRDynamicChecks.cpp:78
lldb_private::IRDynamicChecks::runOnModule
bool runOnModule(llvm::Module &M) override
Run this IR transformer on a single module.
Definition: IRDynamicChecks.cpp:540
Instrumenter::GetI8PtrTy
PointerType * GetI8PtrTy()
Definition: IRDynamicChecks.cpp:277
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::Process
Definition: Process.h:341
lldb_private::ClangDynamicCheckerFunctions::Install
bool Install(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) override
Install the utility functions into a process.
Definition: IRDynamicChecks.cpp:49
ValidPointerChecker
Definition: IRDynamicChecks.cpp:308
StackFrame.h
lldb_private::ClangDynamicCheckerFunctions
Definition: IRDynamicChecks.h:26
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
PrintValue
static std::string PrintValue(llvm::Value *V, bool truncate=false)
Definition: IRDynamicChecks.cpp:95
lldb_private::IRDynamicChecks::getPotentialPassManagerType
llvm::PassManagerType getPotentialPassManagerType() const override
Returns PMT_ModulePassManager.
Definition: IRDynamicChecks.cpp:587
Instrumenter::InspectFunction
virtual bool InspectFunction(llvm::Function &f)
Scan a function to see if any instructions are interesting.
Definition: IRDynamicChecks.cpp:220
VALID_POINTER_CHECK_NAME
#define VALID_POINTER_CHECK_NAME
Definition: IRDynamicChecks.cpp:34
lldb_private::IRDynamicChecks::assignPassManager
void assignPassManager(llvm::PMStack &PMS, llvm::PassManagerType T=llvm::PMT_ModulePassManager) override
Interface stub.
Definition: IRDynamicChecks.cpp:585
Process.h
ObjcObjectChecker::m_objc_object_check_func
llvm::FunctionCallee m_objc_object_check_func
Definition: IRDynamicChecks.cpp:530
lldb_private::IRDynamicChecks::~IRDynamicChecks
~IRDynamicChecks() override
Destructor.
Target.h
ObjcObjectChecker::GetCalledFunction
static llvm::Function * GetCalledFunction(llvm::CallInst *inst)
Definition: IRDynamicChecks.cpp:465
Instrumenter::RegisterInstruction
void RegisterInstruction(llvm::Instruction &inst)
Register a single instruction to be instrumented.
Definition: IRDynamicChecks.cpp:182
LIBLLDB_LOG_EXPRESSIONS
#define LIBLLDB_LOG_EXPRESSIONS
Definition: Logging.h:22
ValidPointerChecker::InstrumentInstruction
bool InstrumentInstruction(llvm::Instruction *inst) override
Add instrumentation to a single instruction.
Definition: IRDynamicChecks.cpp:318
ID
static char ID
Definition: IRDynamicChecks.cpp:32
Log.h
lldb_private::Target::CreateUtilityFunction
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:2382
ObjcObjectChecker
Definition: IRDynamicChecks.cpp:366
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
ObjcObjectChecker::eMsgSendSuper_stret
@ eMsgSendSuper_stret
Definition: IRDynamicChecks.cpp:378
Instrumenter::BuildObjectCheckerFunc
llvm::FunctionCallee BuildObjectCheckerFunc(lldb::addr_t start_address)
Build a function pointer for a function with signature void (*)(uint8_t*, uint8_t*) with a given addr...
Definition: IRDynamicChecks.cpp:261
UtilityFunction.h
lldb_private::IRDynamicChecks::m_checker_functions
ClangDynamicCheckerFunctions & m_checker_functions
The checker functions for the process.
Definition: IRDynamicChecks.h:122
Instrumenter::GetIntptrTy
IntegerType * GetIntptrTy()
Definition: IRDynamicChecks.cpp:284
Instrumenter::InstIterator
InstVector::iterator InstIterator
Definition: IRDynamicChecks.cpp:296
Instrumenter::Instrumenter
Instrumenter(llvm::Module &module, std::shared_ptr< UtilityFunction > checker_function)
Constructor.
Definition: IRDynamicChecks.cpp:137
g_valid_pointer_check_text
static const char g_valid_pointer_check_text[]
Definition: IRDynamicChecks.cpp:37
Instrumenter::InspectInstruction
virtual bool InspectInstruction(llvm::Instruction &i)
Determine whether a single instruction is interesting to instrument, and, if so, call RegisterInstruc...
Definition: IRDynamicChecks.cpp:194
message
message(FATAL_ERROR "invalid libipt include path provided") endif() include_directories($
Definition: Plugins/Trace/intel-pt/CMakeLists.txt:6
lldb_private::ClangDynamicCheckerFunctions::m_objc_object_check
std::shared_ptr< UtilityFunction > m_objc_object_check
Definition: IRDynamicChecks.h:57
Instrumenter::Inspect
bool Inspect(llvm::Function &function)
Inspect a function to find instructions to instrument.
Definition: IRDynamicChecks.cpp:151
Instrumenter::m_checker_function
std::shared_ptr< UtilityFunction > m_checker_function
The dynamic checker function for the process.
Definition: IRDynamicChecks.cpp:301
Instrumenter::m_intptr_ty
IntegerType * m_intptr_ty
Definition: IRDynamicChecks.cpp:305
lldb_private::DiagnosticManager
Definition: DiagnosticManager.h:93
ObjCLanguageRuntime.h
Instrumenter::InstVector
std::vector< llvm::Instruction * > InstVector
Definition: IRDynamicChecks.cpp:295
Instrumenter::BuildPointerValidatorFunc
llvm::FunctionCallee BuildPointerValidatorFunc(lldb::addr_t start_address)
Build a function pointer for a function with signature void (*)(uint8_t*) with a given address.
Definition: IRDynamicChecks.cpp:238
Instrumenter::m_to_instrument
InstVector m_to_instrument
List of instructions the inspector found.
Definition: IRDynamicChecks.cpp:298
Instrumenter::m_module
llvm::Module & m_module
The module which is being instrumented.
Definition: IRDynamicChecks.cpp:299
lldb_private::ObjCLanguageRuntime::CreateObjectChecker
virtual llvm::Expected< std::unique_ptr< UtilityFunction > > CreateObjectChecker(std::string name, ExecutionContext &exe_ctx)=0
lldb_private::ExecutionContext::GetTargetRef
Target & GetTargetRef() const
Returns a reference to the target object.
Definition: ExecutionContext.cpp:226
lldb_private::ClangDynamicCheckerFunctions::m_valid_pointer_check
std::shared_ptr< UtilityFunction > m_valid_pointer_check
Definition: IRDynamicChecks.h:56
ObjcObjectChecker::eMsgSend_fpret
@ eMsgSend_fpret
Definition: IRDynamicChecks.cpp:379
lldb::eLanguageTypeC
@ eLanguageTypeC
Non-standardized C, such as K&R.
Definition: lldb-enumerations.h:439
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Instrumenter::Instrument
bool Instrument()
Instrument all the instructions found by Inspect()
Definition: IRDynamicChecks.cpp:157
ObjcObjectChecker::msgSend_type
msgSend_type
Definition: IRDynamicChecks.cpp:375
IRDynamicChecks.h
ObjcObjectChecker::InstrumentInstruction
bool InstrumentInstruction(llvm::Instruction *inst) override
Add instrumentation to a single instruction.
Definition: IRDynamicChecks.cpp:386
ConstString.h
lldb_private::Log
Definition: Log.h:49
ObjcObjectChecker::InspectInstruction
bool InspectInstruction(llvm::Instruction &i) override
Determine whether a single instruction is interesting to instrument, and, if so, call RegisterInstruc...
Definition: IRDynamicChecks.cpp:469
lldb_private::DynamicCheckerFunctions
Encapsulates dynamic check functions used by expressions.
Definition: DynamicCheckerFunctions.h:30
lldb_private::IRDynamicChecks::IRDynamicChecks
IRDynamicChecks(ClangDynamicCheckerFunctions &checker_functions, const char *func_name="$__lldb_expr")
Constructor.
Definition: IRDynamicChecks.cpp:533
ValidPointerChecker::ValidPointerChecker
ValidPointerChecker(llvm::Module &module, std::shared_ptr< UtilityFunction > checker_function)
Definition: IRDynamicChecks.cpp:310
ObjcObjectChecker::GetFunction
static llvm::Function * GetFunction(llvm::Value *value)
Definition: IRDynamicChecks.cpp:447
lldb_private::IRDynamicChecks::m_func_name
std::string m_func_name
The name of the function to add checks to.
Definition: IRDynamicChecks.h:120
Instrumenter::m_i8ptr_ty
PointerType * m_i8ptr_ty
Definition: IRDynamicChecks.cpp:304
ExecutionContext.h
Instrumenter
Definition: IRDynamicChecks.cpp:131
Instrumenter::InspectBasicBlock
virtual bool InspectBasicBlock(llvm::BasicBlock &bb)
Scan a basic block to see if any instructions are interesting.
Definition: IRDynamicChecks.cpp:203