blob: d9f7e0f965cec37d28c1ce72a6ee092177014cbd [file] [log] [blame]
Jim Ingham642036f2010-09-23 02:01:19 +00001//===-- LanguageRuntime.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/Target/LanguageRuntime.h"
Jim Ingham3df164e2012-03-05 04:47:34 +000011#include "lldb/Target/Target.h"
Jim Ingham642036f2010-09-23 02:01:19 +000012#include "lldb/Core/PluginManager.h"
13
14using namespace lldb;
15using namespace lldb_private;
16
17LanguageRuntime*
18LanguageRuntime::FindPlugin (Process *process, lldb::LanguageType language)
19{
20 std::auto_ptr<LanguageRuntime> language_runtime_ap;
21 LanguageRuntimeCreateInstance create_callback;
22
23 for (uint32_t idx = 0;
24 (create_callback = PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(idx)) != NULL;
25 ++idx)
26 {
27 language_runtime_ap.reset (create_callback(process, language));
28
29 if (language_runtime_ap.get())
30 return language_runtime_ap.release();
31 }
32
33 return NULL;
34}
35
36//----------------------------------------------------------------------
37// Constructor
38//----------------------------------------------------------------------
Jim Inghamb66cd072010-09-28 01:25:32 +000039LanguageRuntime::LanguageRuntime(Process *process) :
40 m_process (process)
Jim Ingham642036f2010-09-23 02:01:19 +000041{
42}
43
44//----------------------------------------------------------------------
45// Destructor
46//----------------------------------------------------------------------
47LanguageRuntime::~LanguageRuntime()
48{
49}
Jim Ingham3df164e2012-03-05 04:47:34 +000050
51BreakpointSP
52LanguageRuntime::CreateExceptionBreakpoint(
53 Target &target,
54 lldb::LanguageType language,
55 bool catch_bp,
56 bool throw_bp,
57 bool is_internal)
58{
59 BreakpointSP exc_breakpt_sp;
60 BreakpointResolverSP resolver_sp(new ExceptionBreakpointResolver(NULL, language, catch_bp, throw_bp));
61 SearchFilterSP filter_sp(target.GetSearchFilterForModule(NULL));
62
63 exc_breakpt_sp = target.CreateBreakpoint (filter_sp, resolver_sp, is_internal);
64
65 return exc_breakpt_sp;
66}
67
68LanguageRuntime::ExceptionBreakpointResolver::ExceptionBreakpointResolver (Breakpoint *bkpt,
69 LanguageType language,
70 bool catch_bp,
71 bool throw_bp) :
Jim Ingham4722b102012-03-06 00:37:27 +000072 BreakpointResolver (bkpt, BreakpointResolver::ExceptionResolver),
Jim Ingham3df164e2012-03-05 04:47:34 +000073 m_language (language),
74 m_catch_bp (catch_bp),
75 m_throw_bp (throw_bp)
76
77{
78}
79
80void
81LanguageRuntime::ExceptionBreakpointResolver::GetDescription (Stream *s)
82{
Jim Ingham4722b102012-03-06 00:37:27 +000083 s->Printf ("Exception breakpoint (catch: %s throw: %s)",
Jim Ingham3df164e2012-03-05 04:47:34 +000084 m_catch_bp ? "on" : "off",
85 m_throw_bp ? "on" : "off");
86
87 SetActualResolver();
88 if (m_actual_resolver_sp)
89 {
90 s->Printf (" using: ");
91 m_actual_resolver_sp->GetDescription (s);
92 }
93 else
Jim Ingham4722b102012-03-06 00:37:27 +000094 s->Printf (" the correct runtime exception handler will be determined when you run");
Jim Ingham3df164e2012-03-05 04:47:34 +000095}
96
97bool
98LanguageRuntime::ExceptionBreakpointResolver::SetActualResolver()
99{
100 ProcessSP process_sp = m_process_wp.lock();
101
102 // See if our process weak pointer is still good:
103 if (!process_sp)
104 {
105 // If not, our resolver is no good, so chuck that. Then see if we can get the
106 // target's new process.
107 m_actual_resolver_sp.reset();
108 if (m_breakpoint)
109 {
110 Target &target = m_breakpoint->GetTarget();
111 process_sp = target.GetProcessSP();
112 if (process_sp)
113 {
114 m_process_wp = process_sp;
115 process_sp = m_process_wp.lock();
116 }
117 }
118 }
119
120 if (process_sp)
121 {
122 if (m_actual_resolver_sp)
123 return true;
124 else
125 {
126 // If we have a process but not a resolver, set one now.
127 LanguageRuntime *runtime = process_sp->GetLanguageRuntime(m_language);
128 if (runtime)
129 {
130 m_actual_resolver_sp = runtime->CreateExceptionResolver (m_breakpoint, m_catch_bp, m_throw_bp);
Jim Ingham9880efa2012-08-11 00:35:26 +0000131 return (bool) m_actual_resolver_sp;
Jim Ingham3df164e2012-03-05 04:47:34 +0000132 }
133 else
134 return false;
135 }
136 }
137 else
138 return false;
139}
140
141Searcher::CallbackReturn
142LanguageRuntime::ExceptionBreakpointResolver::SearchCallback (SearchFilter &filter,
143 SymbolContext &context,
144 Address *addr,
145 bool containing)
146{
147
148 if (!SetActualResolver())
149 {
150 return eCallbackReturnStop;
151 }
152 else
153 return m_actual_resolver_sp->SearchCallback (filter, context, addr, containing);
154}
155
156Searcher::Depth
157LanguageRuntime::ExceptionBreakpointResolver::GetDepth ()
158{
159 if (!SetActualResolver())
160 return eDepthTarget;
161 else
162 return m_actual_resolver_sp->GetDepth();
163}
164
Jim Ingham4722b102012-03-06 00:37:27 +0000165static const char *language_names[] =
166{
167 "unknown",
168 "c89",
169 "c",
170 "ada83",
171 "c++",
172 "cobol74",
173 "cobol85",
174 "fortran77",
175 "fortran90",
176 "pascal83",
177 "modula2",
178 "java",
179 "c99",
180 "ada95",
181 "fortran95",
182 "pli",
183 "objective-c",
184 "objective-c++",
185 "upc",
186 "d",
187 "python"
188};
189static uint32_t num_languages = sizeof(language_names) / sizeof (char *);
190
191LanguageType
192LanguageRuntime::GetLanguageTypeFromString (const char *string)
193{
194 for (uint32_t i = 0; i < num_languages; i++)
195 {
196 if (strcmp (language_names[i], string) == 0)
197 return (LanguageType) i;
198 }
199 return eLanguageTypeUnknown;
200}
201
202const char *
203LanguageRuntime::GetNameForLanguageType (LanguageType language)
204{
205 if (language < num_languages)
206 return language_names[language];
207 else
208 return language_names[eLanguageTypeUnknown];
209}
210