37
37
#include " lldb/Utility/RegisterValue.h"
38
38
#include " lldb/Utility/VASPrintf.h"
39
39
#include " lldb/lldb-private.h"
40
+
41
+ #include < cassert>
40
42
#include < memory>
41
43
42
44
using namespace lldb ;
@@ -135,9 +137,8 @@ void RegisterContextUnwind::InitializeZerothFrame() {
135
137
// (which would be a no-op in frame 0 where we get it from the register set,
136
138
// but still a good idea to make the call here for other ABIs that may
137
139
// exist.)
138
- ABI *abi = process->GetABI ().get ();
139
- if (abi)
140
- current_pc = abi->FixCodeAddress (current_pc);
140
+ if (ABISP abi_sp = process->GetABI ())
141
+ current_pc = abi_sp->FixCodeAddress (current_pc);
141
142
142
143
UnwindPlanSP lang_runtime_plan_sp = LanguageRuntime::GetRuntimeUnwindPlan (
143
144
m_thread, this , m_behaves_like_zeroth_frame);
@@ -289,6 +290,13 @@ void RegisterContextUnwind::InitializeZerothFrame() {
289
290
} else
290
291
ReadFrameAddress (row_register_kind, active_row->GetAFAValue (), m_afa);
291
292
293
+ if (m_cfa == LLDB_INVALID_ADDRESS && m_afa == LLDB_INVALID_ADDRESS) {
294
+ UnwindLogMsg (
295
+ " could not read CFA or AFA values for first frame, not valid." );
296
+ m_frame_type = eNotAValidFrame;
297
+ return ;
298
+ }
299
+
292
300
UnwindLogMsg (" initialized frame current pc is 0x%" PRIx64 " cfa is 0x%" PRIx64
293
301
" afa is 0x%" PRIx64 " using %s UnwindPlan" ,
294
302
(uint64_t )m_current_pc.GetLoadAddress (exe_ctx.GetTargetPtr ()),
@@ -346,17 +354,23 @@ void RegisterContextUnwind::InitializeNonZerothFrame() {
346
354
347
355
// Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
348
356
// this will strip bit zero in case we read a PC from memory or from the LR.
349
- ABI *abi = process->GetABI (). get ();
350
- if (abi )
351
- pc = abi ->FixCodeAddress (pc);
357
+ ABISP abi_sp = process->GetABI ();
358
+ if (abi_sp )
359
+ pc = abi_sp ->FixCodeAddress (pc);
352
360
353
361
if (log) {
354
362
UnwindLogMsg (" pc = 0x%" PRIx64, pc);
355
363
addr_t reg_val;
356
- if (ReadGPRValue (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP, reg_val))
364
+ if (ReadGPRValue (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP, reg_val)) {
365
+ if (abi_sp)
366
+ reg_val = abi_sp->FixDataAddress (reg_val);
357
367
UnwindLogMsg (" fp = 0x%" PRIx64, reg_val);
358
- if (ReadGPRValue (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, reg_val))
368
+ }
369
+ if (ReadGPRValue (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, reg_val)) {
370
+ if (abi_sp)
371
+ reg_val = abi_sp->FixDataAddress (reg_val);
359
372
UnwindLogMsg (" sp = 0x%" PRIx64, reg_val);
373
+ }
360
374
}
361
375
362
376
// A pc of 0x0 means it's the end of the stack crawl unless we're above a trap
@@ -415,11 +429,11 @@ void RegisterContextUnwind::InitializeNonZerothFrame() {
415
429
}
416
430
}
417
431
418
- if (abi ) {
432
+ if (abi_sp ) {
419
433
m_fast_unwind_plan_sp.reset ();
420
434
m_full_unwind_plan_sp =
421
435
std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
422
- abi ->CreateDefaultUnwindPlan (*m_full_unwind_plan_sp);
436
+ abi_sp ->CreateDefaultUnwindPlan (*m_full_unwind_plan_sp);
423
437
if (m_frame_type != eSkipFrame) // don't override eSkipFrame
424
438
{
425
439
m_frame_type = eNormalFrame;
@@ -1742,8 +1756,8 @@ bool RegisterContextUnwind::TryFallbackUnwindPlan() {
1742
1756
if (ReadRegisterValueFromRegisterLocation (regloc, reg_info, reg_value)) {
1743
1757
old_caller_pc_value = reg_value.GetAsUInt64 ();
1744
1758
if (ProcessSP process_sp = m_thread.GetProcess ()) {
1745
- if (ABISP abi = process_sp->GetABI ())
1746
- old_caller_pc_value = abi ->FixCodeAddress (old_caller_pc_value);
1759
+ if (ABISP abi_sp = process_sp->GetABI ())
1760
+ old_caller_pc_value = abi_sp ->FixCodeAddress (old_caller_pc_value);
1747
1761
}
1748
1762
}
1749
1763
}
@@ -1802,8 +1816,8 @@ bool RegisterContextUnwind::TryFallbackUnwindPlan() {
1802
1816
reg_value)) {
1803
1817
new_caller_pc_value = reg_value.GetAsUInt64 ();
1804
1818
if (ProcessSP process_sp = m_thread.GetProcess ()) {
1805
- if (ABISP abi = process_sp->GetABI ())
1806
- new_caller_pc_value = abi ->FixCodeAddress (new_caller_pc_value);
1819
+ if (ABISP abi_sp = process_sp->GetABI ())
1820
+ new_caller_pc_value = abi_sp ->FixCodeAddress (new_caller_pc_value);
1807
1821
}
1808
1822
}
1809
1823
}
@@ -1944,6 +1958,7 @@ bool RegisterContextUnwind::ReadFrameAddress(
1944
1958
1945
1959
address = LLDB_INVALID_ADDRESS;
1946
1960
addr_t cfa_reg_contents;
1961
+ ABISP abi_sp = m_thread.GetProcess ()->GetABI ();
1947
1962
1948
1963
switch (fa.GetValueType ()) {
1949
1964
case UnwindPlan::Row::FAValue::isRegisterDereferenced: {
@@ -1954,11 +1969,13 @@ bool RegisterContextUnwind::ReadFrameAddress(
1954
1969
GetRegisterInfoAtIndex (cfa_reg.GetAsKind (eRegisterKindLLDB));
1955
1970
RegisterValue reg_value;
1956
1971
if (reg_info) {
1972
+ if (abi_sp)
1973
+ cfa_reg_contents = abi_sp->FixDataAddress (cfa_reg_contents);
1957
1974
Status error = ReadRegisterValueFromMemory (
1958
1975
reg_info, cfa_reg_contents, reg_info->byte_size , reg_value);
1959
1976
if (error.Success ()) {
1960
1977
address = reg_value.GetAsUInt64 ();
1961
- if (ABISP abi_sp = m_thread. GetProcess ()-> GetABI () )
1978
+ if (abi_sp)
1962
1979
address = abi_sp->FixCodeAddress (address);
1963
1980
UnwindLogMsg (
1964
1981
" CFA value via dereferencing reg %s (%d): reg has val 0x%" PRIx64
@@ -1980,6 +1997,8 @@ bool RegisterContextUnwind::ReadFrameAddress(
1980
1997
RegisterNumber cfa_reg (m_thread, row_register_kind,
1981
1998
fa.GetRegisterNumber ());
1982
1999
if (ReadGPRValue (cfa_reg, cfa_reg_contents)) {
2000
+ if (abi_sp)
2001
+ cfa_reg_contents = abi_sp->FixDataAddress (cfa_reg_contents);
1983
2002
if (cfa_reg_contents == LLDB_INVALID_ADDRESS || cfa_reg_contents == 0 ||
1984
2003
cfa_reg_contents == 1 ) {
1985
2004
UnwindLogMsg (
@@ -2067,6 +2086,8 @@ lldb::addr_t RegisterContextUnwind::GetReturnAddressHint(int32_t plan_offset) {
2067
2086
return LLDB_INVALID_ADDRESS;
2068
2087
if (!m_sym_ctx.module_sp || !m_sym_ctx.symbol )
2069
2088
return LLDB_INVALID_ADDRESS;
2089
+ if (ABISP abi_sp = m_thread.GetProcess ()->GetABI ())
2090
+ hint = abi_sp->FixCodeAddress (hint);
2070
2091
2071
2092
hint += plan_offset;
2072
2093
@@ -2116,28 +2137,46 @@ bool RegisterContextUnwind::ReadGPRValue(lldb::RegisterKind register_kind,
2116
2137
}
2117
2138
2118
2139
const RegisterInfo *reg_info = GetRegisterInfoAtIndex (lldb_regnum);
2140
+ assert (reg_info);
2141
+ if (!reg_info) {
2142
+ UnwindLogMsg (
2143
+ " Could not find RegisterInfo definition for lldb register number %d" ,
2144
+ lldb_regnum);
2145
+ return false ;
2146
+ }
2147
+
2148
+ uint32_t generic_regnum = LLDB_INVALID_REGNUM;
2149
+ if (register_kind == eRegisterKindGeneric)
2150
+ generic_regnum = regnum;
2151
+ else
2152
+ m_thread.GetRegisterContext ()->ConvertBetweenRegisterKinds (
2153
+ register_kind, regnum, eRegisterKindGeneric, generic_regnum);
2154
+ ABISP abi_sp = m_thread.GetProcess ()->GetABI ();
2155
+
2119
2156
RegisterValue reg_value;
2120
2157
// if this is frame 0 (currently executing frame), get the requested reg
2121
2158
// contents from the actual thread registers
2122
2159
if (IsFrameZero ()) {
2123
2160
if (m_thread.GetRegisterContext ()->ReadRegister (reg_info, reg_value)) {
2124
2161
value = reg_value.GetAsUInt64 ();
2162
+ if (abi_sp && generic_regnum != LLDB_INVALID_REGNUM) {
2163
+ if (generic_regnum == LLDB_REGNUM_GENERIC_PC ||
2164
+ generic_regnum == LLDB_REGNUM_GENERIC_RA)
2165
+ value = abi_sp->FixCodeAddress (value);
2166
+ if (generic_regnum == LLDB_REGNUM_GENERIC_SP ||
2167
+ generic_regnum == LLDB_REGNUM_GENERIC_FP)
2168
+ value = abi_sp->FixDataAddress (value);
2169
+ }
2125
2170
return true ;
2126
2171
}
2127
2172
return false ;
2128
2173
}
2129
2174
2130
2175
bool pc_register = false ;
2131
- uint32_t generic_regnum;
2132
- if (register_kind == eRegisterKindGeneric &&
2133
- (regnum == LLDB_REGNUM_GENERIC_PC || regnum == LLDB_REGNUM_GENERIC_RA)) {
2176
+ if ( generic_regnum != LLDB_INVALID_REGNUM &&
2177
+ (generic_regnum == LLDB_REGNUM_GENERIC_PC ||
2178
+ generic_regnum == LLDB_REGNUM_GENERIC_RA))
2134
2179
pc_register = true ;
2135
- } else if (m_thread.GetRegisterContext ()->ConvertBetweenRegisterKinds (
2136
- register_kind, regnum, eRegisterKindGeneric, generic_regnum) &&
2137
- (generic_regnum == LLDB_REGNUM_GENERIC_PC ||
2138
- generic_regnum == LLDB_REGNUM_GENERIC_RA)) {
2139
- pc_register = true ;
2140
- }
2141
2180
2142
2181
lldb_private::UnwindLLDB::RegisterLocation regloc;
2143
2182
if (!m_parent_unwind.SearchForSavedLocationForRegister (
@@ -2147,9 +2186,8 @@ bool RegisterContextUnwind::ReadGPRValue(lldb::RegisterKind register_kind,
2147
2186
if (ReadRegisterValueFromRegisterLocation (regloc, reg_info, reg_value)) {
2148
2187
value = reg_value.GetAsUInt64 ();
2149
2188
if (pc_register) {
2150
- if (ProcessSP process_sp = m_thread.GetProcess ()) {
2151
- if (ABISP abi = process_sp->GetABI ())
2152
- value = abi->FixCodeAddress (value);
2189
+ if (ABISP abi_sp = m_thread.GetProcess ()->GetABI ()) {
2190
+ value = abi_sp->FixCodeAddress (value);
2153
2191
}
2154
2192
}
2155
2193
return true ;
@@ -2198,10 +2236,8 @@ bool RegisterContextUnwind::ReadRegister(const RegisterInfo *reg_info,
2198
2236
if (is_pc_regnum && value.GetType () == RegisterValue::eTypeUInt64) {
2199
2237
addr_t reg_value = value.GetAsUInt64 (LLDB_INVALID_ADDRESS);
2200
2238
if (reg_value != LLDB_INVALID_ADDRESS) {
2201
- if (ProcessSP process_sp = m_thread.GetProcess ()) {
2202
- if (ABISP abi = process_sp->GetABI ())
2203
- value = abi->FixCodeAddress (reg_value);
2204
- }
2239
+ if (ABISP abi_sp = m_thread.GetProcess ()->GetABI ())
2240
+ value = abi_sp->FixCodeAddress (reg_value);
2205
2241
}
2206
2242
}
2207
2243
}
@@ -2283,9 +2319,8 @@ bool RegisterContextUnwind::GetStartPC(addr_t &start_pc) {
2283
2319
ProcessSP process_sp (m_thread.GetProcess ());
2284
2320
if (process_sp)
2285
2321
{
2286
- ABI *abi = process_sp->GetABI ().get ();
2287
- if (abi)
2288
- start_pc = abi->FixCodeAddress (start_pc);
2322
+ if (ABISP abi_sp = process_sp->GetABI ())
2323
+ start_pc = abi_sp->FixCodeAddress (start_pc);
2289
2324
}
2290
2325
}
2291
2326
return read_successfully;
@@ -2313,13 +2348,8 @@ bool RegisterContextUnwind::ReadPC(addr_t &pc) {
2313
2348
// through a NULL pointer -- we want to be able to unwind past that frame
2314
2349
// to help find the bug.
2315
2350
2316
- ProcessSP process_sp (m_thread.GetProcess ());
2317
- if (process_sp)
2318
- {
2319
- ABI *abi = process_sp->GetABI ().get ();
2320
- if (abi)
2321
- pc = abi->FixCodeAddress (pc);
2322
- }
2351
+ if (ABISP abi_sp = m_thread.GetProcess ()->GetABI ())
2352
+ pc = abi_sp->FixCodeAddress (pc);
2323
2353
2324
2354
return !(m_all_registers_available == false &&
2325
2355
above_trap_handler == false && (pc == 0 || pc == 1 ));
0 commit comments