Coverage Report

Created: 2022-01-15 10:30

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