LLDB mainline
ABISysV_arm64.cpp
Go to the documentation of this file.
1//===-- ABISysV_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 "ABISysV_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
39 name = "x0";
40 return true;
41}
42
43size_t ABISysV_arm64::GetRedZoneSize() const { return 128; }
44
45// Static Functions
46
49 const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();
50 const llvm::Triple::VendorType vendor_type = arch.GetTriple().getVendor();
51
52 if (vendor_type != llvm::Triple::Apple) {
53 if (arch_type == llvm::Triple::aarch64 ||
54 arch_type == llvm::Triple::aarch64_32) {
55 return ABISP(
56 new ABISysV_arm64(std::move(process_sp), MakeMCRegisterInfo(arch)));
57 }
58 }
59
60 return ABISP();
61}
62
64 addr_t func_addr, addr_t return_addr,
65 llvm::ArrayRef<addr_t> args) const {
66 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
67 if (!reg_ctx)
68 return false;
69
70 Log *log = GetLog(LLDBLog::Expressions);
71
72 if (log) {
74 s.Printf("ABISysV_arm64::PrepareTrivialCall (tid = 0x%" PRIx64
75 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
76 ", return_addr = 0x%" PRIx64,
77 thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
78 (uint64_t)return_addr);
79
80 for (size_t i = 0; i < args.size(); ++i)
81 s.Printf(", arg%d = 0x%" PRIx64, static_cast<int>(i + 1), args[i]);
82 s.PutCString(")");
83 log->PutString(s.GetString());
84 }
85
86 // x0 - x7 contain first 8 simple args
87 if (args.size() > 8)
88 return false;
89
90 for (size_t i = 0; i < args.size(); ++i) {
91 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(
93 LLDB_LOGF(log, "About to write arg%d (0x%" PRIx64 ") into %s",
94 static_cast<int>(i + 1), args[i], reg_info->name);
95 if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
96 return false;
97 }
98
99 // Set "lr" to the return address
100 if (!reg_ctx->WriteRegisterFromUnsigned(
103 return_addr))
104 return false;
105
106 // Set "sp" to the requested value
107 if (!reg_ctx->WriteRegisterFromUnsigned(
110 sp))
111 return false;
112
113 // Set "pc" to the address requested
114 if (!reg_ctx->WriteRegisterFromUnsigned(
117 func_addr))
118 return false;
119
120 return true;
121}
122
123// TODO: We dont support fp/SIMD arguments in v0-v7
125 uint32_t num_values = values.GetSize();
126
127 ExecutionContext exe_ctx(thread.shared_from_this());
128
129 // Extract the register context so we can read arguments from registers
130
131 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
132
133 if (!reg_ctx)
134 return false;
135
136 addr_t sp = 0;
137
138 for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
139 // We currently only support extracting values with Clang QualTypes. Do we
140 // care about others?
141 Value *value = values.GetValueAtIndex(value_idx);
142
143 if (!value)
144 return false;
145
146 CompilerType value_type = value->GetCompilerType();
147 if (value_type) {
148 bool is_signed = false;
149 size_t bit_width = 0;
150 std::optional<uint64_t> bit_size = value_type.GetBitSize(&thread);
151 if (!bit_size)
152 return false;
153 if (value_type.IsIntegerOrEnumerationType(is_signed)) {
154 bit_width = *bit_size;
155 } else if (value_type.IsPointerOrReferenceType()) {
156 bit_width = *bit_size;
157 } else {
158 // We only handle integer, pointer and reference types currently...
159 return false;
160 }
161
162 if (bit_width <= (exe_ctx.GetProcessRef().GetAddressByteSize() * 8)) {
163 if (value_idx < 8) {
164 // Arguments 1-8 are in x0-x7...
165 const RegisterInfo *reg_info = nullptr;
166 reg_info = reg_ctx->GetRegisterInfo(
168
169 if (reg_info) {
170 RegisterValue reg_value;
171
172 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
173 if (is_signed)
174 reg_value.SignExtend(bit_width);
175 if (!reg_value.GetScalarValue(value->GetScalar()))
176 return false;
177 continue;
178 }
179 }
180 return false;
181 } else {
182 // TODO: Verify for stack layout for SysV
183 if (sp == 0) {
184 // Read the stack pointer if we already haven't read it
185 sp = reg_ctx->GetSP(0);
186 if (sp == 0)
187 return false;
188 }
189
190 // Arguments 5 on up are on the stack
191 const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
194 sp, arg_byte_size, is_signed, value->GetScalar(), error))
195 return false;
196
197 sp += arg_byte_size;
198 // Align up to the next 8 byte boundary if needed
199 if (sp % 8) {
200 sp >>= 3;
201 sp += 1;
202 sp <<= 3;
203 }
204 }
205 }
206 }
207 }
208 return true;
209}
210
212 lldb::ValueObjectSP &new_value_sp) {
214 if (!new_value_sp) {
215 error = Status::FromErrorString("Empty value object for return value.");
216 return error;
217 }
218
219 CompilerType return_value_type = new_value_sp->GetCompilerType();
220 if (!return_value_type) {
221 error = Status::FromErrorString("Null clang type for return value.");
222 return error;
223 }
224
225 Thread *thread = frame_sp->GetThread().get();
226
227 RegisterContext *reg_ctx = thread->GetRegisterContext().get();
228
229 if (reg_ctx) {
230 DataExtractor data;
231 Status data_error;
232 const uint64_t byte_size = new_value_sp->GetData(data, data_error);
233 if (data_error.Fail()) {
235 "Couldn't convert return value to raw data: %s",
236 data_error.AsCString());
237 return error;
238 }
239
240 const uint32_t type_flags = return_value_type.GetTypeInfo(nullptr);
241 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
242 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
243 // Extract the register context so we can read arguments from registers
244 lldb::offset_t offset = 0;
245 if (byte_size <= 16) {
246 const RegisterInfo *x0_info = reg_ctx->GetRegisterInfo(
248 if (byte_size <= 8) {
249 uint64_t raw_value = data.GetMaxU64(&offset, byte_size);
250
251 if (!reg_ctx->WriteRegisterFromUnsigned(x0_info, raw_value))
252 error = Status::FromErrorString("failed to write register x0");
253 } else {
254 uint64_t raw_value = data.GetMaxU64(&offset, 8);
255
256 if (reg_ctx->WriteRegisterFromUnsigned(x0_info, raw_value)) {
257 const RegisterInfo *x1_info = reg_ctx->GetRegisterInfo(
259 raw_value = data.GetMaxU64(&offset, byte_size - offset);
260
261 if (!reg_ctx->WriteRegisterFromUnsigned(x1_info, raw_value))
262 error = Status::FromErrorString("failed to write register x1");
263 }
264 }
265 } else {
267 "We don't support returning longer than 128 bit "
268 "integer values at present.");
269 }
270 } else if (type_flags & eTypeIsFloat) {
271 if (type_flags & eTypeIsComplex) {
272 // Don't handle complex yet.
274 "returning complex float values are not supported");
275 } else {
276 const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
277
278 if (v0_info) {
279 if (byte_size <= 16) {
280 RegisterValue reg_value;
281 error = reg_value.SetValueFromData(*v0_info, data, 0, true);
282 if (error.Success())
283 if (!reg_ctx->WriteRegister(v0_info, reg_value))
284 error =
285 Status::FromErrorString("failed to write register v0");
286 } else {
288 "returning float values longer than 128 "
289 "bits are not supported");
290 }
291 } else
293 "v0 register is not available on this target");
294 }
295 }
296 } else if (type_flags & eTypeIsVector) {
297 if (byte_size > 0) {
298 const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
299
300 if (v0_info) {
301 if (byte_size <= v0_info->byte_size) {
302 RegisterValue reg_value;
303 error = reg_value.SetValueFromData(*v0_info, data, 0, true);
304 if (error.Success()) {
305 if (!reg_ctx->WriteRegister(v0_info, reg_value))
306 error = Status::FromErrorString("failed to write register v0");
307 }
308 }
309 }
310 }
311 }
312 } else {
313 error = Status::FromErrorString("no registers are available");
314 }
315
316 return error;
317}
318
320 unwind_plan.Clear();
322
323 uint32_t lr_reg_num = arm64_dwarf::lr;
324 uint32_t sp_reg_num = arm64_dwarf::sp;
325
327
328 // Our previous Call Frame Address is the stack pointer
329 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
330
331 unwind_plan.AppendRow(row);
332 unwind_plan.SetReturnAddressRegister(lr_reg_num);
333
334 // All other registers are the same.
335
336 unwind_plan.SetSourceName("arm64 at-func-entry default");
340
341 return true;
342}
343
345 unwind_plan.Clear();
347
348 uint32_t fp_reg_num = arm64_dwarf::fp;
349 uint32_t pc_reg_num = arm64_dwarf::pc;
350
352 const int32_t ptr_size = 8;
353
354 row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
355 row->SetOffset(0);
356 row->SetUnspecifiedRegistersAreUndefined(true);
357
358 row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);
359 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);
360
361 unwind_plan.AppendRow(row);
362 unwind_plan.SetSourceName("arm64 default unwind plan");
366
367 return true;
368}
369
370// AAPCS64 (Procedure Call Standard for the ARM 64-bit Architecture) says
371// registers x19 through x28 and sp are callee preserved. v8-v15 are non-
372// volatile (and specifically only the lower 8 bytes of these regs), the rest
373// of the fp/SIMD registers are volatile.
374
375// We treat x29 as callee preserved also, else the unwinder won't try to
376// retrieve fp saves.
377
379 if (reg_info) {
380 const char *name = reg_info->name;
381
382 // Sometimes we'll be called with the "alternate" name for these registers;
383 // recognize them as non-volatile.
384
385 if (name[0] == 'p' && name[1] == 'c') // pc
386 return false;
387 if (name[0] == 'f' && name[1] == 'p') // fp
388 return false;
389 if (name[0] == 's' && name[1] == 'p') // sp
390 return false;
391 if (name[0] == 'l' && name[1] == 'r') // lr
392 return false;
393
394 if (name[0] == 'x' || name[0] == 'r') {
395 // Volatile registers: x0-x18
396 // Although documentation says only x19-28 + sp are callee saved We ll
397 // also have to treat x30 as non-volatile. Each dwarf frame has its own
398 // value of lr. Return false for the non-volatile gpr regs, true for
399 // everything else
400 switch (name[1]) {
401 case '1':
402 switch (name[2]) {
403 case '9':
404 return false; // x19 is non-volatile
405 default:
406 return true;
407 }
408 break;
409 case '2':
410 switch (name[2]) {
411 case '0':
412 case '1':
413 case '2':
414 case '3':
415 case '4':
416 case '5':
417 case '6':
418 case '7':
419 case '8':
420 return false; // x20 - 28 are non-volatile
421 case '9':
422 return false; // x29 aka fp treat as non-volatile
423 default:
424 return true;
425 }
426 case '3': // x30 (lr) and x31 (sp) treat as non-volatile
427 if (name[2] == '0' || name[2] == '1')
428 return false;
429 break;
430 default:
431 return true; // all volatile cases not handled above fall here.
432 }
433 } else if (name[0] == 'v' || name[0] == 's' || name[0] == 'd') {
434 // Volatile registers: v0-7, v16-v31
435 // Return false for non-volatile fp/SIMD regs, true for everything else
436 switch (name[1]) {
437 case '8':
438 case '9':
439 return false; // v8-v9 are non-volatile
440 case '1':
441 switch (name[2]) {
442 case '0':
443 case '1':
444 case '2':
445 case '3':
446 case '4':
447 case '5':
448 return false; // v10-v15 are non-volatile
449 default:
450 return true;
451 }
452 default:
453 return true;
454 }
455 }
456 }
457 return true;
458}
459
461 ExecutionContext &exe_ctx, RegisterContext *reg_ctx,
462 const CompilerType &value_type,
463 bool is_return_value, // false => parameter, true => return value
464 uint32_t &NGRN, // NGRN (see ABI documentation)
465 uint32_t &NSRN, // NSRN (see ABI documentation)
466 DataExtractor &data) {
467 std::optional<uint64_t> byte_size =
468 value_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
469
470 if (byte_size || *byte_size == 0)
471 return false;
472
473 std::unique_ptr<DataBufferHeap> heap_data_up(
474 new DataBufferHeap(*byte_size, 0));
475 const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();
477
478 CompilerType base_type;
479 const uint32_t homogeneous_count =
480 value_type.IsHomogeneousAggregate(&base_type);
481 if (homogeneous_count > 0 && homogeneous_count <= 8) {
482 // Make sure we have enough registers
483 if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
484 if (!base_type)
485 return false;
486 std::optional<uint64_t> base_byte_size =
487 base_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
488 if (!base_byte_size)
489 return false;
490 uint32_t data_offset = 0;
491
492 for (uint32_t i = 0; i < homogeneous_count; ++i) {
493 char v_name[8];
494 ::snprintf(v_name, sizeof(v_name), "v%u", NSRN);
495 const RegisterInfo *reg_info =
496 reg_ctx->GetRegisterInfoByName(v_name, 0);
497 if (reg_info == nullptr)
498 return false;
499
500 if (*base_byte_size > reg_info->byte_size)
501 return false;
502
503 RegisterValue reg_value;
504
505 if (!reg_ctx->ReadRegister(reg_info, reg_value))
506 return false;
507
508 // Make sure we have enough room in "heap_data_up"
509 if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
510 const size_t bytes_copied = reg_value.GetAsMemoryData(
511 *reg_info, heap_data_up->GetBytes() + data_offset,
512 *base_byte_size, byte_order, error);
513 if (bytes_copied != *base_byte_size)
514 return false;
515 data_offset += bytes_copied;
516 ++NSRN;
517 } else
518 return false;
519 }
520 data.SetByteOrder(byte_order);
522 data.SetData(DataBufferSP(heap_data_up.release()));
523 return true;
524 }
525 }
526
527 const size_t max_reg_byte_size = 16;
528 if (*byte_size <= max_reg_byte_size) {
529 size_t bytes_left = *byte_size;
530 uint32_t data_offset = 0;
531 while (data_offset < *byte_size) {
532 if (NGRN >= 8)
533 return false;
534
535 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(
537 if (reg_info == nullptr)
538 return false;
539
540 RegisterValue reg_value;
541
542 if (!reg_ctx->ReadRegister(reg_info, reg_value))
543 return false;
544
545 const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
546 const size_t bytes_copied = reg_value.GetAsMemoryData(
547 *reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
548 byte_order, error);
549 if (bytes_copied == 0)
550 return false;
551 if (bytes_copied >= bytes_left)
552 break;
553 data_offset += bytes_copied;
554 bytes_left -= bytes_copied;
555 ++NGRN;
556 }
557 } else {
558 const RegisterInfo *reg_info = nullptr;
559 if (is_return_value) {
560 // The SysV arm64 ABI doesn't require you to write the return location
561 // back to x8 before returning from the function the way the x86_64 ABI
562 // does. It looks like all the users of this ABI currently choose not to
563 // do that, and so we can't reconstruct stack based returns on exit
564 // from the function.
565 return false;
566 } else {
567 // We are assuming we are stopped at the first instruction in a function
568 // and that the ABI is being respected so all parameters appear where
569 // they should be (functions with no external linkage can legally violate
570 // the ABI).
571 if (NGRN >= 8)
572 return false;
573
574 reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
576 if (reg_info == nullptr)
577 return false;
578 ++NGRN;
579 }
580
581 const lldb::addr_t value_addr =
583
584 if (value_addr == LLDB_INVALID_ADDRESS)
585 return false;
586
587 if (exe_ctx.GetProcessRef().ReadMemory(
588 value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
589 error) != heap_data_up->GetByteSize()) {
590 return false;
591 }
592 }
593
594 data.SetByteOrder(byte_order);
596 data.SetData(DataBufferSP(heap_data_up.release()));
597 return true;
598}
599
601 Thread &thread, CompilerType &return_compiler_type) const {
602 ValueObjectSP return_valobj_sp;
603 Value value;
604
605 ExecutionContext exe_ctx(thread.shared_from_this());
606 if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)
607 return return_valobj_sp;
608
609 // value.SetContext (Value::eContextTypeClangType, return_compiler_type);
610 value.SetCompilerType(return_compiler_type);
611
612 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
613 if (!reg_ctx)
614 return return_valobj_sp;
615
616 std::optional<uint64_t> byte_size = return_compiler_type.GetByteSize(&thread);
617 if (!byte_size)
618 return return_valobj_sp;
619
620 const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr);
621 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
622 value.SetValueType(Value::ValueType::Scalar);
623
624 bool success = false;
625 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
626 // Extract the register context so we can read arguments from registers
627 if (*byte_size <= 8) {
628 const RegisterInfo *x0_reg_info = nullptr;
629 x0_reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
631 if (x0_reg_info) {
632 uint64_t raw_value =
633 thread.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info,
634 0);
635 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
636 switch (*byte_size) {
637 default:
638 break;
639 case 16: // uint128_t
640 // In register x0 and x1
641 {
642 const RegisterInfo *x1_reg_info = nullptr;
643 x1_reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
645
646 if (x1_reg_info) {
647 if (*byte_size <=
648 x0_reg_info->byte_size + x1_reg_info->byte_size) {
649 std::unique_ptr<DataBufferHeap> heap_data_up(
650 new DataBufferHeap(*byte_size, 0));
651 const ByteOrder byte_order =
652 exe_ctx.GetProcessRef().GetByteOrder();
653 RegisterValue x0_reg_value;
654 RegisterValue x1_reg_value;
655 if (reg_ctx->ReadRegister(x0_reg_info, x0_reg_value) &&
656 reg_ctx->ReadRegister(x1_reg_info, x1_reg_value)) {
658 if (x0_reg_value.GetAsMemoryData(
659 *x0_reg_info, heap_data_up->GetBytes() + 0, 8,
660 byte_order, error) &&
661 x1_reg_value.GetAsMemoryData(
662 *x1_reg_info, heap_data_up->GetBytes() + 8, 8,
663 byte_order, error)) {
664 DataExtractor data(
665 DataBufferSP(heap_data_up.release()), byte_order,
667
668 return_valobj_sp = ValueObjectConstResult::Create(
669 &thread, return_compiler_type, ConstString(""), data);
670 return return_valobj_sp;
671 }
672 }
673 }
674 }
675 }
676 break;
677 case sizeof(uint64_t):
678 if (is_signed)
679 value.GetScalar() = (int64_t)(raw_value);
680 else
681 value.GetScalar() = (uint64_t)(raw_value);
682 success = true;
683 break;
684
685 case sizeof(uint32_t):
686 if (is_signed)
687 value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
688 else
689 value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
690 success = true;
691 break;
692
693 case sizeof(uint16_t):
694 if (is_signed)
695 value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
696 else
697 value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
698 success = true;
699 break;
700
701 case sizeof(uint8_t):
702 if (is_signed)
703 value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
704 else
705 value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
706 success = true;
707 break;
708 }
709 }
710 }
711 } else if (type_flags & eTypeIsFloat) {
712 if (type_flags & eTypeIsComplex) {
713 // Don't handle complex yet.
714 } else {
715 if (*byte_size <= sizeof(long double)) {
716 const RegisterInfo *v0_reg_info =
717 reg_ctx->GetRegisterInfoByName("v0", 0);
718 RegisterValue v0_value;
719 if (reg_ctx->ReadRegister(v0_reg_info, v0_value)) {
720 DataExtractor data;
721 if (v0_value.GetData(data)) {
722 lldb::offset_t offset = 0;
723 if (*byte_size == sizeof(float)) {
724 value.GetScalar() = data.GetFloat(&offset);
725 success = true;
726 } else if (*byte_size == sizeof(double)) {
727 value.GetScalar() = data.GetDouble(&offset);
728 success = true;
729 } else if (*byte_size == sizeof(long double)) {
730 value.GetScalar() = data.GetLongDouble(&offset);
731 success = true;
732 }
733 }
734 }
735 }
736 }
737 }
738
739 if (success)
740 return_valobj_sp = ValueObjectConstResult::Create(
741 thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
742 } else if (type_flags & eTypeIsVector && *byte_size <= 16) {
743 if (*byte_size > 0) {
744 const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0);
745
746 if (v0_info) {
747 std::unique_ptr<DataBufferHeap> heap_data_up(
748 new DataBufferHeap(*byte_size, 0));
749 const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder();
750 RegisterValue reg_value;
751 if (reg_ctx->ReadRegister(v0_info, reg_value)) {
753 if (reg_value.GetAsMemoryData(*v0_info, heap_data_up->GetBytes(),
754 heap_data_up->GetByteSize(), byte_order,
755 error)) {
756 DataExtractor data(DataBufferSP(heap_data_up.release()), byte_order,
758 return_valobj_sp = ValueObjectConstResult::Create(
759 &thread, return_compiler_type, ConstString(""), data);
760 }
761 }
762 }
763 }
764 } else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass ||
765 (type_flags & eTypeIsVector && *byte_size > 16)) {
766 DataExtractor data;
767
768 uint32_t NGRN = 0; // Search ABI docs for NGRN
769 uint32_t NSRN = 0; // Search ABI docs for NSRN
770 const bool is_return_value = true;
772 exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
773 data)) {
774 return_valobj_sp = ValueObjectConstResult::Create(
775 &thread, return_compiler_type, ConstString(""), data);
776 }
777 }
778 return return_valobj_sp;
779}
780
782 if (mask == LLDB_INVALID_ADDRESS_MASK)
783 return pc;
784 lldb::addr_t pac_sign_extension = 0x0080000000000000ULL;
785 return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
786}
787
788// Reads code or data address mask for the current Linux process.
790 llvm::StringRef reg_name) {
791 // LLDB_INVALID_ADDRESS_MASK means there isn't a mask or it has not been read
792 // yet. We do not return the top byte mask unless thread_sp is valid. This
793 // prevents calls to this function before the thread is setup locking in the
794 // value to just the top byte mask, in cases where pointer authentication
795 // might also be active.
796 uint64_t address_mask = LLDB_INVALID_ADDRESS_MASK;
797 lldb::ThreadSP thread_sp = process_sp->GetThreadList().GetSelectedThread();
798 if (thread_sp) {
799 // Linux configures user-space virtual addresses with top byte ignored.
800 // We set default value of mask such that top byte is masked out.
801 address_mask = ~((1ULL << 56) - 1);
802 // If Pointer Authentication feature is enabled then Linux exposes
803 // PAC data and code mask register. Try reading relevant register
804 // below and merge it with default address mask calculated above.
805 lldb::RegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
806 if (reg_ctx_sp) {
807 const RegisterInfo *reg_info =
808 reg_ctx_sp->GetRegisterInfoByName(reg_name, 0);
809 if (reg_info) {
810 lldb::addr_t mask_reg_val = reg_ctx_sp->ReadRegisterAsUnsigned(
812 if (mask_reg_val != LLDB_INVALID_ADDRESS)
813 address_mask |= mask_reg_val;
814 }
815 }
816 }
817 return address_mask;
818}
819
821 if (lldb::ProcessSP process_sp = GetProcessSP()) {
822 if (process_sp->GetTarget().GetArchitecture().GetTriple().isOSLinux() &&
823 process_sp->GetCodeAddressMask() == LLDB_INVALID_ADDRESS_MASK)
824 process_sp->SetCodeAddressMask(
825 ReadLinuxProcessAddressMask(process_sp, "code_mask"));
826
827 // b55 is the highest bit outside TBI (if it's enabled), use
828 // it to determine if the high bits are set to 0 or 1.
829 const addr_t pac_sign_extension = 0x0080000000000000ULL;
830 addr_t mask = process_sp->GetCodeAddressMask();
831 // Test if the high memory mask has been overriden separately
832 if (pc & pac_sign_extension &&
833 process_sp->GetHighmemCodeAddressMask() != LLDB_INVALID_ADDRESS_MASK)
834 mask = process_sp->GetHighmemCodeAddressMask();
835
836 return FixAddress(pc, mask);
837 }
838 return pc;
839}
840
842 if (lldb::ProcessSP process_sp = GetProcessSP()) {
843 if (process_sp->GetTarget().GetArchitecture().GetTriple().isOSLinux() &&
844 process_sp->GetDataAddressMask() == LLDB_INVALID_ADDRESS_MASK)
845 process_sp->SetDataAddressMask(
846 ReadLinuxProcessAddressMask(process_sp, "data_mask"));
847
848 // b55 is the highest bit outside TBI (if it's enabled), use
849 // it to determine if the high bits are set to 0 or 1.
850 const addr_t pac_sign_extension = 0x0080000000000000ULL;
851 addr_t mask = process_sp->GetDataAddressMask();
852 // Test if the high memory mask has been overriden separately
853 if (pc & pac_sign_extension &&
854 process_sp->GetHighmemDataAddressMask() != LLDB_INVALID_ADDRESS_MASK)
855 mask = process_sp->GetHighmemDataAddressMask();
856
857 return FixAddress(pc, mask);
858 }
859 return pc;
860}
861
864 "SysV ABI for AArch64 targets", CreateInstance);
865}
866
869}
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 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 lldb::addr_t ReadLinuxProcessAddressMask(lldb::ProcessSP process_sp, llvm::StringRef reg_name)
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:376
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const override
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 void Initialize()
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
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
bool GetPointerReturnRegister(const char *&name) override
lldb::addr_t FixAddress(lldb::addr_t pc, lldb::addr_t mask) override
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
static llvm::StringRef GetPluginNameStatic()
Definition: ABISysV_arm64.h:80
size_t GetRedZoneSize() const override
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
static void Terminate()
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
uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value)
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 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)
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_REGNUM_GENERIC_ARG2
Definition: lldb-defines.h:63
#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::Thread > ThreadSP
Definition: lldb-forward.h:450
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
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 byte_size
Size in bytes of the register.
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