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(
203203 },
204204 .Array => switch (typed_value.val.tag()) {
205205 .bytes => {
206 // TODO populate .debug_info for the array
207206 const payload = typed_value.val.castTag(.bytes).?;
208207 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
209208 // The bytes payload already includes the sentinel, if any
......@@ -212,7 +211,6 @@ pub fn generateSymbol(
212211 return Result{ .appended = {} };
213212 },
214213 .aggregate => {
215 // TODO populate .debug_info for the array
216214 const elem_vals = typed_value.val.castTag(.aggregate).?.data;
217215 const elem_ty = typed_value.ty.elemType();
218216 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
src/link/Dwarf.zig+35
......@@ -270,6 +270,27 @@ pub const DeclState = struct {
270270 try self.addTypeReloc(atom, ty.childType(), @intCast(u32, index), null);
271271 }
272272 },
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 },
273294 .Struct => blk: {
274295 // DW.AT.structure_type
275296 try dbg_info_buffer.append(@enumToInt(AbbrevKind.struct_type));
......@@ -564,6 +585,8 @@ pub const AbbrevKind = enum(u8) {
564585 pad1,
565586 parameter,
566587 variable,
588 array_type,
589 array_dim,
567590};
568591
569592/// 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 {
13571380 DW.AT.name, DW.FORM.string,
13581381 0,
13591382 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
13601395 0,
13611396 0,
13621397 0, // section sentinel