Jason Molenda | 3a4ea24 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1 | //===-- FuncUnwinders.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 "lldb/lldb-private.h" |
| 11 | #include "lldb/Symbol/FuncUnwinders.h" |
| 12 | #include "lldb/Symbol/ObjectFile.h" |
| 13 | #include "lldb/Symbol/UnwindPlan.h" |
| 14 | #include "lldb/Core/AddressRange.h" |
| 15 | #include "lldb/Core/Address.h" |
| 16 | #include "lldb/Symbol/UnwindTable.h" |
| 17 | #include "lldb/Utility/UnwindAssemblyProfiler.h" |
| 18 | #include "lldb/Utility/ArchDefaultUnwindPlan.h" |
| 19 | #include "lldb/Symbol/DWARFCallFrameInfo.h" |
| 20 | #include "lldb/Target/Thread.h" |
| 21 | #include "lldb/Target/Target.h" |
| 22 | |
| 23 | using namespace lldb; |
| 24 | using namespace lldb_private; |
| 25 | |
| 26 | |
| 27 | FuncUnwinders::FuncUnwinders (UnwindTable& unwind_table, UnwindAssemblyProfiler *assembly_profiler, AddressRange range) : |
| 28 | m_unwind_table(unwind_table), |
| 29 | m_assembly_profiler(assembly_profiler), |
| 30 | m_range(range), |
| 31 | m_unwind_at_call_site(NULL), |
| 32 | m_unwind_at_non_call_site(NULL), |
| 33 | m_fast_unwind(NULL), |
| 34 | m_arch_default_unwind(NULL), |
| 35 | m_first_non_prologue_insn() { } |
| 36 | |
| 37 | FuncUnwinders::~FuncUnwinders () |
| 38 | { |
| 39 | if (m_unwind_at_call_site) |
| 40 | delete m_unwind_at_call_site; |
| 41 | if (m_unwind_at_non_call_site) |
| 42 | delete m_unwind_at_non_call_site; |
| 43 | if (m_fast_unwind) |
| 44 | delete m_fast_unwind; |
| 45 | if (m_arch_default_unwind) |
| 46 | delete m_arch_default_unwind; |
| 47 | } |
| 48 | |
| 49 | UnwindPlan* |
| 50 | FuncUnwinders::GetUnwindPlanAtCallSite () |
| 51 | { |
| 52 | if (m_unwind_at_call_site != NULL) |
| 53 | return m_unwind_at_call_site; |
| 54 | if (!m_range.GetBaseAddress().IsValid()) |
| 55 | return NULL; |
| 56 | |
| 57 | DWARFCallFrameInfo *eh_frame = m_unwind_table.GetEHFrameInfo(); |
| 58 | if (eh_frame) |
| 59 | { |
| 60 | UnwindPlan *up = new UnwindPlan; |
| 61 | if (eh_frame->GetUnwindPlan (m_range.GetBaseAddress (), *up) == true) |
| 62 | { |
| 63 | m_unwind_at_call_site = up; |
| 64 | return m_unwind_at_call_site; |
| 65 | } |
| 66 | } |
| 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | UnwindPlan* |
| 71 | FuncUnwinders::GetUnwindPlanAtNonCallSite (Thread& thread) |
| 72 | { |
| 73 | if (m_unwind_at_non_call_site != NULL) |
| 74 | m_unwind_at_non_call_site; |
| 75 | m_unwind_at_non_call_site = new UnwindPlan; |
| 76 | m_assembly_profiler->GetNonCallSiteUnwindPlanFromAssembly (m_range, thread, *m_unwind_at_non_call_site); |
| 77 | return m_unwind_at_non_call_site; |
| 78 | } |
| 79 | |
| 80 | UnwindPlan* |
| 81 | FuncUnwinders::GetUnwindPlanFastUnwind (Thread& thread) |
| 82 | { |
| 83 | if (m_fast_unwind != NULL) |
| 84 | return m_fast_unwind; |
| 85 | m_fast_unwind = new UnwindPlan; |
| 86 | m_assembly_profiler->GetFastUnwindPlan (m_range, thread, *m_fast_unwind); |
| 87 | return m_fast_unwind; |
| 88 | } |
| 89 | |
| 90 | UnwindPlan* |
| 91 | FuncUnwinders::GetUnwindPlanArchitectureDefault (Thread& thread) |
| 92 | { |
| 93 | if (m_arch_default_unwind != NULL) |
| 94 | return m_arch_default_unwind; |
| 95 | |
| 96 | Address current_pc; |
| 97 | Target *target = thread.CalculateTarget(); |
| 98 | ArchSpec arch; |
| 99 | if (target) |
| 100 | { |
| 101 | ArchSpec arch = target->GetArchitecture (); |
| 102 | ArchDefaultUnwindPlan *arch_default = ArchDefaultUnwindPlan::FindPlugin (arch); |
| 103 | if (arch_default) |
| 104 | { |
| 105 | m_arch_default_unwind = arch_default->GetArchDefaultUnwindPlan (thread, current_pc); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return m_arch_default_unwind; |
| 110 | } |
| 111 | |
| 112 | Address& |
| 113 | FuncUnwinders::GetFirstNonPrologueInsn (Target& target) |
| 114 | { |
| 115 | if (m_first_non_prologue_insn.IsValid()) |
| 116 | return m_first_non_prologue_insn; |
| 117 | m_assembly_profiler->FirstNonPrologueInsn (m_range, target, NULL, m_first_non_prologue_insn); |
| 118 | return m_first_non_prologue_insn; |
| 119 | } |
| 120 | |
| 121 | const Address& |
| 122 | FuncUnwinders::GetFunctionStartAddress () const |
| 123 | { |
| 124 | return m_range.GetBaseAddress(); |
| 125 | } |
| 126 | |