214 lines · plain
1# RUN: rm -rf %t && mkdir -p %t2# RUN: split-file %s %t3# RUN: %python %t/all.py > %t/all.ll4# RUN: sed 's@---TEMPORARY_DIR---@%{/t:regex_replacement}@' %t/debug.map.template > %t/debug.map5# RUN: %llc_dwarf -mtriple x86_64-apple-macosx10.4.0 -o %t/all.o -filetype=obj %t/all.ll6# RUN: dsymutil -f -y %t/debug.map -o - | llvm-dwarfdump -debug-line - | FileCheck %s7# RUN: dsymutil --linker parallel -f -y %t/debug.map -o - | llvm-dwarfdump -debug-line - | tee %t/output.txt | FileCheck %s8 9# CHECK: include_directories[255] = "/tmp/tmp.0HPkdttdoU/d254"10# CHECK-NEXT: include_directories[256] = "/tmp/tmp.0HPkdttdoU/d255"11# CHECK-NEXT: include_directories[257] = "/tmp/tmp.0HPkdttdoU/d256"12 13# CHECK: dir_index: 25514# CHECK: dir_index: 25615# CHECK: dir_index: 25716 17# Original file generated doing the following (fish shell):18# - for cnt in (seq 0 256); mkdir -p d$cnt ; printf "void func$cnd() {}\n#define FUNC$cnt func$cnt()\n" >> d$cnt/f$cnt.c ; end19# - for cnt in (seq 0 256); printf "#include \"f$cnt.c\"" >> all.c ; end20# - printf "void all() {\n" >> all.c21# - for cnt in (seq 0 256); printf "FUNC$cnt;\n" >> all.c ; end22# - printf "}\n" >> all.c23# - clang -target x86_64-apple-macos -S -emit-llvm -gdwarf-5 -o all.ll all.c (for cnt in (seq 0 256); echo "-Id$cnt"; end)24# - Edit all.ll manually and change all DIFile so the directory in filename is25# moved into the directory field.26# - Transformed into Python manually.27 28#--- all.py29import math30import string31 32PROLOGUE = string.Template("""\33; ModuleID = 'all.c'34source_filename = "all.c"35target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"36target triple = "x86_64-apple-macosx10.4.0"37""")38 39FUNCTION = string.Template("""\40; Function Attrs: noinline nounwind optnone uwtable41define void @func$idx() #0 !dbg !$dbg_reference_subprogram {42 ret void, !dbg !$dbg_reference_location_ret43}44""")45 46ALL_FUNCTION_PROLOGUE = string.Template("""\47; Function Attrs: noinline nounwind optnone uwtable48define void @all() #0 !dbg !$dbg_reference_subprogram {49""")50 51ALL_FUNCTION_CALL = string.Template("""\52 call void @func$idx(), !dbg !$dbg_reference_location_call53""")54 55ALL_FUNCTION_EPILOGUE = string.Template("""\56 ret void, !dbg !$dbg_reference_location_ret57}58""")59 60DWARF_PROLOGUE = string.Template("""\61attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+cmov,+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+ssse3,+x87" "tune-cpu"="generic" }62 63!llvm.dbg.cu = !{!0}64!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}65!llvm.ident = !{!8}66 67!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 18.1.6 (CentOS 18.1.6-3.el9)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")68!1 = !DIFile(filename: "all.c", directory: "/tmp/tmp.0HPkdttdoU", checksumkind: CSK_MD5, checksum: "8b5068f097f0c272ddc808ed2d82cb12")69!2 = !{i32 7, !"Dwarf Version", i32 5}70!3 = !{i32 2, !"Debug Info Version", i32 3}71!4 = !{i32 1, !"wchar_size", i32 4}72!5 = !{i32 8, !"PIC Level", i32 2}73!6 = !{i32 7, !"uwtable", i32 2}74!7 = !{i32 7, !"frame-pointer", i32 2}75!8 = !{!"clang version 18.1.6 (CentOS 18.1.6-3.el9)"}76""")77 78DWARF_FUNCTION_WITH_TYPE = string.Template("""\79!$dbg_reference_subprogram = distinct !DISubprogram(name: "func$idx", scope: !$dbg_reference_file, file: !$dbg_reference_file, line: 1, type: !11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)80!$dbg_reference_file = !DIFile(filename: "f$idx.c", directory: "/tmp/tmp.0HPkdttdoU/d$idx", checksumkind: CSK_MD5, checksum: "01234567890123456789012345678901")81!11 = !DISubroutineType(types: !12)82!12 = !{null}83!$dbg_reference_location = !DILocation(line: 1, column: $column, scope: !$dbg_reference_subprogram)84""")85 86DWARF_FUNCTION = string.Template("""\87!$dbg_reference_subprogram = distinct !DISubprogram(name: "func$idx", scope: !$dbg_reference_file, file: !$dbg_reference_file, line: 1, type: !11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)88!$dbg_reference_file = !DIFile(filename: "f$idx.c", directory: "/tmp/tmp.0HPkdttdoU/d$idx", checksumkind: CSK_MD5, checksum: "01234567890123456789012345678901")89!$dbg_reference_location = !DILocation(line: 1, column: $column, scope: !$dbg_reference_subprogram)90""")91 92DWARF_ALL_FUNCTION_PROLOGUE = string.Template("""\93!$dbg_reference_subprogram = distinct !DISubprogram(name: "all", scope: !1, file: !1, line: $line_number, type: !11, scopeLine: $line_number, spFlags: DISPFlagDefinition, unit: !0)94""")95 96DWARF_ALL_FUNCTION_LOCATION = string.Template("""\97!$dbg_reference_location = !DILocation(line: $line_number, column: 1, scope: !$dbg_reference_subprogram)98""")99 100NUM_FUNCS = 257101 102dbg_reference_subprogram = 9103dbg_reference_file = 10104dbg_reference_location = 13105column_base = 15106functions = []107dwarf_subprograms = []108 109first = True110for idx in range(NUM_FUNCS):111 functions.append(112 FUNCTION.substitute(113 idx=idx,114 dbg_reference_subprogram=dbg_reference_subprogram,115 dbg_reference_location_ret=dbg_reference_location,116 )117 )118 if first:119 dwarf_subprograms.append(120 DWARF_FUNCTION_WITH_TYPE.substitute(121 idx=idx,122 dbg_reference_subprogram=dbg_reference_subprogram,123 dbg_reference_file=dbg_reference_file,124 dbg_reference_location=dbg_reference_location,125 column=column_base,126 )127 )128 else:129 dwarf_subprograms.append(130 DWARF_FUNCTION.substitute(131 idx=idx,132 dbg_reference_subprogram=dbg_reference_subprogram,133 dbg_reference_file=dbg_reference_file,134 dbg_reference_location=dbg_reference_location,135 column=column_base + math.floor(math.log10(idx)),136 )137 )138 139 dbg_reference_subprogram += 5 if first else 3140 dbg_reference_file += 5 if first else 3141 dbg_reference_location += 3142 first = False143 144dbg_reference_location = dbg_reference_subprogram + 1145line_number = 258146all_function = []147dwarf_all_subprogram = []148 149all_function.append(150 ALL_FUNCTION_PROLOGUE.substitute(151 dbg_reference_subprogram=dbg_reference_subprogram152 )153)154dwarf_all_subprogram.append(155 DWARF_ALL_FUNCTION_PROLOGUE.substitute(156 dbg_reference_subprogram=dbg_reference_subprogram,157 line_number=line_number158 )159)160line_number += 1161 162for idx in range(NUM_FUNCS):163 all_function.append(164 ALL_FUNCTION_CALL.substitute(165 idx=idx,166 dbg_reference_location_call=dbg_reference_location,167 )168 )169 dwarf_all_subprogram.append(170 DWARF_ALL_FUNCTION_LOCATION.substitute(171 dbg_reference_location=dbg_reference_location,172 line_number=line_number,173 dbg_reference_subprogram=dbg_reference_subprogram,174 )175 )176 177 dbg_reference_location += 1178 line_number += 1179 180all_function.append(181 ALL_FUNCTION_EPILOGUE.substitute(182 dbg_reference_location_ret=dbg_reference_location183 )184)185dwarf_all_subprogram.append(186 DWARF_ALL_FUNCTION_LOCATION.substitute(187 dbg_reference_location=dbg_reference_location,188 line_number=line_number,189 dbg_reference_subprogram=dbg_reference_subprogram,190 )191)192 193print(PROLOGUE.substitute())194for function in functions:195 print(function)196for all_function_piece in all_function:197 print(all_function_piece, end='')198print()199print(DWARF_PROLOGUE.substitute(), end='')200for dwarf_subprogram in dwarf_subprograms:201 print(dwarf_subprogram, end='')202for dwarf_all_subprogram_piece in dwarf_all_subprogram:203 print(dwarf_all_subprogram_piece, end='')204print()205 206#--- debug.map.template207---208triple: 'x86_64-apple-darwin'209objects:210 - filename: ---TEMPORARY_DIR---/all.o211 symbols:212 - { sym: _all, objAddr: 0x0, binAddr: 0x0, size: 0x0 }213...214