1 //===-- ItaniumABILanguageRuntime.cpp --------------------------------------*-
2 //C++ -*-===//
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #include "ItaniumABILanguageRuntime.h"
12
13 #include "lldb/Breakpoint/BreakpointLocation.h"
14 #include "lldb/Core/Mangled.h"
15 #include "lldb/Core/Module.h"
16 #include "lldb/Core/PluginManager.h"
17 #include "lldb/Core/ValueObject.h"
18 #include "lldb/Core/ValueObjectMemory.h"
19 #include "lldb/DataFormatters/FormattersHelpers.h"
20 #include "lldb/Expression/DiagnosticManager.h"
21 #include "lldb/Expression/FunctionCaller.h"
22 #include "lldb/Interpreter/CommandObject.h"
23 #include "lldb/Interpreter/CommandObjectMultiword.h"
24 #include "lldb/Interpreter/CommandReturnObject.h"
25 #include "lldb/Symbol/ClangASTContext.h"
26 #include "lldb/Symbol/Symbol.h"
27 #include "lldb/Symbol/SymbolFile.h"
28 #include "lldb/Symbol/TypeList.h"
29 #include "lldb/Target/Process.h"
30 #include "lldb/Target/RegisterContext.h"
31 #include "lldb/Target/SectionLoadList.h"
32 #include "lldb/Target/StopInfo.h"
33 #include "lldb/Target/Target.h"
34 #include "lldb/Target/Thread.h"
35 #include "lldb/Utility/ConstString.h"
36 #include "lldb/Utility/Log.h"
37 #include "lldb/Utility/Scalar.h"
38 #include "lldb/Utility/Status.h"
39
40 #include <vector>
41
42 using namespace lldb;
43 using namespace lldb_private;
44
45 static const char *vtable_demangled_prefix = "vtable for ";
46
CouldHaveDynamicValue(ValueObject & in_value)47 bool ItaniumABILanguageRuntime::CouldHaveDynamicValue(ValueObject &in_value) {
48 const bool check_cxx = true;
49 const bool check_objc = false;
50 return in_value.GetCompilerType().IsPossibleDynamicType(NULL, check_cxx,
51 check_objc);
52 }
53
GetTypeInfoFromVTableAddress(ValueObject & in_value,lldb::addr_t original_ptr,lldb::addr_t vtable_load_addr)54 TypeAndOrName ItaniumABILanguageRuntime::GetTypeInfoFromVTableAddress(
55 ValueObject &in_value, lldb::addr_t original_ptr,
56 lldb::addr_t vtable_load_addr) {
57 if (m_process && vtable_load_addr != LLDB_INVALID_ADDRESS) {
58 // Find the symbol that contains the "vtable_load_addr" address
59 Address vtable_addr;
60 Target &target = m_process->GetTarget();
61 if (!target.GetSectionLoadList().IsEmpty()) {
62 if (target.GetSectionLoadList().ResolveLoadAddress(vtable_load_addr,
63 vtable_addr)) {
64 // See if we have cached info for this type already
65 TypeAndOrName type_info = GetDynamicTypeInfo(vtable_addr);
66 if (type_info)
67 return type_info;
68
69 SymbolContext sc;
70 target.GetImages().ResolveSymbolContextForAddress(
71 vtable_addr, eSymbolContextSymbol, sc);
72 Symbol *symbol = sc.symbol;
73 if (symbol != NULL) {
74 const char *name =
75 symbol->GetMangled()
76 .GetDemangledName(lldb::eLanguageTypeC_plus_plus)
77 .AsCString();
78 if (name && strstr(name, vtable_demangled_prefix) == name) {
79 Log *log(
80 lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
81 if (log)
82 log->Printf("0x%16.16" PRIx64
83 ": static-type = '%s' has vtable symbol '%s'\n",
84 original_ptr, in_value.GetTypeName().GetCString(),
85 name);
86 // We are a C++ class, that's good. Get the class name and look it
87 // up:
88 const char *class_name = name + strlen(vtable_demangled_prefix);
89 // We know the class name is absolute, so tell FindTypes that by
90 // prefixing it with the root namespace:
91 std::string lookup_name("::");
92 lookup_name.append(class_name);
93
94 type_info.SetName(class_name);
95 const bool exact_match = true;
96 TypeList class_types;
97
98 uint32_t num_matches = 0;
99 // First look in the module that the vtable symbol came from and
100 // look for a single exact match.
101 llvm::DenseSet<SymbolFile *> searched_symbol_files;
102 if (sc.module_sp) {
103 num_matches = sc.module_sp->FindTypes(
104 ConstString(lookup_name), exact_match, 1,
105 searched_symbol_files, class_types);
106 }
107
108 // If we didn't find a symbol, then move on to the entire module
109 // list in the target and get as many unique matches as possible
110 if (num_matches == 0) {
111 num_matches = target.GetImages().FindTypes(
112 nullptr, ConstString(lookup_name), exact_match, UINT32_MAX,
113 searched_symbol_files, class_types);
114 }
115
116 lldb::TypeSP type_sp;
117 if (num_matches == 0) {
118 if (log)
119 log->Printf("0x%16.16" PRIx64 ": is not dynamic\n",
120 original_ptr);
121 return TypeAndOrName();
122 }
123 if (num_matches == 1) {
124 type_sp = class_types.GetTypeAtIndex(0);
125 if (type_sp) {
126 if (ClangASTContext::IsCXXClassType(
127 type_sp->GetForwardCompilerType())) {
128 if (log)
129 log->Printf(
130 "0x%16.16" PRIx64
131 ": static-type = '%s' has dynamic type: uid={0x%" PRIx64
132 "}, type-name='%s'\n",
133 original_ptr, in_value.GetTypeName().AsCString(),
134 type_sp->GetID(), type_sp->GetName().GetCString());
135 type_info.SetTypeSP(type_sp);
136 }
137 }
138 } else if (num_matches > 1) {
139 size_t i;
140 if (log) {
141 for (i = 0; i < num_matches; i++) {
142 type_sp = class_types.GetTypeAtIndex(i);
143 if (type_sp) {
144 if (log)
145 log->Printf(
146 "0x%16.16" PRIx64
147 ": static-type = '%s' has multiple matching dynamic "
148 "types: uid={0x%" PRIx64 "}, type-name='%s'\n",
149 original_ptr, in_value.GetTypeName().AsCString(),
150 type_sp->GetID(), type_sp->GetName().GetCString());
151 }
152 }
153 }
154
155 for (i = 0; i < num_matches; i++) {
156 type_sp = class_types.GetTypeAtIndex(i);
157 if (type_sp) {
158 if (ClangASTContext::IsCXXClassType(
159 type_sp->GetForwardCompilerType())) {
160 if (log)
161 log->Printf(
162 "0x%16.16" PRIx64 ": static-type = '%s' has multiple "
163 "matching dynamic types, picking "
164 "this one: uid={0x%" PRIx64
165 "}, type-name='%s'\n",
166 original_ptr, in_value.GetTypeName().AsCString(),
167 type_sp->GetID(), type_sp->GetName().GetCString());
168 type_info.SetTypeSP(type_sp);
169 }
170 }
171 }
172
173 if (log && i == num_matches) {
174 log->Printf(
175 "0x%16.16" PRIx64
176 ": static-type = '%s' has multiple matching dynamic "
177 "types, didn't find a C++ match\n",
178 original_ptr, in_value.GetTypeName().AsCString());
179 }
180 }
181 if (type_info)
182 SetDynamicTypeInfo(vtable_addr, type_info);
183 return type_info;
184 }
185 }
186 }
187 }
188 }
189 return TypeAndOrName();
190 }
191
GetDynamicTypeAndAddress(ValueObject & in_value,lldb::DynamicValueType use_dynamic,TypeAndOrName & class_type_or_name,Address & dynamic_address,Value::ValueType & value_type)192 bool ItaniumABILanguageRuntime::GetDynamicTypeAndAddress(
193 ValueObject &in_value, lldb::DynamicValueType use_dynamic,
194 TypeAndOrName &class_type_or_name, Address &dynamic_address,
195 Value::ValueType &value_type) {
196 // For Itanium, if the type has a vtable pointer in the object, it will be at
197 // offset 0 in the object. That will point to the "address point" within the
198 // vtable (not the beginning of the vtable.) We can then look up the symbol
199 // containing this "address point" and that symbol's name demangled will
200 // contain the full class name. The second pointer above the "address point"
201 // is the "offset_to_top". We'll use that to get the start of the value
202 // object which holds the dynamic type.
203 //
204
205 class_type_or_name.Clear();
206 value_type = Value::ValueType::eValueTypeScalar;
207
208 // Only a pointer or reference type can have a different dynamic and static
209 // type:
210 if (!CouldHaveDynamicValue(in_value))
211 return false;
212
213 // First job, pull out the address at 0 offset from the object.
214 AddressType address_type;
215 lldb::addr_t original_ptr = in_value.GetPointerValue(&address_type);
216 if (original_ptr == LLDB_INVALID_ADDRESS)
217 return false;
218
219 ExecutionContext exe_ctx(in_value.GetExecutionContextRef());
220
221 Process *process = exe_ctx.GetProcessPtr();
222
223 if (process == nullptr)
224 return false;
225
226 Status error;
227 const lldb::addr_t vtable_address_point =
228 process->ReadPointerFromMemory(original_ptr, error);
229
230 if (!error.Success() || vtable_address_point == LLDB_INVALID_ADDRESS)
231 return false;
232
233 class_type_or_name = GetTypeInfoFromVTableAddress(in_value, original_ptr,
234 vtable_address_point);
235
236 if (!class_type_or_name)
237 return false;
238
239 TypeSP type_sp = class_type_or_name.GetTypeSP();
240 // There can only be one type with a given name, so we've just found
241 // duplicate definitions, and this one will do as well as any other. We
242 // don't consider something to have a dynamic type if it is the same as
243 // the static type. So compare against the value we were handed.
244 if (!type_sp)
245 return true;
246
247 if (ClangASTContext::AreTypesSame(in_value.GetCompilerType(),
248 type_sp->GetForwardCompilerType())) {
249 // The dynamic type we found was the same type, so we don't have a
250 // dynamic type here...
251 return false;
252 }
253
254 // The offset_to_top is two pointers above the vtable pointer.
255 const uint32_t addr_byte_size = process->GetAddressByteSize();
256 const lldb::addr_t offset_to_top_location =
257 vtable_address_point - 2 * addr_byte_size;
258 // Watch for underflow, offset_to_top_location should be less than
259 // vtable_address_point
260 if (offset_to_top_location >= vtable_address_point)
261 return false;
262 const int64_t offset_to_top = process->ReadSignedIntegerFromMemory(
263 offset_to_top_location, addr_byte_size, INT64_MIN, error);
264
265 if (offset_to_top == INT64_MIN)
266 return false;
267 // So the dynamic type is a value that starts at offset_to_top above
268 // the original address.
269 lldb::addr_t dynamic_addr = original_ptr + offset_to_top;
270 if (!process->GetTarget().GetSectionLoadList().ResolveLoadAddress(
271 dynamic_addr, dynamic_address)) {
272 dynamic_address.SetRawAddress(dynamic_addr);
273 }
274 return true;
275 }
276
FixUpDynamicType(const TypeAndOrName & type_and_or_name,ValueObject & static_value)277 TypeAndOrName ItaniumABILanguageRuntime::FixUpDynamicType(
278 const TypeAndOrName &type_and_or_name, ValueObject &static_value) {
279 CompilerType static_type(static_value.GetCompilerType());
280 Flags static_type_flags(static_type.GetTypeInfo());
281
282 TypeAndOrName ret(type_and_or_name);
283 if (type_and_or_name.HasType()) {
284 // The type will always be the type of the dynamic object. If our parent's
285 // type was a pointer, then our type should be a pointer to the type of the
286 // dynamic object. If a reference, then the original type should be
287 // okay...
288 CompilerType orig_type = type_and_or_name.GetCompilerType();
289 CompilerType corrected_type = orig_type;
290 if (static_type_flags.AllSet(eTypeIsPointer))
291 corrected_type = orig_type.GetPointerType();
292 else if (static_type_flags.AllSet(eTypeIsReference))
293 corrected_type = orig_type.GetLValueReferenceType();
294 ret.SetCompilerType(corrected_type);
295 } else {
296 // If we are here we need to adjust our dynamic type name to include the
297 // correct & or * symbol
298 std::string corrected_name(type_and_or_name.GetName().GetCString());
299 if (static_type_flags.AllSet(eTypeIsPointer))
300 corrected_name.append(" *");
301 else if (static_type_flags.AllSet(eTypeIsReference))
302 corrected_name.append(" &");
303 // the parent type should be a correctly pointer'ed or referenc'ed type
304 ret.SetCompilerType(static_type);
305 ret.SetName(corrected_name.c_str());
306 }
307 return ret;
308 }
309
IsVTableName(const char * name)310 bool ItaniumABILanguageRuntime::IsVTableName(const char *name) {
311 if (name == NULL)
312 return false;
313
314 // Can we maybe ask Clang about this?
315 return strstr(name, "_vptr$") == name;
316 }
317
318 //------------------------------------------------------------------
319 // Static Functions
320 //------------------------------------------------------------------
321 LanguageRuntime *
CreateInstance(Process * process,lldb::LanguageType language)322 ItaniumABILanguageRuntime::CreateInstance(Process *process,
323 lldb::LanguageType language) {
324 // FIXME: We have to check the process and make sure we actually know that
325 // this process supports
326 // the Itanium ABI.
327 if (language == eLanguageTypeC_plus_plus ||
328 language == eLanguageTypeC_plus_plus_03 ||
329 language == eLanguageTypeC_plus_plus_11 ||
330 language == eLanguageTypeC_plus_plus_14)
331 return new ItaniumABILanguageRuntime(process);
332 else
333 return NULL;
334 }
335
336 class CommandObjectMultiwordItaniumABI_Demangle : public CommandObjectParsed {
337 public:
CommandObjectMultiwordItaniumABI_Demangle(CommandInterpreter & interpreter)338 CommandObjectMultiwordItaniumABI_Demangle(CommandInterpreter &interpreter)
339 : CommandObjectParsed(interpreter, "demangle",
340 "Demangle a C++ mangled name.",
341 "language cplusplus demangle") {
342 CommandArgumentEntry arg;
343 CommandArgumentData index_arg;
344
345 // Define the first (and only) variant of this arg.
346 index_arg.arg_type = eArgTypeSymbol;
347 index_arg.arg_repetition = eArgRepeatPlus;
348
349 // There is only one variant this argument could be; put it into the
350 // argument entry.
351 arg.push_back(index_arg);
352
353 // Push the data for the first argument into the m_arguments vector.
354 m_arguments.push_back(arg);
355 }
356
357 ~CommandObjectMultiwordItaniumABI_Demangle() override = default;
358
359 protected:
DoExecute(Args & command,CommandReturnObject & result)360 bool DoExecute(Args &command, CommandReturnObject &result) override {
361 bool demangled_any = false;
362 bool error_any = false;
363 for (auto &entry : command.entries()) {
364 if (entry.ref.empty())
365 continue;
366
367 // the actual Mangled class should be strict about this, but on the
368 // command line if you're copying mangled names out of 'nm' on Darwin,
369 // they will come out with an extra underscore - be willing to strip this
370 // on behalf of the user. This is the moral equivalent of the -_/-n
371 // options to c++filt
372 auto name = entry.ref;
373 if (name.startswith("__Z"))
374 name = name.drop_front();
375
376 Mangled mangled(name, true);
377 if (mangled.GuessLanguage() == lldb::eLanguageTypeC_plus_plus) {
378 ConstString demangled(
379 mangled.GetDisplayDemangledName(lldb::eLanguageTypeC_plus_plus));
380 demangled_any = true;
381 result.AppendMessageWithFormat("%s ---> %s\n", entry.ref.str().c_str(),
382 demangled.GetCString());
383 } else {
384 error_any = true;
385 result.AppendErrorWithFormat("%s is not a valid C++ mangled name\n",
386 entry.ref.str().c_str());
387 }
388 }
389
390 result.SetStatus(
391 error_any ? lldb::eReturnStatusFailed
392 : (demangled_any ? lldb::eReturnStatusSuccessFinishResult
393 : lldb::eReturnStatusSuccessFinishNoResult));
394 return result.Succeeded();
395 }
396 };
397
398 class CommandObjectMultiwordItaniumABI : public CommandObjectMultiword {
399 public:
CommandObjectMultiwordItaniumABI(CommandInterpreter & interpreter)400 CommandObjectMultiwordItaniumABI(CommandInterpreter &interpreter)
401 : CommandObjectMultiword(
402 interpreter, "cplusplus",
403 "Commands for operating on the C++ language runtime.",
404 "cplusplus <subcommand> [<subcommand-options>]") {
405 LoadSubCommand(
406 "demangle",
407 CommandObjectSP(
408 new CommandObjectMultiwordItaniumABI_Demangle(interpreter)));
409 }
410
411 ~CommandObjectMultiwordItaniumABI() override = default;
412 };
413
Initialize()414 void ItaniumABILanguageRuntime::Initialize() {
415 PluginManager::RegisterPlugin(
416 GetPluginNameStatic(), "Itanium ABI for the C++ language", CreateInstance,
417 [](CommandInterpreter &interpreter) -> lldb::CommandObjectSP {
418 return CommandObjectSP(
419 new CommandObjectMultiwordItaniumABI(interpreter));
420 });
421 }
422
Terminate()423 void ItaniumABILanguageRuntime::Terminate() {
424 PluginManager::UnregisterPlugin(CreateInstance);
425 }
426
GetPluginNameStatic()427 lldb_private::ConstString ItaniumABILanguageRuntime::GetPluginNameStatic() {
428 static ConstString g_name("itanium");
429 return g_name;
430 }
431
432 //------------------------------------------------------------------
433 // PluginInterface protocol
434 //------------------------------------------------------------------
GetPluginName()435 lldb_private::ConstString ItaniumABILanguageRuntime::GetPluginName() {
436 return GetPluginNameStatic();
437 }
438
GetPluginVersion()439 uint32_t ItaniumABILanguageRuntime::GetPluginVersion() { return 1; }
440
CreateExceptionResolver(Breakpoint * bkpt,bool catch_bp,bool throw_bp)441 BreakpointResolverSP ItaniumABILanguageRuntime::CreateExceptionResolver(
442 Breakpoint *bkpt, bool catch_bp, bool throw_bp) {
443 return CreateExceptionResolver(bkpt, catch_bp, throw_bp, false);
444 }
445
CreateExceptionResolver(Breakpoint * bkpt,bool catch_bp,bool throw_bp,bool for_expressions)446 BreakpointResolverSP ItaniumABILanguageRuntime::CreateExceptionResolver(
447 Breakpoint *bkpt, bool catch_bp, bool throw_bp, bool for_expressions) {
448 // One complication here is that most users DON'T want to stop at
449 // __cxa_allocate_expression, but until we can do anything better with
450 // predicting unwinding the expression parser does. So we have two forms of
451 // the exception breakpoints, one for expressions that leaves out
452 // __cxa_allocate_exception, and one that includes it. The
453 // SetExceptionBreakpoints does the latter, the CreateExceptionBreakpoint in
454 // the runtime the former.
455 static const char *g_catch_name = "__cxa_begin_catch";
456 static const char *g_throw_name1 = "__cxa_throw";
457 static const char *g_throw_name2 = "__cxa_rethrow";
458 static const char *g_exception_throw_name = "__cxa_allocate_exception";
459 std::vector<const char *> exception_names;
460 exception_names.reserve(4);
461 if (catch_bp)
462 exception_names.push_back(g_catch_name);
463
464 if (throw_bp) {
465 exception_names.push_back(g_throw_name1);
466 exception_names.push_back(g_throw_name2);
467 }
468
469 if (for_expressions)
470 exception_names.push_back(g_exception_throw_name);
471
472 BreakpointResolverSP resolver_sp(new BreakpointResolverName(
473 bkpt, exception_names.data(), exception_names.size(),
474 eFunctionNameTypeBase, eLanguageTypeUnknown, 0, eLazyBoolNo));
475
476 return resolver_sp;
477 }
478
CreateExceptionSearchFilter()479 lldb::SearchFilterSP ItaniumABILanguageRuntime::CreateExceptionSearchFilter() {
480 Target &target = m_process->GetTarget();
481
482 if (target.GetArchitecture().GetTriple().getVendor() == llvm::Triple::Apple) {
483 // Limit the number of modules that are searched for these breakpoints for
484 // Apple binaries.
485 FileSpecList filter_modules;
486 filter_modules.Append(FileSpec("libc++abi.dylib"));
487 filter_modules.Append(FileSpec("libSystem.B.dylib"));
488 return target.GetSearchFilterForModuleList(&filter_modules);
489 } else {
490 return LanguageRuntime::CreateExceptionSearchFilter();
491 }
492 }
493
CreateExceptionBreakpoint(bool catch_bp,bool throw_bp,bool for_expressions,bool is_internal)494 lldb::BreakpointSP ItaniumABILanguageRuntime::CreateExceptionBreakpoint(
495 bool catch_bp, bool throw_bp, bool for_expressions, bool is_internal) {
496 Target &target = m_process->GetTarget();
497 FileSpecList filter_modules;
498 BreakpointResolverSP exception_resolver_sp =
499 CreateExceptionResolver(NULL, catch_bp, throw_bp, for_expressions);
500 SearchFilterSP filter_sp(CreateExceptionSearchFilter());
501 const bool hardware = false;
502 const bool resolve_indirect_functions = false;
503 return target.CreateBreakpoint(filter_sp, exception_resolver_sp, is_internal,
504 hardware, resolve_indirect_functions);
505 }
506
SetExceptionBreakpoints()507 void ItaniumABILanguageRuntime::SetExceptionBreakpoints() {
508 if (!m_process)
509 return;
510
511 const bool catch_bp = false;
512 const bool throw_bp = true;
513 const bool is_internal = true;
514 const bool for_expressions = true;
515
516 // For the exception breakpoints set by the Expression parser, we'll be a
517 // little more aggressive and stop at exception allocation as well.
518
519 if (m_cxx_exception_bp_sp) {
520 m_cxx_exception_bp_sp->SetEnabled(true);
521 } else {
522 m_cxx_exception_bp_sp = CreateExceptionBreakpoint(
523 catch_bp, throw_bp, for_expressions, is_internal);
524 if (m_cxx_exception_bp_sp)
525 m_cxx_exception_bp_sp->SetBreakpointKind("c++ exception");
526 }
527 }
528
ClearExceptionBreakpoints()529 void ItaniumABILanguageRuntime::ClearExceptionBreakpoints() {
530 if (!m_process)
531 return;
532
533 if (m_cxx_exception_bp_sp) {
534 m_cxx_exception_bp_sp->SetEnabled(false);
535 }
536 }
537
ExceptionBreakpointsAreSet()538 bool ItaniumABILanguageRuntime::ExceptionBreakpointsAreSet() {
539 return m_cxx_exception_bp_sp && m_cxx_exception_bp_sp->IsEnabled();
540 }
541
ExceptionBreakpointsExplainStop(lldb::StopInfoSP stop_reason)542 bool ItaniumABILanguageRuntime::ExceptionBreakpointsExplainStop(
543 lldb::StopInfoSP stop_reason) {
544 if (!m_process)
545 return false;
546
547 if (!stop_reason || stop_reason->GetStopReason() != eStopReasonBreakpoint)
548 return false;
549
550 uint64_t break_site_id = stop_reason->GetValue();
551 return m_process->GetBreakpointSiteList().BreakpointSiteContainsBreakpoint(
552 break_site_id, m_cxx_exception_bp_sp->GetID());
553 }
554
GetExceptionObjectForThread(ThreadSP thread_sp)555 ValueObjectSP ItaniumABILanguageRuntime::GetExceptionObjectForThread(
556 ThreadSP thread_sp) {
557 if (!thread_sp->SafeToCallFunctions())
558 return {};
559
560 ClangASTContext *clang_ast_context =
561 m_process->GetTarget().GetScratchClangASTContext();
562 CompilerType voidstar =
563 clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
564
565 DiagnosticManager diagnostics;
566 ExecutionContext exe_ctx;
567 EvaluateExpressionOptions options;
568
569 options.SetUnwindOnError(true);
570 options.SetIgnoreBreakpoints(true);
571 options.SetStopOthers(true);
572 options.SetTimeout(std::chrono::milliseconds(500));
573 options.SetTryAllThreads(false);
574 thread_sp->CalculateExecutionContext(exe_ctx);
575
576 const ModuleList &modules = m_process->GetTarget().GetImages();
577 SymbolContextList contexts;
578 SymbolContext context;
579
580 modules.FindSymbolsWithNameAndType(
581 ConstString("__cxa_current_exception_type"), eSymbolTypeCode, contexts);
582 contexts.GetContextAtIndex(0, context);
583 Address addr = context.symbol->GetAddress();
584
585 Status error;
586 FunctionCaller *function_caller =
587 m_process->GetTarget().GetFunctionCallerForLanguage(
588 eLanguageTypeC, voidstar, addr, ValueList(), "caller", error);
589
590 ExpressionResults func_call_ret;
591 Value results;
592 func_call_ret = function_caller->ExecuteFunction(exe_ctx, nullptr, options,
593 diagnostics, results);
594 if (func_call_ret != eExpressionCompleted || !error.Success()) {
595 return ValueObjectSP();
596 }
597
598 size_t ptr_size = m_process->GetAddressByteSize();
599 addr_t result_ptr = results.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
600 addr_t exception_addr =
601 m_process->ReadPointerFromMemory(result_ptr - ptr_size, error);
602
603 lldb_private::formatters::InferiorSizedWord exception_isw(exception_addr,
604 *m_process);
605 ValueObjectSP exception = ValueObject::CreateValueObjectFromData(
606 "exception", exception_isw.GetAsData(m_process->GetByteOrder()), exe_ctx,
607 voidstar);
608 exception = exception->GetDynamicValue(eDynamicDontRunTarget);
609
610 return exception;
611 }
612
GetDynamicTypeInfo(const lldb_private::Address & vtable_addr)613 TypeAndOrName ItaniumABILanguageRuntime::GetDynamicTypeInfo(
614 const lldb_private::Address &vtable_addr) {
615 std::lock_guard<std::mutex> locker(m_dynamic_type_map_mutex);
616 DynamicTypeCache::const_iterator pos = m_dynamic_type_map.find(vtable_addr);
617 if (pos == m_dynamic_type_map.end())
618 return TypeAndOrName();
619 else
620 return pos->second;
621 }
622
SetDynamicTypeInfo(const lldb_private::Address & vtable_addr,const TypeAndOrName & type_info)623 void ItaniumABILanguageRuntime::SetDynamicTypeInfo(
624 const lldb_private::Address &vtable_addr, const TypeAndOrName &type_info) {
625 std::lock_guard<std::mutex> locker(m_dynamic_type_map_mutex);
626 m_dynamic_type_map[vtable_addr] = type_info;
627 }
628