[PATCH] D96055: [DebugInfo] Emit comments for debug_loc bytes as integers

David Stenberg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 4 09:08:20 PST 2021


dstenb created this revision.
dstenb added reviewers: SouraVX, aprantl, dblaikie.
dstenb added a project: debug-info.
Herald added a subscriber: hiraditya.
dstenb requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The DebugLocDwarfExpression::emitData1() function would emit the
assembly file comments using raw characters. As emitting non-printable
characters or characters >127 can lead to issues, just emit the comments
as integers instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96055

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/test/DebugInfo/X86/implicit_value_comments.ll


Index: llvm/test/DebugInfo/X86/implicit_value_comments.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/X86/implicit_value_comments.ll
@@ -0,0 +1,70 @@
+;; This test verifies that the comments for the bytes in the
+;; DW_OP_implicit_value operation are emitted as integers rather than
+;; characters.
+
+; RUN: llc -debugger-tune=gdb -filetype=asm %s -o -  | FileCheck %s
+
+; CHECK: .short  6                               # Loc expr size
+; CHECK-NEXT: .byte   158                        # DW_OP_implicit_value
+; CHECK-NEXT: .byte   4                          # 4
+; CHECK-NEXT: .byte   195                        # 195
+; CHECK-NEXT: .byte   245                        # 245
+; CHECK-NEXT: .byte   72                         # 72
+; CHECK-NEXT: .byte   64                         # 64
+; CHECK-NEXT: .quad   0
+; CHECK-NEXT: .quad   0
+
+;; Generated from: clang -ggdb -O1
+;;int main() {
+;;        float f = 3.14f;
+;;        printf("dummy\n");
+;;        f *= f;
+;;        return 0;
+;;}
+; ModuleID = 'implicit_value_comments.c'
+source_filename = "implicit_value_comments.c"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at str = private unnamed_addr constant [6 x i8] c"dummy\00", align 1
+
+; Function Attrs: nofree nounwind uwtable
+define dso_local i32 @main() local_unnamed_addr #0 !dbg !7 {
+entry:
+  call void @llvm.dbg.value(metadata float 0x40091EB860000000, metadata !12, metadata !DIExpression()), !dbg !14
+  %puts = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0)), !dbg !15
+  call void @llvm.dbg.value(metadata float undef, metadata !12, metadata !DIExpression()), !dbg !14
+  ret i32 0, !dbg !16
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata) #1
+
+; Function Attrs: nofree nounwind
+declare i32 @puts(i8* nocapture readonly) local_unnamed_addr #2
+
+attributes #0 = { nofree nounwind uwtable }
+attributes #1 = { nounwind readnone speculatable willreturn }
+attributes #2 = { nofree nounwind }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "implicit_value_comments.c", directory: "/home/")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 11.0.0"}
+!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !{!12}
+!12 = !DILocalVariable(name: "f", scope: !7, file: !1, line: 2, type: !13)
+!13 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
+!14 = !DILocation(line: 0, scope: !7)
+!15 = !DILocation(line: 3, column: 2, scope: !7)
+!16 = !DILocation(line: 5, column: 2, scope: !7)
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -188,7 +188,7 @@
 }
 
 void DebugLocDwarfExpression::emitData1(uint8_t Value) {
-  getActiveStreamer().emitInt8(Value, Twine(Value));
+  getActiveStreamer().emitInt8(Value, Twine((int)Value));
 }
 
 void DebugLocDwarfExpression::emitBaseTypeRef(uint64_t Idx) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96055.321473.patch
Type: text/x-patch
Size: 3855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210204/a5e79bcb/attachment.bin>


More information about the llvm-commits mailing list