9#if defined(__s390x__) && defined(__linux__)
19#include <sys/ptrace.h>
43 k_num_gpr_registers_s390x,
44 "g_gpr_regnums_s390x has wrong number of register infos");
57 k_num_fpr_registers_s390x,
58 "g_fpu_regnums_s390x has wrong number of register infos");
61static const uint32_t g_linux_regnums_s390x[] = {
65static_assert((
sizeof(g_linux_regnums_s390x) /
66 sizeof(g_linux_regnums_s390x[0])) -
68 k_num_linux_registers_s390x,
69 "g_linux_regnums_s390x has wrong number of register infos");
81 g_linux_regnums_s390x},
85#define REG_CONTEXT_SIZE (sizeof(s390_regs) + sizeof(s390_fp_regs) + 4)
89#define NT_S390_LAST_BREAK 0x306
90#define NT_S390_SYSTEM_CALL 0x307
92std::unique_ptr<NativeRegisterContextLinux>
93NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
95 return std::make_unique<NativeRegisterContextLinux_s390x>(target_arch,
99llvm::Expected<ArchSpec>
100NativeRegisterContextLinux::DetermineArchitecture(
lldb::tid_t tid) {
101 return HostInfo::GetArchitecture();
107CreateRegisterInfoInterface(
const ArchSpec &target_arch) {
108 assert((HostInfo::GetArchitecture().GetAddressByteSize() == 8) &&
109 "Register setting path assumes this is a 64-bit host");
113NativeRegisterContextLinux_s390x::NativeRegisterContextLinux_s390x(
116 native_thread, CreateRegisterInfoInterface(target_arch)),
120 case llvm::Triple::systemz:
129 assert(
false &&
"Unhandled target architecture.");
137uint32_t NativeRegisterContextLinux_s390x::GetRegisterSetCount()
const {
140 if (IsRegisterSetAvailable(set_index))
147uint32_t NativeRegisterContextLinux_s390x::GetUserRegisterCount()
const {
150 const RegisterSet *set = GetRegisterSet(set_index);
158NativeRegisterContextLinux_s390x::GetRegisterSet(uint32_t set_index)
const {
159 if (!IsRegisterSetAvailable(set_index))
162 switch (GetRegisterInfoInterface().GetTargetArchitecture().GetMachine()) {
163 case llvm::Triple::systemz:
166 assert(
false &&
"Unhandled target architecture.");
173bool NativeRegisterContextLinux_s390x::IsRegisterSetAvailable(
174 uint32_t set_index)
const {
178bool NativeRegisterContextLinux_s390x::IsGPR(uint32_t reg_index)
const {
184bool NativeRegisterContextLinux_s390x::IsFPR(uint32_t reg_index)
const {
185 return (m_reg_info.first_fpr <= reg_index &&
186 reg_index <= m_reg_info.last_fpr);
190NativeRegisterContextLinux_s390x::ReadRegister(
const RegisterInfo *reg_info,
193 return Status(
"reg_info NULL");
197 return Status(
"register \"%s\" is an internal-only lldb register, cannot "
206 uint8_t *src = (uint8_t *)&m_regs + reg_info->
byte_offset;
216 assert(
false &&
"Unhandled data size.");
228 uint8_t *src = (uint8_t *)&m_fp_regs + reg_info->
byte_offset;
238 assert(
false &&
"Unhandled data size.");
244 if (reg == lldb_last_break_s390x) {
246 Status error = DoReadRegisterSet(NT_S390_LAST_BREAK, &last_break, 8);
254 if (reg == lldb_system_call_s390x) {
255 uint32_t system_call;
256 Status error = DoReadRegisterSet(NT_S390_SYSTEM_CALL, &system_call, 4);
264 return Status(
"failed - register wasn't recognized");
267Status NativeRegisterContextLinux_s390x::WriteRegister(
270 return Status(
"reg_info NULL");
274 return Status(
"register \"%s\" is an internal-only lldb register, cannot "
283 uint8_t *dst = (uint8_t *)&m_regs + reg_info->
byte_offset;
293 assert(
false &&
"Unhandled data size.");
305 uint8_t *dst = (uint8_t *)&m_fp_regs + reg_info->
byte_offset;
315 assert(
false &&
"Unhandled data size.");
321 if (reg == lldb_last_break_s390x) {
322 return Status(
"The last break address is read-only");
325 if (reg == lldb_system_call_s390x) {
327 return DoWriteRegisterSet(NT_S390_SYSTEM_CALL, &system_call, 4);
330 return Status(
"failed - register wasn't recognized");
333Status NativeRegisterContextLinux_s390x::ReadAllRegisterValues(
338 uint8_t *dst = data_sp->GetBytes();
342 memcpy(dst, GetGPRBuffer(), GetGPRSize());
348 memcpy(dst, GetFPRBuffer(), GetFPRSize());
352 DoReadRegisterSet(NT_S390_SYSTEM_CALL, dst, 4);
359 uint32_t system_call = 0;
360 DoWriteRegisterSet(NT_S390_SYSTEM_CALL, &system_call, 4);
365Status NativeRegisterContextLinux_s390x::WriteAllRegisterValues(
370 error.SetErrorStringWithFormat(
371 "NativeRegisterContextLinux_s390x::%s invalid data_sp provided",
377 error.SetErrorStringWithFormat(
378 "NativeRegisterContextLinux_s390x::%s data_sp contained mismatched "
379 "data size, expected %" PRIu64
", actual %" PRIu64,
384 const uint8_t *src = data_sp->GetBytes();
385 if (src ==
nullptr) {
386 error.SetErrorStringWithFormat(
"NativeRegisterContextLinux_s390x::%s "
387 "DataBuffer::GetBytes() returned a null "
393 memcpy(GetGPRBuffer(), src, GetGPRSize());
399 memcpy(GetFPRBuffer(), src, GetFPRSize());
406 DoWriteRegisterSet(NT_S390_SYSTEM_CALL, src, 4);
412Status NativeRegisterContextLinux_s390x::DoReadRegisterValue(
413 uint32_t offset,
const char *reg_name, uint32_t size,
415 return Status(
"DoReadRegisterValue unsupported");
418Status NativeRegisterContextLinux_s390x::DoWriteRegisterValue(
419 uint32_t offset,
const char *reg_name,
const RegisterValue &value) {
420 return Status(
"DoWriteRegisterValue unsupported");
423Status NativeRegisterContextLinux_s390x::PeekUserArea(uint32_t offset,
427 parea.len = buf_size;
428 parea.process_addr = (
addr_t)buf;
429 parea.kernel_addr = offset;
431 return NativeProcessLinux::PtraceWrapper(PTRACE_PEEKUSR_AREA,
432 m_thread.GetID(), &parea);
435Status NativeRegisterContextLinux_s390x::PokeUserArea(uint32_t offset,
439 parea.len = buf_size;
440 parea.process_addr = (
addr_t)buf;
441 parea.kernel_addr = offset;
443 return NativeProcessLinux::PtraceWrapper(PTRACE_POKEUSR_AREA,
444 m_thread.GetID(), &parea);
447Status NativeRegisterContextLinux_s390x::ReadGPR() {
448 return PeekUserArea(offsetof(user_regs_struct, psw), GetGPRBuffer(),
452Status NativeRegisterContextLinux_s390x::WriteGPR() {
453 return PokeUserArea(offsetof(user_regs_struct, psw), GetGPRBuffer(),
457Status NativeRegisterContextLinux_s390x::ReadFPR() {
458 return PeekUserArea(offsetof(user_regs_struct, fp_regs), GetGPRBuffer(),
462Status NativeRegisterContextLinux_s390x::WriteFPR() {
463 return PokeUserArea(offsetof(user_regs_struct, fp_regs), GetGPRBuffer(),
467Status NativeRegisterContextLinux_s390x::DoReadRegisterSet(uint32_t regset,
472 iov.iov_len = buf_size;
474 return ReadRegisterSet(&iov, buf_size, regset);
477Status NativeRegisterContextLinux_s390x::DoWriteRegisterSet(uint32_t regset,
481 iov.iov_base =
const_cast<void *
>(buf);
482 iov.iov_len = buf_size;
484 return WriteRegisterSet(&iov, buf_size, regset);
487Status NativeRegisterContextLinux_s390x::IsWatchpointHit(uint32_t wp_index,
489 per_lowcore_bits per_lowcore;
491 if (wp_index >= NumSupportedHardwareWatchpoints())
492 return Status(
"Watchpoint index out of range");
499 Status error = PeekUserArea(offsetof(user_regs_struct, per_info.lowcore),
500 &per_lowcore,
sizeof(per_lowcore));
506 is_hit = (per_lowcore.perc_storage_alteration == 1 &&
507 per_lowcore.perc_store_real_address == 0);
511 memset(&per_lowcore, 0,
sizeof(per_lowcore));
512 PokeUserArea(offsetof(user_regs_struct, per_info.lowcore), &per_lowcore,
513 sizeof(per_lowcore));
519Status NativeRegisterContextLinux_s390x::GetWatchpointHitIndex(
521 uint32_t num_hw_wps = NumSupportedHardwareWatchpoints();
522 for (wp_index = 0; wp_index < num_hw_wps; ++wp_index) {
536Status NativeRegisterContextLinux_s390x::IsWatchpointVacant(uint32_t wp_index,
538 if (wp_index >= NumSupportedHardwareWatchpoints())
539 return Status(
"Watchpoint index out of range");
546bool NativeRegisterContextLinux_s390x::ClearHardwareWatchpoint(
550 if (wp_index >= NumSupportedHardwareWatchpoints())
553 Status error = PeekUserArea(offsetof(user_regs_struct, per_info), &per_info,
558 per_info.control_regs.bits.em_storage_alteration = 0;
559 per_info.control_regs.bits.storage_alt_space_ctl = 0;
560 per_info.starting_addr = 0;
561 per_info.ending_addr = 0;
563 error = PokeUserArea(offsetof(user_regs_struct, per_info), &per_info,
572Status NativeRegisterContextLinux_s390x::ClearAllHardwareWatchpoints() {
573 if (ClearHardwareWatchpoint(0))
575 return Status(
"Clearing all hardware watchpoints failed.");
578uint32_t NativeRegisterContextLinux_s390x::SetHardwareWatchpoint(
582 if (watch_flags != 0x1)
588 Status error = PeekUserArea(offsetof(user_regs_struct, per_info), &per_info,
593 per_info.control_regs.bits.em_storage_alteration = 1;
594 per_info.control_regs.bits.storage_alt_space_ctl = 1;
595 per_info.starting_addr = addr;
596 per_info.ending_addr = addr + size - 1;
598 error = PokeUserArea(offsetof(user_regs_struct, per_info), &per_info,
603 m_watchpoint_addr = addr;
608NativeRegisterContextLinux_s390x::GetWatchpointAddress(uint32_t wp_index) {
609 if (wp_index >= NumSupportedHardwareWatchpoints())
611 return m_watchpoint_addr;
614uint32_t NativeRegisterContextLinux_s390x::NumSupportedHardwareWatchpoints() {
static llvm::raw_ostream & error(Stream &strm)
constexpr size_t k_num_register_sets
static const uint32_t g_gpr_regnums_s390x[]
static const uint32_t g_fpu_regnums_s390x[]
static const RegisterSet g_reg_sets_s390x[k_num_register_sets]
An architecture specification class.
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
A subclass of DataBuffer that stores a data buffer on the heap.
RegisterInfo interface to patch RegisterInfo structure for archs.
void SetUInt64(uint64_t uint, Type t=eTypeUInt64)
uint64_t GetAsUInt64(uint64_t fail_value=UINT64_MAX, bool *success_ptr=nullptr) const
uint32_t GetAsUInt32(uint32_t fail_value=UINT32_MAX, bool *success_ptr=nullptr) const
void SetUInt32(uint32_t uint, Type t=eTypeUInt32)
#define LLDB_INVALID_INDEX32
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_REGNUM
A class that represents a running process on the host machine.
@ k_num_gpr_registers_s390x
@ k_num_fpr_registers_s390x
@ k_num_linux_registers_s390x
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
@ eRegisterKindLLDB
lldb's internal register numbers
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_offset
The byte offset in the register context data where this register's value is found.
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.
Registers are grouped into register sets.
size_t num_registers
The number of registers in REGISTERS array below.