authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-09 14:09:18-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-10-09 14:09:18-07:00
log10cb578e4e16bac44055f277cd06baaf99b159b6
tree108509bfba5587a5e930f48d9f5d6fa5483dda44
parentce5a5c361b5b098c3b7d68f88136a9c91e7bec19
parentd748cfc2b778f87f97b86001634cff66120f21a5
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21640 from jacobly0/dwarf-progress

Dwarf: progress

10 files changed, 508 insertions(+), 281 deletions(-)

ci/x86_64-linux-debug.sh+1-1
......@@ -64,7 +64,7 @@ stage3-debug/bin/zig build \
6464
6565stage3-debug/bin/zig build test docs \
6666 --maxrss 21000000000 \
67 -Dlldb=$HOME/deps/lldb-zig/Debug-4a44163df/bin/lldb \
67 -Dlldb=$HOME/deps/lldb-zig/Debug-6ece8bda1/bin/lldb \
6868 -fqemu \
6969 -fwasmtime \
7070 -Dstatic-llvm \
ci/x86_64-linux-release.sh+1-1
......@@ -64,7 +64,7 @@ stage3-release/bin/zig build \
6464
6565stage3-release/bin/zig build test docs \
6666 --maxrss 21000000000 \
67 -Dlldb=$HOME/deps/lldb-zig/Release-4a44163df/bin/lldb \
67 -Dlldb=$HOME/deps/lldb-zig/Release-6ece8bda1/bin/lldb \
6868 -fqemu \
6969 -fwasmtime \
7070 -Dstatic-llvm \
src/arch/x86_64/CodeGen.zig+83-7
......@@ -36,6 +36,7 @@ const abi = @import("abi.zig");
3636const bits = @import("bits.zig");
3737const errUnionErrorOffset = codegen.errUnionErrorOffset;
3838const errUnionPayloadOffset = codegen.errUnionPayloadOffset;
39const encoder = @import("encoder.zig");
3940
4041const Condition = bits.Condition;
4142const Immediate = bits.Immediate;
......@@ -1188,6 +1189,74 @@ fn formatWipMir(
11881189 try writer.print(" | {}", .{lowered_inst});
11891190 first = false;
11901191 }
1192 if (first) {
1193 const ip = &data.self.pt.zcu.intern_pool;
1194 const mir_inst = lower.mir.instructions.get(data.inst);
1195 try writer.print(" | .{s}", .{@tagName(mir_inst.ops)});
1196 switch (mir_inst.ops) {
1197 else => unreachable,
1198 .pseudo_dbg_prologue_end_none,
1199 .pseudo_dbg_line_line_column,
1200 .pseudo_dbg_epilogue_begin_none,
1201 .pseudo_dbg_enter_block_none,
1202 .pseudo_dbg_leave_block_none,
1203 .pseudo_dbg_var_args_none,
1204 .pseudo_dead_none,
1205 => {},
1206 .pseudo_dbg_enter_inline_func, .pseudo_dbg_leave_inline_func => try writer.print(" {}", .{
1207 ip.getNav(ip.indexToKey(mir_inst.data.func).func.owner_nav).name.fmt(ip),
1208 }),
1209 .pseudo_dbg_local_a => try writer.print(" {}", .{mir_inst.data.a.air_inst}),
1210 .pseudo_dbg_local_ai_s => try writer.print(" {}, {d}", .{
1211 mir_inst.data.ai.air_inst,
1212 @as(i32, @bitCast(mir_inst.data.ai.i)),
1213 }),
1214 .pseudo_dbg_local_ai_u => try writer.print(" {}, {d}", .{
1215 mir_inst.data.ai.air_inst,
1216 mir_inst.data.ai.i,
1217 }),
1218 .pseudo_dbg_local_ai_64 => try writer.print(" {}, {d}", .{
1219 mir_inst.data.ai.air_inst,
1220 lower.mir.extraData(Mir.Imm64, mir_inst.data.ai.i).data.decode(),
1221 }),
1222 .pseudo_dbg_local_as => {
1223 const mem_op: Instruction.Operand = .{ .mem = .initSib(.qword, .{
1224 .base = .{ .reloc = mir_inst.data.as.sym_index },
1225 }) };
1226 try writer.print(" {}, {}", .{ mir_inst.data.as.air_inst, mem_op.fmt(.m) });
1227 },
1228 .pseudo_dbg_local_aso => {
1229 const sym_off = lower.mir.extraData(bits.SymbolOffset, mir_inst.data.ax.payload).data;
1230 const mem_op: Instruction.Operand = .{ .mem = .initSib(.qword, .{
1231 .base = .{ .reloc = sym_off.sym_index },
1232 .disp = sym_off.off,
1233 }) };
1234 try writer.print(" {}, {}", .{ mir_inst.data.ax.air_inst, mem_op.fmt(.m) });
1235 },
1236 .pseudo_dbg_local_aro => {
1237 const air_off = lower.mir.extraData(Mir.AirOffset, mir_inst.data.rx.payload).data;
1238 const mem_op: Instruction.Operand = .{ .mem = .initSib(.qword, .{
1239 .base = .{ .reg = mir_inst.data.rx.r1 },
1240 .disp = air_off.off,
1241 }) };
1242 try writer.print(" {}, {}", .{ air_off.air_inst, mem_op.fmt(.m) });
1243 },
1244 .pseudo_dbg_local_af => {
1245 const frame_addr = lower.mir.extraData(bits.FrameAddr, mir_inst.data.ax.payload).data;
1246 const mem_op: Instruction.Operand = .{ .mem = .initSib(.qword, .{
1247 .base = .{ .frame = frame_addr.index },
1248 .disp = frame_addr.off,
1249 }) };
1250 try writer.print(" {}, {d}", .{ mir_inst.data.ax.air_inst, mem_op.fmt(.m) });
1251 },
1252 .pseudo_dbg_local_am => {
1253 const mem_op: Instruction.Operand = .{
1254 .mem = lower.mir.extraData(Mir.Memory, mir_inst.data.ax.payload).data.decode(),
1255 };
1256 try writer.print(" {}, {}", .{ mir_inst.data.ax.air_inst, mem_op.fmt(.m) });
1257 },
1258 }
1259 }
11911260}
11921261fn fmtWipMir(self: *Self, inst: Mir.Inst.Index) std.fmt.Formatter(formatWipMir) {
11931262 return .{ .data = .{ .self = self, .inst = inst } };
......@@ -2180,6 +2249,12 @@ fn checkInvariantsAfterAirInst(self: *Self, inst: Air.Inst.Index, old_air_bookke
21802249 }
21812250}
21822251
2252fn genBodyBlock(self: *Self, body: []const Air.Inst.Index) InnerError!void {
2253 try self.asmPseudo(.pseudo_dbg_enter_block_none);
2254 try self.genBody(body);
2255 try self.asmPseudo(.pseudo_dbg_leave_block_none);
2256}
2257
21832258fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
21842259 const pt = self.pt;
21852260 const zcu = pt.zcu;
......@@ -13184,7 +13259,7 @@ fn genTry(
1318413259 const state = try self.saveState();
1318513260
1318613261 for (liveness_cond_br.else_deaths) |death| try self.processDeath(death);
13187 try self.genBody(body);
13262 try self.genBodyBlock(body);
1318813263 try self.restoreState(state, &.{}, .{
1318913264 .emit_instructions = false,
1319013265 .update_tracking = true,
......@@ -13293,7 +13368,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
1329313368 const reloc = try self.genCondBrMir(cond_ty, cond);
1329413369
1329513370 for (liveness_cond_br.then_deaths) |death| try self.processDeath(death);
13296 try self.genBody(then_body);
13371 try self.genBodyBlock(then_body);
1329713372 try self.restoreState(state, &.{}, .{
1329813373 .emit_instructions = false,
1329913374 .update_tracking = true,
......@@ -13304,7 +13379,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
1330413379 self.performReloc(reloc);
1330513380
1330613381 for (liveness_cond_br.else_deaths) |death| try self.processDeath(death);
13307 try self.genBody(else_body);
13382 try self.genBodyBlock(else_body);
1330813383 try self.restoreState(state, &.{}, .{
1330913384 .emit_instructions = false,
1331013385 .update_tracking = true,
......@@ -13665,14 +13740,16 @@ fn airLoop(self: *Self, inst: Air.Inst.Index) !void {
1366513740 });
1366613741 defer assert(self.loops.remove(inst));
1366713742
13668 try self.genBody(body);
13743 try self.genBodyBlock(body);
1366913744 self.finishAirBookkeeping();
1367013745}
1367113746
1367213747fn airBlock(self: *Self, inst: Air.Inst.Index) !void {
1367313748 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1367413749 const extra = self.air.extraData(Air.Block, ty_pl.payload);
13750 try self.asmPseudo(.pseudo_dbg_enter_block_none);
1367513751 try self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
13752 try self.asmPseudo(.pseudo_dbg_leave_block_none);
1367613753}
1367713754
1367813755fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !void {
......@@ -13684,7 +13761,6 @@ fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !
1368413761 try self.blocks.putNoClobber(self.gpa, inst, .{ .state = self.initRetroactiveState() });
1368513762 const liveness = self.liveness.getBlock(inst);
1368613763
13687 // TODO emit debug info lexical block
1368813764 try self.genBody(body);
1368913765
1369013766 var block_data = self.blocks.fetchRemove(inst).?;
......@@ -13796,7 +13872,7 @@ fn lowerSwitchBr(self: *Self, inst: Air.Inst.Index, switch_br: Air.UnwrappedSwit
1379613872
1379713873 // Relocate all success cases to the body we're about to generate.
1379813874 for (relocs) |reloc| self.performReloc(reloc);
13799 try self.genBody(case.body);
13875 try self.genBodyBlock(case.body);
1380013876 try self.restoreState(state, &.{}, .{
1380113877 .emit_instructions = false,
1380213878 .update_tracking = true,
......@@ -13814,7 +13890,7 @@ fn lowerSwitchBr(self: *Self, inst: Air.Inst.Index, switch_br: Air.UnwrappedSwit
1381413890 const else_deaths = liveness.deaths.len - 1;
1381513891 for (liveness.deaths[else_deaths]) |operand| try self.processDeath(operand);
1381613892
13817 try self.genBody(else_body);
13893 try self.genBodyBlock(else_body);
1381813894 try self.restoreState(state, &.{}, .{
1381913895 .emit_instructions = false,
1382013896 .update_tracking = true,
src/arch/x86_64/Emit.zig+24
......@@ -287,6 +287,30 @@ pub fn emitMir(emit: *Emit) Error!void {
287287 .none => {},
288288 }
289289 },
290 .pseudo_dbg_enter_block_none => {
291 switch (emit.debug_output) {
292 .dwarf => |dw| {
293 log.debug("mirDbgEnterBlock (line={d}, col={d})", .{
294 emit.prev_di_line, emit.prev_di_column,
295 });
296 try dw.enterBlock(emit.code.items.len);
297 },
298 .plan9 => {},
299 .none => {},
300 }
301 },
302 .pseudo_dbg_leave_block_none => {
303 switch (emit.debug_output) {
304 .dwarf => |dw| {
305 log.debug("mirDbgLeaveBlock (line={d}, col={d})", .{
306 emit.prev_di_line, emit.prev_di_column,
307 });
308 try dw.leaveBlock(emit.code.items.len);
309 },
310 .plan9 => {},
311 .none => {},
312 }
313 },
290314 .pseudo_dbg_enter_inline_func => {
291315 switch (emit.debug_output) {
292316 .dwarf => |dw| {
src/arch/x86_64/Lower.zig+2
......@@ -312,6 +312,8 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
312312 .pseudo_dbg_prologue_end_none,
313313 .pseudo_dbg_line_line_column,
314314 .pseudo_dbg_epilogue_begin_none,
315 .pseudo_dbg_enter_block_none,
316 .pseudo_dbg_leave_block_none,
315317 .pseudo_dbg_enter_inline_func,
316318 .pseudo_dbg_leave_inline_func,
317319 .pseudo_dbg_local_a,
src/arch/x86_64/Mir.zig+4
......@@ -935,6 +935,10 @@ pub const Inst = struct {
935935 pseudo_dbg_line_line_column,
936936 /// Start of epilogue
937937 pseudo_dbg_epilogue_begin_none,
938 /// Start of lexical block
939 pseudo_dbg_enter_block_none,
940 /// End of lexical block
941 pseudo_dbg_leave_block_none,
938942 /// Start of inline function
939943 pseudo_dbg_enter_inline_func,
940944 /// End of inline function
src/arch/x86_64/encoder.zig+4-4
......@@ -233,7 +233,7 @@ pub const Instruction = struct {
233233 _ = unused_format_string;
234234 _ = options;
235235 _ = writer;
236 @compileError("do not format Operand directly; use fmtPrint() instead");
236 @compileError("do not format Operand directly; use fmt() instead");
237237 }
238238
239239 const FormatContext = struct {
......@@ -241,7 +241,7 @@ pub const Instruction = struct {
241241 enc_op: Encoding.Op,
242242 };
243243
244 fn fmt(
244 fn fmtContext(
245245 ctx: FormatContext,
246246 comptime unused_format_string: []const u8,
247247 options: std.fmt.FormatOptions,
......@@ -309,7 +309,7 @@ pub const Instruction = struct {
309309 }
310310 }
311311
312 pub fn fmtPrint(op: Operand, enc_op: Encoding.Op) std.fmt.Formatter(fmt) {
312 pub fn fmt(op: Operand, enc_op: Encoding.Op) std.fmt.Formatter(fmtContext) {
313313 return .{ .data = .{ .op = op, .enc_op = enc_op } };
314314 }
315315 };
......@@ -373,7 +373,7 @@ pub const Instruction = struct {
373373 if (op == .none) break;
374374 if (i > 0) try writer.writeByte(',');
375375 try writer.writeByte(' ');
376 try writer.print("{}", .{op.fmtPrint(enc)});
376 try writer.print("{}", .{op.fmt(enc)});
377377 }
378378 }
379379
src/link/Dwarf.zig+95-64
......@@ -1374,10 +1374,11 @@ pub const WipNav = struct {
13741374 any_children: bool,
13751375 func: InternPool.Index,
13761376 func_sym_index: u32,
1377 func_high_reloc: u32,
1378 inlined_funcs: std.ArrayListUnmanaged(struct {
1377 func_high_pc: u32,
1378 blocks: std.ArrayListUnmanaged(struct {
13791379 abbrev_code: u32,
1380 high_reloc: u32,
1380 low_pc_off: u64,
1381 high_pc: u32,
13811382 }),
13821383 cfi: struct {
13831384 loc: u32,
......@@ -1391,7 +1392,7 @@ pub const WipNav = struct {
13911392
13921393 pub fn deinit(wip_nav: *WipNav) void {
13931394 const gpa = wip_nav.dwarf.gpa;
1394 if (wip_nav.func != .none) wip_nav.inlined_funcs.deinit(gpa);
1395 if (wip_nav.func != .none) wip_nav.blocks.deinit(gpa);
13951396 wip_nav.debug_frame.deinit(gpa);
13961397 wip_nav.debug_info.deinit(gpa);
13971398 wip_nav.debug_line.deinit(gpa);
......@@ -1486,49 +1487,72 @@ pub const WipNav = struct {
14861487 try dlw.writeByte(DW.LNS.set_epilogue_begin);
14871488 }
14881489
1489 pub fn enterInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64, line: u32, column: u32) UpdateError!void {
1490 pub fn enterBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void {
1491 const dwarf = wip_nav.dwarf;
1492 const diw = wip_nav.debug_info.writer(dwarf.gpa);
1493 const block = try wip_nav.blocks.addOne(dwarf.gpa);
1494
1495 block.abbrev_code = @intCast(wip_nav.debug_info.items.len);
1496 try wip_nav.abbrevCode(.block);
1497 block.low_pc_off = code_off;
1498 try wip_nav.infoAddrSym(wip_nav.func_sym_index, code_off);
1499 block.high_pc = @intCast(wip_nav.debug_info.items.len);
1500 try diw.writeInt(u32, 0, dwarf.endian);
1501 wip_nav.any_children = false;
1502 }
1503
1504 pub fn leaveBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void {
1505 const block_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.block));
1506 const block = wip_nav.blocks.pop();
1507 if (wip_nav.any_children)
1508 try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null))
1509 else
1510 std.leb.writeUnsignedFixed(
1511 block_bytes,
1512 wip_nav.debug_info.items[block.abbrev_code..][0..block_bytes],
1513 try wip_nav.dwarf.refAbbrevCode(.empty_block),
1514 );
1515 std.mem.writeInt(u32, wip_nav.debug_info.items[block.high_pc..][0..4], @intCast(code_off - block.low_pc_off), wip_nav.dwarf.endian);
1516 wip_nav.any_children = true;
1517 }
1518
1519 pub fn enterInlineFunc(
1520 wip_nav: *WipNav,
1521 func: InternPool.Index,
1522 code_off: u64,
1523 line: u32,
1524 column: u32,
1525 ) UpdateError!void {
14901526 const dwarf = wip_nav.dwarf;
14911527 const zcu = wip_nav.pt.zcu;
14921528 const diw = wip_nav.debug_info.writer(dwarf.gpa);
1493 const inlined_func = try wip_nav.inlined_funcs.addOne(dwarf.gpa);
1529 const block = try wip_nav.blocks.addOne(dwarf.gpa);
14941530
1495 inlined_func.abbrev_code = @intCast(wip_nav.debug_info.items.len);
1531 block.abbrev_code = @intCast(wip_nav.debug_info.items.len);
14961532 try wip_nav.abbrevCode(.inlined_func);
14971533 try wip_nav.refNav(zcu.funcInfo(func).owner_nav);
14981534 try uleb128(diw, zcu.navSrcLine(zcu.funcInfo(wip_nav.func).owner_nav) + line + 1);
14991535 try uleb128(diw, column + 1);
1500 const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs;
1501 try external_relocs.ensureUnusedCapacity(dwarf.gpa, 2);
1502 external_relocs.appendAssumeCapacity(.{
1503 .source_off = @intCast(wip_nav.debug_info.items.len),
1504 .target_sym = wip_nav.func_sym_index,
1505 .target_off = code_off,
1506 });
1507 try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size));
1508 inlined_func.high_reloc = @intCast(external_relocs.items.len);
1509 external_relocs.appendAssumeCapacity(.{
1510 .source_off = @intCast(wip_nav.debug_info.items.len),
1511 .target_sym = wip_nav.func_sym_index,
1512 .target_off = undefined,
1513 });
1514 try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size));
1536 block.low_pc_off = code_off;
1537 try wip_nav.infoAddrSym(wip_nav.func_sym_index, code_off);
1538 block.high_pc = @intCast(wip_nav.debug_info.items.len);
1539 try diw.writeInt(u32, 0, dwarf.endian);
15151540 try wip_nav.setInlineFunc(func);
15161541 wip_nav.any_children = false;
15171542 }
15181543
15191544 pub fn leaveInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64) UpdateError!void {
15201545 const inlined_func_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.inlined_func));
1521 const inlined_func = wip_nav.inlined_funcs.pop();
1522 const external_relocs = &wip_nav.dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs;
1523 external_relocs.items[inlined_func.high_reloc].target_off = code_off;
1546 const block = wip_nav.blocks.pop();
15241547 if (wip_nav.any_children)
15251548 try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null))
15261549 else
15271550 std.leb.writeUnsignedFixed(
15281551 inlined_func_bytes,
1529 wip_nav.debug_info.items[inlined_func.abbrev_code..][0..inlined_func_bytes],
1552 wip_nav.debug_info.items[block.abbrev_code..][0..inlined_func_bytes],
15301553 try wip_nav.dwarf.refAbbrevCode(.empty_inlined_func),
15311554 );
1555 std.mem.writeInt(u32, wip_nav.debug_info.items[block.high_pc..][0..4], @intCast(code_off - block.low_pc_off), wip_nav.dwarf.endian);
15321556 try wip_nav.setInlineFunc(func);
15331557 wip_nav.any_children = true;
15341558 }
......@@ -1664,17 +1688,18 @@ pub const WipNav = struct {
16641688 return ctx.wip_nav.dwarf.endian;
16651689 }
16661690 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {
1667 try ctx.wip_nav.infoAddrSym(sym_index);
1691 try ctx.wip_nav.infoAddrSym(sym_index, 0);
16681692 }
16691693 } = .{ .wip_nav = wip_nav };
16701694 try uleb128(adapter.writer(), counter.stream.bytes_written);
16711695 try loc.write(adapter);
16721696 }
16731697
1674 fn infoAddrSym(wip_nav: *WipNav, sym_index: u32) UpdateError!void {
1698 fn infoAddrSym(wip_nav: *WipNav, sym_index: u32, sym_off: u64) UpdateError!void {
16751699 try wip_nav.infoExternalReloc(.{
16761700 .source_off = @intCast(wip_nav.debug_info.items.len),
16771701 .target_sym = sym_index,
1702 .target_off = sym_off,
16781703 });
16791704 try wip_nav.debug_info.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));
16801705 }
......@@ -1695,17 +1720,18 @@ pub const WipNav = struct {
16951720 return ctx.wip_nav.dwarf.endian;
16961721 }
16971722 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {
1698 try ctx.wip_nav.frameAddrSym(sym_index);
1723 try ctx.wip_nav.frameAddrSym(sym_index, 0);
16991724 }
17001725 } = .{ .wip_nav = wip_nav };
17011726 try uleb128(adapter.writer(), counter.stream.bytes_written);
17021727 try loc.write(adapter);
17031728 }
17041729
1705 fn frameAddrSym(wip_nav: *WipNav, sym_index: u32) UpdateError!void {
1730 fn frameAddrSym(wip_nav: *WipNav, sym_index: u32, sym_off: u64) UpdateError!void {
17061731 try wip_nav.frameExternalReloc(.{
17071732 .source_off = @intCast(wip_nav.debug_frame.items.len),
17081733 .target_sym = sym_index,
1734 .target_off = sym_off,
17091735 });
17101736 try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));
17111737 }
......@@ -2150,8 +2176,8 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
21502176 .any_children = false,
21512177 .func = .none,
21522178 .func_sym_index = undefined,
2153 .func_high_reloc = undefined,
2154 .inlined_funcs = undefined,
2179 .func_high_pc = undefined,
2180 .blocks = undefined,
21552181 .cfi = undefined,
21562182 .debug_frame = .{},
21572183 .debug_info = .{},
......@@ -2294,7 +2320,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
22942320 const func_type = ip.indexToKey(func.ty).func_type;
22952321 wip_nav.func = nav_val.toIntern();
22962322 wip_nav.func_sym_index = sym_index;
2297 wip_nav.inlined_funcs = .{};
2323 wip_nav.blocks = .{};
22982324 if (dwarf.debug_frame.header.format != .none) wip_nav.cfi = .{
22992325 .loc = 0,
23002326 .cfa = dwarf.debug_frame.header.initial_instructions[0].def_cfa,
......@@ -2319,7 +2345,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
23192345 .source_off = @intCast(wip_nav.debug_frame.items.len),
23202346 });
23212347 try dfw.writeByteNTimes(0, dwarf.sectionOffsetBytes());
2322 try wip_nav.frameAddrSym(sym_index);
2348 try wip_nav.frameAddrSym(sym_index, 0);
23232349 try dfw.writeByteNTimes(undefined, @intFromEnum(dwarf.address_size));
23242350 },
23252351 .eh_frame => {
......@@ -2346,20 +2372,9 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
23462372 try wip_nav.strp(nav.name.toSlice(ip));
23472373 try wip_nav.strp(nav.fqn.toSlice(ip));
23482374 try wip_nav.refType(Type.fromInterned(func_type.return_type));
2349 const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs;
2350 try external_relocs.ensureUnusedCapacity(dwarf.gpa, 2);
2351 external_relocs.appendAssumeCapacity(.{
2352 .source_off = @intCast(wip_nav.debug_info.items.len),
2353 .target_sym = sym_index,
2354 });
2355 try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size));
2356 wip_nav.func_high_reloc = @intCast(external_relocs.items.len);
2357 external_relocs.appendAssumeCapacity(.{
2358 .source_off = @intCast(wip_nav.debug_info.items.len),
2359 .target_sym = sym_index,
2360 .target_off = undefined,
2361 });
2362 try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size));
2375 try wip_nav.infoAddrSym(sym_index, 0);
2376 wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len);
2377 try diw.writeInt(u32, 0, dwarf.endian);
23632378 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
23642379 target_info.defaultFunctionAlignment(file.mod.resolved_target.result).toByteUnits().?);
23652380 try diw.writeByte(@intFromBool(false));
......@@ -2466,8 +2481,7 @@ pub fn finishWipNav(
24662481 },
24672482 }
24682483 {
2469 const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs;
2470 external_relocs.items[wip_nav.func_high_reloc].target_off = sym.size;
2484 std.mem.writeInt(u32, wip_nav.debug_info.items[wip_nav.func_high_pc..][0..4], @intCast(sym.size), dwarf.endian);
24712485 if (wip_nav.any_children) {
24722486 const diw = wip_nav.debug_info.writer(dwarf.gpa);
24732487 try uleb128(diw, @intFromEnum(AbbrevCode.null));
......@@ -2562,8 +2576,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
25622576 .any_children = false,
25632577 .func = .none,
25642578 .func_sym_index = undefined,
2565 .func_high_reloc = undefined,
2566 .inlined_funcs = undefined,
2579 .func_high_pc = undefined,
2580 .blocks = undefined,
25672581 .cfi = undefined,
25682582 .debug_frame = .{},
25692583 .debug_info = .{},
......@@ -3036,8 +3050,8 @@ fn updateType(
30363050 .any_children = false,
30373051 .func = .none,
30383052 .func_sym_index = undefined,
3039 .func_high_reloc = undefined,
3040 .inlined_funcs = undefined,
3053 .func_high_pc = undefined,
3054 .blocks = undefined,
30413055 .cfi = undefined,
30423056 .debug_frame = .{},
30433057 .debug_info = .{},
......@@ -3480,8 +3494,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
34803494 .any_children = false,
34813495 .func = .none,
34823496 .func_sym_index = undefined,
3483 .func_high_reloc = undefined,
3484 .inlined_funcs = undefined,
3497 .func_high_pc = undefined,
3498 .blocks = undefined,
34853499 .cfi = undefined,
34863500 .debug_frame = .{},
34873501 .debug_info = .{},
......@@ -3553,8 +3567,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35533567 .any_children = false,
35543568 .func = .none,
35553569 .func_sym_index = undefined,
3556 .func_high_reloc = undefined,
3557 .inlined_funcs = undefined,
3570 .func_high_pc = undefined,
3571 .blocks = undefined,
35583572 .cfi = undefined,
35593573 .debug_frame = .{},
35603574 .debug_info = .{},
......@@ -3756,8 +3770,8 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
37563770 .any_children = false,
37573771 .func = .none,
37583772 .func_sym_index = undefined,
3759 .func_high_reloc = undefined,
3760 .inlined_funcs = undefined,
3773 .func_high_pc = undefined,
3774 .blocks = undefined,
37613775 .cfi = undefined,
37623776 .debug_frame = .{},
37633777 .debug_info = .{},
......@@ -4212,6 +4226,8 @@ const AbbrevCode = enum {
42124226 empty_packed_struct_type,
42134227 union_type,
42144228 empty_union_type,
4229 empty_block,
4230 block,
42154231 empty_inlined_func,
42164232 inlined_func,
42174233 local_arg,
......@@ -4319,7 +4335,7 @@ const AbbrevCode = enum {
43194335 .{ .linkage_name, .strp },
43204336 .{ .type, .ref_addr },
43214337 .{ .low_pc, .addr },
4322 .{ .high_pc, .addr },
4338 .{ .high_pc, .data4 },
43234339 .{ .alignment, .udata },
43244340 .{ .external, .flag },
43254341 .{ .noreturn, .flag },
......@@ -4331,7 +4347,7 @@ const AbbrevCode = enum {
43314347 .{ .linkage_name, .strp },
43324348 .{ .type, .ref_addr },
43334349 .{ .low_pc, .addr },
4334 .{ .high_pc, .addr },
4350 .{ .high_pc, .data4 },
43354351 .{ .alignment, .udata },
43364352 .{ .external, .flag },
43374353 .{ .noreturn, .flag },
......@@ -4672,6 +4688,21 @@ const AbbrevCode = enum {
46724688 .{ .alignment, .udata },
46734689 },
46744690 },
4691 .empty_block = .{
4692 .tag = .lexical_block,
4693 .attrs = &.{
4694 .{ .low_pc, .addr },
4695 .{ .high_pc, .data4 },
4696 },
4697 },
4698 .block = .{
4699 .tag = .lexical_block,
4700 .children = true,
4701 .attrs = &.{
4702 .{ .low_pc, .addr },
4703 .{ .high_pc, .data4 },
4704 },
4705 },
46754706 .empty_inlined_func = .{
46764707 .tag = .inlined_subroutine,
46774708 .attrs = &.{
......@@ -4679,7 +4710,7 @@ const AbbrevCode = enum {
46794710 .{ .call_line, .udata },
46804711 .{ .call_column, .udata },
46814712 .{ .low_pc, .addr },
4682 .{ .high_pc, .addr },
4713 .{ .high_pc, .data4 },
46834714 },
46844715 },
46854716 .inlined_func = .{
......@@ -4690,7 +4721,7 @@ const AbbrevCode = enum {
46904721 .{ .call_line, .udata },
46914722 .{ .call_column, .udata },
46924723 .{ .low_pc, .addr },
4693 .{ .high_pc, .addr },
4724 .{ .high_pc, .data4 },
46944725 },
46954726 },
46964727 .local_arg = .{
test/src/Debugger.zig+286-199
......@@ -113,70 +113,70 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
113113 &.{
114114 \\(lldb) frame variable --show-types -- basic
115115 \\(root.basic.Basic) basic = {
116 \\ (void) void = {}
117 \\ (bool) bool_false = false
118 \\ (bool) bool_true = true
119 \\ (u0) u0_0 = 0
120 \\ (u1) u1_0 = 0
121 \\ (u1) u1_1 = 1
122 \\ (u2) u2_0 = 0
123 \\ (u2) u2_3 = 3
124 \\ (u3) u3_0 = 0
125 \\ (u3) u3_7 = 7
126 \\ (u4) u4_0 = 0
127 \\ (u4) u4_15 = 15
128 \\ (u5) u5_0 = 0
129 \\ (u5) u5_31 = 31
130 \\ (u6) u6_0 = 0
131 \\ (u6) u6_63 = 63
132 \\ (u7) u7_0 = 0
133 \\ (u7) u7_127 = 127
134 \\ (u8) u8_0 = 0
135 \\ (u8) u8_255 = 255
136 \\ (u16) u16_0 = 0
137 \\ (u16) u16_65535 = 65535
138 \\ (u24) u24_0 = 0
139 \\ (u24) u24_16777215 = 16777215
140 \\ (u32) u32_0 = 0
141 \\ (u32) u32_4294967295 = 4294967295
142 \\ (i0) i0_0 = 0
143 \\ (i1) i1_-1 = -1
144 \\ (i1) i1_0 = 0
145 \\ (i2) i2_-2 = -2
146 \\ (i2) i2_0 = 0
147 \\ (i2) i2_1 = 1
148 \\ (i3) i3_-4 = -4
149 \\ (i3) i3_0 = 0
150 \\ (i3) i3_3 = 3
151 \\ (i4) i4_-8 = -8
152 \\ (i4) i4_0 = 0
153 \\ (i4) i4_7 = 7
154 \\ (i5) i5_-16 = -16
155 \\ (i5) i5_0 = 0
156 \\ (i5) i5_15 = 15
157 \\ (i6) i6_-32 = -32
158 \\ (i6) i6_0 = 0
159 \\ (i6) i6_31 = 31
160 \\ (i7) i7_-64 = -64
161 \\ (i7) i7_0 = 0
162 \\ (i7) i7_63 = 63
163 \\ (i8) i8_-128 = -128
164 \\ (i8) i8_0 = 0
165 \\ (i8) i8_127 = 127
166 \\ (i16) i16_-32768 = -32768
167 \\ (i16) i16_0 = 0
168 \\ (i16) i16_32767 = 32767
169 \\ (i24) i24_-8388608 = -8388608
170 \\ (i24) i24_0 = 0
171 \\ (i24) i24_8388607 = 8388607
172 \\ (i32) i32_-2147483648 = -2147483648
173 \\ (i32) i32_0 = 0
174 \\ (i32) i32_2147483647 = 2147483647
175 \\ (f16) f16_42.625 = 42.625
176 \\ (f32) f32_-2730.65625 = -2730.65625
177 \\ (f64) f64_357913941.33203125 = 357913941.33203125
178 \\ (f80) f80_-91625968981.3330078125 = -91625968981.3330078125
179 \\ (f128) f128_384307168202282325.333332061767578125 = 384307168202282325.333332061767578125
116 \\ (void) .void = {}
117 \\ (bool) .bool_false = false
118 \\ (bool) .bool_true = true
119 \\ (u0) .u0_0 = 0
120 \\ (u1) .u1_0 = 0
121 \\ (u1) .u1_1 = 1
122 \\ (u2) .u2_0 = 0
123 \\ (u2) .u2_3 = 3
124 \\ (u3) .u3_0 = 0
125 \\ (u3) .u3_7 = 7
126 \\ (u4) .u4_0 = 0
127 \\ (u4) .u4_15 = 15
128 \\ (u5) .u5_0 = 0
129 \\ (u5) .u5_31 = 31
130 \\ (u6) .u6_0 = 0
131 \\ (u6) .u6_63 = 63
132 \\ (u7) .u7_0 = 0
133 \\ (u7) .u7_127 = 127
134 \\ (u8) .u8_0 = 0
135 \\ (u8) .u8_255 = 255
136 \\ (u16) .u16_0 = 0
137 \\ (u16) .u16_65535 = 65535
138 \\ (u24) .u24_0 = 0
139 \\ (u24) .u24_16777215 = 16777215
140 \\ (u32) .u32_0 = 0
141 \\ (u32) .u32_4294967295 = 4294967295
142 \\ (i0) .i0_0 = 0
143 \\ (i1) .@"i1_-1" = -1
144 \\ (i1) .i1_0 = 0
145 \\ (i2) .@"i2_-2" = -2
146 \\ (i2) .i2_0 = 0
147 \\ (i2) .i2_1 = 1
148 \\ (i3) .@"i3_-4" = -4
149 \\ (i3) .i3_0 = 0
150 \\ (i3) .i3_3 = 3
151 \\ (i4) .@"i4_-8" = -8
152 \\ (i4) .i4_0 = 0
153 \\ (i4) .i4_7 = 7
154 \\ (i5) .@"i5_-16" = -16
155 \\ (i5) .i5_0 = 0
156 \\ (i5) .i5_15 = 15
157 \\ (i6) .@"i6_-32" = -32
158 \\ (i6) .i6_0 = 0
159 \\ (i6) .i6_31 = 31
160 \\ (i7) .@"i7_-64" = -64
161 \\ (i7) .i7_0 = 0
162 \\ (i7) .i7_63 = 63
163 \\ (i8) .@"i8_-128" = -128
164 \\ (i8) .i8_0 = 0
165 \\ (i8) .i8_127 = 127
166 \\ (i16) .@"i16_-32768" = -32768
167 \\ (i16) .i16_0 = 0
168 \\ (i16) .i16_32767 = 32767
169 \\ (i24) .@"i24_-8388608" = -8388608
170 \\ (i24) .i24_0 = 0
171 \\ (i24) .i24_8388607 = 8388607
172 \\ (i32) .@"i32_-2147483648" = -2147483648
173 \\ (i32) .i32_0 = 0
174 \\ (i32) .i32_2147483647 = 2147483647
175 \\ (f16) .@"f16_42.625" = 42.625
176 \\ (f32) .@"f32_-2730.65625" = -2730.65625
177 \\ (f64) .@"f64_357913941.33203125" = 357913941.33203125
178 \\ (f80) .@"f80_-91625968981.3330078125" = -91625968981.3330078125
179 \\ (f128) .@"f128_384307168202282325.333332061767578125" = 384307168202282325.333332061767578125
180180 \\}
181181 \\(lldb) breakpoint delete --force 1
182182 \\1 breakpoints deleted; 0 breakpoint locations disabled.
......@@ -249,57 +249,57 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
249249 &.{
250250 \\(lldb) frame variable --show-types -- pointers
251251 \\(root.pointers.Pointers) pointers = {
252 \\ (*u32) single = 0x0000000000001010
253 \\ (*const u32) single_const = 0x0000000000001014
254 \\ (*volatile u32) single_volatile = 0x0000000000001018
255 \\ (*const volatile u32) single_const_volatile = 0x000000000000101c
256 \\ (*allowzero u32) single_allowzero = 0x0000000000001020
257 \\ (*allowzero const u32) single_allowzero_const = 0x0000000000001024
258 \\ (*allowzero volatile u32) single_allowzero_volatile = 0x0000000000001028
259 \\ (*allowzero const volatile u32) single_allowzero_const_volatile = 0x000000000000102c
260 \\ ([*]u32) many = 0x0000000000002010
261 \\ ([*]const u32) many_const = 0x0000000000002014
262 \\ ([*]volatile u32) many_volatile = 0x0000000000002018
263 \\ ([*]const volatile u32) many_const_volatile = 0x000000000000201c
264 \\ ([*]allowzero u32) many_allowzero = 0x0000000000002020
265 \\ ([*]allowzero const u32) many_allowzero_const = 0x0000000000002024
266 \\ ([*]allowzero volatile u32) many_allowzero_volatile = 0x0000000000002028
267 \\ ([*]allowzero const volatile u32) many_allowzero_const_volatile = 0x000000000000202c
268 \\ ([]u32) slice = len=1 {
252 \\ (*u32) .single = 0x0000000000001010
253 \\ (*const u32) .single_const = 0x0000000000001014
254 \\ (*volatile u32) .single_volatile = 0x0000000000001018
255 \\ (*const volatile u32) .single_const_volatile = 0x000000000000101c
256 \\ (*allowzero u32) .single_allowzero = 0x0000000000001020
257 \\ (*allowzero const u32) .single_allowzero_const = 0x0000000000001024
258 \\ (*allowzero volatile u32) .single_allowzero_volatile = 0x0000000000001028
259 \\ (*allowzero const volatile u32) .single_allowzero_const_volatile = 0x000000000000102c
260 \\ ([*]u32) .many = 0x0000000000002010
261 \\ ([*]const u32) .many_const = 0x0000000000002014
262 \\ ([*]volatile u32) .many_volatile = 0x0000000000002018
263 \\ ([*]const volatile u32) .many_const_volatile = 0x000000000000201c
264 \\ ([*]allowzero u32) .many_allowzero = 0x0000000000002020
265 \\ ([*]allowzero const u32) .many_allowzero_const = 0x0000000000002024
266 \\ ([*]allowzero volatile u32) .many_allowzero_volatile = 0x0000000000002028
267 \\ ([*]allowzero const volatile u32) .many_allowzero_const_volatile = 0x000000000000202c
268 \\ ([]u32) .slice = len=1 {
269269 \\ (u32) [0] = 3010
270270 \\ }
271 \\ ([]const u32) slice_const = len=2 {
271 \\ ([]const u32) .slice_const = len=2 {
272272 \\ (u32) [0] = 3010
273273 \\ (u32) [1] = 3014
274274 \\ }
275 \\ ([]volatile u32) slice_volatile = len=3 {
275 \\ ([]volatile u32) .slice_volatile = len=3 {
276276 \\ (u32) [0] = 3010
277277 \\ (u32) [1] = 3014
278278 \\ (u32) [2] = 3018
279279 \\ }
280 \\ ([]const volatile u32) slice_const_volatile = len=4 {
280 \\ ([]const volatile u32) .slice_const_volatile = len=4 {
281281 \\ (u32) [0] = 3010
282282 \\ (u32) [1] = 3014
283283 \\ (u32) [2] = 3018
284284 \\ (u32) [3] = 3022
285285 \\ }
286 \\ ([]allowzero u32) slice_allowzero = len=0 {}
287 \\ ([]allowzero const u32) slice_allowzero_const = len=1 {
286 \\ ([]allowzero u32) .slice_allowzero = len=0 {}
287 \\ ([]allowzero const u32) .slice_allowzero_const = len=1 {
288288 \\ (u32) [0] = 3026
289289 \\ }
290 \\ ([]allowzero volatile u32) slice_allowzero_volatile = len=2 {
290 \\ ([]allowzero volatile u32) .slice_allowzero_volatile = len=2 {
291291 \\ (u32) [0] = 3026
292292 \\ (u32) [1] = 3030
293293 \\ }
294 \\ ([]allowzero const volatile u32) slice_allowzero_const_volatile = len=3 {
294 \\ ([]allowzero const volatile u32) .slice_allowzero_const_volatile = len=3 {
295295 \\ (u32) [0] = 3026
296296 \\ (u32) [1] = 3030
297297 \\ (u32) [2] = 3034
298298 \\ }
299 \\ ([*c]u32) c = 0x0000000000004010
300 \\ ([*c]const u32) c_const = 0x0000000000004014
301 \\ ([*c]volatile u32) c_volatile = 0x0000000000004018
302 \\ ([*c]const volatile u32) c_const_volatile = 0x000000000000401c
299 \\ ([*c]u32) .c = 0x0000000000004010
300 \\ ([*c]const u32) .c_const = 0x0000000000004014
301 \\ ([*c]volatile u32) .c_volatile = 0x0000000000004018
302 \\ ([*c]const volatile u32) .c_const_volatile = 0x000000000000401c
303303 \\}
304304 \\(lldb) breakpoint delete --force 1
305305 \\1 breakpoints deleted; 0 breakpoint locations disabled.
......@@ -362,10 +362,10 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
362362 \\}
363363 \\(lldb) frame variable --show-types --format c-string -- strings
364364 \\(root.strings.Strings) strings = {
365 \\ ([*c]const u8) c_ptr = "c_ptr\x07\x08\t"
366 \\ ([*:0]const u8) many_ptr = "many_ptr\n\x0b\x0c"
367 \\ (*const [12:0]u8) ptr_array = "ptr_array\x00\r\x1b"
368 \\ ([:0]const u8) slice = "slice\"\'\\\x00" len=9 {
365 \\ ([*c]const u8) .c_ptr = "c_ptr\x07\x08\t"
366 \\ ([*:0]const u8) .many_ptr = "many_ptr\n\x0b\x0c"
367 \\ (*const [12:0]u8) .ptr_array = "ptr_array\x00\r\x1b"
368 \\ ([:0]const u8) .slice = "slice\"\'\\\x00" len=9 {
369369 \\ (u8) [0] = "s"
370370 \\ (u8) [1] = "l"
371371 \\ (u8) [2] = "i"
......@@ -434,10 +434,10 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
434434 \\}
435435 \\(lldb) frame variable --show-types -- enums
436436 \\(root.enums.Enums) enums = {
437 \\ (root.enums.Enums.Zero) zero = @enumFromInt(13)
438 \\ (root.enums.Enums.One) one = .first
439 \\ (root.enums.Enums.Two) two = @enumFromInt(-1234)
440 \\ (root.enums.Enums.Three) three = .second
437 \\ (root.enums.Enums.Zero) .zero = @enumFromInt(13)
438 \\ (root.enums.Enums.One) .one = .first
439 \\ (root.enums.Enums.Two) .two = @enumFromInt(-1234)
440 \\ (root.enums.Enums.Three) .three = .second
441441 \\}
442442 \\(lldb) breakpoint delete --force 1
443443 \\1 breakpoints deleted; 0 breakpoint locations disabled.
......@@ -498,15 +498,15 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
498498 \\}
499499 \\(lldb) frame variable --show-types -- errors
500500 \\(root.errors.Errors) errors = {
501 \\ (error{One}) one = error.One
502 \\ (error{One,Two}) two = error.Two
503 \\ (error{One,Two,Three}) three = error.Three
504 \\ (anyerror) any = error.Any
505 \\ (anyerror!void) any_void = {
506 \\ (anyerror) error = error.NotVoid
501 \\ (error{One}) .one = error.One
502 \\ (error{One,Two}) .two = error.Two
503 \\ (error{One,Two,Three}) .three = error.Three
504 \\ (anyerror) .any = error.Any
505 \\ (anyerror!void) .any_void = {
506 \\ (anyerror) .error = error.NotVoid
507507 \\ }
508 \\ (error{One}!u32) any_u32 = {
509 \\ (u32) value = 42
508 \\ (error{One}!u32) .any_u32 = {
509 \\ (u32) .value = 42
510510 \\ }
511511 \\}
512512 \\(lldb) breakpoint delete --force 1
......@@ -630,17 +630,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
630630 \\}
631631 \\(lldb) frame variable --show-types -- unions
632632 \\(root.unions.Unions) unions = {
633 \\ (root.unions.Unions.Untagged) untagged = {
634 \\ (u32) u32 = 3217031168
635 \\ (i32) i32 = -1077936128
636 \\ (f32) f32 = -1.5
633 \\ (root.unions.Unions.Untagged) .untagged = {
634 \\ (u32) .u32 = 3217031168
635 \\ (i32) .i32 = -1077936128
636 \\ (f32) .f32 = -1.5
637637 \\ }
638 \\ (root.unions.Unions.SafetyTagged) safety_tagged = {
639 \\ (root.unions.Unions.Enum) en = .second
638 \\ (root.unions.Unions.SafetyTagged) .safety_tagged = {
639 \\ (root.unions.Unions.Enum) .en = .second
640640 \\ }
641 \\ (root.unions.Unions.Tagged) tagged = {
642 \\ (error{Error}!root.unions.Unions.Enum) eu = {
643 \\ (error{Error}) error = error.Error
641 \\ (root.unions.Unions.Tagged) .tagged = {
642 \\ (error{Error}!root.unions.Unions.Enum) .eu = {
643 \\ (error{Error}) .error = error.Error
644644 \\ }
645645 \\ }
646646 \\}
......@@ -721,6 +721,93 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
721721 \\1 breakpoints deleted; 0 breakpoint locations disabled.
722722 },
723723 );
724 db.addLldbTest(
725 "if_blocks",
726 target,
727 &.{
728 .{
729 .path = "if_blocks.zig",
730 .source =
731 \\pub fn main() void {
732 \\ for (0..2) |i| {
733 \\ if (i == 0) {
734 \\ var x: u32 = 123;
735 \\ _ = &x;
736 \\ } else {
737 \\ var x: f32 = 4.5;
738 \\ _ = &x;
739 \\ }
740 \\ }
741 \\}
742 \\
743 ,
744 },
745 },
746 \\breakpoint set --file if_blocks.zig --source-pattern-regexp '_ = &x;'
747 \\process launch
748 \\frame variable
749 \\process continue
750 \\frame variable
751 \\breakpoint delete --force 1
752 ,
753 &.{
754 \\(lldb) frame variable
755 \\(usize) i = 0
756 \\(u32) x = 123
757 \\(lldb) process continue
758 ,
759 \\(lldb) frame variable
760 \\(usize) i = 1
761 \\(f32) x = 4.5
762 \\(lldb) breakpoint delete --force 1
763 \\1 breakpoints deleted; 0 breakpoint locations disabled.
764 },
765 );
766 db.addLldbTest(
767 "switch_blocks",
768 target,
769 &.{
770 .{
771 .path = "switch_blocks.zig",
772 .source =
773 \\pub fn main() void {
774 \\ for (0..2) |i| {
775 \\ switch (i) {
776 \\ 0 => {
777 \\ var x: u32 = 123;
778 \\ _ = &x;
779 \\ },
780 \\ else => {
781 \\ var x: f32 = 4.5;
782 \\ _ = &x;
783 \\ },
784 \\ }
785 \\ }
786 \\}
787 \\
788 ,
789 },
790 },
791 \\breakpoint set --file switch_blocks.zig --source-pattern-regexp '_ = &x;'
792 \\process launch
793 \\frame variable
794 \\process continue
795 \\frame variable
796 \\breakpoint delete --force 1
797 ,
798 &.{
799 \\(lldb) frame variable
800 \\(usize) i = 0
801 \\(u32) x = 123
802 \\(lldb) process continue
803 ,
804 \\(lldb) frame variable
805 \\(usize) i = 1
806 \\(f32) x = 4.5
807 \\(lldb) breakpoint delete --force 1
808 \\1 breakpoints deleted; 0 breakpoint locations disabled.
809 },
810 );
724811 db.addLldbTest(
725812 "inline_call",
726813 target,
......@@ -1370,24 +1457,24 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
13701457 \\(lldb) frame variable --show-types -- map.unmanaged
13711458 \\(std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63)) map.unmanaged = len=5 capacity=16 {
13721459 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [0] = {
1373 \\ (u32) key = 0
1374 \\ (u32) value = 1
1460 \\ (u32) .key = 0
1461 \\ (u32) .value = 1
13751462 \\ }
13761463 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [1] = {
1377 \\ (u32) key = 2
1378 \\ (u32) value = 3
1464 \\ (u32) .key = 2
1465 \\ (u32) .value = 3
13791466 \\ }
13801467 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [2] = {
1381 \\ (u32) key = 4
1382 \\ (u32) value = 5
1468 \\ (u32) .key = 4
1469 \\ (u32) .value = 5
13831470 \\ }
13841471 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [3] = {
1385 \\ (u32) key = 6
1386 \\ (u32) value = 7
1472 \\ (u32) .key = 6
1473 \\ (u32) .value = 7
13871474 \\ }
13881475 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [4] = {
1389 \\ (u32) key = 8
1390 \\ (u32) value = 9
1476 \\ (u32) .key = 8
1477 \\ (u32) .value = 9
13911478 \\ }
13921479 \\}
13931480 \\(lldb) breakpoint delete --force 1
......@@ -1447,37 +1534,37 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
14471534 \\(lldb) frame variable --show-types -- list0 list0.len list0.capacity list0[0] list0[1] list0[2] list0.0 list0.1 list0.2
14481535 \\(std.multi_array_list.MultiArrayList(main.Elem0)) list0 = len=3 capacity=8 {
14491536 \\ (root.main.Elem0) [0] = {
1450 \\ (u32) 0 = 1
1451 \\ (u8) 1 = 2
1452 \\ (u16) 2 = 3
1537 \\ (u32) .@"0" = 1
1538 \\ (u8) .@"1" = 2
1539 \\ (u16) .@"2" = 3
14531540 \\ }
14541541 \\ (root.main.Elem0) [1] = {
1455 \\ (u32) 0 = 4
1456 \\ (u8) 1 = 5
1457 \\ (u16) 2 = 6
1542 \\ (u32) .@"0" = 4
1543 \\ (u8) .@"1" = 5
1544 \\ (u16) .@"2" = 6
14581545 \\ }
14591546 \\ (root.main.Elem0) [2] = {
1460 \\ (u32) 0 = 7
1461 \\ (u8) 1 = 8
1462 \\ (u16) 2 = 9
1547 \\ (u32) .@"0" = 7
1548 \\ (u8) .@"1" = 8
1549 \\ (u16) .@"2" = 9
14631550 \\ }
14641551 \\}
14651552 \\(usize) list0.len = 3
14661553 \\(usize) list0.capacity = 8
14671554 \\(root.main.Elem0) list0[0] = {
1468 \\ (u32) 0 = 1
1469 \\ (u8) 1 = 2
1470 \\ (u16) 2 = 3
1555 \\ (u32) .@"0" = 1
1556 \\ (u8) .@"1" = 2
1557 \\ (u16) .@"2" = 3
14711558 \\}
14721559 \\(root.main.Elem0) list0[1] = {
1473 \\ (u32) 0 = 4
1474 \\ (u8) 1 = 5
1475 \\ (u16) 2 = 6
1560 \\ (u32) .@"0" = 4
1561 \\ (u8) .@"1" = 5
1562 \\ (u16) .@"2" = 6
14761563 \\}
14771564 \\(root.main.Elem0) list0[2] = {
1478 \\ (u32) 0 = 7
1479 \\ (u8) 1 = 8
1480 \\ (u16) 2 = 9
1565 \\ (u32) .@"0" = 7
1566 \\ (u8) .@"1" = 8
1567 \\ (u16) .@"2" = 9
14811568 \\}
14821569 \\([3]u32) list0.0 = {
14831570 \\ (u32) [0] = 1
......@@ -1497,37 +1584,37 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
14971584 \\(lldb) frame variable --show-types -- slice0 slice0.len slice0.capacity slice0[0] slice0[1] slice0[2] slice0.0 slice0.1 slice0.2
14981585 \\(std.multi_array_list.MultiArrayList(main.Elem0).Slice) slice0 = len=3 capacity=8 {
14991586 \\ (root.main.Elem0) [0] = {
1500 \\ (u32) 0 = 1
1501 \\ (u8) 1 = 2
1502 \\ (u16) 2 = 3
1587 \\ (u32) .@"0" = 1
1588 \\ (u8) .@"1" = 2
1589 \\ (u16) .@"2" = 3
15031590 \\ }
15041591 \\ (root.main.Elem0) [1] = {
1505 \\ (u32) 0 = 4
1506 \\ (u8) 1 = 5
1507 \\ (u16) 2 = 6
1592 \\ (u32) .@"0" = 4
1593 \\ (u8) .@"1" = 5
1594 \\ (u16) .@"2" = 6
15081595 \\ }
15091596 \\ (root.main.Elem0) [2] = {
1510 \\ (u32) 0 = 7
1511 \\ (u8) 1 = 8
1512 \\ (u16) 2 = 9
1597 \\ (u32) .@"0" = 7
1598 \\ (u8) .@"1" = 8
1599 \\ (u16) .@"2" = 9
15131600 \\ }
15141601 \\}
15151602 \\(usize) slice0.len = 3
15161603 \\(usize) slice0.capacity = 8
15171604 \\(root.main.Elem0) slice0[0] = {
1518 \\ (u32) 0 = 1
1519 \\ (u8) 1 = 2
1520 \\ (u16) 2 = 3
1605 \\ (u32) .@"0" = 1
1606 \\ (u8) .@"1" = 2
1607 \\ (u16) .@"2" = 3
15211608 \\}
15221609 \\(root.main.Elem0) slice0[1] = {
1523 \\ (u32) 0 = 4
1524 \\ (u8) 1 = 5
1525 \\ (u16) 2 = 6
1610 \\ (u32) .@"0" = 4
1611 \\ (u8) .@"1" = 5
1612 \\ (u16) .@"2" = 6
15261613 \\}
15271614 \\(root.main.Elem0) slice0[2] = {
1528 \\ (u32) 0 = 7
1529 \\ (u8) 1 = 8
1530 \\ (u16) 2 = 9
1615 \\ (u32) .@"0" = 7
1616 \\ (u8) .@"1" = 8
1617 \\ (u16) .@"2" = 9
15311618 \\}
15321619 \\([3]u32) slice0.0 = {
15331620 \\ (u32) [0] = 1
......@@ -1547,37 +1634,37 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
15471634 \\(lldb) frame variable --show-types -- list1 list1.len list1.capacity list1[0] list1[1] list1[2] list1.a list1.b list1.c
15481635 \\(std.multi_array_list.MultiArrayList(main.Elem1)) list1 = len=3 capacity=12 {
15491636 \\ (root.main.Elem1) [0] = {
1550 \\ (u32) a = 1
1551 \\ (u8) b = 2
1552 \\ (u16) c = 3
1637 \\ (u32) .a = 1
1638 \\ (u8) .b = 2
1639 \\ (u16) .c = 3
15531640 \\ }
15541641 \\ (root.main.Elem1) [1] = {
1555 \\ (u32) a = 4
1556 \\ (u8) b = 5
1557 \\ (u16) c = 6
1642 \\ (u32) .a = 4
1643 \\ (u8) .b = 5
1644 \\ (u16) .c = 6
15581645 \\ }
15591646 \\ (root.main.Elem1) [2] = {
1560 \\ (u32) a = 7
1561 \\ (u8) b = 8
1562 \\ (u16) c = 9
1647 \\ (u32) .a = 7
1648 \\ (u8) .b = 8
1649 \\ (u16) .c = 9
15631650 \\ }
15641651 \\}
15651652 \\(usize) list1.len = 3
15661653 \\(usize) list1.capacity = 12
15671654 \\(root.main.Elem1) list1[0] = {
1568 \\ (u32) a = 1
1569 \\ (u8) b = 2
1570 \\ (u16) c = 3
1655 \\ (u32) .a = 1
1656 \\ (u8) .b = 2
1657 \\ (u16) .c = 3
15711658 \\}
15721659 \\(root.main.Elem1) list1[1] = {
1573 \\ (u32) a = 4
1574 \\ (u8) b = 5
1575 \\ (u16) c = 6
1660 \\ (u32) .a = 4
1661 \\ (u8) .b = 5
1662 \\ (u16) .c = 6
15761663 \\}
15771664 \\(root.main.Elem1) list1[2] = {
1578 \\ (u32) a = 7
1579 \\ (u8) b = 8
1580 \\ (u16) c = 9
1665 \\ (u32) .a = 7
1666 \\ (u8) .b = 8
1667 \\ (u16) .c = 9
15811668 \\}
15821669 \\([3]u32) list1.a = {
15831670 \\ (u32) [0] = 1
......@@ -1597,37 +1684,37 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
15971684 \\(lldb) frame variable --show-types -- slice1 slice1.len slice1.capacity slice1[0] slice1[1] slice1[2] slice1.a slice1.b slice1.c
15981685 \\(std.multi_array_list.MultiArrayList(main.Elem1).Slice) slice1 = len=3 capacity=12 {
15991686 \\ (root.main.Elem1) [0] = {
1600 \\ (u32) a = 1
1601 \\ (u8) b = 2
1602 \\ (u16) c = 3
1687 \\ (u32) .a = 1
1688 \\ (u8) .b = 2
1689 \\ (u16) .c = 3
16031690 \\ }
16041691 \\ (root.main.Elem1) [1] = {
1605 \\ (u32) a = 4
1606 \\ (u8) b = 5
1607 \\ (u16) c = 6
1692 \\ (u32) .a = 4
1693 \\ (u8) .b = 5
1694 \\ (u16) .c = 6
16081695 \\ }
16091696 \\ (root.main.Elem1) [2] = {
1610 \\ (u32) a = 7
1611 \\ (u8) b = 8
1612 \\ (u16) c = 9
1697 \\ (u32) .a = 7
1698 \\ (u8) .b = 8
1699 \\ (u16) .c = 9
16131700 \\ }
16141701 \\}
16151702 \\(usize) slice1.len = 3
16161703 \\(usize) slice1.capacity = 12
16171704 \\(root.main.Elem1) slice1[0] = {
1618 \\ (u32) a = 1
1619 \\ (u8) b = 2
1620 \\ (u16) c = 3
1705 \\ (u32) .a = 1
1706 \\ (u8) .b = 2
1707 \\ (u16) .c = 3
16211708 \\}
16221709 \\(root.main.Elem1) slice1[1] = {
1623 \\ (u32) a = 4
1624 \\ (u8) b = 5
1625 \\ (u16) c = 6
1710 \\ (u32) .a = 4
1711 \\ (u8) .b = 5
1712 \\ (u16) .c = 6
16261713 \\}
16271714 \\(root.main.Elem1) slice1[2] = {
1628 \\ (u32) a = 7
1629 \\ (u8) b = 8
1630 \\ (u16) c = 9
1715 \\ (u32) .a = 7
1716 \\ (u8) .b = 8
1717 \\ (u16) .c = 9
16311718 \\}
16321719 \\([3]u32) slice1.a = {
16331720 \\ (u32) [0] = 1
tools/lldb_pretty_printers.py+8-5
......@@ -1,7 +1,7 @@
11# pretty printing for the zig language, zig standard library, and zig stage 2 compiler.
22# put commands in ~/.lldbinit to run them automatically when starting lldb
33# `command script import /path/to/zig/tools/lldb_pretty_printers.py` to import this file
4# `type category enable zig` to enable pretty printing for the zig language
4# `type category enable zig.lang` to enable pretty printing for the zig language
55# `type category enable zig.std` to enable pretty printing for the zig standard library
66# `type category enable zig.stage2` to enable pretty printing for the zig stage 2 compiler
77import lldb
......@@ -688,11 +688,14 @@ def add(debugger, *, category, regex=False, type, identifier=None, synth=False,
688688def MultiArrayList_Entry(type): return '^multi_array_list\\.MultiArrayList\\(%s\\)\\.Entry__struct_[1-9][0-9]*$' % type
689689
690690def __lldb_init_module(debugger, _=None):
691 # Initialize Zig Categories
692 debugger.HandleCommand('type category define --language c99 zig.lang zig.std')
693
691694 # Initialize Zig Language
692 add(debugger, category='zig', regex=True, type='^\\[\\]', identifier='zig_Slice', synth=True, expand=True, summary='len=${svar%#}')
693 add(debugger, category='zig', type='[]u8', identifier='zig_String', summary=True)
694 add(debugger, category='zig', regex=True, type='^\\?', identifier='zig_Optional', synth=True, summary=True)
695 add(debugger, category='zig', regex=True, type='^(error{.*}|anyerror)!', identifier='zig_ErrorUnion', synth=True, inline_children=True, summary=True)
695 add(debugger, category='zig.lang', regex=True, type='^\\[\\]', identifier='zig_Slice', synth=True, expand=True, summary='len=${svar%#}')
696 add(debugger, category='zig.lang', type='[]u8', identifier='zig_String', summary=True)
697 add(debugger, category='zig.lang', regex=True, type='^\\?', identifier='zig_Optional', synth=True, summary=True)
698 add(debugger, category='zig.lang', regex=True, type='^(error{.*}|anyerror)!', identifier='zig_ErrorUnion', synth=True, inline_children=True, summary=True)
696699
697700 # Initialize Zig Standard Library
698701 add(debugger, category='zig.std', type='mem.Allocator', summary='${var.ptr}')