authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-09-09 03:27:52-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-09-10 12:27:57-04:00
loge048e788862881a42304bff91c2f832a924d77c7
treeb276a9000d3a0bc018587414be4df747fd775e83
parente0469773542e49c9a76df6746afa10f22d44dae4

Dwarf: implement and test multi array list


5 files changed, 147 insertions(+), 4 deletions(-)

lib/std/hash_map.zig+1-1
...@@ -1767,7 +1767,7 @@ pub fn HashMapUnmanaged(...@@ -1767,7 +1767,7 @@ pub fn HashMapUnmanaged(
1767 }1767 }
17681768
1769 comptime {1769 comptime {
1770 if (!builtin.strip_debug_info) {1770 if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {
1771 _ = &dbHelper;1771 _ = &dbHelper;
1772 }1772 }
1773 }1773 }
lib/std/multi_array_list.zig+1-1
...@@ -573,7 +573,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -573,7 +573,7 @@ pub fn MultiArrayList(comptime T: type) type {
573 }573 }
574574
575 comptime {575 comptime {
576 if (!builtin.strip_debug_info) {576 if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {
577 _ = &dbHelper;577 _ = &dbHelper;
578 _ = &Slice.dbHelper;578 _ = &Slice.dbHelper;
579 }579 }
src/InternPool.zig+1-1
...@@ -4723,7 +4723,7 @@ pub const Index = enum(u32) {...@@ -4723,7 +4723,7 @@ pub const Index = enum(u32) {
4723 }4723 }
47244724
4725 comptime {4725 comptime {
4726 if (!builtin.strip_debug_info) {4726 if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {
4727 _ = &dbHelper;4727 _ = &dbHelper;
4728 }4728 }
4729 }4729 }
src/link/Dwarf.zig+1-1
...@@ -1762,7 +1762,7 @@ pub const WipNav = struct {...@@ -1762,7 +1762,7 @@ pub const WipNav = struct {
1762 fn blockValue(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc, val: Value) UpdateError!void {1762 fn blockValue(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc, val: Value) UpdateError!void {
1763 const ty = val.typeOf(wip_nav.pt.zcu);1763 const ty = val.typeOf(wip_nav.pt.zcu);
1764 const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa);1764 const diw = wip_nav.debug_info.writer(wip_nav.dwarf.gpa);
1765 const bytes = ty.abiSize(wip_nav.pt.zcu);1765 const bytes = if (ty.hasRuntimeBits(wip_nav.pt.zcu)) ty.abiSize(wip_nav.pt.zcu) else 0;
1766 try uleb128(diw, bytes);1766 try uleb128(diw, bytes);
1767 if (bytes == 0) return;1767 if (bytes == 0) return;
1768 var dim = wip_nav.debug_info.toManaged(wip_nav.dwarf.gpa);1768 var dim = wip_nav.debug_info.toManaged(wip_nav.dwarf.gpa);
test/src/Debugger.zig+143
...@@ -1325,6 +1325,149 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -1325,6 +1325,149 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
1325 \\1 breakpoints deleted; 0 breakpoint locations disabled.1325 \\1 breakpoints deleted; 0 breakpoint locations disabled.
1326 },1326 },
1327 );1327 );
1328 db.addLldbTest(
1329 "multi_array_list",
1330 target,
1331 &.{
1332 .{
1333 .path = "main.zig",
1334 .source =
1335 \\const std = @import("std");
1336 \\fn testMultiArrayList() void {}
1337 \\pub fn main() !void {
1338 \\ const Elem0 = struct { u32, u8, u16 };
1339 \\ var list0: std.MultiArrayList(Elem0) = .{};
1340 \\ defer list0.deinit(std.heap.page_allocator);
1341 \\ try list0.setCapacity(std.heap.page_allocator, 8);
1342 \\ list0.appendAssumeCapacity(.{ 1, 2, 3 });
1343 \\ list0.appendAssumeCapacity(.{ 4, 5, 6 });
1344 \\ list0.appendAssumeCapacity(.{ 7, 8, 9 });
1345 \\
1346 \\ const Elem1 = struct { a: u32, b: u8, c: u16 };
1347 \\ var list1: std.MultiArrayList(Elem1) = .{};
1348 \\ defer list1.deinit(std.heap.page_allocator);
1349 \\ try list1.setCapacity(std.heap.page_allocator, 12);
1350 \\ list1.appendAssumeCapacity(.{ .a = 1, .b = 2, .c = 3 });
1351 \\ list1.appendAssumeCapacity(.{ .a = 4, .b = 5, .c = 6 });
1352 \\ list1.appendAssumeCapacity(.{ .a = 7, .b = 8, .c = 9 });
1353 \\
1354 \\ testMultiArrayList();
1355 \\}
1356 \\
1357 ,
1358 },
1359 },
1360 \\breakpoint set --file main.zig --source-pattern-regexp 'testMultiArrayList\(\);'
1361 \\process launch
1362 \\frame variable --show-types -- list0 list0.len list0.capacity list0[0] list0[1] list0[2] list0.0 list0.1 list0.2
1363 \\frame variable --show-types -- list1 list1.len list1.capacity list1[0] list1[1] list1[2] list1.a list1.b list1.c
1364 \\breakpoint delete --force 1
1365 ,
1366 &.{
1367 \\(lldb) frame variable --show-types -- list0 list0.len list0.capacity list0[0] list0[1] list0[2] list0.0 list0.1 list0.2
1368 \\(std.multi_array_list.MultiArrayList(main.main.Elem0)) list0 = len=3 capacity=8 {
1369 \\ (root.main.main.Elem0) [0] = {
1370 \\ (u32) 0 = 1
1371 \\ (u8) 1 = 2
1372 \\ (u16) 2 = 3
1373 \\ }
1374 \\ (root.main.main.Elem0) [1] = {
1375 \\ (u32) 0 = 4
1376 \\ (u8) 1 = 5
1377 \\ (u16) 2 = 6
1378 \\ }
1379 \\ (root.main.main.Elem0) [2] = {
1380 \\ (u32) 0 = 7
1381 \\ (u8) 1 = 8
1382 \\ (u16) 2 = 9
1383 \\ }
1384 \\}
1385 \\(usize) list0.len = 3
1386 \\(usize) list0.capacity = 8
1387 \\(root.main.main.Elem0) list0[0] = {
1388 \\ (u32) 0 = 1
1389 \\ (u8) 1 = 2
1390 \\ (u16) 2 = 3
1391 \\}
1392 \\(root.main.main.Elem0) list0[1] = {
1393 \\ (u32) 0 = 4
1394 \\ (u8) 1 = 5
1395 \\ (u16) 2 = 6
1396 \\}
1397 \\(root.main.main.Elem0) list0[2] = {
1398 \\ (u32) 0 = 7
1399 \\ (u8) 1 = 8
1400 \\ (u16) 2 = 9
1401 \\}
1402 \\([3]u32) list0.0 = {
1403 \\ (u32) [0] = 1
1404 \\ (u32) [1] = 4
1405 \\ (u32) [2] = 7
1406 \\}
1407 \\([3]u8) list0.1 = {
1408 \\ (u8) [0] = 2
1409 \\ (u8) [1] = 5
1410 \\ (u8) [2] = 8
1411 \\}
1412 \\([3]u16) list0.2 = {
1413 \\ (u16) [0] = 3
1414 \\ (u16) [1] = 6
1415 \\ (u16) [2] = 9
1416 \\}
1417 \\(lldb) frame variable --show-types -- list1 list1.len list1.capacity list1[0] list1[1] list1[2] list1.a list1.b list1.c
1418 \\(std.multi_array_list.MultiArrayList(main.main.Elem1)) list1 = len=3 capacity=12 {
1419 \\ (root.main.main.Elem1) [0] = {
1420 \\ (u32) a = 1
1421 \\ (u8) b = 2
1422 \\ (u16) c = 3
1423 \\ }
1424 \\ (root.main.main.Elem1) [1] = {
1425 \\ (u32) a = 4
1426 \\ (u8) b = 5
1427 \\ (u16) c = 6
1428 \\ }
1429 \\ (root.main.main.Elem1) [2] = {
1430 \\ (u32) a = 7
1431 \\ (u8) b = 8
1432 \\ (u16) c = 9
1433 \\ }
1434 \\}
1435 \\(usize) list1.len = 3
1436 \\(usize) list1.capacity = 12
1437 \\(root.main.main.Elem1) list1[0] = {
1438 \\ (u32) a = 1
1439 \\ (u8) b = 2
1440 \\ (u16) c = 3
1441 \\}
1442 \\(root.main.main.Elem1) list1[1] = {
1443 \\ (u32) a = 4
1444 \\ (u8) b = 5
1445 \\ (u16) c = 6
1446 \\}
1447 \\(root.main.main.Elem1) list1[2] = {
1448 \\ (u32) a = 7
1449 \\ (u8) b = 8
1450 \\ (u16) c = 9
1451 \\}
1452 \\([3]u32) list1.a = {
1453 \\ (u32) [0] = 1
1454 \\ (u32) [1] = 4
1455 \\ (u32) [2] = 7
1456 \\}
1457 \\([3]u8) list1.b = {
1458 \\ (u8) [0] = 2
1459 \\ (u8) [1] = 5
1460 \\ (u8) [2] = 8
1461 \\}
1462 \\([3]u16) list1.c = {
1463 \\ (u16) [0] = 3
1464 \\ (u16) [1] = 6
1465 \\ (u16) [2] = 9
1466 \\}
1467 \\(lldb) breakpoint delete --force 1
1468 \\1 breakpoints deleted; 0 breakpoint locations disabled.
1469 },
1470 );
1328 db.addLldbTest(1471 db.addLldbTest(
1329 "segmented_list",1472 "segmented_list",
1330 target,1473 target,