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
107 dwarf_lr = 108,
111};
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 {
233 Log *log = GetLog(LLDBLog::Expressions);
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 = 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
416 lldb::ValueObjectSP &new_value_sp) {
418 if (!new_value_sp)
419 return Status::FromErrorString("Empty value object for return value.");
420
421 CompilerType compiler_type = new_value_sp->GetCompilerType();
422 if (!compiler_type)
423 return Status::FromErrorString("Null clang type for return value.");
424
425 Thread *thread = frame_sp->GetThread().get();
426
427 bool is_signed;
428 uint32_t count;
429 bool is_complex;
430
431 RegisterContext *reg_ctx = thread->GetRegisterContext().get();
432
433 bool set_it_simple = false;
434 if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
435 compiler_type.IsPointerType()) {
436 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
437
438 DataExtractor data;
439 Status data_error;
440 size_t num_bytes = new_value_sp->GetData(data, data_error);
441 if (data_error.Fail())
443 "Couldn't convert return value to raw data: %s",
444 data_error.AsCString());
445 lldb::offset_t offset = 0;
446 if (num_bytes <= 8) {
447 uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
448
449 if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
450 set_it_simple = true;
451 } else {
453 "We don't support returning longer than 64 bit "
454 "integer values at present.");
455 }
456 } else if (compiler_type.IsFloatingPointType(count, is_complex)) {
457 if (is_complex)
459 "We don't support returning complex values at present");
460 else {
461 std::optional<uint64_t> bit_width =
462 compiler_type.GetBitSize(frame_sp.get());
463 if (!bit_width) {
464 error = Status::FromErrorString("can't get type size");
465 return error;
466 }
467 if (*bit_width <= 64) {
468 DataExtractor data;
469 Status data_error;
470 size_t num_bytes = new_value_sp->GetData(data, data_error);
471 if (data_error.Fail()) {
473 "Couldn't convert return value to raw data: %s",
474 data_error.AsCString());
475 return error;
476 }
477
478 unsigned char buffer[16];
479 ByteOrder byte_order = data.GetByteOrder();
480
481 data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
482 set_it_simple = true;
483 } else {
484 // FIXME - don't know how to do 80 bit long doubles yet.
486 "We don't support returning float values > 64 bits at present");
487 }
488 }
489 }
490
491 if (!set_it_simple) {
492 // Okay we've got a structure or something that doesn't fit in a simple
493 // register. We should figure out where it really goes, but we don't
494 // support this yet.
496 "We only support setting simple integer and float "
497 "return types at present.");
498 }
499
500 return error;
501}
502
504 Thread &thread, CompilerType &return_compiler_type) const {
505 ValueObjectSP return_valobj_sp;
506 Value value;
507
508 if (!return_compiler_type)
509 return return_valobj_sp;
510
511 // value.SetContext (Value::eContextTypeClangType, return_value_type);
512 value.SetCompilerType(return_compiler_type);
513
514 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
515 if (!reg_ctx)
516 return return_valobj_sp;
517
518 const uint32_t type_flags = return_compiler_type.GetTypeInfo();
519 if (type_flags & eTypeIsScalar) {
520 value.SetValueType(Value::ValueType::Scalar);
521
522 bool success = false;
523 if (type_flags & eTypeIsInteger) {
524 // Extract the register context so we can read arguments from registers
525
526 std::optional<uint64_t> byte_size =
527 return_compiler_type.GetByteSize(&thread);
528 if (!byte_size)
529 return return_valobj_sp;
530 uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
531 reg_ctx->GetRegisterInfoByName("r3", 0), 0);
532 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
533 switch (*byte_size) {
534 default:
535 break;
536
537 case sizeof(uint64_t):
538 if (is_signed)
539 value.GetScalar() = (int64_t)(raw_value);
540 else
541 value.GetScalar() = (uint64_t)(raw_value);
542 success = true;
543 break;
544
545 case sizeof(uint32_t):
546 if (is_signed)
547 value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
548 else
549 value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
550 success = true;
551 break;
552
553 case sizeof(uint16_t):
554 if (is_signed)
555 value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
556 else
557 value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
558 success = true;
559 break;
560
561 case sizeof(uint8_t):
562 if (is_signed)
563 value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
564 else
565 value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
566 success = true;
567 break;
568 }
569 } else if (type_flags & eTypeIsFloat) {
570 if (type_flags & eTypeIsComplex) {
571 // Don't handle complex yet.
572 } else {
573 std::optional<uint64_t> byte_size =
574 return_compiler_type.GetByteSize(&thread);
575 if (byte_size && *byte_size <= sizeof(long double)) {
576 const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
577 RegisterValue f1_value;
578 if (reg_ctx->ReadRegister(f1_info, f1_value)) {
579 DataExtractor data;
580 if (f1_value.GetData(data)) {
581 lldb::offset_t offset = 0;
582 if (*byte_size == sizeof(float)) {
583 value.GetScalar() = (float)data.GetFloat(&offset);
584 success = true;
585 } else if (*byte_size == sizeof(double)) {
586 value.GetScalar() = (double)data.GetDouble(&offset);
587 success = true;
588 }
589 }
590 }
591 }
592 }
593 }
594
595 if (success)
596 return_valobj_sp = ValueObjectConstResult::Create(
597 thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
598 } else if (type_flags & eTypeIsPointer) {
599 unsigned r3_id =
601 value.GetScalar() =
602 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 0);
603 value.SetValueType(Value::ValueType::Scalar);
604 return_valobj_sp = ValueObjectConstResult::Create(
605 thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
606 } else if (type_flags & eTypeIsVector) {
607 std::optional<uint64_t> byte_size =
608 return_compiler_type.GetByteSize(&thread);
609 if (byte_size && *byte_size > 0) {
610 const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("v2", 0);
611 if (altivec_reg) {
612 if (*byte_size <= altivec_reg->byte_size) {
613 ProcessSP process_sp(thread.GetProcess());
614 if (process_sp) {
615 std::unique_ptr<DataBufferHeap> heap_data_up(
616 new DataBufferHeap(*byte_size, 0));
617 const ByteOrder byte_order = process_sp->GetByteOrder();
618 RegisterValue reg_value;
619 if (reg_ctx->ReadRegister(altivec_reg, reg_value)) {
621 if (reg_value.GetAsMemoryData(
622 *altivec_reg, heap_data_up->GetBytes(),
623 heap_data_up->GetByteSize(), byte_order, error)) {
624 DataExtractor data(DataBufferSP(heap_data_up.release()),
625 byte_order,
626 process_sp->GetTarget()
627 .GetArchitecture()
628 .GetAddressByteSize());
629 return_valobj_sp = ValueObjectConstResult::Create(
630 &thread, return_compiler_type, ConstString(""), data);
631 }
632 }
633 }
634 }
635 }
636 }
637 }
638
639 return return_valobj_sp;
640}
641
643 Thread &thread, CompilerType &return_compiler_type) const {
644 ValueObjectSP return_valobj_sp;
645
646 if (!return_compiler_type)
647 return return_valobj_sp;
648
649 ExecutionContext exe_ctx(thread.shared_from_this());
650 return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
651 if (return_valobj_sp)
652 return return_valobj_sp;
653
654 RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
655 if (!reg_ctx_sp)
656 return return_valobj_sp;
657
658 std::optional<uint64_t> bit_width = return_compiler_type.GetBitSize(&thread);
659 if (!bit_width)
660 return return_valobj_sp;
661 if (return_compiler_type.IsAggregateType()) {
662 Target *target = exe_ctx.GetTargetPtr();
663 bool is_memory = true;
664 if (*bit_width <= 128) {
665 ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
666 WritableDataBufferSP data_sp(new DataBufferHeap(16, 0));
667 DataExtractor return_ext(data_sp, target_byte_order,
669
670 const RegisterInfo *r3_info = reg_ctx_sp->GetRegisterInfoByName("r3", 0);
671 const RegisterInfo *rdx_info =
672 reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
673
674 RegisterValue r3_value, rdx_value;
675 reg_ctx_sp->ReadRegister(r3_info, r3_value);
676 reg_ctx_sp->ReadRegister(rdx_info, rdx_value);
677
678 DataExtractor r3_data, rdx_data;
679
680 r3_value.GetData(r3_data);
681 rdx_value.GetData(rdx_data);
682
683 uint32_t integer_bytes =
684 0; // Tracks how much of the r3/rds registers we've consumed so far
685
686 const uint32_t num_children = return_compiler_type.GetNumFields();
687
688 // Since we are in the small struct regime, assume we are not in memory.
689 is_memory = false;
690
691 for (uint32_t idx = 0; idx < num_children; idx++) {
692 std::string name;
693 uint64_t field_bit_offset = 0;
694 bool is_signed;
695 bool is_complex;
696 uint32_t count;
697
698 CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(
699 idx, name, &field_bit_offset, nullptr, nullptr);
700 std::optional<uint64_t> field_bit_width =
701 field_compiler_type.GetBitSize(&thread);
702 if (!field_bit_width)
703 return return_valobj_sp;
704
705 // If there are any unaligned fields, this is stored in memory.
706 if (field_bit_offset % *field_bit_width != 0) {
707 is_memory = true;
708 break;
709 }
710
711 uint32_t field_byte_width = *field_bit_width / 8;
712 uint32_t field_byte_offset = field_bit_offset / 8;
713
714 DataExtractor *copy_from_extractor = nullptr;
715 uint32_t copy_from_offset = 0;
716
717 if (field_compiler_type.IsIntegerOrEnumerationType(is_signed) ||
718 field_compiler_type.IsPointerType()) {
719 if (integer_bytes < 8) {
720 if (integer_bytes + field_byte_width <= 8) {
721 // This is in RAX, copy from register to our result structure:
722 copy_from_extractor = &r3_data;
723 copy_from_offset = integer_bytes;
724 integer_bytes += field_byte_width;
725 } else {
726 // The next field wouldn't fit in the remaining space, so we
727 // pushed it to rdx.
728 copy_from_extractor = &rdx_data;
729 copy_from_offset = 0;
730 integer_bytes = 8 + field_byte_width;
731 }
732 } else if (integer_bytes + field_byte_width <= 16) {
733 copy_from_extractor = &rdx_data;
734 copy_from_offset = integer_bytes - 8;
735 integer_bytes += field_byte_width;
736 } else {
737 // The last field didn't fit. I can't see how that would happen
738 // w/o the overall size being greater than 16 bytes. For now,
739 // return a nullptr return value object.
740 return return_valobj_sp;
741 }
742 } else if (field_compiler_type.IsFloatingPointType(count, is_complex)) {
743 // Structs with long doubles are always passed in memory.
744 if (*field_bit_width == 128) {
745 is_memory = true;
746 break;
747 } else if (*field_bit_width == 64) {
748 copy_from_offset = 0;
749 } else if (*field_bit_width == 32) {
750 // This one is kind of complicated. If we are in an "eightbyte"
751 // with another float, we'll be stuffed into an xmm register with
752 // it. If we are in an "eightbyte" with one or more ints, then we
753 // will be stuffed into the appropriate GPR with them.
754 bool in_gpr;
755 if (field_byte_offset % 8 == 0) {
756 // We are at the beginning of one of the eightbytes, so check the
757 // next element (if any)
758 if (idx == num_children - 1)
759 in_gpr = false;
760 else {
761 uint64_t next_field_bit_offset = 0;
762 CompilerType next_field_compiler_type =
763 return_compiler_type.GetFieldAtIndex(idx + 1, name,
764 &next_field_bit_offset,
765 nullptr, nullptr);
766 if (next_field_compiler_type.IsIntegerOrEnumerationType(
767 is_signed))
768 in_gpr = true;
769 else {
770 copy_from_offset = 0;
771 in_gpr = false;
772 }
773 }
774 } else if (field_byte_offset % 4 == 0) {
775 // We are inside of an eightbyte, so see if the field before us
776 // is floating point: This could happen if somebody put padding
777 // in the structure.
778 if (idx == 0)
779 in_gpr = false;
780 else {
781 uint64_t prev_field_bit_offset = 0;
782 CompilerType prev_field_compiler_type =
783 return_compiler_type.GetFieldAtIndex(idx - 1, name,
784 &prev_field_bit_offset,
785 nullptr, nullptr);
786 if (prev_field_compiler_type.IsIntegerOrEnumerationType(
787 is_signed))
788 in_gpr = true;
789 else {
790 copy_from_offset = 4;
791 in_gpr = false;
792 }
793 }
794 } else {
795 is_memory = true;
796 continue;
797 }
798
799 // Okay, we've figured out whether we are in GPR or XMM, now figure
800 // out which one.
801 if (in_gpr) {
802 if (integer_bytes < 8) {
803 // This is in RAX, copy from register to our result structure:
804 copy_from_extractor = &r3_data;
805 copy_from_offset = integer_bytes;
806 integer_bytes += field_byte_width;
807 } else {
808 copy_from_extractor = &rdx_data;
809 copy_from_offset = integer_bytes - 8;
810 integer_bytes += field_byte_width;
811 }
812 }
813 }
814 }
815
816 // These two tests are just sanity checks. If I somehow get the type
817 // calculation wrong above it is better to just return nothing than to
818 // assert or crash.
819 if (!copy_from_extractor)
820 return return_valobj_sp;
821 if (copy_from_offset + field_byte_width >
822 copy_from_extractor->GetByteSize())
823 return return_valobj_sp;
824
825 copy_from_extractor->CopyByteOrderedData(
826 copy_from_offset, field_byte_width,
827 data_sp->GetBytes() + field_byte_offset, field_byte_width,
828 target_byte_order);
829 }
830
831 if (!is_memory) {
832 // The result is in our data buffer. Let's make a variable object out
833 // of it:
834 return_valobj_sp = ValueObjectConstResult::Create(
835 &thread, return_compiler_type, ConstString(""), return_ext);
836 }
837 }
838
839 // FIXME: This is just taking a guess, r3 may very well no longer hold the
840 // return storage location.
841 // If we are going to do this right, when we make a new frame we should
842 // check to see if it uses a memory return, and if we are at the first
843 // instruction and if so stash away the return location. Then we would
844 // only return the memory return value if we know it is valid.
845
846 if (is_memory) {
847 unsigned r3_id =
848 reg_ctx_sp->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
849 lldb::addr_t storage_addr =
850 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id,
851 0);
852 return_valobj_sp = ValueObjectMemory::Create(
853 &thread, "", Address(storage_addr, nullptr), return_compiler_type);
854 }
855 }
856
857 return return_valobj_sp;
858}
859
861 unwind_plan.Clear();
863
864 uint32_t lr_reg_num = dwarf_lr;
865 uint32_t sp_reg_num = dwarf_r1;
866 uint32_t pc_reg_num = dwarf_pc;
867
869
870 // Our Call Frame Address is the stack pointer value
871 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
872
873 // The previous PC is in the LR
874 row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
875 unwind_plan.AppendRow(row);
876
877 // All other registers are the same.
878
879 unwind_plan.SetSourceName("ppc at-func-entry default");
881
882 return true;
883}
884
886 unwind_plan.Clear();
888
889 uint32_t sp_reg_num = dwarf_r1;
890 uint32_t pc_reg_num = dwarf_lr;
891
893
894 const int32_t ptr_size = 4;
895 row->SetUnspecifiedRegistersAreUndefined(true);
896 row->GetCFAValue().SetIsRegisterDereferenced(sp_reg_num);
897
898 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * 1, true);
899 row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
900
901 unwind_plan.AppendRow(row);
902 unwind_plan.SetSourceName("ppc default unwind plan");
907 return true;
908}
909
911 return !RegisterIsCalleeSaved(reg_info);
912}
913
914// See "Register Usage" in the
915// "System V Application Binary Interface"
916// "64-bit PowerPC ELF Application Binary Interface Supplement" current version
917// is 1.9 released 2004 at http://refspecs.linuxfoundation.org/ELF/ppc/PPC-
918// elf64abi-1.9.pdf
919
921 if (reg_info) {
922 // Preserved registers are :
923 // r1,r2,r13-r31
924 // f14-f31 (not yet)
925 // v20-v31 (not yet)
926 // vrsave (not yet)
927
928 const char *name = reg_info->name;
929 if (name[0] == 'r') {
930 if ((name[1] == '1' || name[1] == '2') && name[2] == '\0')
931 return true;
932 if (name[1] == '1' && name[2] > '2')
933 return true;
934 if ((name[1] == '2' || name[1] == '3') && name[2] != '\0')
935 return true;
936 }
937
938 if (name[0] == 'f' && name[1] >= '0' && name[1] <= '9') {
939 if (name[3] == '1' && name[4] >= '4')
940 return true;
941 if ((name[3] == '2' || name[3] == '3') && name[4] != '\0')
942 return true;
943 }
944
945 if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
946 return true;
947 if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
948 return true;
949 if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
950 return true;
951 }
952 return false;
953}
954
957 "System V ABI for ppc targets", CreateInstance);
958}
959
962}
static const uint32_t k_num_register_infos
static const RegisterInfo g_register_infos[]
dwarf_regnums
@ dwarf_r1
@ dwarf_pc
@ dwarf_r7
Definition: ABISysV_ppc.cpp:47
@ dwarf_f12
Definition: ABISysV_ppc.cpp:84
@ dwarf_f27
Definition: ABISysV_ppc.cpp:99
@ dwarf_f17
Definition: ABISysV_ppc.cpp:89
@ dwarf_r21
Definition: ABISysV_ppc.cpp:61
@ dwarf_f9
Definition: ABISysV_ppc.cpp:81
@ dwarf_f28
@ dwarf_r24
Definition: ABISysV_ppc.cpp:64
@ dwarf_f19
Definition: ABISysV_ppc.cpp:91
@ dwarf_r12
Definition: ABISysV_ppc.cpp:52
@ dwarf_f11
Definition: ABISysV_ppc.cpp:83
@ dwarf_cr
@ dwarf_f31
@ dwarf_r3
Definition: ABISysV_ppc.cpp:43
@ dwarf_f16
Definition: ABISysV_ppc.cpp:88
@ dwarf_r13
Definition: ABISysV_ppc.cpp:53
@ dwarf_r2
Definition: ABISysV_ppc.cpp:42
@ dwarf_f22
Definition: ABISysV_ppc.cpp:94
@ dwarf_f26
Definition: ABISysV_ppc.cpp:98
@ dwarf_r8
Definition: ABISysV_ppc.cpp:48
@ dwarf_r28
Definition: ABISysV_ppc.cpp:68
@ dwarf_r11
Definition: ABISysV_ppc.cpp:51
@ dwarf_r31
Definition: ABISysV_ppc.cpp:71
@ dwarf_f10
Definition: ABISysV_ppc.cpp:82
@ dwarf_f23
Definition: ABISysV_ppc.cpp:95
@ dwarf_f6
Definition: ABISysV_ppc.cpp:78
@ dwarf_r19
Definition: ABISysV_ppc.cpp:59
@ dwarf_r1
Definition: ABISysV_ppc.cpp:41
@ dwarf_f5
Definition: ABISysV_ppc.cpp:77
@ dwarf_r26
Definition: ABISysV_ppc.cpp:66
@ dwarf_f2
Definition: ABISysV_ppc.cpp:74
@ dwarf_f0
Definition: ABISysV_ppc.cpp:72
@ dwarf_f7
Definition: ABISysV_ppc.cpp:79
@ dwarf_r9
Definition: ABISysV_ppc.cpp:49
@ dwarf_pc
@ dwarf_lr
@ dwarf_r29
Definition: ABISysV_ppc.cpp:69
@ dwarf_r16
Definition: ABISysV_ppc.cpp:56
@ dwarf_xer
@ dwarf_r18
Definition: ABISysV_ppc.cpp:58
@ dwarf_f15
Definition: ABISysV_ppc.cpp:87
@ dwarf_f14
Definition: ABISysV_ppc.cpp:86
@ dwarf_r17
Definition: ABISysV_ppc.cpp:57
@ dwarf_f30
@ dwarf_f24
Definition: ABISysV_ppc.cpp:96
@ dwarf_f1
Definition: ABISysV_ppc.cpp:73
@ dwarf_r15
Definition: ABISysV_ppc.cpp:55
@ dwarf_r23
Definition: ABISysV_ppc.cpp:63
@ dwarf_f18
Definition: ABISysV_ppc.cpp:90
@ dwarf_f25
Definition: ABISysV_ppc.cpp:97
@ dwarf_ctr
@ dwarf_r10
Definition: ABISysV_ppc.cpp:50
@ dwarf_r14
Definition: ABISysV_ppc.cpp:54
@ dwarf_f3
Definition: ABISysV_ppc.cpp:75
@ dwarf_r6
Definition: ABISysV_ppc.cpp:46
@ dwarf_f21
Definition: ABISysV_ppc.cpp:93
@ dwarf_r25
Definition: ABISysV_ppc.cpp:65
@ dwarf_fpscr
@ dwarf_f13
Definition: ABISysV_ppc.cpp:85
@ dwarf_f29
@ dwarf_r30
Definition: ABISysV_ppc.cpp:70
@ dwarf_r0
Definition: ABISysV_ppc.cpp:40
@ dwarf_cfa
@ dwarf_r5
Definition: ABISysV_ppc.cpp:45
@ dwarf_f20
Definition: ABISysV_ppc.cpp:92
@ dwarf_r20
Definition: ABISysV_ppc.cpp:60
@ dwarf_r27
Definition: ABISysV_ppc.cpp:67
@ dwarf_r4
Definition: ABISysV_ppc.cpp:44
@ dwarf_r22
Definition: ABISysV_ppc.cpp:62
@ dwarf_f8
Definition: ABISysV_ppc.cpp:80
@ dwarf_f4
Definition: ABISysV_ppc.cpp:76
static const uint32_t k_num_register_infos
static const RegisterInfo g_register_infos[]
#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)
Definition: PluginManager.h:32
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
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
static llvm::StringRef GetPluginNameStatic()
Definition: ABISysV_ppc.h:81
static void Terminate()
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
static void Initialize()
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
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
static std::unique_ptr< llvm::MCRegisterInfo > MakeMCRegisterInfo(const ArchSpec &arch)
Utility function to construct a MCRegisterInfo using the ArchSpec triple.
Definition: ABI.cpp:234
A section + offset based address class.
Definition: Address.h:62
An architecture specification class.
Definition: ArchSpec.h:31
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:709
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:461
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:756
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const
bool IsFloatingPointType(uint32_t &count, bool &is_complex) const
uint32_t GetNumFields() const
bool IsIntegerOrEnumerationType(bool &is_signed) const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
std::optional< 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.
Definition: DataExtractor.h:48
float GetFloat(lldb::offset_t *offset_ptr) const
Extract a float from *offset_ptr.
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:745
An error handling class.
Definition: Status.h:115
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: Status.cpp:106
static Status FromErrorString(const char *str)
Definition: Status.h:138
bool Fail() const
Test for error condition.
Definition: Status.cpp:270
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:195
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:1039
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:408
virtual lldb::RegisterContextSP GetRegisterContext()=0
lldb::ProcessSP GetProcess() const
Definition: Thread.h:157
void SetUnwindPlanForSignalTrap(lldb_private::LazyBool is_for_signal_trap)
Definition: UnwindPlan.h:536
void SetRegisterKind(lldb::RegisterKind kind)
Definition: UnwindPlan.h:471
void SetReturnAddressRegister(uint32_t regnum)
Definition: UnwindPlan.h:473
void AppendRow(const RowSP &row_sp)
Definition: UnwindPlan.cpp:392
std::shared_ptr< Row > RowSP
Definition: UnwindPlan.h:429
void SetSourcedFromCompiler(lldb_private::LazyBool from_compiler)
Definition: UnwindPlan.h:512
void SetSourceName(const char *)
Definition: UnwindPlan.cpp:594
void SetUnwindPlanValidAtAllInstructions(lldb_private::LazyBool valid_at_all_insn)
Definition: UnwindPlan.h:524
Value * GetValueAtIndex(size_t idx)
Definition: Value.cpp:691
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
Definition: Value.h:112
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:268
void SetValueType(ValueType value_type)
Definition: Value.h:89
const CompilerType & GetCompilerType()
Definition: Value.cpp:239
#define LLDB_REGNUM_GENERIC_RA
Definition: lldb-defines.h:59
#define LLDB_REGNUM_GENERIC_ARG8
Definition: lldb-defines.h:75
#define LLDB_REGNUM_GENERIC_ARG6
Definition: lldb-defines.h:71
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:57
#define LLDB_REGNUM_GENERIC_ARG4
Definition: lldb-defines.h:67
#define LLDB_REGNUM_GENERIC_ARG3
Definition: lldb-defines.h:65
#define LLDB_REGNUM_GENERIC_ARG1
Definition: lldb-defines.h:61
#define LLDB_REGNUM_GENERIC_ARG7
Definition: lldb-defines.h:73
#define LLDB_REGNUM_GENERIC_FLAGS
Definition: lldb-defines.h:60
#define UINT32_MAX
Definition: lldb-defines.h:19
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:87
#define LLDB_REGNUM_GENERIC_ARG2
Definition: lldb-defines.h:63
#define LLDB_REGNUM_GENERIC_PC
Definition: lldb-defines.h:56
#define LLDB_REGNUM_GENERIC_ARG5
Definition: lldb-defines.h:69
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
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ABI > ABISP
Definition: lldb-forward.h:317
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:424
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:484
uint64_t offset_t
Definition: lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
@ eEncodingUint
unsigned integer
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:336
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:337
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
Definition: lldb-forward.h:394
@ 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.
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47