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;
224224pub const ZIG_padding = 0x2cce;
225225pub const ZIG_relative_decl = 0x2cd0;
226226pub const ZIG_decl_line_relative = 0x2cd1;
227pub const ZIG_is_allowzero = 0x2ce1;
228227pub const ZIG_sentinel = 0x2ce2;
229228
230229// UPC extension.
src/link/Dwarf.zig+4-6
......@@ -2338,7 +2338,6 @@ fn updateType(
23382338 const ptr_child_type = Type.fromInterned(ptr_type.child);
23392339 try uleb128(diw, @intFromEnum(AbbrevCode.ptr_type));
23402340 try wip_nav.strp(name);
2341 try diw.writeByte(@intFromBool(ptr_type.flags.is_allowzero));
23422341 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse
23432342 ptr_child_type.abiAlignment(pt).toByteUnits().?);
23442343 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));
......@@ -2486,10 +2485,10 @@ fn updateType(
24862485 {
24872486 try uleb128(diw, @intFromEnum(AbbrevCode.generated_field));
24882487 try wip_nav.strp("is_error");
2489 const is_error_field_type = Type.fromInterned(try pt.intern(.{
2490 .opt_type = error_union_type.error_set_type,
2491 }));
2492 try wip_nav.refType(is_error_field_type);
2488 try wip_nav.refType(Type.fromInterned(try pt.intern(.{ .int_type = .{
2489 .signedness = .unsigned,
2490 .bits = pt.zcu.errorSetBits(),
2491 } })));
24932492 try uleb128(diw, error_union_error_set_offset);
24942493
24952494 try uleb128(diw, @intFromEnum(AbbrevCode.unsigned_tagged_union_field));
......@@ -3612,7 +3611,6 @@ const AbbrevCode = enum(u8) {
36123611 .tag = .pointer_type,
36133612 .attrs = &.{
36143613 .{ .name, .strp },
3615 .{ .ZIG_is_allowzero, .flag },
36163614 .{ .alignment, .udata },
36173615 .{ .address_class, .data1 },
36183616 .{ .type, .ref_addr },
test/src/Debugger.zig+206-74
......@@ -183,114 +183,171 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
183183 },
184184 );
185185 db.addLldbTest(
186 "storage",
186 "pointers",
187187 target,
188188 &.{
189189 .{
190 .path = "storage.zig",
190 .path = "pointers.zig",
191191 .source =
192 \\const global_const: u64 = 0x19e50dc8d6002077;
193 \\var global_var: u64 = 0xcc423cec08622e32;
194 \\threadlocal var global_threadlocal1: u64 = 0xb4d643528c042121;
195 \\threadlocal var global_threadlocal2: u64 = 0x43faea1cf5ad7a22;
196 \\fn testStorage(
197 \\ param1: u64,
198 \\ param2: u64,
199 \\ param3: u64,
200 \\ param4: u64,
201 \\ param5: u64,
202 \\ param6: u64,
203 \\ param7: u64,
204 \\ param8: u64,
205 \\) callconv(.C) void {
206 \\ const local_comptime_val: u64 = global_const *% global_const;
207 \\ const local_comptime_ptr: struct { u64 } = .{ local_comptime_val *% local_comptime_val };
208 \\ const local_const: u64 = global_var ^ global_threadlocal1 ^ global_threadlocal2 ^
209 \\ param1 ^ param2 ^ param3 ^ param4 ^ param5 ^ param6 ^ param7 ^ param8;
210 \\ var local_var: u64 = local_comptime_ptr[0] ^ local_const;
211 \\ local_var = local_var;
192 \\const Pointers = struct {
193 \\ var array: [7]u32 = .{
194 \\ 3010,
195 \\ 3014,
196 \\ 3018,
197 \\ 3022,
198 \\ 3026,
199 \\ 3030,
200 \\ 3034,
201 \\ };
202 \\
203 \\ single: *u32 = @ptrFromInt(0x1010),
204 \\ single_const: *const u32 = @ptrFromInt(0x1014),
205 \\ single_volatile: *volatile u32 = @ptrFromInt(0x1018),
206 \\ single_const_volatile: *const volatile u32 = @ptrFromInt(0x101c),
207 \\ single_allowzero: *allowzero u32 = @ptrFromInt(0x1020),
208 \\ single_const_allowzero: *const allowzero u32 = @ptrFromInt(0x1024),
209 \\ single_volatile_allowzero: *volatile allowzero u32 = @ptrFromInt(0x1028),
210 \\ single_const_volatile_allowzero: *const volatile allowzero u32 = @ptrFromInt(0x102c),
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;
212236 \\}
213237 \\pub fn main() void {
214 \\ testStorage(
215 \\ 0x6a607e08125c7e00,
216 \\ 0x98944cb2a45a8b51,
217 \\ 0xa320cf10601ee6fb,
218 \\ 0x691ed3535bad3274,
219 \\ 0x63690e6867a5799f,
220 \\ 0x8e163f0ec76067f2,
221 \\ 0xf9a252c455fb4c06,
222 \\ 0xc88533722601e481,
223 \\ );
238 \\ testPointers(.{});
224239 \\}
225240 \\
226241 ,
227242 },
228243 },
229 \\breakpoint set --file storage.zig --source-pattern-regexp 'local_var = local_var;'
244 \\breakpoint set --file pointers.zig --source-pattern-regexp '_ = pointers;'
230245 \\process launch
231 \\target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2
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
246 \\frame variable --show-types pointers
233247 \\breakpoint delete --force 1
234248 ,
235249 &.{
236 \\(lldb) target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2
237 \\(u64) global_const = 0x19e50dc8d6002077
238 \\(u64) global_var = 0xcc423cec08622e32
239 \\(u64) global_threadlocal1 = 0xb4d643528c042121
240 \\(u64) global_threadlocal2 = 0x43faea1cf5ad7a22
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_var
242 \\(u64) param1 = 0x6a607e08125c7e00
243 \\(u64) param2 = 0x98944cb2a45a8b51
244 \\(u64) param3 = 0xa320cf10601ee6fb
245 \\(u64) param4 = 0x691ed3535bad3274
246 \\(u64) param5 = 0x63690e6867a5799f
247 \\(u64) param6 = 0x8e163f0ec76067f2
248 \\(u64) param7 = 0xf9a252c455fb4c06
249 \\(u64) param8 = 0xc88533722601e481
250 \\(u64) local_comptime_val = 0x69490636f81df751
251 \\(u64) local_comptime_ptr.0 = 0x82e834dae74767a1
252 \\(u64) local_const = 0xdffceb8b2f41e205
253 \\(u64) local_var = 0x5d14df51c80685a4
250 \\(lldb) frame variable --show-types pointers
251 \\(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 \\ (*const allowzero u32) single_const_allowzero = 0x0000000000001024
258 \\ (*volatile allowzero u32) single_volatile_allowzero = 0x0000000000001028
259 \\ (*const volatile allowzero u32) single_const_volatile_allowzero = 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 \\ ([*]const allowzero u32) many_const_allowzero = 0x0000000000002024
266 \\ ([*]volatile allowzero u32) many_volatile_allowzero = 0x0000000000002028
267 \\ ([*]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 \\}
254304 \\(lldb) breakpoint delete --force 1
255305 \\1 breakpoints deleted; 0 breakpoint locations disabled.
256306 },
257307 );
258308 db.addLldbTest(
259 "slices",
309 "errors",
260310 target,
261311 &.{
262312 .{
263 .path = "slices.zig",
313 .path = "errors.zig",
264314 .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 \\}
265326 \\pub fn main() void {
266 \\ {
267 \\ var array: [4]u32 = .{ 1, 2, 4, 8 };
268 \\ const slice: []u32 = &array;
269 \\ _ = slice;
270 \\ }
327 \\ testErrors(.{});
271328 \\}
272329 \\
273330 ,
274331 },
275332 },
276 \\breakpoint set --file slices.zig --source-pattern-regexp '_ = slice;'
333 \\breakpoint set --file errors.zig --source-pattern-regexp '_ = errors;'
277334 \\process launch
278 \\frame variable --show-types array slice
335 \\frame variable --show-types errors
279336 \\breakpoint delete --force 1
280337 ,
281338 &.{
282 \\(lldb) frame variable --show-types array slice
283 \\([4]u32) array = {
284 \\ (u32) [0] = 1
285 \\ (u32) [1] = 2
286 \\ (u32) [2] = 4
287 \\ (u32) [3] = 8
288 \\}
289 \\([]u32) slice = {
290 \\ (u32) [0] = 1
291 \\ (u32) [1] = 2
292 \\ (u32) [2] = 4
293 \\ (u32) [3] = 8
339 \\(lldb) frame variable --show-types errors
340 \\(root.errors.Errors) errors = {
341 \\ (error{One}) one = error.One
342 \\ (error{One,Two}) two = error.Two
343 \\ (error{One,Two,Three}) three = error.Three
344 \\ (anyerror) any = error.Any
345 \\ (anyerror!void) any_void = {
346 \\ (anyerror) error = error.NotVoid
347 \\ }
348 \\ (error{One}!u32) any_u32 = {
349 \\ (u32) value = 42
350 \\ }
294351 \\}
295352 \\(lldb) breakpoint delete --force 1
296353 \\1 breakpoints deleted; 0 breakpoint locations disabled.
......@@ -346,6 +403,79 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
346403 \\1 breakpoints deleted; 0 breakpoint locations disabled.
347404 },
348405 );
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 );
349479 db.addLldbTest(
350480 "cross_module_call",
351481 target,
......@@ -358,6 +488,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
358488 \\ module.foo(123);
359489 \\ module.bar(456);
360490 \\}
491 \\
361492 ,
362493 },
363494 .{
......@@ -370,6 +501,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
370501 \\pub inline fn bar(y: u32) void {
371502 \\ _ = y;
372503 \\}
504 \\
373505 ,
374506 },
375507 },