| author | |
| committer | |
| log | 8e3370367bbbcae43670380cb4ca841a9e5ada33 |
| tree | 5ba2f971ef4c209c97d23742e667eb6afe28156f |
| parent | 924dd674e2e584bbef5e7650f481e49829c8fe28 |
| parent | d870a68e680242d130dcecef1f1ccc0969f326c0 |
| signature |
std: fix outdated valgrind module3 files changed, 111 insertions(+), 62 deletions(-)
lib/std/valgrind.zig+44-34| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | const math = @import("index.zig").math; | |
| 2 | const std = @import("std.zig"); | |
| 3 | const math = std.math; | |
| 3 | 4 | |
| 4 | 5 | pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize { |
| 5 | 6 | if (!builtin.valgrind_support) { |
| ... | ... | @@ -13,7 +14,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: |
| 13 | 14 | \\ roll $29, %%edi ; roll $19, %%edi |
| 14 | 15 | \\ xchgl %%ebx,%%ebx |
| 15 | 16 | : [_] "={edx}" (-> usize) |
| 16 | : [_] "{eax}" (&[]usize{ request, a1, a2, a3, a4, a5 }), | |
| 17 | : [_] "{eax}" (&[_]usize{ request, a1, a2, a3, a4, a5 }), | |
| 17 | 18 | [_] "0" (default) |
| 18 | 19 | : "cc", "memory" |
| 19 | 20 | ); |
| ... | ... | @@ -24,7 +25,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: |
| 24 | 25 | \\ rolq $61, %%rdi ; rolq $51, %%rdi |
| 25 | 26 | \\ xchgq %%rbx,%%rbx |
| 26 | 27 | : [_] "={rdx}" (-> usize) |
| 27 | : [_] "{rax}" (&[]usize{ request, a1, a2, a3, a4, a5 }), | |
| 28 | : [_] "{rax}" (&[_]usize{ request, a1, a2, a3, a4, a5 }), | |
| 28 | 29 | [_] "0" (default) |
| 29 | 30 | : "cc", "memory" |
| 30 | 31 | ); |
| ... | ... | @@ -95,48 +96,52 @@ fn doClientRequestStmt(request: ClientRequest, a1: usize, a2: usize, a3: usize, |
| 95 | 96 | /// running under Valgrind which is running under another Valgrind, |
| 96 | 97 | /// etc. |
| 97 | 98 | pub fn runningOnValgrind() usize { |
| 98 | return doClientRequestExpr(0, ClientRequest.RunningOnValgrind, 0, 0, 0, 0, 0); | |
| 99 | return doClientRequestExpr(0, .RunningOnValgrind, 0, 0, 0, 0, 0); | |
| 100 | } | |
| 101 | ||
| 102 | test "works whether running on valgrind or not" { | |
| 103 | _ = runningOnValgrind(); | |
| 99 | 104 | } |
| 100 | 105 | |
| 101 | 106 | /// Discard translation of code in the slice qzz. Useful if you are debugging |
| 102 | 107 | /// a JITter or some such, since it provides a way to make sure valgrind will |
| 103 | 108 | /// retranslate the invalidated area. Returns no value. |
| 104 | 109 | pub fn discardTranslations(qzz: []const u8) void { |
| 105 | doClientRequestStmt(ClientRequest.DiscardTranslations, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0); | |
| 110 | doClientRequestStmt(.DiscardTranslations, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0); | |
| 106 | 111 | } |
| 107 | 112 | |
| 108 | 113 | pub fn innerThreads(qzz: [*]u8) void { |
| 109 | doClientRequestStmt(ClientRequest.InnerThreads, qzz, 0, 0, 0, 0); | |
| 114 | doClientRequestStmt(.InnerThreads, qzz, 0, 0, 0, 0); | |
| 110 | 115 | } |
| 111 | 116 | |
| 112 | 117 | //pub fn printf(format: [*]const u8, args: ...) usize { |
| 113 | 118 | // return doClientRequestExpr(0, |
| 114 | // ClientRequest.PrintfValistByRef, | |
| 119 | // .PrintfValistByRef, | |
| 115 | 120 | // @ptrToInt(format), @ptrToInt(args), |
| 116 | 121 | // 0, 0, 0); |
| 117 | 122 | //} |
| 118 | 123 | |
| 119 | 124 | //pub fn printfBacktrace(format: [*]const u8, args: ...) usize { |
| 120 | 125 | // return doClientRequestExpr(0, |
| 121 | // ClientRequest.PrintfBacktraceValistByRef, | |
| 126 | // .PrintfBacktraceValistByRef, | |
| 122 | 127 | // @ptrToInt(format), @ptrToInt(args), |
| 123 | 128 | // 0, 0, 0); |
| 124 | 129 | //} |
| 125 | 130 | |
| 126 | 131 | pub fn nonSIMDCall0(func: fn (usize) usize) usize { |
| 127 | return doClientRequestExpr(0, ClientRequest.ClientCall0, @ptrToInt(func), 0, 0, 0, 0); | |
| 132 | return doClientRequestExpr(0, .ClientCall0, @ptrToInt(func), 0, 0, 0, 0); | |
| 128 | 133 | } |
| 129 | 134 | |
| 130 | 135 | pub fn nonSIMDCall1(func: fn (usize, usize) usize, a1: usize) usize { |
| 131 | return doClientRequestExpr(0, ClientRequest.ClientCall1, @ptrToInt(func), a1, 0, 0, 0); | |
| 136 | return doClientRequestExpr(0, .ClientCall1, @ptrToInt(func), a1, 0, 0, 0); | |
| 132 | 137 | } |
| 133 | 138 | |
| 134 | 139 | pub fn nonSIMDCall2(func: fn (usize, usize, usize) usize, a1: usize, a2: usize) usize { |
| 135 | return doClientRequestExpr(0, ClientRequest.ClientCall2, @ptrToInt(func), a1, a2, 0, 0); | |
| 140 | return doClientRequestExpr(0, .ClientCall2, @ptrToInt(func), a1, a2, 0, 0); | |
| 136 | 141 | } |
| 137 | 142 | |
| 138 | 143 | pub fn nonSIMDCall3(func: fn (usize, usize, usize, usize) usize, a1: usize, a2: usize, a3: usize) usize { |
| 139 | return doClientRequestExpr(0, ClientRequest.ClientCall3, @ptrToInt(func), a1, a2, a3, 0); | |
| 144 | return doClientRequestExpr(0, .ClientCall3, @ptrToInt(func), a1, a2, a3, 0); | |
| 140 | 145 | } |
| 141 | 146 | |
| 142 | 147 | /// Counts the number of errors that have been recorded by a tool. Nb: |
| ... | ... | @@ -144,19 +149,19 @@ pub fn nonSIMDCall3(func: fn (usize, usize, usize, usize) usize, a1: usize, a2: |
| 144 | 149 | /// VG_(unique_error)() for them to be counted. |
| 145 | 150 | pub fn countErrors() usize { |
| 146 | 151 | return doClientRequestExpr(0, // default return |
| 147 | ClientRequest.CountErrors, 0, 0, 0, 0, 0); | |
| 152 | .CountErrors, 0, 0, 0, 0, 0); | |
| 148 | 153 | } |
| 149 | 154 | |
| 150 | 155 | pub fn mallocLikeBlock(mem: []u8, rzB: usize, is_zeroed: bool) void { |
| 151 | doClientRequestStmt(ClientRequest.MalloclikeBlock, @ptrToInt(mem.ptr), mem.len, rzB, @boolToInt(is_zeroed), 0); | |
| 156 | doClientRequestStmt(.MalloclikeBlock, @ptrToInt(mem.ptr), mem.len, rzB, @boolToInt(is_zeroed), 0); | |
| 152 | 157 | } |
| 153 | 158 | |
| 154 | 159 | pub fn resizeInPlaceBlock(oldmem: []u8, newsize: usize, rzB: usize) void { |
| 155 | doClientRequestStmt(ClientRequest.ResizeinplaceBlock, @ptrToInt(oldmem.ptr), oldmem.len, newsize, rzB, 0); | |
| 160 | doClientRequestStmt(.ResizeinplaceBlock, @ptrToInt(oldmem.ptr), oldmem.len, newsize, rzB, 0); | |
| 156 | 161 | } |
| 157 | 162 | |
| 158 | 163 | pub fn freeLikeBlock(addr: [*]u8, rzB: usize) void { |
| 159 | doClientRequestStmt(ClientRequest.FreelikeBlock, @ptrToInt(addr), rzB, 0, 0, 0); | |
| 164 | doClientRequestStmt(.FreelikeBlock, @ptrToInt(addr), rzB, 0, 0, 0); | |
| 160 | 165 | } |
| 161 | 166 | |
| 162 | 167 | /// Create a memory pool. |
| ... | ... | @@ -165,66 +170,66 @@ pub const MempoolFlags = extern enum { |
| 165 | 170 | MetaPool = 2, |
| 166 | 171 | }; |
| 167 | 172 | pub fn createMempool(pool: [*]u8, rzB: usize, is_zeroed: bool, flags: usize) void { |
| 168 | doClientRequestStmt(ClientRequest.CreateMempool, @ptrToInt(pool), rzB, @boolToInt(is_zeroed), flags, 0); | |
| 173 | doClientRequestStmt(.CreateMempool, @ptrToInt(pool), rzB, @boolToInt(is_zeroed), flags, 0); | |
| 169 | 174 | } |
| 170 | 175 | |
| 171 | 176 | /// Destroy a memory pool. |
| 172 | 177 | pub fn destroyMempool(pool: [*]u8) void { |
| 173 | doClientRequestStmt(ClientRequest.DestroyMempool, pool, 0, 0, 0, 0); | |
| 178 | doClientRequestStmt(.DestroyMempool, pool, 0, 0, 0, 0); | |
| 174 | 179 | } |
| 175 | 180 | |
| 176 | 181 | /// Associate a piece of memory with a memory pool. |
| 177 | 182 | pub fn mempoolAlloc(pool: [*]u8, mem: []u8) void { |
| 178 | doClientRequestStmt(ClientRequest.MempoolAlloc, @ptrToInt(pool), @ptrToInt(mem.ptr), mem.len, 0, 0); | |
| 183 | doClientRequestStmt(.MempoolAlloc, @ptrToInt(pool), @ptrToInt(mem.ptr), mem.len, 0, 0); | |
| 179 | 184 | } |
| 180 | 185 | |
| 181 | 186 | /// Disassociate a piece of memory from a memory pool. |
| 182 | 187 | pub fn mempoolFree(pool: [*]u8, addr: [*]u8) void { |
| 183 | doClientRequestStmt(ClientRequest.MempoolFree, @ptrToInt(pool), @ptrToInt(addr), 0, 0, 0); | |
| 188 | doClientRequestStmt(.MempoolFree, @ptrToInt(pool), @ptrToInt(addr), 0, 0, 0); | |
| 184 | 189 | } |
| 185 | 190 | |
| 186 | 191 | /// Disassociate any pieces outside a particular range. |
| 187 | 192 | pub fn mempoolTrim(pool: [*]u8, mem: []u8) void { |
| 188 | doClientRequestStmt(ClientRequest.MempoolTrim, @ptrToInt(pool), @ptrToInt(mem.ptr), mem.len, 0, 0); | |
| 193 | doClientRequestStmt(.MempoolTrim, @ptrToInt(pool), @ptrToInt(mem.ptr), mem.len, 0, 0); | |
| 189 | 194 | } |
| 190 | 195 | |
| 191 | 196 | /// Resize and/or move a piece associated with a memory pool. |
| 192 | 197 | pub fn moveMempool(poolA: [*]u8, poolB: [*]u8) void { |
| 193 | doClientRequestStmt(ClientRequest.MoveMempool, @ptrToInt(poolA), @ptrToInt(poolB), 0, 0, 0); | |
| 198 | doClientRequestStmt(.MoveMempool, @ptrToInt(poolA), @ptrToInt(poolB), 0, 0, 0); | |
| 194 | 199 | } |
| 195 | 200 | |
| 196 | 201 | /// Resize and/or move a piece associated with a memory pool. |
| 197 | 202 | pub fn mempoolChange(pool: [*]u8, addrA: [*]u8, mem: []u8) void { |
| 198 | doClientRequestStmt(ClientRequest.MempoolChange, @ptrToInt(pool), @ptrToInt(addrA), @ptrToInt(mem.ptr), mem.len, 0); | |
| 203 | doClientRequestStmt(.MempoolChange, @ptrToInt(pool), @ptrToInt(addrA), @ptrToInt(mem.ptr), mem.len, 0); | |
| 199 | 204 | } |
| 200 | 205 | |
| 201 | 206 | /// Return if a mempool exists. |
| 202 | 207 | pub fn mempoolExists(pool: [*]u8) bool { |
| 203 | return doClientRequestExpr(0, ClientRequest.MempoolExists, @ptrToInt(pool), 0, 0, 0, 0) != 0; | |
| 208 | return doClientRequestExpr(0, .MempoolExists, @ptrToInt(pool), 0, 0, 0, 0) != 0; | |
| 204 | 209 | } |
| 205 | 210 | |
| 206 | 211 | /// Mark a piece of memory as being a stack. Returns a stack id. |
| 207 | 212 | /// start is the lowest addressable stack byte, end is the highest |
| 208 | 213 | /// addressable stack byte. |
| 209 | 214 | pub fn stackRegister(stack: []u8) usize { |
| 210 | return doClientRequestExpr(0, ClientRequest.StackRegister, @ptrToInt(stack.ptr), @ptrToInt(stack.ptr) + stack.len, 0, 0, 0); | |
| 215 | return doClientRequestExpr(0, .StackRegister, @ptrToInt(stack.ptr), @ptrToInt(stack.ptr) + stack.len, 0, 0, 0); | |
| 211 | 216 | } |
| 212 | 217 | |
| 213 | 218 | /// Unmark the piece of memory associated with a stack id as being a stack. |
| 214 | 219 | pub fn stackDeregister(id: usize) void { |
| 215 | doClientRequestStmt(ClientRequest.StackDeregister, id, 0, 0, 0, 0); | |
| 220 | doClientRequestStmt(.StackDeregister, id, 0, 0, 0, 0); | |
| 216 | 221 | } |
| 217 | 222 | |
| 218 | 223 | /// Change the start and end address of the stack id. |
| 219 | 224 | /// start is the new lowest addressable stack byte, end is the new highest |
| 220 | 225 | /// addressable stack byte. |
| 221 | 226 | pub fn stackChange(id: usize, newstack: []u8) void { |
| 222 | doClientRequestStmt(ClientRequest.StackChange, id, @ptrToInt(newstack.ptr), @ptrToInt(newstack.ptr) + newstack.len, 0, 0); | |
| 227 | doClientRequestStmt(.StackChange, id, @ptrToInt(newstack.ptr), @ptrToInt(newstack.ptr) + newstack.len, 0, 0); | |
| 223 | 228 | } |
| 224 | 229 | |
| 225 | 230 | // Load PDB debug info for Wine PE image_map. |
| 226 | 231 | // pub fn loadPdbDebuginfo(fd, ptr, total_size, delta) void { |
| 227 | // doClientRequestStmt(ClientRequest.LoadPdbDebuginfo, | |
| 232 | // doClientRequestStmt(.LoadPdbDebuginfo, | |
| 228 | 233 | // fd, ptr, total_size, delta, |
| 229 | 234 | // 0); |
| 230 | 235 | // } |
| ... | ... | @@ -234,7 +239,7 @@ pub fn stackChange(id: usize, newstack: []u8) void { |
| 234 | 239 | /// result will be dumped in there and is guaranteed to be zero |
| 235 | 240 | /// terminated. If no info is found, the first byte is set to zero. |
| 236 | 241 | pub fn mapIpToSrcloc(addr: *const u8, buf64: [64]u8) usize { |
| 237 | return doClientRequestExpr(0, ClientRequest.MapIpToSrcloc, @ptrToInt(addr), @ptrToInt(&buf64[0]), 0, 0, 0); | |
| 242 | return doClientRequestExpr(0, .MapIpToSrcloc, @ptrToInt(addr), @ptrToInt(&buf64[0]), 0, 0, 0); | |
| 238 | 243 | } |
| 239 | 244 | |
| 240 | 245 | /// Disable error reporting for this thread. Behaves in a stack like |
| ... | ... | @@ -246,12 +251,12 @@ pub fn mapIpToSrcloc(addr: *const u8, buf64: [64]u8) usize { |
| 246 | 251 | /// reporting. Child threads do not inherit this setting from their |
| 247 | 252 | /// parents -- they are always created with reporting enabled. |
| 248 | 253 | pub fn disableErrorReporting() void { |
| 249 | doClientRequestStmt(ClientRequest.ChangeErrDisablement, 1, 0, 0, 0, 0); | |
| 254 | doClientRequestStmt(.ChangeErrDisablement, 1, 0, 0, 0, 0); | |
| 250 | 255 | } |
| 251 | 256 | |
| 252 | 257 | /// Re-enable error reporting, (see disableErrorReporting()) |
| 253 | 258 | pub fn enableErrorReporting() void { |
| 254 | doClientRequestStmt(ClientRequest.ChangeErrDisablement, math.maxInt(usize), 0, 0, 0, 0); | |
| 259 | doClientRequestStmt(.ChangeErrDisablement, math.maxInt(usize), 0, 0, 0, 0); | |
| 255 | 260 | } |
| 256 | 261 | |
| 257 | 262 | /// Execute a monitor command from the client program. |
| ... | ... | @@ -260,8 +265,13 @@ pub fn enableErrorReporting() void { |
| 260 | 265 | /// If no connection is opened, output will go to the log output. |
| 261 | 266 | /// Returns 1 if command not recognised, 0 otherwise. |
| 262 | 267 | pub fn monitorCommand(command: [*]u8) bool { |
| 263 | return doClientRequestExpr(0, ClientRequest.GdbMonitorCommand, @ptrToInt(command.ptr), 0, 0, 0, 0) != 0; | |
| 268 | return doClientRequestExpr(0, .GdbMonitorCommand, @ptrToInt(command.ptr), 0, 0, 0, 0) != 0; | |
| 264 | 269 | } |
| 265 | 270 | |
| 266 | pub const memcheck = @import("memcheck.zig"); | |
| 267 | pub const callgrind = @import("callgrind.zig"); | |
| 271 | pub const memcheck = @import("valgrind/memcheck.zig"); | |
| 272 | pub const callgrind = @import("valgrind/callgrind.zig"); | |
| 273 | ||
| 274 | test "" { | |
| 275 | _ = @import("valgrind/memcheck.zig"); | |
| 276 | _ = @import("valgrind/callgrind.zig"); | |
| 277 | } |
lib/std/valgrind/callgrind.zig+7-7| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const std = @import("../index.zig"); | |
| 1 | const std = @import("../std.zig"); | |
| 2 | 2 | const valgrind = std.valgrind; |
| 3 | 3 | |
| 4 | 4 | pub const CallgrindClientRequest = extern enum { |
| ... | ... | @@ -20,7 +20,7 @@ fn doCallgrindClientRequestStmt(request: CallgrindClientRequest, a1: usize, a2: |
| 20 | 20 | |
| 21 | 21 | /// Dump current state of cost centers, and zero them afterwards |
| 22 | 22 | pub fn dumpStats() void { |
| 23 | doCallgrindClientRequestStmt(CallgrindClientRequest.DumpStats, 0, 0, 0, 0, 0); | |
| 23 | doCallgrindClientRequestStmt(.DumpStats, 0, 0, 0, 0, 0); | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /// Dump current state of cost centers, and zero them afterwards. |
| ... | ... | @@ -28,12 +28,12 @@ pub fn dumpStats() void { |
| 28 | 28 | /// the dump. This string is written as a description field into the |
| 29 | 29 | /// profile data dump. |
| 30 | 30 | pub fn dumpStatsAt(pos_str: [*]u8) void { |
| 31 | doCallgrindClientRequestStmt(CallgrindClientRequest.DumpStatsAt, @ptrToInt(pos_str), 0, 0, 0, 0); | |
| 31 | doCallgrindClientRequestStmt(.DumpStatsAt, @ptrToInt(pos_str), 0, 0, 0, 0); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /// Zero cost centers |
| 35 | 35 | pub fn zeroStats() void { |
| 36 | doCallgrindClientRequestStmt(CallgrindClientRequest.ZeroStats, 0, 0, 0, 0, 0); | |
| 36 | doCallgrindClientRequestStmt(.ZeroStats, 0, 0, 0, 0, 0); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /// Toggles collection state. |
| ... | ... | @@ -41,7 +41,7 @@ pub fn zeroStats() void { |
| 41 | 41 | /// should be noted or if they are to be ignored. Events are noted |
| 42 | 42 | /// by increment of counters in a cost center |
| 43 | 43 | pub fn toggleCollect() void { |
| 44 | doCallgrindClientRequestStmt(CallgrindClientRequest.ToggleCollect, 0, 0, 0, 0, 0); | |
| 44 | doCallgrindClientRequestStmt(.ToggleCollect, 0, 0, 0, 0, 0); | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /// Start full callgrind instrumentation if not already switched on. |
| ... | ... | @@ -49,7 +49,7 @@ pub fn toggleCollect() void { |
| 49 | 49 | /// this will lead to an artificial cache warmup phase afterwards with |
| 50 | 50 | /// cache misses which would not have happened in reality. |
| 51 | 51 | pub fn startInstrumentation() void { |
| 52 | doCallgrindClientRequestStmt(CallgrindClientRequest.StartInstrumentation, 0, 0, 0, 0, 0); | |
| 52 | doCallgrindClientRequestStmt(.StartInstrumentation, 0, 0, 0, 0, 0); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /// Stop full callgrind instrumentation if not already switched off. |
| ... | ... | @@ -60,5 +60,5 @@ pub fn startInstrumentation() void { |
| 60 | 60 | /// To start Callgrind in this mode to ignore the setup phase, use |
| 61 | 61 | /// the option "--instr-atstart=no". |
| 62 | 62 | pub fn stopInstrumentation() void { |
| 63 | doCallgrindClientRequestStmt(CallgrindClientRequest.StopInstrumentation, 0, 0, 0, 0, 0); | |
| 63 | doCallgrindClientRequestStmt(.StopInstrumentation, 0, 0, 0, 0, 0); | |
| 64 | 64 | } |
lib/std/valgrind/memcheck.zig+60-21| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | const std = @import("../index.zig"); | |
| 1 | const std = @import("../std.zig"); | |
| 2 | const testing = std.testing; | |
| 2 | 3 | const valgrind = std.valgrind; |
| 3 | 4 | |
| 4 | 5 | pub const MemCheckClientRequest = extern enum { |
| ... | ... | @@ -31,7 +32,7 @@ fn doMemCheckClientRequestStmt(request: MemCheckClientRequest, a1: usize, a2: us |
| 31 | 32 | /// This returns -1 when run on Valgrind and 0 otherwise. |
| 32 | 33 | pub fn makeMemNoAccess(qzz: []u8) i1 { |
| 33 | 34 | return @intCast(i1, doMemCheckClientRequestExpr(0, // default return |
| 34 | MemCheckClientRequest.MakeMemNoAccess, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0)); | |
| 35 | .MakeMemNoAccess, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0)); | |
| 35 | 36 | } |
| 36 | 37 | |
| 37 | 38 | /// Similarly, mark memory at qzz.ptr as addressable but undefined |
| ... | ... | @@ -39,7 +40,7 @@ pub fn makeMemNoAccess(qzz: []u8) i1 { |
| 39 | 40 | /// This returns -1 when run on Valgrind and 0 otherwise. |
| 40 | 41 | pub fn makeMemUndefined(qzz: []u8) i1 { |
| 41 | 42 | return @intCast(i1, doMemCheckClientRequestExpr(0, // default return |
| 42 | MemCheckClientRequest.MakeMemUndefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0)); | |
| 43 | .MakeMemUndefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0)); | |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | 46 | /// Similarly, mark memory at qzz.ptr as addressable and defined |
| ... | ... | @@ -47,7 +48,7 @@ pub fn makeMemUndefined(qzz: []u8) i1 { |
| 47 | 48 | pub fn makeMemDefined(qzz: []u8) i1 { |
| 48 | 49 | // This returns -1 when run on Valgrind and 0 otherwise. |
| 49 | 50 | return @intCast(i1, doMemCheckClientRequestExpr(0, // default return |
| 50 | MemCheckClientRequest.MakeMemDefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0)); | |
| 51 | .MakeMemDefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0)); | |
| 51 | 52 | } |
| 52 | 53 | |
| 53 | 54 | /// Similar to makeMemDefined except that addressability is |
| ... | ... | @@ -56,7 +57,7 @@ pub fn makeMemDefined(qzz: []u8) i1 { |
| 56 | 57 | /// This returns -1 when run on Valgrind and 0 otherwise. |
| 57 | 58 | pub fn makeMemDefinedIfAddressable(qzz: []u8) i1 { |
| 58 | 59 | return @intCast(i1, doMemCheckClientRequestExpr(0, // default return |
| 59 | MemCheckClientRequest.MakeMemDefinedIfAddressable, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0)); | |
| 60 | .MakeMemDefinedIfAddressable, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0)); | |
| 60 | 61 | } |
| 61 | 62 | |
| 62 | 63 | /// Create a block-description handle. The description is an ascii |
| ... | ... | @@ -65,14 +66,14 @@ pub fn makeMemDefinedIfAddressable(qzz: []u8) i1 { |
| 65 | 66 | /// properties of the memory range. |
| 66 | 67 | pub fn createBlock(qzz: []u8, desc: [*]u8) usize { |
| 67 | 68 | return doMemCheckClientRequestExpr(0, // default return |
| 68 | MemCheckClientRequest.CreateBlock, @ptrToInt(qzz.ptr), qzz.len, @ptrToInt(desc), 0, 0); | |
| 69 | .CreateBlock, @ptrToInt(qzz.ptr), qzz.len, @ptrToInt(desc), 0, 0); | |
| 69 | 70 | } |
| 70 | 71 | |
| 71 | 72 | /// Discard a block-description-handle. Returns 1 for an |
| 72 | 73 | /// invalid handle, 0 for a valid handle. |
| 73 | 74 | pub fn discard(blkindex) bool { |
| 74 | 75 | return doMemCheckClientRequestExpr(0, // default return |
| 75 | MemCheckClientRequest.Discard, 0, blkindex, 0, 0, 0) != 0; | |
| 76 | .Discard, 0, blkindex, 0, 0, 0) != 0; | |
| 76 | 77 | } |
| 77 | 78 | |
| 78 | 79 | /// Check that memory at qzz.ptr is addressable for qzz.len bytes. |
| ... | ... | @@ -80,7 +81,7 @@ pub fn discard(blkindex) bool { |
| 80 | 81 | /// error message and returns the address of the first offending byte. |
| 81 | 82 | /// Otherwise it returns zero. |
| 82 | 83 | pub fn checkMemIsAddressable(qzz: []u8) usize { |
| 83 | return doMemCheckClientRequestExpr(0, MemCheckClientRequest.CheckMemIsAddressable, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0); | |
| 84 | return doMemCheckClientRequestExpr(0, .CheckMemIsAddressable, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0); | |
| 84 | 85 | } |
| 85 | 86 | |
| 86 | 87 | /// Check that memory at qzz.ptr is addressable and defined for |
| ... | ... | @@ -88,31 +89,31 @@ pub fn checkMemIsAddressable(qzz: []u8) usize { |
| 88 | 89 | /// established, Valgrind prints an error message and returns the |
| 89 | 90 | /// address of the first offending byte. Otherwise it returns zero. |
| 90 | 91 | pub fn checkMemIsDefined(qzz: []u8) usize { |
| 91 | return doMemCheckClientRequestExpr(0, MemCheckClientRequest.CheckMemIsDefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0); | |
| 92 | return doMemCheckClientRequestExpr(0, .CheckMemIsDefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0); | |
| 92 | 93 | } |
| 93 | 94 | |
| 94 | 95 | /// Do a full memory leak check (like --leak-check=full) mid-execution. |
| 95 | 96 | pub fn doLeakCheck() void { |
| 96 | doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 0, 0, 0, 0, 0); | |
| 97 | doMemCheckClientRequestStmt(.DO_LEAK_CHECK, 0, 0, 0, 0, 0); | |
| 97 | 98 | } |
| 98 | 99 | |
| 99 | 100 | /// Same as doLeakCheck() but only showing the entries for |
| 100 | 101 | /// which there was an increase in leaked bytes or leaked nr of blocks |
| 101 | 102 | /// since the previous leak search. |
| 102 | 103 | pub fn doAddedLeakCheck() void { |
| 103 | doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 0, 1, 0, 0, 0); | |
| 104 | doMemCheckClientRequestStmt(.DO_LEAK_CHECK, 0, 1, 0, 0, 0); | |
| 104 | 105 | } |
| 105 | 106 | |
| 106 | 107 | /// Same as doAddedLeakCheck() but showing entries with |
| 107 | 108 | /// increased or decreased leaked bytes/blocks since previous leak |
| 108 | 109 | /// search. |
| 109 | 110 | pub fn doChangedLeakCheck() void { |
| 110 | doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 0, 2, 0, 0, 0); | |
| 111 | doMemCheckClientRequestStmt(.DO_LEAK_CHECK, 0, 2, 0, 0, 0); | |
| 111 | 112 | } |
| 112 | 113 | |
| 113 | 114 | /// Do a summary memory leak check (like --leak-check=summary) mid-execution. |
| 114 | 115 | pub fn doQuickLeakCheck() void { |
| 115 | doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 1, 0, 0, 0, 0); | |
| 116 | doMemCheckClientRequestStmt(.DO_LEAK_CHECK, 1, 0, 0, 0, 0); | |
| 116 | 117 | } |
| 117 | 118 | |
| 118 | 119 | /// Return number of leaked, dubious, reachable and suppressed bytes found by |
| ... | ... | @@ -125,27 +126,65 @@ const CountResult = struct { |
| 125 | 126 | }; |
| 126 | 127 | |
| 127 | 128 | pub fn countLeaks() CountResult { |
| 128 | var res = CountResult{ | |
| 129 | var res: CountResult = .{ | |
| 129 | 130 | .leaked = 0, |
| 130 | 131 | .dubious = 0, |
| 131 | 132 | .reachable = 0, |
| 132 | 133 | .suppressed = 0, |
| 133 | 134 | }; |
| 134 | doMemCheckClientRequestStmt(MemCheckClientRequest.CountLeaks, &res.leaked, &res.dubious, &res.reachable, &res.suppressed, 0); | |
| 135 | doMemCheckClientRequestStmt( | |
| 136 | .CountLeaks, | |
| 137 | @ptrToInt(&res.leaked), | |
| 138 | @ptrToInt(&res.dubious), | |
| 139 | @ptrToInt(&res.reachable), | |
| 140 | @ptrToInt(&res.suppressed), | |
| 141 | 0, | |
| 142 | ); | |
| 135 | 143 | return res; |
| 136 | 144 | } |
| 137 | 145 | |
| 146 | test "countLeaks" { | |
| 147 | testing.expectEqual( | |
| 148 | @as(CountResult, .{ | |
| 149 | .leaked = 0, | |
| 150 | .dubious = 0, | |
| 151 | .reachable = 0, | |
| 152 | .suppressed = 0, | |
| 153 | }), | |
| 154 | countLeaks(), | |
| 155 | ); | |
| 156 | } | |
| 157 | ||
| 138 | 158 | pub fn countLeakBlocks() CountResult { |
| 139 | var res = CountResult{ | |
| 159 | var res: CountResult = .{ | |
| 140 | 160 | .leaked = 0, |
| 141 | 161 | .dubious = 0, |
| 142 | 162 | .reachable = 0, |
| 143 | 163 | .suppressed = 0, |
| 144 | 164 | }; |
| 145 | doMemCheckClientRequestStmt(MemCheckClientRequest.CountLeakBlocks, &res.leaked, &res.dubious, &res.reachable, &res.suppressed, 0); | |
| 165 | doMemCheckClientRequestStmt( | |
| 166 | .CountLeakBlocks, | |
| 167 | @ptrToInt(&res.leaked), | |
| 168 | @ptrToInt(&res.dubious), | |
| 169 | @ptrToInt(&res.reachable), | |
| 170 | @ptrToInt(&res.suppressed), | |
| 171 | 0, | |
| 172 | ); | |
| 146 | 173 | return res; |
| 147 | 174 | } |
| 148 | 175 | |
| 176 | test "countLeakBlocks" { | |
| 177 | testing.expectEqual( | |
| 178 | @as(CountResult, .{ | |
| 179 | .leaked = 0, | |
| 180 | .dubious = 0, | |
| 181 | .reachable = 0, | |
| 182 | .suppressed = 0, | |
| 183 | }), | |
| 184 | countLeakBlocks(), | |
| 185 | ); | |
| 186 | } | |
| 187 | ||
| 149 | 188 | /// Get the validity data for addresses zza and copy it |
| 150 | 189 | /// into the provided zzvbits array. Return values: |
| 151 | 190 | /// 0 if not running on valgrind |
| ... | ... | @@ -156,7 +195,7 @@ pub fn countLeakBlocks() CountResult { |
| 156 | 195 | /// impossible to segfault your system by using this call. |
| 157 | 196 | pub fn getVbits(zza: []u8, zzvbits: []u8) u2 { |
| 158 | 197 | std.debug.assert(zzvbits.len >= zza.len / 8); |
| 159 | return @intCast(u2, doMemCheckClientRequestExpr(0, MemCheckClientRequest.GetVbits, @ptrToInt(zza.ptr), @ptrToInt(zzvbits), zza.len, 0, 0)); | |
| 198 | return @intCast(u2, doMemCheckClientRequestExpr(0, .GetVbits, @ptrToInt(zza.ptr), @ptrToInt(zzvbits), zza.len, 0, 0)); | |
| 160 | 199 | } |
| 161 | 200 | |
| 162 | 201 | /// Set the validity data for addresses zza, copying it |
| ... | ... | @@ -169,17 +208,17 @@ pub fn getVbits(zza: []u8, zzvbits: []u8) u2 { |
| 169 | 208 | /// impossible to segfault your system by using this call. |
| 170 | 209 | pub fn setVbits(zzvbits: []u8, zza: []u8) u2 { |
| 171 | 210 | std.debug.assert(zzvbits.len >= zza.len / 8); |
| 172 | return @intCast(u2, doMemCheckClientRequestExpr(0, MemCheckClientRequest.SetVbits, @ptrToInt(zza.ptr), @ptrToInt(zzvbits), zza.len, 0, 0)); | |
| 211 | return @intCast(u2, doMemCheckClientRequestExpr(0, .SetVbits, @ptrToInt(zza.ptr), @ptrToInt(zzvbits), zza.len, 0, 0)); | |
| 173 | 212 | } |
| 174 | 213 | |
| 175 | 214 | /// Disable and re-enable reporting of addressing errors in the |
| 176 | 215 | /// specified address range. |
| 177 | 216 | pub fn disableAddrErrorReportingInRange(qzz: []u8) usize { |
| 178 | 217 | return doMemCheckClientRequestExpr(0, // default return |
| 179 | MemCheckClientRequest.DisableAddrErrorReportingInRange, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0); | |
| 218 | .DisableAddrErrorReportingInRange, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0); | |
| 180 | 219 | } |
| 181 | 220 | |
| 182 | 221 | pub fn enableAddrErrorReportingInRange(qzz: []u8) usize { |
| 183 | 222 | return doMemCheckClientRequestExpr(0, // default return |
| 184 | MemCheckClientRequest.EnableAddrErrorReportingInRange, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0); | |
| 223 | .EnableAddrErrorReportingInRange, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0); | |
| 185 | 224 | } |