aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authorkcbanner <kcbanner@gmail.com>2023-07-07 10:13:48 -0400
committerkcbanner <kcbanner@gmail.com>2023-07-20 22:58:15 -0400
commit5c0d4cef1afda3e01bded01636ef71846522909b (patch)
treee93d46ed7db47bca7c8a3b89de18dcf55bdd6313 /lib/std/debug.zig
parent463bbe7807b236e6e3493fb8551c585620ae266b (diff)
downloadzig-5c0d4cef1afda3e01bded01636ef71846522909b.tar.gz
zig-5c0d4cef1afda3e01bded01636ef71846522909b.zip
debug: add dupeContext, store a pointer to a copy of ThreadContext on UnwindContext
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 7fac160855..7e26b6a4b0 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -133,6 +133,9 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
}
}
+/// Platform-specific thread state. This contains register state, and on some platforms
+/// information about the stack. This is not safe to trivially copy, because some platforms
+/// use internal pointers within this structure. To make a copy, use `dupeContext`.
pub const ThreadContext = blk: {
if (native_os == .windows) {
break :blk std.os.windows.CONTEXT;
@@ -457,6 +460,19 @@ pub inline fn getContext(context: *ThreadContext) bool {
return result;
}
+pub fn dupeContext(source: *const ThreadContext, dest: *ThreadContext) void {
+ if (native_os == .windows) dest.* = source.*;
+ if (!have_ucontext) return {};
+
+ return switch (native_os) {
+ .macos => {
+ dest.* = source.*;
+ dest.mcontext = &dest.__mcontext_data;
+ },
+ else => dest.* = source.*,
+ };
+}
+
pub const UnwindError = if (have_ucontext)
@typeInfo(@typeInfo(@TypeOf(StackIterator.next_dwarf)).Fn.return_type.?).ErrorUnion.error_set
else