authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-17 09:27:08-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-17 09:27:15-04:00
logd4e3d0e676fefbe7cf3ba15576ba9574e73a6449
tree1f8b03a0f3192cf007695c864f6633ec0e27b1dc
parentf601aa780ece6288c87a6424039022d5df9769cc

Dwarf: fix and test error unions


2 files changed, 116 insertions(+), 74 deletions(-)

src/link/Dwarf.zig+4-4
...@@ -2485,10 +2485,10 @@ fn updateType(...@@ -2485,10 +2485,10 @@ fn updateType(
2485 {2485 {
2486 try uleb128(diw, @intFromEnum(AbbrevCode.generated_field));2486 try uleb128(diw, @intFromEnum(AbbrevCode.generated_field));
2487 try wip_nav.strp("is_error");2487 try wip_nav.strp("is_error");
2488 const is_error_field_type = Type.fromInterned(try pt.intern(.{2488 try wip_nav.refType(Type.fromInterned(try pt.intern(.{ .int_type = .{
2489 .opt_type = error_union_type.error_set_type,2489 .signedness = .unsigned,
2490 }));2490 .bits = pt.zcu.errorSetBits(),
2491 try wip_nav.refType(is_error_field_type);2491 } })));
2492 try uleb128(diw, error_union_error_set_offset);2492 try uleb128(diw, error_union_error_set_offset);
24932493
2494 try uleb128(diw, @intFromEnum(AbbrevCode.unsigned_tagged_union_field));2494 try uleb128(diw, @intFromEnum(AbbrevCode.unsigned_tagged_union_field));
test/src/Debugger.zig+112-70
...@@ -190,7 +190,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -190,7 +190,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
190 .path = "pointers.zig",190 .path = "pointers.zig",
191 .source =191 .source =
192 \\const Pointers = struct {192 \\const Pointers = struct {
193 \\ var array: [8]u32 = .{193 \\ var array: [7]u32 = .{
194 \\ 3010,194 \\ 3010,
195 \\ 3014,195 \\ 3014,
196 \\ 3018,196 \\ 3018,
...@@ -198,7 +198,6 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -198,7 +198,6 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
198 \\ 3026,198 \\ 3026,
199 \\ 3030,199 \\ 3030,
200 \\ 3034,200 \\ 3034,
201 \\ 3038,
202 \\ };201 \\ };
203 \\202 \\
204 \\ single: *u32 = @ptrFromInt(0x1010),203 \\ single: *u32 = @ptrFromInt(0x1010),
...@@ -222,17 +221,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -222,17 +221,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
222 \\ slice_const: []const u32 = array[0..2],221 \\ slice_const: []const u32 = array[0..2],
223 \\ slice_volatile: []volatile u32 = array[0..3],222 \\ slice_volatile: []volatile u32 = array[0..3],
224 \\ slice_const_volatile: []const volatile u32 = array[0..4],223 \\ slice_const_volatile: []const volatile u32 = array[0..4],
225 \\ slice_allowzero: []allowzero u32 = array[4..5],224 \\ slice_allowzero: []allowzero u32 = array[4..4],
226 \\ slice_const_allowzero: []const allowzero u32 = array[4..6],225 \\ slice_const_allowzero: []const allowzero u32 = array[4..5],
227 \\ slice_volatile_allowzero: []volatile allowzero u32 = array[4..7],226 \\ slice_volatile_allowzero: []volatile allowzero u32 = array[4..6],
228 \\ slice_const_volatile_allowzero: []const volatile allowzero u32 = array[4..8],227 \\ slice_const_volatile_allowzero: []const volatile allowzero u32 = array[4..7],
229 \\228 \\
230 \\ c: [*c]u32 = @ptrFromInt(0x4010),229 \\ c: [*c]u32 = @ptrFromInt(0x4010),
231 \\ c_const: [*c]const u32 = @ptrFromInt(0x4014),230 \\ c_const: [*c]const u32 = @ptrFromInt(0x4014),
232 \\ c_volatile: [*c]volatile u32 = @ptrFromInt(0x4018),231 \\ c_volatile: [*c]volatile u32 = @ptrFromInt(0x4018),
233 \\ c_const_volatile: [*c]const volatile u32 = @ptrFromInt(0x401c),232 \\ c_const_volatile: [*c]const volatile u32 = @ptrFromInt(0x401c),
234 \\};233 \\};
235 \\pub fn testPointers(pointers: Pointers) void {234 \\fn testPointers(pointers: Pointers) void {
236 \\ _ = pointers;235 \\ _ = pointers;
237 \\}236 \\}
238 \\pub fn main() void {237 \\pub fn main() void {
...@@ -266,42 +265,37 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -266,42 +265,37 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
266 \\ ([*]const allowzero u32) many_const_allowzero = 0x0000000000002024265 \\ ([*]const allowzero u32) many_const_allowzero = 0x0000000000002024
267 \\ ([*]volatile allowzero u32) many_volatile_allowzero = 0x0000000000002028266 \\ ([*]volatile allowzero u32) many_volatile_allowzero = 0x0000000000002028
268 \\ ([*]const volatile allowzero u32) many_const_volatile_allowzero = 0x000000000000202c267 \\ ([*]const volatile allowzero u32) many_const_volatile_allowzero = 0x000000000000202c
269 \\ ([]u32) slice = {268 \\ ([]u32) slice = len=1 {
270 \\ (u32) [0] = 3010269 \\ (u32) [0] = 3010
271 \\ }270 \\ }
272 \\ ([]const u32) slice_const = {271 \\ ([]const u32) slice_const = len=2 {
273 \\ (u32) [0] = 3010272 \\ (u32) [0] = 3010
274 \\ (u32) [1] = 3014273 \\ (u32) [1] = 3014
275 \\ }274 \\ }
276 \\ ([]volatile u32) slice_volatile = {275 \\ ([]volatile u32) slice_volatile = len=3 {
277 \\ (u32) [0] = 3010276 \\ (u32) [0] = 3010
278 \\ (u32) [1] = 3014277 \\ (u32) [1] = 3014
279 \\ (u32) [2] = 3018278 \\ (u32) [2] = 3018
280 \\ }279 \\ }
281 \\ ([]const volatile u32) slice_const_volatile = {280 \\ ([]const volatile u32) slice_const_volatile = len=4 {
282 \\ (u32) [0] = 3010281 \\ (u32) [0] = 3010
283 \\ (u32) [1] = 3014282 \\ (u32) [1] = 3014
284 \\ (u32) [2] = 3018283 \\ (u32) [2] = 3018
285 \\ (u32) [3] = 3022284 \\ (u32) [3] = 3022
286 \\ }285 \\ }
287 \\ ([]allowzero u32) slice_allowzero = {286 \\ ([]allowzero u32) slice_allowzero = len=0 {}
287 \\ ([]const allowzero u32) slice_const_allowzero = len=1 {
288 \\ (u32) [0] = 3026288 \\ (u32) [0] = 3026
289 \\ }289 \\ }
290 \\ ([]const allowzero u32) slice_const_allowzero = {290 \\ ([]volatile allowzero u32) slice_volatile_allowzero = len=2 {
291 \\ (u32) [0] = 3026291 \\ (u32) [0] = 3026
292 \\ (u32) [1] = 3030292 \\ (u32) [1] = 3030
293 \\ }293 \\ }
294 \\ ([]volatile allowzero u32) slice_volatile_allowzero = {294 \\ ([]const volatile allowzero u32) slice_const_volatile_allowzero = len=3 {
295 \\ (u32) [0] = 3026295 \\ (u32) [0] = 3026
296 \\ (u32) [1] = 3030296 \\ (u32) [1] = 3030
297 \\ (u32) [2] = 3034297 \\ (u32) [2] = 3034
298 \\ }298 \\ }
299 \\ ([]const volatile allowzero u32) slice_const_volatile_allowzero = {
300 \\ (u32) [0] = 3026
301 \\ (u32) [1] = 3030
302 \\ (u32) [2] = 3034
303 \\ (u32) [3] = 3038
304 \\ }
305 \\ ([*c]u32) c = 0x0000000000004010299 \\ ([*c]u32) c = 0x0000000000004010
306 \\ ([*c]const u32) c_const = 0x0000000000004014300 \\ ([*c]const u32) c_const = 0x0000000000004014
307 \\ ([*c]volatile u32) c_volatile = 0x0000000000004018301 \\ ([*c]volatile u32) c_volatile = 0x0000000000004018
...@@ -311,6 +305,104 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -311,6 +305,104 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
311 \\1 breakpoints deleted; 0 breakpoint locations disabled.305 \\1 breakpoints deleted; 0 breakpoint locations disabled.
312 },306 },
313 );307 );
308 db.addLldbTest(
309 "errors",
310 target,
311 &.{
312 .{
313 .path = "errors.zig",
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 \\}
326 \\pub fn main() void {
327 \\ testErrors(.{});
328 \\}
329 \\
330 ,
331 },
332 },
333 \\breakpoint set --file errors.zig --source-pattern-regexp '_ = errors;'
334 \\process launch
335 \\frame variable --show-types errors
336 \\breakpoint delete --force 1
337 ,
338 &.{
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 \\ }
351 \\}
352 \\(lldb) breakpoint delete --force 1
353 \\1 breakpoints deleted; 0 breakpoint locations disabled.
354 },
355 );
356 db.addLldbTest(
357 "optionals",
358 target,
359 &.{
360 .{
361 .path = "optionals.zig",
362 .source =
363 \\pub fn main() void {
364 \\ {
365 \\ var null_u32: ?u32 = null;
366 \\ var maybe_u32: ?u32 = null;
367 \\ var nonnull_u32: ?u32 = 456;
368 \\ maybe_u32 = 123;
369 \\ _ = .{ &null_u32, &nonnull_u32 };
370 \\ }
371 \\}
372 \\
373 ,
374 },
375 },
376 \\breakpoint set --file optionals.zig --source-pattern-regexp 'maybe_u32 = 123;'
377 \\process launch
378 \\frame variable null_u32 maybe_u32 nonnull_u32
379 \\breakpoint delete --force 1
380 \\
381 \\breakpoint set --file optionals.zig --source-pattern-regexp '_ = .{ &null_u32, &nonnull_u32 };'
382 \\process continue
383 \\frame variable --show-types null_u32 maybe_u32 nonnull_u32
384 \\breakpoint delete --force 2
385 ,
386 &.{
387 \\(lldb) frame variable null_u32 maybe_u32 nonnull_u32
388 \\(?u32) null_u32 = null
389 \\(?u32) maybe_u32 = null
390 \\(?u32) nonnull_u32 = (nonnull_u32.? = 456)
391 \\(lldb) breakpoint delete --force 1
392 \\1 breakpoints deleted; 0 breakpoint locations disabled.
393 ,
394 \\(lldb) frame variable --show-types null_u32 maybe_u32 nonnull_u32
395 \\(?u32) null_u32 = null
396 \\(?u32) maybe_u32 = {
397 \\ (u32) maybe_u32.? = 123
398 \\}
399 \\(?u32) nonnull_u32 = {
400 \\ (u32) nonnull_u32.? = 456
401 \\}
402 \\(lldb) breakpoint delete --force 2
403 \\1 breakpoints deleted; 0 breakpoint locations disabled.
404 },
405 );
314 db.addLldbTest(406 db.addLldbTest(
315 "storage",407 "storage",
316 target,408 target,
...@@ -384,56 +476,6 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -384,56 +476,6 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
384 \\1 breakpoints deleted; 0 breakpoint locations disabled.476 \\1 breakpoints deleted; 0 breakpoint locations disabled.
385 },477 },
386 );478 );
387 db.addLldbTest(
388 "optionals",
389 target,
390 &.{
391 .{
392 .path = "optionals.zig",
393 .source =
394 \\pub fn main() void {
395 \\ {
396 \\ var null_u32: ?u32 = null;
397 \\ var maybe_u32: ?u32 = null;
398 \\ var nonnull_u32: ?u32 = 456;
399 \\ maybe_u32 = 123;
400 \\ _ = .{ &null_u32, &nonnull_u32 };
401 \\ }
402 \\}
403 \\
404 ,
405 },
406 },
407 \\breakpoint set --file optionals.zig --source-pattern-regexp 'maybe_u32 = 123;'
408 \\process launch
409 \\frame variable null_u32 maybe_u32 nonnull_u32
410 \\breakpoint delete --force 1
411 \\
412 \\breakpoint set --file optionals.zig --source-pattern-regexp '_ = .{ &null_u32, &nonnull_u32 };'
413 \\process continue
414 \\frame variable --show-types null_u32 maybe_u32 nonnull_u32
415 \\breakpoint delete --force 2
416 ,
417 &.{
418 \\(lldb) frame variable null_u32 maybe_u32 nonnull_u32
419 \\(?u32) null_u32 = null
420 \\(?u32) maybe_u32 = null
421 \\(?u32) nonnull_u32 = (nonnull_u32.? = 456)
422 \\(lldb) breakpoint delete --force 1
423 \\1 breakpoints deleted; 0 breakpoint locations disabled.
424 ,
425 \\(lldb) frame variable --show-types null_u32 maybe_u32 nonnull_u32
426 \\(?u32) null_u32 = null
427 \\(?u32) maybe_u32 = {
428 \\ (u32) maybe_u32.? = 123
429 \\}
430 \\(?u32) nonnull_u32 = {
431 \\ (u32) nonnull_u32.? = 456
432 \\}
433 \\(lldb) breakpoint delete --force 2
434 \\1 breakpoints deleted; 0 breakpoint locations disabled.
435 },
436 );
437 db.addLldbTest(479 db.addLldbTest(
438 "cross_module_call",480 "cross_module_call",
439 target,481 target,