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"
22#include "lldb/Target/Process.h"
24#include "lldb/Target/Target.h"
25#include "lldb/Target/Thread.h"
28#include "lldb/Utility/Log.h"
30#include "lldb/Utility/Scalar.h"
31#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.SetErrorString("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.SetErrorString("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()) {
262 error.SetErrorStringWithFormat(
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.SetErrorString("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.SetErrorString("failed to write register x1");
290 }
291 }
292 } else {
293 error.SetErrorString("We don't support returning longer than 128 bit "
294 "integer values at present.");
295 }
296 } else if (type_flags & eTypeIsFloat) {
297 if (type_flags & eTypeIsComplex) {
298 // Don't handle complex yet.
299 error.SetErrorString(
300 "returning complex float values are not supported");
301 } else {
302 const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
303
304 if (v0_info) {
305 if (byte_size <= 16) {
306 RegisterValue reg_value;
307 error = reg_value.SetValueFromData(*v0_info, data, 0, true);
308 if (error.Success())
309 if (!reg_ctx->WriteRegister(v0_info, reg_value))
310 error.SetErrorString("failed to write register v0");
311 } else {
312 error.SetErrorString("returning float values longer than 128 "
313 "bits are not supported");
314 }
315 } else
316 error.SetErrorString("v0 register is not available on this target");
317 }
318 }
319 } else if (type_flags & eTypeIsVector) {
320 if (byte_size > 0) {
321 const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
322
323 if (v0_info) {
324 if (byte_size <= v0_info->byte_size) {
325 RegisterValue reg_value;
326 error = reg_value.SetValueFromData(*v0_info, data, 0, true);
327 if (error.Success()) {
328 if (!reg_ctx->WriteRegister(v0_info, reg_value))
329 error.SetErrorString("failed to write register v0");
330 }
331 }
332 }
333 }
334 }
335 } else {
336 error.SetErrorString("no registers are available");
337 }
338
339 return error;
340}
341
343 unwind_plan.Clear();
345
346 uint32_t lr_reg_num = arm64_dwarf::lr;
347 uint32_t sp_reg_num = arm64_dwarf::sp;
348 uint32_t pc_reg_num = arm64_dwarf::pc;
349
351
352 // Our previous Call Frame Address is the stack pointer
353 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
354
355 // Our previous PC is in the LR
356 row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
357
358 unwind_plan.AppendRow(row);
359
360 // All other registers are the same.
361
362 unwind_plan.SetSourceName("arm64 at-func-entry default");
364
365 return true;
366}
367
369 unwind_plan.Clear();
371
372 uint32_t fp_reg_num = arm64_dwarf::fp;
373 uint32_t pc_reg_num = arm64_dwarf::pc;
374
376 const int32_t ptr_size = 8;
377
378 row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
379 row->SetOffset(0);
380 row->SetUnspecifiedRegistersAreUndefined(true);
381
382 row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);
383 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);
384
385 unwind_plan.AppendRow(row);
386 unwind_plan.SetSourceName("arm64-apple-darwin default unwind plan");
390 return true;
391}
392
393// AAPCS64 (Procedure Call Standard for the ARM 64-bit Architecture) says
394// registers x19 through x28 and sp are callee preserved. v8-v15 are non-
395// volatile (and specifically only the lower 8 bytes of these regs), the rest
396// of the fp/SIMD registers are volatile.
397//
398// v. https://github.com/ARM-software/abi-aa/blob/main/aapcs64/
399
400// We treat x29 as callee preserved also, else the unwinder won't try to
401// retrieve fp saves.
402
404 if (reg_info) {
405 const char *name = reg_info->name;
406
407 // Sometimes we'll be called with the "alternate" name for these registers;
408 // recognize them as non-volatile.
409
410 if (name[0] == 'p' && name[1] == 'c') // pc
411 return false;
412 if (name[0] == 'f' && name[1] == 'p') // fp
413 return false;
414 if (name[0] == 's' && name[1] == 'p') // sp
415 return false;
416 if (name[0] == 'l' && name[1] == 'r') // lr
417 return false;
418
419 if (name[0] == 'x') {
420 // Volatile registers: x0-x18, x30 (lr)
421 // Return false for the non-volatile gpr regs, true for everything else
422 switch (name[1]) {
423 case '1':
424 switch (name[2]) {
425 case '9':
426 return false; // x19 is non-volatile
427 default:
428 return true;
429 }
430 break;
431 case '2':
432 switch (name[2]) {
433 case '0':
434 case '1':
435 case '2':
436 case '3':
437 case '4':
438 case '5':
439 case '6':
440 case '7':
441 case '8':
442 return false; // x20 - 28 are non-volatile
443 case '9':
444 return false; // x29 aka fp treat as non-volatile on Darwin
445 default:
446 return true;
447 }
448 case '3': // x30 aka lr treat as non-volatile
449 if (name[2] == '0')
450 return false;
451 break;
452 default:
453 return true;
454 }
455 } else if (name[0] == 'v' || name[0] == 's' || name[0] == 'd') {
456 // Volatile registers: v0-7, v16-v31
457 // Return false for non-volatile fp/SIMD regs, true for everything else
458 switch (name[1]) {
459 case '8':
460 case '9':
461 return false; // v8-v9 are non-volatile
462 case '1':
463 switch (name[2]) {
464 case '0':
465 case '1':
466 case '2':
467 case '3':
468 case '4':
469 case '5':
470 return false; // v10-v15 are non-volatile
471 default:
472 return true;
473 }
474 default:
475 return true;
476 }
477 }
478 }
479 return true;
480}
481
483 ExecutionContext &exe_ctx, RegisterContext *reg_ctx,
484 const CompilerType &value_type,
485 bool is_return_value, // false => parameter, true => return value
486 uint32_t &NGRN, // NGRN (see ABI documentation)
487 uint32_t &NSRN, // NSRN (see ABI documentation)
488 DataExtractor &data) {
489 std::optional<uint64_t> byte_size =
490 value_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
491 if (!byte_size || *byte_size == 0)
492 return false;
493
494 std::unique_ptr<DataBufferHeap> heap_data_up(
495 new DataBufferHeap(*byte_size, 0));
496 const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();
498
499 CompilerType base_type;
500 const uint32_t homogeneous_count =
501 value_type.IsHomogeneousAggregate(&base_type);
502 if (homogeneous_count > 0 && homogeneous_count <= 8) {
503 // Make sure we have enough registers
504 if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
505 if (!base_type)
506 return false;
507 std::optional<uint64_t> base_byte_size =
508 base_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
509 if (!base_byte_size)
510 return false;
511 uint32_t data_offset = 0;
512
513 for (uint32_t i = 0; i < homogeneous_count; ++i) {
514 char v_name[8];
515 ::snprintf(v_name, sizeof(v_name), "v%u", NSRN);
516 const RegisterInfo *reg_info =
517 reg_ctx->GetRegisterInfoByName(v_name, 0);
518 if (reg_info == nullptr)
519 return false;
520
521 if (*base_byte_size > reg_info->byte_size)
522 return false;
523
524 RegisterValue reg_value;
525
526 if (!reg_ctx->ReadRegister(reg_info, reg_value))
527 return false;
528
529 // Make sure we have enough room in "heap_data_up"
530 if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
531 const size_t bytes_copied = reg_value.GetAsMemoryData(
532 *reg_info, heap_data_up->GetBytes() + data_offset,
533 *base_byte_size, byte_order, error);
534 if (bytes_copied != *base_byte_size)
535 return false;
536 data_offset += bytes_copied;
537 ++NSRN;
538 } else
539 return false;
540 }
541 data.SetByteOrder(byte_order);
543 data.SetData(DataBufferSP(heap_data_up.release()));
544 return true;
545 }
546 }
547
548 const size_t max_reg_byte_size = 16;
549 if (*byte_size <= max_reg_byte_size) {
550 size_t bytes_left = *byte_size;
551 uint32_t data_offset = 0;
552 while (data_offset < *byte_size) {
553 if (NGRN >= 8)
554 return false;
555
556 uint32_t reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
558 if (reg_num == LLDB_INVALID_REGNUM)
559 return false;
560
561 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_num);
562 if (reg_info == nullptr)
563 return false;
564
565 RegisterValue reg_value;
566
567 if (!reg_ctx->ReadRegister(reg_info, reg_value))
568 return false;
569
570 const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
571 const size_t bytes_copied = reg_value.GetAsMemoryData(
572 *reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
573 byte_order, error);
574 if (bytes_copied == 0)
575 return false;
576 if (bytes_copied >= bytes_left)
577 break;
578 data_offset += bytes_copied;
579 bytes_left -= bytes_copied;
580 ++NGRN;
581 }
582 } else {
583 const RegisterInfo *reg_info = nullptr;
584 if (is_return_value) {
585 // The Darwin arm64 ABI doesn't write the return location back to x8
586 // before returning from the function the way the x86_64 ABI does. So
587 // we can't reconstruct stack based returns on exit from the function:
588 return false;
589 } else {
590 // We are assuming we are stopped at the first instruction in a function
591 // and that the ABI is being respected so all parameters appear where
592 // they should be (functions with no external linkage can legally violate
593 // the ABI).
594 if (NGRN >= 8)
595 return false;
596
597 uint32_t reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(
599 if (reg_num == LLDB_INVALID_REGNUM)
600 return false;
601 reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_num);
602 if (reg_info == nullptr)
603 return false;
604 ++NGRN;
605 }
606
607 const lldb::addr_t value_addr =
609
610 if (value_addr == LLDB_INVALID_ADDRESS)
611 return false;
612
613 if (exe_ctx.GetProcessRef().ReadMemory(
614 value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
615 error) != heap_data_up->GetByteSize()) {
616 return false;
617 }
618 }
619
620 data.SetByteOrder(byte_order);
622 data.SetData(DataBufferSP(heap_data_up.release()));
623 return true;
624}
625
627 Thread &thread, CompilerType &return_compiler_type) const {
628 ValueObjectSP return_valobj_sp;
629 Value value;
630
631 ExecutionContext exe_ctx(thread.shared_from_this());
632 if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)
633 return return_valobj_sp;
634
635 // value.SetContext (Value::eContextTypeClangType, return_compiler_type);
636 value.SetCompilerType(return_compiler_type);
637
638 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
639 if (!reg_ctx)
640 return return_valobj_sp;
641
642 std::optional<uint64_t> byte_size = return_compiler_type.GetByteSize(&thread);
643 if (!byte_size)
644 return return_valobj_sp;
645
646 const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr);
647 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
648 value.SetValueType(Value::ValueType::Scalar);
649
650 bool success = false;
651 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
652 // Extract the register context so we can read arguments from registers
653 if (*byte_size <= 8) {
654 const RegisterInfo *x0_reg_info =
655 reg_ctx->GetRegisterInfoByName("x0", 0);
656 if (x0_reg_info) {
657 uint64_t raw_value =
658 thread.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info,
659 0);
660 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
661 switch (*byte_size) {
662 default:
663 break;
664 case 16: // uint128_t
665 // In register x0 and x1
666 {
667 const RegisterInfo *x1_reg_info =
668 reg_ctx->GetRegisterInfoByName("x1", 0);
669
670 if (x1_reg_info) {
671 if (*byte_size <=
672 x0_reg_info->byte_size + x1_reg_info->byte_size) {
673 std::unique_ptr<DataBufferHeap> heap_data_up(
674 new DataBufferHeap(*byte_size, 0));
675 const ByteOrder byte_order =
676 exe_ctx.GetProcessRef().GetByteOrder();
677 RegisterValue x0_reg_value;
678 RegisterValue x1_reg_value;
679 if (reg_ctx->ReadRegister(x0_reg_info, x0_reg_value) &&
680 reg_ctx->ReadRegister(x1_reg_info, x1_reg_value)) {
682 if (x0_reg_value.GetAsMemoryData(
683 *x0_reg_info, heap_data_up->GetBytes() + 0, 8,
684 byte_order, error) &&
685 x1_reg_value.GetAsMemoryData(
686 *x1_reg_info, heap_data_up->GetBytes() + 8, 8,
687 byte_order, error)) {
688 DataExtractor data(
689 DataBufferSP(heap_data_up.release()), byte_order,
691
692 return_valobj_sp = ValueObjectConstResult::Create(
693 &thread, return_compiler_type, ConstString(""), data);
694 return return_valobj_sp;
695 }
696 }
697 }
698 }
699 }
700 break;
701 case sizeof(uint64_t):
702 if (is_signed)
703 value.GetScalar() = (int64_t)(raw_value);
704 else
705 value.GetScalar() = (uint64_t)(raw_value);
706 success = true;
707 break;
708
709 case sizeof(uint32_t):
710 if (is_signed)
711 value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
712 else
713 value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
714 success = true;
715 break;
716
717 case sizeof(uint16_t):
718 if (is_signed)
719 value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
720 else
721 value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
722 success = true;
723 break;
724
725 case sizeof(uint8_t):
726 if (is_signed)
727 value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
728 else
729 value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
730 success = true;
731 break;
732 }
733 }
734 }
735 } else if (type_flags & eTypeIsFloat) {
736 if (type_flags & eTypeIsComplex) {
737 // Don't handle complex yet.
738 } else {
739 if (*byte_size <= sizeof(long double)) {
740 const RegisterInfo *v0_reg_info =
741 reg_ctx->GetRegisterInfoByName("v0", 0);
742 RegisterValue v0_value;
743 if (reg_ctx->ReadRegister(v0_reg_info, v0_value)) {
744 DataExtractor data;
745 if (v0_value.GetData(data)) {
746 lldb::offset_t offset = 0;
747 if (*byte_size == sizeof(float)) {
748 value.GetScalar() = data.GetFloat(&offset);
749 success = true;
750 } else if (*byte_size == sizeof(double)) {
751 value.GetScalar() = data.GetDouble(&offset);
752 success = true;
753 } else if (*byte_size == sizeof(long double)) {
754 value.GetScalar() = data.GetLongDouble(&offset);
755 success = true;
756 }
757 }
758 }
759 }
760 }
761 }
762
763 if (success)
764 return_valobj_sp = ValueObjectConstResult::Create(
765 thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
766 } else if (type_flags & eTypeIsVector) {
767 if (*byte_size > 0) {
768
769 const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
770
771 if (v0_info) {
772 if (*byte_size <= v0_info->byte_size) {
773 std::unique_ptr<DataBufferHeap> heap_data_up(
774 new DataBufferHeap(*byte_size, 0));
775 const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();
776 RegisterValue reg_value;
777 if (reg_ctx->ReadRegister(v0_info, reg_value)) {
779 if (reg_value.GetAsMemoryData(*v0_info, heap_data_up->GetBytes(),
780 heap_data_up->GetByteSize(),
781 byte_order, error)) {
782 DataExtractor data(DataBufferSP(heap_data_up.release()),
783 byte_order,
785 return_valobj_sp = ValueObjectConstResult::Create(
786 &thread, return_compiler_type, ConstString(""), data);
787 }
788 }
789 }
790 }
791 }
792 } else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass) {
793 DataExtractor data;
794
795 uint32_t NGRN = 0; // Search ABI docs for NGRN
796 uint32_t NSRN = 0; // Search ABI docs for NSRN
797 const bool is_return_value = true;
799 exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
800 data)) {
801 return_valobj_sp = ValueObjectConstResult::Create(
802 &thread, return_compiler_type, ConstString(""), data);
803 }
804 }
805 return return_valobj_sp;
806}
807
809 addr_t pac_sign_extension = 0x0080000000000000ULL;
810 addr_t tbi_mask = 0xff80000000000000ULL;
811 addr_t mask = 0;
812
813 if (ProcessSP process_sp = GetProcessSP()) {
814 mask = process_sp->GetCodeAddressMask();
815 if (pc & pac_sign_extension) {
816 addr_t highmem_mask = process_sp->GetHighmemCodeAddressMask();
817 if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
818 mask = highmem_mask;
819 }
820 }
821 if (mask == LLDB_INVALID_ADDRESS_MASK)
822 mask = tbi_mask;
823
824 return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
825}
826
828 addr_t pac_sign_extension = 0x0080000000000000ULL;
829 addr_t tbi_mask = 0xff80000000000000ULL;
830 addr_t mask = 0;
831
832 if (ProcessSP process_sp = GetProcessSP()) {
833 mask = process_sp->GetDataAddressMask();
834 if (pc & pac_sign_extension) {
835 addr_t highmem_mask = process_sp->GetHighmemDataAddressMask();
836 if (highmem_mask != LLDB_INVALID_ADDRESS_MASK)
837 mask = highmem_mask;
838 }
839 }
840 if (mask == LLDB_INVALID_ADDRESS_MASK)
841 mask = tbi_mask;
842
843 return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
844}
845
849}
850
853}
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:366
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:450
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:137
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:2265
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:1966
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3454
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3458
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:44
bool Fail() const
Test for error condition.
Definition: Status.cpp:180
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:129
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:405
virtual lldb::RegisterContextSP GetRegisterContext()=0
void SetUnwindPlanForSignalTrap(lldb_private::LazyBool is_for_signal_trap)
Definition: UnwindPlan.h:502
void SetRegisterKind(lldb::RegisterKind kind)
Definition: UnwindPlan.h:437
void AppendRow(const RowSP &row_sp)
Definition: UnwindPlan.cpp:362
std::shared_ptr< Row > RowSP
Definition: UnwindPlan.h:395
void SetSourcedFromCompiler(lldb_private::LazyBool from_compiler)
Definition: UnwindPlan.h:478
void SetSourceName(const char *)
Definition: UnwindPlan.cpp:564
void SetUnwindPlanValidAtAllInstructions(lldb_private::LazyBool valid_at_all_insn)
Definition: UnwindPlan.h:490
Value * GetValueAtIndex(size_t idx)
Definition: Value.cpp:686
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:331
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ABI > ABISP
Definition: lldb-forward.h:312
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:415
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:475
uint64_t offset_t
Definition: lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:384
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:331
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