Skip to content

Commit 6aa6d08

Browse files
committed
Dwarf: implement and test hash maps
1 parent d5a7fcf commit 6aa6d08

File tree

2 files changed

+104
-33
lines changed

2 files changed

+104
-33
lines changed

lib/std/hash_map.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,9 +1767,11 @@ pub fn HashMapUnmanaged(
17671767
}
17681768

17691769
comptime {
1770-
if (builtin.zig_backend == .stage2_llvm and !builtin.strip_debug_info) {
1771-
_ = &dbHelper;
1772-
}
1770+
if (!builtin.strip_debug_info) _ = switch (builtin.zig_backend) {
1771+
.stage2_llvm => &dbHelper,
1772+
.stage2_x86_64 => KV,
1773+
else => {},
1774+
};
17731775
}
17741776
};
17751777
}

test/src/Debugger.zig

Lines changed: 99 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
107107
},
108108
\\breakpoint set --file basic.zig --source-pattern-regexp '_ = basic;'
109109
\\process launch
110-
\\frame variable --show-types basic
110+
\\frame variable --show-types -- basic
111111
\\breakpoint delete --force 1
112112
,
113113
&.{
114-
\\(lldb) frame variable --show-types basic
114+
\\(lldb) frame variable --show-types -- basic
115115
\\(root.basic.Basic) basic = {
116116
\\ (void) void = {}
117117
\\ (bool) bool_false = false
@@ -243,11 +243,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
243243
},
244244
\\breakpoint set --file pointers.zig --source-pattern-regexp '_ = pointers;'
245245
\\process launch
246-
\\frame variable --show-types pointers
246+
\\frame variable --show-types -- pointers
247247
\\breakpoint delete --force 1
248248
,
249249
&.{
250-
\\(lldb) frame variable --show-types pointers
250+
\\(lldb) frame variable --show-types -- pointers
251251
\\(root.pointers.Pointers) pointers = {
252252
\\ (*u32) single = 0x0000000000001010
253253
\\ (*const u32) single_const = 0x0000000000001014
@@ -330,13 +330,13 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
330330
},
331331
\\breakpoint set --file strings.zig --source-pattern-regexp '_ = strings;'
332332
\\process launch
333-
\\frame variable --show-types strings.slice
334-
\\frame variable --show-types --format character strings.slice
335-
\\frame variable --show-types --format c-string strings
333+
\\frame variable --show-types -- strings.slice
334+
\\frame variable --show-types --format character -- strings.slice
335+
\\frame variable --show-types --format c-string -- strings
336336
\\breakpoint delete --force 1
337337
,
338338
&.{
339-
\\(lldb) frame variable --show-types strings.slice
339+
\\(lldb) frame variable --show-types -- strings.slice
340340
\\([:0]const u8) strings.slice = len=9 {
341341
\\ (u8) [0] = 115
342342
\\ (u8) [1] = 108
@@ -348,7 +348,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
348348
\\ (u8) [7] = 92
349349
\\ (u8) [8] = 0
350350
\\}
351-
\\(lldb) frame variable --show-types --format character strings.slice
351+
\\(lldb) frame variable --show-types --format character -- strings.slice
352352
\\([:0]const u8) strings.slice = len=9 {
353353
\\ (u8) [0] = 's'
354354
\\ (u8) [1] = 'l'
@@ -360,7 +360,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
360360
\\ (u8) [7] = '\\'
361361
\\ (u8) [8] = '\x00'
362362
\\}
363-
\\(lldb) frame variable --show-types --format c-string strings
363+
\\(lldb) frame variable --show-types --format c-string -- strings
364364
\\(root.strings.Strings) strings = {
365365
\\ ([*c]const u8) c_ptr = "c_ptr\x07\x08\t"
366366
\\ ([*:0]const u8) many_ptr = "many_ptr\n\x0b\x0c"
@@ -412,7 +412,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
412412
\\breakpoint set --file enums.zig --source-pattern-regexp '_ = enums;'
413413
\\process launch
414414
\\expression --show-types -- Enums
415-
\\frame variable --show-types enums
415+
\\frame variable --show-types -- enums
416416
\\breakpoint delete --force 1
417417
,
418418
&.{
@@ -432,7 +432,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
432432
\\ (root.enums.Enums.Three) third = .third
433433
\\ }
434434
\\}
435-
\\(lldb) frame variable --show-types enums
435+
\\(lldb) frame variable --show-types -- enums
436436
\\(root.enums.Enums) enums = {
437437
\\ (root.enums.Enums.Zero) zero = @enumFromInt(13)
438438
\\ (root.enums.Enums.One) one = .first
@@ -476,7 +476,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
476476
\\breakpoint set --file errors.zig --source-pattern-regexp '_ = errors;'
477477
\\process launch
478478
\\expression --show-types -- Errors
479-
\\frame variable --show-types errors
479+
\\frame variable --show-types -- errors
480480
\\breakpoint delete --force 1
481481
,
482482
&.{
@@ -496,7 +496,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
496496
\\ (error{One,Two,Three}) Three = error.Three
497497
\\ }
498498
\\}
499-
\\(lldb) frame variable --show-types errors
499+
\\(lldb) frame variable --show-types -- errors
500500
\\(root.errors.Errors) errors = {
501501
\\ (error{One}) one = error.One
502502
\\ (error{One,Two}) two = error.Two
@@ -535,23 +535,23 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
535535
},
536536
\\breakpoint set --file optionals.zig --source-pattern-regexp 'maybe_u32 = 123;'
537537
\\process launch
538-
\\frame variable null_u32 maybe_u32 nonnull_u32
538+
\\frame variable -- null_u32 maybe_u32 nonnull_u32
539539
\\breakpoint delete --force 1
540540
\\
541541
\\breakpoint set --file optionals.zig --source-pattern-regexp '_ = \.{ &null_u32, &nonnull_u32 };'
542542
\\process continue
543-
\\frame variable --show-types null_u32 maybe_u32 nonnull_u32
543+
\\frame variable --show-types -- null_u32 maybe_u32 nonnull_u32
544544
\\breakpoint delete --force 2
545545
,
546546
&.{
547-
\\(lldb) frame variable null_u32 maybe_u32 nonnull_u32
547+
\\(lldb) frame variable -- null_u32 maybe_u32 nonnull_u32
548548
\\(?u32) null_u32 = null
549549
\\(?u32) maybe_u32 = null
550550
\\(?u32) nonnull_u32 = (nonnull_u32.? = 456)
551551
\\(lldb) breakpoint delete --force 1
552552
\\1 breakpoints deleted; 0 breakpoint locations disabled.
553553
,
554-
\\(lldb) frame variable --show-types null_u32 maybe_u32 nonnull_u32
554+
\\(lldb) frame variable --show-types -- null_u32 maybe_u32 nonnull_u32
555555
\\(?u32) null_u32 = null
556556
\\(?u32) maybe_u32 = {
557557
\\ (u32) maybe_u32.? = 123
@@ -605,7 +605,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
605605
\\breakpoint set --file unions.zig --source-pattern-regexp '_ = unions;'
606606
\\process launch
607607
\\expression --show-types -- Unions
608-
\\frame variable --show-types unions
608+
\\frame variable --show-types -- unions
609609
\\breakpoint delete --force 1
610610
,
611611
&.{
@@ -628,7 +628,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
628628
\\ (@typeInfo(unions.Unions.Tagged).@"union".tag_type.?) eu = .eu
629629
\\ }
630630
\\}
631-
\\(lldb) frame variable --show-types unions
631+
\\(lldb) frame variable --show-types -- unions
632632
\\(root.unions.Unions) unions = {
633633
\\ (root.unions.Unions.Untagged) untagged = {
634634
\\ (u32) u32 = 3217031168
@@ -694,17 +694,17 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
694694
},
695695
\\breakpoint set --file storage.zig --source-pattern-regexp 'local_var = local_var;'
696696
\\process launch
697-
\\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_var
697+
\\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_var
699699
\\breakpoint delete --force 1
700700
,
701701
&.{
702-
\\(lldb) target variable --show-types --format hex global_const global_var global_threadlocal1 global_threadlocal2
702+
\\(lldb) target variable --show-types --format hex -- global_const global_var global_threadlocal1 global_threadlocal2
703703
\\(u64) global_const = 0x19e50dc8d6002077
704704
\\(u64) global_var = 0xcc423cec08622e32
705705
\\(u64) global_threadlocal1 = 0xb4d643528c042121
706706
\\(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_var
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_var
708708
\\(u64) param1 = 0x6a607e08125c7e00
709709
\\(u64) param2 = 0x98944cb2a45a8b51
710710
\\(u64) param3 = 0xa320cf10601ee6fb
@@ -1305,26 +1305,95 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
13051305
},
13061306
\\breakpoint set --file main.zig --source-pattern-regexp 'x = fabsf\(x\);'
13071307
\\process launch
1308-
\\frame variable x
1308+
\\frame variable -- x
13091309
\\breakpoint delete --force 1
13101310
\\
13111311
\\breakpoint set --file main.zig --source-pattern-regexp '_ = &x;'
13121312
\\process continue
1313-
\\frame variable x
1313+
\\frame variable -- x
13141314
\\breakpoint delete --force 2
13151315
,
13161316
&.{
1317-
\\(lldb) frame variable x
1317+
\\(lldb) frame variable -- x
13181318
\\(f32) x = -1234.5
13191319
\\(lldb) breakpoint delete --force 1
13201320
\\1 breakpoints deleted; 0 breakpoint locations disabled.
13211321
,
1322-
\\(lldb) frame variable x
1322+
\\(lldb) frame variable -- x
13231323
\\(f32) x = 1234.5
13241324
\\(lldb) breakpoint delete --force 2
13251325
\\1 breakpoints deleted; 0 breakpoint locations disabled.
13261326
},
13271327
);
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+
);
13281397
db.addLldbTest(
13291398
"multi_array_list",
13301399
target,
@@ -1615,11 +1684,11 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
16151684
},
16161685
\\breakpoint set --file main.zig --source-pattern-regexp 'testSegmentedList\(\);'
16171686
\\process launch
1618-
\\frame variable list0 list1 list2 list4
1687+
\\frame variable -- list0 list1 list2 list4
16191688
\\breakpoint delete --force 1
16201689
,
16211690
&.{
1622-
\\(lldb) frame variable list0 list1 list2 list4
1691+
\\(lldb) frame variable -- list0 list1 list2 list4
16231692
\\(std.segmented_list.SegmentedList(usize,0)) list0 = len=32 {
16241693
\\ [0] = 0
16251694
\\ [1] = 1

0 commit comments

Comments
 (0)