Skip to content

Commit 3336d73

Browse files
authored
[lldb][NFC] New names for the two RegisterLocation classes (#109611)
lldb has two RegisterLocation classes that do slightly different things. UnwindPlan::Row::RegisterLocation (new: AbstractRegisterLocation) has a description of how to find a register's value or location, not specific to a particular stopping point. It may say that at a given offset into a function, the caller's register has been spilled to stack memory at CFA minus an offset. Or it may say that the caller's register is at a DWARF exprssion. UnwindLLDB::RegisterLocation (new: ConcreteRegisterLocation) is a specific address where the register is currently stored, or the register it has been copied into, or its value at this point in the current function execution. When lldb stops in a function, it interprets the AbstractRegisterLocation's instructions using the register context and stack memory, to create the ConcreteRegisterLocation at this point in time for this stack frame. I'm not thrilled with AbstractRegisterLocation and ConcreteRegisterLocation, but it's better than the same name and it will be easier to update them if someone suggests a better pair.
1 parent 19f04e9 commit 3336d73

19 files changed

+178
-170
lines changed

lldb/include/lldb/Symbol/UnwindPlan.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class UnwindPlan {
5454
public:
5555
class Row {
5656
public:
57-
class RegisterLocation {
57+
class AbstractRegisterLocation {
5858
public:
5959
enum RestoreType {
6060
unspecified, // not specified, we may be able to assume this
@@ -72,11 +72,11 @@ class UnwindPlan {
7272
isConstant // reg = constant
7373
};
7474

75-
RegisterLocation() : m_location() {}
75+
AbstractRegisterLocation() : m_location() {}
7676

77-
bool operator==(const RegisterLocation &rhs) const;
77+
bool operator==(const AbstractRegisterLocation &rhs) const;
7878

79-
bool operator!=(const RegisterLocation &rhs) const {
79+
bool operator!=(const AbstractRegisterLocation &rhs) const {
8080
return !(*this == rhs);
8181
}
8282

@@ -337,10 +337,10 @@ class UnwindPlan {
337337
bool operator==(const Row &rhs) const;
338338

339339
bool GetRegisterInfo(uint32_t reg_num,
340-
RegisterLocation &register_location) const;
340+
AbstractRegisterLocation &register_location) const;
341341

342342
void SetRegisterInfo(uint32_t reg_num,
343-
const RegisterLocation register_location);
343+
const AbstractRegisterLocation register_location);
344344

345345
void RemoveRegisterInfo(uint32_t reg_num);
346346

@@ -398,7 +398,7 @@ class UnwindPlan {
398398
lldb::addr_t base_addr) const;
399399

400400
protected:
401-
typedef std::map<uint32_t, RegisterLocation> collection;
401+
typedef std::map<uint32_t, AbstractRegisterLocation> collection;
402402
lldb::addr_t m_offset = 0; // Offset into the function for this row
403403

404404
FAValue m_cfa_value;

lldb/include/lldb/Target/ABI.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ class ABI : public PluginInterface {
102102

103103
virtual bool RegisterIsVolatile(const RegisterInfo *reg_info) = 0;
104104

105-
virtual bool
106-
GetFallbackRegisterLocation(const RegisterInfo *reg_info,
107-
UnwindPlan::Row::RegisterLocation &unwind_regloc);
105+
virtual bool GetFallbackRegisterLocation(
106+
const RegisterInfo *reg_info,
107+
UnwindPlan::Row::AbstractRegisterLocation &unwind_regloc);
108108

109109
// Should take a look at a call frame address (CFA) which is just the stack
110110
// pointer value upon entry to a function. ABIs usually impose alignment

lldb/include/lldb/Target/RegisterContextUnwind.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class RegisterContextUnwind : public lldb_private::RegisterContext {
8484
// past the top (end) of the stack
8585
};
8686

87-
// UnwindLLDB needs to pass around references to RegisterLocations
87+
// UnwindLLDB needs to pass around references to ConcreteRegisterLocations
8888
friend class UnwindLLDB;
8989

9090
// Returns true if we have an unwind loop -- the same stack frame unwinding
@@ -135,29 +135,28 @@ class RegisterContextUnwind : public lldb_private::RegisterContext {
135135
// preserved a register that this
136136
// function didn't modify/use.
137137
//
138-
// The RegisterLocation type may be set to eRegisterNotAvailable -- this will
139-
// happen for a volatile register
140-
// being queried mid-stack. Instead of floating frame 0's contents of that
141-
// register up the stack (which may
142-
// or may not be the value of that reg when the function was executing), we
143-
// won't return any value.
138+
// The ConcreteRegisterLocation type may be set to eRegisterNotAvailable --
139+
// this will happen for a volatile register being queried mid-stack. Instead
140+
// of floating frame 0's contents of that register up the stack (which may or
141+
// may not be the value of that reg when the function was executing), we won't
142+
// return any value.
144143
//
145144
// If a non-volatile register (a "preserved" register) is requested mid-stack
146145
// and no frames "below" the requested
147146
// stack have saved the register anywhere, it is safe to assume that frame 0's
148147
// register values are still the same
149148
// as the requesting frame's.
150-
lldb_private::UnwindLLDB::RegisterSearchResult
151-
SavedLocationForRegister(uint32_t lldb_regnum,
152-
lldb_private::UnwindLLDB::RegisterLocation &regloc);
149+
lldb_private::UnwindLLDB::RegisterSearchResult SavedLocationForRegister(
150+
uint32_t lldb_regnum,
151+
lldb_private::UnwindLLDB::ConcreteRegisterLocation &regloc);
153152

154153
bool ReadRegisterValueFromRegisterLocation(
155-
lldb_private::UnwindLLDB::RegisterLocation regloc,
154+
lldb_private::UnwindLLDB::ConcreteRegisterLocation regloc,
156155
const lldb_private::RegisterInfo *reg_info,
157156
lldb_private::RegisterValue &value);
158157

159158
bool WriteRegisterValueToRegisterLocation(
160-
lldb_private::UnwindLLDB::RegisterLocation regloc,
159+
lldb_private::UnwindLLDB::ConcreteRegisterLocation regloc,
161160
const lldb_private::RegisterInfo *reg_info,
162161
const lldb_private::RegisterValue &value);
163162

@@ -249,7 +248,7 @@ class RegisterContextUnwind : public lldb_private::RegisterContext {
249248

250249
uint32_t m_frame_number; // What stack frame this RegisterContext is
251250

252-
std::map<uint32_t, lldb_private::UnwindLLDB::RegisterLocation>
251+
std::map<uint32_t, lldb_private::UnwindLLDB::ConcreteRegisterLocation>
253252
m_registers; // where to find reg values for this frame
254253

255254
lldb_private::UnwindLLDB &m_parent_unwind; // The UnwindLLDB that is creating

lldb/include/lldb/Target/UnwindLLDB.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ class UnwindLLDB : public lldb_private::Unwind {
3838
protected:
3939
friend class lldb_private::RegisterContextUnwind;
4040

41-
struct RegisterLocation {
41+
/// An UnwindPlan::Row::AbstractRegisterLocation, combined with the register
42+
/// context and memory for a specific stop point, is used to create a
43+
/// ConcreteRegisterLocation.
44+
struct ConcreteRegisterLocation {
4245
enum RegisterLocationTypes {
4346
eRegisterNotSaved = 0, // register was not preserved by callee. If
4447
// volatile reg, is unavailable
@@ -90,7 +93,8 @@ class UnwindLLDB : public lldb_private::Unwind {
9093
// Iterate over the RegisterContextUnwind's in our m_frames vector, look for
9194
// the first one that has a saved location for this reg.
9295
bool SearchForSavedLocationForRegister(
93-
uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc,
96+
uint32_t lldb_regnum,
97+
lldb_private::UnwindLLDB::ConcreteRegisterLocation &regloc,
9498
uint32_t starting_frame_num, bool pc_register);
9599

96100
/// Provide the list of user-specified trap handler functions

lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ bool ABISysV_s390x::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {
644644

645645
bool ABISysV_s390x::GetFallbackRegisterLocation(
646646
const RegisterInfo *reg_info,
647-
UnwindPlan::Row::RegisterLocation &unwind_regloc) {
647+
UnwindPlan::Row::AbstractRegisterLocation &unwind_regloc) {
648648
// If a volatile register is being requested, we don't want to forward the
649649
// next frame's register contents up the stack -- the register is not
650650
// retrievable at this frame.

lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class ABISysV_s390x : public lldb_private::RegInfoBasedABI {
4343

4444
bool GetFallbackRegisterLocation(
4545
const lldb_private::RegisterInfo *reg_info,
46-
lldb_private::UnwindPlan::Row::RegisterLocation &unwind_regloc) override;
46+
lldb_private::UnwindPlan::Row::AbstractRegisterLocation &unwind_regloc)
47+
override;
4748

4849
bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
4950
// Make sure the stack call frame addresses are 8 byte aligned

lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ bool SymbolFileBreakpad::ParseCFIUnwindRow(llvm::StringRef unwind_rules,
614614
row.GetCFAValue().SetIsDWARFExpression(saved.data(), saved.size());
615615
} else if (const RegisterInfo *info =
616616
ResolveRegisterOrRA(triple, resolver, lhs)) {
617-
UnwindPlan::Row::RegisterLocation loc;
617+
UnwindPlan::Row::AbstractRegisterLocation loc;
618618
loc.SetIsDWARFExpression(saved.data(), saved.size());
619619
row.SetRegisterInfo(info->kinds[eRegisterKindLLDB], loc);
620620
} else
@@ -766,7 +766,7 @@ SymbolFileBreakpad::ParseWinUnwindPlan(const Bookmark &bookmark,
766766
}
767767

768768
llvm::ArrayRef<uint8_t> saved = SaveAsDWARF(*it->second);
769-
UnwindPlan::Row::RegisterLocation loc;
769+
UnwindPlan::Row::AbstractRegisterLocation loc;
770770
loc.SetIsDWARFExpression(saved.data(), saved.size());
771771
row_sp->SetRegisterInfo(info->kinds[eRegisterKindLLDB], loc);
772772
}

lldb/source/Plugins/UnwindAssembly/x86/UnwindAssembly-x86.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool UnwindAssembly_x86::AugmentUnwindPlanFromCallSite(
9797
first_row->GetCFAValue().GetOffset() != wordsize) {
9898
return false;
9999
}
100-
UnwindPlan::Row::RegisterLocation first_row_pc_loc;
100+
UnwindPlan::Row::AbstractRegisterLocation first_row_pc_loc;
101101
if (!first_row->GetRegisterInfo(
102102
pc_regnum.GetAsKind(unwind_plan.GetRegisterKind()),
103103
first_row_pc_loc) ||
@@ -126,7 +126,7 @@ bool UnwindAssembly_x86::AugmentUnwindPlanFromCallSite(
126126
// Get the register locations for eip/rip from the first & last rows. Are
127127
// they both CFA plus an offset? Is it the same offset?
128128

129-
UnwindPlan::Row::RegisterLocation last_row_pc_loc;
129+
UnwindPlan::Row::AbstractRegisterLocation last_row_pc_loc;
130130
if (last_row->GetRegisterInfo(
131131
pc_regnum.GetAsKind(unwind_plan.GetRegisterKind()),
132132
last_row_pc_loc)) {

lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ bool x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly(
915915
addr_t current_func_text_offset = 0;
916916
int current_sp_bytes_offset_from_fa = 0;
917917
bool is_aligned = false;
918-
UnwindPlan::Row::RegisterLocation initial_regloc;
918+
UnwindPlan::Row::AbstractRegisterLocation initial_regloc;
919919
UnwindPlan::RowSP row(new UnwindPlan::Row);
920920

921921
unwind_plan.SetPlanValidAddressRange(func_range);
@@ -1051,7 +1051,7 @@ bool x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly(
10511051
if (nonvolatile_reg_p(machine_regno) &&
10521052
machine_regno_to_lldb_regno(machine_regno, lldb_regno) &&
10531053
!saved_registers[machine_regno]) {
1054-
UnwindPlan::Row::RegisterLocation regloc;
1054+
UnwindPlan::Row::AbstractRegisterLocation regloc;
10551055
if (is_aligned)
10561056
regloc.SetAtAFAPlusOffset(-current_sp_bytes_offset_from_fa);
10571057
else
@@ -1142,7 +1142,7 @@ bool x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly(
11421142
!saved_registers[machine_regno]) {
11431143
saved_registers[machine_regno] = true;
11441144

1145-
UnwindPlan::Row::RegisterLocation regloc;
1145+
UnwindPlan::Row::AbstractRegisterLocation regloc;
11461146

11471147
// stack_offset for 'movq %r15, -80(%rbp)' will be 80. In the Row, we
11481148
// want to express this as the offset from the FA. If the frame base is
@@ -1234,7 +1234,7 @@ bool x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly(
12341234
// determine the effcts of. Verify that the stack frame state
12351235
// has been unwound to the same as it was at function entry to avoid
12361236
// mis-identifying a JMP instruction as an epilogue.
1237-
UnwindPlan::Row::RegisterLocation sp, pc;
1237+
UnwindPlan::Row::AbstractRegisterLocation sp, pc;
12381238
if (row->GetRegisterInfo(m_lldb_sp_regnum, sp) &&
12391239
row->GetRegisterInfo(m_lldb_ip_regnum, pc)) {
12401240
// Any ret instruction variant is definitely indicative of an

lldb/source/Symbol/ArmUnwindInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ bool ArmUnwindInfo::GetUnwindPlan(Target &target, const Address &addr,
333333
}
334334

335335
if (!have_location_for_pc) {
336-
UnwindPlan::Row::RegisterLocation lr_location;
336+
UnwindPlan::Row::AbstractRegisterLocation lr_location;
337337
if (row->GetRegisterInfo(dwarf_lr, lr_location))
338338
row->SetRegisterInfo(dwarf_pc, lr_location);
339339
else

lldb/source/Symbol/DWARFCallFrameInfo.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset,
633633

634634
std::vector<UnwindPlan::RowSP> stack;
635635

636-
UnwindPlan::Row::RegisterLocation reg_location;
636+
UnwindPlan::Row::AbstractRegisterLocation reg_location;
637637
while (m_cfi_data.ValidOffset(offset) && offset < end_offset) {
638638
uint8_t inst = m_cfi_data.GetU8(&offset);
639639
uint8_t primary_opcode = inst & 0xC0;
@@ -822,7 +822,7 @@ bool DWARFCallFrameInfo::HandleCommonDwarfOpcode(uint8_t primary_opcode,
822822
int32_t data_align,
823823
lldb::offset_t &offset,
824824
UnwindPlan::Row &row) {
825-
UnwindPlan::Row::RegisterLocation reg_location;
825+
UnwindPlan::Row::AbstractRegisterLocation reg_location;
826826

827827
if (primary_opcode) {
828828
switch (primary_opcode) {
@@ -852,7 +852,7 @@ bool DWARFCallFrameInfo::HandleCommonDwarfOpcode(uint8_t primary_opcode,
852852
// except for the encoding and size of the register argument.
853853
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
854854
int32_t op_offset = (int32_t)m_cfi_data.GetULEB128(&offset) * data_align;
855-
UnwindPlan::Row::RegisterLocation reg_location;
855+
UnwindPlan::Row::AbstractRegisterLocation reg_location;
856856
reg_location.SetAtCFAPlusOffset(op_offset);
857857
row.SetRegisterInfo(reg_num, reg_location);
858858
return true;
@@ -864,7 +864,7 @@ bool DWARFCallFrameInfo::HandleCommonDwarfOpcode(uint8_t primary_opcode,
864864
// number. The required action is to set the rule for the specified
865865
// register to undefined.
866866
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
867-
UnwindPlan::Row::RegisterLocation reg_location;
867+
UnwindPlan::Row::AbstractRegisterLocation reg_location;
868868
reg_location.SetUndefined();
869869
row.SetRegisterInfo(reg_num, reg_location);
870870
return true;
@@ -876,7 +876,7 @@ bool DWARFCallFrameInfo::HandleCommonDwarfOpcode(uint8_t primary_opcode,
876876
// number. The required action is to set the rule for the specified
877877
// register to same value.
878878
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
879-
UnwindPlan::Row::RegisterLocation reg_location;
879+
UnwindPlan::Row::AbstractRegisterLocation reg_location;
880880
reg_location.SetSame();
881881
row.SetRegisterInfo(reg_num, reg_location);
882882
return true;
@@ -889,7 +889,7 @@ bool DWARFCallFrameInfo::HandleCommonDwarfOpcode(uint8_t primary_opcode,
889889
// second register.
890890
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
891891
uint32_t other_reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
892-
UnwindPlan::Row::RegisterLocation reg_location;
892+
UnwindPlan::Row::AbstractRegisterLocation reg_location;
893893
reg_location.SetInRegister(other_reg_num);
894894
row.SetRegisterInfo(reg_num, reg_location);
895895
return true;
@@ -950,7 +950,7 @@ bool DWARFCallFrameInfo::HandleCommonDwarfOpcode(uint8_t primary_opcode,
950950
uint32_t block_len = (uint32_t)m_cfi_data.GetULEB128(&offset);
951951
const uint8_t *block_data =
952952
static_cast<const uint8_t *>(m_cfi_data.GetData(&offset, block_len));
953-
UnwindPlan::Row::RegisterLocation reg_location;
953+
UnwindPlan::Row::AbstractRegisterLocation reg_location;
954954
reg_location.SetAtDWARFExpression(block_data, block_len);
955955
row.SetRegisterInfo(reg_num, reg_location);
956956
return true;
@@ -964,7 +964,7 @@ bool DWARFCallFrameInfo::HandleCommonDwarfOpcode(uint8_t primary_opcode,
964964
// signed and factored.
965965
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
966966
int32_t op_offset = (int32_t)m_cfi_data.GetSLEB128(&offset) * data_align;
967-
UnwindPlan::Row::RegisterLocation reg_location;
967+
UnwindPlan::Row::AbstractRegisterLocation reg_location;
968968
reg_location.SetAtCFAPlusOffset(op_offset);
969969
row.SetRegisterInfo(reg_num, reg_location);
970970
return true;

lldb/source/Symbol/FuncUnwinders.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ LazyBool FuncUnwinders::CompareUnwindPlansForIdenticalInitialPCLocation(
371371
UnwindPlan::RowSP b_first_row = b->GetRowAtIndex(0);
372372

373373
if (a_first_row.get() && b_first_row.get()) {
374-
UnwindPlan::Row::RegisterLocation a_pc_regloc;
375-
UnwindPlan::Row::RegisterLocation b_pc_regloc;
374+
UnwindPlan::Row::AbstractRegisterLocation a_pc_regloc;
375+
UnwindPlan::Row::AbstractRegisterLocation b_pc_regloc;
376376

377377
a_first_row->GetRegisterInfo(pc_reg_lldb_regnum, a_pc_regloc);
378378
b_first_row->GetRegisterInfo(pc_reg_lldb_regnum, b_pc_regloc);

0 commit comments

Comments
 (0)