Skip to content

Commit e3576b0

Browse files
committed
[Driver] Simplify -g level computation and its interaction with -gsplit-dwarf
Summary: When -gsplit-dwarf is used together with other -g options, in most cases the computed debug info level is decided by the last -g option, with one special case (see below). This patch drops that special case and thus makes it easy to reason about: // If a lower debug level -g comes after -gsplit-dwarf, in some cases // -gsplit-dwarf is cancelled. -gsplit-dwarf -g0 => 0 -gsplit-dwarf -gline-directives-only => DebugDirectivesOnly -gsplit-dwarf -gmlt -fsplit-dwarf-inlining => 1 -gsplit-dwarf -gmlt -fno-split-dwarf-inlining => 1 + split // If -gsplit-dwarf comes after -g options, with this patch, the net // effect is 2 + split for all combinations -g0 -gsplit-dwarf => 2 + split -gline-directives-only -gsplit-dwarf => 2 + split -gmlt -gsplit-dwarf -fsplit-dwarf-inlining => 2 + split -gmlt -gsplit-dwarf -fno-split-dwarf-inlining => 1 + split (before) 2 + split (after) The last case has been changed. In general, if the user intends to lower debug info level, place that -g option after -gsplit-dwarf. Some context: In gcc, the last of -gsplit-dwarf -g0 -g1 -g2 -g3 -ggdb[0-3] -gdwarf-* ... decides the debug info level (-gsplit-dwarf -gdwarf-* have level 2). It is a bit unfortunate that -gsplit-dwarf -gdwarf-* ... participate in the level computation but that is the status quo. Reviewers: dblaikie, echristo, probinson Reviewed By: dblaikie, probinson Subscribers: probinson, aprantl, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59923 llvm-svn: 358544
1 parent ab70da0 commit e3576b0

File tree

2 files changed

+24
-35
lines changed

2 files changed

+24
-35
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,35 +3170,24 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
31703170
SplitDWARFInlining = false;
31713171
}
31723172

3173-
if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
3174-
if (checkDebugInfoOption(A, Args, D, TC)) {
3175-
// If the last option explicitly specified a debug-info level, use it.
3176-
if (A->getOption().matches(options::OPT_gN_Group)) {
3177-
DebugInfoKind = DebugLevelToInfoKind(*A);
3178-
// If you say "-gsplit-dwarf -gline-tables-only", -gsplit-dwarf loses.
3179-
// But -gsplit-dwarf is not a g_group option, hence we have to check the
3180-
// order explicitly. If -gsplit-dwarf wins, we fix DebugInfoKind later.
3181-
// This gets a bit more complicated if you've disabled inline info in
3182-
// the skeleton CUs (SplitDWARFInlining) - then there's value in
3183-
// composing split-dwarf and line-tables-only, so let those compose
3184-
// naturally in that case. And if you just turned off debug info,
3185-
// (-gsplit-dwarf -g0) - do that.
3186-
if (DwarfFission != DwarfFissionKind::None) {
3187-
if (A->getIndex() > SplitDWARFArg->getIndex()) {
3188-
if (DebugInfoKind == codegenoptions::NoDebugInfo ||
3189-
DebugInfoKind == codegenoptions::DebugDirectivesOnly ||
3190-
(DebugInfoKind == codegenoptions::DebugLineTablesOnly &&
3191-
SplitDWARFInlining))
3192-
DwarfFission = DwarfFissionKind::None;
3193-
} else if (SplitDWARFInlining)
3194-
DebugInfoKind = codegenoptions::NoDebugInfo;
3195-
}
3196-
} else {
3197-
// For any other 'g' option, use Limited.
3198-
DebugInfoKind = codegenoptions::LimitedDebugInfo;
3199-
}
3200-
} else {
3201-
DebugInfoKind = codegenoptions::LimitedDebugInfo;
3173+
if (const Arg *A =
3174+
Args.getLastArg(options::OPT_g_Group, options::OPT_gsplit_dwarf,
3175+
options::OPT_gsplit_dwarf_EQ)) {
3176+
DebugInfoKind = codegenoptions::LimitedDebugInfo;
3177+
3178+
// If the last option explicitly specified a debug-info level, use it.
3179+
if (checkDebugInfoOption(A, Args, D, TC) &&
3180+
A->getOption().matches(options::OPT_gN_Group)) {
3181+
DebugInfoKind = DebugLevelToInfoKind(*A);
3182+
// For -g0 or -gline-tables-only, drop -gsplit-dwarf. This gets a bit more
3183+
// complicated if you've disabled inline info in the skeleton CUs
3184+
// (SplitDWARFInlining) - then there's value in composing split-dwarf and
3185+
// line-tables-only, so let those compose naturally in that case.
3186+
if (DebugInfoKind == codegenoptions::NoDebugInfo ||
3187+
DebugInfoKind == codegenoptions::DebugDirectivesOnly ||
3188+
(DebugInfoKind == codegenoptions::DebugLineTablesOnly &&
3189+
SplitDWARFInlining))
3190+
DwarfFission = DwarfFissionKind::None;
32023191
}
32033192
}
32043193

@@ -3273,16 +3262,12 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
32733262
}
32743263
}
32753264

3276-
// -gsplit-dwarf should turn on -g and enable the backend dwarf
3277-
// splitting and extraction.
3265+
// -gsplit-dwarf enables the backend dwarf splitting and extraction.
32783266
if (T.isOSBinFormatELF()) {
32793267
if (!SplitDWARFInlining)
32803268
CmdArgs.push_back("-fno-split-dwarf-inlining");
32813269

32823270
if (DwarfFission != DwarfFissionKind::None) {
3283-
if (DebugInfoKind == codegenoptions::NoDebugInfo)
3284-
DebugInfoKind = codegenoptions::LimitedDebugInfo;
3285-
32863271
if (DwarfFission == DwarfFissionKind::Single)
32873272
CmdArgs.push_back("-enable-split-dwarf=single");
32883273
else

clang/test/Driver/split-debug.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
// RUN: FileCheck -check-prefix=CHECK-SPLIT-WITH-GMLT < %t %s
7272
//
7373
// CHECK-SPLIT-WITH-GMLT: "-enable-split-dwarf"
74-
// CHECK-SPLIT-WITH-GMLT: "-debug-info-kind=line-tables-only"
74+
// CHECK-SPLIT-WITH-GMLT: "-debug-info-kind=limited"
7575
// CHECK-SPLIT-WITH-GMLT: "-split-dwarf-file"
7676

7777
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -fno-split-dwarf-inlining -S -### %s 2> %t
@@ -103,13 +103,17 @@
103103

104104
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -g0 -S -### %s 2> %t
105105
// RUN: FileCheck -check-prefix=CHECK-G0-OVER-SPLIT < %t %s
106+
// RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=split -g0 -S -### %s 2> %t
107+
// RUN: FileCheck -check-prefix=CHECK-G0-OVER-SPLIT < %t %s
106108
//
107109
// CHECK-G0-OVER-SPLIT-NOT: "-enable-split-dwarf"
108110
// CHECK-G0-OVER-SPLIT-NOT: "-debug-info-kind
109111
// CHECK-G0-OVER-SPLIT-NOT: "-split-dwarf-file"
110112

111113
// RUN: %clang -target x86_64-unknown-linux-gnu -g0 -gsplit-dwarf -S -### %s 2> %t
112114
// RUN: FileCheck -check-prefix=CHECK-SPLIT-OVER-G0 < %t %s
115+
// RUN: %clang -target x86_64-unknown-linux-gnu -g0 -gsplit-dwarf=split -S -### %s 2> %t
116+
// RUN: FileCheck -check-prefix=CHECK-SPLIT-OVER-G0 < %t %s
113117
//
114118
// CHECK-SPLIT-OVER-G0: "-enable-split-dwarf" "-debug-info-kind=limited"
115119
// CHECK-SPLIT-OVER-G0: "-split-dwarf-file"

0 commit comments

Comments
 (0)