LLDB  mainline
AppleObjCTrampolineHandler.cpp
Go to the documentation of this file.
1 //===-- AppleObjCTrampolineHandler.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 
11 
14 #include "lldb/Core/Debugger.h"
15 #include "lldb/Core/Module.h"
16 #include "lldb/Core/StreamFile.h"
17 #include "lldb/Core/Value.h"
22 #include "lldb/Symbol/Symbol.h"
23 #include "lldb/Target/ABI.h"
25 #include "lldb/Target/Process.h"
27 #include "lldb/Target/Target.h"
28 #include "lldb/Target/Thread.h"
31 #include "lldb/Utility/FileSpec.h"
32 #include "lldb/Utility/LLDBLog.h"
33 #include "lldb/Utility/Log.h"
34 
35 #include "llvm/ADT/STLExtras.h"
36 #include "llvm/ADT/ScopeExit.h"
37 
39 
40 #include <memory>
41 
42 using namespace lldb;
43 using namespace lldb_private;
44 
45 const char *AppleObjCTrampolineHandler::g_lookup_implementation_function_name =
46  "__lldb_objc_find_implementation_for_selector";
47 const char *AppleObjCTrampolineHandler::
48  g_lookup_implementation_with_stret_function_code =
49  R"(
50  if (is_stret) {
51  return_struct.impl_addr =
52  class_getMethodImplementation_stret (return_struct.class_addr,
53  return_struct.sel_addr);
54  } else {
55  return_struct.impl_addr =
56  class_getMethodImplementation (return_struct.class_addr,
57  return_struct.sel_addr);
58  }
59  if (debug)
60  printf ("\n*** Returning implementation: %p.\n",
61  return_struct.impl_addr);
62 
63  return return_struct.impl_addr;
64 }
65 )";
66 const char *
67  AppleObjCTrampolineHandler::g_lookup_implementation_no_stret_function_code =
68  R"(
69  return_struct.impl_addr =
70  class_getMethodImplementation (return_struct.class_addr,
71  return_struct.sel_addr);
72  if (debug)
73  printf ("\n*** getMethodImpletation for addr: 0x%p sel: 0x%p result: 0x%p.\n",
74  return_struct.class_addr, return_struct.sel_addr, return_struct.impl_addr);
75 
76  return return_struct.impl_addr;
77 }
78 )";
79 
80 const char
81  *AppleObjCTrampolineHandler::g_lookup_implementation_function_common_code =
82  R"(
83 extern "C"
84 {
85  extern void *class_getMethodImplementation(void *objc_class, void *sel);
86  extern void *class_getMethodImplementation_stret(void *objc_class, void *sel);
87  extern void * object_getClass (id object);
88  extern void * sel_getUid(char *name);
89  extern int printf(const char *format, ...);
90 }
91 extern "C" void *
92 __lldb_objc_find_implementation_for_selector (void *object,
93  void *sel,
94  int is_str_ptr,
95  int is_stret,
96  int is_super,
97  int is_super2,
98  int is_fixup,
99  int is_fixed,
100  int debug)
101 {
102  struct __lldb_imp_return_struct {
103  void *class_addr;
104  void *sel_addr;
105  void *impl_addr;
106  };
107 
108  struct __lldb_objc_class {
109  void *isa;
110  void *super_ptr;
111  };
112  struct __lldb_objc_super {
113  void *receiver;
114  struct __lldb_objc_class *class_ptr;
115  };
116  struct __lldb_msg_ref {
117  void *dont_know;
118  void *sel;
119  };
120 
121  struct __lldb_imp_return_struct return_struct;
122 
123  if (debug)
124  printf ("\n*** Called with obj: %p sel: %p is_str_ptr: %d "
125  "is_stret: %d is_super: %d, "
126  "is_super2: %d, is_fixup: %d, is_fixed: %d\n",
127  object, sel, is_str_ptr, is_stret,
128  is_super, is_super2, is_fixup, is_fixed);
129 
130  if (is_str_ptr) {
131  if (debug)
132  printf("*** Turning string: '%s'", sel);
133  sel = sel_getUid((char *)sel);
134  if (debug)
135  printf("*** into sel to %p", sel);
136  }
137  if (is_super) {
138  if (is_super2) {
139  return_struct.class_addr
140  = ((__lldb_objc_super *) object)->class_ptr->super_ptr;
141  } else {
142  return_struct.class_addr = ((__lldb_objc_super *) object)->class_ptr;
143  }
144  if (debug)
145  printf("*** Super, class addr: %p\n", return_struct.class_addr);
146  } else {
147  // This code seems a little funny, but has its reasons...
148  // The call to [object class] is here because if this is a class, and has
149  // not been called into yet, we need to do something to force the class to
150  // initialize itself.
151  // Then the call to object_getClass will actually return the correct class,
152  // either the class if object is a class instance, or the meta-class if it
153  // is a class pointer.
154  void *class_ptr = (void *) [(id) object class];
155  return_struct.class_addr = (id) object_getClass((id) object);
156  if (debug) {
157  if (class_ptr == object) {
158  printf ("Found a class object, need to return the meta class %p -> %p\n",
159  class_ptr, return_struct.class_addr);
160  } else {
161  printf ("[object class] returned: %p object_getClass: %p.\n",
162  class_ptr, return_struct.class_addr);
163  }
164  }
165  }
166 
167  if (is_fixup) {
168  if (is_fixed) {
169  return_struct.sel_addr = ((__lldb_msg_ref *) sel)->sel;
170  } else {
171  char *sel_name = (char *) ((__lldb_msg_ref *) sel)->sel;
172  return_struct.sel_addr = sel_getUid (sel_name);
173  if (debug)
174  printf ("\n*** Got fixed up selector: %p for name %s.\n",
175  return_struct.sel_addr, sel_name);
176  }
177  } else {
178  return_struct.sel_addr = sel;
179  }
180 )";
181 
182 AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::VTableRegion(
183  AppleObjCVTables *owner, lldb::addr_t header_addr)
184  : m_valid(true), m_owner(owner), m_header_addr(header_addr) {
185  SetUpRegion();
186 }
187 
189 
191  // The header looks like:
192  //
193  // uint16_t headerSize
194  // uint16_t descSize
195  // uint32_t descCount
196  // void * next
197  //
198  // First read in the header:
199 
200  char memory_buffer[16];
201  ProcessSP process_sp = m_owner->GetProcessSP();
202  if (!process_sp)
203  return;
204  DataExtractor data(memory_buffer, sizeof(memory_buffer),
205  process_sp->GetByteOrder(),
206  process_sp->GetAddressByteSize());
207  size_t actual_size = 8 + process_sp->GetAddressByteSize();
208  Status error;
209  size_t bytes_read =
210  process_sp->ReadMemory(m_header_addr, memory_buffer, actual_size, error);
211  if (bytes_read != actual_size) {
212  m_valid = false;
213  return;
214  }
215 
216  lldb::offset_t offset = 0;
217  const uint16_t header_size = data.GetU16(&offset);
218  const uint16_t descriptor_size = data.GetU16(&offset);
219  const size_t num_descriptors = data.GetU32(&offset);
220 
221  m_next_region = data.GetAddress(&offset);
222 
223  // If the header size is 0, that means we've come in too early before this
224  // data is set up.
225  // Set ourselves as not valid, and continue.
226  if (header_size == 0 || num_descriptors == 0) {
227  m_valid = false;
228  return;
229  }
230 
231  // Now read in all the descriptors:
232  // The descriptor looks like:
233  //
234  // uint32_t offset
235  // uint32_t flags
236  //
237  // Where offset is either 0 - in which case it is unused, or it is
238  // the offset of the vtable code from the beginning of the
239  // descriptor record. Below, we'll convert that into an absolute
240  // code address, since I don't want to have to compute it over and
241  // over.
242 
243  // Ingest the whole descriptor array:
244  const lldb::addr_t desc_ptr = m_header_addr + header_size;
245  const size_t desc_array_size = num_descriptors * descriptor_size;
246  WritableDataBufferSP data_sp(new DataBufferHeap(desc_array_size, '\0'));
247  uint8_t *dst = (uint8_t *)data_sp->GetBytes();
248 
249  DataExtractor desc_extractor(dst, desc_array_size, process_sp->GetByteOrder(),
250  process_sp->GetAddressByteSize());
251  bytes_read = process_sp->ReadMemory(desc_ptr, dst, desc_array_size, error);
252  if (bytes_read != desc_array_size) {
253  m_valid = false;
254  return;
255  }
256 
257  // The actual code for the vtables will be laid out consecutively, so I also
258  // compute the start and end of the whole code block.
259 
260  offset = 0;
261  m_code_start_addr = 0;
262  m_code_end_addr = 0;
263 
264  for (size_t i = 0; i < num_descriptors; i++) {
265  lldb::addr_t start_offset = offset;
266  uint32_t voffset = desc_extractor.GetU32(&offset);
267  uint32_t flags = desc_extractor.GetU32(&offset);
268  lldb::addr_t code_addr = desc_ptr + start_offset + voffset;
269  m_descriptors.push_back(VTableDescriptor(flags, code_addr));
270 
271  if (m_code_start_addr == 0 || code_addr < m_code_start_addr)
272  m_code_start_addr = code_addr;
273  if (code_addr > m_code_end_addr)
274  m_code_end_addr = code_addr;
275 
276  offset = start_offset + descriptor_size;
277  }
278  // Finally, a little bird told me that all the vtable code blocks
279  // are the same size. Let's compute the blocks and if they are all
280  // the same add the size to the code end address:
281  lldb::addr_t code_size = 0;
282  bool all_the_same = true;
283  for (size_t i = 0; i < num_descriptors - 1; i++) {
284  lldb::addr_t this_size =
285  m_descriptors[i + 1].code_start - m_descriptors[i].code_start;
286  if (code_size == 0)
287  code_size = this_size;
288  else {
289  if (this_size != code_size)
290  all_the_same = false;
291  if (this_size > code_size)
292  code_size = this_size;
293  }
294  }
295  if (all_the_same)
296  m_code_end_addr += code_size;
297 }
298 
301  if (!IsValid())
302  return false;
303 
304  if (addr < m_code_start_addr || addr > m_code_end_addr)
305  return false;
306 
307  std::vector<VTableDescriptor>::iterator pos, end = m_descriptors.end();
308  for (pos = m_descriptors.begin(); pos != end; pos++) {
309  if (addr <= (*pos).code_start) {
310  flags = (*pos).flags;
311  return true;
312  }
313  }
314  return false;
315 }
316 
318  Stream &s) {
319  s.Printf("Header addr: 0x%" PRIx64 " Code start: 0x%" PRIx64
320  " Code End: 0x%" PRIx64 " Next: 0x%" PRIx64 "\n",
321  m_header_addr, m_code_start_addr, m_code_end_addr, m_next_region);
322  size_t num_elements = m_descriptors.size();
323  for (size_t i = 0; i < num_elements; i++) {
324  s.Indent();
325  s.Printf("Code start: 0x%" PRIx64 " Flags: %d\n",
326  m_descriptors[i].code_start, m_descriptors[i].flags);
327  }
328 }
329 
331  const ProcessSP &process_sp, const ModuleSP &objc_module_sp)
334  m_objc_module_sp(objc_module_sp) {
335  if (process_sp)
336  m_process_wp = process_sp;
337 }
338 
340  ProcessSP process_sp = GetProcessSP();
341  if (process_sp) {
342  if (m_trampolines_changed_bp_id != LLDB_INVALID_BREAK_ID)
343  process_sp->GetTarget().RemoveBreakpointByID(m_trampolines_changed_bp_id);
344  }
345 }
346 
348  if (m_trampoline_header != LLDB_INVALID_ADDRESS)
349  return true;
350 
351  ProcessSP process_sp = GetProcessSP();
352  if (process_sp) {
353  Target &target = process_sp->GetTarget();
354 
355  if (!m_objc_module_sp) {
356  for (ModuleSP module_sp : target.GetImages().Modules()) {
357  if (ObjCLanguageRuntime::Get(*process_sp)
358  ->IsModuleObjCLibrary(module_sp)) {
359  m_objc_module_sp = module_sp;
360  break;
361  }
362  }
363  }
364 
365  if (m_objc_module_sp) {
366  ConstString trampoline_name("gdb_objc_trampolines");
367  const Symbol *trampoline_symbol =
368  m_objc_module_sp->FindFirstSymbolWithNameAndType(trampoline_name,
370  if (trampoline_symbol != nullptr) {
371  m_trampoline_header = trampoline_symbol->GetLoadAddress(&target);
372  if (m_trampoline_header == LLDB_INVALID_ADDRESS)
373  return false;
374 
375  // Next look up the "changed" symbol and set a breakpoint on that...
376  ConstString changed_name("gdb_objc_trampolines_changed");
377  const Symbol *changed_symbol =
378  m_objc_module_sp->FindFirstSymbolWithNameAndType(changed_name,
380  if (changed_symbol != nullptr) {
381  const Address changed_symbol_addr = changed_symbol->GetAddress();
382  if (!changed_symbol_addr.IsValid())
383  return false;
384 
385  lldb::addr_t changed_addr =
386  changed_symbol_addr.GetOpcodeLoadAddress(&target);
387  if (changed_addr != LLDB_INVALID_ADDRESS) {
388  BreakpointSP trampolines_changed_bp_sp =
389  target.CreateBreakpoint(changed_addr, true, false);
390  if (trampolines_changed_bp_sp) {
391  m_trampolines_changed_bp_id = trampolines_changed_bp_sp->GetID();
392  trampolines_changed_bp_sp->SetCallback(RefreshTrampolines, this,
393  true);
394  trampolines_changed_bp_sp->SetBreakpointKind(
395  "objc-trampolines-changed");
396  return true;
397  }
398  }
399  }
400  }
401  }
402  }
403  return false;
404 }
405 
407  void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id,
408  lldb::user_id_t break_loc_id) {
409  AppleObjCVTables *vtable_handler = (AppleObjCVTables *)baton;
410  if (vtable_handler->InitializeVTableSymbols()) {
411  // The Update function is called with the address of an added region. So we
412  // grab that address, and
413  // feed it into ReadRegions. Of course, our friend the ABI will get the
414  // values for us.
415  ExecutionContext exe_ctx(context->exe_ctx_ref);
416  Process *process = exe_ctx.GetProcessPtr();
417  const ABI *abi = process->GetABI().get();
418 
419  TypeSystemClang *clang_ast_context =
421  if (!clang_ast_context)
422  return false;
423 
424  ValueList argument_values;
425  Value input_value;
426  CompilerType clang_void_ptr_type =
427  clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
428 
430  // input_value.SetContext (Value::eContextTypeClangType,
431  // clang_void_ptr_type);
432  input_value.SetCompilerType(clang_void_ptr_type);
433  argument_values.PushValue(input_value);
434 
435  bool success =
436  abi->GetArgumentValues(exe_ctx.GetThreadRef(), argument_values);
437  if (!success)
438  return false;
439 
440  // Now get a pointer value from the zeroth argument.
441  Status error;
442  DataExtractor data;
443  error = argument_values.GetValueAtIndex(0)->GetValueAsData(&exe_ctx, data,
444  nullptr);
445  lldb::offset_t offset = 0;
446  lldb::addr_t region_addr = data.GetAddress(&offset);
447 
448  if (region_addr != 0)
449  vtable_handler->ReadRegions(region_addr);
450  }
451  return false;
452 }
453 
455  // The no argument version reads the start region from the value of
456  // the gdb_regions_header, and gets started from there.
457 
458  m_regions.clear();
459  if (!InitializeVTableSymbols())
460  return false;
461  Status error;
462  ProcessSP process_sp = GetProcessSP();
463  if (process_sp) {
464  lldb::addr_t region_addr =
465  process_sp->ReadPointerFromMemory(m_trampoline_header, error);
466  if (error.Success())
467  return ReadRegions(region_addr);
468  }
469  return false;
470 }
471 
473  lldb::addr_t region_addr) {
474  ProcessSP process_sp = GetProcessSP();
475  if (!process_sp)
476  return false;
477 
478  Log *log = GetLog(LLDBLog::Step);
479 
480  // We aren't starting at the trampoline symbol.
481  InitializeVTableSymbols();
482  lldb::addr_t next_region = region_addr;
483 
484  // Read in the sizes of the headers.
485  while (next_region != 0) {
486  m_regions.push_back(VTableRegion(this, next_region));
487  if (!m_regions.back().IsValid()) {
488  m_regions.clear();
489  return false;
490  }
491  if (log) {
492  StreamString s;
493  m_regions.back().Dump(s);
494  LLDB_LOGF(log, "Read vtable region: \n%s", s.GetData());
495  }
496 
497  next_region = m_regions.back().GetNextRegionAddr();
498  }
499 
500  return true;
501 }
502 
504  lldb::addr_t addr, uint32_t &flags) {
505  region_collection::iterator pos, end = m_regions.end();
506  for (pos = m_regions.begin(); pos != end; pos++) {
507  if ((*pos).AddressInRegion(addr, flags))
508  return true;
509  }
510  return false;
511 }
512 
515  // NAME STRET SUPER SUPER2 FIXUP TYPE
516  {"objc_msgSend", false, false, false, DispatchFunction::eFixUpNone},
517  {"objc_msgSend_fixup", false, false, false,
519  {"objc_msgSend_fixedup", false, false, false,
521  {"objc_msgSend_stret", true, false, false,
523  {"objc_msgSend_stret_fixup", true, false, false,
525  {"objc_msgSend_stret_fixedup", true, false, false,
527  {"objc_msgSend_fpret", false, false, false,
529  {"objc_msgSend_fpret_fixup", false, false, false,
531  {"objc_msgSend_fpret_fixedup", false, false, false,
533  {"objc_msgSend_fp2ret", false, false, true,
535  {"objc_msgSend_fp2ret_fixup", false, false, true,
537  {"objc_msgSend_fp2ret_fixedup", false, false, true,
539  {"objc_msgSendSuper", false, true, false, DispatchFunction::eFixUpNone},
540  {"objc_msgSendSuper_stret", true, true, false,
542  {"objc_msgSendSuper2", false, true, true, DispatchFunction::eFixUpNone},
543  {"objc_msgSendSuper2_fixup", false, true, true,
545  {"objc_msgSendSuper2_fixedup", false, true, true,
547  {"objc_msgSendSuper2_stret", true, true, true,
549  {"objc_msgSendSuper2_stret_fixup", true, true, true,
551  {"objc_msgSendSuper2_stret_fixedup", true, true, true,
553 };
554 
555 // This is the table of ObjC "accelerated dispatch" functions. They are a set
556 // of objc methods that are "seldom overridden" and so the compiler replaces the
557 // objc_msgSend with a call to one of the dispatch functions. That will check
558 // whether the method has been overridden, and directly call the Foundation
559 // implementation if not.
560 // This table is supposed to be complete. If ones get added in the future, we
561 // will have to add them to the table.
563  "objc_alloc",
564  "objc_autorelease",
565  "objc_release",
566  "objc_retain",
567  "objc_alloc_init",
568  "objc_allocWithZone",
569  "objc_opt_class",
570  "objc_opt_isKindOfClass",
571  "objc_opt_new",
572  "objc_opt_respondsToSelector",
573  "objc_opt_self",
574 };
575 
577  const ProcessSP &process_sp, const ModuleSP &objc_module_sp)
578  : m_process_wp(), m_objc_module_sp(objc_module_sp),
582  if (process_sp)
583  m_process_wp = process_sp;
584  // Look up the known resolution functions:
585 
586  ConstString get_impl_name("class_getMethodImplementation");
587  ConstString get_impl_stret_name("class_getMethodImplementation_stret");
588  ConstString msg_forward_name("_objc_msgForward");
589  ConstString msg_forward_stret_name("_objc_msgForward_stret");
590 
591  Target *target = process_sp ? &process_sp->GetTarget() : nullptr;
592  const Symbol *class_getMethodImplementation =
593  m_objc_module_sp->FindFirstSymbolWithNameAndType(get_impl_name,
595  const Symbol *class_getMethodImplementation_stret =
596  m_objc_module_sp->FindFirstSymbolWithNameAndType(get_impl_stret_name,
598  const Symbol *msg_forward = m_objc_module_sp->FindFirstSymbolWithNameAndType(
599  msg_forward_name, eSymbolTypeCode);
600  const Symbol *msg_forward_stret =
601  m_objc_module_sp->FindFirstSymbolWithNameAndType(msg_forward_stret_name,
603 
604  if (class_getMethodImplementation)
606  class_getMethodImplementation->GetAddress().GetOpcodeLoadAddress(
607  target);
608  if (class_getMethodImplementation_stret)
610  class_getMethodImplementation_stret->GetAddress().GetOpcodeLoadAddress(
611  target);
612  if (msg_forward)
613  m_msg_forward_addr = msg_forward->GetAddress().GetOpcodeLoadAddress(target);
614  if (msg_forward_stret)
616  msg_forward_stret->GetAddress().GetOpcodeLoadAddress(target);
617 
618  // FIXME: Do some kind of logging here.
620  // If we can't even find the ordinary get method implementation function,
621  // then we aren't going to be able to
622  // step through any method dispatches. Warn to that effect and get out of
623  // here.
624  if (process_sp->CanJIT()) {
625  process_sp->GetTarget().GetDebugger().GetErrorStream().Printf(
626  "Could not find implementation lookup function \"%s\""
627  " step in through ObjC method dispatch will not work.\n",
628  get_impl_name.AsCString());
629  }
630  return;
631  }
632 
633  // We will either set the implementation to the _stret or non_stret version,
634  // so either way it's safe to start filling the m_lookup_..._code here.
637 
639  // It there is no stret return lookup function, assume that it is the same
640  // as the straight lookup:
642  // Also we will use the version of the lookup code that doesn't rely on the
643  // stret version of the function.
646  } else {
649  }
650 
651  // Look up the addresses for the objc dispatch functions and cache
652  // them. For now I'm inspecting the symbol names dynamically to
653  // figure out how to dispatch to them. If it becomes more
654  // complicated than this we can turn the g_dispatch_functions char *
655  // array into a template table, and populate the DispatchFunction
656  // map from there.
657 
658  for (size_t i = 0; i != llvm::array_lengthof(g_dispatch_functions); i++) {
659  ConstString name_const_str(g_dispatch_functions[i].name);
660  const Symbol *msgSend_symbol =
661  m_objc_module_sp->FindFirstSymbolWithNameAndType(name_const_str,
663  if (msgSend_symbol && msgSend_symbol->ValueIsAddress()) {
664  // FIXME: Make g_dispatch_functions static table of
665  // DispatchFunctions, and have the map be address->index.
666  // Problem is we also need to lookup the dispatch function. For
667  // now we could have a side table of stret & non-stret dispatch
668  // functions. If that's as complex as it gets, we're fine.
669 
670  lldb::addr_t sym_addr =
671  msgSend_symbol->GetAddressRef().GetOpcodeLoadAddress(target);
672 
673  m_msgSend_map.insert(std::pair<lldb::addr_t, int>(sym_addr, i));
674  }
675  }
676 
677  // Similarly, cache the addresses of the "optimized dispatch" function.
678  for (size_t i = 0; i != llvm::array_lengthof(g_opt_dispatch_names); i++) {
679  ConstString name_const_str(g_opt_dispatch_names[i]);
680  const Symbol *msgSend_symbol =
681  m_objc_module_sp->FindFirstSymbolWithNameAndType(name_const_str,
683  if (msgSend_symbol && msgSend_symbol->ValueIsAddress()) {
684  lldb::addr_t sym_addr =
685  msgSend_symbol->GetAddressRef().GetOpcodeLoadAddress(target);
686 
687  m_opt_dispatch_map.emplace(sym_addr, i);
688  }
689  }
690 
691  // Build our vtable dispatch handler here:
692  m_vtables_up =
693  std::make_unique<AppleObjCVTables>(process_sp, m_objc_module_sp);
694  if (m_vtables_up)
695  m_vtables_up->ReadRegions();
696 }
697 
700  ValueList &dispatch_values) {
701  ThreadSP thread_sp(thread.shared_from_this());
702  ExecutionContext exe_ctx(thread_sp);
703  Log *log = GetLog(LLDBLog::Step);
704 
706  FunctionCaller *impl_function_caller = nullptr;
707 
708  // Scope for mutex locker:
709  {
710  std::lock_guard<std::mutex> guard(m_impl_function_mutex);
711 
712  // First stage is to make the ClangUtility to hold our injected function:
713 
714  if (!m_impl_code) {
716  auto utility_fn_or_error = exe_ctx.GetTargetRef().CreateUtilityFunction(
719  if (!utility_fn_or_error) {
721  log, utility_fn_or_error.takeError(),
722  "Failed to get Utility Function for implementation lookup: {0}.");
723  return args_addr;
724  }
725  m_impl_code = std::move(*utility_fn_or_error);
726  } else {
727  LLDB_LOGF(log, "No method lookup implementation code.");
728  return LLDB_INVALID_ADDRESS;
729  }
730 
731  // Next make the runner function for our implementation utility function.
733  thread.GetProcess()->GetTarget());
734  if (!clang_ast_context)
735  return LLDB_INVALID_ADDRESS;
736 
737  CompilerType clang_void_ptr_type =
738  clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
739  Status error;
740 
741  impl_function_caller = m_impl_code->MakeFunctionCaller(
742  clang_void_ptr_type, dispatch_values, thread_sp, error);
743  if (error.Fail()) {
744  LLDB_LOGF(log,
745  "Error getting function caller for dispatch lookup: \"%s\".",
746  error.AsCString());
747  return args_addr;
748  }
749  } else {
750  impl_function_caller = m_impl_code->GetFunctionCaller();
751  }
752  }
753 
754  // Now write down the argument values for this particular call.
755  // This looks like it might be a race condition if other threads
756  // were calling into here, but actually it isn't because we allocate
757  // a new args structure for this call by passing args_addr =
758  // LLDB_INVALID_ADDRESS...
759 
760  DiagnosticManager diagnostics;
761  if (!impl_function_caller->WriteFunctionArguments(
762  exe_ctx, args_addr, dispatch_values, diagnostics)) {
763  if (log) {
764  LLDB_LOGF(log, "Error writing function arguments.");
765  diagnostics.Dump(log);
766  }
767  return args_addr;
768  }
769 
770  return args_addr;
771 }
772 
775  MsgsendMap::iterator pos;
776  pos = m_msgSend_map.find(addr);
777  if (pos != m_msgSend_map.end()) {
778  return &g_dispatch_functions[(*pos).second];
779  }
780  return nullptr;
781 }
782 
783 void
785  std::function<void(lldb::addr_t,
786  const DispatchFunction &)> callback) {
787  for (auto elem : m_msgSend_map) {
788  callback(elem.first, g_dispatch_functions[elem.second]);
789  }
790 }
791 
792 ThreadPlanSP
794  bool stop_others) {
795  ThreadPlanSP ret_plan_sp;
796  lldb::addr_t curr_pc = thread.GetRegisterContext()->GetPC();
797 
798  DispatchFunction vtable_dispatch = {"vtable", false, false, false,
800  // The selector specific stubs are a wrapper for objc_msgSend. They don't get
801  // passed a SEL, but instead the selector string is encoded in the stub
802  // name, in the form:
803  // objc_msgSend$SelectorName
804  // and the stub figures out the uniqued selector. If we find ourselves in
805  // one of these stubs, we strip off the selector string and pass that to the
806  // implementation finder function, which looks up the SEL (you have to do this
807  // in process) and passes that to the runtime lookup function.
808  DispatchFunction sel_stub_dispatch = {"sel-specific-stub", false, false,
810 
811  // First step is to see if we're in a selector-specific dispatch stub.
812  // Those are of the form _objc_msgSend$<SELECTOR>, so see if the current
813  // function has that name:
814  Address func_addr;
815  Target &target = thread.GetProcess()->GetTarget();
816  llvm::StringRef sym_name;
817  const DispatchFunction *this_dispatch = nullptr;
818 
819  if (target.ResolveLoadAddress(curr_pc, func_addr)) {
820  Symbol *curr_sym = func_addr.CalculateSymbolContextSymbol();
821  if (curr_sym)
822  sym_name = curr_sym->GetName().GetStringRef();
823 
824  if (!sym_name.empty() && !sym_name.consume_front("objc_msgSend$"))
825  sym_name = {};
826  else
827  this_dispatch = &sel_stub_dispatch;
828  }
829  bool in_selector_stub = !sym_name.empty();
830  // Second step is to look and see if we are in one of the known ObjC
831  // dispatch functions. We've already compiled a table of same, so
832  // consult it.
833 
834  if (!in_selector_stub)
835  this_dispatch = FindDispatchFunction(curr_pc);
836 
837  // Next check to see if we are in a vtable region:
838 
839  if (!this_dispatch && m_vtables_up) {
840  uint32_t flags;
841  if (m_vtables_up->IsAddressInVTables(curr_pc, flags)) {
842  vtable_dispatch.stret_return =
845  this_dispatch = &vtable_dispatch;
846  }
847  }
848 
849  // Since we set this_dispatch in both the vtable & sel specific stub cases
850  // this if will be used for all three of those cases.
851  if (this_dispatch) {
852  Log *log = GetLog(LLDBLog::Step);
853 
854  // We are decoding a method dispatch. First job is to pull the
855  // arguments out. If we are in a regular stub, we get self & selector,
856  // but if we are in a selector-specific stub, we'll have to get that from
857  // the string sym_name.
858 
859  lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0);
860 
861  const ABI *abi = nullptr;
862  ProcessSP process_sp(thread.CalculateProcess());
863  if (process_sp)
864  abi = process_sp->GetABI().get();
865  if (abi == nullptr)
866  return ret_plan_sp;
867 
868  TargetSP target_sp(thread.CalculateTarget());
869 
870  TypeSystemClang *clang_ast_context =
872  if (!clang_ast_context)
873  return ret_plan_sp;
874 
875  ValueList argument_values;
876  Value void_ptr_value;
877  CompilerType clang_void_ptr_type =
878  clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
879  void_ptr_value.SetValueType(Value::ValueType::Scalar);
880  // void_ptr_value.SetContext (Value::eContextTypeClangType,
881  // clang_void_ptr_type);
882  void_ptr_value.SetCompilerType(clang_void_ptr_type);
883 
884  int obj_index;
885  int sel_index;
886 
887  // If this is a selector-specific stub then just push one value, 'cause
888  // we only get the object.
889  // If this is a struct return dispatch, then the first argument is
890  // the return struct pointer, and the object is the second, and
891  // the selector is the third.
892  // Otherwise the object is the first and the selector the second.
893  if (in_selector_stub) {
894  obj_index = 0;
895  sel_index = 1;
896  argument_values.PushValue(void_ptr_value);
897  } else if (this_dispatch->stret_return) {
898  obj_index = 1;
899  sel_index = 2;
900  argument_values.PushValue(void_ptr_value);
901  argument_values.PushValue(void_ptr_value);
902  argument_values.PushValue(void_ptr_value);
903  } else {
904  obj_index = 0;
905  sel_index = 1;
906  argument_values.PushValue(void_ptr_value);
907  argument_values.PushValue(void_ptr_value);
908  }
909 
910  bool success = abi->GetArgumentValues(thread, argument_values);
911  if (!success)
912  return ret_plan_sp;
913 
914  lldb::addr_t obj_addr =
915  argument_values.GetValueAtIndex(obj_index)->GetScalar().ULongLong();
916  if (obj_addr == 0x0) {
917  LLDB_LOGF(
918  log,
919  "Asked to step to dispatch to nil object, returning empty plan.");
920  return ret_plan_sp;
921  }
922 
923  ExecutionContext exe_ctx(thread.shared_from_this());
924  // isa_addr will store the class pointer that the method is being
925  // dispatched to - so either the class directly or the super class
926  // if this is one of the objc_msgSendSuper flavors. That's mostly
927  // used to look up the class/selector pair in our cache.
928 
931  // If we are not in a selector stub, get the sel address from the arguments.
932  if (!in_selector_stub)
933  sel_addr =
934  argument_values.GetValueAtIndex(sel_index)->GetScalar().ULongLong();
935 
936  // Figure out the class this is being dispatched to and see if
937  // we've already cached this method call, If so we can push a
938  // run-to-address plan directly. Otherwise we have to figure out
939  // where the implementation lives.
940 
941  if (this_dispatch->is_super) {
942  if (this_dispatch->is_super2) {
943  // In the objc_msgSendSuper2 case, we don't get the object
944  // directly, we get a structure containing the object and the
945  // class to which the super message is being sent. So we need
946  // to dig the super out of the class and use that.
947 
948  Value super_value(*(argument_values.GetValueAtIndex(obj_index)));
949  super_value.GetScalar() += process_sp->GetAddressByteSize();
950  super_value.ResolveValue(&exe_ctx);
951 
952  if (super_value.GetScalar().IsValid()) {
953 
954  // isa_value now holds the class pointer. The second word of the
955  // class pointer is the super-class pointer:
956  super_value.GetScalar() += process_sp->GetAddressByteSize();
957  super_value.ResolveValue(&exe_ctx);
958  if (super_value.GetScalar().IsValid())
959  isa_addr = super_value.GetScalar().ULongLong();
960  else {
961  LLDB_LOGF(log, "Failed to extract the super class value from the "
962  "class in objc_super.");
963  }
964  } else {
965  LLDB_LOGF(log, "Failed to extract the class value from objc_super.");
966  }
967  } else {
968  // In the objc_msgSendSuper case, we don't get the object
969  // directly, we get a two element structure containing the
970  // object and the super class to which the super message is
971  // being sent. So the class we want is the second element of
972  // this structure.
973 
974  Value super_value(*(argument_values.GetValueAtIndex(obj_index)));
975  super_value.GetScalar() += process_sp->GetAddressByteSize();
976  super_value.ResolveValue(&exe_ctx);
977 
978  if (super_value.GetScalar().IsValid()) {
979  isa_addr = super_value.GetScalar().ULongLong();
980  } else {
981  LLDB_LOGF(log, "Failed to extract the class value from objc_super.");
982  }
983  }
984  } else {
985  // In the direct dispatch case, the object->isa is the class pointer we
986  // want.
987 
988  // This is a little cheesy, but since object->isa is the first field,
989  // making the object value a load address value and resolving it will get
990  // the pointer sized data pointed to by that value...
991 
992  // Note, it isn't a fatal error not to be able to get the
993  // address from the object, since this might be a "tagged
994  // pointer" which isn't a real object, but rather some word
995  // length encoded dingus.
996 
997  Value isa_value(*(argument_values.GetValueAtIndex(obj_index)));
998 
1000  isa_value.ResolveValue(&exe_ctx);
1001  if (isa_value.GetScalar().IsValid()) {
1002  isa_addr = isa_value.GetScalar().ULongLong();
1003  } else {
1004  LLDB_LOGF(log, "Failed to extract the isa value from object.");
1005  }
1006  }
1007 
1008  // Okay, we've got the address of the class for which we're resolving this,
1009  // let's see if it's in our cache:
1010  lldb::addr_t impl_addr = LLDB_INVALID_ADDRESS;
1011  // If this is a regular dispatch, look up the sel in our addr to sel cache:
1012  if (isa_addr != LLDB_INVALID_ADDRESS) {
1013  ObjCLanguageRuntime *objc_runtime =
1015  assert(objc_runtime != nullptr);
1016  if (!in_selector_stub) {
1017  LLDB_LOG(log, "Resolving call for class - {0} and selector - {1}",
1018  isa_addr, sel_addr);
1019  impl_addr = objc_runtime->LookupInMethodCache(isa_addr, sel_addr);
1020  } else {
1021  LLDB_LOG(log, "Resolving call for class - {0} and selector - {1}",
1022  isa_addr, sym_name);
1023  impl_addr = objc_runtime->LookupInMethodCache(isa_addr, sym_name);
1024  }
1025  }
1026  // If it is a selector-specific stub dispatch, look in the string cache:
1027 
1028  if (impl_addr != LLDB_INVALID_ADDRESS) {
1029  // Yup, it was in the cache, so we can run to that address directly.
1030 
1031  LLDB_LOGF(log, "Found implementation address in cache: 0x%" PRIx64,
1032  impl_addr);
1033 
1034  ret_plan_sp = std::make_shared<ThreadPlanRunToAddress>(thread, impl_addr,
1035  stop_others);
1036  } else {
1037  // We haven't seen this class/selector pair yet. Look it up.
1038  StreamString errors;
1039  Address impl_code_address;
1040 
1041  ValueList dispatch_values;
1042 
1043  // We've will inject a little function in the target that takes the
1044  // object, selector/selector string and some flags,
1045  // and figures out the implementation. Looks like:
1046  // void *__lldb_objc_find_implementation_for_selector (void *object,
1047  // void *sel,
1048  // int
1049  // is_str_ptr,
1050  // int is_stret,
1051  // int is_super,
1052  // int is_super2,
1053  // int is_fixup,
1054  // int is_fixed,
1055  // int debug)
1056  // If we don't have an actual SEL, but rather a string version of the
1057  // selector WE injected, set is_str_ptr to true, and sel to the address
1058  // of the string.
1059  // So set up the arguments for that call.
1060 
1061  dispatch_values.PushValue(*(argument_values.GetValueAtIndex(obj_index)));
1062  lldb::addr_t sel_str_addr = LLDB_INVALID_ADDRESS;
1063  if (!in_selector_stub) {
1064  // If we don't have a selector string, push the selector from arguments.
1065  dispatch_values.PushValue(
1066  *(argument_values.GetValueAtIndex(sel_index)));
1067  } else {
1068  // Otherwise, inject the string into the target, and push that value for
1069  // the sel argument.
1070  Status error;
1071  sel_str_addr = process_sp->AllocateMemory(
1072  sym_name.size() + 1, ePermissionsReadable | ePermissionsWritable,
1073  error);
1074  if (sel_str_addr == LLDB_INVALID_ADDRESS || error.Fail()) {
1075  LLDB_LOG(log,
1076  "Could not allocate memory for selector string {0}: {1}",
1077  sym_name, error);
1078  return ret_plan_sp;
1079  }
1080  process_sp->WriteMemory(sel_str_addr, sym_name.str().c_str(),
1081  sym_name.size() + 1, error);
1082  if (error.Fail()) {
1083  LLDB_LOG(log, "Could not write string to address {0}", sel_str_addr);
1084  return ret_plan_sp;
1085  }
1086  Value sel_ptr_value(void_ptr_value);
1087  sel_ptr_value.GetScalar() = sel_str_addr;
1088  dispatch_values.PushValue(sel_ptr_value);
1089  }
1090 
1091  Value flag_value;
1092  CompilerType clang_int_type =
1093  clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(
1094  lldb::eEncodingSint, 32);
1096  // flag_value.SetContext (Value::eContextTypeClangType, clang_int_type);
1097  flag_value.SetCompilerType(clang_int_type);
1098 
1099  if (in_selector_stub)
1100  flag_value.GetScalar() = 1;
1101  else
1102  flag_value.GetScalar() = 0;
1103  dispatch_values.PushValue(flag_value);
1104 
1105  if (this_dispatch->stret_return)
1106  flag_value.GetScalar() = 1;
1107  else
1108  flag_value.GetScalar() = 0;
1109  dispatch_values.PushValue(flag_value);
1110 
1111  if (this_dispatch->is_super)
1112  flag_value.GetScalar() = 1;
1113  else
1114  flag_value.GetScalar() = 0;
1115  dispatch_values.PushValue(flag_value);
1116 
1117  if (this_dispatch->is_super2)
1118  flag_value.GetScalar() = 1;
1119  else
1120  flag_value.GetScalar() = 0;
1121  dispatch_values.PushValue(flag_value);
1122 
1123  switch (this_dispatch->fixedup) {
1125  flag_value.GetScalar() = 0;
1126  dispatch_values.PushValue(flag_value);
1127  dispatch_values.PushValue(flag_value);
1128  break;
1130  flag_value.GetScalar() = 1;
1131  dispatch_values.PushValue(flag_value);
1132  flag_value.GetScalar() = 1;
1133  dispatch_values.PushValue(flag_value);
1134  break;
1136  flag_value.GetScalar() = 1;
1137  dispatch_values.PushValue(flag_value);
1138  flag_value.GetScalar() = 0;
1139  dispatch_values.PushValue(flag_value);
1140  break;
1141  }
1142  if (log && log->GetVerbose())
1143  flag_value.GetScalar() = 1;
1144  else
1145  flag_value.GetScalar() = 0; // FIXME - Set to 0 when debugging is done.
1146  dispatch_values.PushValue(flag_value);
1147 
1148  ret_plan_sp = std::make_shared<AppleThreadPlanStepThroughObjCTrampoline>(
1149  thread, *this, dispatch_values, isa_addr, sel_addr, sel_str_addr,
1150  sym_name);
1151  if (log) {
1152  StreamString s;
1153  ret_plan_sp->GetDescription(&s, eDescriptionLevelFull);
1154  LLDB_LOGF(log, "Using ObjC step plan: %s.\n", s.GetData());
1155  }
1156  }
1157  }
1158 
1159  // Finally, check if we have hit an "optimized dispatch" function. This will
1160  // either directly call the base implementation or dispatch an objc_msgSend
1161  // if the method has been overridden. So we just do a "step in/step out",
1162  // setting a breakpoint on objc_msgSend, and if we hit the msgSend, we
1163  // will automatically step in again. That's the job of the
1164  // AppleThreadPlanStepThroughDirectDispatch.
1165  if (!this_dispatch && !ret_plan_sp) {
1166  MsgsendMap::iterator pos;
1167  pos = m_opt_dispatch_map.find(curr_pc);
1168  if (pos != m_opt_dispatch_map.end()) {
1169  const char *opt_name = g_opt_dispatch_names[(*pos).second];
1170  ret_plan_sp = std::make_shared<AppleThreadPlanStepThroughDirectDispatch>(
1171  thread, *this, opt_name);
1172  }
1173  }
1174 
1175  return ret_plan_sp;
1176 }
1177 
1180  return m_impl_code->GetFunctionCaller();
1181 }
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::SetUpRegion
void SetUpRegion()
Definition: AppleObjCTrampolineHandler.cpp:190
lldb_private::Value::ValueType::Scalar
@ Scalar
A raw scalar value.
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::m_process_wp
lldb::ProcessWP m_process_wp
Definition: AppleObjCTrampolineHandler.h:139
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::Dump
void Dump(Stream &s)
Definition: AppleObjCTrampolineHandler.cpp:317
lldb_private::DataExtractor::GetAddress
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
Definition: DataExtractor.cpp:649
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::is_super
bool is_super
Definition: AppleObjCTrampolineHandler.h:43
lldb_private::StoppointCallbackContext
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
Definition: StoppointCallbackContext.h:26
lldb_private::Log::GetVerbose
bool GetVerbose() const
Definition: Log.cpp:300
lldb_private::Address::IsValid
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:345
lldb::eSymbolTypeCode
@ eSymbolTypeCode
Definition: lldb-enumerations.h:622
lldb_private::AppleObjCTrampolineHandler::AppleObjCTrampolineHandler
AppleObjCTrampolineHandler(const lldb::ProcessSP &process_sp, const lldb::ModuleSP &objc_module_sp)
Definition: AppleObjCTrampolineHandler.cpp:576
lldb_private::ABI
Definition: ABI.h:27
lldb_private::ModuleList::Modules
ModuleIterable Modules() const
Definition: ModuleList.h:491
FunctionCaller.h
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::fixedup
FixUpState fixedup
Definition: AppleObjCTrampolineHandler.h:45
lldb_private::ObjCLanguageRuntime
Definition: ObjCLanguageRuntime.h:35
lldb_private::Value
Definition: Value.h:38
lldb_private::Symbol
Definition: Symbol.h:20
lldb_private::Value::SetValueType
void SetValueType(ValueType value_type)
Definition: Value.h:89
lldb_private::Symbol::ValueIsAddress
bool ValueIsAddress() const
Definition: Symbol.cpp:117
lldb_private::ExecutionContext::GetProcessPtr
Process * GetProcessPtr() const
Returns a pointer to the process object.
Definition: ExecutionContext.cpp:206
lldb_private::DiagnosticManager::Dump
void Dump(Log *log)
Definition: DiagnosticManager.cpp:18
lldb_private::Value::GetValueAsData
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition: Value.cpp:298
lldb_private::AppleObjCTrampolineHandler::DispatchFunction
Definition: AppleObjCTrampolineHandler.h:37
lldb_private::ObjCLanguageRuntime::Get
static ObjCLanguageRuntime * Get(Process &process)
Definition: ObjCLanguageRuntime.h:214
lldb_private::ValueList::GetValueAtIndex
Value * GetValueAtIndex(size_t idx)
Definition: Value.cpp:669
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::~AppleObjCVTables
~AppleObjCVTables()
Definition: AppleObjCTrampolineHandler.cpp:339
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:343
lldb_private::Process
Definition: Process.h:338
arm64_dwarf::x0
@ x0
Definition: ARM64_DWARF_Registers.h:17
lldb_private::TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize
CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size) override
Definition: TypeSystemClang.cpp:795
lldb_private::Thread::CalculateTarget
lldb::TargetSP CalculateTarget() override
Definition: Thread.cpp:1383
Module.h
lldb_private::Process::GetTarget
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1206
lldb_private::StoppointCallbackContext::exe_ctx_ref
ExecutionContextRef exe_ctx_ref
Definition: StoppointCallbackContext.h:43
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::eFixUpToFix
@ eFixUpToFix
Definition: AppleObjCTrampolineHandler.h:39
StoppointCallbackContext.h
lldb_private::AppleObjCTrampolineHandler::g_opt_dispatch_names
static const char * g_opt_dispatch_names[]
Definition: AppleObjCTrampolineHandler.h:148
lldb::eSymbolTypeData
@ eSymbolTypeData
Definition: lldb-enumerations.h:624
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
lldb_private::Value::ValueType::LoadAddress
@ LoadAddress
A load address value.
UserExpression.h
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables
Definition: AppleObjCTrampolineHandler.h:69
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::ValueList
Definition: Value.h:157
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::IsAddressInVTables
bool IsAddressInVTables(lldb::addr_t addr, uint32_t &flags)
Definition: AppleObjCTrampolineHandler.cpp:503
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::m_objc_module_sp
lldb::ModuleSP m_objc_module_sp
Definition: AppleObjCTrampolineHandler.h:144
lldb_private::Stream
Definition: Stream.h:28
lldb_private::Target::CreateBreakpoint
lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, uint32_t column, lldb::addr_t offset, LazyBool check_inlines, LazyBool skip_prologue, bool internal, bool request_hardware, LazyBool move_to_nearest_code)
Definition: Target.cpp:350
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::AppleObjCTrampolineHandler::~AppleObjCTrampolineHandler
~AppleObjCTrampolineHandler()
lldb_private::AppleObjCTrampolineHandler::m_impl_code
std::unique_ptr< UtilityFunction > m_impl_code
Definition: AppleObjCTrampolineHandler.h:158
lldb_private::Target::ResolveLoadAddress
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow)
Definition: Target.cpp:2906
Debugger.h
lldb_private::Target
Definition: Target.h:473
lldb_private::Address::GetOpcodeLoadAddress
lldb::addr_t GetOpcodeLoadAddress(Target *target, AddressClass addr_class=AddressClass::eInvalid) const
Get the load address as an opcode load address.
Definition: Address.cpp:368
lldb_private::AppleObjCTrampolineHandler::m_msgSend_map
MsgsendMap m_msgSend_map
Definition: AppleObjCTrampolineHandler.h:153
lldb_private::AppleObjCTrampolineHandler::m_lookup_implementation_function_code
std::string m_lookup_implementation_function_code
Definition: AppleObjCTrampolineHandler.h:157
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::RefreshTrampolines
static bool RefreshTrampolines(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
Definition: AppleObjCTrampolineHandler.cpp:406
ABI.h
lldb_private::Target::GetImages
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:947
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::m_trampoline_header
lldb::addr_t m_trampoline_header
Definition: AppleObjCTrampolineHandler.h:141
Process.h
lldb_private::Value::SetCompilerType
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:251
Target.h
lldb_private::Value::GetScalar
const Scalar & GetScalar() const
Definition: Value.h:112
lldb_private::Thread::GetProcess
lldb::ProcessSP GetProcess() const
Definition: Thread.h:153
lldb_private::AppleObjCTrampolineHandler::g_lookup_implementation_with_stret_function_code
static const char * g_lookup_implementation_with_stret_function_code
Definition: AppleObjCTrampolineHandler.h:65
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb::eEncodingSint
@ eEncodingSint
signed integer
Definition: lldb-enumerations.h:149
lldb_private::ValueList::PushValue
void PushValue(const Value &value)
Definition: Value.cpp:665
lldb_private::AppleObjCTrampolineHandler::g_lookup_implementation_function_name
static const char * g_lookup_implementation_function_name
These hold the code for the function that finds the implementation of an ObjC message send given the ...
Definition: AppleObjCTrampolineHandler.h:63
lldb_private::Thread::CalculateProcess
lldb::ProcessSP CalculateProcess() override
Definition: Thread.cpp:1391
lldb_private::FunctionCaller::WriteFunctionArguments
bool WriteFunctionArguments(ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, DiagnosticManager &diagnostic_manager)
Insert the default function argument struct.
Definition: FunctionCaller.cpp:116
lldb_private::Stream::Indent
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition: Stream.cpp:130
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::InitializeVTableSymbols
bool InitializeVTableSymbols()
Definition: AppleObjCTrampolineHandler.cpp:347
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::ReadRegions
bool ReadRegions()
Definition: AppleObjCTrampolineHandler.cpp:454
lldb_private::Scalar::ULongLong
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition: Scalar.cpp:334
Log.h
TypeSystemClang.h
lldb_private::AppleObjCTrampolineHandler::m_vtables_up
std::unique_ptr< AppleObjCVTables > m_vtables_up
Definition: AppleObjCTrampolineHandler.h:164
lldb_private::Thread
Definition: Thread.h:61
AppleThreadPlanStepThroughObjCTrampoline.h
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
lldb_private::AppleObjCTrampolineHandler::g_dispatch_functions
static const DispatchFunction g_dispatch_functions[]
Definition: AppleObjCTrampolineHandler.h:147
lldb_private::Symbol::GetAddressRef
Address & GetAddressRef()
Definition: Symbol.h:57
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::m_trampolines_changed_bp_id
lldb::break_id_t m_trampolines_changed_bp_id
Definition: AppleObjCTrampolineHandler.h:142
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:2405
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::StreamString
Definition: StreamString.h:23
lldb::eDescriptionLevelFull
@ eDescriptionLevelFull
Definition: lldb-enumerations.h:209
lldb_private::AppleObjCTrampolineHandler::ForEachDispatchFunction
void ForEachDispatchFunction(std::function< void(lldb::addr_t, const DispatchFunction &)>)
Definition: AppleObjCTrampolineHandler.cpp:784
lldb_private::AppleObjCTrampolineHandler::m_opt_dispatch_map
MsgsendMap m_opt_dispatch_map
Definition: AppleObjCTrampolineHandler.h:154
lldb_private::AppleObjCTrampolineHandler::FindDispatchFunction
const DispatchFunction * FindDispatchFunction(lldb::addr_t addr)
Definition: AppleObjCTrampolineHandler.cpp:774
lldb::eBasicTypeVoid
@ eBasicTypeVoid
Definition: lldb-enumerations.h:749
ThreadPlanRunToAddress.h
Thread.h
lldb_private::Address::CalculateSymbolContextSymbol
Symbol * CalculateSymbolContextSymbol() const
Definition: Address.cpp:893
lldb_private::LLDBLog::Step
@ Step
lldb_private::AppleObjCTrampolineHandler::m_msg_forward_addr
lldb::addr_t m_msg_forward_addr
Definition: AppleObjCTrampolineHandler.h:162
UtilityFunction.h
lldb_private::AppleObjCTrampolineHandler::GetLookupImplementationFunctionCaller
FunctionCaller * GetLookupImplementationFunctionCaller()
Definition: AppleObjCTrampolineHandler.cpp:1179
LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
lldb_private::Value::ResolveValue
Scalar & ResolveValue(ExecutionContext *exe_ctx)
Definition: Value.cpp:560
Symbol.h
lldb_private::AppleObjCTrampolineHandler::m_impl_stret_fn_addr
lldb::addr_t m_impl_stret_fn_addr
Definition: AppleObjCTrampolineHandler.h:161
lldb_private::Symbol::GetName
ConstString GetName() const
Definition: Symbol.cpp:501
StreamFile.h
lldb_private::ExecutionContext::GetThreadRef
Thread & GetThreadRef() const
Returns a reference to the thread object.
Definition: ExecutionContext.cpp:234
lldb_private::Status
Definition: Status.h:44
lldb_private::CompilerType::GetPointerType
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
Definition: CompilerType.cpp:407
uint32_t
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion
Definition: AppleObjCTrampolineHandler.h:87
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::AppleObjCVTables
AppleObjCVTables(const lldb::ProcessSP &process_sp, const lldb::ModuleSP &objc_module_sp)
Definition: AppleObjCTrampolineHandler.cpp:330
lldb_private::Address
Definition: Address.h:59
lldb_private::AppleObjCTrampolineHandler::g_lookup_implementation_function_common_code
static const char * g_lookup_implementation_function_common_code
Definition: AppleObjCTrampolineHandler.h:64
lldb_private::AppleObjCTrampolineHandler::m_impl_fn_addr
lldb::addr_t m_impl_fn_addr
Definition: AppleObjCTrampolineHandler.h:160
lldb_private::DiagnosticManager
Definition: DiagnosticManager.h:93
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::AddressInRegion
bool AddressInRegion(lldb::addr_t addr, uint32_t &flags)
Definition: AppleObjCTrampolineHandler.cpp:300
ObjCLanguageRuntime.h
uint16_t
lldb_private::ScratchTypeSystemClang::GetForTarget
static TypeSystemClang * GetForTarget(Target &target, llvm::Optional< IsolatedASTKind > ast_kind=DefaultAST, bool create_on_demand=true)
Returns the scratch TypeSystemClang for the given target.
Definition: TypeSystemClang.cpp:9797
lldb_private::DataExtractor::GetU32
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
Definition: DataExtractor.cpp:425
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:336
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::eFixUpNone
@ eFixUpNone
Definition: AppleObjCTrampolineHandler.h:39
DiagnosticManager.h
lldb_private::ExecutionContext::GetTargetRef
Target & GetTargetRef() const
Returns a reference to the target object.
Definition: ExecutionContext.cpp:224
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::is_super2
bool is_super2
Definition: AppleObjCTrampolineHandler.h:44
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
lldb_private::DataExtractor::GetU16
uint16_t GetU16(lldb::offset_t *offset_ptr) const
Extract a uint16_t value from *offset_ptr.
Definition: DataExtractor.cpp:347
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::eOBJC_TRAMPOLINE_STRET
@ eOBJC_TRAMPOLINE_STRET
Definition: AppleObjCTrampolineHandler.h:74
lldb_private::TypeSystemClang::GetBasicType
CompilerType GetBasicType(lldb::BasicType type)
Definition: TypeSystemClang.cpp:930
FileSpec.h
lldb_private::AppleObjCTrampolineHandler::g_lookup_implementation_no_stret_function_code
static const char * g_lookup_implementation_no_stret_function_code
Definition: AppleObjCTrampolineHandler.h:66
lldb_private::AppleObjCTrampolineHandler::m_impl_function_mutex
std::mutex m_impl_function_mutex
Definition: AppleObjCTrampolineHandler.h:159
lldb_private::TypeSystemClang
A TypeSystem implementation based on Clang.
Definition: TypeSystemClang.h:105
lldb_private::AppleObjCTrampolineHandler::SetupDispatchFunction
lldb::addr_t SetupDispatchFunction(Thread &thread, ValueList &dispatch_values)
Definition: AppleObjCTrampolineHandler.cpp:699
ConstString.h
lldb_private::Process::GetABI
const lldb::ABISP & GetABI()
Definition: Process.cpp:1482
lldb_private::Log
Definition: Log.h:115
lldb_private::AppleObjCTrampolineHandler::GetStepThroughDispatchPlan
lldb::ThreadPlanSP GetStepThroughDispatchPlan(Thread &thread, bool stop_others)
Definition: AppleObjCTrampolineHandler.cpp:793
lldb_private::Thread::GetStackFrameAtIndex
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:398
lldb_private::Symbol::GetLoadAddress
lldb::addr_t GetLoadAddress(Target *target) const
Definition: Symbol.cpp:494
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::eFixUpFixed
@ eFixUpFixed
Definition: AppleObjCTrampolineHandler.h:39
lldb_private::Thread::GetRegisterContext
virtual lldb::RegisterContextSP GetRegisterContext()=0
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:308
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::AppleObjCTrampolineHandler::DispatchFunction::stret_return
bool stret_return
Definition: AppleObjCTrampolineHandler.h:42
lldb
Definition: SBAddress.h:15
lldb_private::ABI::GetArgumentValues
virtual bool GetArgumentValues(Thread &thread, ValueList &values) const =0
RegisterContext.h
LLDB_LOG_ERROR
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:359
Value.h
lldb_private::ObjCLanguageRuntime::LookupInMethodCache
lldb::addr_t LookupInMethodCache(lldb::addr_t class_addr, lldb::addr_t sel)
Definition: ObjCLanguageRuntime.cpp:90
LLDBLog.h
ExecutionContext.h
lldb_private::AppleObjCTrampolineHandler::m_process_wp
lldb::ProcessWP m_process_wp
Definition: AppleObjCTrampolineHandler.h:155
lldb_private::AppleObjCTrampolineHandler::m_objc_module_sp
lldb::ModuleSP m_objc_module_sp
Definition: AppleObjCTrampolineHandler.h:156
lldb_private::Scalar::IsValid
bool IsValid() const
Definition: Scalar.h:106
AppleObjCTrampolineHandler.h
lldb_private::FunctionCaller
Definition: FunctionCaller.h:56
lldb_private::AppleObjCTrampolineHandler::m_msg_forward_stret_addr
lldb::addr_t m_msg_forward_stret_addr
Definition: AppleObjCTrampolineHandler.h:163
lldb_private::AppleObjCTrampolineHandler::AppleObjCVTables::VTableDescriptor
Definition: AppleObjCTrampolineHandler.h:79
lldb_private::Symbol::GetAddress
Address GetAddress() const
Definition: Symbol.h:73