authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-09-10 12:15:51-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-09-10 13:06:08-04:00
log6aa6d088d93174767d3a8387d536f4083c39e14f
treee2fbdd384dbc2509c4a3b633b41e651a6e01b157
parentd5a7fcfc13b8aa65a56cfa12c235b207ab6ae949

Dwarf: implement and test hash maps


2 files changed, 104 insertions(+), 33 deletions(-)

lib/std/hash_map.zig+5-3
...@@ -1767,9 +1767,11 @@ pub fn HashMapUnmanaged(...@@ -1767,9 +1767,11 @@ pub fn HashMapUnmanaged(
1767 }1767 }
17681768
1769 comptime {1769 comptime {
1770 if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {1770 if (!builtin.strip_debug_info) _ = switch (builtin.zig_backend) {
1771 _ = &dbHelper;1771 .stage2_llvm => &dbHelper,
1772 }1772 .stage2_x86_64 => KV,
1773 else => {},
1774 };
1773 }1775 }
1774 };1776 };
1775}1777}
test/src/Debugger.zig+99-30
...@@ -107,11 +107,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -107,11 +107,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
107 },107 },
108 \\breakpoint set --file basic.zig --source-pattern-regexp '_ = basic;'108 \\breakpoint set --file basic.zig --source-pattern-regexp '_ = basic;'
109 \\process launch109 \\process launch
110 \\frame variable --show-types basic110 \\frame variable --show-types -- basic
111 \\breakpoint delete --force 1111 \\breakpoint delete --force 1
112 ,112 ,
113 &.{113 &.{
114 \\(lldb) frame variable --show-types basic114 \\(lldb) frame variable --show-types -- basic
115 \\(root.basic.Basic) basic = {115 \\(root.basic.Basic) basic = {
116 \\ (void) void = {}116 \\ (void) void = {}
117 \\ (bool) bool_false = false117 \\ (bool) bool_false = false
...@@ -243,11 +243,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -243,11 +243,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
243 },243 },
244 \\breakpoint set --file pointers.zig --source-pattern-regexp '_ = pointers;'244 \\breakpoint set --file pointers.zig --source-pattern-regexp '_ = pointers;'
245 \\process launch245 \\process launch
246 \\frame variable --show-types pointers246 \\frame variable --show-types -- pointers
247 \\breakpoint delete --force 1247 \\breakpoint delete --force 1
248 ,248 ,
249 &.{249 &.{
250 \\(lldb) frame variable --show-types pointers250 \\(lldb) frame variable --show-types -- pointers
251 \\(root.pointers.Pointers) pointers = {251 \\(root.pointers.Pointers) pointers = {
252 \\ (*u32) single = 0x0000000000001010252 \\ (*u32) single = 0x0000000000001010
253 \\ (*const u32) single_const = 0x0000000000001014253 \\ (*const u32) single_const = 0x0000000000001014
...@@ -330,13 +330,13 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -330,13 +330,13 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
330 },330 },
331 \\breakpoint set --file strings.zig --source-pattern-regexp '_ = strings;'331 \\breakpoint set --file strings.zig --source-pattern-regexp '_ = strings;'
332 \\process launch332 \\process launch
333 \\frame variable --show-types strings.slice333 \\frame variable --show-types -- strings.slice
334 \\frame variable --show-types --format character strings.slice334 \\frame variable --show-types --format character -- strings.slice
335 \\frame variable --show-types --format c-string strings335 \\frame variable --show-types --format c-string -- strings
336 \\breakpoint delete --force 1336 \\breakpoint delete --force 1
337 ,337 ,
338 &.{338 &.{
339 \\(lldb) frame variable --show-types strings.slice339 \\(lldb) frame variable --show-types -- strings.slice
340 \\([:0]const u8) strings.slice = len=9 {340 \\([:0]const u8) strings.slice = len=9 {
341 \\ (u8) [0] = 115341 \\ (u8) [0] = 115
342 \\ (u8) [1] = 108342 \\ (u8) [1] = 108
...@@ -348,7 +348,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -348,7 +348,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
348 \\ (u8) [7] = 92348 \\ (u8) [7] = 92
349 \\ (u8) [8] = 0349 \\ (u8) [8] = 0
350 \\}350 \\}
351 \\(lldb) frame variable --show-types --format character strings.slice351 \\(lldb) frame variable --show-types --format character -- strings.slice
352 \\([:0]const u8) strings.slice = len=9 {352 \\([:0]const u8) strings.slice = len=9 {
353 \\ (u8) [0] = 's'353 \\ (u8) [0] = 's'
354 \\ (u8) [1] = 'l'354 \\ (u8) [1] = 'l'
...@@ -360,7 +360,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -360,7 +360,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
360 \\ (u8) [7] = '\\'360 \\ (u8) [7] = '\\'
361 \\ (u8) [8] = '\x00'361 \\ (u8) [8] = '\x00'
362 \\}362 \\}
363 \\(lldb) frame variable --show-types --format c-string strings363 \\(lldb) frame variable --show-types --format c-string -- strings
364 \\(root.strings.Strings) strings = {364 \\(root.strings.Strings) strings = {
365 \\ ([*c]const u8) c_ptr = "c_ptr\x07\x08\t"365 \\ ([*c]const u8) c_ptr = "c_ptr\x07\x08\t"
366 \\ ([*:0]const u8) many_ptr = "many_ptr\n\x0b\x0c"366 \\ ([*:0]const u8) many_ptr = "many_ptr\n\x0b\x0c"
...@@ -412,7 +412,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -412,7 +412,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
412 \\breakpoint set --file enums.zig --source-pattern-regexp '_ = enums;'412 \\breakpoint set --file enums.zig --source-pattern-regexp '_ = enums;'
413 \\process launch413 \\process launch
414 \\expression --show-types -- Enums414 \\expression --show-types -- Enums
415 \\frame variable --show-types enums415 \\frame variable --show-types -- enums
416 \\breakpoint delete --force 1416 \\breakpoint delete --force 1
417 ,417 ,
418 &.{418 &.{
...@@ -432,7 +432,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -432,7 +432,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
432 \\ (root.enums.Enums.Three) third = .third432 \\ (root.enums.Enums.Three) third = .third
433 \\ }433 \\ }
434 \\}434 \\}
435 \\(lldb) frame variable --show-types enums435 \\(lldb) frame variable --show-types -- enums
436 \\(root.enums.Enums) enums = {436 \\(root.enums.Enums) enums = {
437 \\ (root.enums.Enums.Zero) zero = @enumFromInt(13)437 \\ (root.enums.Enums.Zero) zero = @enumFromInt(13)
438 \\ (root.enums.Enums.One) one = .first438 \\ (root.enums.Enums.One) one = .first
...@@ -476,7 +476,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -476,7 +476,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
476 \\breakpoint set --file errors.zig --source-pattern-regexp '_ = errors;'476 \\breakpoint set --file errors.zig --source-pattern-regexp '_ = errors;'
477 \\process launch477 \\process launch
478 \\expression --show-types -- Errors478 \\expression --show-types -- Errors
479 \\frame variable --show-types errors479 \\frame variable --show-types -- errors
480 \\breakpoint delete --force 1480 \\breakpoint delete --force 1
481 ,481 ,
482 &.{482 &.{
...@@ -496,7 +496,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -496,7 +496,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
496 \\ (error{One,Two,Three}) Three = error.Three496 \\ (error{One,Two,Three}) Three = error.Three
497 \\ }497 \\ }
498 \\}498 \\}
499 \\(lldb) frame variable --show-types errors499 \\(lldb) frame variable --show-types -- errors
500 \\(root.errors.Errors) errors = {500 \\(root.errors.Errors) errors = {
501 \\ (error{One}) one = error.One501 \\ (error{One}) one = error.One
502 \\ (error{One,Two}) two = error.Two502 \\ (error{One,Two}) two = error.Two
...@@ -535,23 +535,23 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -535,23 +535,23 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
535 },535 },
536 \\breakpoint set --file optionals.zig --source-pattern-regexp 'maybe_u32 = 123;'536 \\breakpoint set --file optionals.zig --source-pattern-regexp 'maybe_u32 = 123;'
537 \\process launch537 \\process launch
538 \\frame variable null_u32 maybe_u32 nonnull_u32538 \\frame variable -- null_u32 maybe_u32 nonnull_u32
539 \\breakpoint delete --force 1539 \\breakpoint delete --force 1
540 \\540 \\
541 \\breakpoint set --file optionals.zig --source-pattern-regexp '_ = \.{ &null_u32, &nonnull_u32 };'541 \\breakpoint set --file optionals.zig --source-pattern-regexp '_ = \.{ &null_u32, &nonnull_u32 };'
542 \\process continue542 \\process continue
543 \\frame variable --show-types null_u32 maybe_u32 nonnull_u32543 \\frame variable --show-types -- null_u32 maybe_u32 nonnull_u32
544 \\breakpoint delete --force 2544 \\breakpoint delete --force 2
545 ,545 ,
546 &.{546 &.{
547 \\(lldb) frame variable null_u32 maybe_u32 nonnull_u32547 \\(lldb) frame variable -- null_u32 maybe_u32 nonnull_u32
548 \\(?u32) null_u32 = null548 \\(?u32) null_u32 = null
549 \\(?u32) maybe_u32 = null549 \\(?u32) maybe_u32 = null
550 \\(?u32) nonnull_u32 = (nonnull_u32.? = 456)550 \\(?u32) nonnull_u32 = (nonnull_u32.? = 456)
551 \\(lldb) breakpoint delete --force 1551 \\(lldb) breakpoint delete --force 1
552 \\1 breakpoints deleted; 0 breakpoint locations disabled.552 \\1 breakpoints deleted; 0 breakpoint locations disabled.
553 ,553 ,
554 \\(lldb) frame variable --show-types null_u32 maybe_u32 nonnull_u32554 \\(lldb) frame variable --show-types -- null_u32 maybe_u32 nonnull_u32
555 \\(?u32) null_u32 = null555 \\(?u32) null_u32 = null
556 \\(?u32) maybe_u32 = {556 \\(?u32) maybe_u32 = {
557 \\ (u32) maybe_u32.? = 123557 \\ (u32) maybe_u32.? = 123
...@@ -605,7 +605,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -605,7 +605,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
605 \\breakpoint set --file unions.zig --source-pattern-regexp '_ = unions;'605 \\breakpoint set --file unions.zig --source-pattern-regexp '_ = unions;'
606 \\process launch606 \\process launch
607 \\expression --show-types -- Unions607 \\expression --show-types -- Unions
608 \\frame variable --show-types unions608 \\frame variable --show-types -- unions
609 \\breakpoint delete --force 1609 \\breakpoint delete --force 1
610 ,610 ,
611 &.{611 &.{
...@@ -628,7 +628,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -628,7 +628,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
628 \\ (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) eu = .eu628 \\ (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) eu = .eu
629 \\ }629 \\ }
630 \\}630 \\}
631 \\(lldb) frame variable --show-types unions631 \\(lldb) frame variable --show-types -- unions
632 \\(root.unions.Unions) unions = {632 \\(root.unions.Unions) unions = {
633 \\ (root.unions.Unions.Untagged) untagged = {633 \\ (root.unions.Unions.Untagged) untagged = {
634 \\ (u32) u32 = 3217031168634 \\ (u32) u32 = 3217031168
...@@ -694,17 +694,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -694,17 +694,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
694 },694 },
695 \\breakpoint set --file storage.zig --source-pattern-regexp 'local_var = local_var;'695 \\breakpoint set --file storage.zig --source-pattern-regexp 'local_var = local_var;'
696 \\process launch696 \\process launch
697 \\target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2697 \\target variable --show-types --format hex -- global_const global_var global_threadlocal1 global_threadlocal2
698 \\frame variable --show-types --format hex param1 param2 param3 param4 param5 param6 param7 param8 local_comptime_val local_comptime_ptr.0 local_const local_var698 \\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
699 \\breakpoint delete --force 1699 \\breakpoint delete --force 1
700 ,700 ,
701 &.{701 &.{
702 \\(lldb) target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2702 \\(lldb) target variable --show-types --format hex -- global_const global_var global_threadlocal1 global_threadlocal2
703 \\(u64) global_const = 0x19e50dc8d6002077703 \\(u64) global_const = 0x19e50dc8d6002077
704 \\(u64) global_var = 0xcc423cec08622e32704 \\(u64) global_var = 0xcc423cec08622e32
705 \\(u64) global_threadlocal1 = 0xb4d643528c042121705 \\(u64) global_threadlocal1 = 0xb4d643528c042121
706 \\(u64) global_threadlocal2 = 0x43faea1cf5ad7a22706 \\(u64) global_threadlocal2 = 0x43faea1cf5ad7a22
707 \\(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_var707 \\(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
708 \\(u64) param1 = 0x6a607e08125c7e00708 \\(u64) param1 = 0x6a607e08125c7e00
709 \\(u64) param2 = 0x98944cb2a45a8b51709 \\(u64) param2 = 0x98944cb2a45a8b51
710 \\(u64) param3 = 0xa320cf10601ee6fb710 \\(u64) param3 = 0xa320cf10601ee6fb
...@@ -1305,26 +1305,95 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -1305,26 +1305,95 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
1305 },1305 },
1306 \\breakpoint set --file main.zig --source-pattern-regexp 'x = fabsf\(x\);'1306 \\breakpoint set --file main.zig --source-pattern-regexp 'x = fabsf\(x\);'
1307 \\process launch1307 \\process launch
1308 \\frame variable x1308 \\frame variable -- x
1309 \\breakpoint delete --force 11309 \\breakpoint delete --force 1
1310 \\1310 \\
1311 \\breakpoint set --file main.zig --source-pattern-regexp '_ = &x;'1311 \\breakpoint set --file main.zig --source-pattern-regexp '_ = &x;'
1312 \\process continue1312 \\process continue
1313 \\frame variable x1313 \\frame variable -- x
1314 \\breakpoint delete --force 21314 \\breakpoint delete --force 2
1315 ,1315 ,
1316 &.{1316 &.{
1317 \\(lldb) frame variable x1317 \\(lldb) frame variable -- x
1318 \\(f32) x = -1234.51318 \\(f32) x = -1234.5
1319 \\(lldb) breakpoint delete --force 11319 \\(lldb) breakpoint delete --force 1
1320 \\1 breakpoints deleted; 0 breakpoint locations disabled.1320 \\1 breakpoints deleted; 0 breakpoint locations disabled.
1321 ,1321 ,
1322 \\(lldb) frame variable x1322 \\(lldb) frame variable -- x
1323 \\(f32) x = 1234.51323 \\(f32) x = 1234.5
1324 \\(lldb) breakpoint delete --force 21324 \\(lldb) breakpoint delete --force 2
1325 \\1 breakpoints deleted; 0 breakpoint locations disabled.1325 \\1 breakpoints deleted; 0 breakpoint locations disabled.
1326 },1326 },
1327 );1327 );
1328 db.addLldbTest(
1329 "hash_map",
1330 target,
1331 &.{
1332 .{
1333 .path = "main.zig",
1334 .source =
1335 \\const std = @import("std");
1336 \\const Context = struct {
1337 \\ pub fn hash(_: Context, key: u32) Map.Hash {
1338 \\ return key;
1339 \\ }
1340 \\ pub fn eql(_: Context, lhs: u32, rhs: u32) bool {
1341 \\ return lhs == rhs;
1342 \\ }
1343 \\};
1344 \\const Map = std.HashMap(u32, u32, Context, 63);
1345 \\fn testHashMap(map: Map) void {
1346 \\ _ = map;
1347 \\}
1348 \\pub fn main() !void {
1349 \\ var map = Map.init(std.heap.page_allocator);
1350 \\ defer map.deinit();
1351 \\ try map.ensureTotalCapacity(10);
1352 \\ map.putAssumeCapacity(0, 1);
1353 \\ map.putAssumeCapacity(2, 3);
1354 \\ map.putAssumeCapacity(4, 5);
1355 \\ map.putAssumeCapacity(6, 7);
1356 \\ map.putAssumeCapacity(8, 9);
1357 \\
1358 \\ testHashMap(map);
1359 \\}
1360 \\
1361 ,
1362 },
1363 },
1364 \\breakpoint set --file main.zig --source-pattern-regexp '_ = map;'
1365 \\process launch
1366 \\frame variable --show-types -- map.unmanaged
1367 \\breakpoint delete --force 1
1368 ,
1369 &.{
1370 \\(lldb) frame variable --show-types -- map.unmanaged
1371 \\(std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63)) map.unmanaged = len=5 capacity=16 {
1372 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [0] = {
1373 \\ (u32) key = 0
1374 \\ (u32) value = 1
1375 \\ }
1376 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [1] = {
1377 \\ (u32) key = 2
1378 \\ (u32) value = 3
1379 \\ }
1380 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [2] = {
1381 \\ (u32) key = 4
1382 \\ (u32) value = 5
1383 \\ }
1384 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [3] = {
1385 \\ (u32) key = 6
1386 \\ (u32) value = 7
1387 \\ }
1388 \\ (std.hash_map.HashMapUnmanaged(u32,u32,main.Context,63).KV) [4] = {
1389 \\ (u32) key = 8
1390 \\ (u32) value = 9
1391 \\ }
1392 \\}
1393 \\(lldb) breakpoint delete --force 1
1394 \\1 breakpoints deleted; 0 breakpoint locations disabled.
1395 },
1396 );
1328 db.addLldbTest(1397 db.addLldbTest(
1329 "multi_array_list",1398 "multi_array_list",
1330 target,1399 target,
...@@ -1615,11 +1684,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {...@@ -1615,11 +1684,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
1615 },1684 },
1616 \\breakpoint set --file main.zig --source-pattern-regexp 'testSegmentedList\(\);'1685 \\breakpoint set --file main.zig --source-pattern-regexp 'testSegmentedList\(\);'
1617 \\process launch1686 \\process launch
1618 \\frame variable list0 list1 list2 list41687 \\frame variable -- list0 list1 list2 list4
1619 \\breakpoint delete --force 11688 \\breakpoint delete --force 1
1620 ,1689 ,
1621 &.{1690 &.{
1622 \\(lldb) frame variable list0 list1 list2 list41691 \\(lldb) frame variable -- list0 list1 list2 list4
1623 \\(std.segmented_list.SegmentedList(usize,0)) list0 = len=32 {1692 \\(std.segmented_list.SegmentedList(usize,0)) list0 = len=32 {
1624 \\ [0] = 01693 \\ [0] = 0
1625 \\ [1] = 11694 \\ [1] = 1