Skip to content

Commit 227db86

Browse files
committed
Switch to using -debug-info-kind=constructor as default (from =limited)
Summary: -debug-info-kind=constructor reduces the amount of class debug info that is emitted; this patch switches to using this as the default. Constructor homing emits the complete type info for a class only when the constructor is emitted, so it is expected that there will be some classes that are not defined in the debug info anymore because they are never constructed, and we shouldn't need debug info for these classes. I compared the PDB files for clang, and there are 273 class types that are defined with `=limited` but not with `=constructor` (out of ~60,000 total class types). We've looked at a number of the types that are no longer defined with =constructor. The vast majority of cases are something like class A is used as a parameter in a member function of some other class B, which is emitted. But the function that uses class A is never called, and class A is never constructed, and therefore isn't emitted in the debug info. Bug: https://bugs.llvm.org/show_bug.cgi?id=46537 Subscribers: aprantl, cfe-commits, lldb-commits Tags: #clang, #lldb Differential Revision: https://reviews.llvm.org/D79147
1 parent 672ae62 commit 227db86

File tree

11 files changed

+32
-29
lines changed

11 files changed

+32
-29
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ static codegenoptions::DebugInfoKind DebugLevelToInfoKind(const Arg &A) {
498498
return codegenoptions::DebugLineTablesOnly;
499499
if (A.getOption().matches(options::OPT_gline_directives_only))
500500
return codegenoptions::DebugDirectivesOnly;
501-
return codegenoptions::LimitedDebugInfo;
501+
return codegenoptions::DebugInfoConstructor;
502502
}
503503

504504
static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
@@ -2380,7 +2380,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
23802380
CmdArgs.push_back(Value.data());
23812381
} else {
23822382
RenderDebugEnablingArgs(Args, CmdArgs,
2383-
codegenoptions::LimitedDebugInfo,
2383+
codegenoptions::DebugInfoConstructor,
23842384
DwarfVersion, llvm::DebuggerKind::Default);
23852385
}
23862386
} else if (Value.startswith("-mcpu") || Value.startswith("-mfpu") ||
@@ -3653,7 +3653,7 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
36533653
if (const Arg *A =
36543654
Args.getLastArg(options::OPT_g_Group, options::OPT_gsplit_dwarf,
36553655
options::OPT_gsplit_dwarf_EQ)) {
3656-
DebugInfoKind = codegenoptions::LimitedDebugInfo;
3656+
DebugInfoKind = codegenoptions::DebugInfoConstructor;
36573657

36583658
// If the last option explicitly specified a debug-info level, use it.
36593659
if (checkDebugInfoOption(A, Args, D, TC) &&
@@ -3758,7 +3758,7 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
37583758
if (checkDebugInfoOption(A, Args, D, TC)) {
37593759
if (DebugInfoKind != codegenoptions::DebugLineTablesOnly &&
37603760
DebugInfoKind != codegenoptions::DebugDirectivesOnly) {
3761-
DebugInfoKind = codegenoptions::LimitedDebugInfo;
3761+
DebugInfoKind = codegenoptions::DebugInfoConstructor;
37623762
CmdArgs.push_back("-dwarf-ext-refs");
37633763
CmdArgs.push_back("-fmodule-format=obj");
37643764
}
@@ -3778,7 +3778,9 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
37783778
TC.GetDefaultStandaloneDebug());
37793779
if (const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
37803780
(void)checkDebugInfoOption(A, Args, D, TC);
3781-
if (DebugInfoKind == codegenoptions::LimitedDebugInfo && NeedFullDebug)
3781+
if ((DebugInfoKind == codegenoptions::LimitedDebugInfo ||
3782+
DebugInfoKind == codegenoptions::DebugInfoConstructor) &&
3783+
NeedFullDebug)
37823784
DebugInfoKind = codegenoptions::FullDebugInfo;
37833785

37843786
if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source,
@@ -6552,7 +6554,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
65526554
options::OPT_gline_tables_only)) {
65536555
*EmitCodeView = true;
65546556
if (DebugInfoArg->getOption().matches(options::OPT__SLASH_Z7))
6555-
*DebugInfoKind = codegenoptions::LimitedDebugInfo;
6557+
*DebugInfoKind = codegenoptions::DebugInfoConstructor;
65566558
else
65576559
*DebugInfoKind = codegenoptions::DebugLineTablesOnly;
65586560
} else {
@@ -6849,7 +6851,7 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
68496851
// the guard for source type, however there is a test which asserts
68506852
// that some assembler invocation receives no -debug-info-kind,
68516853
// and it's not clear whether that test is just overly restrictive.
6852-
DebugInfoKind = (WantDebug ? codegenoptions::LimitedDebugInfo
6854+
DebugInfoKind = (WantDebug ? codegenoptions::DebugInfoConstructor
68536855
: codegenoptions::NoDebugInfo);
68546856
// Add the -fdebug-compilation-dir flag if needed.
68556857
addDebugCompDirArg(Args, CmdArgs, C.getDriver().getVFS());

clang/test/Driver/cl-options.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,11 @@
524524

525525
// RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s
526526
// Zi: "-gcodeview"
527-
// Zi: "-debug-info-kind=limited"
527+
// Zi: "-debug-info-kind=constructor"
528528

529529
// RUN: %clang_cl /Z7 /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7 %s
530530
// Z7: "-gcodeview"
531-
// Z7: "-debug-info-kind=limited"
531+
// Z7: "-debug-info-kind=constructor"
532532

533533
// RUN: %clang_cl /Zd /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7GMLT %s
534534
// Z7GMLT: "-gcodeview"
@@ -557,7 +557,7 @@
557557
// which made it "win". This test could not detect that bug.
558558
// RUN: %clang_cl /Z7 -gdwarf /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7_gdwarf %s
559559
// Z7_gdwarf: "-gcodeview"
560-
// Z7_gdwarf: "-debug-info-kind=limited"
560+
// Z7_gdwarf: "-debug-info-kind=constructor"
561561
// Z7_gdwarf: "-dwarf-version=4"
562562

563563
// RUN: %clang_cl -fmsc-version=1800 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX11 %s

clang/test/Driver/clang-g-opts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
3232

3333
// CHECK-WITHOUT-G-NOT: -debug-info-kind
34-
// CHECK-WITH-G: "-debug-info-kind=limited"
34+
// CHECK-WITH-G: "-debug-info-kind=constructor"
3535
// CHECK-WITH-G: "-dwarf-version=4"
3636
// CHECK-WITH-G-DWARF2: "-dwarf-version=2"
3737

clang/test/Driver/cuda-dwarf-2.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
// HAS_DEBUG-NOT: warning: debug
5151
// HAS_DEBUG: "-fcuda-is-device"
52-
// HAS_DEBUG-SAME: "-debug-info-kind={{limited|line-tables-only}}"
52+
// HAS_DEBUG-SAME: "-debug-info-kind={{constructor|line-tables-only}}"
5353
// HAS_DEBUG-SAME: "-dwarf-version=2"
5454
// HAS_DEBUG: ptxas
5555
// HAS_DEBUG-SAME: "-g"

clang/test/Driver/debug-options-as.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// RUN: | FileCheck %s
2424
//
2525
// CHECK: "-cc1as"
26-
// CHECK: "-debug-info-kind=limited"
26+
// CHECK: "-debug-info-kind=constructor"
2727

2828
// Check to make sure clang with -g on a .s file gets passed -dwarf-debug-producer.
2929
// rdar://12955296

clang/test/Driver/debug-options.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,18 @@
274274
// GLIO_ONLY_DWARF2: "-dwarf-version=2"
275275
//
276276
// G_ONLY: "-cc1"
277-
// G_ONLY: "-debug-info-kind=limited"
277+
// G_ONLY: "-debug-info-kind=constructor"
278278
//
279279
// These tests assert that "-gline-tables-only" "-g" uses the latter,
280280
// but otherwise not caring about the DebugInfoKind.
281281
// G_ONLY_DWARF2: "-cc1"
282-
// G_ONLY_DWARF2: "-debug-info-kind={{standalone|limited}}"
282+
// G_ONLY_DWARF2: "-debug-info-kind={{standalone|constructor}}"
283283
// G_ONLY_DWARF2: "-dwarf-version=2"
284284
//
285285
// G_STANDALONE: "-cc1"
286286
// G_STANDALONE: "-debug-info-kind=standalone"
287287
// G_LIMITED: "-cc1"
288-
// G_LIMITED: "-debug-info-kind=limited"
288+
// G_LIMITED: "-debug-info-kind=constructor"
289289
// G_DWARF2: "-dwarf-version=2"
290290
// G_DWARF4: "-dwarf-version=4"
291291
//
@@ -339,7 +339,7 @@
339339
// NOCI: "-gno-column-info"
340340
//
341341
// GEXTREFS: "-dwarf-ext-refs" "-fmodule-format=obj"
342-
// GEXTREFS: "-debug-info-kind={{standalone|limited}}"
342+
// GEXTREFS: "-debug-info-kind={{standalone|constructor}}"
343343

344344
// RUN: not %clang -cc1 -debug-info-kind=watkind 2>&1 | FileCheck -check-prefix=BADSTRING1 %s
345345
// BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind'

clang/test/Driver/integrated-as.s

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@
2727
// XA_INCLUDE2: "-Ifoo_dir"
2828

2929
// RUN: %clang -### -target x86_64--- -c -integrated-as %s -gdwarf-4 -gdwarf-2 2>&1 | FileCheck --check-prefix=DWARF2 %s
30-
// DWARF2: "-debug-info-kind=limited" "-dwarf-version=2"
30+
// DWARF2: "-debug-info-kind=constructor" "-dwarf-version=2"
3131

3232
// RUN: %clang -### -target x86_64--- -c -integrated-as %s -gdwarf-3 2>&1 | FileCheck --check-prefix=DWARF3 %s
33-
// DWARF3: "-debug-info-kind=limited" "-dwarf-version=3"
33+
// DWARF3: "-debug-info-kind=constructor" "-dwarf-version=3"
3434

3535
// RUN: %clang -### -target x86_64--- -c -integrated-as %s -gdwarf-4 2>&1 | FileCheck --check-prefix=DWARF4 %s
36-
// DWARF4: "-debug-info-kind=limited" "-dwarf-version=4"
36+
// DWARF4: "-debug-info-kind=constructor" "-dwarf-version=4"
3737

3838
// RUN: %clang -### -target x86_64--- -c -integrated-as %s -Xassembler -gdwarf-2 2>&1 | FileCheck --check-prefix=DWARF2XASSEMBLER %s
39-
// DWARF2XASSEMBLER: "-debug-info-kind=limited" "-dwarf-version=2"
39+
// DWARF2XASSEMBLER: "-debug-info-kind=constructor" "-dwarf-version=2"
4040

4141
// RUN: %clang -### -target x86_64--- -c -integrated-as %s -Wa,-gdwarf-2 2>&1 | FileCheck --check-prefix=DWARF2WA %s
42-
// DWARF2WA: "-debug-info-kind=limited" "-dwarf-version=2"
42+
// DWARF2WA: "-debug-info-kind=constructor" "-dwarf-version=2"
4343

4444
// A dwarf version number that driver can't parse is just stuffed in.
4545
// RUN: %clang -### -target x86_64--- -c -integrated-as %s -Wa,-gdwarf-huh 2>&1 | FileCheck --check-prefix=BOGODWARF %s

clang/test/Driver/myriad-toolchain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
// NOSTDLIB-NOT: "-lc"
8484

8585
// RUN: %clang -### -c -g %s -target sparc-myriad 2>&1 | FileCheck -check-prefix=G_SPARC %s
86-
// G_SPARC: "-debug-info-kind=limited" "-dwarf-version=2"
86+
// G_SPARC: "-debug-info-kind=constructor" "-dwarf-version=2"
8787

8888
// RUN: %clang -### -c %s -target sparc-myriad-rtems -fuse-init-array 2>&1 \
8989
// RUN: | FileCheck -check-prefix=USE-INIT-ARRAY %s

clang/test/Driver/openmp-offload-gpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241

242242
// HAS_DEBUG-NOT: warning: debug
243243
// HAS_DEBUG: "-triple" "nvptx64-nvidia-cuda"
244-
// HAS_DEBUG-SAME: "-debug-info-kind={{limited|line-tables-only}}"
244+
// HAS_DEBUG-SAME: "-debug-info-kind={{constructor|line-tables-only}}"
245245
// HAS_DEBUG-SAME: "-dwarf-version=2"
246246
// HAS_DEBUG-SAME: "-fopenmp-is-device"
247247
// HAS_DEBUG: ptxas

clang/test/Driver/split-debug.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@
6868
// RUN: FileCheck -check-prefix=CHECK-NOINLINE-WITHOUT-SPLIT < %t %s
6969
//
7070
// CHECK-NOINLINE-WITHOUT-SPLIT: "-fno-split-dwarf-inlining"
71-
// CHECK-NOINLINE-WITHOUT-SPLIT: "-debug-info-kind=limited"
71+
// CHECK-NOINLINE-WITHOUT-SPLIT: "-debug-info-kind=constructor"
7272

7373
// RUN: %clang -target x86_64-unknown-linux-gnu -gmlt -gsplit-dwarf -fno-split-dwarf-inlining -S -### %s 2> %t
7474
// RUN: FileCheck -check-prefix=CHECK-SPLIT-WITH-GMLT < %t %s
7575
//
76-
// CHECK-SPLIT-WITH-GMLT: "-debug-info-kind=limited"
76+
// CHECK-SPLIT-WITH-GMLT: "-debug-info-kind=constructor"
7777
// CHECK-SPLIT-WITH-GMLT: "-split-dwarf-output"
7878

7979
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -fno-split-dwarf-inlining -S -### %s 2> %t
8080
// RUN: FileCheck -check-prefix=CHECK-SPLIT-WITH-NOINL < %t %s
8181
//
82-
// CHECK-SPLIT-WITH-NOINL: "-debug-info-kind=limited"
82+
// CHECK-SPLIT-WITH-NOINL: "-debug-info-kind=constructor"
8383
// CHECK-SPLIT-WITH-NOINL: "-split-dwarf-output"
8484

8585
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -gmlt -fsplit-dwarf-inlining -S -### %s 2> %t
@@ -92,7 +92,7 @@
9292
// RUN: %clang -target x86_64-unknown-linux-gnu -gmlt -gsplit-dwarf -S -### %s 2> %t
9393
// RUN: FileCheck -check-prefix=CHECK-SPLIT-OVER-GMLT < %t %s
9494
//
95-
// CHECK-SPLIT-OVER-GMLT: "-debug-info-kind=limited"
95+
// CHECK-SPLIT-OVER-GMLT: "-debug-info-kind=constructor"
9696
// CHECK-SPLIT-OVER-GMLT: "-split-dwarf-file"
9797
// CHECK-SPLIT-OVER-GMLT: "-split-dwarf-output"
9898

@@ -117,6 +117,6 @@
117117
// RUN: %clang -target x86_64-unknown-linux-gnu -g0 -gsplit-dwarf=split -S -### %s 2> %t
118118
// RUN: FileCheck -check-prefix=CHECK-SPLIT-OVER-G0 < %t %s
119119
//
120-
// CHECK-SPLIT-OVER-G0: "-debug-info-kind=limited"
120+
// CHECK-SPLIT-OVER-G0: "-debug-info-kind=constructor"
121121
// CHECK-SPLIT-OVER-G0: "-split-dwarf-file"
122122
// CHECK-SPLIT-OVER-G0: "-split-dwarf-output"

lldb/test/Shell/SymbolFile/PDB/Inputs/ClassLayoutTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class Class : public Base { // Test base class.
106106
int main() {
107107
MemberTest::Base B1;
108108
B1.Get();
109+
MemberTest::Class C1;
109110
MemberTest::Class::StaticMemberFunc(1, 10, 2);
110111
return 0;
111112
}

0 commit comments

Comments
 (0)