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(
24852485 {
24862486 try uleb128(diw, @intFromEnum(AbbrevCode.generated_field));
24872487 try wip_nav.strp("is_error");
2488 const is_error_field_type = Type.fromInterned(try pt.intern(.{
2489 .opt_type = error_union_type.error_set_type,
2490 }));
2491 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 } })));
24922492 try uleb128(diw, error_union_error_set_offset);
24932493
24942494 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 {
190190 .path = "pointers.zig",
191191 .source =
192192 \\const Pointers = struct {
193 \\ var array: [8]u32 = .{
193 \\ var array: [7]u32 = .{
194194 \\ 3010,
195195 \\ 3014,
196196 \\ 3018,
......@@ -198,7 +198,6 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
198198 \\ 3026,
199199 \\ 3030,
200200 \\ 3034,
201 \\ 3038,
202201 \\ };
203202 \\
204203 \\ single: *u32 = @ptrFromInt(0x1010),
......@@ -222,17 +221,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
222221 \\ slice_const: []const u32 = array[0..2],
223222 \\ slice_volatile: []volatile u32 = array[0..3],
224223 \\ slice_const_volatile: []const volatile u32 = array[0..4],
225 \\ slice_allowzero: []allowzero u32 = array[4..5],
226 \\ slice_const_allowzero: []const allowzero u32 = array[4..6],
227 \\ slice_volatile_allowzero: []volatile allowzero u32 = array[4..7],
228 \\ slice_const_volatile_allowzero: []const volatile allowzero u32 = array[4..8],
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],
229228 \\
230229 \\ c: [*c]u32 = @ptrFromInt(0x4010),
231230 \\ c_const: [*c]const u32 = @ptrFromInt(0x4014),
232231 \\ c_volatile: [*c]volatile u32 = @ptrFromInt(0x4018),
233232 \\ c_const_volatile: [*c]const volatile u32 = @ptrFromInt(0x401c),
234233 \\};
235 \\pub fn testPointers(pointers: Pointers) void {
234 \\fn testPointers(pointers: Pointers) void {
236235 \\ _ = pointers;
237236 \\}
238237 \\pub fn main() void {
......@@ -266,42 +265,37 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
266265 \\ ([*]const allowzero u32) many_const_allowzero = 0x0000000000002024
267266 \\ ([*]volatile allowzero u32) many_volatile_allowzero = 0x0000000000002028
268267 \\ ([*]const volatile allowzero u32) many_const_volatile_allowzero = 0x000000000000202c
269 \\ ([]u32) slice = {
268 \\ ([]u32) slice = len=1 {
270269 \\ (u32) [0] = 3010
271270 \\ }
272 \\ ([]const u32) slice_const = {
271 \\ ([]const u32) slice_const = len=2 {
273272 \\ (u32) [0] = 3010
274273 \\ (u32) [1] = 3014
275274 \\ }
276 \\ ([]volatile u32) slice_volatile = {
275 \\ ([]volatile u32) slice_volatile = len=3 {
277276 \\ (u32) [0] = 3010
278277 \\ (u32) [1] = 3014
279278 \\ (u32) [2] = 3018
280279 \\ }
281 \\ ([]const volatile u32) slice_const_volatile = {
280 \\ ([]const volatile u32) slice_const_volatile = len=4 {
282281 \\ (u32) [0] = 3010
283282 \\ (u32) [1] = 3014
284283 \\ (u32) [2] = 3018
285284 \\ (u32) [3] = 3022
286285 \\ }
287 \\ ([]allowzero u32) slice_allowzero = {
286 \\ ([]allowzero u32) slice_allowzero = len=0 {}
287 \\ ([]const allowzero u32) slice_const_allowzero = len=1 {
288288 \\ (u32) [0] = 3026
289289 \\ }
290 \\ ([]const allowzero u32) slice_const_allowzero = {
290 \\ ([]volatile allowzero u32) slice_volatile_allowzero = len=2 {
291291 \\ (u32) [0] = 3026
292292 \\ (u32) [1] = 3030
293293 \\ }
294 \\ ([]volatile allowzero u32) slice_volatile_allowzero = {
294 \\ ([]const volatile allowzero u32) slice_const_volatile_allowzero = len=3 {
295295 \\ (u32) [0] = 3026
296296 \\ (u32) [1] = 3030
297297 \\ (u32) [2] = 3034
298298 \\ }
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 \\ }
305299 \\ ([*c]u32) c = 0x0000000000004010
306300 \\ ([*c]const u32) c_const = 0x0000000000004014
307301 \\ ([*c]volatile u32) c_volatile = 0x0000000000004018
......@@ -311,6 +305,104 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
311305 \\1 breakpoints deleted; 0 breakpoint locations disabled.
312306 },
313307 );
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 );
314406 db.addLldbTest(
315407 "storage",
316408 target,
......@@ -384,56 +476,6 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
384476 \\1 breakpoints deleted; 0 breakpoint locations disabled.
385477 },
386478 );
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 );
437479 db.addLldbTest(
438480 "cross_module_call",
439481 target,