LLDB mainline
ABIMacOSX_arm64.cpp
Go to the documentation of this file.
1//===-- ABIMacOSX_arm64.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 "ABIMacOSX_arm64.h"
10
11#include <optional>
12#include <vector>
13
14#include "llvm/ADT/STLExtras.h"
15#include "llvm/TargetParser/Triple.h"
16
17#include "lldb/Core/Module.h"
19#include "lldb/Core/Value.h"
21#include "lldb/Target/Process.h"
23#include "lldb/Target/Target.h"
24#include "lldb/Target/Thread.h"
27#include "lldb/Utility/Log.h"
29#include "lldb/Utility/Scalar.h"
30#include "lldb/Utility/Status.h"
32
34
35using namespace lldb;
36using namespace lldb_private;
37
38static const char *pluginDesc = "Mac OS X ABI for arm64 targets";
39
40size_t ABIMacOSX_arm64::GetRedZoneSize() const { return 128; }
41
42// Static Functions
43
46 const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();
47 const llvm::Triple::VendorType vendor_type = arch.GetTriple().getVendor();
48
49 if (vendor_type == llvm::Triple::Apple) {
50 if (arch_type == llvm::Triple::aarch64 ||
51 arch_type == llvm::Triple::aarch64_32) {
52 return ABISP(
53 new ABIMacOSX_arm64(std::move(process_sp), MakeMCRegisterInfo(arch)));
54 }
55 }
56
57 return ABISP();
58}
59
61 Thread &thread, lldb::addr_t sp, lldb::addr_t func_addr,
62 lldb::addr_t return_addr, llvm::ArrayRef<lldb::addr_t> args) const {
63 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
64 if (!reg_ctx)
65 return false;
66
67 Log *log = GetLog(LLDBLog::Expressions);
68
69 if (log) {
71 s.Printf("ABIMacOSX_arm64::PrepareTrivialCall (tid = 0x%" PRIx64
72 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
73 ", return_addr = 0x%" PRIx64,
74 thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
75 (uint64_t)return_addr);
76
77 for (size_t i = 0; i < args.size(); ++i)
78 s.Printf(", arg%d = 0x%" PRIx64, static_cast<int>(i + 1), args[i]);
79 s.PutCString(")");
80 log->PutString(s.GetString());
81 }
82
83 const uint32_t pc_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
85 const uint32_t sp_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
87 const uint32_t ra_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
89
90 // x0 - x7 contain first 8 simple args
91 if (args.size() > 8) // TODO handle more than 8 arguments
92 return false;
93
94 for (size_t i = 0; i < args.size(); ++i) {
95 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(
97 LLDB_LOGF(log, "About to write arg%d (0x%" PRIx64 ") into %s",
98 static_cast<int>(i + 1), args[i], reg_info->name);
99 if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
100 return false;
101 }
102
103 // Set "lr" to the return address
104 if (!reg_ctx->WriteRegisterFromUnsigned(
105 reg_ctx->GetRegisterInfoAtIndex(ra_reg_num), return_addr))
106 return false;
107
108 // Set "sp" to the requested value
109 if (!reg_ctx->WriteRegisterFromUnsigned(
110 reg_ctx->GetRegisterInfoAtIndex(sp_reg_num), sp))
111 return false;
112
113 // Set "pc" to the address requested
114 if (!reg_ctx->WriteRegisterFromUnsigned(
115 reg_ctx->GetRegisterInfoAtIndex(pc_reg_num), func_addr))
116 return false;
117
118 return true;
119}
120
122 ValueList &values) const {
123 uint32_t num_values = values.GetSize();
124
125 ExecutionContext exe_ctx(thread.shared_from_this());
126
127 // Extract the register context so we can read arguments from registers
128
129 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
130
131 if (!reg_ctx)
132 return false;
133
134 addr_t sp = 0;
135
136 for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
137 // We currently only support extracting values with Clang QualTypes. Do we
138 // care about others?
139 Value *value = values.GetValueAtIndex(value_idx);
140
141 if (!value)
142 return false;
143
144 CompilerType value_type = value->GetCompilerType();
145 std::optional<uint64_t> bit_size = value_type.GetBitSize(&thread);
146 if (!bit_size)
147 return false;
148
149 bool is_signed = false;
150 size_t bit_width = 0;
151 if (value_type.IsIntegerOrEnumerationType(is_signed)) {
152 bit_width = *bit_size;
153 } else if (value_type.IsPointerOrReferenceType()) {
154 bit_width = *bit_size;
155 } else {
156 // We only handle integer, pointer and reference types currently...
157 return false;
158 }
159
160 if (bit_width <= (exe_ctx.GetProcessRef().GetAddressByteSize() * 8)) {
161 if (value_idx < 8) {
162 // Arguments 1-6 are in x0-x5...
163 const RegisterInfo *reg_info = nullptr;
164 // Search by generic ID first, then fall back to by name
165 uint32_t arg_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
167 if (arg_reg_num != LLDB_INVALID_REGNUM) {
168 reg_info = reg_ctx->GetRegisterInfoAtIndex(arg_reg_num);
169 } else {
170 switch (value_idx) {
171 case 0:
172 reg_info = reg_ctx->GetRegisterInfoByName("x0");
173 break;
174 case 1:
175 reg_info = reg_ctx->GetRegisterInfoByName("x1");
176 break;
177 case 2:
178 reg_info = reg_ctx->GetRegisterInfoByName("x2");
179 break;
180 case 3:
181 reg_info = reg_ctx->GetRegisterInfoByName("x3");
182 break;
183 case 4:
184 reg_info = reg_ctx->GetRegisterInfoByName("x4");
185 break;
186 case 5:
187 reg_info = reg_ctx->GetRegisterInfoByName("x5");
188 break;
189 case 6:
190 reg_info = reg_ctx->GetRegisterInfoByName("x6");
191 break;
192 case 7:
193 reg_info = reg_ctx->GetRegisterInfoByName("x7");
194 break;
195 }
196 }
197
198 if (reg_info) {
199 RegisterValue reg_value;
200
201 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
202 if (is_signed)
203 reg_value.SignExtend(bit_width);
204 if (!reg_value.GetScalarValue(value->GetScalar()))
205 return false;
206 continue;
207 }
208 }
209 return false;
210 } else {
211 if (sp == 0) {
212 // Read the stack pointer if we already haven't read it
213 sp = reg_ctx->GetSP(0);
214 if (sp == 0)
215 return false;
216 }
217
218 // Arguments 5 on up are on the stack
219 const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
222 sp, arg_byte_size, is_signed, value->GetScalar(), error))
223 return false;
224
225 sp += arg_byte_size;
226 // Align up to the next 8 byte boundary if needed
227 if (sp % 8) {
228 sp >>= 3;
229 sp += 1;
230 sp <<= 3;
231 }
232 }
233 }
234 }
235 return true;
236}
237
238Status
240 lldb::ValueObjectSP &new_value_sp) {
242 if (!new_value_sp) {
243 error = Status::FromErrorString("Empty value object for return value.");
244 return error;
245 }
246
247 CompilerType return_value_type = new_value_sp->GetCompilerType();
248 if (!return_value_type) {
249 error = Status::FromErrorString("Null clang type for return value.");
250 return error;
251 }
252
253 Thread *thread = frame_sp->GetThread().get();
254
255 RegisterContext *reg_ctx = thread->GetRegisterContext().get();
256
257 if (reg_ctx) {
258 DataExtractor data;
259 Status data_error;
260 const uint64_t byte_size = new_value_sp->GetData(data, data_error);
261 if (data_error.Fail()) {
263 "Couldn't convert return value to raw data: %s",
264 data_error.AsCString());
265 return error;
266 }
267
268 const uint32_t type_flags = return_value_type.GetTypeInfo(nullptr);
269 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
270 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
271 // Extract the register context so we can read arguments from registers
272 lldb::offset_t offset = 0;
273 if (byte_size <= 16) {
274 const RegisterInfo *x0_info = reg_ctx->GetRegisterInfoByName("x0", 0);
275 if (byte_size <= 8) {
276 uint64_t raw_value = data.GetMaxU64(&offset, byte_size);
277
278 if (!reg_ctx->WriteRegisterFromUnsigned(x0_info, raw_value))
279 error = Status::FromErrorString("failed to write register x0");
280 } else {
281 uint64_t raw_value = data.GetMaxU64(&offset, 8);
282
283 if (reg_ctx->WriteRegisterFromUnsigned(x0_info, raw_value)) {
284 const RegisterInfo *x1_info =
285 reg_ctx->GetRegisterInfoByName("x1", 0);
286 raw_value = data.GetMaxU64(&offset, byte_size - offset);
287
288 if (!reg_ctx->WriteRegisterFromUnsigned(x1_info, raw_value))
289 error = Status::FromErrorString("failed to write register x1");
290 }
291 }
292 } else {
294 "We don't support returning longer than 128 bit "
295 "integer values at present.");
296 }
297 } else if (type_flags & eTypeIsFloat) {
298 if (type_flags & eTypeIsComplex) {
299 // Don't handle complex yet.
301 "returning complex float values are not supported");
302 } else {
303 const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
304
305 if (v0_info) {
306 if (byte_size <= 16) {
307 RegisterValue reg_value;
308 error = reg_value.SetValueFromData(*v0_info, data, 0, true);
309 if (error.Success())
310 if (!reg_ctx->WriteRegister(v0_info, reg_value))
311 error =
312 Status::FromErrorString("failed to write register v0");
313 } else {
315 "returning float values longer than 128 "
316 "bits are not supported");
317 }
318 } else
320 "v0 register is not available on this target");
321 }
322 }
323 } else if (type_flags & eTypeIsVector) {
324 if (byte_size > 0) {
325 const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
326
327 if (v0_info) {
328 if (byte_size <= v0_info->byte_size) {
329 RegisterValue reg_value;
330 error = reg_value.SetValueFromData(*v0_info, data, 0, true);
331 if (error.Success()) {
332 if (!reg_ctx->WriteRegister(v0_info, reg_value))
333 error = Status::FromErrorString("failed to write register v0");
334 }
335 }
336 }
337 }
338 }
339 } else {
340 error = Status::FromErrorString("no registers are available");
341 }
342
343 return error;
344}
345
347 unwind_plan.Clear();
349
350 uint32_t lr_reg_num = arm64_dwarf::lr;
351 uint32_t sp_reg_num = arm64_dwarf::sp;
352 uint32_t pc_reg_num = arm64_dwarf::pc;
353
355
356 // Our previous Call Frame Address is the stack pointer
357 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
358
359 // Our previous PC is in the LR
360 row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
361
362 unwind_plan.AppendRow(row);
363
364 // All other registers are the same.
365
366 unwind_plan.SetSourceName("arm64 at-func-entry default");
368
369 return true;
370}
371
373 unwind_plan.Clear();
375
376 uint32_t fp_reg_num = arm64_dwarf::fp;
377 uint32_t pc_reg_num = arm64_dwarf::pc;
378
380 const int32_t ptr_size = 8;
381
382 row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
383 row->SetOffset(0);
384 row->SetUnspecifiedRegistersAreUndefined(true);
385
386 row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);
387 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);
388
389 unwind_plan.AppendRow(row);
390 unwind_plan.SetSourceName("arm64-apple-darwin default unwind plan");
394 return true;
395}
396
397// AAPCS64 (Procedure Call Standard for the ARM 64-bit Architecture) says
398// registers x19 through x28 and sp are callee preserved. v8-v15 are non-
399// volatile (and specifically only the lower 8 bytes of these regs), the rest
400// of the fp/SIMD registers are volatile.
401//
402// v. https://github.com/ARM-software/abi-aa/blob/main/aapcs64/
403
404// We treat x29 as callee preserved also, else the unwinder won't try to
405// retrieve fp saves.
406
408 if (reg_info) {
409 const char *name = reg_info->name;
410
411 // Sometimes we'll be called with the "alternate" name for these registers;
412 // recognize them as non-volatile.
413
414 if (name[0] == 'p' && name[1] == 'c') // pc
415 return false;
416 if (name[0] == 'f' && name[1] == 'p') // fp
417 return false;
418 if (name[0] == 's' && name[1] == 'p') // sp
419 return false;
420 if (name[0] == 'l' && name[1] == 'r') // lr
421 return false;
422
423 if (name[0] == 'x') {
424 // Volatile registers: x0-x18, x30 (lr)
425 // Return false for the non-volatile gpr regs, true for everything else
426 switch (name[1]) {
427 case '1':
428 switch (name[2]) {
429 case '9':
430 return false; // x19 is non-volatile
431 default:
432 return true;
433 }
434 break;
435 case '2':
436 switch (name[2]) {
437 case '0':
438 case '1':
439 case '2':
440 case '3':
441 case '4':
442 case '5':
443 case '6':
444 case '7':
445 case '8':
446 return false; // x20 - 28 are non-volatile
447 case '9':
448 return false; // x29 aka fp treat as non-volatile on Darwin
449 default:
450 return true;
451 }
452 case '3': // x30 aka lr treat as non-volatile
453 if (name[2] == '0')
454 return false;
455 break;
456 default:
457 return true;
458 }
459 } else if (name[0] == 'v' || name[0] == 's' || name[0] == 'd') {
460 // Volatile registers: v0-7, v16-v31
461 // Return false for non-volatile fp/SIMD regs, true for everything else
462 switch (name[1]) {
463 case '8':
464 case '9':
465 return false; // v8-v9 are non-volatile
466 case '1':
467 switch (name[2]) {
468 case '0':
469 case '1':
470 case '2':
471 case '3':
472 case '4':
473 case '5':
474 return false; // v10-v15 are non-volatile
475 default:
476 return true;
477 }
478 default:
479 return true;
480 }
481 }
482 }
483 return true;
484}
485
487 ExecutionContext &exe_ctx, RegisterContext *reg_ctx,
488 const CompilerType &value_type,
489 bool is_return_value, // false => parameter, true => return value
490 uint32_t &NGRN, // NGRN (see ABI documentation)
491 uint32_t &NSRN, // NSRN (see ABI documentation)
492 DataExtractor &data) {
493 std::optional<uint64_t> byte_size =
494 value_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
495 if (!byte_size || *byte_size == 0)
496 return false;
497
498 std::unique_ptr<DataBufferHeap> heap_data_up(
499 new DataBufferHeap(*byte_size, 0));
500 const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();
502
503 CompilerType base_type;
504 const uint32_t homogeneous_count =
505 value_type.IsHomogeneousAggregate(&base_type);
506 if (homogeneous_count > 0 && homogeneous_count <= 8) {
507 // Make sure we have enough registers
508 if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
509 if (!base_type)
510 return false;
511 std::optional<uint64_t> base_byte_size =
512 base_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
513 if (!base_byte_size)
514 return false;
515 uint32_t data_offset = 0;
516
517 for (uint32_t i = 0; i < homogeneous_count; ++i) {
518 char v_name[8];
519 ::snprintf(v_name, sizeof(v_name), "v%u", NSRN);
520 const RegisterInfo *reg_info =
521 reg_ctx->GetRegisterInfoByName(v_name, 0);
522 if (reg_info == nullptr)
523 return false;
524
525 if (*base_byte_size > reg_info->byte_size)
526 return false;
527
528 RegisterValue reg_value;
529
530 if (!reg_ctx->ReadRegister(reg_info, reg_value))
531 return false;
532
533 // Make sure we have enough room in "heap_data_up"
534 if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
535 const size_t bytes_copied = reg_value.GetAsMemoryData(
536 *reg_info, heap_data_up->GetBytes() + data_offset,
537 *base_byte_size, byte_order, error);
538 if (bytes_copied != *base_byte_size)
539 return false;
540 data_offset += bytes_copied;
541 ++NSRN;
542 } else
543 return false;
544 }
545 data.SetByteOrder(byte_order);
547 data.SetData(DataBufferSP(heap_data_up.release()));
548 return true;
549 }
550 }
551
552 const size_t max_reg_byte_size = 16;
553 if (*byte_size <= max_reg_byte_size) {
554 size_t bytes_left = *byte_size;
555 uint32_t data_offset = 0;
556 while (data_offset < *byte_size) {
557 if (NGRN >= 8)
558 return false;
559
560 uint32_t reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
562 if (reg_num == LLDB_INVALID_REGNUM)
563 return false;
564
565 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_num);
566 if (reg_info == nullptr)
567 return false;
568
569 RegisterValue reg_value;
570
571 if (!reg_ctx->ReadRegister(reg_info, reg_value))
572 return false;
573
574 const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
575 const size_t bytes_copied = reg_value.GetAsMemoryData(
576 *reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
577 byte_order, error);
578 if (bytes_copied == 0)
579 return false;
580 if (bytes_copied >= bytes_left)
581 break;
582 data_offset += bytes_copied;
583 bytes_left -= bytes_copied;
584 ++NGRN;
585 }
586 } else {
587 const RegisterInfo *reg_info = nullptr;
588 if (is_return_value) {
589 // The Darwin arm64 ABI doesn't write the return location back to x8
590 // before returning from the function the way the x86_64 ABI does. So
591 // we can't reconstruct stack based returns on exit from the function:
592 return false;
593 } else {
594 // We are assuming we are stopped at the first instruction in a function
595 // and that the ABI is being respected so all parameters appear where
596 // they should be (functions with no external linkage can legally violate
597 // the ABI).
598 if (NGRN >= 8)
599 return false;
600
601 uint32_t reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
603 if (reg_num == LLDB_INVALID_REGNUM)
604 return false;
605 reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_num);
606 if (reg_info == nullptr)
607 return false;
608 ++NGRN;
609 }
610
611 const lldb::addr_t value_addr =
613
614 if (value_addr == LLDB_INVALID_ADDRESS)
615 return false;
616
617 if (exe_ctx.GetProcessRef().ReadMemory(
618 value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
619 error) != heap_data_up->GetByteSize()) {
620 return false;
621 }
622 }
623
624 data.SetByteOrder(byte_order);
626 data.SetData(DataBufferSP(heap_data_up.release()));
627 return true;
628}
629
631 Thread &thread, CompilerType &return_compiler_type) const {
632 ValueObjectSP return_valobj_sp;
633 Value value;
634
635 ExecutionContext exe_ctx(thread.shared_from_this());
636 if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)
637 return return_valobj_sp;
638
639 // value.SetContext (Value::eContextTypeClangType, return_compiler_type);
640 value.SetCompilerType(return_compiler_type);
641
642 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
643 if (!reg_ctx)
644 return return_valobj_sp;
645
646 std::optional<uint64_t> byte_size = return_compiler_type.GetByteSize(&thread);
647 if (!byte_size)
648 return return_valobj_sp;
649
650 const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr);
651 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
652 value.SetValueType(Value::ValueType::Scalar);
653
654 bool success = false;
655 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
656 // Extract the register context so we can read arguments from registers
657 if (*byte_size <= 8) {
658 const RegisterInfo *x0_reg_info =
659 reg_ctx->GetRegisterInfoByName("x0", 0);
660 if (x0_reg_info) {
661 uint64_t raw_value =
662 thread.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info,
663 0);
664 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
665 switch (*byte_size) {
666 default:
667 break;
668 case 16: // uint128_t
669 // In register x0 and x1
670 {
671 const RegisterInfo *x1_reg_info =
672 reg_ctx->GetRegisterInfoByName("x1", 0);
673
674 if (x1_reg_info) {
675 if (*byte_size <=
676 x0_reg_info->byte_size + x1_reg_info->byte_size) {
677 std::unique_ptr<DataBufferHeap> heap_data_up(
678 new DataBufferHeap(*byte_size, 0));
679 const ByteOrder byte_order =
680 exe_ctx.GetProcessRef().GetByteOrder();
681 RegisterValue x0_reg_value;
682 RegisterValue x1_reg_value;
683 if (reg_ctx->ReadRegister(x0_reg_info, x0_reg_value) &&
684 reg_ctx->ReadRegister(x1_reg_info, x1_reg_value)) {
686 if (x0_reg_value.GetAsMemoryData(
687 *x0_reg_info, heap_data_up->GetBytes() + 0, 8,
688 byte_order, error) &&
689 x1_reg_value.GetAsMemoryData(
690 *x1_reg_info, heap_data_up->GetBytes() + 8, 8,
691 byte_order, error)) {
692 DataExtractor data(
693 DataBufferSP(heap_data_up.release()), byte_order,
695
696 return_valobj_sp = ValueObjectConstResult::Create(
697 &thread, return_compiler_type, ConstString(""), data);
698 return return_valobj_sp;
699 }
700 }
701 }
702 }
703 }
704 break;
705 case sizeof(uint64_t):
706 if (is_signed)
707 value.GetScalar() = (int64_t)(raw_value);
708 else
709 value.GetScalar() = (uint64_t)(raw_value);
710 success = true;
711 break;
712
713 case sizeof(uint32_t):
714 if (is_signed)
715 value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
716 else
717 value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
718 success = true;
719 break;
720
721 case sizeof(uint16_t):
722 if (is_signed)
723 value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
724 else
725 value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
726 success = true;
727 break;
728
729 case sizeof(uint8_t):
730 if (is_signed)
731 value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
732 else
733 value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
734 success = true;
735 break;
736 }
737 }
738 }
739 } else if (type_flags & eTypeIsFloat) {
740 if (type_flags & eTypeIsComplex) {
741 // Don't handle complex yet.
742 } else {
743 if (*byte_size <= sizeof(long double)) {
744 const RegisterInfo *v0_reg_info =
745 reg_ctx->GetRegisterInfoByName("v0", 0);
746 RegisterValue v0_value;
747 if (reg_ctx->ReadRegister(v0_reg_info, v0_value)) {
748 DataExtractor data;
749 if (v0_value.GetData(data)) {
750 lldb::offset_t offset = 0;
751 if (*byte_size == sizeof(float)) {
752 value.GetScalar() = data.GetFloat(&offset);
753 success = true;
754 } else if (*byte_size == sizeof(double)) {
755 value.GetScalar() = data.GetDouble(&offset);
756 success = true;
757 } else if (*byte_size == sizeof(long double)) {
758 value.GetScalar() = data.GetLongDouble(&offset);
759 success = true;
760 }
761 }
762 }
763 }
764 }
765 }
766
767 if (success)
768 return_valobj_sp = ValueObjectConstResult::Create(
769 thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
770 } else if (type_flags & eTypeIsVector) {
771 if (*byte_size > 0) {
772
773 const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
774
775 if (v0_info) {
776 if (*byte_size <= v0_info->byte_size) {
777 std::unique_ptr<DataBufferHeap> heap_data_up(
778 new DataBufferHeap(*byte_size, 0));
779 const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();
780 RegisterValue reg_value;
781 if (reg_ctx->ReadRegister(v0_info, reg_value)) {
783 if (reg_value.GetAsMemoryData(*v0_info, heap_data_up->GetBytes(),
784 heap_data_up->GetByteSize(),
785 byte_order, error)) {
786 DataExtractor data(DataBufferSP(heap_data_up.release()),
787 byte_order,
789 return_valobj_sp = ValueObjectConstResult::Create(
790 &thread, return_compiler_type, ConstString(""), data);
791 }
792 }
793 }
794 }
795 }
796 } else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass) {
797 DataExtractor data;
798
799 uint32_t NGRN = 0; // Search ABI docs for NGRN
800 uint32_t NSRN = 0; // Search ABI docs for NSRN
801 const bool is_return_value = true;
803 exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
804 data)) {
805 return_valobj_sp = ValueObjectConstResult::Create(
806 &thread, return_compiler_type, ConstString(""), data);
807 }
808 }
809 return return_valobj_sp;
810}
811
813 addr_t pac_sign_extension = 0x0080000000000000ULL;
814 addr_t tbi_mask = 0xff80000000000000ULL;
815 addr_t mask = 0;
816
817 if (ProcessSP process_sp = GetProcessSP()) {
818 mask = process_sp->GetCodeAddressMask();
819 if (pc & pac_sign_extension) {
820 addr_t highmem_mask = process_sp->GetHighmemCodeAddressMask();
821 if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
822 mask = highmem_mask;
823 }
824 }
825 if (mask == LLDB_INVALID_ADDRESS_MASK)
826 mask = tbi_mask;
827
828 return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
829}
830
832 addr_t pac_sign_extension = 0x0080000000000000ULL;
833 addr_t tbi_mask = 0xff80000000000000ULL;
834 addr_t mask = 0;
835
836 if (ProcessSP process_sp = GetProcessSP()) {
837 mask = process_sp->GetDataAddressMask();
838 if (pc & pac_sign_extension) {
839 addr_t highmem_mask = process_sp->GetHighmemDataAddressMask();
840 if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
841 mask = highmem_mask;
842 }
843 }
844 if (mask == LLDB_INVALID_ADDRESS_MASK)
845 mask = tbi_mask;
846
847 return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
848}
849
853}
854
857}
static bool LoadValueFromConsecutiveGPRRegisters(ExecutionContext &exe_ctx, RegisterContext *reg_ctx, const CompilerType &value_type, bool is_return_value, uint32_t &NGRN, uint32_t &NSRN, DataExtractor &data)
static const char * pluginDesc
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:376
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
static llvm::StringRef GetPluginNameStatic()
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
size_t GetRedZoneSize() const override
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
lldb::addr_t FixCodeAddress(lldb::addr_t pc) override
Some targets might use bits in a code address to indicate a mode switch.
lldb::addr_t FixDataAddress(lldb::addr_t pc) override
static void Terminate()
static void Initialize()
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const override
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) 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
lldb::ProcessSP GetProcessSP() const
Request to get a Process shared pointer.
Definition: ABI.h:96
An architecture specification class.
Definition: ArchSpec.h:31
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:461
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.
uint32_t IsHomogeneousAggregate(CompilerType *base_type_ptr) 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 IsPointerOrReferenceType(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.
long double GetLongDouble(lldb::offset_t *offset_ptr) const
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
void SetAddressByteSize(uint32_t addr_size)
Set the address byte size.
double GetDouble(lldb::offset_t *offset_ptr) const
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Process & GetProcessRef() const
Returns a reference to the process object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process 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)
size_t ReadScalarIntegerFromMemory(lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Status &error)
Definition: Process.cpp:2375
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition: Process.cpp:1953
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3611
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3615
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
Convert from a given register numbering scheme to the lldb register numbering scheme.
uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value)
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
uint64_t GetSP(uint64_t fail_value=LLDB_INVALID_ADDRESS)
virtual bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue &reg_value)=0
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 SignExtend(uint32_t sign_bitpos)
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 GetScalarValue(Scalar &scalar) const
Status SetValueFromData(const RegisterInfo &reg_info, DataExtractor &data, lldb::offset_t offset, bool partial_data_ok)
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
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:408
virtual lldb::RegisterContextSP GetRegisterContext()=0
void SetUnwindPlanForSignalTrap(lldb_private::LazyBool is_for_signal_trap)
Definition: UnwindPlan.h:536
void SetRegisterKind(lldb::RegisterKind kind)
Definition: UnwindPlan.h:471
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)
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_INVALID_ADDRESS_MASK
Address Mask Bits not used for addressing are set to 1 in the mask; all mask bits set is an invalid v...
Definition: lldb-defines.h:133
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:57
#define LLDB_REGNUM_GENERIC_ARG1
Definition: lldb-defines.h:61
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define UINT32_MAX
Definition: lldb-defines.h:19
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:87
#define LLDB_REGNUM_GENERIC_PC
Definition: lldb-defines.h:56
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
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:336
uint64_t addr_t
Definition: lldb-types.h:80
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindDWARF
the register numbers seen DWARF
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_size
Size in bytes of the register.
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