Skip to content

Commit bb99428

Browse files
authored
DebugInfo: Emit as "C++" rather than "C" (#6361)
This helps at least lldb handle calling functions (currently the debug info describes every function as `void()`, so no parameters or return values are supported) - seems gdb and lldb both depend on demangling to varying degrees in C code (marking a function as "prototyped" in C in DWARF does seem to also address this problem). Given: ``` fn PrintThree() { Core.Print(3); } ``` Before: ``` (lldb) p PrintThree() error: Couldn't look up symbols: PrintThree Hint: The expression tried to call a function that is not present in the target, perhaps because it was optimized out by the compiler. ``` After: ``` (lldb) p PrintThree() 3 (lldb) ```
1 parent 35274f2 commit bb99428

File tree

189 files changed

+262
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+262
-264
lines changed

toolchain/driver/testdata/compile/optimize/clang_no_optimize_twice.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn Call() -> i32 {
6565
// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
6666
// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0}
6767
// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
68-
// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
68+
// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
6969
// CHECK:STDOUT: !6 = !DIFile(filename: "foo.carbon", directory: "")
7070
// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "Call", linkageName: "_CCall.Main", scope: null, file: !6, line: 12, type: !8, spFlags: DISPFlagDefinition, unit: !5)
7171
// CHECK:STDOUT: !8 = !DISubroutineType(types: !9)

toolchain/driver/testdata/compile/optimize/optimize_debug.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn VectorizedWithOptSpeed(a: array(i32, 65536)*) {
9191
// CHECK:STDOUT:
9292
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
9393
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
94-
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
94+
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
9595
// CHECK:STDOUT: !3 = !DIFile(filename: "foo.carbon", directory: "")
9696
// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "NoInlineWithOz", linkageName: "_CNoInlineWithOz.Main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
9797
// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)

toolchain/driver/testdata/compile/optimize/optimize_default.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn VectorizedWithOptSpeed(a: array(i32, 65536)*) {
9191
// CHECK:STDOUT:
9292
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
9393
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
94-
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
94+
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
9595
// CHECK:STDOUT: !3 = !DIFile(filename: "foo.carbon", directory: "")
9696
// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "NoInlineWithOz", linkageName: "_CNoInlineWithOz.Main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
9797
// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)

toolchain/driver/testdata/compile/optimize/optimize_none.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn VectorizedWithOptSpeed(a: array(i32, 65536)*) {
113113
// CHECK:STDOUT:
114114
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
115115
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
116-
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
116+
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
117117
// CHECK:STDOUT: !3 = !DIFile(filename: "foo.carbon", directory: "")
118118
// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "NoInlineWithOz", linkageName: "_CNoInlineWithOz.Main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
119119
// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)

toolchain/driver/testdata/compile/optimize/optimize_size.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn VectorizedWithOptSpeed(a: array(i32, 65536)*) {
113113
// CHECK:STDOUT:
114114
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
115115
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
116-
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
116+
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
117117
// CHECK:STDOUT: !3 = !DIFile(filename: "foo.carbon", directory: "")
118118
// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "NoInlineWithOz", linkageName: "_CNoInlineWithOz.Main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
119119
// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)

toolchain/driver/testdata/compile/optimize/optimize_speed.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn VectorizedWithOptSpeed(a: array(i32, 65536)*) {
107107
// CHECK:STDOUT:
108108
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
109109
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
110-
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
110+
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
111111
// CHECK:STDOUT: !3 = !DIFile(filename: "foo.carbon", directory: "")
112112
// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "NoInlineWithOz", linkageName: "_CNoInlineWithOz.Main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
113113
// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)

toolchain/driver/testdata/stdin.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@
7676
// CHECK:STDOUT:
7777
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
7878
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
79-
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
79+
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
8080
// CHECK:STDOUT: !3 = !DIFile(filename: "-", directory: "")

toolchain/lower/context.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,10 @@ auto Context::BuildDICompileUnit(llvm::StringRef module_name,
7777
llvm::DEBUG_METADATA_VERSION);
7878
// TODO: Include directory path in the compile_unit_file.
7979
llvm::DIFile* compile_unit_file = di_builder.createFile(module_name, "");
80-
// TODO: Introduce a new language code for Carbon. C works well for now since
81-
// it's something debuggers will already know/have support for at least.
82-
// Probably have to bump to C++ at some point for virtual functions,
83-
// templates, etc.
84-
return di_builder.createCompileUnit(llvm::dwarf::DW_LANG_C, compile_unit_file,
85-
"carbon",
80+
// TODO: Introduce a new language code for Carbon. C++ works well for now
81+
// since it's something debuggers will already know/have support for at least.
82+
return di_builder.createCompileUnit(llvm::dwarf::DW_LANG_C_plus_plus,
83+
compile_unit_file, "carbon",
8684
/*isOptimized=*/false, /*Flags=*/"",
8785
/*RV=*/0);
8886
}

toolchain/lower/testdata/alias/local.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn F() -> i32 {
4040
// CHECK:STDOUT:
4141
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
4242
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
43-
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
43+
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
4444
// CHECK:STDOUT: !3 = !DIFile(filename: "local.carbon", directory: "")
4545
// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
4646
// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)

toolchain/lower/testdata/array/array_in_place.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn G() {
4444
// CHECK:STDOUT:
4545
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
4646
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
47-
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
47+
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
4848
// CHECK:STDOUT: !3 = !DIFile(filename: "array_in_place.carbon", directory: "")
4949
// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main", scope: null, file: !3, line: 15, type: !5, spFlags: DISPFlagDefinition, unit: !2)
5050
// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)

0 commit comments

Comments
 (0)