Merge pull request #21323 from jacobly0/dwarf-decls

Dwarf: implement more decls
This commit is contained in:
Jacob Young 2024-09-10 17:31:06 -04:00 committed by GitHub
commit 8ec68c63fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 1354 additions and 695 deletions

View File

@ -64,7 +64,7 @@ stage3-debug/bin/zig build \
stage3-debug/bin/zig build test docs \ stage3-debug/bin/zig build test docs \
--maxrss 21000000000 \ --maxrss 21000000000 \
-Dlldb=$HOME/deps/lldb-zig/Debug-befcd57a8/bin/lldb \ -Dlldb=$HOME/deps/lldb-zig/Debug-4a44163df/bin/lldb \
-fqemu \ -fqemu \
-fwasmtime \ -fwasmtime \
-Dstatic-llvm \ -Dstatic-llvm \

View File

@ -64,7 +64,7 @@ stage3-release/bin/zig build \
stage3-release/bin/zig build test docs \ stage3-release/bin/zig build test docs \
--maxrss 21000000000 \ --maxrss 21000000000 \
-Dlldb=$HOME/deps/lldb-zig/Release-befcd57a8/bin/lldb \ -Dlldb=$HOME/deps/lldb-zig/Release-4a44163df/bin/lldb \
-fqemu \ -fqemu \
-fwasmtime \ -fwasmtime \
-Dstatic-llvm \ -Dstatic-llvm \

View File

@ -1767,9 +1767,11 @@ pub fn HashMapUnmanaged(
} }
comptime { comptime {
if (!builtin.strip_debug_info) { if (!builtin.strip_debug_info) _ = switch (builtin.zig_backend) {
_ = &dbHelper; .stage2_llvm => &dbHelper,
} .stage2_x86_64 => KV,
else => {},
};
} }
}; };
} }

View File

@ -573,7 +573,7 @@ pub fn MultiArrayList(comptime T: type) type {
} }
comptime { comptime {
if (!builtin.strip_debug_info) { if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {
_ = &dbHelper; _ = &dbHelper;
_ = &Slice.dbHelper; _ = &Slice.dbHelper;
} }

View File

@ -4723,7 +4723,7 @@ pub const Index = enum(u32) {
} }
comptime { comptime {
if (!builtin.strip_debug_info) { if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {
_ = &dbHelper; _ = &dbHelper;
} }
} }

View File

@ -25,7 +25,6 @@ const Alignment = InternPool.Alignment;
const CodeGenError = codegen.CodeGenError; const CodeGenError = codegen.CodeGenError;
const Result = codegen.Result; const Result = codegen.Result;
const DebugInfoOutput = codegen.DebugInfoOutput;
const bits = @import("bits.zig"); const bits = @import("bits.zig");
const abi = @import("abi.zig"); const abi = @import("abi.zig");
@ -48,7 +47,7 @@ pt: Zcu.PerThread,
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
bin_file: *link.File, bin_file: *link.File,
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
target: *const std.Target, target: *const std.Target,
func_index: InternPool.Index, func_index: InternPool.Index,
owner_nav: InternPool.Nav.Index, owner_nav: InternPool.Nav.Index,
@ -327,7 +326,7 @@ pub fn generate(
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
) CodeGenError!Result { ) CodeGenError!Result {
const zcu = pt.zcu; const zcu = pt.zcu;
const gpa = zcu.gpa; const gpa = zcu.gpa;

View File

@ -13,11 +13,10 @@ const assert = std.debug.assert;
const Instruction = bits.Instruction; const Instruction = bits.Instruction;
const Register = bits.Register; const Register = bits.Register;
const log = std.log.scoped(.aarch64_emit); const log = std.log.scoped(.aarch64_emit);
const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
mir: Mir, mir: Mir,
bin_file: *link.File, bin_file: *link.File,
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
target: *const std.Target, target: *const std.Target,
err_msg: ?*ErrorMsg = null, err_msg: ?*ErrorMsg = null,
src_loc: Zcu.LazySrcLoc, src_loc: Zcu.LazySrcLoc,

View File

@ -25,7 +25,6 @@ const Alignment = InternPool.Alignment;
const Result = codegen.Result; const Result = codegen.Result;
const CodeGenError = codegen.CodeGenError; const CodeGenError = codegen.CodeGenError;
const DebugInfoOutput = codegen.DebugInfoOutput;
const bits = @import("bits.zig"); const bits = @import("bits.zig");
const abi = @import("abi.zig"); const abi = @import("abi.zig");
@ -49,7 +48,7 @@ pt: Zcu.PerThread,
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
bin_file: *link.File, bin_file: *link.File,
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
target: *const std.Target, target: *const std.Target,
func_index: InternPool.Index, func_index: InternPool.Index,
err_msg: ?*ErrorMsg, err_msg: ?*ErrorMsg,
@ -335,7 +334,7 @@ pub fn generate(
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
) CodeGenError!Result { ) CodeGenError!Result {
const zcu = pt.zcu; const zcu = pt.zcu;
const gpa = zcu.gpa; const gpa = zcu.gpa;

View File

@ -16,12 +16,11 @@ const assert = std.debug.assert;
const Instruction = bits.Instruction; const Instruction = bits.Instruction;
const Register = bits.Register; const Register = bits.Register;
const log = std.log.scoped(.aarch32_emit); const log = std.log.scoped(.aarch32_emit);
const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
const CodeGen = @import("CodeGen.zig"); const CodeGen = @import("CodeGen.zig");
mir: Mir, mir: Mir,
bin_file: *link.File, bin_file: *link.File,
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
target: *const std.Target, target: *const std.Target,
err_msg: ?*ErrorMsg = null, err_msg: ?*ErrorMsg = null,
src_loc: Zcu.LazySrcLoc, src_loc: Zcu.LazySrcLoc,

View File

@ -32,7 +32,6 @@ const Alignment = InternPool.Alignment;
const CodeGenError = codegen.CodeGenError; const CodeGenError = codegen.CodeGenError;
const Result = codegen.Result; const Result = codegen.Result;
const DebugInfoOutput = codegen.DebugInfoOutput;
const bits = @import("bits.zig"); const bits = @import("bits.zig");
const abi = @import("abi.zig"); const abi = @import("abi.zig");
@ -61,7 +60,7 @@ gpa: Allocator,
mod: *Package.Module, mod: *Package.Module,
target: *const std.Target, target: *const std.Target,
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
err_msg: ?*ErrorMsg, err_msg: ?*ErrorMsg,
args: []MCValue, args: []MCValue,
ret_mcv: InstTracking, ret_mcv: InstTracking,
@ -760,7 +759,7 @@ pub fn generate(
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
) CodeGenError!Result { ) CodeGenError!Result {
const zcu = pt.zcu; const zcu = pt.zcu;
const comp = zcu.comp; const comp = zcu.comp;
@ -928,7 +927,7 @@ pub fn generateLazy(
src_loc: Zcu.LazySrcLoc, src_loc: Zcu.LazySrcLoc,
lazy_sym: link.File.LazySymbol, lazy_sym: link.File.LazySymbol,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
) CodeGenError!Result { ) CodeGenError!Result {
const comp = bin_file.comp; const comp = bin_file.comp;
const gpa = comp.gpa; const gpa = comp.gpa;

View File

@ -2,7 +2,7 @@
bin_file: *link.File, bin_file: *link.File,
lower: Lower, lower: Lower,
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
prev_di_line: u32, prev_di_line: u32,
@ -216,7 +216,6 @@ const log = std.log.scoped(.emit);
const mem = std.mem; const mem = std.mem;
const std = @import("std"); const std = @import("std");
const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
const Emit = @This(); const Emit = @This();
const Lower = @import("Lower.zig"); const Lower = @import("Lower.zig");
const Mir = @import("Mir.zig"); const Mir = @import("Mir.zig");

View File

@ -22,7 +22,6 @@ const Liveness = @import("../../Liveness.zig");
const Type = @import("../../Type.zig"); const Type = @import("../../Type.zig");
const CodeGenError = codegen.CodeGenError; const CodeGenError = codegen.CodeGenError;
const Result = @import("../../codegen.zig").Result; const Result = @import("../../codegen.zig").Result;
const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
const Endian = std.builtin.Endian; const Endian = std.builtin.Endian;
const Alignment = InternPool.Alignment; const Alignment = InternPool.Alignment;
@ -57,7 +56,7 @@ bin_file: *link.File,
target: *const std.Target, target: *const std.Target,
func_index: InternPool.Index, func_index: InternPool.Index,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
err_msg: ?*ErrorMsg, err_msg: ?*ErrorMsg,
args: []MCValue, args: []MCValue,
ret_mcv: MCValue, ret_mcv: MCValue,
@ -268,7 +267,7 @@ pub fn generate(
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
) CodeGenError!Result { ) CodeGenError!Result {
const zcu = pt.zcu; const zcu = pt.zcu;
const gpa = zcu.gpa; const gpa = zcu.gpa;

View File

@ -9,7 +9,6 @@ const Zcu = @import("../../Zcu.zig");
const ErrorMsg = Zcu.ErrorMsg; const ErrorMsg = Zcu.ErrorMsg;
const Liveness = @import("../../Liveness.zig"); const Liveness = @import("../../Liveness.zig");
const log = std.log.scoped(.sparcv9_emit); const log = std.log.scoped(.sparcv9_emit);
const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
const Emit = @This(); const Emit = @This();
const Mir = @import("Mir.zig"); const Mir = @import("Mir.zig");
@ -19,7 +18,7 @@ const Register = bits.Register;
mir: Mir, mir: Mir,
bin_file: *link.File, bin_file: *link.File,
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
target: *const std.Target, target: *const std.Target,
err_msg: ?*ErrorMsg = null, err_msg: ?*ErrorMsg = null,
src_loc: Zcu.LazySrcLoc, src_loc: Zcu.LazySrcLoc,

View File

@ -648,7 +648,7 @@ block_depth: u32 = 0,
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
gpa: mem.Allocator, gpa: mem.Allocator,
debug_output: codegen.DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
func_index: InternPool.Index, func_index: InternPool.Index,
/// Contains a list of current branches. /// Contains a list of current branches.
/// When we return from a branch, the branch will be popped from this list, /// When we return from a branch, the branch will be popped from this list,
@ -1211,7 +1211,7 @@ pub fn generate(
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: codegen.DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
) codegen.CodeGenError!codegen.Result { ) codegen.CodeGenError!codegen.Result {
const zcu = pt.zcu; const zcu = pt.zcu;
const gpa = zcu.gpa; const gpa = zcu.gpa;

View File

@ -26,7 +26,7 @@ owner_nav: InternPool.Nav.Index,
// Debug information // Debug information
/// Holds the debug information for this emission /// Holds the debug information for this emission
dbg_output: codegen.DebugInfoOutput, dbg_output: link.File.DebugInfoOutput,
/// Previous debug info line /// Previous debug info line
prev_di_line: u32, prev_di_line: u32,
/// Previous debug info column /// Previous debug info column

View File

@ -17,7 +17,6 @@ const Air = @import("../../Air.zig");
const Allocator = mem.Allocator; const Allocator = mem.Allocator;
const CodeGenError = codegen.CodeGenError; const CodeGenError = codegen.CodeGenError;
const Compilation = @import("../../Compilation.zig"); const Compilation = @import("../../Compilation.zig");
const DebugInfoOutput = codegen.DebugInfoOutput;
const ErrorMsg = Zcu.ErrorMsg; const ErrorMsg = Zcu.ErrorMsg;
const Result = codegen.Result; const Result = codegen.Result;
const Emit = @import("Emit.zig"); const Emit = @import("Emit.zig");
@ -53,7 +52,7 @@ pt: Zcu.PerThread,
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
bin_file: *link.File, bin_file: *link.File,
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
target: *const std.Target, target: *const std.Target,
owner: Owner, owner: Owner,
inline_func: InternPool.Index, inline_func: InternPool.Index,
@ -819,7 +818,7 @@ pub fn generate(
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
) CodeGenError!Result { ) CodeGenError!Result {
const zcu = pt.zcu; const zcu = pt.zcu;
const comp = zcu.comp; const comp = zcu.comp;
@ -1000,7 +999,7 @@ pub fn generateLazy(
src_loc: Zcu.LazySrcLoc, src_loc: Zcu.LazySrcLoc,
lazy_sym: link.File.LazySymbol, lazy_sym: link.File.LazySymbol,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
) CodeGenError!Result { ) CodeGenError!Result {
const comp = bin_file.comp; const comp = bin_file.comp;
const gpa = comp.gpa; const gpa = comp.gpa;

View File

@ -3,7 +3,7 @@
air: Air, air: Air,
lower: Lower, lower: Lower,
atom_index: u32, atom_index: u32,
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
prev_di_line: u32, prev_di_line: u32,
@ -546,7 +546,6 @@ const log = std.log.scoped(.emit);
const std = @import("std"); const std = @import("std");
const Air = @import("../../Air.zig"); const Air = @import("../../Air.zig");
const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
const Emit = @This(); const Emit = @This();
const Lower = @import("Lower.zig"); const Lower = @import("Lower.zig");
const Mir = @import("Mir.zig"); const Mir = @import("Mir.zig");

View File

@ -38,12 +38,6 @@ pub const CodeGenError = error{
CodegenFail, CodegenFail,
} || link.File.UpdateDebugInfoError; } || link.File.UpdateDebugInfoError;
pub const DebugInfoOutput = union(enum) {
dwarf: *link.File.Dwarf.WipNav,
plan9: *link.File.Plan9.DebugInfoOutput,
none,
};
fn devFeatureForBackend(comptime backend: std.builtin.CompilerBackend) dev.Feature { fn devFeatureForBackend(comptime backend: std.builtin.CompilerBackend) dev.Feature {
comptime assert(mem.startsWith(u8, @tagName(backend), "stage2_")); comptime assert(mem.startsWith(u8, @tagName(backend), "stage2_"));
return @field(dev.Feature, @tagName(backend)["stage2_".len..] ++ "_backend"); return @field(dev.Feature, @tagName(backend)["stage2_".len..] ++ "_backend");
@ -69,7 +63,7 @@ pub fn generateFunction(
air: Air, air: Air,
liveness: Liveness, liveness: Liveness,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
) CodeGenError!Result { ) CodeGenError!Result {
const zcu = pt.zcu; const zcu = pt.zcu;
const func = zcu.funcInfo(func_index); const func = zcu.funcInfo(func_index);
@ -95,7 +89,7 @@ pub fn generateLazyFunction(
src_loc: Zcu.LazySrcLoc, src_loc: Zcu.LazySrcLoc,
lazy_sym: link.File.LazySymbol, lazy_sym: link.File.LazySymbol,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
) CodeGenError!Result { ) CodeGenError!Result {
const zcu = pt.zcu; const zcu = pt.zcu;
const file = Type.fromInterned(lazy_sym.ty).typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(&zcu.intern_pool); const file = Type.fromInterned(lazy_sym.ty).typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(&zcu.intern_pool);
@ -127,10 +121,10 @@ pub fn generateLazySymbol(
// TODO don't use an "out" parameter like this; put it in the result instead // TODO don't use an "out" parameter like this; put it in the result instead
alignment: *Alignment, alignment: *Alignment,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, debug_output: link.File.DebugInfoOutput,
reloc_info: RelocInfo, reloc_parent: link.File.RelocInfo.Parent,
) CodeGenError!Result { ) CodeGenError!Result {
_ = reloc_info; _ = reloc_parent;
const tracy = trace(@src()); const tracy = trace(@src());
defer tracy.end(); defer tracy.end();
@ -192,8 +186,7 @@ pub fn generateSymbol(
src_loc: Zcu.LazySrcLoc, src_loc: Zcu.LazySrcLoc,
val: Value, val: Value,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, reloc_parent: link.File.RelocInfo.Parent,
reloc_info: RelocInfo,
) CodeGenError!Result { ) CodeGenError!Result {
const tracy = trace(@src()); const tracy = trace(@src());
defer tracy.end(); defer tracy.end();
@ -290,7 +283,7 @@ pub fn generateSymbol(
switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(switch (error_union.val) { switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(switch (error_union.val) {
.err_name => try pt.intern(.{ .undef = payload_ty.toIntern() }), .err_name => try pt.intern(.{ .undef = payload_ty.toIntern() }),
.payload => |payload| payload, .payload => |payload| payload,
}), code, debug_output, reloc_info)) { }), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return .{ .fail = em }, .fail => |em| return .{ .fail = em },
} }
@ -318,7 +311,7 @@ pub fn generateSymbol(
}, },
.enum_tag => |enum_tag| { .enum_tag => |enum_tag| {
const int_tag_ty = ty.intTagType(zcu); const int_tag_ty = ty.intTagType(zcu);
switch (try generateSymbol(bin_file, pt, src_loc, try pt.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, try pt.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return .{ .fail = em }, .fail => |em| return .{ .fail = em },
} }
@ -334,16 +327,16 @@ pub fn generateSymbol(
}, },
.f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(16)), .f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(16)),
}, },
.ptr => switch (try lowerPtr(bin_file, pt, src_loc, val.toIntern(), code, debug_output, reloc_info, 0)) { .ptr => switch (try lowerPtr(bin_file, pt, src_loc, val.toIntern(), code, reloc_parent, 0)) {
.ok => {}, .ok => {},
.fail => |em| return .{ .fail = em }, .fail => |em| return .{ .fail = em },
}, },
.slice => |slice| { .slice => |slice| {
switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(slice.ptr), code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(slice.ptr), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return .{ .fail = em }, .fail => |em| return .{ .fail = em },
} }
switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(slice.len), code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(slice.len), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return .{ .fail = em }, .fail => |em| return .{ .fail = em },
} }
@ -355,7 +348,7 @@ pub fn generateSymbol(
if (ty.optionalReprIsPayload(zcu)) { if (ty.optionalReprIsPayload(zcu)) {
if (payload_val) |value| { if (payload_val) |value| {
switch (try generateSymbol(bin_file, pt, src_loc, value, code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, value, code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return Result{ .fail = em }, .fail => |em| return Result{ .fail = em },
} }
@ -368,7 +361,7 @@ pub fn generateSymbol(
const value = payload_val orelse Value.fromInterned(try pt.intern(.{ const value = payload_val orelse Value.fromInterned(try pt.intern(.{
.undef = payload_type.toIntern(), .undef = payload_type.toIntern(),
})); }));
switch (try generateSymbol(bin_file, pt, src_loc, value, code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, value, code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return Result{ .fail = em }, .fail => |em| return Result{ .fail = em },
} }
@ -390,7 +383,7 @@ pub fn generateSymbol(
elem elem
else else
array_type.sentinel, array_type.sentinel,
}), code, debug_output, reloc_info)) { }), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return .{ .fail = em }, .fail => |em| return .{ .fail = em },
} }
@ -449,7 +442,7 @@ pub fn generateSymbol(
math.cast(usize, index) orelse return error.Overflow math.cast(usize, index) orelse return error.Overflow
], ],
.repeated_elem => |elem| elem, .repeated_elem => |elem| elem,
}), code, debug_output, reloc_info)) { }), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return .{ .fail = em }, .fail => |em| return .{ .fail = em },
} }
@ -482,7 +475,7 @@ pub fn generateSymbol(
.repeated_elem => |elem| elem, .repeated_elem => |elem| elem,
}; };
switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return Result{ .fail = em }, .fail => |em| return Result{ .fail = em },
} }
@ -524,7 +517,7 @@ pub fn generateSymbol(
return error.Overflow; return error.Overflow;
var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size); var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size);
defer tmp_list.deinit(); defer tmp_list.deinit();
switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), &tmp_list, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), &tmp_list, reloc_parent)) {
.ok => @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items), .ok => @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items),
.fail => |em| return Result{ .fail = em }, .fail => |em| return Result{ .fail = em },
} }
@ -559,7 +552,7 @@ pub fn generateSymbol(
) orelse return error.Overflow; ) orelse return error.Overflow;
if (padding > 0) try code.appendNTimes(0, padding); if (padding > 0) try code.appendNTimes(0, padding);
switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(field_val), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return Result{ .fail = em }, .fail => |em| return Result{ .fail = em },
} }
@ -583,12 +576,12 @@ pub fn generateSymbol(
const layout = ty.unionGetLayout(zcu); const layout = ty.unionGetLayout(zcu);
if (layout.payload_size == 0) { if (layout.payload_size == 0) {
return generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info); return generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, reloc_parent);
} }
// Check if we should store the tag first. // Check if we should store the tag first.
if (layout.tag_size > 0 and layout.tag_align.compare(.gte, layout.payload_align)) { if (layout.tag_size > 0 and layout.tag_align.compare(.gte, layout.payload_align)) {
switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return Result{ .fail = em }, .fail => |em| return Result{ .fail = em },
} }
@ -601,7 +594,7 @@ pub fn generateSymbol(
if (!field_ty.hasRuntimeBits(zcu)) { if (!field_ty.hasRuntimeBits(zcu)) {
try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow); try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow);
} else { } else {
switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return Result{ .fail = em }, .fail => |em| return Result{ .fail = em },
} }
@ -612,14 +605,14 @@ pub fn generateSymbol(
} }
} }
} else { } else {
switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return Result{ .fail = em }, .fail => |em| return Result{ .fail = em },
} }
} }
if (layout.tag_size > 0 and layout.tag_align.compare(.lt, layout.payload_align)) { if (layout.tag_size > 0 and layout.tag_align.compare(.lt, layout.payload_align)) {
switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info)) { switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, reloc_parent)) {
.ok => {}, .ok => {},
.fail => |em| return Result{ .fail = em }, .fail => |em| return Result{ .fail = em },
} }
@ -640,40 +633,29 @@ fn lowerPtr(
src_loc: Zcu.LazySrcLoc, src_loc: Zcu.LazySrcLoc,
ptr_val: InternPool.Index, ptr_val: InternPool.Index,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, reloc_parent: link.File.RelocInfo.Parent,
reloc_info: RelocInfo,
prev_offset: u64, prev_offset: u64,
) CodeGenError!Result { ) CodeGenError!Result {
const zcu = pt.zcu; const zcu = pt.zcu;
const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr; const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr;
const offset: u64 = prev_offset + ptr.byte_offset; const offset: u64 = prev_offset + ptr.byte_offset;
return switch (ptr.base_addr) { return switch (ptr.base_addr) {
.nav => |nav| try lowerNavRef(bin_file, pt, src_loc, nav, code, debug_output, reloc_info, offset), .nav => |nav| try lowerNavRef(bin_file, pt, src_loc, nav, code, reloc_parent, offset),
.uav => |uav| try lowerUavRef(bin_file, pt, src_loc, uav, code, debug_output, reloc_info, offset), .uav => |uav| try lowerUavRef(bin_file, pt, src_loc, uav, code, reloc_parent, offset),
.int => try generateSymbol(bin_file, pt, src_loc, try pt.intValue(Type.usize, offset), code, debug_output, reloc_info), .int => try generateSymbol(bin_file, pt, src_loc, try pt.intValue(Type.usize, offset), code, reloc_parent),
.eu_payload => |eu_ptr| try lowerPtr( .eu_payload => |eu_ptr| try lowerPtr(
bin_file, bin_file,
pt, pt,
src_loc, src_loc,
eu_ptr, eu_ptr,
code, code,
debug_output, reloc_parent,
reloc_info,
offset + errUnionPayloadOffset( offset + errUnionPayloadOffset(
Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu).errorUnionPayload(zcu), Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu).errorUnionPayload(zcu),
zcu, zcu,
), ),
), ),
.opt_payload => |opt_ptr| try lowerPtr( .opt_payload => |opt_ptr| try lowerPtr(bin_file, pt, src_loc, opt_ptr, code, reloc_parent, offset),
bin_file,
pt,
src_loc,
opt_ptr,
code,
debug_output,
reloc_info,
offset,
),
.field => |field| { .field => |field| {
const base_ptr = Value.fromInterned(field.base); const base_ptr = Value.fromInterned(field.base);
const base_ty = base_ptr.typeOf(zcu).childType(zcu); const base_ty = base_ptr.typeOf(zcu).childType(zcu);
@ -692,27 +674,21 @@ fn lowerPtr(
}, },
else => unreachable, else => unreachable,
}; };
return lowerPtr(bin_file, pt, src_loc, field.base, code, debug_output, reloc_info, offset + field_off); return lowerPtr(bin_file, pt, src_loc, field.base, code, reloc_parent, offset + field_off);
}, },
.arr_elem, .comptime_field, .comptime_alloc => unreachable, .arr_elem, .comptime_field, .comptime_alloc => unreachable,
}; };
} }
const RelocInfo = struct {
parent_atom_index: u32,
};
fn lowerUavRef( fn lowerUavRef(
lf: *link.File, lf: *link.File,
pt: Zcu.PerThread, pt: Zcu.PerThread,
src_loc: Zcu.LazySrcLoc, src_loc: Zcu.LazySrcLoc,
uav: InternPool.Key.Ptr.BaseAddr.Uav, uav: InternPool.Key.Ptr.BaseAddr.Uav,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, reloc_parent: link.File.RelocInfo.Parent,
reloc_info: RelocInfo,
offset: u64, offset: u64,
) CodeGenError!Result { ) CodeGenError!Result {
_ = debug_output;
const zcu = pt.zcu; const zcu = pt.zcu;
const ip = &zcu.intern_pool; const ip = &zcu.intern_pool;
const target = lf.comp.root_mod.resolved_target.result; const target = lf.comp.root_mod.resolved_target.result;
@ -735,7 +711,7 @@ fn lowerUavRef(
} }
const vaddr = try lf.getUavVAddr(uav_val, .{ const vaddr = try lf.getUavVAddr(uav_val, .{
.parent_atom_index = reloc_info.parent_atom_index, .parent = reloc_parent,
.offset = code.items.len, .offset = code.items.len,
.addend = @intCast(offset), .addend = @intCast(offset),
}); });
@ -756,12 +732,10 @@ fn lowerNavRef(
src_loc: Zcu.LazySrcLoc, src_loc: Zcu.LazySrcLoc,
nav_index: InternPool.Nav.Index, nav_index: InternPool.Nav.Index,
code: *std.ArrayList(u8), code: *std.ArrayList(u8),
debug_output: DebugInfoOutput, reloc_parent: link.File.RelocInfo.Parent,
reloc_info: RelocInfo,
offset: u64, offset: u64,
) CodeGenError!Result { ) CodeGenError!Result {
_ = src_loc; _ = src_loc;
_ = debug_output;
const zcu = pt.zcu; const zcu = pt.zcu;
const ip = &zcu.intern_pool; const ip = &zcu.intern_pool;
const target = zcu.navFileScope(nav_index).mod.resolved_target.result; const target = zcu.navFileScope(nav_index).mod.resolved_target.result;
@ -775,7 +749,7 @@ fn lowerNavRef(
} }
const vaddr = try lf.getNavVAddr(pt, nav_index, .{ const vaddr = try lf.getNavVAddr(pt, nav_index, .{
.parent_atom_index = reloc_info.parent_atom_index, .parent = reloc_parent,
.offset = code.items.len, .offset = code.items.len,
.addend = @intCast(offset), .addend = @intCast(offset),
}); });

View File

@ -330,6 +330,11 @@ pub const File = struct {
} }
} }
pub const DebugInfoOutput = union(enum) {
dwarf: *Dwarf.WipNav,
plan9: *Plan9.DebugInfoOutput,
none,
};
pub const UpdateDebugInfoError = Dwarf.UpdateError; pub const UpdateDebugInfoError = Dwarf.UpdateError;
pub const FlushDebugInfoError = Dwarf.FlushError; pub const FlushDebugInfoError = Dwarf.FlushError;
@ -673,9 +678,14 @@ pub const File = struct {
} }
pub const RelocInfo = struct { pub const RelocInfo = struct {
parent_atom_index: u32, parent: Parent,
offset: u64, offset: u64,
addend: u32, addend: u32,
pub const Parent = union(enum) {
atom_index: u32,
debug_output: DebugInfoOutput,
};
}; };
/// Get allocated `Nav`'s address in virtual memory. /// Get allocated `Nav`'s address in virtual memory.

View File

@ -1163,8 +1163,8 @@ fn lowerConst(
try self.setSymbolName(sym, name); try self.setSymbolName(sym, name);
sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_id + 1)); sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_id + 1));
const res = try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .none, .{ const res = try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .{
.parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, .atom_index = self.getAtom(atom_index).getSymbolIndex().?,
}); });
const code = switch (res) { const code = switch (res) {
.ok => code_buffer.items, .ok => code_buffer.items,
@ -1235,8 +1235,7 @@ pub fn updateNav(
zcu.navSrcLoc(nav_index), zcu.navSrcLoc(nav_index),
nav_init, nav_init,
&code_buffer, &code_buffer,
.none, .{ .atom_index = atom.getSymbolIndex().? },
.{ .parent_atom_index = atom.getSymbolIndex().? },
); );
const code = switch (res) { const code = switch (res) {
.ok => code_buffer.items, .ok => code_buffer.items,
@ -1284,7 +1283,7 @@ fn updateLazySymbolAtom(
&required_alignment, &required_alignment,
&code_buffer, &code_buffer,
.none, .none,
.{ .parent_atom_index = local_sym_index }, .{ .atom_index = local_sym_index },
); );
const code = switch (res) { const code = switch (res) {
.ok => code_buffer.items, .ok => code_buffer.items,
@ -1823,7 +1822,10 @@ pub fn getNavVAddr(
.@"extern" => |@"extern"| try self.getGlobalSymbol(nav.name.toSlice(ip), @"extern".lib_name.toSlice(ip)), .@"extern" => |@"extern"| try self.getGlobalSymbol(nav.name.toSlice(ip), @"extern".lib_name.toSlice(ip)),
else => self.getAtom(try self.getOrCreateAtomForNav(nav_index)).getSymbolIndex().?, else => self.getAtom(try self.getOrCreateAtomForNav(nav_index)).getSymbolIndex().?,
}; };
const atom_index = self.getAtomIndexForSymbol(.{ .sym_index = reloc_info.parent_atom_index, .file = null }).?; const atom_index = self.getAtomIndexForSymbol(.{
.sym_index = reloc_info.parent.atom_index,
.file = null,
}).?;
const target = SymbolWithLoc{ .sym_index = sym_index, .file = null }; const target = SymbolWithLoc{ .sym_index = sym_index, .file = null };
try Atom.addRelocation(self, atom_index, .{ try Atom.addRelocation(self, atom_index, .{
.type = .direct, .type = .direct,
@ -1901,7 +1903,10 @@ pub fn getUavVAddr(
const this_atom_index = self.uavs.get(uav).?.atom; const this_atom_index = self.uavs.get(uav).?.atom;
const sym_index = self.getAtom(this_atom_index).getSymbolIndex().?; const sym_index = self.getAtom(this_atom_index).getSymbolIndex().?;
const atom_index = self.getAtomIndexForSymbol(.{ .sym_index = reloc_info.parent_atom_index, .file = null }).?; const atom_index = self.getAtomIndexForSymbol(.{
.sym_index = reloc_info.parent.atom_index,
.file = null,
}).?;
const target = SymbolWithLoc{ .sym_index = sym_index, .file = null }; const target = SymbolWithLoc{ .sym_index = sym_index, .file = null };
try Atom.addRelocation(self, atom_index, .{ try Atom.addRelocation(self, atom_index, .{
.type = .direct, .type = .direct,

File diff suppressed because it is too large Load Diff

View File

@ -957,13 +957,26 @@ pub fn getNavVAddr(
}; };
const this_sym = self.symbol(this_sym_index); const this_sym = self.symbol(this_sym_index);
const vaddr = this_sym.address(.{}, elf_file); const vaddr = this_sym.address(.{}, elf_file);
const parent_atom = self.symbol(reloc_info.parent_atom_index).atom(elf_file).?; switch (reloc_info.parent) {
const r_type = relocation.encode(.abs, elf_file.getTarget().cpu.arch); .atom_index => |atom_index| {
try parent_atom.addReloc(elf_file.base.comp.gpa, .{ const parent_atom = self.symbol(atom_index).atom(elf_file).?;
.r_offset = reloc_info.offset, const r_type = relocation.encode(.abs, elf_file.getTarget().cpu.arch);
.r_info = (@as(u64, @intCast(this_sym_index)) << 32) | r_type, try parent_atom.addReloc(elf_file.base.comp.gpa, .{
.r_addend = reloc_info.addend, .r_offset = reloc_info.offset,
}, self); .r_info = (@as(u64, @intCast(this_sym_index)) << 32) | r_type,
.r_addend = reloc_info.addend,
}, self);
},
.debug_output => |debug_output| switch (debug_output) {
.dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
.source_off = @intCast(reloc_info.offset),
.target_sym = this_sym_index,
.target_off = reloc_info.addend,
}),
.plan9 => unreachable,
.none => unreachable,
},
}
return @intCast(vaddr); return @intCast(vaddr);
} }
@ -976,13 +989,26 @@ pub fn getUavVAddr(
const sym_index = self.uavs.get(uav).?.symbol_index; const sym_index = self.uavs.get(uav).?.symbol_index;
const sym = self.symbol(sym_index); const sym = self.symbol(sym_index);
const vaddr = sym.address(.{}, elf_file); const vaddr = sym.address(.{}, elf_file);
const parent_atom = self.symbol(reloc_info.parent_atom_index).atom(elf_file).?; switch (reloc_info.parent) {
const r_type = relocation.encode(.abs, elf_file.getTarget().cpu.arch); .atom_index => |atom_index| {
try parent_atom.addReloc(elf_file.base.comp.gpa, .{ const parent_atom = self.symbol(atom_index).atom(elf_file).?;
.r_offset = reloc_info.offset, const r_type = relocation.encode(.abs, elf_file.getTarget().cpu.arch);
.r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type, try parent_atom.addReloc(elf_file.base.comp.gpa, .{
.r_addend = reloc_info.addend, .r_offset = reloc_info.offset,
}, self); .r_info = (@as(u64, @intCast(sym_index)) << 32) | r_type,
.r_addend = reloc_info.addend,
}, self);
},
.debug_output => |debug_output| switch (debug_output) {
.dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
.source_off = @intCast(reloc_info.offset),
.target_sym = sym_index,
.target_off = reloc_info.addend,
}),
.plan9 => unreachable,
.none => unreachable,
},
}
return @intCast(vaddr); return @intCast(vaddr);
} }
@ -1600,15 +1626,13 @@ pub fn updateNav(
var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, nav_index, sym_index) else null; var debug_wip_nav = if (self.dwarf) |*dwarf| try dwarf.initWipNav(pt, nav_index, sym_index) else null;
defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit(); defer if (debug_wip_nav) |*wip_nav| wip_nav.deinit();
// TODO implement .debug_info for global variables
const res = try codegen.generateSymbol( const res = try codegen.generateSymbol(
&elf_file.base, &elf_file.base,
pt, pt,
zcu.navSrcLoc(nav_index), zcu.navSrcLoc(nav_index),
Value.fromInterned(nav_init), Value.fromInterned(nav_init),
&code_buffer, &code_buffer,
if (debug_wip_nav) |*wip_nav| .{ .dwarf = wip_nav } else .none, .{ .atom_index = sym_index },
.{ .parent_atom_index = sym_index },
); );
const code = switch (res) { const code = switch (res) {
@ -1691,7 +1715,7 @@ fn updateLazySymbol(
&required_alignment, &required_alignment,
&code_buffer, &code_buffer,
.none, .none,
.{ .parent_atom_index = symbol_index }, .{ .atom_index = symbol_index },
); );
const code = switch (res) { const code = switch (res) {
.ok => code_buffer.items, .ok => code_buffer.items,
@ -1780,8 +1804,7 @@ fn lowerConst(
src_loc, src_loc,
val, val,
&code_buffer, &code_buffer,
.{ .none = {} }, .{ .atom_index = sym_index },
.{ .parent_atom_index = sym_index },
); );
const code = switch (res) { const code = switch (res) {
.ok => code_buffer.items, .ok => code_buffer.items,

View File

@ -633,20 +633,33 @@ pub fn getNavVAddr(
}; };
const sym = self.symbols.items[sym_index]; const sym = self.symbols.items[sym_index];
const vaddr = sym.getAddress(.{}, macho_file); const vaddr = sym.getAddress(.{}, macho_file);
const parent_atom = self.symbols.items[reloc_info.parent_atom_index].getAtom(macho_file).?; switch (reloc_info.parent) {
try parent_atom.addReloc(macho_file, .{ .atom_index => |atom_index| {
.tag = .@"extern", const parent_atom = self.symbols.items[atom_index].getAtom(macho_file).?;
.offset = @intCast(reloc_info.offset), try parent_atom.addReloc(macho_file, .{
.target = sym_index, .tag = .@"extern",
.addend = reloc_info.addend, .offset = @intCast(reloc_info.offset),
.type = .unsigned, .target = sym_index,
.meta = .{ .addend = reloc_info.addend,
.pcrel = false, .type = .unsigned,
.has_subtractor = false, .meta = .{
.length = 3, .pcrel = false,
.symbolnum = @intCast(sym.nlist_idx), .has_subtractor = false,
.length = 3,
.symbolnum = @intCast(sym.nlist_idx),
},
});
}, },
}); .debug_output => |debug_output| switch (debug_output) {
.dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
.source_off = @intCast(reloc_info.offset),
.target_sym = sym_index,
.target_off = reloc_info.addend,
}),
.plan9 => unreachable,
.none => unreachable,
},
}
return vaddr; return vaddr;
} }
@ -659,20 +672,33 @@ pub fn getUavVAddr(
const sym_index = self.uavs.get(uav).?.symbol_index; const sym_index = self.uavs.get(uav).?.symbol_index;
const sym = self.symbols.items[sym_index]; const sym = self.symbols.items[sym_index];
const vaddr = sym.getAddress(.{}, macho_file); const vaddr = sym.getAddress(.{}, macho_file);
const parent_atom = self.symbols.items[reloc_info.parent_atom_index].getAtom(macho_file).?; switch (reloc_info.parent) {
try parent_atom.addReloc(macho_file, .{ .atom_index => |atom_index| {
.tag = .@"extern", const parent_atom = self.symbols.items[atom_index].getAtom(macho_file).?;
.offset = @intCast(reloc_info.offset), try parent_atom.addReloc(macho_file, .{
.target = sym_index, .tag = .@"extern",
.addend = reloc_info.addend, .offset = @intCast(reloc_info.offset),
.type = .unsigned, .target = sym_index,
.meta = .{ .addend = reloc_info.addend,
.pcrel = false, .type = .unsigned,
.has_subtractor = false, .meta = .{
.length = 3, .pcrel = false,
.symbolnum = @intCast(sym.nlist_idx), .has_subtractor = false,
.length = 3,
.symbolnum = @intCast(sym.nlist_idx),
},
});
}, },
}); .debug_output => |debug_output| switch (debug_output) {
.dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
.source_off = @intCast(reloc_info.offset),
.target_sym = sym_index,
.target_off = reloc_info.addend,
}),
.plan9 => unreachable,
.none => unreachable,
},
}
return vaddr; return vaddr;
} }
@ -903,8 +929,7 @@ pub fn updateNav(
zcu.navSrcLoc(nav_index), zcu.navSrcLoc(nav_index),
Value.fromInterned(nav_init), Value.fromInterned(nav_init),
&code_buffer, &code_buffer,
if (debug_wip_nav) |*wip_nav| .{ .dwarf = wip_nav } else .none, .{ .atom_index = sym_index },
.{ .parent_atom_index = sym_index },
); );
const code = switch (res) { const code = switch (res) {
@ -1212,11 +1237,14 @@ fn lowerConst(
const name_str = try self.addString(gpa, name); const name_str = try self.addString(gpa, name);
const sym_index = try self.newSymbolWithAtom(gpa, name_str, macho_file); const sym_index = try self.newSymbolWithAtom(gpa, name_str, macho_file);
const res = try codegen.generateSymbol(&macho_file.base, pt, src_loc, val, &code_buffer, .{ const res = try codegen.generateSymbol(
.none = {}, &macho_file.base,
}, .{ pt,
.parent_atom_index = sym_index, src_loc,
}); val,
&code_buffer,
.{ .atom_index = sym_index },
);
const code = switch (res) { const code = switch (res) {
.ok => code_buffer.items, .ok => code_buffer.items,
.fail => |em| return .{ .fail = em }, .fail => |em| return .{ .fail = em },
@ -1378,7 +1406,7 @@ fn updateLazySymbol(
&required_alignment, &required_alignment,
&code_buffer, &code_buffer,
.none, .none,
.{ .parent_atom_index = symbol_index }, .{ .atom_index = symbol_index },
); );
const code = switch (res) { const code = switch (res) {
.ok => code_buffer.items, .ok => code_buffer.items,

View File

@ -422,10 +422,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
); );
const code = switch (res) { const code = switch (res) {
.ok => try code_buffer.toOwnedSlice(), .ok => try code_buffer.toOwnedSlice(),
.fail => |em| { .fail => |em| return zcu.failed_codegen.put(gpa, func.owner_nav, em),
try zcu.failed_codegen.put(gpa, func.owner_nav, em);
return;
},
}; };
self.getAtomPtr(atom_idx).code = .{ self.getAtomPtr(atom_idx).code = .{
.code_ptr = null, .code_ptr = null,
@ -463,15 +460,17 @@ pub fn updateNav(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Inde
var code_buffer = std.ArrayList(u8).init(gpa); var code_buffer = std.ArrayList(u8).init(gpa);
defer code_buffer.deinit(); defer code_buffer.deinit();
// TODO we need the symbol index for symbol in the table of locals for the containing atom // TODO we need the symbol index for symbol in the table of locals for the containing atom
const res = try codegen.generateSymbol(&self.base, pt, zcu.navSrcLoc(nav_index), nav_init, &code_buffer, .none, .{ const res = try codegen.generateSymbol(
.parent_atom_index = @intCast(atom_idx), &self.base,
}); pt,
zcu.navSrcLoc(nav_index),
nav_init,
&code_buffer,
.{ .atom_index = @intCast(atom_idx) },
);
const code = switch (res) { const code = switch (res) {
.ok => code_buffer.items, .ok => code_buffer.items,
.fail => |em| { .fail => |em| return zcu.failed_codegen.put(gpa, nav_index, em),
try zcu.failed_codegen.put(gpa, nav_index, em);
return;
},
}; };
try self.data_nav_table.ensureUnusedCapacity(gpa, 1); try self.data_nav_table.ensureUnusedCapacity(gpa, 1);
const duped_code = try gpa.dupe(u8, code); const duped_code = try gpa.dupe(u8, code);
@ -1116,7 +1115,7 @@ fn updateLazySymbolAtom(self: *Plan9, pt: Zcu.PerThread, sym: File.LazySymbol, a
&required_alignment, &required_alignment,
&code_buffer, &code_buffer,
.none, .none,
.{ .parent_atom_index = @as(Atom.Index, @intCast(atom_index)) }, .{ .atom_index = @intCast(atom_index) },
); );
const code = switch (res) { const code = switch (res) {
.ok => code_buffer.items, .ok => code_buffer.items,
@ -1373,21 +1372,21 @@ pub fn getNavVAddr(
log.debug("getDeclVAddr for {}", .{nav.name.fmt(ip)}); log.debug("getDeclVAddr for {}", .{nav.name.fmt(ip)});
if (ip.indexToKey(nav.status.resolved.val) == .@"extern") { if (ip.indexToKey(nav.status.resolved.val) == .@"extern") {
if (nav.name.eqlSlice("etext", ip)) { if (nav.name.eqlSlice("etext", ip)) {
try self.addReloc(reloc_info.parent_atom_index, .{ try self.addReloc(reloc_info.parent.atom_index, .{
.target = undefined, .target = undefined,
.offset = reloc_info.offset, .offset = reloc_info.offset,
.addend = reloc_info.addend, .addend = reloc_info.addend,
.type = .special_etext, .type = .special_etext,
}); });
} else if (nav.name.eqlSlice("edata", ip)) { } else if (nav.name.eqlSlice("edata", ip)) {
try self.addReloc(reloc_info.parent_atom_index, .{ try self.addReloc(reloc_info.parent.atom_index, .{
.target = undefined, .target = undefined,
.offset = reloc_info.offset, .offset = reloc_info.offset,
.addend = reloc_info.addend, .addend = reloc_info.addend,
.type = .special_edata, .type = .special_edata,
}); });
} else if (nav.name.eqlSlice("end", ip)) { } else if (nav.name.eqlSlice("end", ip)) {
try self.addReloc(reloc_info.parent_atom_index, .{ try self.addReloc(reloc_info.parent.atom_index, .{
.target = undefined, .target = undefined,
.offset = reloc_info.offset, .offset = reloc_info.offset,
.addend = reloc_info.addend, .addend = reloc_info.addend,
@ -1400,7 +1399,7 @@ pub fn getNavVAddr(
// otherwise, we just add a relocation // otherwise, we just add a relocation
const atom_index = try self.seeNav(pt, nav_index); const atom_index = try self.seeNav(pt, nav_index);
// the parent_atom_index in this case is just the decl_index of the parent // the parent_atom_index in this case is just the decl_index of the parent
try self.addReloc(reloc_info.parent_atom_index, .{ try self.addReloc(reloc_info.parent.atom_index, .{
.target = atom_index, .target = atom_index,
.offset = reloc_info.offset, .offset = reloc_info.offset,
.addend = reloc_info.addend, .addend = reloc_info.addend,
@ -1435,7 +1434,7 @@ pub fn lowerUav(
gop.value_ptr.* = index; gop.value_ptr.* = index;
// we need to free name latex // we need to free name latex
var code_buffer = std.ArrayList(u8).init(gpa); var code_buffer = std.ArrayList(u8).init(gpa);
const res = try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .{ .none = {} }, .{ .parent_atom_index = index }); const res = try codegen.generateSymbol(&self.base, pt, src_loc, val, &code_buffer, .{ .atom_index = index });
const code = switch (res) { const code = switch (res) {
.ok => code_buffer.items, .ok => code_buffer.items,
.fail => |em| return .{ .fail = em }, .fail => |em| return .{ .fail = em },
@ -1459,7 +1458,7 @@ pub fn lowerUav(
pub fn getUavVAddr(self: *Plan9, uav: InternPool.Index, reloc_info: link.File.RelocInfo) !u64 { pub fn getUavVAddr(self: *Plan9, uav: InternPool.Index, reloc_info: link.File.RelocInfo) !u64 {
const atom_index = self.uavs.get(uav).?; const atom_index = self.uavs.get(uav).?;
try self.addReloc(reloc_info.parent_atom_index, .{ try self.addReloc(reloc_info.parent.atom_index, .{
.target = atom_index, .target = atom_index,
.offset = reloc_info.offset, .offset = reloc_info.offset,
.addend = reloc_info.addend, .addend = reloc_info.addend,

View File

@ -277,8 +277,7 @@ pub fn updateNav(
zcu.navSrcLoc(nav_index), zcu.navSrcLoc(nav_index),
nav_init, nav_init,
&code_writer, &code_writer,
.none, .{ .atom_index = @intFromEnum(atom.sym_index) },
.{ .parent_atom_index = @intFromEnum(atom.sym_index) },
); );
const code = switch (res) { const code = switch (res) {
@ -520,10 +519,7 @@ fn lowerConst(
src_loc, src_loc,
val, val,
&value_bytes, &value_bytes,
.none, .{ .atom_index = @intFromEnum(atom.sym_index) },
.{
.parent_atom_index = @intFromEnum(atom.sym_index),
},
); );
break :code switch (result) { break :code switch (result) {
.ok => value_bytes.items, .ok => value_bytes.items,
@ -762,8 +758,11 @@ pub fn getNavVAddr(
else => {}, else => {},
} }
std.debug.assert(reloc_info.parent_atom_index != 0); std.debug.assert(reloc_info.parent.atom_index != 0);
const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?; const atom_index = wasm_file.symbol_atom.get(.{
.file = zig_object.index,
.index = @enumFromInt(reloc_info.parent.atom_index),
}).?;
const atom = wasm_file.getAtomPtr(atom_index); const atom = wasm_file.getAtomPtr(atom_index);
const is_wasm32 = target.cpu.arch == .wasm32; const is_wasm32 = target.cpu.arch == .wasm32;
if (ip.isFunctionType(ip.getNav(nav_index).typeOf(ip))) { if (ip.isFunctionType(ip.getNav(nav_index).typeOf(ip))) {
@ -800,7 +799,10 @@ pub fn getUavVAddr(
const atom_index = zig_object.uavs.get(uav).?; const atom_index = zig_object.uavs.get(uav).?;
const target_symbol_index = @intFromEnum(wasm_file.getAtom(atom_index).sym_index); const target_symbol_index = @intFromEnum(wasm_file.getAtom(atom_index).sym_index);
const parent_atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?; const parent_atom_index = wasm_file.symbol_atom.get(.{
.file = zig_object.index,
.index = @enumFromInt(reloc_info.parent.atom_index),
}).?;
const parent_atom = wasm_file.getAtomPtr(parent_atom_index); const parent_atom = wasm_file.getAtomPtr(parent_atom_index);
const is_wasm32 = target.cpu.arch == .wasm32; const is_wasm32 = target.cpu.arch == .wasm32;
const zcu = wasm_file.base.comp.zcu.?; const zcu = wasm_file.base.comp.zcu.?;

View File

@ -107,11 +107,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
}, },
\\breakpoint set --file basic.zig --source-pattern-regexp '_ = basic;' \\breakpoint set --file basic.zig --source-pattern-regexp '_ = basic;'
\\process launch \\process launch
\\frame variable --show-types basic \\frame variable --show-types -- basic
\\breakpoint delete --force 1 \\breakpoint delete --force 1
, ,
&.{ &.{
\\(lldb) frame variable --show-types basic \\(lldb) frame variable --show-types -- basic
\\(root.basic.Basic) basic = { \\(root.basic.Basic) basic = {
\\ (void) void = {} \\ (void) void = {}
\\ (bool) bool_false = false \\ (bool) bool_false = false
@ -243,11 +243,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
}, },
\\breakpoint set --file pointers.zig --source-pattern-regexp '_ = pointers;' \\breakpoint set --file pointers.zig --source-pattern-regexp '_ = pointers;'
\\process launch \\process launch
\\frame variable --show-types pointers \\frame variable --show-types -- pointers
\\breakpoint delete --force 1 \\breakpoint delete --force 1
, ,
&.{ &.{
\\(lldb) frame variable --show-types pointers \\(lldb) frame variable --show-types -- pointers
\\(root.pointers.Pointers) pointers = { \\(root.pointers.Pointers) pointers = {
\\ (*u32) single = 0x0000000000001010 \\ (*u32) single = 0x0000000000001010
\\ (*const u32) single_const = 0x0000000000001014 \\ (*const u32) single_const = 0x0000000000001014
@ -330,13 +330,13 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
}, },
\\breakpoint set --file strings.zig --source-pattern-regexp '_ = strings;' \\breakpoint set --file strings.zig --source-pattern-regexp '_ = strings;'
\\process launch \\process launch
\\frame variable --show-types strings.slice \\frame variable --show-types -- strings.slice
\\frame variable --show-types --format character strings.slice \\frame variable --show-types --format character -- strings.slice
\\frame variable --show-types --format c-string strings \\frame variable --show-types --format c-string -- strings
\\breakpoint delete --force 1 \\breakpoint delete --force 1
, ,
&.{ &.{
\\(lldb) frame variable --show-types strings.slice \\(lldb) frame variable --show-types -- strings.slice
\\([:0]const u8) strings.slice = len=9 { \\([:0]const u8) strings.slice = len=9 {
\\ (u8) [0] = 115 \\ (u8) [0] = 115
\\ (u8) [1] = 108 \\ (u8) [1] = 108
@ -348,7 +348,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
\\ (u8) [7] = 92 \\ (u8) [7] = 92
\\ (u8) [8] = 0 \\ (u8) [8] = 0
\\} \\}
\\(lldb) frame variable --show-types --format character strings.slice \\(lldb) frame variable --show-types --format character -- strings.slice
\\([:0]const u8) strings.slice = len=9 { \\([:0]const u8) strings.slice = len=9 {
\\ (u8) [0] = 's' \\ (u8) [0] = 's'
\\ (u8) [1] = 'l' \\ (u8) [1] = 'l'
@ -360,7 +360,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
\\ (u8) [7] = '\\' \\ (u8) [7] = '\\'
\\ (u8) [8] = '\x00' \\ (u8) [8] = '\x00'
\\} \\}
\\(lldb) frame variable --show-types --format c-string strings \\(lldb) frame variable --show-types --format c-string -- strings
\\(root.strings.Strings) strings = { \\(root.strings.Strings) strings = {
\\ ([*c]const u8) c_ptr = "c_ptr\x07\x08\t" \\ ([*c]const u8) c_ptr = "c_ptr\x07\x08\t"
\\ ([*:0]const u8) many_ptr = "many_ptr\n\x0b\x0c" \\ ([*:0]const u8) many_ptr = "many_ptr\n\x0b\x0c"
@ -411,11 +411,28 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
}, },
\\breakpoint set --file enums.zig --source-pattern-regexp '_ = enums;' \\breakpoint set --file enums.zig --source-pattern-regexp '_ = enums;'
\\process launch \\process launch
\\frame variable --show-types enums \\expression --show-types -- Enums
\\frame variable --show-types -- enums
\\breakpoint delete --force 1 \\breakpoint delete --force 1
, ,
&.{ &.{
\\(lldb) frame variable --show-types enums \\(lldb) expression --show-types -- Enums
\\(type) Enums = struct {
\\ (type) Zero = enum {}
\\ (type) One = enum {
\\ (root.enums.Enums.One) first = .first
\\ }
\\ (type) Two = enum {
\\ (root.enums.Enums.Two) first = .first
\\ (root.enums.Enums.Two) second = .second
\\ }
\\ (type) Three = enum {
\\ (root.enums.Enums.Three) first = .first
\\ (root.enums.Enums.Three) second = .second
\\ (root.enums.Enums.Three) third = .third
\\ }
\\}
\\(lldb) frame variable --show-types -- enums
\\(root.enums.Enums) enums = { \\(root.enums.Enums) enums = {
\\ (root.enums.Enums.Zero) zero = @enumFromInt(13) \\ (root.enums.Enums.Zero) zero = @enumFromInt(13)
\\ (root.enums.Enums.One) one = .first \\ (root.enums.Enums.One) one = .first
@ -434,12 +451,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
.path = "errors.zig", .path = "errors.zig",
.source = .source =
\\const Errors = struct { \\const Errors = struct {
\\ one: error{One} = error.One, \\ const Zero = error{};
\\ two: error{One,Two} = error.Two, \\ const One = Zero || error{One};
\\ three: error{One,Two,Three} = error.Three, \\ const Two = One || error{Two};
\\ const Three = Two || error{Three};
\\
\\ one: One = error.One,
\\ two: Two = error.Two,
\\ three: Three = error.Three,
\\ any: anyerror = error.Any, \\ any: anyerror = error.Any,
\\ any_void: anyerror!void = error.NotVoid, \\ any_void: anyerror!void = error.NotVoid,
\\ any_u32: error{One}!u32 = 42, \\ any_u32: One!u32 = 42,
\\}; \\};
\\fn testErrors(errors: Errors) void { \\fn testErrors(errors: Errors) void {
\\ _ = errors; \\ _ = errors;
@ -453,11 +475,28 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
}, },
\\breakpoint set --file errors.zig --source-pattern-regexp '_ = errors;' \\breakpoint set --file errors.zig --source-pattern-regexp '_ = errors;'
\\process launch \\process launch
\\frame variable --show-types errors \\expression --show-types -- Errors
\\frame variable --show-types -- errors
\\breakpoint delete --force 1 \\breakpoint delete --force 1
, ,
&.{ &.{
\\(lldb) frame variable --show-types errors \\(lldb) expression --show-types -- Errors
\\(type) Errors = struct {
\\ (type) Zero = error {}
\\ (type) One = error {
\\ (error{One}) One = error.One
\\ }
\\ (type) Two = error {
\\ (error{One,Two}) One = error.One
\\ (error{One,Two}) Two = error.Two
\\ }
\\ (type) Three = error {
\\ (error{One,Two,Three}) One = error.One
\\ (error{One,Two,Three}) Two = error.Two
\\ (error{One,Two,Three}) Three = error.Three
\\ }
\\}
\\(lldb) frame variable --show-types -- errors
\\(root.errors.Errors) errors = { \\(root.errors.Errors) errors = {
\\ (error{One}) one = error.One \\ (error{One}) one = error.One
\\ (error{One,Two}) two = error.Two \\ (error{One,Two}) two = error.Two
@ -496,23 +535,23 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
}, },
\\breakpoint set --file optionals.zig --source-pattern-regexp 'maybe_u32 = 123;' \\breakpoint set --file optionals.zig --source-pattern-regexp 'maybe_u32 = 123;'
\\process launch \\process launch
\\frame variable null_u32 maybe_u32 nonnull_u32 \\frame variable -- null_u32 maybe_u32 nonnull_u32
\\breakpoint delete --force 1 \\breakpoint delete --force 1
\\ \\
\\breakpoint set --file optionals.zig --source-pattern-regexp '_ = .{ &null_u32, &nonnull_u32 };' \\breakpoint set --file optionals.zig --source-pattern-regexp '_ = \.{ &null_u32, &nonnull_u32 };'
\\process continue \\process continue
\\frame variable --show-types null_u32 maybe_u32 nonnull_u32 \\frame variable --show-types -- null_u32 maybe_u32 nonnull_u32
\\breakpoint delete --force 2 \\breakpoint delete --force 2
, ,
&.{ &.{
\\(lldb) frame variable null_u32 maybe_u32 nonnull_u32 \\(lldb) frame variable -- null_u32 maybe_u32 nonnull_u32
\\(?u32) null_u32 = null \\(?u32) null_u32 = null
\\(?u32) maybe_u32 = null \\(?u32) maybe_u32 = null
\\(?u32) nonnull_u32 = (nonnull_u32.? = 456) \\(?u32) nonnull_u32 = (nonnull_u32.? = 456)
\\(lldb) breakpoint delete --force 1 \\(lldb) breakpoint delete --force 1
\\1 breakpoints deleted; 0 breakpoint locations disabled. \\1 breakpoints deleted; 0 breakpoint locations disabled.
, ,
\\(lldb) frame variable --show-types null_u32 maybe_u32 nonnull_u32 \\(lldb) frame variable --show-types -- null_u32 maybe_u32 nonnull_u32
\\(?u32) null_u32 = null \\(?u32) null_u32 = null
\\(?u32) maybe_u32 = { \\(?u32) maybe_u32 = {
\\ (u32) maybe_u32.? = 123 \\ (u32) maybe_u32.? = 123
@ -565,11 +604,31 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
}, },
\\breakpoint set --file unions.zig --source-pattern-regexp '_ = unions;' \\breakpoint set --file unions.zig --source-pattern-regexp '_ = unions;'
\\process launch \\process launch
\\frame variable --show-types unions \\expression --show-types -- Unions
\\frame variable --show-types -- unions
\\breakpoint delete --force 1 \\breakpoint delete --force 1
, ,
&.{ &.{
\\(lldb) frame variable --show-types unions \\(lldb) expression --show-types -- Unions
\\(type) Unions = struct {
\\ (type) Untagged = union {}
\\ (type) SafetyTagged = union(enum) {
\\ (@typeInfo(unions.Unions.SafetyTagged).@"union".tag_type.?) void = .void
\\ (@typeInfo(unions.Unions.SafetyTagged).@"union".tag_type.?) en = .en
\\ (@typeInfo(unions.Unions.SafetyTagged).@"union".tag_type.?) eu = .eu
\\ }
\\ (type) Enum = enum {
\\ (root.unions.Unions.Enum) first = .first
\\ (root.unions.Unions.Enum) second = .second
\\ (root.unions.Unions.Enum) third = .third
\\ }
\\ (type) Tagged = union(enum) {
\\ (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) void = .void
\\ (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) en = .en
\\ (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) eu = .eu
\\ }
\\}
\\(lldb) frame variable --show-types -- unions
\\(root.unions.Unions) unions = { \\(root.unions.Unions) unions = {
\\ (root.unions.Unions.Untagged) untagged = { \\ (root.unions.Unions.Untagged) untagged = {
\\ (u32) u32 = 3217031168 \\ (u32) u32 = 3217031168
@ -635,17 +694,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
}, },
\\breakpoint set --file storage.zig --source-pattern-regexp 'local_var = local_var;' \\breakpoint set --file storage.zig --source-pattern-regexp 'local_var = local_var;'
\\process launch \\process launch
\\target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2 \\target variable --show-types --format hex -- global_const global_var global_threadlocal1 global_threadlocal2
\\frame variable --show-types --format hex param1 param2 param3 param4 param5 param6 param7 param8 local_comptime_val local_comptime_ptr.0 local_const local_var \\frame variable --show-types --format hex -- param1 param2 param3 param4 param5 param6 param7 param8 local_comptime_val local_comptime_ptr.0 local_const local_var
\\breakpoint delete --force 1 \\breakpoint delete --force 1
, ,
&.{ &.{
\\(lldb) target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2 \\(lldb) target variable --show-types --format hex -- global_const global_var global_threadlocal1 global_threadlocal2
\\(u64) global_const = 0x19e50dc8d6002077 \\(u64) global_const = 0x19e50dc8d6002077
\\(u64) global_var = 0xcc423cec08622e32 \\(u64) global_var = 0xcc423cec08622e32
\\(u64) global_threadlocal1 = 0xb4d643528c042121 \\(u64) global_threadlocal1 = 0xb4d643528c042121
\\(u64) global_threadlocal2 = 0x43faea1cf5ad7a22 \\(u64) global_threadlocal2 = 0x43faea1cf5ad7a22
\\(lldb) frame variable --show-types --format hex param1 param2 param3 param4 param5 param6 param7 param8 local_comptime_val local_comptime_ptr.0 local_const local_var \\(lldb) frame variable --show-types --format hex -- param1 param2 param3 param4 param5 param6 param7 param8 local_comptime_val local_comptime_ptr.0 local_const local_var
\\(u64) param1 = 0x6a607e08125c7e00 \\(u64) param1 = 0x6a607e08125c7e00
\\(u64) param2 = 0x98944cb2a45a8b51 \\(u64) param2 = 0x98944cb2a45a8b51
\\(u64) param3 = 0xa320cf10601ee6fb \\(u64) param3 = 0xa320cf10601ee6fb
@ -1240,31 +1299,536 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
\\ x = fabsf(x); \\ x = fabsf(x);
\\ _ = &x; \\ _ = &x;
\\} \\}
\\
, ,
}, },
}, },
\\breakpoint set --file main.zig --source-pattern-regexp 'x = fabsf\(x\);' \\breakpoint set --file main.zig --source-pattern-regexp 'x = fabsf\(x\);'
\\process launch \\process launch
\\frame variable x \\frame variable -- x
\\breakpoint delete --force 1 \\breakpoint delete --force 1
\\ \\
\\breakpoint set --file main.zig --source-pattern-regexp '_ = &x;' \\breakpoint set --file main.zig --source-pattern-regexp '_ = &x;'
\\process continue \\process continue
\\frame variable x \\frame variable -- x
\\breakpoint delete --force 2 \\breakpoint delete --force 2
, ,
&.{ &.{
\\(lldb) frame variable x \\(lldb) frame variable -- x
\\(f32) x = -1234.5 \\(f32) x = -1234.5
\\(lldb) breakpoint delete --force 1 \\(lldb) breakpoint delete --force 1
\\1 breakpoints deleted; 0 breakpoint locations disabled. \\1 breakpoints deleted; 0 breakpoint locations disabled.
, ,
\\(lldb) frame variable x \\(lldb) frame variable -- x
\\(f32) x = 1234.5 \\(f32) x = 1234.5
\\(lldb) breakpoint delete --force 2 \\(lldb) breakpoint delete --force 2
\\1 breakpoints deleted; 0 breakpoint locations disabled. \\1 breakpoints deleted; 0 breakpoint locations disabled.
}, },
); );
db.addLldbTest(
"hash_map",
target,
&.{
.{
.path = "main.zig",
.source =
\\const std = @import("std");
\\const Context = struct {
\\ pub fn hash(_: Context, key: u32) Map.Hash {
\\ return key;
\\ }
\\ pub fn eql(_: Context, lhs: u32, rhs: u32) bool {
\\ return lhs == rhs;
\\ }
\\};
\\const Map = std.HashMap(u32, u32, Context, 63);
\\fn testHashMap(map: Map) void {
\\ _ = map;
\\}
\\pub fn main() !void {
\\ var map = Map.init(std.heap.page_allocator);
\\ defer map.deinit();
\\ try map.ensureTotalCapacity(10);
\\ map.putAssumeCapacity(0, 1);
\\ map.putAssumeCapacity(2, 3);
\\ map.putAssumeCapacity(4, 5);
\\ map.putAssumeCapacity(6, 7);
\\ map.putAssumeCapacity(8, 9);
\\
\\ testHashMap(map);
\\}
\\
,
},
},
\\breakpoint set --file main.zig --source-pattern-regexp '_ = map;'
\\process launch
\\frame variable --show-types -- map.unmanaged
\\breakpoint delete --force 1
,
&.{
\\(lldb) frame variable --show-types -- map.unmanaged
\\(std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63)) map.unmanaged = len=5 capacity=16 {
\\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [0] = {
\\ (u32) key = 0
\\ (u32) value = 1
\\ }
\\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [1] = {
\\ (u32) key = 2
\\ (u32) value = 3
\\ }
\\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [2] = {
\\ (u32) key = 4
\\ (u32) value = 5
\\ }
\\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [3] = {
\\ (u32) key = 6
\\ (u32) value = 7
\\ }
\\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [4] = {
\\ (u32) key = 8
\\ (u32) value = 9
\\ }
\\}
\\(lldb) breakpoint delete --force 1
\\1 breakpoints deleted; 0 breakpoint locations disabled.
},
);
db.addLldbTest(
"multi_array_list",
target,
&.{
.{
.path = "main.zig",
.source =
\\const std = @import("std");
\\const Elem0 = struct { u32, u8, u16 };
\\const Elem1 = struct { a: u32, b: u8, c: u16 };
\\fn testMultiArrayList(
\\ list0: std.MultiArrayList(Elem0),
\\ slice0: std.MultiArrayList(Elem0).Slice,
\\ list1: std.MultiArrayList(Elem1),
\\ slice1: std.MultiArrayList(Elem1).Slice,
\\) void {
\\ _ = .{ list0, slice0, list1, slice1 };
\\}
\\pub fn main() !void {
\\ var list0: std.MultiArrayList(Elem0) = .{};
\\ defer list0.deinit(std.heap.page_allocator);
\\ try list0.setCapacity(std.heap.page_allocator, 8);
\\ list0.appendAssumeCapacity(.{ 1, 2, 3 });
\\ list0.appendAssumeCapacity(.{ 4, 5, 6 });
\\ list0.appendAssumeCapacity(.{ 7, 8, 9 });
\\ const slice0 = list0.slice();
\\
\\ var list1: std.MultiArrayList(Elem1) = .{};
\\ defer list1.deinit(std.heap.page_allocator);
\\ try list1.setCapacity(std.heap.page_allocator, 12);
\\ list1.appendAssumeCapacity(.{ .a = 1, .b = 2, .c = 3 });
\\ list1.appendAssumeCapacity(.{ .a = 4, .b = 5, .c = 6 });
\\ list1.appendAssumeCapacity(.{ .a = 7, .b = 8, .c = 9 });
\\ const slice1 = list1.slice();
\\
\\ testMultiArrayList(list0, slice0, list1, slice1);
\\}
\\
,
},
},
\\breakpoint set --file main.zig --source-pattern-regexp '_ = \.{ list0, slice0, list1, slice1 };'
\\process launch
\\frame variable --show-types -- list0 list0.len list0.capacity list0[0] list0[1] list0[2] list0.0 list0.1 list0.2
\\frame variable --show-types -- slice0 slice0.len slice0.capacity slice0[0] slice0[1] slice0[2] slice0.0 slice0.1 slice0.2
\\frame variable --show-types -- list1 list1.len list1.capacity list1[0] list1[1] list1[2] list1.a list1.b list1.c
\\frame variable --show-types -- slice1 slice1.len slice1.capacity slice1[0] slice1[1] slice1[2] slice1.a slice1.b slice1.c
\\breakpoint delete --force 1
,
&.{
\\(lldb) frame variable --show-types -- list0 list0.len list0.capacity list0[0] list0[1] list0[2] list0.0 list0.1 list0.2
\\(std.multi_array_list.MultiArrayList(main.Elem0)) list0 = len=3 capacity=8 {
\\ (root.main.Elem0) [0] = {
\\ (u32) 0 = 1
\\ (u8) 1 = 2
\\ (u16) 2 = 3
\\ }
\\ (root.main.Elem0) [1] = {
\\ (u32) 0 = 4
\\ (u8) 1 = 5
\\ (u16) 2 = 6
\\ }
\\ (root.main.Elem0) [2] = {
\\ (u32) 0 = 7
\\ (u8) 1 = 8
\\ (u16) 2 = 9
\\ }
\\}
\\(usize) list0.len = 3
\\(usize) list0.capacity = 8
\\(root.main.Elem0) list0[0] = {
\\ (u32) 0 = 1
\\ (u8) 1 = 2
\\ (u16) 2 = 3
\\}
\\(root.main.Elem0) list0[1] = {
\\ (u32) 0 = 4
\\ (u8) 1 = 5
\\ (u16) 2 = 6
\\}
\\(root.main.Elem0) list0[2] = {
\\ (u32) 0 = 7
\\ (u8) 1 = 8
\\ (u16) 2 = 9
\\}
\\([3]u32) list0.0 = {
\\ (u32) [0] = 1
\\ (u32) [1] = 4
\\ (u32) [2] = 7
\\}
\\([3]u8) list0.1 = {
\\ (u8) [0] = 2
\\ (u8) [1] = 5
\\ (u8) [2] = 8
\\}
\\([3]u16) list0.2 = {
\\ (u16) [0] = 3
\\ (u16) [1] = 6
\\ (u16) [2] = 9
\\}
\\(lldb) frame variable --show-types -- slice0 slice0.len slice0.capacity slice0[0] slice0[1] slice0[2] slice0.0 slice0.1 slice0.2
\\(std.multi_array_list.MultiArrayList(main.Elem0).Slice) slice0 = len=3 capacity=8 {
\\ (root.main.Elem0) [0] = {
\\ (u32) 0 = 1
\\ (u8) 1 = 2
\\ (u16) 2 = 3
\\ }
\\ (root.main.Elem0) [1] = {
\\ (u32) 0 = 4
\\ (u8) 1 = 5
\\ (u16) 2 = 6
\\ }
\\ (root.main.Elem0) [2] = {
\\ (u32) 0 = 7
\\ (u8) 1 = 8
\\ (u16) 2 = 9
\\ }
\\}
\\(usize) slice0.len = 3
\\(usize) slice0.capacity = 8
\\(root.main.Elem0) slice0[0] = {
\\ (u32) 0 = 1
\\ (u8) 1 = 2
\\ (u16) 2 = 3
\\}
\\(root.main.Elem0) slice0[1] = {
\\ (u32) 0 = 4
\\ (u8) 1 = 5
\\ (u16) 2 = 6
\\}
\\(root.main.Elem0) slice0[2] = {
\\ (u32) 0 = 7
\\ (u8) 1 = 8
\\ (u16) 2 = 9
\\}
\\([3]u32) slice0.0 = {
\\ (u32) [0] = 1
\\ (u32) [1] = 4
\\ (u32) [2] = 7
\\}
\\([3]u8) slice0.1 = {
\\ (u8) [0] = 2
\\ (u8) [1] = 5
\\ (u8) [2] = 8
\\}
\\([3]u16) slice0.2 = {
\\ (u16) [0] = 3
\\ (u16) [1] = 6
\\ (u16) [2] = 9
\\}
\\(lldb) frame variable --show-types -- list1 list1.len list1.capacity list1[0] list1[1] list1[2] list1.a list1.b list1.c
\\(std.multi_array_list.MultiArrayList(main.Elem1)) list1 = len=3 capacity=12 {
\\ (root.main.Elem1) [0] = {
\\ (u32) a = 1
\\ (u8) b = 2
\\ (u16) c = 3
\\ }
\\ (root.main.Elem1) [1] = {
\\ (u32) a = 4
\\ (u8) b = 5
\\ (u16) c = 6
\\ }
\\ (root.main.Elem1) [2] = {
\\ (u32) a = 7
\\ (u8) b = 8
\\ (u16) c = 9
\\ }
\\}
\\(usize) list1.len = 3
\\(usize) list1.capacity = 12
\\(root.main.Elem1) list1[0] = {
\\ (u32) a = 1
\\ (u8) b = 2
\\ (u16) c = 3
\\}
\\(root.main.Elem1) list1[1] = {
\\ (u32) a = 4
\\ (u8) b = 5
\\ (u16) c = 6
\\}
\\(root.main.Elem1) list1[2] = {
\\ (u32) a = 7
\\ (u8) b = 8
\\ (u16) c = 9
\\}
\\([3]u32) list1.a = {
\\ (u32) [0] = 1
\\ (u32) [1] = 4
\\ (u32) [2] = 7
\\}
\\([3]u8) list1.b = {
\\ (u8) [0] = 2
\\ (u8) [1] = 5
\\ (u8) [2] = 8
\\}
\\([3]u16) list1.c = {
\\ (u16) [0] = 3
\\ (u16) [1] = 6
\\ (u16) [2] = 9
\\}
\\(lldb) frame variable --show-types -- slice1 slice1.len slice1.capacity slice1[0] slice1[1] slice1[2] slice1.a slice1.b slice1.c
\\(std.multi_array_list.MultiArrayList(main.Elem1).Slice) slice1 = len=3 capacity=12 {
\\ (root.main.Elem1) [0] = {
\\ (u32) a = 1
\\ (u8) b = 2
\\ (u16) c = 3
\\ }
\\ (root.main.Elem1) [1] = {
\\ (u32) a = 4
\\ (u8) b = 5
\\ (u16) c = 6
\\ }
\\ (root.main.Elem1) [2] = {
\\ (u32) a = 7
\\ (u8) b = 8
\\ (u16) c = 9
\\ }
\\}
\\(usize) slice1.len = 3
\\(usize) slice1.capacity = 12
\\(root.main.Elem1) slice1[0] = {
\\ (u32) a = 1
\\ (u8) b = 2
\\ (u16) c = 3
\\}
\\(root.main.Elem1) slice1[1] = {
\\ (u32) a = 4
\\ (u8) b = 5
\\ (u16) c = 6
\\}
\\(root.main.Elem1) slice1[2] = {
\\ (u32) a = 7
\\ (u8) b = 8
\\ (u16) c = 9
\\}
\\([3]u32) slice1.a = {
\\ (u32) [0] = 1
\\ (u32) [1] = 4
\\ (u32) [2] = 7
\\}
\\([3]u8) slice1.b = {
\\ (u8) [0] = 2
\\ (u8) [1] = 5
\\ (u8) [2] = 8
\\}
\\([3]u16) slice1.c = {
\\ (u16) [0] = 3
\\ (u16) [1] = 6
\\ (u16) [2] = 9
\\}
\\(lldb) breakpoint delete --force 1
\\1 breakpoints deleted; 0 breakpoint locations disabled.
},
);
db.addLldbTest(
"segmented_list",
target,
&.{
.{
.path = "main.zig",
.source =
\\const std = @import("std");
\\fn testSegmentedList() void {}
\\pub fn main() !void {
\\ var list0: std.SegmentedList(usize, 0) = .{};
\\ defer list0.deinit(std.heap.page_allocator);
\\
\\ var list1: std.SegmentedList(usize, 1) = .{};
\\ defer list1.deinit(std.heap.page_allocator);
\\
\\ var list2: std.SegmentedList(usize, 2) = .{};
\\ defer list2.deinit(std.heap.page_allocator);
\\
\\ var list4: std.SegmentedList(usize, 4) = .{};
\\ defer list4.deinit(std.heap.page_allocator);
\\
\\ for (0..32) |i| {
\\ try list0.append(std.heap.page_allocator, i);
\\ try list1.append(std.heap.page_allocator, i);
\\ try list2.append(std.heap.page_allocator, i);
\\ try list4.append(std.heap.page_allocator, i);
\\ }
\\ testSegmentedList();
\\}
\\
,
},
},
\\breakpoint set --file main.zig --source-pattern-regexp 'testSegmentedList\(\);'
\\process launch
\\frame variable -- list0 list1 list2 list4
\\breakpoint delete --force 1
,
&.{
\\(lldb) frame variable -- list0 list1 list2 list4
\\(std.segmented_list.SegmentedList(usize,0)) list0 = len=32 {
\\ [0] = 0
\\ [1] = 1
\\ [2] = 2
\\ [3] = 3
\\ [4] = 4
\\ [5] = 5
\\ [6] = 6
\\ [7] = 7
\\ [8] = 8
\\ [9] = 9
\\ [10] = 10
\\ [11] = 11
\\ [12] = 12
\\ [13] = 13
\\ [14] = 14
\\ [15] = 15
\\ [16] = 16
\\ [17] = 17
\\ [18] = 18
\\ [19] = 19
\\ [20] = 20
\\ [21] = 21
\\ [22] = 22
\\ [23] = 23
\\ [24] = 24
\\ [25] = 25
\\ [26] = 26
\\ [27] = 27
\\ [28] = 28
\\ [29] = 29
\\ [30] = 30
\\ [31] = 31
\\}
\\(std.segmented_list.SegmentedList(usize,1)) list1 = len=32 {
\\ [0] = 0
\\ [1] = 1
\\ [2] = 2
\\ [3] = 3
\\ [4] = 4
\\ [5] = 5
\\ [6] = 6
\\ [7] = 7
\\ [8] = 8
\\ [9] = 9
\\ [10] = 10
\\ [11] = 11
\\ [12] = 12
\\ [13] = 13
\\ [14] = 14
\\ [15] = 15
\\ [16] = 16
\\ [17] = 17
\\ [18] = 18
\\ [19] = 19
\\ [20] = 20
\\ [21] = 21
\\ [22] = 22
\\ [23] = 23
\\ [24] = 24
\\ [25] = 25
\\ [26] = 26
\\ [27] = 27
\\ [28] = 28
\\ [29] = 29
\\ [30] = 30
\\ [31] = 31
\\}
\\(std.segmented_list.SegmentedList(usize,2)) list2 = len=32 {
\\ [0] = 0
\\ [1] = 1
\\ [2] = 2
\\ [3] = 3
\\ [4] = 4
\\ [5] = 5
\\ [6] = 6
\\ [7] = 7
\\ [8] = 8
\\ [9] = 9
\\ [10] = 10
\\ [11] = 11
\\ [12] = 12
\\ [13] = 13
\\ [14] = 14
\\ [15] = 15
\\ [16] = 16
\\ [17] = 17
\\ [18] = 18
\\ [19] = 19
\\ [20] = 20
\\ [21] = 21
\\ [22] = 22
\\ [23] = 23
\\ [24] = 24
\\ [25] = 25
\\ [26] = 26
\\ [27] = 27
\\ [28] = 28
\\ [29] = 29
\\ [30] = 30
\\ [31] = 31
\\}
\\(std.segmented_list.SegmentedList(usize,4)) list4 = len=32 {
\\ [0] = 0
\\ [1] = 1
\\ [2] = 2
\\ [3] = 3
\\ [4] = 4
\\ [5] = 5
\\ [6] = 6
\\ [7] = 7
\\ [8] = 8
\\ [9] = 9
\\ [10] = 10
\\ [11] = 11
\\ [12] = 12
\\ [13] = 13
\\ [14] = 14
\\ [15] = 15
\\ [16] = 16
\\ [17] = 17
\\ [18] = 18
\\ [19] = 19
\\ [20] = 20
\\ [21] = 21
\\ [22] = 22
\\ [23] = 23
\\ [24] = 24
\\ [25] = 25
\\ [26] = 26
\\ [27] = 27
\\ [28] = 28
\\ [29] = 29
\\ [30] = 30
\\ [31] = 31
\\}
\\(lldb) breakpoint delete --force 1
\\1 breakpoints deleted; 0 breakpoint locations disabled.
},
);
} }
const File = struct { import: ?[]const u8 = null, path: []const u8, source: []const u8 }; const File = struct { import: ?[]const u8 = null, path: []const u8, source: []const u8 };