LLDB mainline
ABISysV_ppc.cpp
Go to the documentation of this file.
1//===-- ABISysV_ppc.cpp ---------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "ABISysV_ppc.h"
10
11#include "llvm/ADT/STLExtras.h"
12#include "llvm/TargetParser/Triple.h"
13
14#include "lldb/Core/Module.h"
16#include "lldb/Core/Value.h"
18#include "lldb/Target/Process.h"
21#include "lldb/Target/Target.h"
22#include "lldb/Target/Thread.h"
26#include "lldb/Utility/Log.h"
28#include "lldb/Utility/Status.h"
32#include <optional>
33
34using namespace lldb;
35using namespace lldb_private;
36
38
112
113// Note that the size and offset will be updated by platform-specific classes.
114#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4) \
115 { \
116 #reg, alt, 8, 0, eEncodingUint, eFormatHex, {kind1, kind2, kind3, kind4 }, \
117 nullptr, nullptr, nullptr, \
118 }
119
121 // General purpose registers. eh_frame, DWARF,
122 // Generic, Process Plugin
197 {nullptr,
198 nullptr,
199 8,
200 0,
204 nullptr,
205 nullptr,
206 nullptr,
207 }};
208
209static const uint32_t k_num_register_infos = std::size(g_register_infos);
210
213 count = k_num_register_infos;
214 return g_register_infos;
215}
216
217size_t ABISysV_ppc::GetRedZoneSize() const { return 224; }
218
219// Static Functions
220
221ABISP
223 if (arch.GetTriple().getArch() == llvm::Triple::ppc) {
224 return ABISP(
225 new ABISysV_ppc(std::move(process_sp), MakeMCRegisterInfo(arch)));
226 }
227 return ABISP();
228}
229
231 addr_t func_addr, addr_t return_addr,
232 llvm::ArrayRef<addr_t> args) const {
234
235 if (log) {
236 StreamString s;
237 s.Printf("ABISysV_ppc::PrepareTrivialCall (tid = 0x%" PRIx64
238 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
239 ", return_addr = 0x%" PRIx64,
240 thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
241 (uint64_t)return_addr);
242
243 for (size_t i = 0; i < args.size(); ++i)
244 s.Printf(", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1),
245 args[i]);
246 s.PutCString(")");
247 log->PutString(s.GetString());
248 }
249
250 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
251 if (!reg_ctx)
252 return false;
253
254 const RegisterInfo *reg_info = nullptr;
255
256 if (args.size() > 8) // TODO handle more than 8 arguments
257 return false;
258
259 for (size_t i = 0; i < args.size(); ++i) {
260 reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
262 LLDB_LOGF(log, "About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s",
263 static_cast<uint64_t>(i + 1), args[i], reg_info->name);
264 if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
265 return false;
266 }
267
268 // First, align the SP
269
270 LLDB_LOGF(log, "16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64,
271 (uint64_t)sp, (uint64_t)(sp & ~0xfull));
272
273 sp &= ~(0xfull); // 16-byte alignment
274
275 sp -= 8;
276
278 const RegisterInfo *pc_reg_info =
280 const RegisterInfo *sp_reg_info =
282 ProcessSP process_sp(thread.GetProcess());
283
284 RegisterValue reg_value;
285
286 LLDB_LOGF(log,
287 "Pushing the return address onto the stack: 0x%" PRIx64
288 ": 0x%" PRIx64,
289 (uint64_t)sp, (uint64_t)return_addr);
290
291 // Save return address onto the stack
292 if (!process_sp->WritePointerToMemory(sp, return_addr, error))
293 return false;
294
295 // %r1 is set to the actual stack value.
296
297 LLDB_LOGF(log, "Writing SP: 0x%" PRIx64, (uint64_t)sp);
298
299 if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
300 return false;
301
302 // %pc is set to the address of the called function.
303
304 LLDB_LOGF(log, "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
312static 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;
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
339bool 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] =
365 argument_register_ids[1] =
368 argument_register_ids[2] =
371 argument_register_ids[3] =
374 argument_register_ids[4] =
377 argument_register_ids[5] =
380 argument_register_ids[6] =
383 argument_register_ids[7] =
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 std::optional<uint64_t> bit_size =
399 llvm::expectedToOptional(compiler_type.GetBitSize(&thread));
400 if (!bit_size)
401 return false;
402 bool is_signed;
403 if (compiler_type.IsIntegerOrEnumerationType(is_signed))
404 ReadIntegerArgument(value->GetScalar(), *bit_size, is_signed, thread,
405 argument_register_ids, current_argument_register,
406 current_stack_argument);
407 else if (compiler_type.IsPointerType())
408 ReadIntegerArgument(value->GetScalar(), *bit_size, false, thread,
409 argument_register_ids, current_argument_register,
410 current_stack_argument);
411 }
412
413 return true;
414}
415
417 lldb::ValueObjectSP &new_value_sp) {
419 if (!new_value_sp)
420 return Status::FromErrorString("Empty value object for return value.");
421
422 CompilerType compiler_type = new_value_sp->GetCompilerType();
423 if (!compiler_type)
424 return Status::FromErrorString("Null clang type for return value.");
425
426 Thread *thread = frame_sp->GetThread().get();
427
428 bool is_signed;
429
430 RegisterContext *reg_ctx = thread->GetRegisterContext().get();
431
432 bool set_it_simple = false;
433 if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
434 compiler_type.IsPointerType()) {
435 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
436
437 DataExtractor data;
438 Status data_error;
439 size_t num_bytes = new_value_sp->GetData(data, data_error);
440 if (data_error.Fail())
442 "Couldn't convert return value to raw data: %s",
443 data_error.AsCString());
444 lldb::offset_t offset = 0;
445 if (num_bytes <= 8) {
446 uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
447
448 if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
449 set_it_simple = true;
450 } else {
452 "We don't support returning longer than 64 bit "
453 "integer values at present.");
454 }
455 } else if (compiler_type.IsRealFloatingPointType()) {
456 std::optional<uint64_t> bit_width =
457 llvm::expectedToOptional(compiler_type.GetBitSize(frame_sp.get()));
458 if (!bit_width) {
459 error = Status::FromErrorString("can't get type size");
460 return error;
461 }
462 if (*bit_width <= 64) {
463 DataExtractor data;
464 Status data_error;
465 size_t num_bytes = new_value_sp->GetData(data, data_error);
466 if (data_error.Fail()) {
468 "Couldn't convert return value to raw data: %s",
469 data_error.AsCString());
470 return error;
471 }
472
473 unsigned char buffer[16];
474 ByteOrder byte_order = data.GetByteOrder();
475
476 data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
477 set_it_simple = true;
478 } else {
479 // FIXME - don't know how to do 80 bit long doubles yet.
481 "We don't support returning float values > 64 bits at present");
482 }
483 }
484
485 if (!set_it_simple) {
486 // Okay we've got a structure or something that doesn't fit in a simple
487 // register. We should figure out where it really goes, but we don't
488 // support this yet.
490 "We only support setting simple integer and float "
491 "return types at present.");
492 }
493
494 return error;
495}
496
498 Thread &thread, CompilerType &return_compiler_type) const {
499 ValueObjectSP return_valobj_sp;
500 Value value;
501
502 if (!return_compiler_type)
503 return return_valobj_sp;
504
505 // value.SetContext (Value::eContextTypeClangType, return_value_type);
506 value.SetCompilerType(return_compiler_type);
507
508 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
509 if (!reg_ctx)
510 return return_valobj_sp;
511
512 const uint32_t type_flags = return_compiler_type.GetTypeInfo();
513 if (type_flags & eTypeIsScalar) {
515
516 bool success = false;
517 if (type_flags & eTypeIsInteger) {
518 // Extract the register context so we can read arguments from registers
519
520 std::optional<uint64_t> byte_size =
521 llvm::expectedToOptional(return_compiler_type.GetByteSize(&thread));
522 if (!byte_size)
523 return return_valobj_sp;
524 uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
525 reg_ctx->GetRegisterInfoByName("r3", 0), 0);
526 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
527 switch (*byte_size) {
528 default:
529 break;
530
531 case sizeof(uint64_t):
532 if (is_signed)
533 value.GetScalar() = (int64_t)(raw_value);
534 else
535 value.GetScalar() = (uint64_t)(raw_value);
536 success = true;
537 break;
538
539 case sizeof(uint32_t):
540 if (is_signed)
541 value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
542 else
543 value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
544 success = true;
545 break;
546
547 case sizeof(uint16_t):
548 if (is_signed)
549 value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
550 else
551 value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
552 success = true;
553 break;
554
555 case sizeof(uint8_t):
556 if (is_signed)
557 value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
558 else
559 value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
560 success = true;
561 break;
562 }
563 } else if (type_flags & eTypeIsFloat) {
564 if (type_flags & eTypeIsComplex) {
565 // Don't handle complex yet.
566 } else {
567 std::optional<uint64_t> byte_size =
568 llvm::expectedToOptional(return_compiler_type.GetByteSize(&thread));
569 if (byte_size && *byte_size <= sizeof(long double)) {
570 const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
571 RegisterValue f1_value;
572 if (reg_ctx->ReadRegister(f1_info, f1_value)) {
573 DataExtractor data;
574 if (f1_value.GetData(data)) {
575 lldb::offset_t offset = 0;
576 if (*byte_size == sizeof(float)) {
577 value.GetScalar() = (float)data.GetFloat(&offset);
578 success = true;
579 } else if (*byte_size == sizeof(double)) {
580 value.GetScalar() = (double)data.GetDouble(&offset);
581 success = true;
582 }
583 }
584 }
585 }
586 }
587 }
588
589 if (success)
590 return_valobj_sp = ValueObjectConstResult::Create(
591 thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
592 } else if (type_flags & eTypeIsPointer) {
593 unsigned r3_id =
595 value.GetScalar() =
596 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 0);
598 return_valobj_sp = ValueObjectConstResult::Create(
599 thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
600 } else if (type_flags & eTypeIsVector) {
601 std::optional<uint64_t> byte_size =
602 llvm::expectedToOptional(return_compiler_type.GetByteSize(&thread));
603 if (byte_size && *byte_size > 0) {
604 const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("v2", 0);
605 if (altivec_reg) {
606 if (*byte_size <= altivec_reg->byte_size) {
607 ProcessSP process_sp(thread.GetProcess());
608 if (process_sp) {
609 std::unique_ptr<DataBufferHeap> heap_data_up(
610 new DataBufferHeap(*byte_size, 0));
611 const ByteOrder byte_order = process_sp->GetByteOrder();
612 RegisterValue reg_value;
613 if (reg_ctx->ReadRegister(altivec_reg, reg_value)) {
615 if (reg_value.GetAsMemoryData(
616 *altivec_reg, heap_data_up->GetBytes(),
617 heap_data_up->GetByteSize(), byte_order, error)) {
618 DataExtractor data(DataBufferSP(heap_data_up.release()),
619 byte_order,
620 process_sp->GetTarget()
621 .GetArchitecture()
622 .GetAddressByteSize());
623 return_valobj_sp = ValueObjectConstResult::Create(
624 &thread, return_compiler_type, ConstString(""), data);
625 }
626 }
627 }
628 }
629 }
630 }
631 }
632
633 return return_valobj_sp;
634}
635
637 Thread &thread, CompilerType &return_compiler_type) const {
638 ValueObjectSP return_valobj_sp;
639
640 if (!return_compiler_type)
641 return return_valobj_sp;
642
643 ExecutionContext exe_ctx(thread.shared_from_this());
644 return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
645 if (return_valobj_sp)
646 return return_valobj_sp;
647
648 RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
649 if (!reg_ctx_sp)
650 return return_valobj_sp;
651
652 std::optional<uint64_t> bit_width =
653 llvm::expectedToOptional(return_compiler_type.GetBitSize(&thread));
654 if (!bit_width)
655 return return_valobj_sp;
656 if (return_compiler_type.IsAggregateType()) {
657 Target *target = exe_ctx.GetTargetPtr();
658 bool is_memory = true;
659 if (*bit_width <= 128) {
660 ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
661 WritableDataBufferSP data_sp(new DataBufferHeap(16, 0));
662 DataExtractor return_ext(data_sp, target_byte_order,
664
665 const RegisterInfo *r3_info = reg_ctx_sp->GetRegisterInfoByName("r3", 0);
666 const RegisterInfo *rdx_info =
667 reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
668
669 RegisterValue r3_value, rdx_value;
670 reg_ctx_sp->ReadRegister(r3_info, r3_value);
671 reg_ctx_sp->ReadRegister(rdx_info, rdx_value);
672
673 DataExtractor r3_data, rdx_data;
674
675 r3_value.GetData(r3_data);
676 rdx_value.GetData(rdx_data);
677
678 uint32_t integer_bytes =
679 0; // Tracks how much of the r3/rds registers we've consumed so far
680
681 const uint32_t num_children = return_compiler_type.GetNumFields();
682
683 // Since we are in the small struct regime, assume we are not in memory.
684 is_memory = false;
685
686 for (uint32_t idx = 0; idx < num_children; idx++) {
687 std::string name;
688 uint64_t field_bit_offset = 0;
689 bool is_signed;
690
691 CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(
692 idx, name, &field_bit_offset, nullptr, nullptr);
693 std::optional<uint64_t> field_bit_width =
694 llvm::expectedToOptional(field_compiler_type.GetBitSize(&thread));
695 if (!field_bit_width)
696 return return_valobj_sp;
697
698 // If there are any unaligned fields, this is stored in memory.
699 if (field_bit_offset % *field_bit_width != 0) {
700 is_memory = true;
701 break;
702 }
703
704 uint32_t field_byte_width = *field_bit_width / 8;
705 uint32_t field_byte_offset = field_bit_offset / 8;
706
707 DataExtractor *copy_from_extractor = nullptr;
708 uint32_t copy_from_offset = 0;
709
710 if (field_compiler_type.IsIntegerOrEnumerationType(is_signed) ||
711 field_compiler_type.IsPointerType()) {
712 if (integer_bytes < 8) {
713 if (integer_bytes + field_byte_width <= 8) {
714 // This is in RAX, copy from register to our result structure:
715 copy_from_extractor = &r3_data;
716 copy_from_offset = integer_bytes;
717 integer_bytes += field_byte_width;
718 } else {
719 // The next field wouldn't fit in the remaining space, so we
720 // pushed it to rdx.
721 copy_from_extractor = &rdx_data;
722 copy_from_offset = 0;
723 integer_bytes = 8 + field_byte_width;
724 }
725 } else if (integer_bytes + field_byte_width <= 16) {
726 copy_from_extractor = &rdx_data;
727 copy_from_offset = integer_bytes - 8;
728 integer_bytes += field_byte_width;
729 } else {
730 // The last field didn't fit. I can't see how that would happen
731 // w/o the overall size being greater than 16 bytes. For now,
732 // return a nullptr return value object.
733 return return_valobj_sp;
734 }
735 } else if (field_compiler_type.GetTypeInfo() & eTypeIsFloat) {
736 // Structs with long doubles are always passed in memory.
737 if (*field_bit_width == 128) {
738 is_memory = true;
739 break;
740 } else if (*field_bit_width == 64) {
741 copy_from_offset = 0;
742 } else if (*field_bit_width == 32) {
743 // This one is kind of complicated. If we are in an "eightbyte"
744 // with another float, we'll be stuffed into an xmm register with
745 // it. If we are in an "eightbyte" with one or more ints, then we
746 // will be stuffed into the appropriate GPR with them.
747 bool in_gpr;
748 if (field_byte_offset % 8 == 0) {
749 // We are at the beginning of one of the eightbytes, so check the
750 // next element (if any)
751 if (idx == num_children - 1)
752 in_gpr = false;
753 else {
754 uint64_t next_field_bit_offset = 0;
755 CompilerType next_field_compiler_type =
756 return_compiler_type.GetFieldAtIndex(idx + 1, name,
757 &next_field_bit_offset,
758 nullptr, nullptr);
759 if (next_field_compiler_type.IsIntegerOrEnumerationType(
760 is_signed))
761 in_gpr = true;
762 else {
763 copy_from_offset = 0;
764 in_gpr = false;
765 }
766 }
767 } else if (field_byte_offset % 4 == 0) {
768 // We are inside of an eightbyte, so see if the field before us
769 // is floating point: This could happen if somebody put padding
770 // in the structure.
771 if (idx == 0)
772 in_gpr = false;
773 else {
774 uint64_t prev_field_bit_offset = 0;
775 CompilerType prev_field_compiler_type =
776 return_compiler_type.GetFieldAtIndex(idx - 1, name,
777 &prev_field_bit_offset,
778 nullptr, nullptr);
779 if (prev_field_compiler_type.IsIntegerOrEnumerationType(
780 is_signed))
781 in_gpr = true;
782 else {
783 copy_from_offset = 4;
784 in_gpr = false;
785 }
786 }
787 } else {
788 is_memory = true;
789 continue;
790 }
791
792 // Okay, we've figured out whether we are in GPR or XMM, now figure
793 // out which one.
794 if (in_gpr) {
795 if (integer_bytes < 8) {
796 // This is in RAX, copy from register to our result structure:
797 copy_from_extractor = &r3_data;
798 copy_from_offset = integer_bytes;
799 integer_bytes += field_byte_width;
800 } else {
801 copy_from_extractor = &rdx_data;
802 copy_from_offset = integer_bytes - 8;
803 integer_bytes += field_byte_width;
804 }
805 }
806 }
807 }
808
809 // These two tests are just sanity checks. If I somehow get the type
810 // calculation wrong above it is better to just return nothing than to
811 // assert or crash.
812 if (!copy_from_extractor)
813 return return_valobj_sp;
814 if (copy_from_offset + field_byte_width >
815 copy_from_extractor->GetByteSize())
816 return return_valobj_sp;
817
818 copy_from_extractor->CopyByteOrderedData(
819 copy_from_offset, field_byte_width,
820 data_sp->GetBytes() + field_byte_offset, field_byte_width,
821 target_byte_order);
822 }
823
824 if (!is_memory) {
825 // The result is in our data buffer. Let's make a variable object out
826 // of it:
827 return_valobj_sp = ValueObjectConstResult::Create(
828 &thread, return_compiler_type, ConstString(""), return_ext);
829 }
830 }
831
832 // FIXME: This is just taking a guess, r3 may very well no longer hold the
833 // return storage location.
834 // If we are going to do this right, when we make a new frame we should
835 // check to see if it uses a memory return, and if we are at the first
836 // instruction and if so stash away the return location. Then we would
837 // only return the memory return value if we know it is valid.
838
839 if (is_memory) {
840 unsigned r3_id =
841 reg_ctx_sp->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
842 lldb::addr_t storage_addr =
843 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id,
844 0);
845 return_valobj_sp = ValueObjectMemory::Create(
846 &thread, "", Address(storage_addr, nullptr), return_compiler_type);
847 }
848 }
849
850 return return_valobj_sp;
851}
852
854 uint32_t lr_reg_num = dwarf_lr;
855 uint32_t sp_reg_num = dwarf_r1;
856 uint32_t pc_reg_num = dwarf_pc;
857
858 UnwindPlan::Row row;
859
860 // Our Call Frame Address is the stack pointer value
861 row.GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
862
863 // The previous PC is in the LR, all other registers are the same.
864 row.SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
865
866 auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF);
867 plan_sp->AppendRow(std::move(row));
868 plan_sp->SetSourceName("ppc at-func-entry default");
869 plan_sp->SetSourcedFromCompiler(eLazyBoolNo);
870 return plan_sp;
871}
872
874
875 uint32_t sp_reg_num = dwarf_r1;
876 uint32_t pc_reg_num = dwarf_lr;
877
878 UnwindPlan::Row row;
879
880 const int32_t ptr_size = 4;
882 row.GetCFAValue().SetIsRegisterDereferenced(sp_reg_num);
883
884 row.SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * 1, true);
885 row.SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
886
887 auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF);
888 plan_sp->AppendRow(std::move(row));
889 plan_sp->SetSourceName("ppc default unwind plan");
890 plan_sp->SetSourcedFromCompiler(eLazyBoolNo);
891 plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
892 plan_sp->SetUnwindPlanForSignalTrap(eLazyBoolNo);
893 plan_sp->SetReturnAddressRegister(dwarf_lr);
894 return plan_sp;
895}
896
898 return !RegisterIsCalleeSaved(reg_info);
899}
900
901// See "Register Usage" in the
902// "System V Application Binary Interface"
903// "64-bit PowerPC ELF Application Binary Interface Supplement" current version
904// is 1.9 released 2004 at http://refspecs.linuxfoundation.org/ELF/ppc/PPC-
905// elf64abi-1.9.pdf
906
908 if (reg_info) {
909 // Preserved registers are :
910 // r1,r2,r13-r31
911 // f14-f31 (not yet)
912 // v20-v31 (not yet)
913 // vrsave (not yet)
914
915 const char *name = reg_info->name;
916 if (name[0] == 'r') {
917 if ((name[1] == '1' || name[1] == '2') && name[2] == '\0')
918 return true;
919 if (name[1] == '1' && name[2] > '2')
920 return true;
921 if ((name[1] == '2' || name[1] == '3') && name[2] != '\0')
922 return true;
923 }
924
925 if (name[0] == 'f' && name[1] >= '0' && name[1] <= '9') {
926 if (name[3] == '1' && name[4] >= '4')
927 return true;
928 if ((name[3] == '2' || name[3] == '3') && name[4] != '\0')
929 return true;
930 }
931
932 if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
933 return true;
934 if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
935 return true;
936 if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
937 return true;
938 }
939 return false;
940}
941
944 "System V ABI for ppc targets", CreateInstance);
945}
946
static const uint32_t k_num_register_infos
static const RegisterInfo g_register_infos[]
dwarf_regnums
@ dwarf_r7
@ dwarf_r21
@ dwarf_r24
@ dwarf_r12
@ dwarf_r3
@ dwarf_r13
@ dwarf_r2
@ dwarf_r8
@ dwarf_r28
@ dwarf_r11
@ dwarf_r31
@ dwarf_r19
@ dwarf_r1
@ dwarf_r26
@ dwarf_r9
@ dwarf_pc
@ dwarf_r29
@ dwarf_r16
@ dwarf_r18
@ dwarf_r17
@ dwarf_r15
@ dwarf_r23
@ dwarf_r10
@ dwarf_r14
@ dwarf_r6
@ dwarf_r25
@ dwarf_r30
@ dwarf_r0
@ dwarf_r5
@ dwarf_r20
@ dwarf_r27
@ dwarf_r4
@ dwarf_r22
@ dwarf_f12
@ dwarf_f27
@ dwarf_f17
@ dwarf_f9
@ dwarf_f28
@ dwarf_f19
@ dwarf_f11
@ dwarf_cr
@ dwarf_f31
@ dwarf_f16
@ dwarf_f22
@ dwarf_f26
@ dwarf_f10
@ dwarf_f23
@ dwarf_f6
@ dwarf_f5
@ dwarf_f2
@ dwarf_f0
@ dwarf_f7
@ dwarf_lr
@ dwarf_xer
@ dwarf_f15
@ dwarf_f14
@ dwarf_f30
@ dwarf_f24
@ dwarf_f1
@ dwarf_f18
@ dwarf_f25
@ dwarf_ctr
@ dwarf_f3
@ dwarf_f21
@ dwarf_fpscr
@ dwarf_f13
@ dwarf_f29
@ dwarf_cfa
@ dwarf_f20
@ dwarf_f8
@ dwarf_f4
#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4)
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)
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_PLUGIN_DEFINE(PluginName)
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
const lldb_private::RegisterInfo * GetRegisterInfoArray(uint32_t &count) override
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &type) const override
lldb::UnwindPlanSP CreateDefaultUnwindPlan() override
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
static llvm::StringRef GetPluginNameStatic()
Definition ABISysV_ppc.h:80
static void Terminate()
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
static void Initialize()
bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info)
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
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
lldb::ValueObjectSP GetReturnValueObjectSimple(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const
size_t GetRedZoneSize() const override
lldb::UnwindPlanSP CreateFunctionEntryUnwindPlan() override
static std::unique_ptr< llvm::MCRegisterInfo > MakeMCRegisterInfo(const ArchSpec &arch)
Utility function to construct a MCRegisterInfo using the ArchSpec triple.
Definition ABI.cpp:225
A section + offset based address class.
Definition Address.h:62
An architecture specification class.
Definition ArchSpec.h:32
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:681
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:457
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition ArchSpec.cpp:730
Generic representation of a type in a programming language.
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
uint32_t GetNumFields() const
bool IsIntegerOrEnumerationType(bool &is_signed) const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
bool IsRealFloatingPointType() const
Returns true for non-complex float types.
llvm::Expected< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
Definition ConstString.h:40
A subclass of DataBuffer that stores a data buffer on the heap.
An data extractor class.
float GetFloat(lldb::offset_t *offset_ptr) const
Extract a float from *offset_ptr.
virtual uint64_t GetByteSize() const
Get the number of bytes contained in this object.
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
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...
double GetDouble(lldb::offset_t *offset_ptr) const
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Target * GetTargetPtr() const
Returns a pointer to the target object.
void PutString(llvm::StringRef str)
Definition Log.cpp:147
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
uint64_t GetSP(uint64_t fail_value=LLDB_INVALID_ADDRESS)
const RegisterInfo * GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num)
bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval)
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
bool GetData(DataExtractor &data) const
uint32_t GetAsMemoryData(const RegisterInfo &reg_info, void *dst, uint32_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
bool SignExtend(uint32_t bit_pos)
Definition Scalar.cpp:762
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Fail() const
Test for error condition.
Definition Status.cpp:293
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
const ArchSpec & GetArchitecture() const
Definition Target.h:1183
void SetIsRegisterDereferenced(uint32_t reg_num)
Definition UnwindPlan.h:250
void SetIsRegisterPlusOffset(uint32_t reg_num, int32_t offset)
Definition UnwindPlan.h:240
bool SetRegisterLocationToIsCFAPlusOffset(uint32_t reg_num, int32_t offset, bool can_replace)
bool SetRegisterLocationToAtCFAPlusOffset(uint32_t reg_num, int32_t offset, bool can_replace)
const FAValue & GetCFAValue() const
Definition UnwindPlan.h:365
bool SetRegisterLocationToRegister(uint32_t reg_num, uint32_t other_reg_num, bool can_replace)
void SetUnspecifiedRegistersAreUndefined(bool unspec_is_undef)
Definition UnwindPlan.h:408
Value * GetValueAtIndex(size_t idx)
Definition Value.cpp:698
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, llvm::StringRef name, const Address &address, lldb::TypeSP &type_sp)
const Scalar & GetScalar() const
See comment on m_scalar to understand what GetScalar returns.
Definition Value.h:113
@ Scalar
A raw scalar value.
Definition Value.h:45
void SetCompilerType(const CompilerType &compiler_type)
Definition Value.cpp:276
void SetValueType(ValueType value_type)
Definition Value.h:89
const CompilerType & GetCompilerType()
Definition Value.cpp:247
#define LLDB_REGNUM_GENERIC_RA
#define LLDB_REGNUM_GENERIC_ARG8
#define LLDB_REGNUM_GENERIC_ARG6
#define LLDB_REGNUM_GENERIC_SP
#define LLDB_REGNUM_GENERIC_ARG4
#define LLDB_REGNUM_GENERIC_ARG3
#define LLDB_REGNUM_GENERIC_ARG1
#define LLDB_REGNUM_GENERIC_ARG7
#define LLDB_REGNUM_GENERIC_FLAGS
#define UINT32_MAX
#define LLDB_INVALID_REGNUM
#define LLDB_REGNUM_GENERIC_ARG2
#define LLDB_REGNUM_GENERIC_PC
#define LLDB_REGNUM_GENERIC_ARG5
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
@ eEncodingUint
unsigned integer
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindLLDB
lldb's internal register numbers
@ eRegisterKindDWARF
the register numbers seen DWARF
Every register is described in detail including its name, alternate name (optional),...
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.
const char * name
Name of this register, can't be NULL.