1 //===-- UnwindAssemblyInstEmulation.cpp --------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "UnwindAssemblyInstEmulation.h" 11 12 #include "llvm-c/EnhancedDisassembly.h" 13 14 #include "lldb/Core/Address.h" 15 #include "lldb/Core/ArchSpec.h" 16 #include "lldb/Core/DataBufferHeap.h" 17 #include "lldb/Core/DataExtractor.h" 18 #include "lldb/Core/Disassembler.h" 19 #include "lldb/Core/Error.h" 20 #include "lldb/Core/Log.h" 21 #include "lldb/Core/PluginManager.h" 22 #include "lldb/Core/StreamString.h" 23 #include "lldb/Target/ExecutionContext.h" 24 #include "lldb/Target/Process.h" 25 #include "lldb/Target/Thread.h" 26 #include "lldb/Target/Target.h" 27 28 using namespace lldb; 29 using namespace lldb_private; 30 31 32 33 //----------------------------------------------------------------------------------------------- 34 // UnwindAssemblyInstEmulation method definitions 35 //----------------------------------------------------------------------------------------------- 36 37 bool 38 UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly (AddressRange& range, 39 Thread& thread, 40 UnwindPlan& unwind_plan) 41 { 42 if (range.GetByteSize() > 0 && 43 range.GetBaseAddress().IsValid() && 44 m_inst_emulator_ap.get()) 45 { 46 47 // The the instruction emulation subclass setup the unwind plan for the 48 // first instruction. 49 m_inst_emulator_ap->CreateFunctionEntryUnwind (unwind_plan); 50 51 // CreateFunctionEntryUnwind should have created the first row. If it 52 // doesn't, then we are done. 53 if (unwind_plan.GetRowCount() == 0) 54 return false; 55 56 ExecutionContext exe_ctx; 57 thread.CalculateExecutionContext(exe_ctx); 58 DisassemblerSP disasm_sp (Disassembler::DisassembleRange (m_arch, 59 NULL, 60 exe_ctx, 61 range)); 62 63 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); 64 65 if (disasm_sp) 66 { 67 68 m_range_ptr = ⦥ 69 m_thread_ptr = &thread; 70 m_unwind_plan_ptr = &unwind_plan; 71 72 const uint32_t addr_byte_size = m_arch.GetAddressByteSize(); 73 const bool show_address = true; 74 const bool show_bytes = true; 75 m_inst_emulator_ap->GetRegisterInfo (unwind_plan.GetRegisterKind(), 76 unwind_plan.GetInitialCFARegister(), 77 m_cfa_reg_info); 78 79 m_fp_is_cfa = false; 80 m_register_values.clear(); 81 m_pushed_regs.clear(); 82 83 // Initialize the CFA with a known value. In the 32 bit case 84 // it will be 0x80000000, and in the 64 bit case 0x8000000000000000. 85 // We use the address byte size to be safe for any future addresss sizes 86 m_initial_sp = (1ull << ((addr_byte_size * 8) - 1)); 87 RegisterValue cfa_reg_value; 88 cfa_reg_value.SetUInt (m_initial_sp, m_cfa_reg_info.byte_size); 89 SetRegisterValue (m_cfa_reg_info, cfa_reg_value); 90 91 const InstructionList &inst_list = disasm_sp->GetInstructionList (); 92 const size_t num_instructions = inst_list.GetSize(); 93 94 if (num_instructions > 0) 95 { 96 Instruction *inst = inst_list.GetInstructionAtIndex (0).get(); 97 const addr_t base_addr = inst->GetAddress().GetFileAddress(); 98 99 // Make a copy of the current instruction Row and save it in m_curr_row 100 // so we can add updates as we process the instructions. 101 UnwindPlan::RowSP last_row = unwind_plan.GetLastRow(); 102 UnwindPlan::Row *newrow = new UnwindPlan::Row; 103 if (last_row.get()) 104 *newrow = *last_row.get(); 105 m_curr_row.reset(newrow); 106 107 // Once we've seen the initial prologue instructions complete, save a 108 // copy of the CFI at that point into prologue_completed_row for possible 109 // use later. 110 int instructions_since_last_prologue_insn = 0; // # of insns since last CFI was update 111 112 bool reinstate_prologue_next_instruction = false; // Next iteration, re-install the prologue row of CFI 113 114 bool last_instruction_restored_return_addr_reg = false; // re-install the prologue row of CFI if the next instruction is a branch immediate 115 116 bool return_address_register_has_been_saved = false; // if we've seen the ra register get saved yet 117 118 UnwindPlan::RowSP prologue_completed_row; // copy of prologue row of CFI 119 120 // cache the pc register number (in whatever register numbering this UnwindPlan uses) for 121 // quick reference during instruction parsing. 122 uint32_t pc_reg_num = LLDB_INVALID_REGNUM; 123 RegisterInfo pc_reg_info; 124 if (m_inst_emulator_ap->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, pc_reg_info)) 125 pc_reg_num = pc_reg_info.kinds[unwind_plan.GetRegisterKind()]; 126 else 127 pc_reg_num = LLDB_INVALID_REGNUM; 128 129 // cache the return address register number (in whatever register numbering this UnwindPlan uses) for 130 // quick reference during instruction parsing. 131 uint32_t ra_reg_num = LLDB_INVALID_REGNUM; 132 RegisterInfo ra_reg_info; 133 if (m_inst_emulator_ap->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA, ra_reg_info)) 134 ra_reg_num = ra_reg_info.kinds[unwind_plan.GetRegisterKind()]; 135 else 136 ra_reg_num = LLDB_INVALID_REGNUM; 137 138 for (size_t idx=0; idx<num_instructions; ++idx) 139 { 140 m_curr_row_modified = false; 141 m_curr_insn_restored_a_register = false; 142 inst = inst_list.GetInstructionAtIndex (idx).get(); 143 if (inst) 144 { 145 if (log && log->GetVerbose ()) 146 { 147 StreamString strm; 148 inst->Dump(&strm, inst_list.GetMaxOpcocdeByteSize (), show_address, show_bytes, NULL); 149 log->PutCString (strm.GetData()); 150 } 151 152 m_inst_emulator_ap->SetInstruction (inst->GetOpcode(), 153 inst->GetAddress(), 154 exe_ctx.GetTargetPtr()); 155 156 m_inst_emulator_ap->EvaluateInstruction (eEmulateInstructionOptionIgnoreConditions); 157 158 // Were there any changes to the CFI while evaluating this instruction? 159 if (m_curr_row_modified) 160 { 161 reinstate_prologue_next_instruction = false; 162 m_curr_row->SetOffset (inst->GetAddress().GetFileAddress() + inst->GetOpcode().GetByteSize() - base_addr); 163 // Append the new row 164 unwind_plan.AppendRow (m_curr_row); 165 166 // Allocate a new Row for m_curr_row, copy the current state into it 167 UnwindPlan::Row *newrow = new UnwindPlan::Row; 168 *newrow = *m_curr_row.get(); 169 m_curr_row.reset(newrow); 170 171 // If m_curr_insn_restored_a_register == true, we're looking at an epilogue instruction. 172 // Set instructions_since_last_prologue_insn to a very high number so we don't append 173 // any of these epilogue instructions to our prologue_complete row. 174 if (m_curr_insn_restored_a_register == false && instructions_since_last_prologue_insn < 8) 175 instructions_since_last_prologue_insn = 0; 176 else 177 instructions_since_last_prologue_insn = 99; 178 179 UnwindPlan::Row::RegisterLocation pc_regloc; 180 UnwindPlan::Row::RegisterLocation ra_regloc; 181 182 // While parsing the instructions of this function, if we've ever 183 // seen the return address register (aka lr on arm) in a non-IsSame() state, 184 // it has been saved on the stack. If it's evern back to IsSame(), we've 185 // executed an epilogue. 186 if (ra_reg_num != LLDB_INVALID_REGNUM 187 && m_curr_row->GetRegisterInfo (ra_reg_num, ra_regloc) 188 && !ra_regloc.IsSame()) 189 { 190 return_address_register_has_been_saved = true; 191 } 192 193 // If the caller's pc is "same", we've just executed an epilogue and we return to the caller 194 // after this instruction completes executing. 195 // If there are any instructions past this, there must have been flow control over this 196 // epilogue so we'll reinstate the original prologue setup instructions. 197 if (prologue_completed_row.get() 198 && pc_reg_num != LLDB_INVALID_REGNUM 199 && m_curr_row->GetRegisterInfo (pc_reg_num, pc_regloc) 200 && pc_regloc.IsSame()) 201 { 202 if (log && log->GetVerbose()) 203 log->Printf("UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly -- pc is <same>, restore prologue instructions."); 204 reinstate_prologue_next_instruction = true; 205 } 206 else if (prologue_completed_row.get() 207 && return_address_register_has_been_saved 208 && ra_reg_num != LLDB_INVALID_REGNUM 209 && m_curr_row->GetRegisterInfo (ra_reg_num, ra_regloc) 210 && ra_regloc.IsSame()) 211 { 212 if (log && log->GetVerbose()) 213 log->Printf("UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly -- lr is <same>, restore prologue instruction if the next instruction is a branch immediate."); 214 last_instruction_restored_return_addr_reg = true; 215 } 216 } 217 else 218 { 219 // If the previous instruction was a return-to-caller (epilogue), and we're still executing 220 // instructions in this function, there must be a code path that jumps over that epilogue. 221 // Also detect the case where we epilogue & branch imm to another function (tail-call opt) 222 // instead of a normal pop lr-into-pc exit. 223 // Reinstate the frame setup from the prologue. 224 if (reinstate_prologue_next_instruction 225 || (m_curr_insn_is_branch_immediate && last_instruction_restored_return_addr_reg)) 226 { 227 if (log && log->GetVerbose()) 228 log->Printf("UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly -- Reinstating prologue instruction set"); 229 UnwindPlan::Row *newrow = new UnwindPlan::Row; 230 *newrow = *prologue_completed_row.get(); 231 m_curr_row.reset(newrow); 232 m_curr_row->SetOffset (inst->GetAddress().GetFileAddress() + inst->GetOpcode().GetByteSize() - base_addr); 233 unwind_plan.AppendRow(m_curr_row); 234 235 newrow = new UnwindPlan::Row; 236 *newrow = *m_curr_row.get(); 237 m_curr_row.reset(newrow); 238 239 reinstate_prologue_next_instruction = false; 240 last_instruction_restored_return_addr_reg = false; 241 m_curr_insn_is_branch_immediate = false; 242 } 243 244 // clear both of these if either one wasn't set 245 if (last_instruction_restored_return_addr_reg) 246 { 247 last_instruction_restored_return_addr_reg = false; 248 } 249 if (m_curr_insn_is_branch_immediate) 250 { 251 m_curr_insn_is_branch_immediate = false; 252 } 253 254 // Stop updating the prologue instructions if we've seen 8 non-prologue instructions 255 // in a row. 256 if (instructions_since_last_prologue_insn++ < 8) 257 { 258 UnwindPlan::Row *newrow = new UnwindPlan::Row; 259 *newrow = *m_curr_row.get(); 260 prologue_completed_row.reset(newrow); 261 if (log && log->GetVerbose()) 262 log->Printf("UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly -- saving a copy of the current row as the prologue row."); 263 } 264 } 265 } 266 } 267 } 268 } 269 270 if (log && log->GetVerbose ()) 271 { 272 StreamString strm; 273 lldb::addr_t base_addr = range.GetBaseAddress().GetLoadAddress(thread.CalculateTarget().get()); 274 strm.Printf ("Resulting unwind rows for [0x%llx - 0x%llx):", base_addr, base_addr + range.GetByteSize()); 275 unwind_plan.Dump(strm, &thread, base_addr); 276 log->PutCString (strm.GetData()); 277 } 278 return unwind_plan.GetRowCount() > 0; 279 } 280 return false; 281 } 282 283 bool 284 UnwindAssemblyInstEmulation::GetFastUnwindPlan (AddressRange& func, 285 Thread& thread, 286 UnwindPlan &unwind_plan) 287 { 288 return false; 289 } 290 291 bool 292 UnwindAssemblyInstEmulation::FirstNonPrologueInsn (AddressRange& func, 293 const ExecutionContext &exe_ctx, 294 Address& first_non_prologue_insn) 295 { 296 return false; 297 } 298 299 UnwindAssembly * 300 UnwindAssemblyInstEmulation::CreateInstance (const ArchSpec &arch) 301 { 302 std::auto_ptr<EmulateInstruction> inst_emulator_ap (EmulateInstruction::FindPlugin (arch, eInstructionTypePrologueEpilogue, NULL)); 303 // Make sure that all prologue instructions are handled 304 if (inst_emulator_ap.get()) 305 return new UnwindAssemblyInstEmulation (arch, inst_emulator_ap.release()); 306 return NULL; 307 } 308 309 310 //------------------------------------------------------------------ 311 // PluginInterface protocol in UnwindAssemblyParser_x86 312 //------------------------------------------------------------------ 313 314 const char * 315 UnwindAssemblyInstEmulation::GetPluginName() 316 { 317 return "UnwindAssemblyInstEmulation"; 318 } 319 320 const char * 321 UnwindAssemblyInstEmulation::GetShortPluginName() 322 { 323 return "unwindassembly.inst-emulation"; 324 } 325 326 327 uint32_t 328 UnwindAssemblyInstEmulation::GetPluginVersion() 329 { 330 return 1; 331 } 332 333 void 334 UnwindAssemblyInstEmulation::Initialize() 335 { 336 PluginManager::RegisterPlugin (GetPluginNameStatic(), 337 GetPluginDescriptionStatic(), 338 CreateInstance); 339 } 340 341 void 342 UnwindAssemblyInstEmulation::Terminate() 343 { 344 PluginManager::UnregisterPlugin (CreateInstance); 345 } 346 347 348 const char * 349 UnwindAssemblyInstEmulation::GetPluginNameStatic() 350 { 351 return "UnwindAssemblyInstEmulation"; 352 } 353 354 const char * 355 UnwindAssemblyInstEmulation::GetPluginDescriptionStatic() 356 { 357 return "Instruction emulation based unwind information."; 358 } 359 360 361 uint64_t 362 UnwindAssemblyInstEmulation::MakeRegisterKindValuePair (const RegisterInfo ®_info) 363 { 364 uint32_t reg_kind, reg_num; 365 if (EmulateInstruction::GetBestRegisterKindAndNumber (®_info, reg_kind, reg_num)) 366 return (uint64_t)reg_kind << 24 | reg_num; 367 return 0ull; 368 } 369 370 void 371 UnwindAssemblyInstEmulation::SetRegisterValue (const RegisterInfo ®_info, const RegisterValue ®_value) 372 { 373 m_register_values[MakeRegisterKindValuePair (reg_info)] = reg_value; 374 } 375 376 bool 377 UnwindAssemblyInstEmulation::GetRegisterValue (const RegisterInfo ®_info, RegisterValue ®_value) 378 { 379 const uint64_t reg_id = MakeRegisterKindValuePair (reg_info); 380 RegisterValueMap::const_iterator pos = m_register_values.find(reg_id); 381 if (pos != m_register_values.end()) 382 { 383 reg_value = pos->second; 384 return true; // We had a real value that comes from an opcode that wrote 385 // to it... 386 } 387 // We are making up a value that is recognizable... 388 reg_value.SetUInt(reg_id, reg_info.byte_size); 389 return false; 390 } 391 392 393 size_t 394 UnwindAssemblyInstEmulation::ReadMemory (EmulateInstruction *instruction, 395 void *baton, 396 const EmulateInstruction::Context &context, 397 lldb::addr_t addr, 398 void *dst, 399 size_t dst_len) 400 { 401 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); 402 403 if (log && log->GetVerbose ()) 404 { 405 StreamString strm; 406 strm.Printf ("UnwindAssemblyInstEmulation::ReadMemory (addr = 0x%16.16llx, dst = %p, dst_len = %llu, context = ", 407 addr, 408 dst, 409 (uint64_t)dst_len); 410 context.Dump(strm, instruction); 411 log->PutCString (strm.GetData ()); 412 } 413 memset (dst, 0, dst_len); 414 return dst_len; 415 } 416 417 size_t 418 UnwindAssemblyInstEmulation::WriteMemory (EmulateInstruction *instruction, 419 void *baton, 420 const EmulateInstruction::Context &context, 421 lldb::addr_t addr, 422 const void *dst, 423 size_t dst_len) 424 { 425 if (baton && dst && dst_len) 426 return ((UnwindAssemblyInstEmulation *)baton)->WriteMemory (instruction, context, addr, dst, dst_len); 427 return 0; 428 } 429 430 size_t 431 UnwindAssemblyInstEmulation::WriteMemory (EmulateInstruction *instruction, 432 const EmulateInstruction::Context &context, 433 lldb::addr_t addr, 434 const void *dst, 435 size_t dst_len) 436 { 437 DataExtractor data (dst, 438 dst_len, 439 instruction->GetArchitecture ().GetByteOrder(), 440 instruction->GetArchitecture ().GetAddressByteSize()); 441 442 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); 443 444 if (log && log->GetVerbose ()) 445 { 446 StreamString strm; 447 448 strm.PutCString ("UnwindAssemblyInstEmulation::WriteMemory ("); 449 data.Dump(&strm, 0, eFormatBytes, 1, dst_len, UINT32_MAX, addr, 0, 0); 450 strm.PutCString (", context = "); 451 context.Dump(strm, instruction); 452 log->PutCString (strm.GetData()); 453 } 454 455 const bool can_replace = true; 456 const bool cant_replace = false; 457 458 switch (context.type) 459 { 460 default: 461 case EmulateInstruction::eContextInvalid: 462 case EmulateInstruction::eContextReadOpcode: 463 case EmulateInstruction::eContextImmediate: 464 case EmulateInstruction::eContextAdjustBaseRegister: 465 case EmulateInstruction::eContextRegisterPlusOffset: 466 case EmulateInstruction::eContextAdjustPC: 467 case EmulateInstruction::eContextRegisterStore: 468 case EmulateInstruction::eContextRegisterLoad: 469 case EmulateInstruction::eContextRelativeBranchImmediate: 470 case EmulateInstruction::eContextAbsoluteBranchRegister: 471 case EmulateInstruction::eContextSupervisorCall: 472 case EmulateInstruction::eContextTableBranchReadMemory: 473 case EmulateInstruction::eContextWriteRegisterRandomBits: 474 case EmulateInstruction::eContextWriteMemoryRandomBits: 475 case EmulateInstruction::eContextArithmetic: 476 case EmulateInstruction::eContextAdvancePC: 477 case EmulateInstruction::eContextReturnFromException: 478 case EmulateInstruction::eContextPopRegisterOffStack: 479 case EmulateInstruction::eContextAdjustStackPointer: 480 break; 481 482 case EmulateInstruction::eContextPushRegisterOnStack: 483 { 484 uint32_t reg_num = LLDB_INVALID_REGNUM; 485 bool is_return_address_reg = false; 486 const uint32_t unwind_reg_kind = m_unwind_plan_ptr->GetRegisterKind(); 487 if (context.info_type == EmulateInstruction::eInfoTypeRegisterToRegisterPlusOffset) 488 { 489 reg_num = context.info.RegisterToRegisterPlusOffset.data_reg.kinds[unwind_reg_kind]; 490 if (context.info.RegisterToRegisterPlusOffset.data_reg.kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_RA) 491 is_return_address_reg = true; 492 } 493 else 494 { 495 assert (!"unhandled case, add code to handle this!"); 496 } 497 498 if (reg_num != LLDB_INVALID_REGNUM) 499 { 500 if (m_pushed_regs.find (reg_num) == m_pushed_regs.end()) 501 { 502 m_pushed_regs[reg_num] = addr; 503 const int32_t offset = addr - m_initial_sp; 504 m_curr_row->SetRegisterLocationToAtCFAPlusOffset (reg_num, offset, cant_replace); 505 m_curr_row_modified = true; 506 if (is_return_address_reg) 507 { 508 // This push was pushing the return address register, 509 // so this is also how we will unwind the PC... 510 RegisterInfo pc_reg_info; 511 if (instruction->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, pc_reg_info)) 512 { 513 uint32_t pc_reg_num = pc_reg_info.kinds[unwind_reg_kind]; 514 if (pc_reg_num != LLDB_INVALID_REGNUM) 515 { 516 m_curr_row->SetRegisterLocationToAtCFAPlusOffset (pc_reg_num, offset, can_replace); 517 m_curr_row_modified = true; 518 } 519 } 520 } 521 } 522 } 523 } 524 break; 525 526 } 527 528 return dst_len; 529 } 530 531 bool 532 UnwindAssemblyInstEmulation::ReadRegister (EmulateInstruction *instruction, 533 void *baton, 534 const RegisterInfo *reg_info, 535 RegisterValue ®_value) 536 { 537 538 if (baton && reg_info) 539 return ((UnwindAssemblyInstEmulation *)baton)->ReadRegister (instruction, reg_info, reg_value); 540 return false; 541 } 542 bool 543 UnwindAssemblyInstEmulation::ReadRegister (EmulateInstruction *instruction, 544 const RegisterInfo *reg_info, 545 RegisterValue ®_value) 546 { 547 bool synthetic = GetRegisterValue (*reg_info, reg_value); 548 549 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); 550 551 if (log && log->GetVerbose ()) 552 { 553 554 StreamString strm; 555 strm.Printf ("UnwindAssemblyInstEmulation::ReadRegister (name = \"%s\") => synthetic_value = %i, value = ", reg_info->name, synthetic); 556 reg_value.Dump(&strm, reg_info, false, false, eFormatDefault); 557 log->PutCString(strm.GetData()); 558 } 559 return true; 560 } 561 562 bool 563 UnwindAssemblyInstEmulation::WriteRegister (EmulateInstruction *instruction, 564 void *baton, 565 const EmulateInstruction::Context &context, 566 const RegisterInfo *reg_info, 567 const RegisterValue ®_value) 568 { 569 if (baton && reg_info) 570 return ((UnwindAssemblyInstEmulation *)baton)->WriteRegister (instruction, context, reg_info, reg_value); 571 return false; 572 } 573 bool 574 UnwindAssemblyInstEmulation::WriteRegister (EmulateInstruction *instruction, 575 const EmulateInstruction::Context &context, 576 const RegisterInfo *reg_info, 577 const RegisterValue ®_value) 578 { 579 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); 580 581 if (log && log->GetVerbose ()) 582 { 583 584 StreamString strm; 585 strm.Printf ("UnwindAssemblyInstEmulation::WriteRegister (name = \"%s\", value = ", reg_info->name); 586 reg_value.Dump(&strm, reg_info, false, false, eFormatDefault); 587 strm.PutCString (", context = "); 588 context.Dump(strm, instruction); 589 log->PutCString(strm.GetData()); 590 } 591 592 const bool must_replace = true; 593 SetRegisterValue (*reg_info, reg_value); 594 595 switch (context.type) 596 { 597 default: 598 case EmulateInstruction::eContextInvalid: 599 case EmulateInstruction::eContextReadOpcode: 600 case EmulateInstruction::eContextImmediate: 601 case EmulateInstruction::eContextAdjustBaseRegister: 602 case EmulateInstruction::eContextRegisterPlusOffset: 603 case EmulateInstruction::eContextAdjustPC: 604 case EmulateInstruction::eContextRegisterStore: 605 case EmulateInstruction::eContextRegisterLoad: 606 case EmulateInstruction::eContextAbsoluteBranchRegister: 607 case EmulateInstruction::eContextSupervisorCall: 608 case EmulateInstruction::eContextTableBranchReadMemory: 609 case EmulateInstruction::eContextWriteRegisterRandomBits: 610 case EmulateInstruction::eContextWriteMemoryRandomBits: 611 case EmulateInstruction::eContextArithmetic: 612 case EmulateInstruction::eContextAdvancePC: 613 case EmulateInstruction::eContextReturnFromException: 614 case EmulateInstruction::eContextPushRegisterOnStack: 615 // { 616 // const uint32_t reg_num = reg_info->kinds[m_unwind_plan_ptr->GetRegisterKind()]; 617 // if (reg_num != LLDB_INVALID_REGNUM) 618 // { 619 // const bool can_replace_only_if_unspecified = true; 620 // 621 // m_curr_row.SetRegisterLocationToUndefined (reg_num, 622 // can_replace_only_if_unspecified, 623 // can_replace_only_if_unspecified); 624 // m_curr_row_modified = true; 625 // } 626 // } 627 break; 628 629 case EmulateInstruction::eContextRelativeBranchImmediate: 630 { 631 632 { 633 m_curr_insn_is_branch_immediate = true; 634 } 635 } 636 break; 637 638 case EmulateInstruction::eContextPopRegisterOffStack: 639 { 640 const uint32_t reg_num = reg_info->kinds[m_unwind_plan_ptr->GetRegisterKind()]; 641 if (reg_num != LLDB_INVALID_REGNUM) 642 { 643 m_curr_row->SetRegisterLocationToSame (reg_num, must_replace); 644 m_curr_row_modified = true; 645 m_curr_insn_restored_a_register = true; 646 } 647 } 648 break; 649 650 case EmulateInstruction::eContextSetFramePointer: 651 if (!m_fp_is_cfa) 652 { 653 m_fp_is_cfa = true; 654 m_cfa_reg_info = *reg_info; 655 const uint32_t cfa_reg_num = reg_info->kinds[m_unwind_plan_ptr->GetRegisterKind()]; 656 assert (cfa_reg_num != LLDB_INVALID_REGNUM); 657 m_curr_row->SetCFARegister(cfa_reg_num); 658 m_curr_row->SetCFAOffset(m_initial_sp - reg_value.GetAsUInt64()); 659 m_curr_row_modified = true; 660 } 661 break; 662 663 case EmulateInstruction::eContextAdjustStackPointer: 664 // If we have created a frame using the frame pointer, don't follow 665 // subsequent adjustments to the stack pointer. 666 if (!m_fp_is_cfa) 667 { 668 m_curr_row->SetCFAOffset (m_initial_sp - reg_value.GetAsUInt64()); 669 m_curr_row_modified = true; 670 } 671 break; 672 } 673 return true; 674 } 675 676 677