Skip to content

Commit a141766

Browse files
author
MUSTAPHA BARKI
authored
Merge branch 'main' into Uncontrolled-data-used-in-path-expression
2 parents 0e06b86 + 88c988e commit a141766

File tree

17 files changed

+251
-51
lines changed

17 files changed

+251
-51
lines changed

lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ struct CreateMethodDecl : public TypeVisitorCallbacks {
3838
TypeIndex func_type_index,
3939
clang::FunctionDecl *&function_decl,
4040
lldb::opaque_compiler_type_t parent_ty,
41-
llvm::StringRef proc_name, CompilerType func_ct)
41+
llvm::StringRef proc_name, ConstString mangled_name,
42+
CompilerType func_ct)
4243
: m_index(m_index), m_clang(m_clang), func_type_index(func_type_index),
4344
function_decl(function_decl), parent_ty(parent_ty),
44-
proc_name(proc_name), func_ct(func_ct) {}
45+
proc_name(proc_name), mangled_name(mangled_name), func_ct(func_ct) {}
4546
PdbIndex &m_index;
4647
TypeSystemClang &m_clang;
4748
TypeIndex func_type_index;
4849
clang::FunctionDecl *&function_decl;
4950
lldb::opaque_compiler_type_t parent_ty;
5051
llvm::StringRef proc_name;
52+
ConstString mangled_name;
5153
CompilerType func_ct;
5254

5355
llvm::Error visitKnownMember(CVMemberRecord &cvr,
@@ -87,8 +89,7 @@ struct CreateMethodDecl : public TypeVisitorCallbacks {
8789
bool is_artificial = (options & MethodOptions::CompilerGenerated) ==
8890
MethodOptions::CompilerGenerated;
8991
function_decl = m_clang.AddMethodToCXXRecordType(
90-
parent_ty, proc_name,
91-
/*asm_label=*/{}, func_ct, /*access=*/access_type,
92+
parent_ty, proc_name, mangled_name, func_ct, /*access=*/access_type,
9293
/*is_virtual=*/is_virtual, /*is_static=*/is_static,
9394
/*is_inline=*/false, /*is_explicit=*/false,
9495
/*is_attr_used=*/false, /*is_artificial=*/is_artificial);
@@ -892,22 +893,26 @@ PdbAstBuilder::CreateFunctionDecl(PdbCompilandSymId func_id,
892893
tag_record = CVTagRecord::create(index.tpi().getType(*eti)).asTag();
893894
}
894895
}
896+
897+
ConstString mangled_name(
898+
pdb->FindMangledFunctionName(func_id).value_or(llvm::StringRef()));
899+
895900
if (!tag_record.FieldList.isSimple()) {
896901
CVType field_list_cvt = index.tpi().getType(tag_record.FieldList);
897902
FieldListRecord field_list;
898903
if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
899904
field_list_cvt, field_list))
900905
llvm::consumeError(std::move(error));
901906
CreateMethodDecl process(index, m_clang, func_ti, function_decl,
902-
parent_opaque_ty, func_name, func_ct);
907+
parent_opaque_ty, func_name, mangled_name,
908+
func_ct);
903909
if (llvm::Error err = visitMemberRecordStream(field_list.Data, process))
904910
llvm::consumeError(std::move(err));
905911
}
906912

907913
if (!function_decl) {
908914
function_decl = m_clang.AddMethodToCXXRecordType(
909-
parent_opaque_ty, func_name,
910-
/*asm_label=*/{}, func_ct,
915+
parent_opaque_ty, func_name, mangled_name, func_ct,
911916
/*access=*/lldb::AccessType::eAccessPublic,
912917
/*is_virtual=*/false, /*is_static=*/false,
913918
/*is_inline=*/false, /*is_explicit=*/false,

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,9 @@ lldb::FunctionSP SymbolFileNativePDB::CreateFunction(PdbCompilandSymId func_id,
501501
return nullptr;
502502

503503
PdbTypeSymId sig_id(proc.FunctionType, false);
504-
Mangled mangled(proc.Name);
504+
std::optional<llvm::StringRef> mangled_opt =
505+
FindMangledSymbol(SegmentOffset(proc.Segment, proc.CodeOffset));
506+
Mangled mangled(mangled_opt.value_or(proc.Name));
505507
FunctionSP func_sp = std::make_shared<Function>(
506508
&comp_unit, toOpaqueUid(func_id), toOpaqueUid(sig_id), mangled,
507509
func_type.get(), func_addr,
@@ -2662,6 +2664,31 @@ SymbolFileNativePDB::GetContextForType(TypeIndex ti) {
26622664
return ctx;
26632665
}
26642666

2667+
std::optional<llvm::StringRef>
2668+
SymbolFileNativePDB::FindMangledFunctionName(PdbCompilandSymId func_id) {
2669+
const CompilandIndexItem *cci =
2670+
m_index->compilands().GetCompiland(func_id.modi);
2671+
if (!cci)
2672+
return std::nullopt;
2673+
2674+
CVSymbol sym_record = cci->m_debug_stream.readSymbolAtOffset(func_id.offset);
2675+
if (sym_record.kind() != S_LPROC32 && sym_record.kind() != S_GPROC32)
2676+
return std::nullopt;
2677+
2678+
ProcSym proc(static_cast<SymbolRecordKind>(sym_record.kind()));
2679+
cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
2680+
return FindMangledSymbol(SegmentOffset(proc.Segment, proc.CodeOffset));
2681+
}
2682+
2683+
std::optional<llvm::StringRef>
2684+
SymbolFileNativePDB::FindMangledSymbol(SegmentOffset so) {
2685+
auto symbol = m_index->publics().findByAddress(m_index->symrecords(),
2686+
so.segment, so.offset);
2687+
if (!symbol)
2688+
return std::nullopt;
2689+
return symbol->first.Name;
2690+
}
2691+
26652692
void SymbolFileNativePDB::CacheUdtDeclarations() {
26662693
for (CVType cvt : m_index->ipi().typeArray()) {
26672694
switch (cvt.kind()) {

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ class SymbolFileNativePDB : public SymbolFileCommon {
140140

141141
std::optional<PdbCompilandSymId> FindSymbolScope(PdbCompilandSymId id);
142142

143+
/// Find the mangled name for a function
144+
///
145+
/// \param id A symbol ID of a S_LPROC32/S_GPROC32 record
146+
/// \returns The mangled name of the function (if available)
147+
std::optional<llvm::StringRef> FindMangledFunctionName(PdbCompilandSymId id);
148+
143149
void FindTypes(const lldb_private::TypeQuery &match,
144150
lldb_private::TypeResults &results) override;
145151

@@ -269,6 +275,8 @@ class SymbolFileNativePDB : public SymbolFileCommon {
269275
void CacheUdtDeclarations();
270276
llvm::Expected<Declaration> ResolveUdtDeclaration(PdbTypeSymId type_id);
271277

278+
std::optional<llvm::StringRef> FindMangledSymbol(SegmentOffset so);
279+
272280
llvm::BumpPtrAllocator m_allocator;
273281

274282
lldb::addr_t m_obj_load_address = 0;

lldb/test/Shell/SymbolFile/NativePDB/break-by-function.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ int main(int argc, char **argv) {
5050
// CHECK: 1: name = 'main', locations = 1
5151
// CHECK: 1.1: where = break-by-function.cpp.tmp.exe`main + {{[0-9]+}}
5252
// CHECK: 2: name = 'OvlGlobalFn', locations = 3
53-
// CHECK: 2.1: where = break-by-function.cpp.tmp.exe`OvlGlobalFn + {{[0-9]+}}
54-
// CHECK: 2.2: where = break-by-function.cpp.tmp.exe`OvlGlobalFn
55-
// CHECK: 2.3: where = break-by-function.cpp.tmp.exe`OvlGlobalFn + {{[0-9]+}}
53+
// CHECK: 2.1: where = break-by-function.cpp.tmp.exe`int OvlGlobalFn(int) + {{[0-9]+}}
54+
// CHECK: 2.2: where = break-by-function.cpp.tmp.exe`int OvlGlobalFn(int, int)
55+
// CHECK: 2.3: where = break-by-function.cpp.tmp.exe`int OvlGlobalFn(int, int, int) + {{[0-9]+}}
5656
// CHECK: 3: name = 'StaticFn', locations = 1
5757
// CHECK: 3.1: where = break-by-function.cpp.tmp.exe`StaticFn + {{[0-9]+}}
5858
// CHECK: 4: name = 'DoesntExist', locations = 0 (pending)

lldb/test/Shell/SymbolFile/NativePDB/break-by-line.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ int main(int argc, char **argv) {
2424
// CHECK: (lldb) target create "{{.*}}break-by-line.cpp.tmp.exe"
2525
// CHECK: Current executable set to '{{.*}}break-by-line.cpp.tmp.exe'
2626
// CHECK: (lldb) break set -f break-by-line.cpp -l 15
27-
// CHECK: Breakpoint 1: where = break-by-line.cpp.tmp.exe`NS::NamespaceFn + {{[0-9]+}} at break-by-line.cpp:15
27+
// CHECK: Breakpoint 1: where = break-by-line.cpp.tmp.exe`int NS::NamespaceFn(int) + {{[0-9]+}} at break-by-line.cpp:15

lldb/test/Shell/SymbolFile/NativePDB/disassembly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main(int argc, char **argv) {
2525
// CHECK-NEXT: disassembly.cpp.tmp.exe[{{.*}}] <+12>: mov qword ptr [rsp + 0x28], rdx
2626
// CHECK-NEXT: disassembly.cpp.tmp.exe[{{.*}}] <+17>: mov dword ptr [rsp + 0x24], ecx
2727
// CHECK: ** 15 foo();
28-
// CHECK: disassembly.cpp.tmp.exe[{{.*}}] <+21>: call {{.*}} ; foo at disassembly.cpp:12
28+
// CHECK: disassembly.cpp.tmp.exe[{{.*}}] <+21>: call {{.*}} ; int foo(void) at disassembly.cpp:12
2929
// CHECK: ** 16 return 0;
3030
// CHECK-NEXT: 17 }
3131
// CHECK-NEXT: 18

lldb/test/Shell/SymbolFile/NativePDB/find-functions.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,19 @@ int main(int argc, char **argv) {
148148
// FIND-OVERLOAD-BASE-DAG: FuncType: id = {{.*}}, compiler_type = "int (void)"
149149
// FIND-OVERLOAD-BASE-DAG: FuncType: id = {{.*}}, compiler_type = "int (char)"
150150
// FIND-OVERLOAD-BASE-DAG: FuncType: id = {{.*}}, compiler_type = "int (char, int, ...)"
151-
// FIND-OVERLOAD-BASE-DAG: Function: id = {{.*}}, name = "Class::overloaded_method"
151+
// FIND-OVERLOAD-BASE-DAG: Function: id = {{.*}}, name = "int Class::overloaded_method(bool)"
152152
// FIND-OVERLOAD-BASE-DAG: FuncType: id = {{.*}}, compiler_type = "_Bool (void)"
153153
// FIND-OVERLOAD-BASE-DAG: FuncType: id = {{.*}}, compiler_type = "_Bool (int)"
154154
// FIND-OVERLOAD-BASE-DAG: FuncType: id = {{.*}}, compiler_type = "int (_Bool)"
155-
// FIND-OVERLOAD-BASE-DAG: Function: id = {{.*}}, name = "overloaded_method"
155+
// FIND-OVERLOAD-BASE-DAG: Function: id = {{.*}}, name = "char overloaded_method(void)"
156+
// FIND-OVERLOAD-BASE-DAG: Function: id = {{.*}}, name = "char overloaded_method(int)"
156157
// FIND-OVERLOAD-BASE-DAG: FuncType: id = {{.*}}, compiler_type = "char (void)"
157158
// FIND-OVERLOAD-BASE-DAG: FuncType: id = {{.*}}, compiler_type = "char (int)"
158159

159160
// FIND-OVERLOAD-METHOD-NOT: "overloaded_method"
160161
// FIND-OVERLOAD-METHOD-DAG: Function: id = {{.*}}, name = "{{.*}}Struct::overloaded_method{{.*}}"
161162
// FIND-OVERLOAD-METHOD-DAG: FuncType: id = {{.*}}, compiler_type = "int (void)"
162163
// FIND-OVERLOAD-METHOD-DAG: FuncType: id = {{.*}}, compiler_type = "int (char)"
163-
// FIND-OVERLOAD-METHOD-DAG: Function: id = {{.*}}, name = "Class::overloaded_method"
164+
// FIND-OVERLOAD-METHOD-DAG: Function: id = {{.*}}, name = "bool Class::overloaded_method(void)"
164165
// FIND-OVERLOAD-METHOD-DAG: FuncType: id = {{.*}}, compiler_type = "_Bool (void)"
165166
// FIND-OVERLOAD-METHOD-DAG: FuncType: id = {{.*}}, compiler_type = "_Bool (int)"

lldb/test/Shell/SymbolFile/NativePDB/local-variables.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int main(int argc, char **argv) {
5555
// CHECK-NEXT: (lldb) step
5656
// CHECK-NEXT: Process {{.*}} stopped
5757
// CHECK-NEXT: * thread #1, stop reason = step in
58-
// CHECK-NEXT: frame #0: {{.*}} local-variables.cpp.tmp.exe`Function(Param1=16, Param2='a') at local-variables.cpp:{{.*}}
58+
// CHECK-NEXT: frame #0: {{.*}} local-variables.cpp.tmp.exe`int Function(Param1=16, Param2='a') at local-variables.cpp:{{.*}}
5959
// CHECK-NEXT: 6
6060
// CHECK-NEXT: 7
6161
// CHECK-NEXT: 8 int Function(int Param1, char Param2) {
@@ -71,7 +71,7 @@ int main(int argc, char **argv) {
7171
// CHECK-NEXT: (lldb) step
7272
// CHECK-NEXT: Process {{.*}} stopped
7373
// CHECK-NEXT: * thread #1, stop reason = step in
74-
// CHECK-NEXT: frame #0: {{.*}} local-variables.cpp.tmp.exe`Function(Param1=16, Param2='a') at local-variables.cpp:{{.*}}
74+
// CHECK-NEXT: frame #0: {{.*}} local-variables.cpp.tmp.exe`int Function(Param1=16, Param2='a') at local-variables.cpp:{{.*}}
7575
// CHECK-NEXT: 7
7676
// CHECK-NEXT: 8 int Function(int Param1, char Param2) {
7777
// CHECK-NEXT: 9 unsigned Local1 = Param1 + 1;
@@ -89,7 +89,7 @@ int main(int argc, char **argv) {
8989
// CHECK-NEXT: (lldb) step
9090
// CHECK-NEXT: Process {{.*}} stopped
9191
// CHECK-NEXT: * thread #1, stop reason = step in
92-
// CHECK-NEXT: frame #0: {{.*}} local-variables.cpp.tmp.exe`Function(Param1=16, Param2='a') at local-variables.cpp:{{.*}}
92+
// CHECK-NEXT: frame #0: {{.*}} local-variables.cpp.tmp.exe`int Function(Param1=16, Param2='a') at local-variables.cpp:{{.*}}
9393
// CHECK-NEXT: 8 int Function(int Param1, char Param2) {
9494
// CHECK-NEXT: 9 unsigned Local1 = Param1 + 1;
9595
// CHECK-NEXT: 10 char Local2 = Param2 + 1;
@@ -109,7 +109,7 @@ int main(int argc, char **argv) {
109109
// CHECK-NEXT: (lldb) step
110110
// CHECK-NEXT: Process {{.*}} stopped
111111
// CHECK-NEXT: * thread #1, stop reason = step in
112-
// CHECK-NEXT: frame #0: {{.*}} local-variables.cpp.tmp.exe`Function(Param1=16, Param2='a') at local-variables.cpp:{{.*}}
112+
// CHECK-NEXT: frame #0: {{.*}} local-variables.cpp.tmp.exe`int Function(Param1=16, Param2='a') at local-variables.cpp:{{.*}}
113113
// CHECK-NEXT: 9 unsigned Local1 = Param1 + 1;
114114
// CHECK-NEXT: 10 char Local2 = Param2 + 1;
115115
// CHECK-NEXT: 11 ++Local1;
@@ -129,7 +129,7 @@ int main(int argc, char **argv) {
129129
// CHECK-NEXT: (lldb) step
130130
// CHECK-NEXT: Process {{.*}} stopped
131131
// CHECK-NEXT: * thread #1, stop reason = step in
132-
// CHECK-NEXT: frame #0: {{.*}} local-variables.cpp.tmp.exe`Function(Param1=16, Param2='a') at local-variables.cpp:{{.*}}
132+
// CHECK-NEXT: frame #0: {{.*}} local-variables.cpp.tmp.exe`int Function(Param1=16, Param2='a') at local-variables.cpp:{{.*}}
133133
// CHECK-NEXT: 10 char Local2 = Param2 + 1;
134134
// CHECK-NEXT: 11 ++Local1;
135135
// CHECK-NEXT: 12 ++Local2;

lldb/test/Shell/SymbolFile/NativePDB/stack_unwinding01.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ int main(int argc, char **argv) {
2424

2525
// CHECK: (lldb) thread backtrace
2626
// CHECK-NEXT: * thread #1, stop reason = breakpoint 1.1
27-
// CHECK-NEXT: * frame #0: {{.*}} stack_unwinding01.cpp.tmp.exe`Struct::simple_method(this={{.*}}, a=2, b=2) at stack_unwinding01.cpp:12
27+
// CHECK-NEXT: * frame #0: {{.*}} stack_unwinding01.cpp.tmp.exe`void Struct::simple_method(this={{.*}}, a=2, b=2) at stack_unwinding01.cpp:12
2828
// CHECK-NEXT: frame #1: {{.*}} stack_unwinding01.cpp.tmp.exe`main(argc={{.*}}, argv={{.*}}) at stack_unwinding01.cpp:20
2929

3030

3131
// CHECK: (lldb) thread backtrace
3232
// CHECK-NEXT: * thread #1, stop reason = breakpoint 1.1
33-
// CHECK-NEXT: * frame #0: {{.*}} stack_unwinding01.cpp.tmp.exe`Struct::simple_method(this={{.*}}, a=3, b=2) at stack_unwinding01.cpp:12
34-
// CHECK-NEXT: frame #1: {{.*}} stack_unwinding01.cpp.tmp.exe`Struct::simple_method(this={{.*}}, a=2, b=2) at stack_unwinding01.cpp:12
33+
// CHECK-NEXT: * frame #0: {{.*}} stack_unwinding01.cpp.tmp.exe`void Struct::simple_method(this={{.*}}, a=3, b=2) at stack_unwinding01.cpp:12
34+
// CHECK-NEXT: frame #1: {{.*}} stack_unwinding01.cpp.tmp.exe`void Struct::simple_method(this={{.*}}, a=2, b=2) at stack_unwinding01.cpp:12
3535
// CHECK-NEXT: frame #2: {{.*}} stack_unwinding01.cpp.tmp.exe`main(argc={{.*}}, argv={{.*}}) at stack_unwinding01.cpp:20
3636

3737
// CHECK: (lldb) thread backtrace
3838
// CHECK-NEXT: * thread #1, stop reason = breakpoint 1.1
39-
// CHECK-NEXT: * frame #0: {{.*}} stack_unwinding01.cpp.tmp.exe`Struct::simple_method(this={{.*}}, a=4, b=2) at stack_unwinding01.cpp:12
40-
// CHECK-NEXT: frame #1: {{.*}} stack_unwinding01.cpp.tmp.exe`Struct::simple_method(this={{.*}}, a=3, b=2) at stack_unwinding01.cpp:12
41-
// CHECK-NEXT: frame #2: {{.*}} stack_unwinding01.cpp.tmp.exe`Struct::simple_method(this={{.*}}, a=2, b=2) at stack_unwinding01.cpp:12
39+
// CHECK-NEXT: * frame #0: {{.*}} stack_unwinding01.cpp.tmp.exe`void Struct::simple_method(this={{.*}}, a=4, b=2) at stack_unwinding01.cpp:12
40+
// CHECK-NEXT: frame #1: {{.*}} stack_unwinding01.cpp.tmp.exe`void Struct::simple_method(this={{.*}}, a=3, b=2) at stack_unwinding01.cpp:12
41+
// CHECK-NEXT: frame #2: {{.*}} stack_unwinding01.cpp.tmp.exe`void Struct::simple_method(this={{.*}}, a=2, b=2) at stack_unwinding01.cpp:12
4242
// CHECK-NEXT: frame #3: {{.*}} stack_unwinding01.cpp.tmp.exe`main(argc={{.*}}, argv={{.*}}) at stack_unwinding01.cpp:20

lldb/test/Shell/SymbolFile/PDB/function-nested-block.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ RUN: lldb-test symbols -find=function -file FunctionNestedBlockTest.cpp -line 4
44
RUN: lldb-test symbols -find=block -file FunctionNestedBlockTest.cpp -line 4 %t.exe | FileCheck --check-prefix=CHECK-BLOCK %s
55

66
CHECK-FUNCTION: Found 1 functions:
7-
CHECK-FUNCTION: name = "{{.*}}", mangled = "{{_?}}main"
7+
CHECK-FUNCTION: name = "main"
88

99
CHECK-BLOCK: Found 1 blocks:
1010
CHECK-BLOCK: Blocks: id = {{.*}}, range = {{.*}}

0 commit comments

Comments
 (0)