authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-17 18:47:27-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-08-17 18:47:27-04:00
log2b05e85107dd1c637ab40f8b145b232d18e8d6c6
tree900da9abde9fd672a2e618e2b8f7233c71eab403
parentcf939b096acfca67c87b698827f64d977853d722
parentd4e3d0e676fefbe7cf3ba15576ba9574e73a6449
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21111 from jacobly0/self-dwarf

Dwarf: debug info progress

3 files changed, 210 insertions(+), 81 deletions(-)

lib/std/dwarf/AT.zig-1
...@@ -224,7 +224,6 @@ pub const ZIG_parent = 0x2ccd;...@@ -224,7 +224,6 @@ pub const ZIG_parent = 0x2ccd;
224pub const ZIG_padding = 0x2cce;224pub const ZIG_padding = 0x2cce;
225pub const ZIG_relative_decl = 0x2cd0;225pub const ZIG_relative_decl = 0x2cd0;
226pub const ZIG_decl_line_relative = 0x2cd1;226pub const ZIG_decl_line_relative = 0x2cd1;
227pub const ZIG_is_allowzero = 0x2ce1;
228pub const ZIG_sentinel = 0x2ce2;227pub const ZIG_sentinel = 0x2ce2;
229228
230// UPC extension.229// UPC extension.
src/link/Dwarf.zig+4-6
...@@ -2338,7 +2338,6 @@ fn updateType(...@@ -2338,7 +2338,6 @@ fn updateType(
2338 const ptr_child_type = Type.fromInterned(ptr_type.child);2338 const ptr_child_type = Type.fromInterned(ptr_type.child);
2339 try uleb128(diw, @intFromEnum(AbbrevCode.ptr_type));2339 try uleb128(diw, @intFromEnum(AbbrevCode.ptr_type));
2340 try wip_nav.strp(name);2340 try wip_nav.strp(name);
2341 try diw.writeByte(@intFromBool(ptr_type.flags.is_allowzero));
2342 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse2341 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse
2343 ptr_child_type.abiAlignment(pt).toByteUnits().?);2342 ptr_child_type.abiAlignment(pt).toByteUnits().?);
2344 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));2343 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));
...@@ -2486,10 +2485,10 @@ fn updateType(...@@ -2486,10 +2485,10 @@ fn updateType(
2486 {2485 {
2487 try uleb128(diw, @intFromEnum(AbbrevCode.generated_field));2486 try uleb128(diw, @intFromEnum(AbbrevCode.generated_field));
2488 try wip_nav.strp("is_error");2487 try wip_nav.strp("is_error");
2489 const is_error_field_type = Type.fromInterned(try pt.intern(.{2488 try wip_nav.refType(Type.fromInterned(try pt.intern(.{ .int_type = .{
2490 .opt_type = error_union_type.error_set_type,2489 .signedness = .unsigned,
2491 }));2490 .bits = pt.zcu.errorSetBits(),
2492 try wip_nav.refType(is_error_field_type);2491 } })));
2493 try uleb128(diw, error_union_error_set_offset);2492 try uleb128(diw, error_union_error_set_offset);
24942493
2495 try uleb128(diw, @intFromEnum(AbbrevCode.unsigned_tagged_union_field));2494 try uleb128(diw, @intFromEnum(AbbrevCode.unsigned_tagged_union_field));
...@@ -3612,7 +3611,6 @@ const AbbrevCode = enum(u8) {...@@ -3612,7 +3611,6 @@ const AbbrevCode = enum(u8) {
3612 .tag = .pointer_type,3611 .tag = .pointer_type,
3613 .attrs = &.{3612 .attrs = &.{
3614 .{ .name, .strp },3613 .{ .name, .strp },
3615 .{ .ZIG_is_allowzero, .flag },
3616 .{ .alignment, .udata },3614 .{ .alignment, .udata },
3617 .{ .address_class, .data1 },3615 .{ .address_class, .data1 },
3618 .{ .type, .ref_addr },3616 .{ .type, .ref_addr },
test/src/Debugger.zig+206-74
...@@ -183,114 +183,171 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -183,114 +183,171 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
183 },183 },
184 );184 );
185 db.addLldbTest(185 db.addLldbTest(
186 "storage",186 "pointers",
187 target,187 target,
188 &.{188 &.{
189 .{189 .{
190 .path = "storage.zig",190 .path = "pointers.zig",
191 .source =191 .source =
192 \\const global_const: u64 = 0x19e50dc8d6002077;192 \\const Pointers = struct {
193 \\var global_var: u64 = 0xcc423cec08622e32;193 \\ var array: [7]u32 = .{
194 \\threadlocal var global_threadlocal1: u64 = 0xb4d643528c042121;194 \\ 3010,
195 \\threadlocal var global_threadlocal2: u64 = 0x43faea1cf5ad7a22;195 \\ 3014,
196 \\fn testStorage(196 \\ 3018,
197 \\ param1: u64,197 \\ 3022,
198 \\ param2: u64,198 \\ 3026,
199 \\ param3: u64,199 \\ 3030,
200 \\ param4: u64,200 \\ 3034,
201 \\ param5: u64,201 \\ };
202 \\ param6: u64,202 \\
203 \\ param7: u64,203 \\ single: *u32 = @ptrFromInt(0x1010),
204 \\ param8: u64,204 \\ single_const: *const u32 = @ptrFromInt(0x1014),
205 \\) callconv(.C) void {205 \\ single_volatile: *volatile u32 = @ptrFromInt(0x1018),
206 \\ const local_comptime_val: u64 = global_const *% global_const;206 \\ single_const_volatile: *const volatile u32 = @ptrFromInt(0x101c),
207 \\ const local_comptime_ptr: struct { u64 } = .{ local_comptime_val *% local_comptime_val };207 \\ single_allowzero: *allowzero u32 = @ptrFromInt(0x1020),
208 \\ const local_const: u64 = global_var ^ global_threadlocal1 ^ global_threadlocal2 ^208 \\ single_const_allowzero: *const allowzero u32 = @ptrFromInt(0x1024),
209 \\ param1 ^ param2 ^ param3 ^ param4 ^ param5 ^ param6 ^ param7 ^ param8;209 \\ single_volatile_allowzero: *volatile allowzero u32 = @ptrFromInt(0x1028),
210 \\ var local_var: u64 = local_comptime_ptr[0] ^ local_const;210 \\ single_const_volatile_allowzero: *const volatile allowzero u32 = @ptrFromInt(0x102c),
211 \\ local_var = local_var;211 \\
212 \\ many: [*]u32 = @ptrFromInt(0x2010),
213 \\ many_const: [*]const u32 = @ptrFromInt(0x2014),
214 \\ many_volatile: [*]volatile u32 = @ptrFromInt(0x2018),
215 \\ many_const_volatile: [*]const volatile u32 = @ptrFromInt(0x201c),
216 \\ many_allowzero: [*]allowzero u32 = @ptrFromInt(0x2020),
217 \\ many_const_allowzero: [*]const allowzero u32 = @ptrFromInt(0x2024),
218 \\ many_volatile_allowzero: [*]volatile allowzero u32 = @ptrFromInt(0x2028),
219 \\ many_const_volatile_allowzero: [*]const volatile allowzero u32 = @ptrFromInt(0x202c),
220 \\ slice: []u32 = array[0..1],
221 \\ slice_const: []const u32 = array[0..2],
222 \\ slice_volatile: []volatile u32 = array[0..3],
223 \\ slice_const_volatile: []const volatile u32 = array[0..4],
224 \\ slice_allowzero: []allowzero u32 = array[4..4],
225 \\ slice_const_allowzero: []const allowzero u32 = array[4..5],
226 \\ slice_volatile_allowzero: []volatile allowzero u32 = array[4..6],
227 \\ slice_const_volatile_allowzero: []const volatile allowzero u32 = array[4..7],
228 \\
229 \\ c: [*c]u32 = @ptrFromInt(0x4010),
230 \\ c_const: [*c]const u32 = @ptrFromInt(0x4014),
231 \\ c_volatile: [*c]volatile u32 = @ptrFromInt(0x4018),
232 \\ c_const_volatile: [*c]const volatile u32 = @ptrFromInt(0x401c),
233 \\};
234 \\fn testPointers(pointers: Pointers) void {
235 \\ _ = pointers;
212 \\}236 \\}
213 \\pub fn main() void {237 \\pub fn main() void {
214 \\ testStorage(238 \\ testPointers(.{});
215 \\ 0x6a607e08125c7e00,
216 \\ 0x98944cb2a45a8b51,
217 \\ 0xa320cf10601ee6fb,
218 \\ 0x691ed3535bad3274,
219 \\ 0x63690e6867a5799f,
220 \\ 0x8e163f0ec76067f2,
221 \\ 0xf9a252c455fb4c06,
222 \\ 0xc88533722601e481,
223 \\ );
224 \\}239 \\}
225 \\240 \\
226 ,241 ,
227 },242 },
228 },243 },
229 \\breakpoint set --file storage.zig --source-pattern-regexp 'local_var = local_var;'244 \\breakpoint set --file pointers.zig --source-pattern-regexp '_ = pointers;'
230 \\process launch245 \\process launch
231 \\target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2246 \\frame variable --show-types pointers
232 \\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
233 \\breakpoint delete --force 1247 \\breakpoint delete --force 1
234 ,248 ,
235 &.{249 &.{
236 \\(lldb) target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2250 \\(lldb) frame variable --show-types pointers
237 \\(u64) global_const = 0x19e50dc8d6002077251 \\(root.pointers.Pointers) pointers = {
238 \\(u64) global_var = 0xcc423cec08622e32252 \\ (*u32) single = 0x0000000000001010
239 \\(u64) global_threadlocal1 = 0xb4d643528c042121253 \\ (*const u32) single_const = 0x0000000000001014
240 \\(u64) global_threadlocal2 = 0x43faea1cf5ad7a22254 \\ (*volatile u32) single_volatile = 0x0000000000001018
241 \\(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_var255 \\ (*const volatile u32) single_const_volatile = 0x000000000000101c
242 \\(u64) param1 = 0x6a607e08125c7e00256 \\ (*allowzero u32) single_allowzero = 0x0000000000001020
243 \\(u64) param2 = 0x98944cb2a45a8b51257 \\ (*const allowzero u32) single_const_allowzero = 0x0000000000001024
244 \\(u64) param3 = 0xa320cf10601ee6fb258 \\ (*volatile allowzero u32) single_volatile_allowzero = 0x0000000000001028
245 \\(u64) param4 = 0x691ed3535bad3274259 \\ (*const volatile allowzero u32) single_const_volatile_allowzero = 0x000000000000102c
246 \\(u64) param5 = 0x63690e6867a5799f260 \\ ([*]u32) many = 0x0000000000002010
247 \\(u64) param6 = 0x8e163f0ec76067f2261 \\ ([*]const u32) many_const = 0x0000000000002014
248 \\(u64) param7 = 0xf9a252c455fb4c06262 \\ ([*]volatile u32) many_volatile = 0x0000000000002018
249 \\(u64) param8 = 0xc88533722601e481263 \\ ([*]const volatile u32) many_const_volatile = 0x000000000000201c
250 \\(u64) local_comptime_val = 0x69490636f81df751264 \\ ([*]allowzero u32) many_allowzero = 0x0000000000002020
251 \\(u64) local_comptime_ptr.0 = 0x82e834dae74767a1265 \\ ([*]const allowzero u32) many_const_allowzero = 0x0000000000002024
252 \\(u64) local_const = 0xdffceb8b2f41e205266 \\ ([*]volatile allowzero u32) many_volatile_allowzero = 0x0000000000002028
253 \\(u64) local_var = 0x5d14df51c80685a4267 \\ ([*]const volatile allowzero u32) many_const_volatile_allowzero = 0x000000000000202c
268 \\ ([]u32) slice = len=1 {
269 \\ (u32) [0] = 3010
270 \\ }
271 \\ ([]const u32) slice_const = len=2 {
272 \\ (u32) [0] = 3010
273 \\ (u32) [1] = 3014
274 \\ }
275 \\ ([]volatile u32) slice_volatile = len=3 {
276 \\ (u32) [0] = 3010
277 \\ (u32) [1] = 3014
278 \\ (u32) [2] = 3018
279 \\ }
280 \\ ([]const volatile u32) slice_const_volatile = len=4 {
281 \\ (u32) [0] = 3010
282 \\ (u32) [1] = 3014
283 \\ (u32) [2] = 3018
284 \\ (u32) [3] = 3022
285 \\ }
286 \\ ([]allowzero u32) slice_allowzero = len=0 {}
287 \\ ([]const allowzero u32) slice_const_allowzero = len=1 {
288 \\ (u32) [0] = 3026
289 \\ }
290 \\ ([]volatile allowzero u32) slice_volatile_allowzero = len=2 {
291 \\ (u32) [0] = 3026
292 \\ (u32) [1] = 3030
293 \\ }
294 \\ ([]const volatile allowzero u32) slice_const_volatile_allowzero = len=3 {
295 \\ (u32) [0] = 3026
296 \\ (u32) [1] = 3030
297 \\ (u32) [2] = 3034
298 \\ }
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
303 \\}
254 \\(lldb) breakpoint delete --force 1304 \\(lldb) breakpoint delete --force 1
255 \\1 breakpoints deleted; 0 breakpoint locations disabled.305 \\1 breakpoints deleted; 0 breakpoint locations disabled.
256 },306 },
257 );307 );
258 db.addLldbTest(308 db.addLldbTest(
259 "slices",309 "errors",
260 target,310 target,
261 &.{311 &.{
262 .{312 .{
263 .path = "slices.zig",313 .path = "errors.zig",
264 .source =314 .source =
315 \\const Errors = struct {
316 \\ one: error{One} = error.One,
317 \\ two: error{One,Two} = error.Two,
318 \\ three: error{One,Two,Three} = error.Three,
319 \\ any: anyerror = error.Any,
320 \\ any_void: anyerror!void = error.NotVoid,
321 \\ any_u32: error{One}!u32 = 42,
322 \\};
323 \\fn testErrors(errors: Errors) void {
324 \\ _ = errors;
325 \\}
265 \\pub fn main() void {326 \\pub fn main() void {
266 \\ {327 \\ testErrors(.{});
267 \\ var array: [4]u32 = .{ 1, 2, 4, 8 };
268 \\ const slice: []u32 = &array;
269 \\ _ = slice;
270 \\ }
271 \\}328 \\}
272 \\329 \\
273 ,330 ,
274 },331 },
275 },332 },
276 \\breakpoint set --file slices.zig --source-pattern-regexp '_ = slice;'333 \\breakpoint set --file errors.zig --source-pattern-regexp '_ = errors;'
277 \\process launch334 \\process launch
278 \\frame variable --show-types array slice335 \\frame variable --show-types errors
279 \\breakpoint delete --force 1336 \\breakpoint delete --force 1
280 ,337 ,
281 &.{338 &.{
282 \\(lldb) frame variable --show-types array slice339 \\(lldb) frame variable --show-types errors
283 \\([4]u32) array = {340 \\(root.errors.Errors) errors = {
284 \\ (u32) [0] = 1341 \\ (error{One}) one = error.One
285 \\ (u32) [1] = 2342 \\ (error{One,Two}) two = error.Two
286 \\ (u32) [2] = 4343 \\ (error{One,Two,Three}) three = error.Three
287 \\ (u32) [3] = 8344 \\ (anyerror) any = error.Any
288 \\}345 \\ (anyerror!void) any_void = {
289 \\([]u32) slice = {346 \\ (anyerror) error = error.NotVoid
290 \\ (u32) [0] = 1347 \\ }
291 \\ (u32) [1] = 2348 \\ (error{One}!u32) any_u32 = {
292 \\ (u32) [2] = 4349 \\ (u32) value = 42
293 \\ (u32) [3] = 8350 \\ }
294 \\}351 \\}
295 \\(lldb) breakpoint delete --force 1352 \\(lldb) breakpoint delete --force 1
296 \\1 breakpoints deleted; 0 breakpoint locations disabled.353 \\1 breakpoints deleted; 0 breakpoint locations disabled.
...@@ -346,6 +403,79 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -346,6 +403,79 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
346 \\1 breakpoints deleted; 0 breakpoint locations disabled.403 \\1 breakpoints deleted; 0 breakpoint locations disabled.
347 },404 },
348 );405 );
406 db.addLldbTest(
407 "storage",
408 target,
409 &.{
410 .{
411 .path = "storage.zig",
412 .source =
413 \\const global_const: u64 = 0x19e50dc8d6002077;
414 \\var global_var: u64 = 0xcc423cec08622e32;
415 \\threadlocal var global_threadlocal1: u64 = 0xb4d643528c042121;
416 \\threadlocal var global_threadlocal2: u64 = 0x43faea1cf5ad7a22;
417 \\fn testStorage(
418 \\ param1: u64,
419 \\ param2: u64,
420 \\ param3: u64,
421 \\ param4: u64,
422 \\ param5: u64,
423 \\ param6: u64,
424 \\ param7: u64,
425 \\ param8: u64,
426 \\) callconv(.C) void {
427 \\ const local_comptime_val: u64 = global_const *% global_const;
428 \\ const local_comptime_ptr: struct { u64 } = .{ local_comptime_val *% local_comptime_val };
429 \\ const local_const: u64 = global_var ^ global_threadlocal1 ^ global_threadlocal2 ^
430 \\ param1 ^ param2 ^ param3 ^ param4 ^ param5 ^ param6 ^ param7 ^ param8;
431 \\ var local_var: u64 = local_comptime_ptr[0] ^ local_const;
432 \\ local_var = local_var;
433 \\}
434 \\pub fn main() void {
435 \\ testStorage(
436 \\ 0x6a607e08125c7e00,
437 \\ 0x98944cb2a45a8b51,
438 \\ 0xa320cf10601ee6fb,
439 \\ 0x691ed3535bad3274,
440 \\ 0x63690e6867a5799f,
441 \\ 0x8e163f0ec76067f2,
442 \\ 0xf9a252c455fb4c06,
443 \\ 0xc88533722601e481,
444 \\ );
445 \\}
446 \\
447 ,
448 },
449 },
450 \\breakpoint set --file storage.zig --source-pattern-regexp 'local_var = local_var;'
451 \\process launch
452 \\target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2
453 \\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
454 \\breakpoint delete --force 1
455 ,
456 &.{
457 \\(lldb) target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2
458 \\(u64) global_const = 0x19e50dc8d6002077
459 \\(u64) global_var = 0xcc423cec08622e32
460 \\(u64) global_threadlocal1 = 0xb4d643528c042121
461 \\(u64) global_threadlocal2 = 0x43faea1cf5ad7a22
462 \\(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
463 \\(u64) param1 = 0x6a607e08125c7e00
464 \\(u64) param2 = 0x98944cb2a45a8b51
465 \\(u64) param3 = 0xa320cf10601ee6fb
466 \\(u64) param4 = 0x691ed3535bad3274
467 \\(u64) param5 = 0x63690e6867a5799f
468 \\(u64) param6 = 0x8e163f0ec76067f2
469 \\(u64) param7 = 0xf9a252c455fb4c06
470 \\(u64) param8 = 0xc88533722601e481
471 \\(u64) local_comptime_val = 0x69490636f81df751
472 \\(u64) local_comptime_ptr.0 = 0x82e834dae74767a1
473 \\(u64) local_const = 0xdffceb8b2f41e205
474 \\(u64) local_var = 0x5d14df51c80685a4
475 \\(lldb) breakpoint delete --force 1
476 \\1 breakpoints deleted; 0 breakpoint locations disabled.
477 },
478 );
349 db.addLldbTest(479 db.addLldbTest(
350 "cross_module_call",480 "cross_module_call",
351 target,481 target,
...@@ -358,6 +488,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -358,6 +488,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
358 \\ module.foo(123);488 \\ module.foo(123);
359 \\ module.bar(456);489 \\ module.bar(456);
360 \\}490 \\}
491 \\
361 ,492 ,
362 },493 },
363 .{494 .{
...@@ -370,6 +501,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -370,6 +501,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
370 \\pub inline fn bar(y: u32) void {501 \\pub inline fn bar(y: u32) void {
371 \\ _ = y;502 \\ _ = y;
372 \\}503 \\}
504 \\
373 ,505 ,
374 },506 },
375 },507 },