Skip to content

Commit 2672795

Browse files
[LLDB] Add constant value mode for RegisterLocation
1 parent d83ae22 commit 2672795

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

lldb/include/lldb/Symbol/UnwindPlan.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class UnwindPlan {
6868
isAFAPlusOffset, // reg = AFA + offset
6969
inOtherRegister, // reg = other reg
7070
atDWARFExpression, // reg = deref(eval(dwarf_expr))
71-
isDWARFExpression // reg = eval(dwarf_expr)
71+
isDWARFExpression, // reg = eval(dwarf_expr)
72+
isConstant // reg = constant
7273
};
7374

7475
RegisterLocation() : m_location() {}
@@ -105,6 +106,15 @@ class UnwindPlan {
105106

106107
bool IsDWARFExpression() const { return m_type == isDWARFExpression; }
107108

109+
bool IsConstant() const { return m_type == isConstant; }
110+
111+
void SetIsConstant(uint64_t value) {
112+
m_type = isConstant;
113+
m_location.constant_value = value;
114+
}
115+
116+
uint64_t GetConstant() const { return m_location.constant_value; }
117+
108118
void SetAtCFAPlusOffset(int32_t offset) {
109119
m_type = atCFAPlusOffset;
110120
m_location.offset = offset;
@@ -192,6 +202,8 @@ class UnwindPlan {
192202
const uint8_t *opcodes;
193203
uint16_t length;
194204
} expr;
205+
// For m_type == isConstant
206+
uint64_t constant_value;
195207
} m_location;
196208
};
197209

@@ -361,6 +373,10 @@ class UnwindPlan {
361373
bool SetRegisterLocationToIsDWARFExpression(uint32_t reg_num,
362374
const uint8_t *opcodes,
363375
uint32_t len, bool can_replace);
376+
377+
bool SetRegisterLocationToIsConstant(uint32_t reg_num, uint64_t constant,
378+
bool can_replace);
379+
364380
// When this UnspecifiedRegistersAreUndefined mode is
365381
// set, any register that is not specified by this Row will
366382
// be described as Undefined.

lldb/source/Symbol/UnwindPlan.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ operator==(const UnwindPlan::Row::RegisterLocation &rhs) const {
4646
return !memcmp(m_location.expr.opcodes, rhs.m_location.expr.opcodes,
4747
m_location.expr.length);
4848
break;
49+
case isConstant:
50+
return m_location.constant_value == rhs.m_location.constant_value;
4951
}
5052
}
5153
return false;
@@ -153,6 +155,9 @@ void UnwindPlan::Row::RegisterLocation::Dump(Stream &s,
153155
if (m_type == atDWARFExpression)
154156
s.PutChar(']');
155157
} break;
158+
case isConstant:
159+
s.Printf("=0x%" PRIx64, m_location.constant_value);
160+
break;
156161
}
157162
}
158163

@@ -362,6 +367,17 @@ bool UnwindPlan::Row::SetRegisterLocationToIsDWARFExpression(
362367
return true;
363368
}
364369

370+
bool UnwindPlan::Row::SetRegisterLocationToIsConstant(uint32_t reg_num,
371+
uint64_t constant,
372+
bool can_replace) {
373+
if (!can_replace &&
374+
m_register_locations.find(reg_num) != m_register_locations.end())
375+
return false;
376+
RegisterLocation reg_loc;
377+
reg_loc.SetIsConstant(constant);
378+
m_register_locations[reg_num] = reg_loc;
379+
return true;
380+
}
365381

366382
bool UnwindPlan::Row::operator==(const UnwindPlan::Row &rhs) const {
367383
return m_offset == rhs.m_offset && m_cfa_value == rhs.m_cfa_value &&

lldb/source/Target/RegisterContextUnwind.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,15 @@ RegisterContextUnwind::SavedLocationForRegister(
16921692
return UnwindLLDB::RegisterSearchResult::eRegisterNotFound;
16931693
}
16941694

1695+
if (unwindplan_regloc.IsConstant()) {
1696+
regloc.type = UnwindLLDB::RegisterLocation::eRegisterValueInferred;
1697+
regloc.location.inferred_value = unwindplan_regloc.GetConstant();
1698+
m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = regloc;
1699+
UnwindLogMsg("supplying caller's register %s (%d) via constant value",
1700+
regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
1701+
return UnwindLLDB::RegisterSearchResult::eRegisterFound;
1702+
}
1703+
16951704
UnwindLogMsg("no save location for %s (%d) in this stack frame",
16961705
regnum.GetName(), regnum.GetAsKind(eRegisterKindLLDB));
16971706

0 commit comments

Comments
 (0)