Jim Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1 | //===-- 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 Ingham | 3df164e | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 11 | #include "lldb/Target/Target.h" |
Jim Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 12 | #include "lldb/Core/PluginManager.h" |
| 13 | |
| 14 | using namespace lldb; |
| 15 | using namespace lldb_private; |
| 16 | |
| 17 | LanguageRuntime* |
| 18 | LanguageRuntime::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 Ingham | b66cd07 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 39 | LanguageRuntime::LanguageRuntime(Process *process) : |
| 40 | m_process (process) |
Jim Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 41 | { |
| 42 | } |
| 43 | |
| 44 | //---------------------------------------------------------------------- |
| 45 | // Destructor |
| 46 | //---------------------------------------------------------------------- |
| 47 | LanguageRuntime::~LanguageRuntime() |
| 48 | { |
| 49 | } |
Jim Ingham | 3df164e | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 50 | |
| 51 | BreakpointSP |
| 52 | LanguageRuntime::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 | |
| 68 | LanguageRuntime::ExceptionBreakpointResolver::ExceptionBreakpointResolver (Breakpoint *bkpt, |
| 69 | LanguageType language, |
| 70 | bool catch_bp, |
| 71 | bool throw_bp) : |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 72 | BreakpointResolver (bkpt, BreakpointResolver::ExceptionResolver), |
Jim Ingham | 3df164e | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 73 | m_language (language), |
| 74 | m_catch_bp (catch_bp), |
| 75 | m_throw_bp (throw_bp) |
| 76 | |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | LanguageRuntime::ExceptionBreakpointResolver::GetDescription (Stream *s) |
| 82 | { |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 83 | s->Printf ("Exception breakpoint (catch: %s throw: %s)", |
Jim Ingham | 3df164e | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 84 | 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 Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 94 | s->Printf (" the correct runtime exception handler will be determined when you run"); |
Jim Ingham | 3df164e | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | bool |
| 98 | LanguageRuntime::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 Ingham | 9880efa | 2012-08-11 00:35:26 +0000 | [diff] [blame^] | 131 | return (bool) m_actual_resolver_sp; |
Jim Ingham | 3df164e | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 132 | } |
| 133 | else |
| 134 | return false; |
| 135 | } |
| 136 | } |
| 137 | else |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | Searcher::CallbackReturn |
| 142 | LanguageRuntime::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 | |
| 156 | Searcher::Depth |
| 157 | LanguageRuntime::ExceptionBreakpointResolver::GetDepth () |
| 158 | { |
| 159 | if (!SetActualResolver()) |
| 160 | return eDepthTarget; |
| 161 | else |
| 162 | return m_actual_resolver_sp->GetDepth(); |
| 163 | } |
| 164 | |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 165 | static 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 | }; |
| 189 | static uint32_t num_languages = sizeof(language_names) / sizeof (char *); |
| 190 | |
| 191 | LanguageType |
| 192 | LanguageRuntime::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 | |
| 202 | const char * |
| 203 | LanguageRuntime::GetNameForLanguageType (LanguageType language) |
| 204 | { |
| 205 | if (language < num_languages) |
| 206 | return language_names[language]; |
| 207 | else |
| 208 | return language_names[eLanguageTypeUnknown]; |
| 209 | } |
| 210 | |