authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-21 14:35:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-21 14:35:08-07:00
logafa0834195c48418179d43430a052b2a23b50e00
tree127f6ca0f8eeb3ecc4c32e9cee2e08e15976ee2b
parent12191c8a220ca5594b278b5077bff98e8fecac08

add std.debug.inValgrind

This is like `@inComptime` but for the Valgrind virtual machine. Related #17717

1 files changed, 10 insertions(+), 0 deletions(-)

lib/std/debug.zig+10
...@@ -2858,6 +2858,16 @@ pub const SafetyLock = struct {...@@ -2858,6 +2858,16 @@ pub const SafetyLock = struct {
2858 }2858 }
2859};2859};
28602860
2861/// Detect whether the program is being executed in the Valgrind virtual machine.
2862///
2863/// When Valgrind integrations are disabled, this returns comptime-known false.
2864/// Otherwise, the result is runtime-known.
2865pub inline fn inValgrind() bool {
2866 if (@inComptime()) return false;
2867 if (!builtin.valgrind_support) return false;
2868 return std.valgrind.runningOnValgrind() > 0;
2869}
2870
2861test {2871test {
2862 _ = &dump_hex;2872 _ = &dump_hex;
2863}2873}