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 "lldb/Core/Address.h"
13 #include "lldb/Core/ArchSpec.h"
14 #include "lldb/Core/DataBufferHeap.h"
15 #include "lldb/Core/DataExtractor.h"
16 #include "lldb/Core/Disassembler.h"
17 #include "lldb/Core/Error.h"
18 #include "lldb/Core/FormatEntity.h"
19 #include "lldb/Core/Log.h"
20 #include "lldb/Core/PluginManager.h"
21 #include "lldb/Core/StreamString.h"
22 #include "lldb/Target/ExecutionContext.h"
23 #include "lldb/Target/Process.h"
24 #include "lldb/Target/Thread.h"
25 #include "lldb/Target/Target.h"
26 
27 using namespace lldb;
28 using namespace lldb_private;
29 
30 
31 
32 //-----------------------------------------------------------------------------------------------
33 //  UnwindAssemblyInstEmulation method definitions
34 //-----------------------------------------------------------------------------------------------
35 
36 bool
37 UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly (AddressRange& range,
38                                                                    Thread& thread,
39                                                                    UnwindPlan& unwind_plan)
40 {
41     if (range.GetByteSize() > 0 &&
42         range.GetBaseAddress().IsValid() &&
43         m_inst_emulator_ap.get())
44     {
45 
46         // The instruction emulation subclass setup the unwind plan for the
47         // first instruction.
48         m_inst_emulator_ap->CreateFunctionEntryUnwind (unwind_plan);
49 
50         // CreateFunctionEntryUnwind should have created the first row. If it
51         // doesn't, then we are done.
52         if (unwind_plan.GetRowCount() == 0)
53             return false;
54 
55         ExecutionContext exe_ctx;
56         thread.CalculateExecutionContext(exe_ctx);
57         const bool prefer_file_cache = true;
58         DisassemblerSP disasm_sp (Disassembler::DisassembleRange (m_arch,
59                                                                   NULL,
60                                                                   NULL,
61                                                                   exe_ctx,
62                                                                   range,
63                                                                   prefer_file_cache));
64 
65         Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND));
66 
67         if (disasm_sp)
68         {
69 
70             m_range_ptr = ⦥
71             m_thread_ptr = &thread;
72             m_unwind_plan_ptr = &unwind_plan;
73 
74             const uint32_t addr_byte_size = m_arch.GetAddressByteSize();
75             const bool show_address = true;
76             const bool show_bytes = true;
77             m_inst_emulator_ap->GetRegisterInfo (unwind_plan.GetRegisterKind(),
78                                                  unwind_plan.GetInitialCFARegister(),
79                                                  m_cfa_reg_info);
80 
81             m_fp_is_cfa = false;
82             m_register_values.clear();
83             m_pushed_regs.clear();
84 
85             // Initialize the CFA with a known value. In the 32 bit case
86             // it will be 0x80000000, and in the 64 bit case 0x8000000000000000.
87             // We use the address byte size to be safe for any future address sizes
88             m_initial_sp = (1ull << ((addr_byte_size * 8) - 1));
89             RegisterValue cfa_reg_value;
90             cfa_reg_value.SetUInt (m_initial_sp, m_cfa_reg_info.byte_size);
91             SetRegisterValue (m_cfa_reg_info, cfa_reg_value);
92 
93             const InstructionList &inst_list = disasm_sp->GetInstructionList ();
94             const size_t num_instructions = inst_list.GetSize();
95 
96             if (num_instructions > 0)
97             {
98                 Instruction *inst = inst_list.GetInstructionAtIndex (0).get();
99                 const lldb::addr_t base_addr = inst->GetAddress().GetFileAddress();
100 
101                 // Map for storing the unwind plan row and the value of the registers at a given offset.
102                 // When we see a forward branch we add a new entry to this map with the actual unwind plan
103                 // row and register context for the target address of the branch as the current data have
104                 // to be valid for the target address of the branch too if we are in the same function.
105                 std::map<lldb::addr_t, std::pair<UnwindPlan::RowSP, RegisterValueMap>> saved_unwind_states;
106 
107                 // Make a copy of the current instruction Row and save it in m_curr_row
108                 // so we can add updates as we process the instructions.
109                 UnwindPlan::RowSP last_row = unwind_plan.GetLastRow();
110                 UnwindPlan::Row *newrow = new UnwindPlan::Row;
111                 if (last_row.get())
112                     *newrow = *last_row.get();
113                 m_curr_row.reset(newrow);
114 
115                 // Add the initial state to the save list with offset 0.
116                 saved_unwind_states.insert({0, {last_row, m_register_values}});
117 
118                 // cache the pc register number (in whatever register numbering this UnwindPlan uses) for
119                 // quick reference during instruction parsing.
120                 RegisterInfo pc_reg_info;
121                 m_inst_emulator_ap->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, pc_reg_info);
122 
123                 // cache the return address register number (in whatever register numbering this UnwindPlan uses) for
124                 // quick reference during instruction parsing.
125                 RegisterInfo ra_reg_info;
126                 m_inst_emulator_ap->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA, ra_reg_info);
127 
128                 for (size_t idx=0; idx<num_instructions; ++idx)
129                 {
130                     m_curr_row_modified = false;
131                     m_forward_branch_offset = 0;
132 
133                     inst = inst_list.GetInstructionAtIndex (idx).get();
134                     if (inst)
135                     {
136                         lldb::addr_t current_offset = inst->GetAddress().GetFileAddress() - base_addr;
137                         auto it = saved_unwind_states.upper_bound(current_offset);
138                         assert(it != saved_unwind_states.begin() && "Unwind row for the function entry missing");
139                         --it; // Move it to the row corresponding to the current offset
140 
141                         // If the offset of m_curr_row don't match with the offset we see in saved_unwind_states
142                         // then we have to update m_curr_row and m_register_values based on the saved values. It
143                         // is happenning after we processed an epilogue and a return to caller instruction.
144                         if (it->second.first->GetOffset() != m_curr_row->GetOffset())
145                         {
146                             UnwindPlan::Row *newrow = new UnwindPlan::Row;
147                             *newrow = *it->second.first;
148                             m_curr_row.reset(newrow);
149                             m_register_values = it->second.second;;
150                         }
151 
152                         if (log && log->GetVerbose ())
153                         {
154                             StreamString strm;
155                             lldb_private::FormatEntity::Entry format;
156                             FormatEntity::Parse("${frame.pc}: ", format);
157                             inst->Dump(&strm, inst_list.GetMaxOpcocdeByteSize (), show_address, show_bytes, NULL, NULL, NULL, &format, 0);
158                             log->PutCString (strm.GetData());
159                         }
160 
161                         m_inst_emulator_ap->SetInstruction (inst->GetOpcode(),
162                                                             inst->GetAddress(),
163                                                             exe_ctx.GetTargetPtr());
164 
165                         m_inst_emulator_ap->EvaluateInstruction (eEmulateInstructionOptionIgnoreConditions);
166 
167                         // If the current instruction is a branch forward then save the current CFI information
168                         // for the offset where we are branching.
169                         if (m_forward_branch_offset != 0 && range.ContainsFileAddress(inst->GetAddress().GetFileAddress() + m_forward_branch_offset))
170                         {
171                             auto newrow = std::make_shared<UnwindPlan::Row>(*m_curr_row.get());
172                             newrow->SetOffset(current_offset + m_forward_branch_offset);
173                             saved_unwind_states.insert({current_offset + m_forward_branch_offset, {newrow, m_register_values}});
174                             unwind_plan.InsertRow(newrow);
175                         }
176 
177                         // Were there any changes to the CFI while evaluating this instruction?
178                         if (m_curr_row_modified)
179                         {
180                             // Save the modified row if we don't already have a CFI row in the currennt address
181                             if (saved_unwind_states.count(current_offset + inst->GetOpcode().GetByteSize()) == 0)
182                             {
183                                 m_curr_row->SetOffset (current_offset + inst->GetOpcode().GetByteSize());
184                                 unwind_plan.InsertRow (m_curr_row);
185                                 saved_unwind_states.insert({current_offset + inst->GetOpcode().GetByteSize(), {m_curr_row, m_register_values}});
186 
187                                 // Allocate a new Row for m_curr_row, copy the current state into it
188                                 UnwindPlan::Row *newrow = new UnwindPlan::Row;
189                                 *newrow = *m_curr_row.get();
190                                 m_curr_row.reset(newrow);
191                             }
192                         }
193                     }
194                 }
195             }
196             // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
197             // I'll fix that but for now, just clear the list and it will go away nicely.
198             disasm_sp->GetInstructionList().Clear();
199         }
200 
201         if (log && log->GetVerbose ())
202         {
203             StreamString strm;
204             lldb::addr_t base_addr = range.GetBaseAddress().GetLoadAddress(thread.CalculateTarget().get());
205             strm.Printf ("Resulting unwind rows for [0x%" PRIx64 " - 0x%" PRIx64 "):", base_addr, base_addr + range.GetByteSize());
206             unwind_plan.Dump(strm, &thread, base_addr);
207             log->PutCString (strm.GetData());
208         }
209         return unwind_plan.GetRowCount() > 0;
210     }
211     return false;
212 }
213 
214 bool
215 UnwindAssemblyInstEmulation::AugmentUnwindPlanFromCallSite (AddressRange& func,
216                                                             Thread& thread,
217                                                             UnwindPlan& unwind_plan)
218 {
219     return false;
220 }
221 
222 bool
223 UnwindAssemblyInstEmulation::GetFastUnwindPlan (AddressRange& func,
224                                                 Thread& thread,
225                                                 UnwindPlan &unwind_plan)
226 {
227     return false;
228 }
229 
230 bool
231 UnwindAssemblyInstEmulation::FirstNonPrologueInsn (AddressRange& func,
232                                                    const ExecutionContext &exe_ctx,
233                                                    Address& first_non_prologue_insn)
234 {
235     return false;
236 }
237 
238 UnwindAssembly *
239 UnwindAssemblyInstEmulation::CreateInstance (const ArchSpec &arch)
240 {
241     std::unique_ptr<EmulateInstruction> inst_emulator_ap (EmulateInstruction::FindPlugin (arch, eInstructionTypePrologueEpilogue, NULL));
242     // Make sure that all prologue instructions are handled
243     if (inst_emulator_ap.get())
244         return new UnwindAssemblyInstEmulation (arch, inst_emulator_ap.release());
245     return NULL;
246 }
247 
248 
249 //------------------------------------------------------------------
250 // PluginInterface protocol in UnwindAssemblyParser_x86
251 //------------------------------------------------------------------
252 ConstString
253 UnwindAssemblyInstEmulation::GetPluginName()
254 {
255     return GetPluginNameStatic();
256 }
257 
258 uint32_t
259 UnwindAssemblyInstEmulation::GetPluginVersion()
260 {
261     return 1;
262 }
263 
264 void
265 UnwindAssemblyInstEmulation::Initialize()
266 {
267     PluginManager::RegisterPlugin (GetPluginNameStatic(),
268                                    GetPluginDescriptionStatic(),
269                                    CreateInstance);
270 }
271 
272 void
273 UnwindAssemblyInstEmulation::Terminate()
274 {
275     PluginManager::UnregisterPlugin (CreateInstance);
276 }
277 
278 
279 ConstString
280 UnwindAssemblyInstEmulation::GetPluginNameStatic()
281 {
282     static ConstString g_name("inst-emulation");
283     return g_name;
284 }
285 
286 const char *
287 UnwindAssemblyInstEmulation::GetPluginDescriptionStatic()
288 {
289     return "Instruction emulation based unwind information.";
290 }
291 
292 
293 uint64_t
294 UnwindAssemblyInstEmulation::MakeRegisterKindValuePair (const RegisterInfo &reg_info)
295 {
296     lldb::RegisterKind reg_kind;
297     uint32_t reg_num;
298     if (EmulateInstruction::GetBestRegisterKindAndNumber (&reg_info, reg_kind, reg_num))
299         return (uint64_t)reg_kind << 24 | reg_num;
300     return 0ull;
301 }
302 
303 void
304 UnwindAssemblyInstEmulation::SetRegisterValue (const RegisterInfo &reg_info, const RegisterValue &reg_value)
305 {
306     m_register_values[MakeRegisterKindValuePair (reg_info)] = reg_value;
307 }
308 
309 bool
310 UnwindAssemblyInstEmulation::GetRegisterValue (const RegisterInfo &reg_info, RegisterValue &reg_value)
311 {
312     const uint64_t reg_id = MakeRegisterKindValuePair (reg_info);
313     RegisterValueMap::const_iterator pos = m_register_values.find(reg_id);
314     if (pos != m_register_values.end())
315     {
316         reg_value = pos->second;
317         return true; // We had a real value that comes from an opcode that wrote
318                      // to it...
319     }
320     // We are making up a value that is recognizable...
321     reg_value.SetUInt(reg_id, reg_info.byte_size);
322     return false;
323 }
324 
325 
326 size_t
327 UnwindAssemblyInstEmulation::ReadMemory (EmulateInstruction *instruction,
328                                          void *baton,
329                                          const EmulateInstruction::Context &context,
330                                          lldb::addr_t addr,
331                                          void *dst,
332                                          size_t dst_len)
333 {
334     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND));
335 
336     if (log && log->GetVerbose ())
337     {
338         StreamString strm;
339         strm.Printf ("UnwindAssemblyInstEmulation::ReadMemory    (addr = 0x%16.16" PRIx64 ", dst = %p, dst_len = %" PRIu64 ", context = ",
340                      addr,
341                      dst,
342                      (uint64_t)dst_len);
343         context.Dump(strm, instruction);
344         log->PutCString (strm.GetData ());
345     }
346     memset (dst, 0, dst_len);
347     return dst_len;
348 }
349 
350 size_t
351 UnwindAssemblyInstEmulation::WriteMemory (EmulateInstruction *instruction,
352                                           void *baton,
353                                           const EmulateInstruction::Context &context,
354                                           lldb::addr_t addr,
355                                           const void *dst,
356                                           size_t dst_len)
357 {
358     if (baton && dst && dst_len)
359         return ((UnwindAssemblyInstEmulation *)baton)->WriteMemory (instruction, context, addr, dst, dst_len);
360     return 0;
361 }
362 
363 size_t
364 UnwindAssemblyInstEmulation::WriteMemory (EmulateInstruction *instruction,
365                                           const EmulateInstruction::Context &context,
366                                           lldb::addr_t addr,
367                                           const void *dst,
368                                           size_t dst_len)
369 {
370     DataExtractor data (dst,
371                         dst_len,
372                         instruction->GetArchitecture ().GetByteOrder(),
373                         instruction->GetArchitecture ().GetAddressByteSize());
374 
375     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND));
376 
377     if (log && log->GetVerbose ())
378     {
379         StreamString strm;
380 
381         strm.PutCString ("UnwindAssemblyInstEmulation::WriteMemory   (");
382         data.Dump(&strm, 0, eFormatBytes, 1, dst_len, UINT32_MAX, addr, 0, 0);
383         strm.PutCString (", context = ");
384         context.Dump(strm, instruction);
385         log->PutCString (strm.GetData());
386     }
387 
388     const bool cant_replace = false;
389 
390     switch (context.type)
391     {
392         default:
393         case EmulateInstruction::eContextInvalid:
394         case EmulateInstruction::eContextReadOpcode:
395         case EmulateInstruction::eContextImmediate:
396         case EmulateInstruction::eContextAdjustBaseRegister:
397         case EmulateInstruction::eContextRegisterPlusOffset:
398         case EmulateInstruction::eContextAdjustPC:
399         case EmulateInstruction::eContextRegisterStore:
400         case EmulateInstruction::eContextRegisterLoad:
401         case EmulateInstruction::eContextRelativeBranchImmediate:
402         case EmulateInstruction::eContextAbsoluteBranchRegister:
403         case EmulateInstruction::eContextSupervisorCall:
404         case EmulateInstruction::eContextTableBranchReadMemory:
405         case EmulateInstruction::eContextWriteRegisterRandomBits:
406         case EmulateInstruction::eContextWriteMemoryRandomBits:
407         case EmulateInstruction::eContextArithmetic:
408         case EmulateInstruction::eContextAdvancePC:
409         case EmulateInstruction::eContextReturnFromException:
410         case EmulateInstruction::eContextPopRegisterOffStack:
411         case EmulateInstruction::eContextAdjustStackPointer:
412             break;
413 
414         case EmulateInstruction::eContextPushRegisterOnStack:
415             {
416                 uint32_t reg_num = LLDB_INVALID_REGNUM;
417                 uint32_t generic_regnum = LLDB_INVALID_REGNUM;
418                 if (context.info_type == EmulateInstruction::eInfoTypeRegisterToRegisterPlusOffset)
419                 {
420                     const uint32_t unwind_reg_kind = m_unwind_plan_ptr->GetRegisterKind();
421                     reg_num = context.info.RegisterToRegisterPlusOffset.data_reg.kinds[unwind_reg_kind];
422                     generic_regnum = context.info.RegisterToRegisterPlusOffset.data_reg.kinds[eRegisterKindGeneric];
423                 }
424                 else
425                     assert (!"unhandled case, add code to handle this!");
426 
427                 if (reg_num != LLDB_INVALID_REGNUM && generic_regnum != LLDB_REGNUM_GENERIC_SP)
428                 {
429                     if (m_pushed_regs.find (reg_num) == m_pushed_regs.end())
430                     {
431                         m_pushed_regs[reg_num] = addr;
432                         const int32_t offset = addr - m_initial_sp;
433                         m_curr_row->SetRegisterLocationToAtCFAPlusOffset (reg_num, offset, cant_replace);
434                         m_curr_row_modified = true;
435                     }
436                 }
437             }
438             break;
439 
440     }
441 
442     return dst_len;
443 }
444 
445 bool
446 UnwindAssemblyInstEmulation::ReadRegister (EmulateInstruction *instruction,
447                                            void *baton,
448                                            const RegisterInfo *reg_info,
449                                            RegisterValue &reg_value)
450 {
451 
452     if (baton && reg_info)
453         return ((UnwindAssemblyInstEmulation *)baton)->ReadRegister (instruction, reg_info, reg_value);
454     return false;
455 }
456 bool
457 UnwindAssemblyInstEmulation::ReadRegister (EmulateInstruction *instruction,
458                                            const RegisterInfo *reg_info,
459                                            RegisterValue &reg_value)
460 {
461     bool synthetic = GetRegisterValue (*reg_info, reg_value);
462 
463     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND));
464 
465     if (log && log->GetVerbose ())
466     {
467 
468         StreamString strm;
469         strm.Printf ("UnwindAssemblyInstEmulation::ReadRegister  (name = \"%s\") => synthetic_value = %i, value = ", reg_info->name, synthetic);
470         reg_value.Dump(&strm, reg_info, false, false, eFormatDefault);
471         log->PutCString(strm.GetData());
472     }
473     return true;
474 }
475 
476 bool
477 UnwindAssemblyInstEmulation::WriteRegister (EmulateInstruction *instruction,
478                                             void *baton,
479                                             const EmulateInstruction::Context &context,
480                                             const RegisterInfo *reg_info,
481                                             const RegisterValue &reg_value)
482 {
483     if (baton && reg_info)
484         return ((UnwindAssemblyInstEmulation *)baton)->WriteRegister (instruction, context, reg_info, reg_value);
485     return false;
486 }
487 bool
488 UnwindAssemblyInstEmulation::WriteRegister (EmulateInstruction *instruction,
489                                             const EmulateInstruction::Context &context,
490                                             const RegisterInfo *reg_info,
491                                             const RegisterValue &reg_value)
492 {
493     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND));
494 
495     if (log && log->GetVerbose ())
496     {
497 
498         StreamString strm;
499         strm.Printf ("UnwindAssemblyInstEmulation::WriteRegister (name = \"%s\", value = ", reg_info->name);
500         reg_value.Dump(&strm, reg_info, false, false, eFormatDefault);
501         strm.PutCString (", context = ");
502         context.Dump(strm, instruction);
503         log->PutCString(strm.GetData());
504     }
505 
506     if (!instruction->IsInstructionConditional())
507         SetRegisterValue (*reg_info, reg_value);
508 
509     switch (context.type)
510     {
511         case EmulateInstruction::eContextInvalid:
512         case EmulateInstruction::eContextReadOpcode:
513         case EmulateInstruction::eContextImmediate:
514         case EmulateInstruction::eContextAdjustBaseRegister:
515         case EmulateInstruction::eContextRegisterPlusOffset:
516         case EmulateInstruction::eContextAdjustPC:
517         case EmulateInstruction::eContextRegisterStore:
518         case EmulateInstruction::eContextSupervisorCall:
519         case EmulateInstruction::eContextTableBranchReadMemory:
520         case EmulateInstruction::eContextWriteRegisterRandomBits:
521         case EmulateInstruction::eContextWriteMemoryRandomBits:
522         case EmulateInstruction::eContextArithmetic:
523         case EmulateInstruction::eContextAdvancePC:
524         case EmulateInstruction::eContextReturnFromException:
525         case EmulateInstruction::eContextPushRegisterOnStack:
526         case EmulateInstruction::eContextRegisterLoad:
527 //            {
528 //                const uint32_t reg_num = reg_info->kinds[m_unwind_plan_ptr->GetRegisterKind()];
529 //                if (reg_num != LLDB_INVALID_REGNUM)
530 //                {
531 //                    const bool can_replace_only_if_unspecified = true;
532 //
533 //                    m_curr_row.SetRegisterLocationToUndefined (reg_num,
534 //                                                               can_replace_only_if_unspecified,
535 //                                                               can_replace_only_if_unspecified);
536 //                    m_curr_row_modified = true;
537 //                }
538 //            }
539             break;
540 
541         case EmulateInstruction::eContextAbsoluteBranchRegister:
542         case EmulateInstruction::eContextRelativeBranchImmediate:
543             {
544                 if (context.info_type == EmulateInstruction::eInfoTypeISAAndImmediate &&
545                     context.info.ISAAndImmediate.unsigned_data32 > 0)
546                 {
547                     m_forward_branch_offset = context.info.ISAAndImmediateSigned.signed_data32;
548                 }
549                 else if (context.info_type == EmulateInstruction::eInfoTypeISAAndImmediateSigned &&
550                          context.info.ISAAndImmediateSigned.signed_data32 > 0)
551                 {
552                     m_forward_branch_offset = context.info.ISAAndImmediate.unsigned_data32;
553                 }
554                 else if (context.info_type == EmulateInstruction::eInfoTypeImmediate &&
555                          context.info.unsigned_immediate > 0)
556                 {
557                     m_forward_branch_offset = context.info.unsigned_immediate;
558                 }
559                 else if (context.info_type == EmulateInstruction::eInfoTypeImmediateSigned &&
560                          context.info.signed_immediate > 0)
561                 {
562                     m_forward_branch_offset = context.info.signed_immediate;
563                 }
564             }
565             break;
566 
567         case EmulateInstruction::eContextPopRegisterOffStack:
568             {
569                 if (!instruction->IsInstructionConditional())
570                 {
571                     const uint32_t reg_num = reg_info->kinds[m_unwind_plan_ptr->GetRegisterKind()];
572                     const uint32_t generic_regnum = reg_info->kinds[eRegisterKindGeneric];
573                     if (reg_num != LLDB_INVALID_REGNUM && generic_regnum != LLDB_REGNUM_GENERIC_SP)
574                     {
575                         switch (context.info_type)
576                         {
577                             case EmulateInstruction::eInfoTypeAddress:
578                                 if (m_pushed_regs.find(reg_num) != m_pushed_regs.end() &&
579                                     context.info.address == m_pushed_regs[reg_num])
580                                 {
581                                     m_curr_row->SetRegisterLocationToSame(reg_num,
582                                                                           false /*must_replace*/);
583                                     m_curr_row_modified = true;
584                                 }
585                                 break;
586                             case EmulateInstruction::eInfoTypeISA:
587                                 assert((generic_regnum == LLDB_REGNUM_GENERIC_PC ||
588                                         generic_regnum == LLDB_REGNUM_GENERIC_FLAGS) &&
589                                        "eInfoTypeISA used for poping a register other the the PC/FLAGS");
590                                 if (generic_regnum != LLDB_REGNUM_GENERIC_FLAGS)
591                                 {
592                                     m_curr_row->SetRegisterLocationToSame(reg_num,
593                                                                           false /*must_replace*/);
594                                     m_curr_row_modified = true;
595                                 }
596                                 break;
597                             default:
598                                 assert(false && "unhandled case, add code to handle this!");
599                                 break;
600                         }
601                     }
602                 }
603             }
604             break;
605 
606         case EmulateInstruction::eContextSetFramePointer:
607             if (!m_fp_is_cfa && !instruction->IsInstructionConditional())
608             {
609                 m_fp_is_cfa = true;
610                 m_cfa_reg_info = *reg_info;
611                 const uint32_t cfa_reg_num = reg_info->kinds[m_unwind_plan_ptr->GetRegisterKind()];
612                 assert (cfa_reg_num != LLDB_INVALID_REGNUM);
613                 m_curr_row->GetCFAValue().SetIsRegisterPlusOffset(cfa_reg_num, m_initial_sp -
614                         reg_value.GetAsUInt64());
615                 m_curr_row_modified = true;
616             }
617             break;
618 
619         case EmulateInstruction::eContextAdjustStackPointer:
620             // If we have created a frame using the frame pointer, don't follow
621             // subsequent adjustments to the stack pointer.
622             if (!m_fp_is_cfa && !instruction->IsInstructionConditional())
623             {
624                 m_curr_row->GetCFAValue().SetIsRegisterPlusOffset(
625                         m_curr_row->GetCFAValue().GetRegisterNumber(),
626                         m_initial_sp - reg_value.GetAsUInt64());
627                 m_curr_row_modified = true;
628             }
629             break;
630     }
631     return true;
632 }
633 
634 
635