authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-17 05:29:13-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-17 05:57:45-04:00
logf601aa780ece6288c87a6424039022d5df9769cc
tree0aba56259a4ffa083d880e7958a5c1b925c0bddf
parentbb70501060a8bfff25818cf1d80491d724f8a634

Dwarf: fix and test allowzero pointers


3 files changed, 131 insertions(+), 44 deletions(-)

lib/std/dwarf/AT.zig-1
......@@ -224,7 +224,6 @@ pub const ZIG_parent = 0x2ccd;
224224pub const ZIG_padding = 0x2cce;
225225pub const ZIG_relative_decl = 0x2cd0;
226226pub const ZIG_decl_line_relative = 0x2cd1;
227pub const ZIG_is_allowzero = 0x2ce1;
228227pub const ZIG_sentinel = 0x2ce2;
229228
230229// UPC extension.
src/link/Dwarf.zig-2
......@@ -2338,7 +2338,6 @@ fn updateType(
23382338 const ptr_child_type = Type.fromInterned(ptr_type.child);
23392339 try uleb128(diw, @intFromEnum(AbbrevCode.ptr_type));
23402340 try wip_nav.strp(name);
2341 try diw.writeByte(@intFromBool(ptr_type.flags.is_allowzero));
23422341 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse
23432342 ptr_child_type.abiAlignment(pt).toByteUnits().?);
23442343 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));
......@@ -3612,7 +3611,6 @@ const AbbrevCode = enum(u8) {
36123611 .tag = .pointer_type,
36133612 .attrs = &.{
36143613 .{ .name, .strp },
3615 .{ .ZIG_is_allowzero, .flag },
36163614 .{ .alignment, .udata },
36173615 .{ .address_class, .data1 },
36183616 .{ .type, .ref_addr },
test/src/Debugger.zig+131-41
......@@ -182,6 +182,135 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
182182 \\1 breakpoints deleted; 0 breakpoint locations disabled.
183183 },
184184 );
185 db.addLldbTest(
186 "pointers",
187 target,
188 &.{
189 .{
190 .path = "pointers.zig",
191 .source =
192 \\const Pointers = struct {
193 \\ var array: [8]u32 = .{
194 \\ 3010,
195 \\ 3014,
196 \\ 3018,
197 \\ 3022,
198 \\ 3026,
199 \\ 3030,
200 \\ 3034,
201 \\ 3038,
202 \\ };
203 \\
204 \\ single: *u32 = @ptrFromInt(0x1010),
205 \\ single_const: *const u32 = @ptrFromInt(0x1014),
206 \\ single_volatile: *volatile u32 = @ptrFromInt(0x1018),
207 \\ single_const_volatile: *const volatile u32 = @ptrFromInt(0x101c),
208 \\ single_allowzero: *allowzero u32 = @ptrFromInt(0x1020),
209 \\ single_const_allowzero: *const allowzero u32 = @ptrFromInt(0x1024),
210 \\ single_volatile_allowzero: *volatile allowzero u32 = @ptrFromInt(0x1028),
211 \\ single_const_volatile_allowzero: *const volatile allowzero u32 = @ptrFromInt(0x102c),
212 \\
213 \\ many: [*]u32 = @ptrFromInt(0x2010),
214 \\ many_const: [*]const u32 = @ptrFromInt(0x2014),
215 \\ many_volatile: [*]volatile u32 = @ptrFromInt(0x2018),
216 \\ many_const_volatile: [*]const volatile u32 = @ptrFromInt(0x201c),
217 \\ many_allowzero: [*]allowzero u32 = @ptrFromInt(0x2020),
218 \\ many_const_allowzero: [*]const allowzero u32 = @ptrFromInt(0x2024),
219 \\ many_volatile_allowzero: [*]volatile allowzero u32 = @ptrFromInt(0x2028),
220 \\ many_const_volatile_allowzero: [*]const volatile allowzero u32 = @ptrFromInt(0x202c),
221 \\ slice: []u32 = array[0..1],
222 \\ slice_const: []const u32 = array[0..2],
223 \\ slice_volatile: []volatile u32 = array[0..3],
224 \\ 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],
229 \\
230 \\ c: [*c]u32 = @ptrFromInt(0x4010),
231 \\ c_const: [*c]const u32 = @ptrFromInt(0x4014),
232 \\ c_volatile: [*c]volatile u32 = @ptrFromInt(0x4018),
233 \\ c_const_volatile: [*c]const volatile u32 = @ptrFromInt(0x401c),
234 \\};
235 \\pub fn testPointers(pointers: Pointers) void {
236 \\ _ = pointers;
237 \\}
238 \\pub fn main() void {
239 \\ testPointers(.{});
240 \\}
241 \\
242 ,
243 },
244 },
245 \\breakpoint set --file pointers.zig --source-pattern-regexp '_ = pointers;'
246 \\process launch
247 \\frame variable --show-types pointers
248 \\breakpoint delete --force 1
249 ,
250 &.{
251 \\(lldb) frame variable --show-types pointers
252 \\(root.pointers.Pointers) pointers = {
253 \\ (*u32) single = 0x0000000000001010
254 \\ (*const u32) single_const = 0x0000000000001014
255 \\ (*volatile u32) single_volatile = 0x0000000000001018
256 \\ (*const volatile u32) single_const_volatile = 0x000000000000101c
257 \\ (*allowzero u32) single_allowzero = 0x0000000000001020
258 \\ (*const allowzero u32) single_const_allowzero = 0x0000000000001024
259 \\ (*volatile allowzero u32) single_volatile_allowzero = 0x0000000000001028
260 \\ (*const volatile allowzero u32) single_const_volatile_allowzero = 0x000000000000102c
261 \\ ([*]u32) many = 0x0000000000002010
262 \\ ([*]const u32) many_const = 0x0000000000002014
263 \\ ([*]volatile u32) many_volatile = 0x0000000000002018
264 \\ ([*]const volatile u32) many_const_volatile = 0x000000000000201c
265 \\ ([*]allowzero u32) many_allowzero = 0x0000000000002020
266 \\ ([*]const allowzero u32) many_const_allowzero = 0x0000000000002024
267 \\ ([*]volatile allowzero u32) many_volatile_allowzero = 0x0000000000002028
268 \\ ([*]const volatile allowzero u32) many_const_volatile_allowzero = 0x000000000000202c
269 \\ ([]u32) slice = {
270 \\ (u32) [0] = 3010
271 \\ }
272 \\ ([]const u32) slice_const = {
273 \\ (u32) [0] = 3010
274 \\ (u32) [1] = 3014
275 \\ }
276 \\ ([]volatile u32) slice_volatile = {
277 \\ (u32) [0] = 3010
278 \\ (u32) [1] = 3014
279 \\ (u32) [2] = 3018
280 \\ }
281 \\ ([]const volatile u32) slice_const_volatile = {
282 \\ (u32) [0] = 3010
283 \\ (u32) [1] = 3014
284 \\ (u32) [2] = 3018
285 \\ (u32) [3] = 3022
286 \\ }
287 \\ ([]allowzero u32) slice_allowzero = {
288 \\ (u32) [0] = 3026
289 \\ }
290 \\ ([]const allowzero u32) slice_const_allowzero = {
291 \\ (u32) [0] = 3026
292 \\ (u32) [1] = 3030
293 \\ }
294 \\ ([]volatile allowzero u32) slice_volatile_allowzero = {
295 \\ (u32) [0] = 3026
296 \\ (u32) [1] = 3030
297 \\ (u32) [2] = 3034
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 = 0x0000000000004010
306 \\ ([*c]const u32) c_const = 0x0000000000004014
307 \\ ([*c]volatile u32) c_volatile = 0x0000000000004018
308 \\ ([*c]const volatile u32) c_const_volatile = 0x000000000000401c
309 \\}
310 \\(lldb) breakpoint delete --force 1
311 \\1 breakpoints deleted; 0 breakpoint locations disabled.
312 },
313 );
185314 db.addLldbTest(
186315 "storage",
187316 target,
......@@ -255,47 +384,6 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
255384 \\1 breakpoints deleted; 0 breakpoint locations disabled.
256385 },
257386 );
258 db.addLldbTest(
259 "slices",
260 target,
261 &.{
262 .{
263 .path = "slices.zig",
264 .source =
265 \\pub fn main() void {
266 \\ {
267 \\ var array: [4]u32 = .{ 1, 2, 4, 8 };
268 \\ const slice: []u32 = &array;
269 \\ _ = slice;
270 \\ }
271 \\}
272 \\
273 ,
274 },
275 },
276 \\breakpoint set --file slices.zig --source-pattern-regexp '_ = slice;'
277 \\process launch
278 \\frame variable --show-types array slice
279 \\breakpoint delete --force 1
280 ,
281 &.{
282 \\(lldb) frame variable --show-types array slice
283 \\([4]u32) array = {
284 \\ (u32) [0] = 1
285 \\ (u32) [1] = 2
286 \\ (u32) [2] = 4
287 \\ (u32) [3] = 8
288 \\}
289 \\([]u32) slice = {
290 \\ (u32) [0] = 1
291 \\ (u32) [1] = 2
292 \\ (u32) [2] = 4
293 \\ (u32) [3] = 8
294 \\}
295 \\(lldb) breakpoint delete --force 1
296 \\1 breakpoints deleted; 0 breakpoint locations disabled.
297 },
298 );
299387 db.addLldbTest(
300388 "optionals",
301389 target,
......@@ -358,6 +446,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
358446 \\ module.foo(123);
359447 \\ module.bar(456);
360448 \\}
449 \\
361450 ,
362451 },
363452 .{
......@@ -370,6 +459,7 @@ pub fn addTestsForTarget(db: *Debugger, target: Target) void {
370459 \\pub inline fn bar(y: u32) void {
371460 \\ _ = y;
372461 \\}
462 \\
373463 ,
374464 },
375465 },