Skip to content

Commit 01d8270

Browse files
committed
[LLDB] Make instruction emulation context type private
This is the first step to being able to handle non trivial types in the union. info_type effects the lifetime of the objects in the union, so making it private means we know you have to call one of the Set<...> functions to change it. Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D134039
1 parent 41dbee1 commit 01d8270

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

lldb/include/lldb/Core/EmulateInstruction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ class EmulateInstruction : public PluginInterface {
183183

184184
struct Context {
185185
ContextType type = eContextInvalid;
186+
187+
private:
186188
enum InfoType info_type = eInfoTypeNoArgs;
189+
190+
public:
191+
enum InfoType GetInfoType() const { return info_type; }
187192
union {
188193
struct RegisterPlusOffset {
189194
RegisterInfo reg; // base register

lldb/source/Core/EmulateInstruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ void EmulateInstruction::Context::Dump(Stream &strm,
440440
break;
441441
}
442442

443-
switch (info_type) {
443+
switch (GetInfoType()) {
444444
case eInfoTypeRegisterPlusOffset:
445445
strm.Printf(" (reg_plus_offset = %s%+" PRId64 ")",
446446
info.RegisterPlusOffset.reg.name,

lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ size_t UnwindAssemblyInstEmulation::WriteMemory(
455455
case EmulateInstruction::eContextPushRegisterOnStack: {
456456
uint32_t reg_num = LLDB_INVALID_REGNUM;
457457
uint32_t generic_regnum = LLDB_INVALID_REGNUM;
458-
assert(context.info_type ==
458+
assert(context.GetInfoType() ==
459459
EmulateInstruction::eInfoTypeRegisterToRegisterPlusOffset &&
460460
"unhandled case, add code to handle this!");
461461
const uint32_t unwind_reg_kind = m_unwind_plan_ptr->GetRegisterKind();
@@ -574,7 +574,8 @@ bool UnwindAssemblyInstEmulation::WriteRegister(
574574
// with the same amount.
575575
lldb::RegisterKind kind = m_unwind_plan_ptr->GetRegisterKind();
576576
if (m_fp_is_cfa && reg_info->kinds[kind] == m_cfa_reg_info.kinds[kind] &&
577-
context.info_type == EmulateInstruction::eInfoTypeRegisterPlusOffset &&
577+
context.GetInfoType() ==
578+
EmulateInstruction::eInfoTypeRegisterPlusOffset &&
578579
context.info.RegisterPlusOffset.reg.kinds[kind] ==
579580
m_cfa_reg_info.kinds[kind]) {
580581
const int64_t offset = context.info.RegisterPlusOffset.signed_offset;
@@ -585,18 +586,19 @@ bool UnwindAssemblyInstEmulation::WriteRegister(
585586

586587
case EmulateInstruction::eContextAbsoluteBranchRegister:
587588
case EmulateInstruction::eContextRelativeBranchImmediate: {
588-
if (context.info_type == EmulateInstruction::eInfoTypeISAAndImmediate &&
589+
if (context.GetInfoType() == EmulateInstruction::eInfoTypeISAAndImmediate &&
589590
context.info.ISAAndImmediate.unsigned_data32 > 0) {
590591
m_forward_branch_offset =
591592
context.info.ISAAndImmediateSigned.signed_data32;
592-
} else if (context.info_type ==
593+
} else if (context.GetInfoType() ==
593594
EmulateInstruction::eInfoTypeISAAndImmediateSigned &&
594595
context.info.ISAAndImmediateSigned.signed_data32 > 0) {
595596
m_forward_branch_offset = context.info.ISAAndImmediate.unsigned_data32;
596-
} else if (context.info_type == EmulateInstruction::eInfoTypeImmediate &&
597+
} else if (context.GetInfoType() ==
598+
EmulateInstruction::eInfoTypeImmediate &&
597599
context.info.unsigned_immediate > 0) {
598600
m_forward_branch_offset = context.info.unsigned_immediate;
599-
} else if (context.info_type ==
601+
} else if (context.GetInfoType() ==
600602
EmulateInstruction::eInfoTypeImmediateSigned &&
601603
context.info.signed_immediate > 0) {
602604
m_forward_branch_offset = context.info.signed_immediate;
@@ -609,7 +611,7 @@ bool UnwindAssemblyInstEmulation::WriteRegister(
609611
const uint32_t generic_regnum = reg_info->kinds[eRegisterKindGeneric];
610612
if (reg_num != LLDB_INVALID_REGNUM &&
611613
generic_regnum != LLDB_REGNUM_GENERIC_SP) {
612-
switch (context.info_type) {
614+
switch (context.GetInfoType()) {
613615
case EmulateInstruction::eInfoTypeAddress:
614616
if (m_pushed_regs.find(reg_num) != m_pushed_regs.end() &&
615617
context.info.address == m_pushed_regs[reg_num]) {

0 commit comments

Comments
 (0)