23std::unique_ptr<DynamicRegisterInfo>
26 auto dyn_reg_info = std::make_unique<DynamicRegisterInfo>();
30 if (dyn_reg_info->SetRegisterInfo(dict, arch) == 0)
47 m_regs = std::move(info.m_regs);
48 m_sets = std::move(info.m_sets);
58 const size_t num_sets =
m_sets.size();
59 for (
size_t set = 0; set < num_sets; ++set)
67 uint32_t index, llvm::StringRef slice_str,
lldb::ByteOrder byte_order) {
75 static llvm::Regex g_bitfield_regex(
76 "([A-Za-z_][A-Za-z0-9_]*)\\[([0-9]+):([0-9]+)\\]");
77 llvm::SmallVector<llvm::StringRef, 4> matches;
78 if (!g_bitfield_regex.match(slice_str, &matches))
79 return llvm::createStringError(
80 llvm::inconvertibleErrorCode(),
81 "failed to match against register bitfield regex (slice: %s)",
82 slice_str.str().c_str());
84 llvm::StringRef reg_name_str = matches[1];
85 llvm::StringRef msbit_str = matches[2];
86 llvm::StringRef lsbit_str = matches[3];
89 if (!llvm::to_integer(msbit_str, msbit) ||
90 !llvm::to_integer(lsbit_str, lsbit))
91 return llvm::createStringError(
92 llvm::inconvertibleErrorCode(),
"msbit (%s) or lsbit (%s) are invalid",
93 msbit_str.str().c_str(), lsbit_str.str().c_str());
96 return llvm::createStringError(llvm::inconvertibleErrorCode(),
97 "msbit (%u) must be greater than lsbit (%u)",
100 const uint32_t msbyte = msbit / 8;
101 const uint32_t lsbyte = lsbit / 8;
104 if (!containing_reg_info)
105 return llvm::createStringError(llvm::inconvertibleErrorCode(),
106 "invalid concrete register \"%s\"",
107 reg_name_str.str().c_str());
109 const uint32_t max_bit = containing_reg_info->
byte_size * 8;
112 return llvm::createStringError(
113 llvm::inconvertibleErrorCode(),
114 "msbit (%u) must be less than the bitsize of the register \"%s\" (%u)",
115 msbit, reg_name_str.str().c_str(), max_bit);
117 return llvm::createStringError(
118 llvm::inconvertibleErrorCode(),
119 "lsbit (%u) must be less than the bitsize of the register \"%s\" (%u)",
120 lsbit, reg_name_str.str().c_str(), max_bit);
133 llvm_unreachable(
"Invalid byte order");
139 const size_t num_composite_regs = composite_reg_list.
GetSize();
140 if (num_composite_regs == 0)
141 return llvm::createStringError(llvm::inconvertibleErrorCode(),
142 "\"composite\" list is empty");
145 for (uint32_t composite_idx = 0; composite_idx < num_composite_regs;
147 std::optional<llvm::StringRef> maybe_composite_reg_name =
149 if (!maybe_composite_reg_name)
150 return llvm::createStringError(
151 llvm::inconvertibleErrorCode(),
152 "\"composite\" list value is not a Python string at index %d",
157 if (!composite_reg_info)
158 return llvm::createStringError(
159 llvm::inconvertibleErrorCode(),
160 "failed to find composite register by name: \"%s\"",
161 maybe_composite_reg_name->str().c_str());
164 std::min(composite_offset, composite_reg_info->
byte_offset);
173 return composite_offset;
179 uint32_t byte_offset;
188 llvm::StringRef slice_str;
196 return llvm::createStringError(llvm::inconvertibleErrorCode(),
197 "insufficient data to calculate byte offset");
207 const uint32_t num_sets = sets->
GetSize();
208 for (uint32_t i = 0; i < num_sets; ++i) {
209 std::optional<llvm::StringRef> maybe_set_name =
211 if (maybe_set_name && !maybe_set_name->empty()) {
216 printf(
"error: register sets must have valid names\n");
229 const uint32_t num_regs = regs->
GetSize();
233 for (uint32_t i = 0; i < num_regs; ++i) {
234 std::optional<StructuredData::Dictionary *> maybe_reg_info_dict =
236 if (!maybe_reg_info_dict) {
238 printf(
"error: items in the 'registers' array must be dictionaries\n");
248 std::vector<uint32_t> value_regs;
249 std::vector<uint32_t> invalidate_regs;
250 memset(®_info, 0,
sizeof(reg_info));
252 llvm::StringRef name_val;
255 printf(
"error: registers must have valid names and offsets\n");
261 llvm::StringRef alt_name_val;
267 llvm::Expected<uint32_t> byte_offset =
273 "error while parsing register {1}: {0}", reg_info.
name);
279 uint64_t bitsize = 0;
282 printf(
"error: invalid or missing 'bitsize' key/value pair in register "
290 llvm::StringRef format_str;
296 printf(
"error: invalid 'format' value in register dictionary\n");
305 llvm::StringRef encoding_str;
316 printf(
"error: invalid 'set' value in register dictionary, valid values "
335 llvm::StringRef generic_str;
348 invalidate_reg_list)) {
349 const size_t num_regs = invalidate_reg_list->
GetSize();
351 for (uint32_t idx = 0; idx < num_regs; ++idx) {
352 if (
auto maybe_invalidate_reg_name =
356 if (invalidate_reg_info) {
362 printf(
"error: failed to find a 'invalidate-regs' register for "
363 "\"%s\" while parsing register \"%s\"\n",
364 maybe_invalidate_reg_name->str().c_str(), reg_info.
name);
366 }
else if (
auto maybe_invalidate_reg_num =
372 printf(
"error: 'invalidate-regs' list value wasn't a valid "
375 printf(
"error: 'invalidate-regs' list value wasn't a python string "
380 printf(
"error: 'invalidate-regs' contained an empty list\n");
389 m_regs.push_back(reg_info);
397 std::vector<DynamicRegisterInfo::Register> &®s,
401 for (
auto it : llvm::enumerate(regs)) {
402 uint32_t local_regnum = it.index();
426 m_regs.push_back(reg_info);
429 assert(set <
m_sets.size());
444 const size_t num_sets =
m_sets.size();
445 for (
size_t set = 0; set < num_sets; ++set) {
461 const size_t num_regs =
m_regs.size();
462 for (
size_t i = 0; i < num_regs; ++i) {
466 m_regs[i].value_regs =
nullptr;
473 const uint32_t reg_num = pos->first;
475 if (
m_regs[reg_num].value_regs) {
477 for (
const uint32_t invalidate_reg_num : pos->second) {
478 reg_to_regs_map::iterator invalidate_pos =
481 for (
const uint32_t concrete_invalidate_reg_num :
482 invalidate_pos->second) {
483 if (concrete_invalidate_reg_num != reg_num)
484 extra_invalid_regs.push_back(concrete_invalidate_reg_num);
488 pos->second.insert(pos->second.end(), extra_invalid_regs.begin(),
489 extra_invalid_regs.end());
498 if (pos->second.size() > 1) {
499 llvm::sort(pos->second);
500 reg_num_collection::iterator unique_end =
501 std::unique(pos->second.begin(), pos->second.end());
502 if (unique_end != pos->second.end())
503 pos->second.erase(unique_end, pos->second.end());
505 assert(!pos->second.empty());
511 for (
size_t i = 0; i < num_regs; ++i) {
515 m_regs[i].invalidate_regs =
nullptr;
520 bool generic_regs_specified =
false;
521 for (
const auto ® :
m_regs) {
523 generic_regs_specified =
true;
528 if (!generic_regs_specified) {
530 case llvm::Triple::aarch64:
531 case llvm::Triple::aarch64_32:
532 case llvm::Triple::aarch64_be:
533 for (
auto ® :
m_regs) {
534 if (strcmp(reg.name,
"pc") == 0)
536 else if ((strcmp(reg.name,
"fp") == 0) ||
537 (strcmp(reg.name,
"x29") == 0))
539 else if ((strcmp(reg.name,
"lr") == 0) ||
540 (strcmp(reg.name,
"x30") == 0))
542 else if ((strcmp(reg.name,
"sp") == 0) ||
543 (strcmp(reg.name,
"x31") == 0))
545 else if (strcmp(reg.name,
"cpsr") == 0)
550 case llvm::Triple::arm:
551 case llvm::Triple::armeb:
552 case llvm::Triple::thumb:
553 case llvm::Triple::thumbeb:
554 for (
auto ® :
m_regs) {
555 if ((strcmp(reg.name,
"pc") == 0) || (strcmp(reg.name,
"r15") == 0))
557 else if ((strcmp(reg.name,
"sp") == 0) ||
558 (strcmp(reg.name,
"r13") == 0))
560 else if ((strcmp(reg.name,
"lr") == 0) ||
561 (strcmp(reg.name,
"r14") == 0))
563 else if ((strcmp(reg.name,
"r7") == 0) &&
564 arch.
GetTriple().getVendor() == llvm::Triple::Apple)
566 else if ((strcmp(reg.name,
"r11") == 0) &&
567 arch.
GetTriple().getVendor() != llvm::Triple::Apple)
569 else if (strcmp(reg.name,
"fp") == 0)
571 else if (strcmp(reg.name,
"cpsr") == 0)
576 case llvm::Triple::x86:
577 for (
auto ® :
m_regs) {
578 if ((strcmp(reg.name,
"eip") == 0) || (strcmp(reg.name,
"pc") == 0))
580 else if ((strcmp(reg.name,
"esp") == 0) ||
581 (strcmp(reg.name,
"sp") == 0))
583 else if ((strcmp(reg.name,
"ebp") == 0) ||
584 (strcmp(reg.name,
"fp") == 0))
586 else if ((strcmp(reg.name,
"eflags") == 0) ||
587 (strcmp(reg.name,
"flags") == 0))
592 case llvm::Triple::x86_64:
593 for (
auto ® :
m_regs) {
594 if ((strcmp(reg.name,
"rip") == 0) || (strcmp(reg.name,
"pc") == 0))
596 else if ((strcmp(reg.name,
"rsp") == 0) ||
597 (strcmp(reg.name,
"sp") == 0))
599 else if ((strcmp(reg.name,
"rbp") == 0) ||
600 (strcmp(reg.name,
"fp") == 0))
602 else if ((strcmp(reg.name,
"rflags") == 0) ||
603 (strcmp(reg.name,
"eflags") == 0) ||
604 (strcmp(reg.name,
"flags") == 0))
623 for (
const auto ® :
m_regs) {
624 if ((strcmp(reg.name,
"vg") == 0) || (strcmp(reg.name,
"svg") == 0)) {
636 std::map<uint32_t, uint32_t> remote_to_local_regnum_map;
637 for (
const auto ® :
m_regs)
644 uint32_t reg_offset = 0;
645 for (
auto const ®num_pair : remote_to_local_regnum_map) {
647 m_regs[regnum_pair.second].value_regs ==
nullptr) {
648 m_regs[regnum_pair.second].byte_offset = reg_offset;
650 reg_offset =
m_regs[regnum_pair.second].byte_offset +
651 m_regs[regnum_pair.second].byte_size;
656 for (
auto ® :
m_regs) {
657 if (reg.value_regs !=
nullptr) {
663 uint32_t value_regnum = reg.value_regs[0];
670 reg.byte_offset += it->second;
675 reg_offset = reg.byte_offset + reg.byte_size;
699 uint32_t num)
const {
702 return &
m_regs[reg_index];
715 name_collection::iterator pos, end =
m_set_names.end();
716 for (pos =
m_set_names.begin(); pos != end; ++pos) {
717 if (*pos == set_name)
724 m_sets.push_back(new_set);
730 uint32_t num)
const {
731 reg_collection::const_iterator pos, end =
m_regs.end();
732 for (pos =
m_regs.begin(); pos != end; ++pos) {
733 if (pos->kinds[kind] == num)
734 return std::distance(
m_regs.begin(), pos);
753 const size_t num_regs =
m_regs.size();
754 s.
Printf(
"%p: DynamicRegisterInfo contains %" PRIu64
" registers:\n",
755 static_cast<const void *
>(
this),
static_cast<uint64_t
>(num_regs));
756 for (
size_t i = 0; i < num_regs; ++i) {
757 s.
Printf(
"[%3" PRIu64
"] name = %-10s", (uint64_t)i,
m_regs[i].name);
758 s.
Printf(
", size = %2u, offset = %4u, encoding = %u, format = %-10s",
762 s.
Printf(
", process plugin = %3u",
772 if (
m_regs[i].value_regs) {
773 s.
Printf(
", value_regs = [ ");
779 if (
m_regs[i].invalidate_regs) {
780 s.
Printf(
", invalidate_regs = [ ");
790 const size_t num_sets =
m_sets.size();
791 s.
Printf(
"%p: DynamicRegisterInfo contains %" PRIu64
" register sets:\n",
792 static_cast<const void *
>(
this),
static_cast<uint64_t
>(num_sets));
793 for (
size_t i = 0; i < num_sets; ++i) {
794 s.
Printf(
"set[%" PRIu64
"] name = %s, regs = [", (uint64_t)i,
796 for (
size_t idx = 0; idx <
m_sets[i].num_registers; ++idx) {
805 for (
auto ®_info :
m_regs)
806 if (reg_info.name == reg_name)
812 std::vector<DynamicRegisterInfo::Register> ®s,
815 const uint32_t reg_num = regs.size();
816 regs.push_back(new_reg_info);
818 std::map<uint32_t, std::vector<uint32_t>> new_invalidates;
819 for (uint32_t value_reg : new_reg_info.
value_regs) {
821 new_invalidates[reg_num].push_back(value_reg);
824 llvm::append_range(new_invalidates[reg_num],
825 regs[value_reg].invalidate_regs);
828 for (uint32_t x : new_invalidates[reg_num])
829 new_invalidates[x].push_back(reg_num);
832 for (
const auto &x : new_invalidates)
833 llvm::append_range(regs[x.first].invalidate_regs, x.second);
#define LLDB_LOG_ERROR(log, error,...)
An architecture specification class.
llvm::Triple & GetTriple()
Architecture triple accessor.
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
static lldb::Encoding StringToEncoding(llvm::StringRef s, lldb::Encoding fail_value=lldb::eEncodingInvalid)
static uint32_t StringToGenericRegister(llvm::StringRef s)
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
size_t SetRegisterInfo(const lldb_private::StructuredData::Dictionary &dict, const lldb_private::ArchSpec &arch)
set_reg_num_collection m_set_reg_nums
reg_to_regs_map m_value_regs_map
std::vector< uint32_t > reg_num_collection
name_collection m_set_names
DynamicRegisterInfo()=default
const lldb_private::RegisterSet * GetRegisterSet(uint32_t i) const
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(uint32_t i) const
uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind, uint32_t num) const
static std::unique_ptr< DynamicRegisterInfo > Create(const StructuredData::Dictionary &dict, const ArchSpec &arch)
size_t GetNumRegisters() const
llvm::Expected< uint32_t > ByteOffsetFromComposite(uint32_t index, lldb_private::StructuredData::Array &composite_reg_list, lldb::ByteOrder byte_order)
void Finalize(const lldb_private::ArchSpec &arch)
void MoveFrom(DynamicRegisterInfo &&info)
llvm::Expected< uint32_t > ByteOffsetFromSlice(uint32_t index, llvm::StringRef slice_str, lldb::ByteOrder byte_order)
size_t GetRegisterDataByteSize() const
size_t m_reg_data_byte_size
reg_offset_map m_value_reg_offset_map
reg_to_regs_map m_invalidate_regs_map
uint32_t GetRegisterSetIndexByName(const lldb_private::ConstString &set_name, bool can_create)
const lldb_private::RegisterInfo * GetRegisterInfo(uint32_t kind, uint32_t num) const
DynamicRegisterInfo & operator=(DynamicRegisterInfo &)=default
size_t GetNumRegisterSets() const
llvm::Expected< uint32_t > ByteOffsetFromRegInfoDict(uint32_t index, lldb_private::StructuredData::Dictionary ®_info_dict, lldb::ByteOrder byte_order)
bool Fail() const
Test for error condition.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t EOL()
Output and End of Line character to the stream.
std::optional< IntType > GetItemAtIndexAsInteger(size_t idx) const
std::optional< Dictionary * > GetItemAtIndexAsDictionary(size_t idx) const
Retrieves the element at index idx from a StructuredData::Array if it is a Dictionary.
std::optional< llvm::StringRef > GetItemAtIndexAsString(size_t idx) const
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const
void DumpToStdout(bool pretty_print=true) const
#define LLDB_REGNUM_GENERIC_RA
#define LLDB_INVALID_INDEX32
#define LLDB_REGNUM_GENERIC_SP
#define LLDB_REGNUM_GENERIC_FLAGS
#define LLDB_INVALID_REGNUM
#define LLDB_REGNUM_GENERIC_PC
#define LLDB_REGNUM_GENERIC_FP
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.
void addSupplementaryRegister(std::vector< DynamicRegisterInfo::Register > ®s, DynamicRegisterInfo::Register new_reg_info)
@ eEncodingUint
unsigned integer
ByteOrder
Byte ordering definitions.
@ 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
@ eRegisterKindEHFrame
the register numbers seen in eh_frame
@ eRegisterKindProcessPlugin
num used by the process plugin - e.g.
uint32_t value_reg_offset
const RegisterFlags * flags_type
std::vector< uint32_t > value_regs
std::vector< uint32_t > invalidate_regs
static Status ToFormat(const char *s, lldb::Format &format, size_t *byte_size_ptr)
Every register is described in detail including its name, alternate name (optional),...
lldb::Encoding encoding
Encoding of the register bits.
const char * alt_name
Alternate name of this register, can be NULL.
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.
lldb::Format format
Default display format.
Registers are grouped into register sets.