LLDB mainline
CommonABIRuntime.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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 "CommonABIRuntime.h"
10
12#include "lldb/Core/Module.h"
14
15using namespace lldb;
16using namespace lldb_private;
17
19
21 lldb::ModuleSP preferred_module,
22 bool &any_found) const {
24
25 any_found = false;
26
27 ConstString const_lookup_name(type_name);
28 TypeList class_types;
29 // First look in the module that the vtable symbol came from and
30 // look for a single exact match.
31 TypeResults results;
32 TypeQuery query(const_lookup_name.GetStringRef(),
33 TypeQueryOptions::e_exact_match |
34 TypeQueryOptions::e_strict_namespaces |
35 TypeQueryOptions::e_find_one);
36 if (preferred_module) {
37 preferred_module->FindTypes(query, results);
38 TypeSP type_sp = results.GetFirstType();
39 if (type_sp)
40 class_types.Insert(type_sp);
41 }
42
43 // If we didn't find a symbol, then move on to the entire module
44 // list in the target and get as many unique matches as possible
45 if (class_types.Empty()) {
46 query.SetFindOne(false);
47 m_process->GetTarget().GetImages().FindTypes(nullptr, query, results);
48 for (const auto &type_sp : results.GetTypeMap().Types())
49 class_types.Insert(type_sp);
50 }
51
52 lldb::TypeSP type_sp;
53 if (class_types.Empty()) {
54 LLDB_LOG(log, "Failed to find '{0}'", type_name);
55 return {};
56 }
57 any_found = true;
58
59 if (class_types.GetSize() == 1) {
60 type_sp = class_types.GetTypeAtIndex(0);
61 if (!type_sp)
62 return {};
63 if (!TypeSystemClang::IsCXXClassType(type_sp->GetForwardCompilerType()))
64 return {};
65
66 return type_sp;
67 }
68
69 if (log) {
70 LLDB_LOG(log,
71 "'{0}' has multiple matching dynamic "
72 "types:",
73 type_name);
74 for (size_t i = 0; i < class_types.GetSize(); i++) {
75 type_sp = class_types.GetTypeAtIndex(i);
76 if (type_sp) {
77 LLDB_LOG(log, "[{0}]: uid={1:x}, type-name='{2}'", i, type_sp->GetID(),
78 type_sp->GetName());
79 }
80 }
81 }
82
83 for (size_t i = 0; i < class_types.GetSize(); i++) {
84 type_sp = class_types.GetTypeAtIndex(i);
85 if (type_sp) {
86 if (TypeSystemClang::IsCXXClassType(type_sp->GetForwardCompilerType())) {
87 LLDB_LOG(log,
88 "'{0}' has multiple matching dynamic types, "
89 "picking this one: [{1}] uid={2:x}, type-name='{3}'\n",
90 type_name, i, type_sp->GetID(), type_sp->GetName());
91 return type_sp;
92 }
93 }
94 }
95
96 LLDB_LOG(log,
97 "'{0}' has multiple matching dynamic types, didn't find a C++ match",
98 type_name);
99 return {};
100}
101
104 std::lock_guard<std::mutex> locker(m_mutex);
105 DynamicTypeCache::const_iterator pos = m_dynamic_type_map.find(vtable_addr);
106 if (pos == m_dynamic_type_map.end())
107 return TypeAndOrName();
108
109 return pos->second;
110}
111
113 const lldb_private::Address &vtable_addr, const TypeAndOrName &type_info) {
114 std::lock_guard<std::mutex> locker(m_mutex);
115 m_dynamic_type_map[vtable_addr] = type_info;
116}
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
A section + offset based address class.
Definition Address.h:62
void SetDynamicTypeInfo(const lldb_private::Address &vtable_addr, const TypeAndOrName &type_info)
lldb::TypeSP LookupTypeByName(llvm::StringRef type_name, lldb::ModuleSP preferred_module, bool &any_found) const
Find a type by its name, preferably in preferred_module.
TypeAndOrName GetDynamicTypeInfo(const lldb_private::Address &vtable_addr)
A uniqued constant string class.
Definition ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
A plug-in interface definition class for debugging a process.
Definition Process.h:359
Sometimes you can find the name of the type corresponding to an object, but we don't have debug infor...
Definition Type.h:780
uint32_t GetSize() const
Definition TypeList.cpp:36
bool Empty() const
Definition TypeList.h:35
void Insert(const lldb::TypeSP &type)
Definition TypeList.cpp:27
lldb::TypeSP GetTypeAtIndex(uint32_t idx) const
Definition TypeList.cpp:42
TypeIterable Types() const
Definition TypeMap.h:48
A class that contains all state required for type lookups.
Definition Type.h:104
void SetFindOne(bool b)
Definition Type.h:299
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
TypeMap & GetTypeMap()
Definition Type.h:386
lldb::TypeSP GetFirstType() const
Definition Type.h:385
static bool IsCXXClassType(const CompilerType &type)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
std::shared_ptr< lldb_private::Type > TypeSP
std::shared_ptr< lldb_private::Module > ModuleSP