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