aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-24 13:43:41 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-09-01 17:54:06 -0700
commit3deda15e21ea3a8138d5b628f2649bbbfe7fa910 (patch)
tree5ed1e0a60bd284984e328f49858c96063f1ff608 /lib/std/debug.zig
parent81e2034d4ad935185344030e5ecedbd1388a65e9 (diff)
downloadzig-3deda15e21ea3a8138d5b628f2649bbbfe7fa910.tar.gz
zig-3deda15e21ea3a8138d5b628f2649bbbfe7fa910.zip
std.os reorganization, avoiding `usingnamespace`
The main purpose of this branch is to explore avoiding the `usingnamespace` feature of the zig language, specifically with regards to `std.os` and related functionality. If this experiment is successful, it will provide a data point on whether or not it would be practical to entirely remove `usingnamespace` from the language. In this commit, `usingnamespace` has been completely eliminated from the Linux x86_64 compilation path, aside from io_uring. The behavior tests pass, however that's as far as this branch goes. It is very breaking, and a lot more work is needed before it could be considered mergeable. I wanted to put a pull requset up early so that zig programmers have time to provide feedback. This is progress towards closing #6600 since it clarifies where the actual "owner" of each declaration is, and reduces the number of different ways to import the same declarations. One of the main organizational strategies used here is to do namespacing with real namespaces (e.g. structs) rather than by having declarations share a common prefix (the C strategy). It's no coincidence that `usingnamespace` has similar semantics to `#include` and becomes much less necessary when using proper namespaces.
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig34
1 files changed, 17 insertions, 17 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 4b715f2b14..540586a38f 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -948,8 +948,8 @@ fn mapWholeFile(file: File) ![]align(mem.page_size) const u8 {
const mapped_mem = try os.mmap(
null,
file_len,
- os.PROT_READ,
- os.MAP_SHARED,
+ os.PROT.READ,
+ os.MAP.SHARED,
file.handle,
0,
);
@@ -1498,12 +1498,12 @@ pub fn attachSegfaultHandler() void {
var act = os.Sigaction{
.handler = .{ .sigaction = handleSegfaultLinux },
.mask = os.empty_sigset,
- .flags = (os.SA_SIGINFO | os.SA_RESTART | os.SA_RESETHAND),
+ .flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND),
};
- os.sigaction(os.SIGSEGV, &act, null);
- os.sigaction(os.SIGILL, &act, null);
- os.sigaction(os.SIGBUS, &act, null);
+ os.sigaction(os.SIG.SEGV, &act, null);
+ os.sigaction(os.SIG.ILL, &act, null);
+ os.sigaction(os.SIG.BUS, &act, null);
}
fn resetSegfaultHandler() void {
@@ -1515,13 +1515,13 @@ fn resetSegfaultHandler() void {
return;
}
var act = os.Sigaction{
- .handler = .{ .sigaction = os.SIG_DFL },
+ .handler = .{ .sigaction = os.SIG.DFL },
.mask = os.empty_sigset,
.flags = 0,
};
- os.sigaction(os.SIGSEGV, &act, null);
- os.sigaction(os.SIGILL, &act, null);
- os.sigaction(os.SIGBUS, &act, null);
+ os.sigaction(os.SIG.SEGV, &act, null);
+ os.sigaction(os.SIG.ILL, &act, null);
+ os.sigaction(os.SIG.BUS, &act, null);
}
fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) noreturn {
@@ -1542,9 +1542,9 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
nosuspend {
const stderr = io.getStdErr().writer();
_ = switch (sig) {
- os.SIGSEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}),
- os.SIGILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}),
- os.SIGBUS => stderr.print("Bus error at address 0x{x}\n", .{addr}),
+ os.SIG.SEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}),
+ os.SIG.ILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}),
+ os.SIG.BUS => stderr.print("Bus error at address 0x{x}\n", .{addr}),
else => unreachable,
} catch os.abort();
}
@@ -1552,20 +1552,20 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
switch (native_arch) {
.i386 => {
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
- const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_EIP]);
- const bp = @intCast(usize, ctx.mcontext.gregs[os.REG_EBP]);
+ const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]);
+ const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]);
dumpStackTraceFromBase(bp, ip);
},
.x86_64 => {
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
const ip = switch (native_os) {
- .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]),
+ .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]),
.freebsd => @intCast(usize, ctx.mcontext.rip),
.openbsd => @intCast(usize, ctx.sc_rip),
else => unreachable,
};
const bp = switch (native_os) {
- .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]),
+ .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]),
.openbsd => @intCast(usize, ctx.sc_rbp),
.freebsd => @intCast(usize, ctx.mcontext.rbp),
else => unreachable,