blob: 5ce4d25fc0a942b787ba7b92808065b6ec8dad11 [file] [log] [blame]
Jason Molenda3a4ea242010-09-10 07:49:16 +00001//===-- 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
23using namespace lldb;
24using namespace lldb_private;
25
26
27FuncUnwinders::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
37FuncUnwinders::~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
49UnwindPlan*
50FuncUnwinders::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
70UnwindPlan*
71FuncUnwinders::GetUnwindPlanAtNonCallSite (Thread& thread)
72{
73 if (m_unwind_at_non_call_site != NULL)
Jason Molenda8280cbe2010-10-25 11:12:07 +000074 return m_unwind_at_non_call_site;
75 UnwindPlan *up = new UnwindPlan;
76 if (!m_assembly_profiler->GetNonCallSiteUnwindPlanFromAssembly (m_range, thread, *up))
77 {
78 delete up;
79 return NULL;
80 }
81 m_unwind_at_non_call_site = up;
Jason Molenda3a4ea242010-09-10 07:49:16 +000082 return m_unwind_at_non_call_site;
83}
84
85UnwindPlan*
86FuncUnwinders::GetUnwindPlanFastUnwind (Thread& thread)
87{
88 if (m_fast_unwind != NULL)
89 return m_fast_unwind;
Jason Molenda8280cbe2010-10-25 11:12:07 +000090 UnwindPlan *up = new UnwindPlan;
91 if (!m_assembly_profiler->GetFastUnwindPlan (m_range, thread, *up))
92 {
93 delete up;
94 return NULL;
95 }
96 m_fast_unwind = up;
Jason Molenda3a4ea242010-09-10 07:49:16 +000097 return m_fast_unwind;
98}
99
100UnwindPlan*
101FuncUnwinders::GetUnwindPlanArchitectureDefault (Thread& thread)
102{
103 if (m_arch_default_unwind != NULL)
104 return m_arch_default_unwind;
105
106 Address current_pc;
107 Target *target = thread.CalculateTarget();
108 ArchSpec arch;
109 if (target)
110 {
111 ArchSpec arch = target->GetArchitecture ();
112 ArchDefaultUnwindPlan *arch_default = ArchDefaultUnwindPlan::FindPlugin (arch);
113 if (arch_default)
114 {
115 m_arch_default_unwind = arch_default->GetArchDefaultUnwindPlan (thread, current_pc);
116 }
117 }
118
119 return m_arch_default_unwind;
120}
121
122Address&
123FuncUnwinders::GetFirstNonPrologueInsn (Target& target)
124{
125 if (m_first_non_prologue_insn.IsValid())
126 return m_first_non_prologue_insn;
127 m_assembly_profiler->FirstNonPrologueInsn (m_range, target, NULL, m_first_non_prologue_insn);
128 return m_first_non_prologue_insn;
129}
130
131const Address&
132FuncUnwinders::GetFunctionStartAddress () const
133{
134 return m_range.GetBaseAddress();
135}
136