LLDB  mainline
ABISysV_ppc.cpp
Go to the documentation of this file.
1 //===-- ABISysV_ppc.cpp -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "ABISysV_ppc.h"
10 
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/ADT/Triple.h"
13 
14 #include "lldb/Core/Module.h"
16 #include "lldb/Core/Value.h"
20 #include "lldb/Symbol/UnwindPlan.h"
21 #include "lldb/Target/Process.h"
23 #include "lldb/Target/StackFrame.h"
24 #include "lldb/Target/Target.h"
25 #include "lldb/Target/Thread.h"
28 #include "lldb/Utility/Log.h"
30 #include "lldb/Utility/Status.h"
31 
32 using namespace lldb;
33 using namespace lldb_private;
34 
36  dwarf_r0 = 0,
102  dwarf_xer = 101,
103  dwarf_lr = 108,
107 };
108 
109 // Note that the size and offset will be updated by platform-specific classes.
110 #define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4) \
111  { \
112  #reg, alt, 8, 0, eEncodingUint, eFormatHex, {kind1, kind2, kind3, kind4 }, \
113  nullptr, nullptr, nullptr, 0 \
114  }
115 
116 static const RegisterInfo g_register_infos[] = {
117  // General purpose registers. eh_frame, DWARF,
118  // Generic, Process Plugin
193  {nullptr,
194  nullptr,
195  8,
196  0,
198  eFormatHex,
199  {dwarf_cfa, dwarf_cfa, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
200  nullptr,
201  nullptr,
202  nullptr,
203  0}};
204 
206  llvm::array_lengthof(g_register_infos);
207 
208 const lldb_private::RegisterInfo *
210  count = k_num_register_infos;
211  return g_register_infos;
212 }
213 
214 size_t ABISysV_ppc::GetRedZoneSize() const { return 224; }
215 
216 // Static Functions
217 
218 ABISP
219 ABISysV_ppc::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) {
220  if (arch.GetTriple().getArch() == llvm::Triple::ppc) {
221  return ABISP(new ABISysV_ppc(process_sp));
222  }
223  return ABISP();
224 }
225 
227  addr_t func_addr, addr_t return_addr,
228  llvm::ArrayRef<addr_t> args) const {
230 
231  if (log) {
232  StreamString s;
233  s.Printf("ABISysV_ppc::PrepareTrivialCall (tid = 0x%" PRIx64
234  ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
235  ", return_addr = 0x%" PRIx64,
236  thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
237  (uint64_t)return_addr);
238 
239  for (size_t i = 0; i < args.size(); ++i)
240  s.Printf(", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1),
241  args[i]);
242  s.PutCString(")");
243  log->PutString(s.GetString());
244  }
245 
246  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
247  if (!reg_ctx)
248  return false;
249 
250  const RegisterInfo *reg_info = nullptr;
251 
252  if (args.size() > 8) // TODO handle more than 8 arguments
253  return false;
254 
255  for (size_t i = 0; i < args.size(); ++i) {
256  reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
258  if (log)
259  log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s",
260  static_cast<uint64_t>(i + 1), args[i], reg_info->name);
261  if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
262  return false;
263  }
264 
265  // First, align the SP
266 
267  if (log)
268  log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64,
269  (uint64_t)sp, (uint64_t)(sp & ~0xfull));
270 
271  sp &= ~(0xfull); // 16-byte alignment
272 
273  sp -= 8;
274 
275  Status error;
276  const RegisterInfo *pc_reg_info =
278  const RegisterInfo *sp_reg_info =
280  ProcessSP process_sp(thread.GetProcess());
281 
282  RegisterValue reg_value;
283 
284  if (log)
285  log->Printf("Pushing the return address onto the stack: 0x%" PRIx64
286  ": 0x%" PRIx64,
287  (uint64_t)sp, (uint64_t)return_addr);
288 
289  // Save return address onto the stack
290  if (!process_sp->WritePointerToMemory(sp, return_addr, error))
291  return false;
292 
293  // %r1 is set to the actual stack value.
294 
295  if (log)
296  log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
297 
298  if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
299  return false;
300 
301  // %pc is set to the address of the called function.
302 
303  if (log)
304  log->Printf("Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
305 
306  if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_info, func_addr))
307  return false;
308 
309  return true;
310 }
311 
312 static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width,
313  bool is_signed, Thread &thread,
314  uint32_t *argument_register_ids,
315  unsigned int &current_argument_register,
316  addr_t &current_stack_argument) {
317  if (bit_width > 64)
318  return false; // Scalar can't hold large integer arguments
319 
320  if (current_argument_register < 6) {
321  scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
322  argument_register_ids[current_argument_register], 0);
323  current_argument_register++;
324  if (is_signed)
325  scalar.SignExtend(bit_width);
326  } else {
327  uint32_t byte_size = (bit_width + (8 - 1)) / 8;
328  Status error;
329  if (thread.GetProcess()->ReadScalarIntegerFromMemory(
330  current_stack_argument, byte_size, is_signed, scalar, error)) {
331  current_stack_argument += byte_size;
332  return true;
333  }
334  return false;
335  }
336  return true;
337 }
338 
339 bool ABISysV_ppc::GetArgumentValues(Thread &thread, ValueList &values) const {
340  unsigned int num_values = values.GetSize();
341  unsigned int value_index;
342 
343  // Extract the register context so we can read arguments from registers
344 
345  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
346 
347  if (!reg_ctx)
348  return false;
349 
350  // Get the pointer to the first stack argument so we have a place to start
351  // when reading data
352 
353  addr_t sp = reg_ctx->GetSP(0);
354 
355  if (!sp)
356  return false;
357 
358  addr_t current_stack_argument = sp + 48; // jump over return address
359 
360  uint32_t argument_register_ids[8];
361 
362  argument_register_ids[0] =
364  ->kinds[eRegisterKindLLDB];
365  argument_register_ids[1] =
367  ->kinds[eRegisterKindLLDB];
368  argument_register_ids[2] =
370  ->kinds[eRegisterKindLLDB];
371  argument_register_ids[3] =
373  ->kinds[eRegisterKindLLDB];
374  argument_register_ids[4] =
376  ->kinds[eRegisterKindLLDB];
377  argument_register_ids[5] =
379  ->kinds[eRegisterKindLLDB];
380  argument_register_ids[6] =
382  ->kinds[eRegisterKindLLDB];
383  argument_register_ids[7] =
385  ->kinds[eRegisterKindLLDB];
386 
387  unsigned int current_argument_register = 0;
388 
389  for (value_index = 0; value_index < num_values; ++value_index) {
390  Value *value = values.GetValueAtIndex(value_index);
391 
392  if (!value)
393  return false;
394 
395  // We currently only support extracting values with Clang QualTypes. Do we
396  // care about others?
397  CompilerType compiler_type = value->GetCompilerType();
398  llvm::Optional<uint64_t> bit_size = compiler_type.GetBitSize(&thread);
399  if (!bit_size)
400  return false;
401  bool is_signed;
402  if (compiler_type.IsIntegerOrEnumerationType(is_signed))
403  ReadIntegerArgument(value->GetScalar(), *bit_size, is_signed, thread,
404  argument_register_ids, current_argument_register,
405  current_stack_argument);
406  else if (compiler_type.IsPointerType())
407  ReadIntegerArgument(value->GetScalar(), *bit_size, false, thread,
408  argument_register_ids, current_argument_register,
409  current_stack_argument);
410  }
411 
412  return true;
413 }
414 
415 Status ABISysV_ppc::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
416  lldb::ValueObjectSP &new_value_sp) {
417  Status error;
418  if (!new_value_sp) {
419  error.SetErrorString("Empty value object for return value.");
420  return error;
421  }
422 
423  CompilerType compiler_type = new_value_sp->GetCompilerType();
424  if (!compiler_type) {
425  error.SetErrorString("Null clang type for return value.");
426  return error;
427  }
428 
429  Thread *thread = frame_sp->GetThread().get();
430 
431  bool is_signed;
432  uint32_t count;
433  bool is_complex;
434 
435  RegisterContext *reg_ctx = thread->GetRegisterContext().get();
436 
437  bool set_it_simple = false;
438  if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
439  compiler_type.IsPointerType()) {
440  const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
441 
442  DataExtractor data;
443  Status data_error;
444  size_t num_bytes = new_value_sp->GetData(data, data_error);
445  if (data_error.Fail()) {
447  "Couldn't convert return value to raw data: %s",
448  data_error.AsCString());
449  return error;
450  }
451  lldb::offset_t offset = 0;
452  if (num_bytes <= 8) {
453  uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
454 
455  if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
456  set_it_simple = true;
457  } else {
458  error.SetErrorString("We don't support returning longer than 64 bit "
459  "integer values at present.");
460  }
461  } else if (compiler_type.IsFloatingPointType(count, is_complex)) {
462  if (is_complex)
463  error.SetErrorString(
464  "We don't support returning complex values at present");
465  else {
466  llvm::Optional<uint64_t> bit_width =
467  compiler_type.GetBitSize(frame_sp.get());
468  if (!bit_width) {
469  error.SetErrorString("can't get type size");
470  return error;
471  }
472  if (*bit_width <= 64) {
473  DataExtractor data;
474  Status data_error;
475  size_t num_bytes = new_value_sp->GetData(data, data_error);
476  if (data_error.Fail()) {
478  "Couldn't convert return value to raw data: %s",
479  data_error.AsCString());
480  return error;
481  }
482 
483  unsigned char buffer[16];
484  ByteOrder byte_order = data.GetByteOrder();
485 
486  data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
487  set_it_simple = true;
488  } else {
489  // FIXME - don't know how to do 80 bit long doubles yet.
490  error.SetErrorString(
491  "We don't support returning float values > 64 bits at present");
492  }
493  }
494  }
495 
496  if (!set_it_simple) {
497  // Okay we've got a structure or something that doesn't fit in a simple
498  // register. We should figure out where it really goes, but we don't
499  // support this yet.
500  error.SetErrorString("We only support setting simple integer and float "
501  "return types at present.");
502  }
503 
504  return error;
505 }
506 
508  Thread &thread, CompilerType &return_compiler_type) const {
509  ValueObjectSP return_valobj_sp;
510  Value value;
511 
512  if (!return_compiler_type)
513  return return_valobj_sp;
514 
515  // value.SetContext (Value::eContextTypeClangType, return_value_type);
516  value.SetCompilerType(return_compiler_type);
517 
518  RegisterContext *reg_ctx = thread.GetRegisterContext().get();
519  if (!reg_ctx)
520  return return_valobj_sp;
521 
522  const uint32_t type_flags = return_compiler_type.GetTypeInfo();
523  if (type_flags & eTypeIsScalar) {
524  value.SetValueType(Value::eValueTypeScalar);
525 
526  bool success = false;
527  if (type_flags & eTypeIsInteger) {
528  // Extract the register context so we can read arguments from registers
529 
530  llvm::Optional<uint64_t> byte_size =
531  return_compiler_type.GetByteSize(nullptr);
532  if (!byte_size)
533  return return_valobj_sp;
534  uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
535  reg_ctx->GetRegisterInfoByName("r3", 0), 0);
536  const bool is_signed = (type_flags & eTypeIsSigned) != 0;
537  switch (*byte_size) {
538  default:
539  break;
540 
541  case sizeof(uint64_t):
542  if (is_signed)
543  value.GetScalar() = (int64_t)(raw_value);
544  else
545  value.GetScalar() = (uint64_t)(raw_value);
546  success = true;
547  break;
548 
549  case sizeof(uint32_t):
550  if (is_signed)
551  value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
552  else
553  value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
554  success = true;
555  break;
556 
557  case sizeof(uint16_t):
558  if (is_signed)
559  value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
560  else
561  value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
562  success = true;
563  break;
564 
565  case sizeof(uint8_t):
566  if (is_signed)
567  value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
568  else
569  value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
570  success = true;
571  break;
572  }
573  } else if (type_flags & eTypeIsFloat) {
574  if (type_flags & eTypeIsComplex) {
575  // Don't handle complex yet.
576  } else {
577  llvm::Optional<uint64_t> byte_size =
578  return_compiler_type.GetByteSize(nullptr);
579  if (byte_size && *byte_size <= sizeof(long double)) {
580  const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
581  RegisterValue f1_value;
582  if (reg_ctx->ReadRegister(f1_info, f1_value)) {
583  DataExtractor data;
584  if (f1_value.GetData(data)) {
585  lldb::offset_t offset = 0;
586  if (*byte_size == sizeof(float)) {
587  value.GetScalar() = (float)data.GetFloat(&offset);
588  success = true;
589  } else if (*byte_size == sizeof(double)) {
590  value.GetScalar() = (double)data.GetDouble(&offset);
591  success = true;
592  }
593  }
594  }
595  }
596  }
597  }
598 
599  if (success)
600  return_valobj_sp = ValueObjectConstResult::Create(
601  thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
602  } else if (type_flags & eTypeIsPointer) {
603  unsigned r3_id =
604  reg_ctx->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
605  value.GetScalar() =
606  (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 0);
607  value.SetValueType(Value::eValueTypeScalar);
608  return_valobj_sp = ValueObjectConstResult::Create(
609  thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
610  } else if (type_flags & eTypeIsVector) {
611  llvm::Optional<uint64_t> byte_size =
612  return_compiler_type.GetByteSize(nullptr);
613  if (byte_size && *byte_size > 0) {
614  const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("v2", 0);
615  if (altivec_reg) {
616  if (*byte_size <= altivec_reg->byte_size) {
617  ProcessSP process_sp(thread.GetProcess());
618  if (process_sp) {
619  std::unique_ptr<DataBufferHeap> heap_data_up(
620  new DataBufferHeap(*byte_size, 0));
621  const ByteOrder byte_order = process_sp->GetByteOrder();
622  RegisterValue reg_value;
623  if (reg_ctx->ReadRegister(altivec_reg, reg_value)) {
624  Status error;
625  if (reg_value.GetAsMemoryData(
626  altivec_reg, heap_data_up->GetBytes(),
627  heap_data_up->GetByteSize(), byte_order, error)) {
628  DataExtractor data(DataBufferSP(heap_data_up.release()),
629  byte_order,
630  process_sp->GetTarget()
631  .GetArchitecture()
632  .GetAddressByteSize());
633  return_valobj_sp = ValueObjectConstResult::Create(
634  &thread, return_compiler_type, ConstString(""), data);
635  }
636  }
637  }
638  }
639  }
640  }
641  }
642 
643  return return_valobj_sp;
644 }
645 
647  Thread &thread, CompilerType &return_compiler_type) const {
648  ValueObjectSP return_valobj_sp;
649 
650  if (!return_compiler_type)
651  return return_valobj_sp;
652 
653  ExecutionContext exe_ctx(thread.shared_from_this());
654  return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
655  if (return_valobj_sp)
656  return return_valobj_sp;
657 
658  RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
659  if (!reg_ctx_sp)
660  return return_valobj_sp;
661 
662  llvm::Optional<uint64_t> bit_width = return_compiler_type.GetBitSize(&thread);
663  if (!bit_width)
664  return return_valobj_sp;
665  if (return_compiler_type.IsAggregateType()) {
666  Target *target = exe_ctx.GetTargetPtr();
667  bool is_memory = true;
668  if (*bit_width <= 128) {
669  ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
670  DataBufferSP data_sp(new DataBufferHeap(16, 0));
671  DataExtractor return_ext(data_sp, target_byte_order,
672  target->GetArchitecture().GetAddressByteSize());
673 
674  const RegisterInfo *r3_info = reg_ctx_sp->GetRegisterInfoByName("r3", 0);
675  const RegisterInfo *rdx_info =
676  reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
677 
678  RegisterValue r3_value, rdx_value;
679  reg_ctx_sp->ReadRegister(r3_info, r3_value);
680  reg_ctx_sp->ReadRegister(rdx_info, rdx_value);
681 
682  DataExtractor r3_data, rdx_data;
683 
684  r3_value.GetData(r3_data);
685  rdx_value.GetData(rdx_data);
686 
687  uint32_t fp_bytes =
688  0; // Tracks how much of the xmm registers we've consumed so far
689  uint32_t integer_bytes =
690  0; // Tracks how much of the r3/rds registers we've consumed so far
691 
692  const uint32_t num_children = return_compiler_type.GetNumFields();
693 
694  // Since we are in the small struct regime, assume we are not in memory.
695  is_memory = false;
696 
697  for (uint32_t idx = 0; idx < num_children; idx++) {
698  std::string name;
699  uint64_t field_bit_offset = 0;
700  bool is_signed;
701  bool is_complex;
702  uint32_t count;
703 
704  CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(
705  idx, name, &field_bit_offset, nullptr, nullptr);
706  llvm::Optional<uint64_t> field_bit_width =
707  field_compiler_type.GetBitSize(&thread);
708  if (!field_bit_width)
709  return return_valobj_sp;
710 
711  // If there are any unaligned fields, this is stored in memory.
712  if (field_bit_offset % *field_bit_width != 0) {
713  is_memory = true;
714  break;
715  }
716 
717  uint32_t field_byte_width = *field_bit_width / 8;
718  uint32_t field_byte_offset = field_bit_offset / 8;
719 
720  DataExtractor *copy_from_extractor = nullptr;
721  uint32_t copy_from_offset = 0;
722 
723  if (field_compiler_type.IsIntegerOrEnumerationType(is_signed) ||
724  field_compiler_type.IsPointerType()) {
725  if (integer_bytes < 8) {
726  if (integer_bytes + field_byte_width <= 8) {
727  // This is in RAX, copy from register to our result structure:
728  copy_from_extractor = &r3_data;
729  copy_from_offset = integer_bytes;
730  integer_bytes += field_byte_width;
731  } else {
732  // The next field wouldn't fit in the remaining space, so we
733  // pushed it to rdx.
734  copy_from_extractor = &rdx_data;
735  copy_from_offset = 0;
736  integer_bytes = 8 + field_byte_width;
737  }
738  } else if (integer_bytes + field_byte_width <= 16) {
739  copy_from_extractor = &rdx_data;
740  copy_from_offset = integer_bytes - 8;
741  integer_bytes += field_byte_width;
742  } else {
743  // The last field didn't fit. I can't see how that would happen
744  // w/o the overall size being greater than 16 bytes. For now,
745  // return a nullptr return value object.
746  return return_valobj_sp;
747  }
748  } else if (field_compiler_type.IsFloatingPointType(count, is_complex)) {
749  // Structs with long doubles are always passed in memory.
750  if (*field_bit_width == 128) {
751  is_memory = true;
752  break;
753  } else if (*field_bit_width == 64) {
754  copy_from_offset = 0;
755  fp_bytes += field_byte_width;
756  } else if (*field_bit_width == 32) {
757  // This one is kind of complicated. If we are in an "eightbyte"
758  // with another float, we'll be stuffed into an xmm register with
759  // it. If we are in an "eightbyte" with one or more ints, then we
760  // will be stuffed into the appropriate GPR with them.
761  bool in_gpr;
762  if (field_byte_offset % 8 == 0) {
763  // We are at the beginning of one of the eightbytes, so check the
764  // next element (if any)
765  if (idx == num_children - 1)
766  in_gpr = false;
767  else {
768  uint64_t next_field_bit_offset = 0;
769  CompilerType next_field_compiler_type =
770  return_compiler_type.GetFieldAtIndex(idx + 1, name,
771  &next_field_bit_offset,
772  nullptr, nullptr);
773  if (next_field_compiler_type.IsIntegerOrEnumerationType(
774  is_signed))
775  in_gpr = true;
776  else {
777  copy_from_offset = 0;
778  in_gpr = false;
779  }
780  }
781  } else if (field_byte_offset % 4 == 0) {
782  // We are inside of an eightbyte, so see if the field before us
783  // is floating point: This could happen if somebody put padding
784  // in the structure.
785  if (idx == 0)
786  in_gpr = false;
787  else {
788  uint64_t prev_field_bit_offset = 0;
789  CompilerType prev_field_compiler_type =
790  return_compiler_type.GetFieldAtIndex(idx - 1, name,
791  &prev_field_bit_offset,
792  nullptr, nullptr);
793  if (prev_field_compiler_type.IsIntegerOrEnumerationType(
794  is_signed))
795  in_gpr = true;
796  else {
797  copy_from_offset = 4;
798  in_gpr = false;
799  }
800  }
801  } else {
802  is_memory = true;
803  continue;
804  }
805 
806  // Okay, we've figured out whether we are in GPR or XMM, now figure
807  // out which one.
808  if (in_gpr) {
809  if (integer_bytes < 8) {
810  // This is in RAX, copy from register to our result structure:
811  copy_from_extractor = &r3_data;
812  copy_from_offset = integer_bytes;
813  integer_bytes += field_byte_width;
814  } else {
815  copy_from_extractor = &rdx_data;
816  copy_from_offset = integer_bytes - 8;
817  integer_bytes += field_byte_width;
818  }
819  } else {
820  fp_bytes += field_byte_width;
821  }
822  }
823  }
824 
825  // These two tests are just sanity checks. If I somehow get the type
826  // calculation wrong above it is better to just return nothing than to
827  // assert or crash.
828  if (!copy_from_extractor)
829  return return_valobj_sp;
830  if (copy_from_offset + field_byte_width >
831  copy_from_extractor->GetByteSize())
832  return return_valobj_sp;
833 
834  copy_from_extractor->CopyByteOrderedData(
835  copy_from_offset, field_byte_width,
836  data_sp->GetBytes() + field_byte_offset, field_byte_width,
837  target_byte_order);
838  }
839 
840  if (!is_memory) {
841  // The result is in our data buffer. Let's make a variable object out
842  // of it:
843  return_valobj_sp = ValueObjectConstResult::Create(
844  &thread, return_compiler_type, ConstString(""), return_ext);
845  }
846  }
847 
848  // FIXME: This is just taking a guess, r3 may very well no longer hold the
849  // return storage location.
850  // If we are going to do this right, when we make a new frame we should
851  // check to see if it uses a memory return, and if we are at the first
852  // instruction and if so stash away the return location. Then we would
853  // only return the memory return value if we know it is valid.
854 
855  if (is_memory) {
856  unsigned r3_id =
857  reg_ctx_sp->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
858  lldb::addr_t storage_addr =
859  (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id,
860  0);
861  return_valobj_sp = ValueObjectMemory::Create(
862  &thread, "", Address(storage_addr, nullptr), return_compiler_type);
863  }
864  }
865 
866  return return_valobj_sp;
867 }
868 
870  unwind_plan.Clear();
871  unwind_plan.SetRegisterKind(eRegisterKindDWARF);
872 
873  uint32_t lr_reg_num = dwarf_lr;
874  uint32_t sp_reg_num = dwarf_r1;
875  uint32_t pc_reg_num = dwarf_pc;
876 
878 
879  // Our Call Frame Address is the stack pointer value
880  row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
881 
882  // The previous PC is in the LR
883  row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
884  unwind_plan.AppendRow(row);
885 
886  // All other registers are the same.
887 
888  unwind_plan.SetSourceName("ppc at-func-entry default");
889  unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
890 
891  return true;
892 }
893 
895  unwind_plan.Clear();
896  unwind_plan.SetRegisterKind(eRegisterKindDWARF);
897 
898  uint32_t sp_reg_num = dwarf_r1;
899  uint32_t pc_reg_num = dwarf_lr;
900 
902 
903  const int32_t ptr_size = 4;
904  row->GetCFAValue().SetIsRegisterDereferenced(sp_reg_num);
905 
906  row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * 1, true);
907  row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
908 
909  unwind_plan.AppendRow(row);
910  unwind_plan.SetSourceName("ppc default unwind plan");
911  unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
913  unwind_plan.SetReturnAddressRegister(dwarf_lr);
914  return true;
915 }
916 
917 bool ABISysV_ppc::RegisterIsVolatile(const RegisterInfo *reg_info) {
918  return !RegisterIsCalleeSaved(reg_info);
919 }
920 
921 // See "Register Usage" in the
922 // "System V Application Binary Interface"
923 // "64-bit PowerPC ELF Application Binary Interface Supplement" current version
924 // is 1.9 released 2004 at http://refspecs.linuxfoundation.org/ELF/ppc/PPC-
925 // elf64abi-1.9.pdf
926 
927 bool ABISysV_ppc::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {
928  if (reg_info) {
929  // Preserved registers are :
930  // r1,r2,r13-r31
931  // f14-f31 (not yet)
932  // v20-v31 (not yet)
933  // vrsave (not yet)
934 
935  const char *name = reg_info->name;
936  if (name[0] == 'r') {
937  if ((name[1] == '1' || name[1] == '2') && name[2] == '\0')
938  return true;
939  if (name[1] == '1' && name[2] > '2')
940  return true;
941  if ((name[1] == '2' || name[1] == '3') && name[2] != '\0')
942  return true;
943  }
944 
945  if (name[0] == 'f' && name[1] >= '0' && name[1] <= '9') {
946  if (name[3] == '1' && name[4] >= '4')
947  return true;
948  if ((name[3] == '2' || name[3] == '3') && name[4] != '\0')
949  return true;
950  }
951 
952  if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
953  return true;
954  if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
955  return true;
956  if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
957  return true;
958  }
959  return false;
960 }
961 
963  PluginManager::RegisterPlugin(GetPluginNameStatic(),
964  "System V ABI for ppc targets", CreateInstance);
965 }
966 
968  PluginManager::UnregisterPlugin(CreateInstance);
969 }
970 
972  static ConstString g_name("sysv-ppc");
973  return g_name;
974 }
975 
976 // PluginInterface protocol
977 
979  return GetPluginNameStatic();
980 }
981 
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
size_t GetRedZoneSize() const override
#define LLDB_REGNUM_GENERIC_PC
Definition: lldb-defines.h:63
An data extractor class.
Definition: DataExtractor.h:47
#define LLDB_REGNUM_GENERIC_ARG6
Definition: lldb-defines.h:78
void SetSourceName(const char *)
Definition: UnwindPlan.cpp:542
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
const ArchSpec & GetArchitecture() const
Definition: Target.h:941
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &type) const override
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:742
lldb_private::ConstString GetPluginName() override
static void Terminate()
#define LLDB_REGNUM_GENERIC_RA
Definition: lldb-defines.h:66
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
#define LLDB_REGNUM_GENERIC_ARG4
Definition: lldb-defines.h:74
uint32_t GetAsMemoryData(const RegisterInfo *reg_info, void *dst, uint32_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
bool IsIntegerOrEnumerationType(bool &is_signed) const
uint64_t GetSP(uint64_t fail_value=LLDB_INVALID_ADDRESS)
void PutString(llvm::StringRef str)
Definition: Log.cpp:110
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:49
An architecture specification class.
Definition: ArchSpec.h:32
#define LLDB_REGNUM_GENERIC_ARG2
Definition: lldb-defines.h:70
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
Value * GetValueAtIndex(size_t idx)
Definition: Value.cpp:701
void SetValueType(ValueType value_type)
Definition: Value.h:154
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:64
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
#define LLDB_REGNUM_GENERIC_ARG7
Definition: lldb-defines.h:80
llvm::Optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
#define LLDB_REGNUM_GENERIC_ARG5
Definition: lldb-defines.h:76
float GetFloat(lldb::offset_t *offset_ptr) const
Extract a float from *offset_ptr.
uint32_t GetNumFields() const
A subclass of DataBuffer that stores a data buffer on the heap.
#define LLDB_REGNUM_GENERIC_ARG1
Definition: lldb-defines.h:68
bool IsPointerType(CompilerType *pointee_type=nullptr) const
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:431
static const RegisterInfo g_register_infos[]
bool SignExtend(uint32_t bit_pos)
Definition: Scalar.cpp:2609
static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width, bool is_signed, Thread &thread, uint32_t *argument_register_ids, unsigned int &current_argument_register, addr_t &current_stack_argument)
#define UINT32_MAX
Definition: lldb-defines.h:31
bool IsFloatingPointType(uint32_t &count, bool &is_complex) const
const lldb_private::RegisterInfo * GetRegisterInfoArray(uint32_t &count) override
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info)
uint64_t offset_t
Definition: lldb-types.h:87
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:57
std::shared_ptr< Row > RowSP
Definition: UnwindPlan.h:366
void AppendRow(const RowSP &row_sp)
Definition: UnwindPlan.cpp:355
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
uint32_t GetPluginVersion() override
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
llvm::StringRef GetString() const
virtual lldb::RegisterContextSP GetRegisterContext()=0
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:788
double GetDouble(lldb::offset_t *offset_ptr) const
#define LLDB_REGNUM_GENERIC_FLAGS
Definition: lldb-defines.h:67
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
const CompilerType & GetCompilerType()
Definition: Value.cpp:239
static const uint32_t k_num_register_infos
void SetRegisterKind(lldb::RegisterKind kind)
Definition: UnwindPlan.h:408
#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4)
A section + offset based address class.
Definition: Address.h:80
bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval)
lldb::ProcessSP GetProcess() const
Definition: Thread.h:154
dwarf_regnums
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
static lldb_private::ConstString GetPluginNameStatic()
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
const RegisterInfo * GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num)
void SetUnwindPlanValidAtAllInstructions(lldb_private::LazyBool valid_at_all_insn)
Definition: UnwindPlan.h:461
lldb::offset_t CopyByteOrderedData(lldb::offset_t src_offset, lldb::offset_t src_len, void *dst, lldb::offset_t dst_len, lldb::ByteOrder dst_byte_order) const
Copy dst_len bytes from *offset_ptr and ensure the copied data is treated as a value that can be swap...
uint64_t addr_t
Definition: lldb-types.h:83
bool GetData(DataExtractor &data) const
bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t functionAddress, lldb::addr_t returnAddress, llvm::ArrayRef< lldb::addr_t > args) const override
A uniqued constant string class.
Definition: ConstString.h:38
bool Fail() const
Test for error condition.
Definition: Status.cpp:181
#define LLDB_REGNUM_GENERIC_ARG8
Definition: lldb-defines.h:82
lldb::ValueObjectSP GetReturnValueObjectSimple(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const
llvm::Optional< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
#define LLDB_REGNUM_GENERIC_ARG3
Definition: lldb-defines.h:72
Definition: SBAddress.h:15
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:255
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:268
#define LIBLLDB_LOG_EXPRESSIONS
Definition: Logging.h:22
const Scalar & GetScalar() const
Definition: Value.h:178
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:130
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:395
void Printf(const char *format,...) __attribute__((format(printf
Definition: Log.cpp:113
void SetSourcedFromCompiler(lldb_private::LazyBool from_compiler)
Definition: UnwindPlan.h:449
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
void SetReturnAddressRegister(uint32_t regnum)
Definition: UnwindPlan.h:410
static void Initialize()
An error handling class.
Definition: Status.h:44
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:90