authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-13 16:22:24+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-13 16:22:24+02:00
log0bf72833307bf500ebec1a08641600f12cda0434
tree396b4784c38c5d9227d98ff63cc9a8469cfe1872
parent4c50a27d682d3241ec73c7130d69d1d2f2553b86

dwarf: gen debug info for arrays


2 files changed, 35 insertions(+), 2 deletions(-)

src/codegen.zig-2
...@@ -203,7 +203,6 @@ pub fn generateSymbol(...@@ -203,7 +203,6 @@ pub fn generateSymbol(
203 },203 },
204 .Array => switch (typed_value.val.tag()) {204 .Array => switch (typed_value.val.tag()) {
205 .bytes => {205 .bytes => {
206 // TODO populate .debug_info for the array
207 const payload = typed_value.val.castTag(.bytes).?;206 const payload = typed_value.val.castTag(.bytes).?;
208 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());207 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
209 // The bytes payload already includes the sentinel, if any208 // The bytes payload already includes the sentinel, if any
...@@ -212,7 +211,6 @@ pub fn generateSymbol(...@@ -212,7 +211,6 @@ pub fn generateSymbol(
212 return Result{ .appended = {} };211 return Result{ .appended = {} };
213 },212 },
214 .aggregate => {213 .aggregate => {
215 // TODO populate .debug_info for the array
216 const elem_vals = typed_value.val.castTag(.aggregate).?.data;214 const elem_vals = typed_value.val.castTag(.aggregate).?.data;
217 const elem_ty = typed_value.ty.elemType();215 const elem_ty = typed_value.ty.elemType();
218 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());216 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
src/link/Dwarf.zig+35
...@@ -270,6 +270,27 @@ pub const DeclState = struct {...@@ -270,6 +270,27 @@ pub const DeclState = struct {
270 try self.addTypeReloc(atom, ty.childType(), @intCast(u32, index), null);270 try self.addTypeReloc(atom, ty.childType(), @intCast(u32, index), null);
271 }271 }
272 },272 },
273 .Array => {
274 // DW.AT.array_type
275 try dbg_info_buffer.append(@enumToInt(AbbrevKind.array_type));
276 // DW.AT.name, DW.FORM.string
277 try dbg_info_buffer.writer().print("{}\x00", .{ty.fmt(target)});
278 // DW.AT.type, DW.FORM.ref4
279 var index = dbg_info_buffer.items.len;
280 try dbg_info_buffer.resize(index + 4);
281 try self.addTypeReloc(atom, ty.childType(), @intCast(u32, index), null);
282 // DW.AT.subrange_type
283 try dbg_info_buffer.append(@enumToInt(AbbrevKind.array_dim));
284 // DW.AT.type, DW.FORM.ref4
285 index = dbg_info_buffer.items.len;
286 try dbg_info_buffer.resize(index + 4);
287 try self.addTypeReloc(atom, Type.usize, @intCast(u32, index), null);
288 // DW.AT.count, DW.FORM.udata
289 const len = ty.arrayLenIncludingSentinel();
290 try leb128.writeULEB128(dbg_info_buffer.writer(), len);
291 // DW.AT.array_type delimit children
292 try dbg_info_buffer.append(0);
293 },
273 .Struct => blk: {294 .Struct => blk: {
274 // DW.AT.structure_type295 // DW.AT.structure_type
275 try dbg_info_buffer.append(@enumToInt(AbbrevKind.struct_type));296 try dbg_info_buffer.append(@enumToInt(AbbrevKind.struct_type));
...@@ -564,6 +585,8 @@ pub const AbbrevKind = enum(u8) {...@@ -564,6 +585,8 @@ pub const AbbrevKind = enum(u8) {
564 pad1,585 pad1,
565 parameter,586 parameter,
566 variable,587 variable,
588 array_type,
589 array_dim,
567};590};
568591
569/// The reloc offset for the virtual address of a function in its Line Number Program.592/// The reloc offset for the virtual address of a function in its Line Number Program.
...@@ -1357,6 +1380,18 @@ pub fn writeDbgAbbrev(self: *Dwarf, file: *File) !void {...@@ -1357,6 +1380,18 @@ pub fn writeDbgAbbrev(self: *Dwarf, file: *File) !void {
1357 DW.AT.name, DW.FORM.string,1380 DW.AT.name, DW.FORM.string,
1358 0,1381 0,
1359 0, // table sentinel1382 0, // table sentinel
1383 @enumToInt(AbbrevKind.array_type),
1384 DW.TAG.array_type, DW.CHILDREN.yes, // header
1385 DW.AT.name, DW.FORM.string,
1386 DW.AT.type, DW.FORM.ref4,
1387 0,
1388 0, // table sentinel
1389 @enumToInt(AbbrevKind.array_dim),
1390 DW.TAG.subrange_type, DW.CHILDREN.no, // header
1391 DW.AT.type, DW.FORM.ref4,
1392 DW.AT.count, DW.FORM.udata,
1393 0,
1394 0, // table sentinel
1360 0,1395 0,
1361 0,1396 0,
1362 0, // section sentinel1397 0, // section sentinel