@zigc/lib 0.16.0-test.1 → 0.17.0-dev.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/c/math.zig +148 -35
- package/c/stropts.zig +17 -0
- package/c.zig +1 -0
- package/compiler/aro/aro/Attribute/names.zig +604 -589
- package/compiler/aro/aro/Attribute.zig +202 -116
- package/compiler/aro/aro/Builtins/common.zig +874 -863
- package/compiler/aro/aro/Builtins/eval.zig +15 -7
- package/compiler/aro/aro/Builtins.zig +0 -1
- package/compiler/aro/aro/CodeGen.zig +3 -1
- package/compiler/aro/aro/Compilation.zig +120 -97
- package/compiler/aro/aro/Diagnostics.zig +21 -17
- package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
- package/compiler/aro/aro/Driver.zig +124 -50
- package/compiler/aro/aro/LangOpts.zig +12 -2
- package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
- package/compiler/aro/aro/Parser.zig +336 -142
- package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
- package/compiler/aro/aro/Preprocessor.zig +127 -56
- package/compiler/aro/aro/Target.zig +17 -12
- package/compiler/aro/aro/Tokenizer.zig +31 -14
- package/compiler/aro/aro/Toolchain.zig +4 -7
- package/compiler/aro/aro/Tree.zig +178 -148
- package/compiler/aro/aro/TypeStore.zig +82 -24
- package/compiler/aro/aro/Value.zig +13 -17
- package/compiler/aro/aro/features.zig +1 -0
- package/compiler/aro/aro/pragmas/once.zig +0 -1
- package/compiler/aro/aro/record_layout.zig +3 -3
- package/compiler/aro/assembly_backend/x86_64.zig +3 -4
- package/compiler/aro/backend/Assembly.zig +1 -2
- package/compiler/aro/backend/Interner.zig +2 -2
- package/compiler/aro/backend/Ir.zig +100 -92
- package/compiler/aro/include/ptrcheck.h +49 -0
- package/compiler/aro/main.zig +26 -10
- package/compiler/build_runner.zig +1 -0
- package/compiler/objdump.zig +93 -0
- package/compiler/reduce.zig +5 -1
- package/compiler/resinator/compile.zig +2 -2
- package/compiler/resinator/main.zig +7 -1
- package/compiler/resinator/preprocess.zig +1 -3
- package/compiler/std-docs.zig +8 -1
- package/compiler/test_runner.zig +194 -62
- package/compiler/translate-c/MacroTranslator.zig +80 -11
- package/compiler/translate-c/PatternList.zig +1 -9
- package/compiler/translate-c/Scope.zig +43 -6
- package/compiler/translate-c/Translator.zig +364 -126
- package/compiler/translate-c/ast.zig +19 -11
- package/compiler/translate-c/main.zig +75 -16
- package/compiler_rt/cos.zig +141 -52
- package/compiler_rt/divmodei4.zig +40 -17
- package/compiler_rt/exp.zig +1 -4
- package/compiler_rt/exp2.zig +1 -4
- package/compiler_rt/exp_f128.zig +377 -0
- package/compiler_rt/limb64.zig +1126 -0
- package/compiler_rt/long_double.zig +37 -0
- package/compiler_rt/mulXi3.zig +1 -1
- package/compiler_rt/mulo.zig +6 -1
- package/compiler_rt/rem_pio2l.zig +173 -0
- package/compiler_rt/sin.zig +140 -55
- package/compiler_rt/sincos.zig +279 -72
- package/compiler_rt/ssp.zig +1 -1
- package/compiler_rt/tan.zig +118 -47
- package/compiler_rt/trig.zig +256 -6
- package/compiler_rt/udivmodei4.zig +28 -0
- package/compiler_rt.zig +2 -0
- package/fuzzer.zig +855 -307
- package/libc/musl/src/math/pow.c +343 -0
- package/package.json +1 -1
- package/std/Build/Fuzz.zig +6 -19
- package/std/Build/Module.zig +1 -1
- package/std/Build/Step/CheckObject.zig +3 -3
- package/std/Build/Step/Compile.zig +18 -0
- package/std/Build/Step/ConfigHeader.zig +49 -33
- package/std/Build/Step/InstallArtifact.zig +18 -0
- package/std/Build/Step/Run.zig +536 -87
- package/std/Build/Step/TranslateC.zig +0 -6
- package/std/Build/Step.zig +8 -15
- package/std/Build/WebServer.zig +29 -17
- package/std/Build/abi.zig +47 -11
- package/std/Build.zig +17 -14
- package/std/Io/Dispatch.zig +2 -0
- package/std/Io/File/Reader.zig +3 -1
- package/std/Io/File.zig +1 -0
- package/std/Io/Kqueue.zig +2 -2
- package/std/Io/Threaded.zig +181 -143
- package/std/Io/Uring.zig +2 -1
- package/std/Io/Writer.zig +41 -41
- package/std/Io.zig +970 -2
- package/std/Target.zig +3 -2
- package/std/Thread.zig +8 -3
- package/std/array_hash_map.zig +96 -555
- package/std/array_list.zig +22 -31
- package/std/bit_set.zig +22 -6
- package/std/builtin/assembly.zig +68 -0
- package/std/c.zig +17 -17
- package/std/compress/flate/Compress.zig +3 -3
- package/std/crypto/Certificate/Bundle.zig +15 -1
- package/std/crypto/codecs/asn1.zig +33 -18
- package/std/crypto/codecs/base64_hex_ct.zig +14 -4
- package/std/debug/Dwarf.zig +29 -9
- package/std/debug/Info.zig +4 -0
- package/std/debug/MachOFile.zig +46 -8
- package/std/debug/Pdb.zig +539 -36
- package/std/debug/SelfInfo/Elf.zig +19 -18
- package/std/debug/SelfInfo/MachO.zig +18 -7
- package/std/debug/SelfInfo/Windows.zig +138 -36
- package/std/debug.zig +179 -65
- package/std/enums.zig +25 -19
- package/std/heap/ArenaAllocator.zig +145 -154
- package/std/heap/debug_allocator.zig +7 -7
- package/std/http/Client.zig +10 -6
- package/std/http.zig +11 -9
- package/std/json/Stringify.zig +3 -3
- package/std/json/dynamic.zig +4 -4
- package/std/math/big/int.zig +16 -17
- package/std/mem/Allocator.zig +4 -5
- package/std/mem.zig +48 -0
- package/std/os/emscripten.zig +2 -18
- package/std/os/linux/arc.zig +144 -0
- package/std/os/linux.zig +21 -4
- package/std/os/windows.zig +2 -2
- package/std/pdb.zig +143 -4
- package/std/posix.zig +6 -12
- package/std/priority_dequeue.zig +13 -12
- package/std/priority_queue.zig +5 -4
- package/std/process/Child.zig +1 -1
- package/std/process/Environ.zig +1 -1
- package/std/start.zig +17 -4
- package/std/std.zig +19 -6
- package/std/testing/FailingAllocator.zig +4 -4
- package/std/testing/Smith.zig +37 -2
- package/std/zig/Ast/Render.zig +186 -458
- package/std/zig/Ast.zig +0 -4
- package/std/zig/AstGen.zig +44 -7
- package/std/zig/AstSmith.zig +2602 -0
- package/std/zig/Client.zig +8 -3
- package/std/zig/Parse.zig +83 -74
- package/std/zig/Server.zig +26 -0
- package/std/zig/Zir.zig +17 -0
- package/std/zig/c_translation/helpers.zig +14 -9
- package/std/zig/llvm/Builder.zig +107 -48
- package/std/zig/system.zig +20 -4
- package/std/zig/tokenizer.zig +2 -1
- package/std/zig.zig +6 -0
- package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
- package/libc/mingw/complex/cabs.c +0 -48
- package/libc/mingw/complex/cabsf.c +0 -48
- package/libc/mingw/complex/cacos.c +0 -50
- package/libc/mingw/complex/cacosf.c +0 -50
- package/libc/mingw/complex/carg.c +0 -48
- package/libc/mingw/complex/cargf.c +0 -48
- package/libc/mingw/complex/casin.c +0 -50
- package/libc/mingw/complex/casinf.c +0 -50
- package/libc/mingw/complex/catan.c +0 -50
- package/libc/mingw/complex/catanf.c +0 -50
- package/libc/mingw/complex/ccos.c +0 -50
- package/libc/mingw/complex/ccosf.c +0 -50
- package/libc/mingw/complex/cexp.c +0 -48
- package/libc/mingw/complex/cexpf.c +0 -48
- package/libc/mingw/complex/cimag.c +0 -48
- package/libc/mingw/complex/cimagf.c +0 -48
- package/libc/mingw/complex/clog.c +0 -48
- package/libc/mingw/complex/clog10.c +0 -49
- package/libc/mingw/complex/clog10f.c +0 -49
- package/libc/mingw/complex/clogf.c +0 -48
- package/libc/mingw/complex/conj.c +0 -48
- package/libc/mingw/complex/conjf.c +0 -48
- package/libc/mingw/complex/cpow.c +0 -48
- package/libc/mingw/complex/cpowf.c +0 -48
- package/libc/mingw/complex/cproj.c +0 -48
- package/libc/mingw/complex/cprojf.c +0 -48
- package/libc/mingw/complex/creal.c +0 -48
- package/libc/mingw/complex/crealf.c +0 -48
- package/libc/mingw/complex/csin.c +0 -50
- package/libc/mingw/complex/csinf.c +0 -50
- package/libc/mingw/complex/csqrt.c +0 -48
- package/libc/mingw/complex/csqrtf.c +0 -48
- package/libc/mingw/complex/ctan.c +0 -50
- package/libc/mingw/complex/ctanf.c +0 -50
- package/libc/mingw/math/arm/s_rint.c +0 -86
- package/libc/mingw/math/arm/s_rintf.c +0 -51
- package/libc/mingw/math/arm/sincos.S +0 -30
- package/libc/mingw/math/arm-common/sincosl.c +0 -13
- package/libc/mingw/math/arm64/rint.c +0 -12
- package/libc/mingw/math/arm64/rintf.c +0 -12
- package/libc/mingw/math/arm64/sincos.S +0 -32
- package/libc/mingw/math/bsd_private_base.h +0 -148
- package/libc/mingw/math/fdiml.c +0 -24
- package/libc/mingw/math/frexpf.c +0 -13
- package/libc/mingw/math/frexpl.c +0 -71
- package/libc/mingw/math/x86/acosf.c +0 -29
- package/libc/mingw/math/x86/atanf.c +0 -23
- package/libc/mingw/math/x86/atanl.c +0 -18
- package/libc/mingw/math/x86/cos.def.h +0 -65
- package/libc/mingw/math/x86/cosl.c +0 -46
- package/libc/mingw/math/x86/cosl_internal.S +0 -55
- package/libc/mingw/math/x86/ldexp.c +0 -23
- package/libc/mingw/math/x86/scalbn.S +0 -41
- package/libc/mingw/math/x86/scalbnf.S +0 -40
- package/libc/mingw/math/x86/sin.def.h +0 -65
- package/libc/mingw/math/x86/sinl.c +0 -46
- package/libc/mingw/math/x86/sinl_internal.S +0 -58
- package/libc/mingw/math/x86/tanl.S +0 -62
- package/libc/mingw/misc/btowc.c +0 -28
- package/libc/mingw/misc/wcstof.c +0 -66
- package/libc/mingw/misc/wcstoimax.c +0 -132
- package/libc/mingw/misc/wcstoumax.c +0 -126
- package/libc/mingw/misc/wctob.c +0 -29
- package/libc/mingw/misc/winbs_uint64.c +0 -6
- package/libc/mingw/misc/winbs_ulong.c +0 -6
- package/libc/mingw/misc/winbs_ushort.c +0 -6
- package/libc/mingw/stdio/_Exit.c +0 -10
- package/libc/mingw/stdio/_findfirst64i32.c +0 -21
- package/libc/mingw/stdio/_findnext64i32.c +0 -21
- package/libc/mingw/stdio/_fstat64i32.c +0 -37
- package/libc/mingw/stdio/_stat64i32.c +0 -37
- package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
- package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
- package/libc/mingw/stdio/_wstat64i32.c +0 -37
- package/libc/musl/src/legacy/isastream.c +0 -7
- package/libc/musl/src/legacy/valloc.c +0 -8
- package/libc/musl/src/math/__cosl.c +0 -96
- package/libc/musl/src/math/__sinl.c +0 -78
- package/libc/musl/src/math/__tanl.c +0 -143
- package/libc/musl/src/math/aarch64/lrint.c +0 -10
- package/libc/musl/src/math/aarch64/lrintf.c +0 -10
- package/libc/musl/src/math/aarch64/rintf.c +0 -7
- package/libc/musl/src/math/cosl.c +0 -39
- package/libc/musl/src/math/fdim.c +0 -10
- package/libc/musl/src/math/fdimf.c +0 -10
- package/libc/musl/src/math/fdiml.c +0 -18
- package/libc/musl/src/math/finite.c +0 -7
- package/libc/musl/src/math/finitef.c +0 -7
- package/libc/musl/src/math/frexp.c +0 -23
- package/libc/musl/src/math/frexpf.c +0 -23
- package/libc/musl/src/math/frexpl.c +0 -29
- package/libc/musl/src/math/i386/lrint.c +0 -8
- package/libc/musl/src/math/i386/lrintf.c +0 -8
- package/libc/musl/src/math/i386/rintf.c +0 -7
- package/libc/musl/src/math/lrint.c +0 -72
- package/libc/musl/src/math/lrintf.c +0 -8
- package/libc/musl/src/math/powerpc64/lrint.c +0 -16
- package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
- package/libc/musl/src/math/rintf.c +0 -30
- package/libc/musl/src/math/s390x/rintf.c +0 -15
- package/libc/musl/src/math/sincosl.c +0 -60
- package/libc/musl/src/math/sinl.c +0 -41
- package/libc/musl/src/math/tanl.c +0 -29
- package/libc/musl/src/math/x32/lrint.s +0 -5
- package/libc/musl/src/math/x32/lrintf.s +0 -5
- package/libc/musl/src/math/x86_64/lrint.c +0 -8
- package/libc/musl/src/math/x86_64/lrintf.c +0 -8
- package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
package/std/debug/Pdb.zig
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const std = @import("../std.zig");
|
|
2
|
-
const
|
|
2
|
+
const Io = std.Io;
|
|
3
|
+
const File = Io.File;
|
|
3
4
|
const Allocator = std.mem.Allocator;
|
|
4
5
|
const pdb = std.pdb;
|
|
5
6
|
const assert = std.debug.assert;
|
|
@@ -10,7 +11,7 @@ file_reader: *File.Reader,
|
|
|
10
11
|
msf: Msf,
|
|
11
12
|
allocator: Allocator,
|
|
12
13
|
string_table: ?*MsfStream,
|
|
13
|
-
|
|
14
|
+
ipi: ?[]u8,
|
|
14
15
|
modules: []Module,
|
|
15
16
|
sect_contribs: []pdb.SectionContribEntry,
|
|
16
17
|
guid: [16]u8,
|
|
@@ -25,6 +26,10 @@ pub const Module = struct {
|
|
|
25
26
|
symbols: []u8,
|
|
26
27
|
subsect_info: []u8,
|
|
27
28
|
checksum_offset: ?usize,
|
|
29
|
+
/// The inlinee source lines, sorted by inlinee. This saves us from repeatedly doing linear
|
|
30
|
+
/// searches over all inlinees. We prefer binary search over a hashmap as LLVM somtimes outputs
|
|
31
|
+
/// multiple entries for a single inlinee ID, see `getInlineeSourceLines` for more info.
|
|
32
|
+
inlinee_source_lines: []InlineeSourceLine,
|
|
28
33
|
|
|
29
34
|
pub fn deinit(self: *Module, allocator: Allocator) void {
|
|
30
35
|
allocator.free(self.module_name);
|
|
@@ -32,6 +37,7 @@ pub const Module = struct {
|
|
|
32
37
|
if (self.populated) {
|
|
33
38
|
allocator.free(self.symbols);
|
|
34
39
|
allocator.free(self.subsect_info);
|
|
40
|
+
allocator.free(self.inlinee_source_lines);
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
};
|
|
@@ -41,7 +47,7 @@ pub fn init(gpa: Allocator, file_reader: *File.Reader) !Pdb {
|
|
|
41
47
|
.file_reader = file_reader,
|
|
42
48
|
.allocator = gpa,
|
|
43
49
|
.string_table = null,
|
|
44
|
-
.
|
|
50
|
+
.ipi = null,
|
|
45
51
|
.msf = try Msf.init(gpa, file_reader),
|
|
46
52
|
.modules = &.{},
|
|
47
53
|
.sect_contribs = &.{},
|
|
@@ -53,6 +59,7 @@ pub fn init(gpa: Allocator, file_reader: *File.Reader) !Pdb {
|
|
|
53
59
|
pub fn deinit(self: *Pdb) void {
|
|
54
60
|
const gpa = self.allocator;
|
|
55
61
|
self.msf.deinit(gpa);
|
|
62
|
+
if (self.ipi) |ipi| gpa.free(ipi);
|
|
56
63
|
for (self.modules) |*module| {
|
|
57
64
|
module.deinit(gpa);
|
|
58
65
|
}
|
|
@@ -67,7 +74,7 @@ pub fn parseDbiStream(self: *Pdb) !void {
|
|
|
67
74
|
const gpa = self.allocator;
|
|
68
75
|
const reader = &stream.interface;
|
|
69
76
|
|
|
70
|
-
const header = try reader.takeStruct(
|
|
77
|
+
const header = try reader.takeStruct(pdb.DbiStreamHeader, .little);
|
|
71
78
|
if (header.version_header != 19990903) // V70, only value observed by LLVM team
|
|
72
79
|
return error.UnknownPDBVersion;
|
|
73
80
|
// if (header.Age != age)
|
|
@@ -85,14 +92,14 @@ pub fn parseDbiStream(self: *Pdb) !void {
|
|
|
85
92
|
const mod_info = try reader.takeStruct(pdb.ModInfo, .little);
|
|
86
93
|
var this_record_len: usize = @sizeOf(pdb.ModInfo);
|
|
87
94
|
|
|
88
|
-
var module_name:
|
|
95
|
+
var module_name: Io.Writer.Allocating = .init(gpa);
|
|
89
96
|
defer module_name.deinit();
|
|
90
97
|
this_record_len += try reader.streamDelimiterLimit(&module_name.writer, 0, .limited(1024));
|
|
91
98
|
assert(reader.buffered()[0] == 0); // TODO change streamDelimiterLimit API
|
|
92
99
|
reader.toss(1);
|
|
93
100
|
this_record_len += 1;
|
|
94
101
|
|
|
95
|
-
var obj_file_name:
|
|
102
|
+
var obj_file_name: Io.Writer.Allocating = .init(gpa);
|
|
96
103
|
defer obj_file_name.deinit();
|
|
97
104
|
this_record_len += try reader.streamDelimiterLimit(&obj_file_name.writer, 0, .limited(1024));
|
|
98
105
|
assert(reader.buffered()[0] == 0); // TODO change streamDelimiterLimit API
|
|
@@ -115,6 +122,7 @@ pub fn parseDbiStream(self: *Pdb) !void {
|
|
|
115
122
|
.symbols = undefined,
|
|
116
123
|
.subsect_info = undefined,
|
|
117
124
|
.checksum_offset = null,
|
|
125
|
+
.inlinee_source_lines = undefined,
|
|
118
126
|
});
|
|
119
127
|
|
|
120
128
|
mod_info_offset += this_record_len;
|
|
@@ -128,7 +136,7 @@ pub fn parseDbiStream(self: *Pdb) !void {
|
|
|
128
136
|
|
|
129
137
|
var sect_cont_offset: usize = 0;
|
|
130
138
|
if (section_contrib_size != 0) {
|
|
131
|
-
const version = reader.takeEnum(
|
|
139
|
+
const version = reader.takeEnum(pdb.SectionContrSubstreamVersion, .little) catch |err| switch (err) {
|
|
132
140
|
error.InvalidEnumTag, error.EndOfStream => return error.InvalidDebugInfo,
|
|
133
141
|
error.ReadFailed => return error.ReadFailed,
|
|
134
142
|
};
|
|
@@ -148,6 +156,15 @@ pub fn parseDbiStream(self: *Pdb) !void {
|
|
|
148
156
|
self.sect_contribs = try sect_contribs.toOwnedSlice();
|
|
149
157
|
}
|
|
150
158
|
|
|
159
|
+
pub fn parseIpiStream(self: *Pdb) !void {
|
|
160
|
+
const gpa = self.allocator;
|
|
161
|
+
const stream = self.getStream(.ipi) orelse return;
|
|
162
|
+
const header = try stream.interface.peekStruct(pdb.IpiStreamHeader, .little);
|
|
163
|
+
if (header.version != .v80) // only value observed by LLVM team
|
|
164
|
+
return error.UnknownPDBVersion;
|
|
165
|
+
self.ipi = try stream.interface.readAlloc(gpa, @sizeOf(pdb.IpiStreamHeader) + header.type_record_bytes);
|
|
166
|
+
}
|
|
167
|
+
|
|
151
168
|
pub fn parseInfoStream(self: *Pdb) !void {
|
|
152
169
|
var stream = self.getStream(pdb.StreamType.pdb) orelse return error.InvalidDebugInfo;
|
|
153
170
|
const reader = &stream.interface;
|
|
@@ -212,38 +229,500 @@ pub fn parseInfoStream(self: *Pdb) !void {
|
|
|
212
229
|
return error.MissingDebugInfo;
|
|
213
230
|
}
|
|
214
231
|
|
|
215
|
-
pub fn
|
|
232
|
+
pub fn getProcSym(self: *Pdb, module: *Module, address: u64) ?*align(1) pdb.ProcSym {
|
|
216
233
|
_ = self;
|
|
217
234
|
std.debug.assert(module.populated);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const prefix: *align(1) pdb.RecordPrefix = @ptrCast(&module.symbols[symbol_i]);
|
|
235
|
+
var reader: Io.Reader = .fixed(module.symbols);
|
|
236
|
+
while (true) {
|
|
237
|
+
const prefix = reader.takeStructPointer(pdb.RecordPrefix) catch return null;
|
|
222
238
|
if (prefix.record_len < 2)
|
|
223
239
|
return null;
|
|
240
|
+
reader.discardAll(prefix.record_len - @sizeOf(u16)) catch return null;
|
|
224
241
|
switch (prefix.record_kind) {
|
|
225
242
|
.lproc32, .gproc32 => {
|
|
226
|
-
const proc_sym: *align(1) pdb.ProcSym = @ptrCast(
|
|
243
|
+
const proc_sym: *align(1) pdb.ProcSym = @ptrCast(prefix);
|
|
227
244
|
if (address >= proc_sym.code_offset and address < proc_sym.code_offset + proc_sym.code_size) {
|
|
228
|
-
return
|
|
245
|
+
return proc_sym;
|
|
229
246
|
}
|
|
230
247
|
},
|
|
231
248
|
else => {},
|
|
232
249
|
}
|
|
233
|
-
symbol_i += prefix.record_len + @sizeOf(u16);
|
|
234
250
|
}
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
pub const InlineSiteSymIterator = struct {
|
|
255
|
+
module_index: usize,
|
|
256
|
+
offset: usize,
|
|
257
|
+
end: usize,
|
|
258
|
+
|
|
259
|
+
const empty: InlineSiteSymIterator = .{
|
|
260
|
+
.module_index = 0,
|
|
261
|
+
.offset = 0,
|
|
262
|
+
.end = 0,
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
pub fn next(iter: *InlineSiteSymIterator, module: *Module) ?*align(1) pdb.InlineSiteSym {
|
|
266
|
+
while (iter.offset < iter.end) {
|
|
267
|
+
const inline_prefix: *align(1) pdb.RecordPrefix = @ptrCast(&module.symbols[iter.offset]);
|
|
268
|
+
const end = iter.offset + inline_prefix.record_len + @sizeOf(u16);
|
|
269
|
+
if (end > iter.end) return null;
|
|
270
|
+
defer iter.offset = end;
|
|
271
|
+
switch (inline_prefix.record_kind) {
|
|
272
|
+
// Skip nested procedures
|
|
273
|
+
.lproc32,
|
|
274
|
+
.lproc32_st,
|
|
275
|
+
.gproc32,
|
|
276
|
+
.gproc32_st,
|
|
277
|
+
.lproc32_id,
|
|
278
|
+
.gproc32_id,
|
|
279
|
+
.lproc32_dpc,
|
|
280
|
+
.lproc32_dpc_id,
|
|
281
|
+
=> {
|
|
282
|
+
const skip: *align(1) pdb.ProcSym = @ptrCast(inline_prefix);
|
|
283
|
+
iter.offset = skip.end;
|
|
284
|
+
},
|
|
285
|
+
.inlinesite,
|
|
286
|
+
.inlinesite2,
|
|
287
|
+
=> return @ptrCast(inline_prefix),
|
|
288
|
+
else => {},
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
pub const BinaryAnnotation = union(enum) {
|
|
297
|
+
code_offset: u32,
|
|
298
|
+
change_code_offset_base: u32,
|
|
299
|
+
change_code_offset: u32,
|
|
300
|
+
change_code_length: u32,
|
|
301
|
+
change_file: u32,
|
|
302
|
+
change_line_offset: i32,
|
|
303
|
+
change_line_end_delta: u32,
|
|
304
|
+
change_range_kind: RangeKind,
|
|
305
|
+
change_column_start: u32,
|
|
306
|
+
change_column_end_delta: i32,
|
|
307
|
+
change_code_offset_and_line_offset: struct { code_delta: u32, line_delta: i32 },
|
|
308
|
+
change_code_length_and_code_offset: struct { length: u32, delta: u32 },
|
|
309
|
+
change_column_end: u32,
|
|
310
|
+
|
|
311
|
+
pub const RangeKind = enum(u32) { expression = 0, statement = 1 };
|
|
312
|
+
|
|
313
|
+
/// A virtual machine that processed binary annotations.
|
|
314
|
+
pub const RangeIterator = struct {
|
|
315
|
+
annotations: Iterator,
|
|
316
|
+
curr: PartialRange,
|
|
317
|
+
/// The previous range is tracked as the code length is sometimes implied by the subsequent
|
|
318
|
+
/// range.
|
|
319
|
+
prev: ?PartialRange,
|
|
320
|
+
|
|
321
|
+
const PartialRange = struct {
|
|
322
|
+
line_offset: i32,
|
|
323
|
+
file_id: ?u32,
|
|
324
|
+
code_offset: u32,
|
|
325
|
+
code_length: ?u32,
|
|
326
|
+
|
|
327
|
+
/// Resolves a partial range to a range with a definite length, or returns null if this
|
|
328
|
+
/// is not possible.
|
|
329
|
+
fn resolve(self: PartialRange, next_code_offset: ?u32) ?Range {
|
|
330
|
+
return .{
|
|
331
|
+
.line_offset = self.line_offset,
|
|
332
|
+
.file_id = self.file_id,
|
|
333
|
+
.code_offset = self.code_offset,
|
|
334
|
+
.code_length = b: {
|
|
335
|
+
if (self.code_length) |l| break :b l;
|
|
336
|
+
const end = next_code_offset orelse return null;
|
|
337
|
+
break :b end - self.code_offset;
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
pub fn init(annotations: Iterator) RangeIterator {
|
|
344
|
+
return .{
|
|
345
|
+
.annotations = annotations,
|
|
346
|
+
.curr = .{
|
|
347
|
+
.line_offset = 0,
|
|
348
|
+
.file_id = null,
|
|
349
|
+
.code_offset = 0,
|
|
350
|
+
.code_length = null,
|
|
351
|
+
},
|
|
352
|
+
.prev = null,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
pub const Range = struct {
|
|
357
|
+
line_offset: i32,
|
|
358
|
+
file_id: ?u32,
|
|
359
|
+
code_offset: u32,
|
|
360
|
+
code_length: u32,
|
|
361
|
+
|
|
362
|
+
pub fn contains(self: Range, offset_in_func: usize) bool {
|
|
363
|
+
return self.code_offset <= offset_in_func and
|
|
364
|
+
offset_in_func < self.code_offset + self.code_length;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
pub fn next(self: *RangeIterator) error{InvalidDebugInfo}!?Range {
|
|
369
|
+
while (try self.annotations.next()) |annotation| {
|
|
370
|
+
switch (annotation) {
|
|
371
|
+
.change_code_offset => |delta| {
|
|
372
|
+
self.curr.code_offset += delta;
|
|
373
|
+
},
|
|
374
|
+
.change_code_length => |length| {
|
|
375
|
+
if (self.prev) |*prev| prev.code_length = prev.code_length orelse length;
|
|
376
|
+
self.curr.code_offset += length;
|
|
377
|
+
},
|
|
378
|
+
// LLVM has code to emit these, but I wasn't able to figure out how trigger it
|
|
379
|
+
// so this logic is untested.
|
|
380
|
+
.change_file => |file_id| {
|
|
381
|
+
self.curr.file_id = file_id;
|
|
382
|
+
},
|
|
383
|
+
// LLVM never emits this opcode, but it's clear enough how to interpret it so we
|
|
384
|
+
// may as well handle it in case they emit it in the future
|
|
385
|
+
.change_code_length_and_code_offset => |info| {
|
|
386
|
+
self.curr.code_length = info.length;
|
|
387
|
+
self.curr.code_offset += info.delta;
|
|
388
|
+
},
|
|
389
|
+
.change_line_offset => |delta| {
|
|
390
|
+
self.curr.line_offset += delta;
|
|
391
|
+
},
|
|
392
|
+
.change_code_offset_and_line_offset => |info| {
|
|
393
|
+
self.curr.code_offset += info.code_delta;
|
|
394
|
+
self.curr.line_offset += info.line_delta;
|
|
395
|
+
},
|
|
396
|
+
|
|
397
|
+
// Not emitted by LLVM at the time of writing, and we don't want to add support
|
|
398
|
+
// without a test case. Safe to ignore since we don't use this info right now.
|
|
399
|
+
.change_line_end_delta,
|
|
400
|
+
.change_column_start,
|
|
401
|
+
.change_column_end_delta,
|
|
402
|
+
.change_column_end,
|
|
403
|
+
=> {},
|
|
404
|
+
|
|
405
|
+
// Not emitted by LLVM at the time of writing. Various sources conflict on how
|
|
406
|
+
// these opcodes should be interpreted, so we make no attempt to handle them.
|
|
407
|
+
.code_offset,
|
|
408
|
+
.change_code_offset_base,
|
|
409
|
+
.change_range_kind,
|
|
410
|
+
=> {
|
|
411
|
+
self.annotations = .empty;
|
|
412
|
+
self.prev = null;
|
|
413
|
+
return null;
|
|
414
|
+
},
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// If we have a new code offset, return the previous range if it exists, resolving
|
|
418
|
+
// its length if necessary.
|
|
419
|
+
switch (annotation) {
|
|
420
|
+
.change_code_offset,
|
|
421
|
+
.change_code_offset_and_line_offset,
|
|
422
|
+
.change_code_length_and_code_offset,
|
|
423
|
+
=> {},
|
|
424
|
+
else => continue,
|
|
425
|
+
}
|
|
426
|
+
defer self.prev = self.curr;
|
|
427
|
+
const prev = self.prev orelse continue;
|
|
428
|
+
return prev.resolve(self.curr.code_offset);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// If we've processed all the binary operations but still have a previous range leftover
|
|
432
|
+
// with a known length, return it.
|
|
433
|
+
const prev = self.prev orelse return null;
|
|
434
|
+
defer self.prev = null;
|
|
435
|
+
return prev.resolve(null);
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
pub const Iterator = struct {
|
|
440
|
+
reader: Io.Reader,
|
|
441
|
+
|
|
442
|
+
pub const empty: Iterator = .{ .reader = .ending_instance };
|
|
443
|
+
|
|
444
|
+
pub fn next(self: *Iterator) error{InvalidDebugInfo}!?BinaryAnnotation {
|
|
445
|
+
return take(&self.reader) catch |err| switch (err) {
|
|
446
|
+
error.ReadFailed => return error.InvalidDebugInfo,
|
|
447
|
+
error.EndOfStream => return null,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
pub fn take(reader: *Io.Reader) Io.Reader.Error!BinaryAnnotation {
|
|
453
|
+
const op = std.enums.fromInt(
|
|
454
|
+
pdb.BinaryAnnotationOpcode,
|
|
455
|
+
try takePackedU32(reader),
|
|
456
|
+
) orelse return error.ReadFailed;
|
|
457
|
+
switch (op) {
|
|
458
|
+
// Microsoft's docs say that invalid is used as padding, though it is left ambiguous
|
|
459
|
+
// whether padding is allowed internally or only after all instructions are complete.
|
|
460
|
+
// Empirically, the latter appears to be the case, at least with the output from LLVM
|
|
461
|
+
// that I've tested.
|
|
462
|
+
.invalid => return error.EndOfStream,
|
|
463
|
+
.code_offset => return .{
|
|
464
|
+
.code_offset = try expect(takePackedU32(reader)),
|
|
465
|
+
},
|
|
466
|
+
.change_code_offset_base => return .{
|
|
467
|
+
.change_code_offset_base = try expect(takePackedU32(reader)),
|
|
468
|
+
},
|
|
469
|
+
.change_code_offset => return .{
|
|
470
|
+
.change_code_offset = try expect(takePackedU32(reader)),
|
|
471
|
+
},
|
|
472
|
+
.change_code_length => return .{
|
|
473
|
+
.change_code_length = try expect(takePackedU32(reader)),
|
|
474
|
+
},
|
|
475
|
+
.change_file => return .{
|
|
476
|
+
.change_file = try expect(takePackedU32(reader)),
|
|
477
|
+
},
|
|
478
|
+
.change_line_offset => return .{
|
|
479
|
+
.change_line_offset = try expect(takePackedI32(reader)),
|
|
480
|
+
},
|
|
481
|
+
.change_line_end_delta => return .{
|
|
482
|
+
.change_line_end_delta = try expect(takePackedU32(reader)),
|
|
483
|
+
},
|
|
484
|
+
.change_range_kind => return .{
|
|
485
|
+
.change_range_kind = std.enums.fromInt(
|
|
486
|
+
RangeKind,
|
|
487
|
+
try expect(takePackedU32(reader)),
|
|
488
|
+
) orelse return error.ReadFailed,
|
|
489
|
+
},
|
|
490
|
+
.change_column_start => return .{
|
|
491
|
+
.change_column_start = try expect(takePackedU32(reader)),
|
|
492
|
+
},
|
|
493
|
+
.change_column_end_delta => return .{
|
|
494
|
+
.change_column_end_delta = try expect(takePackedI32(reader)),
|
|
495
|
+
},
|
|
496
|
+
.change_code_offset_and_line_offset => {
|
|
497
|
+
const EncodedArgs = packed struct(u32) {
|
|
498
|
+
code_delta: u4,
|
|
499
|
+
encoded_line_delta: u28,
|
|
500
|
+
};
|
|
501
|
+
const args: EncodedArgs = @bitCast(try expect(takePackedU32(reader)));
|
|
502
|
+
return .{
|
|
503
|
+
.change_code_offset_and_line_offset = .{
|
|
504
|
+
.code_delta = args.code_delta,
|
|
505
|
+
.line_delta = decodeI32(args.encoded_line_delta),
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
},
|
|
509
|
+
.change_code_length_and_code_offset => return .{
|
|
510
|
+
.change_code_length_and_code_offset = .{
|
|
511
|
+
.length = try expect(takePackedU32(reader)),
|
|
512
|
+
.delta = try expect(takePackedU32(reader)),
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
.change_column_end => return .{
|
|
516
|
+
.change_column_end = try expect(takePackedU32(reader)),
|
|
517
|
+
},
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Adapted from:
|
|
522
|
+
// https://github.com/microsoft/microsoft-pdb/blob/805655a28bd8198004be2ac27e6e0290121a5e89/include/cvinfo.h#L4942
|
|
523
|
+
pub fn takePackedU32(reader: *Io.Reader) Io.Reader.Error!u32 {
|
|
524
|
+
const b0: u32 = try reader.takeByte();
|
|
525
|
+
if (b0 & 0x80 == 0x00) return b0;
|
|
526
|
+
|
|
527
|
+
const b1: u32 = try reader.takeByte();
|
|
528
|
+
if (b0 & 0xC0 == 0x80) return ((b0 & 0x3F) << 8) | b1;
|
|
235
529
|
|
|
530
|
+
const b2: u32 = try reader.takeByte();
|
|
531
|
+
const b3: u32 = try reader.takeByte();
|
|
532
|
+
if (b0 & 0xE0 == 0xC0) return ((b0 & 0x1f) << 24) | (b1 << 16) | (b2 << 8) | b3;
|
|
533
|
+
|
|
534
|
+
return error.ReadFailed;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
pub fn takePackedI32(reader: *Io.Reader) Io.Reader.Error!i32 {
|
|
538
|
+
return decodeI32(try takePackedU32(reader));
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
pub fn decodeI32(u: u32) i32 {
|
|
542
|
+
const i: i32 = @bitCast(u);
|
|
543
|
+
if (i & 1 != 0) {
|
|
544
|
+
return -(i >> 1);
|
|
545
|
+
} else {
|
|
546
|
+
return i >> 1;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
fn expect(value: anytype) error{ReadFailed}!@typeInfo(@TypeOf(value)).error_union.payload {
|
|
551
|
+
comptime assert(@typeInfo(@TypeOf(value)).error_union.error_set == Io.Reader.Error);
|
|
552
|
+
return value catch error.ReadFailed;
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
pub fn findInlineeName(self: *const Pdb, inlinee: u32) ?[]const u8 {
|
|
557
|
+
// According to LLVM, the high bit *can* be used to indicate that a type index comes from the
|
|
558
|
+
// ipi stream in which case that bit needs to be cleared. LLVM doesn't generate data in this
|
|
559
|
+
// manner, but we may as well handle it since it just involves a single bitwise and.
|
|
560
|
+
// https://llvm.org/docs/PDB/TpiStream.html#type-indices
|
|
561
|
+
const type_index = inlinee & 0x7FFFFFFF;
|
|
562
|
+
|
|
563
|
+
var reader: Io.Reader = .fixed(self.ipi orelse return null);
|
|
564
|
+
const header = reader.takeStructPointer(pdb.IpiStreamHeader) catch return null;
|
|
565
|
+
for (header.type_index_begin..header.type_index_end) |curr_type_index| {
|
|
566
|
+
const prefix = reader.takeStructPointer(pdb.LfRecordPrefix) catch return null;
|
|
567
|
+
if (prefix.len < 2) return null;
|
|
568
|
+
reader.discardAll(prefix.len - @sizeOf(u16)) catch return null;
|
|
569
|
+
|
|
570
|
+
if (curr_type_index == type_index) {
|
|
571
|
+
switch (prefix.kind) {
|
|
572
|
+
.func_id => {
|
|
573
|
+
const func: *align(1) pdb.LfFuncId = @ptrCast(prefix);
|
|
574
|
+
return std.mem.sliceTo(@as([*:0]const u8, @ptrCast(&func.name[0])), 0);
|
|
575
|
+
},
|
|
576
|
+
.mfunc_id => {
|
|
577
|
+
const func: *align(1) pdb.LfMFuncId = @ptrCast(prefix);
|
|
578
|
+
return std.mem.sliceTo(@as([*:0]const u8, @ptrCast(&func.name[0])), 0);
|
|
579
|
+
},
|
|
580
|
+
else => return null,
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
pub fn getInlinees(self: *Pdb, module: *Module, proc_sym: *align(1) const pdb.ProcSym) InlineSiteSymIterator {
|
|
588
|
+
const module_index = module - self.modules.ptr;
|
|
589
|
+
const offset = @intFromPtr(proc_sym) -
|
|
590
|
+
@intFromPtr(module.symbols.ptr) +
|
|
591
|
+
proc_sym.record_len +
|
|
592
|
+
@sizeOf(u16);
|
|
593
|
+
const symbols_end = @intFromPtr(module.symbols.ptr) + module.symbols.len;
|
|
594
|
+
if (offset > symbols_end or proc_sym.end > symbols_end) return .empty;
|
|
595
|
+
return .{
|
|
596
|
+
.module_index = module_index,
|
|
597
|
+
.offset = offset,
|
|
598
|
+
.end = proc_sym.end,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
pub fn getBinaryAnnotations(self: *Pdb, module: *Module, site: *align(1) const pdb.InlineSiteSym) BinaryAnnotation.Iterator {
|
|
603
|
+
_ = self;
|
|
604
|
+
var start: usize = @intFromPtr(site) + @sizeOf(pdb.InlineSiteSym);
|
|
605
|
+
var end = start + site.record_len + @sizeOf(u16) - @sizeOf(pdb.InlineSiteSym);
|
|
606
|
+
switch (site.record_kind) {
|
|
607
|
+
.inlinesite => {},
|
|
608
|
+
.inlinesite2 => start += @sizeOf(pdb.InlineSiteSym2) - @sizeOf(pdb.InlineSiteSym),
|
|
609
|
+
else => end = start,
|
|
610
|
+
}
|
|
611
|
+
if (start < @intFromPtr(module.symbols.ptr) or end > @intFromPtr(module.symbols.ptr) + module.symbols.len) return .empty;
|
|
612
|
+
const len = end - start;
|
|
613
|
+
const ptr: [*]const u8 = @ptrFromInt(start);
|
|
614
|
+
const slice = ptr[0..len];
|
|
615
|
+
return .{ .reader = Io.Reader.fixed(slice) };
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
pub fn getInlineSiteSourceLocation(
|
|
619
|
+
self: *Pdb,
|
|
620
|
+
gpa: Allocator,
|
|
621
|
+
mod: *Module,
|
|
622
|
+
site: *align(1) const pdb.InlineSiteSym,
|
|
623
|
+
inlinee_src_line: *align(1) const pdb.InlineeSourceLine,
|
|
624
|
+
offset_in_func: usize,
|
|
625
|
+
) !?std.debug.SourceLocation {
|
|
626
|
+
var ranges: BinaryAnnotation.RangeIterator = .init(self.getBinaryAnnotations(mod, site));
|
|
627
|
+
while (try ranges.next()) |range| {
|
|
628
|
+
if (!range.contains(offset_in_func)) continue;
|
|
629
|
+
|
|
630
|
+
const file_id = range.file_id orelse inlinee_src_line.file_id;
|
|
631
|
+
const file_name = try self.getFileName(gpa, mod, file_id);
|
|
632
|
+
errdefer self.allocator.free(file_name);
|
|
633
|
+
|
|
634
|
+
return .{
|
|
635
|
+
.line = inlinee_src_line.source_line_num +% @as(u32, @bitCast(range.line_offset)),
|
|
636
|
+
// LLVM doesn't currently emit column information for inlined calls in PDBs.
|
|
637
|
+
.column = 0,
|
|
638
|
+
.file_name = file_name,
|
|
639
|
+
};
|
|
640
|
+
}
|
|
236
641
|
return null;
|
|
237
642
|
}
|
|
238
643
|
|
|
239
|
-
pub fn
|
|
644
|
+
pub fn getFileName(self: *Pdb, gpa: Allocator, mod: *Module, file_id: u32) ![]const u8 {
|
|
645
|
+
const checksum_offset = mod.checksum_offset orelse return error.MissingDebugInfo;
|
|
646
|
+
const subsect_index = checksum_offset + file_id;
|
|
647
|
+
const chksum_hdr: *align(1) pdb.FileChecksumEntryHeader = @ptrCast(&mod.subsect_info[subsect_index]);
|
|
648
|
+
const strtab_offset = @sizeOf(pdb.StringTableHeader) + chksum_hdr.file_name_offset;
|
|
649
|
+
self.string_table.?.seekTo(strtab_offset) catch return error.InvalidDebugInfo;
|
|
650
|
+
const string_reader = &self.string_table.?.interface;
|
|
651
|
+
var source_file_name: Io.Writer.Allocating = .init(gpa);
|
|
652
|
+
defer source_file_name.deinit();
|
|
653
|
+
_ = try string_reader.streamDelimiterLimit(&source_file_name.writer, 0, .limited(1024));
|
|
654
|
+
assert(string_reader.buffered()[0] == 0); // TODO change streamDelimiterLimit API
|
|
655
|
+
string_reader.toss(1);
|
|
656
|
+
return try source_file_name.toOwnedSlice();
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
pub fn getSymbolName(self: *Pdb, proc_sym: *align(1) const pdb.ProcSym) []const u8 {
|
|
660
|
+
_ = self;
|
|
661
|
+
return std.mem.sliceTo(@as([*:0]const u8, @ptrCast(&proc_sym.name[0])), 0);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
pub const InlineeSourceLine = struct {
|
|
665
|
+
signature: pdb.InlineeSourceLineSignature,
|
|
666
|
+
info: *align(1) const pdb.InlineeSourceLine,
|
|
667
|
+
|
|
668
|
+
fn lessThan(_: void, lhs: InlineeSourceLine, rhs: InlineeSourceLine) bool {
|
|
669
|
+
return lhs.info.inlinee < rhs.info.inlinee;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
fn compare(inlinee: u32, self: InlineeSourceLine) std.math.Order {
|
|
673
|
+
return std.math.order(inlinee, self.info.inlinee);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
/// Returns all `InlineeSourceLine`s for a given module with the given inlinee. Ideally there would
|
|
678
|
+
/// only be one entry per inlinee, but LLVM appears to assign all functions that share a name the
|
|
679
|
+
/// same inlinee ID. This appears to be a bug, so the best the caller can do right now is print all
|
|
680
|
+
/// the results.
|
|
681
|
+
pub fn getInlineeSourceLines(
|
|
682
|
+
self: *Pdb,
|
|
683
|
+
mod: *Module,
|
|
684
|
+
inlinee: u32,
|
|
685
|
+
) []const InlineeSourceLine {
|
|
686
|
+
_ = self;
|
|
687
|
+
|
|
688
|
+
// Binary search to an arbitrary match, if there are other matches they will be adjacent
|
|
689
|
+
const any = std.sort.binarySearch(
|
|
690
|
+
InlineeSourceLine,
|
|
691
|
+
mod.inlinee_source_lines,
|
|
692
|
+
inlinee,
|
|
693
|
+
InlineeSourceLine.compare,
|
|
694
|
+
) orelse return &.{};
|
|
695
|
+
|
|
696
|
+
// Linearly scan to the first match
|
|
697
|
+
const begin = b: {
|
|
698
|
+
var begin = any;
|
|
699
|
+
while (begin > 0) {
|
|
700
|
+
const prev = begin - 1;
|
|
701
|
+
if (mod.inlinee_source_lines[prev].info.inlinee != inlinee) break;
|
|
702
|
+
begin = prev;
|
|
703
|
+
}
|
|
704
|
+
break :b begin;
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
// Linearly scan to the last match
|
|
708
|
+
const end = b: {
|
|
709
|
+
var end = any + 1;
|
|
710
|
+
while (end < mod.inlinee_source_lines.len and
|
|
711
|
+
mod.inlinee_source_lines[end].info.inlinee == inlinee) : (end += 1)
|
|
712
|
+
{}
|
|
713
|
+
break :b end;
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
// Return a slice of all the matches
|
|
717
|
+
return mod.inlinee_source_lines[begin..end];
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
pub fn getLineNumberInfo(self: *Pdb, gpa: Allocator, module: *Module, address: u64) !std.debug.SourceLocation {
|
|
240
721
|
std.debug.assert(module.populated);
|
|
241
722
|
const subsect_info = module.subsect_info;
|
|
242
|
-
const gpa = self.allocator;
|
|
243
723
|
|
|
244
724
|
var sect_offset: usize = 0;
|
|
245
725
|
var skip_len: usize = undefined;
|
|
246
|
-
const checksum_offset = module.checksum_offset orelse return error.MissingDebugInfo;
|
|
247
726
|
while (sect_offset != subsect_info.len) : (sect_offset += skip_len) {
|
|
248
727
|
const subsect_hdr: *align(1) pdb.DebugSubsectionHeader = @ptrCast(&subsect_info[sect_offset]);
|
|
249
728
|
skip_len = subsect_hdr.length;
|
|
@@ -290,20 +769,8 @@ pub fn getLineNumberInfo(self: *Pdb, module: *Module, address: u64) !std.debug.S
|
|
|
290
769
|
|
|
291
770
|
// line_i == 0 would mean that no matching pdb.LineNumberEntry was found.
|
|
292
771
|
if (line_i > 0) {
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
const strtab_offset = @sizeOf(pdb.StringTableHeader) + chksum_hdr.file_name_offset;
|
|
296
|
-
try self.string_table.?.seekTo(strtab_offset);
|
|
297
|
-
const source_file_name = s: {
|
|
298
|
-
const string_reader = &self.string_table.?.interface;
|
|
299
|
-
var source_file_name: std.Io.Writer.Allocating = .init(gpa);
|
|
300
|
-
defer source_file_name.deinit();
|
|
301
|
-
_ = try string_reader.streamDelimiterLimit(&source_file_name.writer, 0, .limited(1024));
|
|
302
|
-
assert(string_reader.buffered()[0] == 0); // TODO change streamDelimiterLimit API
|
|
303
|
-
string_reader.toss(1);
|
|
304
|
-
break :s try source_file_name.toOwnedSlice();
|
|
305
|
-
};
|
|
306
|
-
errdefer gpa.free(source_file_name);
|
|
772
|
+
const file_name = try self.getFileName(gpa, module, block_hdr.name_index);
|
|
773
|
+
errdefer gpa.free(file_name);
|
|
307
774
|
|
|
308
775
|
const line_entry_idx = line_i - 1;
|
|
309
776
|
|
|
@@ -318,7 +785,7 @@ pub fn getLineNumberInfo(self: *Pdb, module: *Module, address: u64) !std.debug.S
|
|
|
318
785
|
const line_num_entry: *align(1) pdb.LineNumberEntry = @ptrCast(&subsect_info[found_line_index]);
|
|
319
786
|
|
|
320
787
|
return .{
|
|
321
|
-
.file_name =
|
|
788
|
+
.file_name = file_name,
|
|
322
789
|
.line = line_num_entry.flags.start,
|
|
323
790
|
.column = column,
|
|
324
791
|
};
|
|
@@ -366,7 +833,43 @@ pub fn getModule(self: *Pdb, index: usize) !?*Module {
|
|
|
366
833
|
const gpa = self.allocator;
|
|
367
834
|
|
|
368
835
|
mod.symbols = try reader.readAlloc(gpa, mod.mod_info.sym_byte_size - 4);
|
|
836
|
+
errdefer gpa.free(mod.symbols);
|
|
369
837
|
mod.subsect_info = try reader.readAlloc(gpa, mod.mod_info.c13_byte_size);
|
|
838
|
+
errdefer gpa.free(mod.subsect_info);
|
|
839
|
+
mod.inlinee_source_lines = b: {
|
|
840
|
+
var inlinee_source_lines: std.ArrayList(InlineeSourceLine) = .empty;
|
|
841
|
+
defer inlinee_source_lines.deinit(gpa);
|
|
842
|
+
var subsects: Io.Reader = .fixed(mod.subsect_info);
|
|
843
|
+
while (subsects.takeStructPointer(pdb.DebugSubsectionHeader) catch null) |subsect_hdr| {
|
|
844
|
+
var subsect: Io.Reader = .fixed(subsects.take(subsect_hdr.length) catch return null);
|
|
845
|
+
if (subsect_hdr.kind == .inlinee_lines) {
|
|
846
|
+
const inlinee_source_line_signature = subsect.takeEnum(pdb.InlineeSourceLineSignature, .little) catch return error.InvalidDebugInfo;
|
|
847
|
+
const has_extra_files = switch (inlinee_source_line_signature) {
|
|
848
|
+
.normal => false,
|
|
849
|
+
.ex => true,
|
|
850
|
+
else => continue,
|
|
851
|
+
};
|
|
852
|
+
while (subsect.takeStructPointer(pdb.InlineeSourceLine) catch null) |info| {
|
|
853
|
+
if (has_extra_files) {
|
|
854
|
+
const file_count = subsect.takeInt(u32, .little) catch
|
|
855
|
+
return error.InvalidDebugInfo;
|
|
856
|
+
const file_bytes = std.math.mul(usize, file_count, @sizeOf(u32)) catch return error.InvalidDebugInfo;
|
|
857
|
+
subsect.discardAll(file_bytes) catch
|
|
858
|
+
return error.InvalidDebugInfo;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
try inlinee_source_lines.append(gpa, .{
|
|
862
|
+
.signature = inlinee_source_line_signature,
|
|
863
|
+
.info = info,
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
std.mem.sortUnstable(InlineeSourceLine, inlinee_source_lines.items, {}, InlineeSourceLine.lessThan);
|
|
870
|
+
break :b try inlinee_source_lines.toOwnedSlice(gpa);
|
|
871
|
+
};
|
|
872
|
+
errdefer gpa.free(mod.inlinee_source_lines);
|
|
370
873
|
|
|
371
874
|
var sect_offset: usize = 0;
|
|
372
875
|
var skip_len: usize = undefined;
|
|
@@ -497,7 +1000,7 @@ const MsfStream = struct {
|
|
|
497
1000
|
next_read_pos: u64,
|
|
498
1001
|
blocks: []u32,
|
|
499
1002
|
block_size: u32,
|
|
500
|
-
interface:
|
|
1003
|
+
interface: Io.Reader,
|
|
501
1004
|
err: ?Error,
|
|
502
1005
|
|
|
503
1006
|
const Error = File.Reader.SeekError;
|
|
@@ -527,7 +1030,7 @@ const MsfStream = struct {
|
|
|
527
1030
|
};
|
|
528
1031
|
}
|
|
529
1032
|
|
|
530
|
-
fn stream(r: *
|
|
1033
|
+
fn stream(r: *Io.Reader, w: *Io.Writer, limit: Io.Limit) Io.Reader.StreamError!usize {
|
|
531
1034
|
const ms: *MsfStream = @alignCast(@fieldParentPtr("interface", r));
|
|
532
1035
|
|
|
533
1036
|
var block_id: usize = @intCast(ms.next_read_pos / ms.block_size);
|
|
@@ -595,7 +1098,7 @@ const MsfStream = struct {
|
|
|
595
1098
|
}
|
|
596
1099
|
};
|
|
597
1100
|
|
|
598
|
-
fn readSparseBitVector(reader: *
|
|
1101
|
+
fn readSparseBitVector(reader: *Io.Reader, allocator: Allocator) ![]u32 {
|
|
599
1102
|
const num_words = try reader.takeInt(u32, .little);
|
|
600
1103
|
var list = std.array_list.Managed(u32).init(allocator);
|
|
601
1104
|
errdefer list.deinit();
|