| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1 | //===-- ItaniumABILanguageRuntime.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 "ItaniumABILanguageRuntime.h" |
| 11 | |
| Sean Callanan | f211510 | 2010-11-03 22:19:38 +0000 | [diff] [blame] | 12 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 13 | #include "lldb/Core/ConstString.h" |
| 14 | #include "lldb/Core/Error.h" |
| Greg Clayton | 726bc52 | 2012-03-28 17:13:26 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Log.h" |
| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Module.h" |
| 17 | #include "lldb/Core/PluginManager.h" |
| 18 | #include "lldb/Core/Scalar.h" |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 19 | #include "lldb/Core/ValueObject.h" |
| 20 | #include "lldb/Core/ValueObjectMemory.h" |
| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/ClangASTContext.h" |
| 22 | #include "lldb/Target/Process.h" |
| 23 | #include "lldb/Target/RegisterContext.h" |
| Sean Callanan | f211510 | 2010-11-03 22:19:38 +0000 | [diff] [blame] | 24 | #include "lldb/Target/StopInfo.h" |
| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Target.h" |
| 26 | #include "lldb/Target/Thread.h" |
| 27 | |
| 28 | #include <vector> |
| 29 | |
| 30 | using namespace lldb; |
| 31 | using namespace lldb_private; |
| 32 | |
| 33 | static const char *pluginName = "ItaniumABILanguageRuntime"; |
| 34 | static const char *pluginDesc = "Itanium ABI for the C++ language"; |
| 35 | static const char *pluginShort = "language.itanium"; |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 36 | static const char *vtable_demangled_prefix = "vtable for "; |
| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 37 | |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 38 | bool |
| 39 | ItaniumABILanguageRuntime::CouldHaveDynamicValue (ValueObject &in_value) |
| Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 40 | { |
| Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 41 | return in_value.IsPossibleCPlusPlusDynamicType(); |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | bool |
| Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 45 | ItaniumABILanguageRuntime::GetDynamicTypeAndAddress (ValueObject &in_value, |
| 46 | lldb::DynamicValueType use_dynamic, |
| 47 | TypeAndOrName &class_type_or_name, |
| 48 | Address &dynamic_address) |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 49 | { |
| 50 | // For Itanium, if the type has a vtable pointer in the object, it will be at offset 0 |
| 51 | // in the object. That will point to the "address point" within the vtable (not the beginning of the |
| 52 | // vtable.) We can then look up the symbol containing this "address point" and that symbol's name |
| 53 | // demangled will contain the full class name. |
| 54 | // The second pointer above the "address point" is the "offset_to_top". We'll use that to get the |
| 55 | // start of the value object which holds the dynamic type. |
| 56 | // |
| 57 | |
| 58 | // Only a pointer or reference type can have a different dynamic and static type: |
| 59 | if (CouldHaveDynamicValue (in_value)) |
| 60 | { |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 61 | // First job, pull out the address at 0 offset from the object. |
| 62 | AddressType address_type; |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 63 | lldb::addr_t original_ptr = in_value.GetPointerValue(&address_type); |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 64 | if (original_ptr == LLDB_INVALID_ADDRESS) |
| 65 | return false; |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 66 | |
| 67 | ExecutionContext exe_ctx (in_value.GetExecutionContextRef()); |
| 68 | |
| 69 | Target *target = exe_ctx.GetTargetPtr(); |
| 70 | Process *process = exe_ctx.GetProcessPtr(); |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 71 | |
| 72 | char memory_buffer[16]; |
| 73 | DataExtractor data(memory_buffer, sizeof(memory_buffer), |
| 74 | process->GetByteOrder(), |
| 75 | process->GetAddressByteSize()); |
| 76 | size_t address_byte_size = process->GetAddressByteSize(); |
| 77 | Error error; |
| 78 | size_t bytes_read = process->ReadMemory (original_ptr, |
| 79 | memory_buffer, |
| 80 | address_byte_size, |
| 81 | error); |
| 82 | if (!error.Success() || (bytes_read != address_byte_size)) |
| 83 | { |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | uint32_t offset_ptr = 0; |
| 88 | lldb::addr_t vtable_address_point = data.GetAddress (&offset_ptr); |
| 89 | |
| 90 | if (offset_ptr == 0) |
| 91 | return false; |
| 92 | |
| 93 | // Now find the symbol that contains this address: |
| 94 | |
| 95 | SymbolContext sc; |
| 96 | Address address_point_address; |
| 97 | if (target && !target->GetSectionLoadList().IsEmpty()) |
| 98 | { |
| 99 | if (target->GetSectionLoadList().ResolveLoadAddress (vtable_address_point, address_point_address)) |
| 100 | { |
| 101 | target->GetImages().ResolveSymbolContextForAddress (address_point_address, eSymbolContextSymbol, sc); |
| 102 | Symbol *symbol = sc.symbol; |
| 103 | if (symbol != NULL) |
| 104 | { |
| 105 | const char *name = symbol->GetMangled().GetDemangledName().AsCString(); |
| 106 | if (strstr(name, vtable_demangled_prefix) == name) |
| 107 | { |
| Greg Clayton | 726bc52 | 2012-03-28 17:13:26 +0000 | [diff] [blame] | 108 | LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
| 109 | if (log) |
| 110 | log->Printf ("0x%16.16llx: static-type = '%s' has vtable symbol '%s'\n", |
| 111 | original_ptr, |
| 112 | in_value.GetTypeName().GetCString(), |
| 113 | name); |
| 114 | // We are a C++ class, that's good. Get the class name and look it up: |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 115 | const char *class_name = name + strlen(vtable_demangled_prefix); |
| Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 116 | class_type_or_name.SetName (class_name); |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 117 | const bool exact_match = true; |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 118 | TypeList class_types; |
| Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame^] | 119 | |
| 120 | uint32_t num_matches = target->GetImages().FindTypes (sc, |
| 121 | ConstString(class_name), |
| 122 | exact_match, |
| 123 | UINT32_MAX, |
| 124 | class_types); |
| 125 | |
| 126 | lldb::TypeSP type_sp; |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 127 | if (num_matches == 0) |
| 128 | { |
| Greg Clayton | 726bc52 | 2012-03-28 17:13:26 +0000 | [diff] [blame] | 129 | if (log) |
| 130 | log->Printf("0x%16.16llx: is not dynamic\n", original_ptr); |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 131 | return false; |
| 132 | } |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 133 | if (num_matches == 1) |
| 134 | { |
| Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame^] | 135 | type_sp = class_types.GetTypeAtIndex(0); |
| Greg Clayton | 726bc52 | 2012-03-28 17:13:26 +0000 | [diff] [blame] | 136 | if (log) |
| 137 | log->Printf ("0x%16.16llx: static-type = '%s' has dynamic type: uid={0x%llx}, type-name='%s'\n", |
| 138 | original_ptr, |
| 139 | in_value.GetTypeName().AsCString(), |
| 140 | type_sp->GetID(), |
| 141 | type_sp->GetName().GetCString()); |
| 142 | |
| Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 143 | class_type_or_name.SetTypeSP(class_types.GetTypeAtIndex(0)); |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 144 | } |
| 145 | else if (num_matches > 1) |
| 146 | { |
| Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame^] | 147 | size_t i; |
| 148 | if (log) |
| Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 149 | { |
| Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame^] | 150 | for (i = 0; i < num_matches; i++) |
| Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 151 | { |
| Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame^] | 152 | type_sp = class_types.GetTypeAtIndex(i); |
| 153 | if (type_sp) |
| 154 | { |
| 155 | if (log) |
| 156 | log->Printf ("0x%16.16llx: static-type = '%s' has multiple matching dynamic types: uid={0x%llx}, type-name='%s'\n", |
| 157 | original_ptr, |
| 158 | in_value.GetTypeName().AsCString(), |
| 159 | type_sp->GetID(), |
| 160 | type_sp->GetName().GetCString()); |
| 161 | } |
| Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 162 | } |
| 163 | } |
| Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame^] | 164 | |
| 165 | for (i = 0; i < num_matches; i++) |
| 166 | { |
| 167 | type_sp = class_types.GetTypeAtIndex(i); |
| 168 | if (type_sp) |
| 169 | { |
| 170 | if (ClangASTContext::IsCXXClassType(type_sp->GetClangFullType())) |
| 171 | { |
| 172 | if (log) |
| 173 | log->Printf ("0x%16.16llx: static-type = '%s' has multiple matching dynamic types, picking this one: uid={0x%llx}, type-name='%s'\n", |
| 174 | original_ptr, |
| 175 | in_value.GetTypeName().AsCString(), |
| 176 | type_sp->GetID(), |
| 177 | type_sp->GetName().GetCString()); |
| 178 | class_type_or_name.SetTypeSP(type_sp); |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | } |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 183 | |
| Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame^] | 184 | if (i == num_matches) |
| 185 | { |
| 186 | if (log) |
| 187 | log->Printf ("0x%16.16llx: static-type = '%s' has multiple matching dynamic types, didn't find a C++ match\n", |
| 188 | original_ptr, |
| 189 | in_value.GetTypeName().AsCString()); |
| 190 | return false; |
| 191 | } |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 192 | } |
| Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame^] | 193 | |
| 194 | // There can only be one type with a given name, |
| 195 | // so we've just found duplicate definitions, and this |
| 196 | // one will do as well as any other. |
| 197 | // We don't consider something to have a dynamic type if |
| 198 | // it is the same as the static type. So compare against |
| 199 | // the value we were handed. |
| 200 | if (type_sp) |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 201 | { |
| Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame^] | 202 | clang::ASTContext *in_ast_ctx = in_value.GetClangAST (); |
| 203 | clang::ASTContext *this_ast_ctx = type_sp->GetClangAST (); |
| 204 | if (in_ast_ctx == this_ast_ctx) |
| 205 | { |
| 206 | if (ClangASTContext::AreTypesSame (in_ast_ctx, |
| 207 | in_value.GetClangType(), |
| 208 | type_sp->GetClangFullType())) |
| 209 | { |
| 210 | // The dynamic type we found was the same type, |
| 211 | // so we don't have a dynamic type here... |
| 212 | return false; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // The offset_to_top is two pointers above the address. |
| 217 | Address offset_to_top_address = address_point_address; |
| 218 | int64_t slide = -2 * ((int64_t) target->GetArchitecture().GetAddressByteSize()); |
| 219 | offset_to_top_address.Slide (slide); |
| 220 | |
| 221 | Error error; |
| 222 | lldb::addr_t offset_to_top_location = offset_to_top_address.GetLoadAddress(target); |
| 223 | |
| 224 | size_t bytes_read = process->ReadMemory (offset_to_top_location, |
| 225 | memory_buffer, |
| 226 | address_byte_size, |
| 227 | error); |
| 228 | |
| 229 | if (!error.Success() || (bytes_read != address_byte_size)) |
| 230 | { |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | offset_ptr = 0; |
| 235 | int64_t offset_to_top = data.GetMaxS64(&offset_ptr, process->GetAddressByteSize()); |
| 236 | |
| 237 | // So the dynamic type is a value that starts at offset_to_top |
| 238 | // above the original address. |
| 239 | lldb::addr_t dynamic_addr = original_ptr + offset_to_top; |
| 240 | if (!target->GetSectionLoadList().ResolveLoadAddress (dynamic_addr, dynamic_address)) |
| 241 | { |
| 242 | dynamic_address.SetRawAddress(dynamic_addr); |
| 243 | } |
| 244 | return true; |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 245 | } |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | return false; |
| Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | bool |
| 256 | ItaniumABILanguageRuntime::IsVTableName (const char *name) |
| 257 | { |
| 258 | if (name == NULL) |
| 259 | return false; |
| 260 | |
| 261 | // Can we maybe ask Clang about this? |
| 262 | if (strstr (name, "_vptr$") == name) |
| 263 | return true; |
| 264 | else |
| 265 | return false; |
| 266 | } |
| 267 | |
| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 268 | //------------------------------------------------------------------ |
| 269 | // Static Functions |
| 270 | //------------------------------------------------------------------ |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 271 | LanguageRuntime * |
| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 272 | ItaniumABILanguageRuntime::CreateInstance (Process *process, lldb::LanguageType language) |
| 273 | { |
| 274 | // FIXME: We have to check the process and make sure we actually know that this process supports |
| 275 | // the Itanium ABI. |
| 276 | if (language == eLanguageTypeC_plus_plus) |
| 277 | return new ItaniumABILanguageRuntime (process); |
| 278 | else |
| 279 | return NULL; |
| 280 | } |
| 281 | |
| 282 | void |
| 283 | ItaniumABILanguageRuntime::Initialize() |
| 284 | { |
| 285 | PluginManager::RegisterPlugin (pluginName, |
| 286 | pluginDesc, |
| 287 | CreateInstance); |
| 288 | } |
| 289 | |
| 290 | void |
| 291 | ItaniumABILanguageRuntime::Terminate() |
| 292 | { |
| 293 | PluginManager::UnregisterPlugin (CreateInstance); |
| 294 | } |
| 295 | |
| 296 | //------------------------------------------------------------------ |
| 297 | // PluginInterface protocol |
| 298 | //------------------------------------------------------------------ |
| 299 | const char * |
| 300 | ItaniumABILanguageRuntime::GetPluginName() |
| 301 | { |
| 302 | return pluginName; |
| 303 | } |
| 304 | |
| 305 | const char * |
| 306 | ItaniumABILanguageRuntime::GetShortPluginName() |
| 307 | { |
| 308 | return pluginShort; |
| 309 | } |
| 310 | |
| 311 | uint32_t |
| 312 | ItaniumABILanguageRuntime::GetPluginVersion() |
| 313 | { |
| 314 | return 1; |
| 315 | } |
| 316 | |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 317 | static const char *exception_names[] = { "__cxa_begin_catch", "__cxa_throw", "__cxa_rethrow", "__cxa_allocate_exception"}; |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 318 | static const int num_throw_names = 3; |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 319 | static const int num_expression_throw_names = 1; |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 320 | |
| Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 321 | BreakpointResolverSP |
| 322 | ItaniumABILanguageRuntime::CreateExceptionResolver (Breakpoint *bkpt, bool catch_bp, bool throw_bp) |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 323 | { |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 324 | return CreateExceptionResolver (bkpt, catch_bp, throw_bp, false); |
| 325 | } |
| 326 | |
| 327 | BreakpointResolverSP |
| 328 | ItaniumABILanguageRuntime::CreateExceptionResolver (Breakpoint *bkpt, bool catch_bp, bool throw_bp, bool for_expressions) |
| 329 | { |
| Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 330 | BreakpointResolverSP resolver_sp; |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 331 | static const int total_expressions = sizeof (exception_names)/sizeof (char *); |
| Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 332 | |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 333 | // One complication here is that most users DON'T want to stop at __cxa_allocate_expression, but until we can do |
| 334 | // anything better with predicting unwinding the expression parser does. So we have two forms of the exception |
| 335 | // breakpoints, one for expressions that leaves out __cxa_allocate_exception, and one that includes it. |
| 336 | // The SetExceptionBreakpoints does the latter, the CreateExceptionBreakpoint in the runtime the former. |
| 337 | |
| 338 | uint32_t num_expressions; |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 339 | if (catch_bp && throw_bp) |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 340 | { |
| 341 | if (for_expressions) |
| 342 | num_expressions = total_expressions; |
| 343 | else |
| 344 | num_expressions = total_expressions - num_expression_throw_names; |
| 345 | |
| Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 346 | resolver_sp.reset (new BreakpointResolverName (bkpt, |
| 347 | exception_names, |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 348 | num_expressions, |
| Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 349 | eFunctionNameTypeBase, |
| 350 | eLazyBoolNo)); |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 351 | } |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 352 | else if (throw_bp) |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 353 | { |
| 354 | if (for_expressions) |
| 355 | num_expressions = num_throw_names - num_expression_throw_names; |
| 356 | else |
| 357 | num_expressions = num_throw_names; |
| 358 | |
| Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 359 | resolver_sp.reset (new BreakpointResolverName (bkpt, |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 360 | exception_names + 1, |
| 361 | num_expressions, |
| Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 362 | eFunctionNameTypeBase, |
| 363 | eLazyBoolNo)); |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 364 | } |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 365 | else if (catch_bp) |
| Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 366 | resolver_sp.reset (new BreakpointResolverName (bkpt, |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 367 | exception_names, |
| 368 | total_expressions - num_throw_names, |
| Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 369 | eFunctionNameTypeBase, |
| 370 | eLazyBoolNo)); |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 371 | |
| Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 372 | return resolver_sp; |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 375 | void |
| Sean Callanan | f211510 | 2010-11-03 22:19:38 +0000 | [diff] [blame] | 376 | ItaniumABILanguageRuntime::SetExceptionBreakpoints () |
| 377 | { |
| 378 | if (!m_process) |
| 379 | return; |
| 380 | |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 381 | const bool catch_bp = false; |
| 382 | const bool throw_bp = true; |
| 383 | const bool is_internal = true; |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 384 | const bool for_expressions = true; |
| 385 | |
| 386 | // For the exception breakpoints set by the Expression parser, we'll be a little more aggressive and |
| 387 | // stop at exception allocation as well. |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 388 | |
| Sean Callanan | f211510 | 2010-11-03 22:19:38 +0000 | [diff] [blame] | 389 | if (!m_cxx_exception_bp_sp) |
| Jim Ingham | f0fd55e | 2012-03-06 18:10:38 +0000 | [diff] [blame] | 390 | { |
| 391 | Target &target = m_process->GetTarget(); |
| 392 | |
| 393 | BreakpointResolverSP exception_resolver_sp = CreateExceptionResolver (NULL, catch_bp, throw_bp, for_expressions); |
| 394 | SearchFilterSP filter_sp = target.GetSearchFilterForModule(NULL); |
| 395 | |
| 396 | m_cxx_exception_bp_sp = target.CreateBreakpoint (filter_sp, exception_resolver_sp, is_internal); |
| 397 | } |
| Jim Ingham | e3846fd | 2011-07-23 00:12:05 +0000 | [diff] [blame] | 398 | else |
| 399 | m_cxx_exception_bp_sp->SetEnabled (true); |
| Sean Callanan | f211510 | 2010-11-03 22:19:38 +0000 | [diff] [blame] | 400 | |
| Sean Callanan | f211510 | 2010-11-03 22:19:38 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | void |
| 404 | ItaniumABILanguageRuntime::ClearExceptionBreakpoints () |
| 405 | { |
| 406 | if (!m_process) |
| 407 | return; |
| 408 | |
| 409 | if (m_cxx_exception_bp_sp.get()) |
| 410 | { |
| Jim Ingham | e3846fd | 2011-07-23 00:12:05 +0000 | [diff] [blame] | 411 | m_cxx_exception_bp_sp->SetEnabled (false); |
| Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 412 | } |
| Sean Callanan | f211510 | 2010-11-03 22:19:38 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | bool |
| 416 | ItaniumABILanguageRuntime::ExceptionBreakpointsExplainStop (lldb::StopInfoSP stop_reason) |
| 417 | { |
| 418 | if (!m_process) |
| 419 | return false; |
| 420 | |
| 421 | if (!stop_reason || |
| 422 | stop_reason->GetStopReason() != eStopReasonBreakpoint) |
| 423 | return false; |
| 424 | |
| 425 | uint64_t break_site_id = stop_reason->GetValue(); |
| Jim Ingham | 564d8bc2 | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 426 | return m_process->GetBreakpointSiteList().BreakpointSiteContainsBreakpoint(break_site_id, |
| 427 | m_cxx_exception_bp_sp->GetID()); |
| Sean Callanan | f211510 | 2010-11-03 22:19:38 +0000 | [diff] [blame] | 428 | |
| Sean Callanan | f211510 | 2010-11-03 22:19:38 +0000 | [diff] [blame] | 429 | } |