builtinstdmathdoClientRequestClientRequestToolBaseIsTooldoClientRequestExprdoClientRequestStmtrunningOnValgrinddiscardTranslationsinnerThreadsnonSimdCall0nonSimdCall1nonSimdCall2nonSimdCall3countErrorsmallocLikeBlockresizeInPlaceBlockfreeLikeBlockMempoolFlagscreateMempooldestroyMempoolmempoolAllocmempoolFreemempoolTrimmoveMempoolmempoolChangemempoolExistsstackRegisterstackDeregisterstackChangemapIpToSrclocdisableErrorReportingenableErrorReportingmonitorCommandmemcheckcallgrindcachegrind
std.valgrind.builtin
常量
std.valgrind.cachegrind
别名
std.valgrind.callgrind
别名
std.valgrind.ClientRequest
容器
字段
RunningOnValgrind = 4097
DiscardTranslations = 4098
ClientCall0 = 4353
ClientCall1 = 4354
ClientCall2 = 4355
ClientCall3 = 4356
CountErrors = 4609
GdbMonitorCommand = 4610
MalloclikeBlock = 4865
ResizeinplaceBlock = 4875
FreelikeBlock = 4866
CreateMempool = 4867
DestroyMempool = 4868
MempoolAlloc = 4869
MempoolFree = 4870
MempoolTrim = 4871
MoveMempool = 4872
MempoolChange = 4873
MempoolExists = 4874
Printf = 5121
PrintfBacktrace = 5122
PrintfValistByRef = 5123
PrintfBacktraceValistByRef = 5124
StackRegister = 5377
StackDeregister = 5378
StackChange = 5379
LoadPdbDebuginfo = 5633
MapIpToSrcloc = 5889
ChangeErrDisablement = 6145
VexInitForIri = 6401
InnerThreads = 6402
std.valgrind.countErrors
函数
统计工具已记录的错误数量。注意: 工具必须通过 VG_(maybe_record_error)() 或 VG_(unique_error)() 记录错误,才能将其计入。
pub fn countErrors() usize
std.valgrind.createMempool
函数
pub fn createMempool(pool: [*]u8, rzB: usize, is_zeroed: bool, flags: usize) void
参数
pool: [*]u8
rzB: usize
is_zeroed: bool
flags: usize
std.valgrind.destroyMempool
函数
销毁内存池。
pub fn destroyMempool(pool: [*]u8) void
参数
pool: [*]u8
std.valgrind.disableErrorReporting
函数
禁用当前线程的错误报告。此操作按栈式方式工作,因此只要随后调用相同次数的 enableErrorReporting() 来重新启用报告,就可以安全地多次调用。 首次调用此宏会禁用报告。后续调用除增加重新启用报告所需的 enableErrorReporting() 调用次数外,没有其他作用。 子线程不继承父线程的此设置,创建时始终启用错误报告。
pub fn disableErrorReporting() void
std.valgrind.discardTranslations
函数
丢弃切片 qzz 中代码的翻译结果。调试即时编译器等组件时 此操作很有用,因为它可确保 valgrind 重新翻译已失效区域。不返回值。
pub fn discardTranslations(qzz: []const u8) void
参数
qzz: []const u8
std.valgrind.doClientRequest
函数
pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize
参数
default: usize
request: usize
a1: usize
a2: usize
a3: usize
a4: usize
a5: usize
std.valgrind.doClientRequestExpr
函数
fn doClientRequestExpr(default: usize, request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize
参数
std.valgrind.doClientRequestStmt
函数
fn doClientRequestStmt(request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void
参数
std.valgrind.enableErrorReporting
函数
重新启用错误报告。(参见 disableErrorReporting())
pub fn enableErrorReporting() void
std.valgrind.freeLikeBlock
函数
pub fn freeLikeBlock(addr: [*]u8, rzB: usize) void
参数
addr: [*]u8
rzB: usize
std.valgrind.innerThreads
函数
pub fn innerThreads(qzz: [*]u8) void
参数
qzz: [*]u8
std.valgrind.IsTool
函数
pub fn IsTool(base: [2]u8, code: usize) bool
参数
base: [2]u8
code: usize
std.valgrind.mallocLikeBlock
函数
pub fn mallocLikeBlock(mem: []u8, rzB: usize, is_zeroed: bool) void
参数
mem: []u8
rzB: usize
is_zeroed: bool
std.valgrind.mapIpToSrcloc
函数
将代码地址映射为源码文件名和行号。buf64 必须指向调用方地址空间中的 64 字节缓冲区。结果会 写入该缓冲区,并保证以零 结尾。若未找到信息,则将首字节设为零。
pub fn mapIpToSrcloc(addr: *const u8, buf64: [64]u8) usize
参数
addr: *const u8
buf64: [64]u8
std.valgrind.math
别名
别名目标 std.math
std.valgrind.memcheck
别名
std.valgrind.mempoolAlloc
函数
将某块内存与内存池关联。
pub fn mempoolAlloc(pool: [*]u8, mem: []u8) void
参数
pool: [*]u8
mem: []u8
std.valgrind.mempoolChange
函数
调整内存池关联片段的大小,和/或移动它。
pub fn mempoolChange(pool: [*]u8, addrA: [*]u8, mem: []u8) void
参数
pool: [*]u8
addrA: [*]u8
mem: []u8
std.valgrind.mempoolExists
函数
若内存池存在则返回。
pub fn mempoolExists(pool: [*]u8) bool
参数
pool: [*]u8
std.valgrind.MempoolFlags
命名空间
创建内存池。
std.valgrind.MempoolFlags.AutoFree
常量
std.valgrind.MempoolFlags.MetaPool
常量
std.valgrind.mempoolFree
函数
解除某块内存与内存池的关联。
pub fn mempoolFree(pool: [*]u8, addr: [*]u8) void
参数
pool: [*]u8
addr: [*]u8
std.valgrind.mempoolTrim
函数
解除特定范围之外所有内存块的关联。
pub fn mempoolTrim(pool: [*]u8, mem: []u8) void
参数
pool: [*]u8
mem: []u8
std.valgrind.monitorCommand
函数
从客户端程序执行监视器命令。 若已建立 GDB 连接,输出将根据 为 vgdb 设置的输出模式发送。 若未建立连接,输出将写入日志输出。 命令无法识别时返回 1,否则返回 0。
pub fn monitorCommand(command: [*]u8) bool
参数
command: [*]u8
std.valgrind.moveMempool
函数
调整内存池关联片段的大小,和/或移动它。
pub fn moveMempool(poolA: [*]u8, poolB: [*]u8) void
参数
poolA: [*]u8
poolB: [*]u8
std.valgrind.nonSimdCall0
函数
pub fn nonSimdCall0(func: fn (usize) usize) usize
参数
func: fn (usize) usize
std.valgrind.nonSimdCall1
函数
pub fn nonSimdCall1(func: fn (usize, usize) usize, a1: usize) usize
参数
func: fn (usize, usize) usize
a1: usize
std.valgrind.nonSimdCall2
函数
pub fn nonSimdCall2(func: fn (usize, usize, usize) usize, a1: usize, a2: usize) usize
参数
func: fn (usize, usize, usize) usize
a1: usize
a2: usize
std.valgrind.nonSimdCall3
函数
pub fn nonSimdCall3(func: fn (usize, usize, usize, usize) usize, a1: usize, a2: usize, a3: usize) usize
参数
func: fn (usize, usize, usize, usize) usize
a1: usize
a2: usize
a3: usize
std.valgrind.resizeInPlaceBlock
函数
pub fn resizeInPlaceBlock(oldmem: []u8, newsize: usize, rzB: usize) void
参数
oldmem: []u8
newsize: usize
rzB: usize
std.valgrind.runningOnValgrind
函数
返回此代码正运行于多少层 Valgrind 之下。 本机运行时为 0,在 Valgrind 下运行时为 1, 在运行于另一 Valgrind 下的 Valgrind 中运行时为 2, 依此类推。
pub fn runningOnValgrind() usize
std.valgrind.stackChange
函数
更改栈标识对应的起止地址。 start 是新的最低可寻址栈字节,end 是新的 最高可寻址栈字节。
pub fn stackChange(id: usize, newstack: []u8) void
参数
id: usize
newstack: []u8
std.valgrind.stackDeregister
函数
清除与某栈 ID 关联的内存块上的栈标记。
pub fn stackDeregister(id: usize) void
参数
id: usize
std.valgrind.stackRegister
函数
将一块内存标记为栈。返回栈标识。 start 是栈中可寻址的最低字节,end 是 可寻址的最高字节。
pub fn stackRegister(stack: []u8) usize
参数
stack: []u8
std.valgrind.std
别名
别名目标 std
std.valgrind.ToolBase
函数
pub fn ToolBase(base: [2]u8) u32
参数
base: [2]u8
源码
std/valgrind.zig
const builtin = @import("builtin");
const std = @import("std.zig");
const math = std.math;
pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
if (!builtin.valgrind_support) {
return default;
}
const args = &[_]usize{ request, a1, a2, a3, a4, a5 };
return switch (builtin.cpu.arch) {
.arm, .armeb, .thumb, .thumbeb => asm volatile (
\\ mov r12, r12, ror #3 ; mov r12, r12, ror #13
\\ mov r12, r12, ror #29 ; mov r12, r12, ror #19
\\ orr r10, r10, r10
: [_] "={r3}" (-> usize),
: [_] "{r4}" (args),
[_] "{r3}" (default),
: .{ .memory = true }),
.aarch64, .aarch64_be => asm volatile (
\\ ror x12, x12, #3 ; ror x12, x12, #13
\\ ror x12, x12, #51 ; ror x12, x12, #61
\\ orr x10, x10, x10
: [_] "={x3}" (-> usize),
: [_] "{x4}" (args),
[_] "{x3}" (default),
: .{ .memory = true }),
.mips, .mipsel => asm volatile (
\\ srl $0, $0, 13
\\ srl $0, $0, 29
\\ srl $0, $0, 3
\\ srl $0, $0, 19
\\ or $13, $13, $13
: [_] "={$11}" (-> usize),
: [_] "{$12}" (args),
[_] "{$11}" (default),
: .{ .memory = true }),
.mips64, .mips64el => asm volatile (
\\ dsll $0, $0, 3 ; dsll $0, $0, 13
\\ dsll $0, $0, 29 ; dsll $0, $0, 19
\\ or $13, $13, $13
: [_] "={$11}" (-> usize),
: [_] "{$12}" (args),
[_] "{$11}" (default),
: .{ .memory = true }),
.powerpc, .powerpcle => asm volatile (
\\ rlwinm 0, 0, 3, 0, 31 ; rlwinm 0, 0, 13, 0, 31
\\ rlwinm 0, 0, 29, 0, 31 ; rlwinm 0, 0, 19, 0, 31
\\ or 1, 1, 1
: [_] "={r3}" (-> usize),
: [_] "{r4}" (args),
[_] "{r3}" (default),
: .{ .memory = true }),
.powerpc64, .powerpc64le => asm volatile (
\\ rotldi 0, 0, 3 ; rotldi 0, 0, 13
\\ rotldi 0, 0, 61 ; rotldi 0, 0, 51
\\ or 1, 1, 1
: [_] "={r3}" (-> usize),
: [_] "{r4}" (args),
[_] "{r3}" (default),
: .{ .memory = true }),
.riscv64 => asm volatile (
\\ .option push
\\ .option norvc
\\ srli zero, zero, 3
\\ srli zero, zero, 13
\\ srli zero, zero, 51
\\ srli zero, zero, 61
\\ or a0, a0, a0
\\ .option pop
: [_] "={a3}" (-> usize),
: [_] "{a4}" (args),
[_] "{a3}" (default),
: .{ .memory = true }),
.s390x => asm volatile (
\\ lr %%r15, %%r15
\\ lr %%r1, %%r1
\\ lr %%r2, %%r2
\\ lr %%r3, %%r3
\\ lr %%r2, %%r2
: [_] "={r3}" (-> usize),
: [_] "{r2}" (args),
[_] "{r3}" (default),
: .{ .memory = true }),
.x86 => asm volatile (
\\ roll $3, %%edi ; roll $13, %%edi
\\ roll $29, %%edi ; roll $19, %%edi
\\ xchgl %%ebx, %%ebx
: [_] "={edx}" (-> usize),
: [_] "{eax}" (args),
[_] "{edx}" (default),
: .{ .memory = true }),
.x86_64 => asm volatile (
\\ rolq $3, %%rdi ; rolq $13, %%rdi
\\ rolq $61, %%rdi ; rolq $51, %%rdi
\\ xchgq %%rbx, %%rbx
: [_] "={rdx}" (-> usize),
: [_] "{rax}" (args),
[_] "{rdx}" (default),
: .{ .memory = true }),
else => default,
};
}
pub const ClientRequest = enum(u32) {
RunningOnValgrind = 4097,
DiscardTranslations = 4098,
ClientCall0 = 4353,
ClientCall1 = 4354,
ClientCall2 = 4355,
ClientCall3 = 4356,
CountErrors = 4609,
GdbMonitorCommand = 4610,
MalloclikeBlock = 4865,
ResizeinplaceBlock = 4875,
FreelikeBlock = 4866,
CreateMempool = 4867,
DestroyMempool = 4868,
MempoolAlloc = 4869,
MempoolFree = 4870,
MempoolTrim = 4871,
MoveMempool = 4872,
MempoolChange = 4873,
MempoolExists = 4874,
Printf = 5121,
PrintfBacktrace = 5122,
PrintfValistByRef = 5123,
PrintfBacktraceValistByRef = 5124,
StackRegister = 5377,
StackDeregister = 5378,
StackChange = 5379,
LoadPdbDebuginfo = 5633,
MapIpToSrcloc = 5889,
ChangeErrDisablement = 6145,
VexInitForIri = 6401,
InnerThreads = 6402,
};
pub fn ToolBase(base: [2]u8) u32 {
return (@as(u32, base[0] & 0xff) << 24) | (@as(u32, base[1] & 0xff) << 16);
}
pub fn IsTool(base: [2]u8, code: usize) bool {
return ToolBase(base) == (code & 0xffff0000);
}
fn doClientRequestExpr(default: usize, request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
return doClientRequest(default, @as(usize, @intCast(@backingInt(request))), a1, a2, a3, a4, a5);
}
fn doClientRequestStmt(request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {
_ = doClientRequestExpr(0, request, a1, a2, a3, a4, a5);
}
/// 返回此代码正运行于多少层 Valgrind 之下。
/// 本机运行时为 0,在 Valgrind 下运行时为 1,
/// 在运行于另一 Valgrind 下的 Valgrind 中运行时为 2,
/// 依此类推。
pub fn runningOnValgrind() usize {
return doClientRequestExpr(0, .RunningOnValgrind, 0, 0, 0, 0, 0);
}
test "works whether running on valgrind or not" {
_ = runningOnValgrind();
}
/// 丢弃切片 qzz 中代码的翻译结果。调试即时编译器等组件时
/// 此操作很有用,因为它可确保 valgrind
/// 重新翻译已失效区域。不返回值。
pub fn discardTranslations(qzz: []const u8) void {
doClientRequestStmt(.DiscardTranslations, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0);
}
pub fn innerThreads(qzz: [*]u8) void {
doClientRequestStmt(.InnerThreads, @intFromPtr(qzz), 0, 0, 0, 0);
}
pub fn nonSimdCall0(func: fn (usize) usize) usize {
return doClientRequestExpr(0, .ClientCall0, @intFromPtr(func), 0, 0, 0, 0);
}
pub fn nonSimdCall1(func: fn (usize, usize) usize, a1: usize) usize {
return doClientRequestExpr(0, .ClientCall1, @intFromPtr(func), a1, 0, 0, 0);
}
pub fn nonSimdCall2(func: fn (usize, usize, usize) usize, a1: usize, a2: usize) usize {
return doClientRequestExpr(0, .ClientCall2, @intFromPtr(func), a1, a2, 0, 0);
}
pub fn nonSimdCall3(func: fn (usize, usize, usize, usize) usize, a1: usize, a2: usize, a3: usize) usize {
return doClientRequestExpr(0, .ClientCall3, @intFromPtr(func), a1, a2, a3, 0);
}
/// 统计工具已记录的错误数量。注意:
/// 工具必须通过 VG_(maybe_record_error)() 或
/// VG_(unique_error)() 记录错误,才能将其计入。
pub fn countErrors() usize {
return doClientRequestExpr(0, // 默认返回
.CountErrors, 0, 0, 0, 0, 0);
}
pub fn mallocLikeBlock(mem: []u8, rzB: usize, is_zeroed: bool) void {
doClientRequestStmt(.MalloclikeBlock, @intFromPtr(mem.ptr), mem.len, rzB, @intFromBool(is_zeroed), 0);
}
pub fn resizeInPlaceBlock(oldmem: []u8, newsize: usize, rzB: usize) void {
doClientRequestStmt(.ResizeinplaceBlock, @intFromPtr(oldmem.ptr), oldmem.len, newsize, rzB, 0);
}
pub fn freeLikeBlock(addr: [*]u8, rzB: usize) void {
doClientRequestStmt(.FreelikeBlock, @intFromPtr(addr), rzB, 0, 0, 0);
}
/// 创建内存池。
pub const MempoolFlags = struct {
pub const AutoFree = 1;
pub const MetaPool = 2;
};
pub fn createMempool(pool: [*]u8, rzB: usize, is_zeroed: bool, flags: usize) void {
doClientRequestStmt(.CreateMempool, @intFromPtr(pool), rzB, @intFromBool(is_zeroed), flags, 0);
}
/// 销毁内存池。
pub fn destroyMempool(pool: [*]u8) void {
doClientRequestStmt(.DestroyMempool, @intFromPtr(pool), 0, 0, 0, 0);
}
/// 将某块内存与内存池关联。
pub fn mempoolAlloc(pool: [*]u8, mem: []u8) void {
doClientRequestStmt(.MempoolAlloc, @intFromPtr(pool), @intFromPtr(mem.ptr), mem.len, 0, 0);
}
/// 解除某块内存与内存池的关联。
pub fn mempoolFree(pool: [*]u8, addr: [*]u8) void {
doClientRequestStmt(.MempoolFree, @intFromPtr(pool), @intFromPtr(addr), 0, 0, 0);
}
/// 解除特定范围之外所有内存块的关联。
pub fn mempoolTrim(pool: [*]u8, mem: []u8) void {
doClientRequestStmt(.MempoolTrim, @intFromPtr(pool), @intFromPtr(mem.ptr), mem.len, 0, 0);
}
/// 调整内存池关联片段的大小,和/或移动它。
pub fn moveMempool(poolA: [*]u8, poolB: [*]u8) void {
doClientRequestStmt(.MoveMempool, @intFromPtr(poolA), @intFromPtr(poolB), 0, 0, 0);
}
/// 调整内存池关联片段的大小,和/或移动它。
pub fn mempoolChange(pool: [*]u8, addrA: [*]u8, mem: []u8) void {
doClientRequestStmt(.MempoolChange, @intFromPtr(pool), @intFromPtr(addrA), @intFromPtr(mem.ptr), mem.len, 0);
}
/// 若内存池存在则返回。
pub fn mempoolExists(pool: [*]u8) bool {
return doClientRequestExpr(0, .MempoolExists, @intFromPtr(pool), 0, 0, 0, 0) != 0;
}
/// 将一块内存标记为栈。返回栈标识。
/// start 是栈中可寻址的最低字节,end 是
/// 可寻址的最高字节。
pub fn stackRegister(stack: []u8) usize {
return doClientRequestExpr(0, .StackRegister, @intFromPtr(stack.ptr), @intFromPtr(stack.ptr) + stack.len, 0, 0, 0);
}
/// 清除与某栈 ID 关联的内存块上的栈标记。
pub fn stackDeregister(id: usize) void {
doClientRequestStmt(.StackDeregister, id, 0, 0, 0, 0);
}
/// 更改栈标识对应的起止地址。
/// start 是新的最低可寻址栈字节,end 是新的
/// 最高可寻址栈字节。
pub fn stackChange(id: usize, newstack: []u8) void {
doClientRequestStmt(.StackChange, id, @intFromPtr(newstack.ptr), @intFromPtr(newstack.ptr) + newstack.len, 0, 0);
}
// 为 Wine PE image_map 加载 PDB 调试信息。
// pub fn loadPdbDebuginfo(fd, ptr, total_size, delta) void {
// doClientRequestStmt(.LoadPdbDebuginfo,
// fd, ptr, total_size, delta,
// 0);
// }
/// 将代码地址映射为源码文件名和行号。buf64
/// 必须指向调用方地址空间中的 64 字节缓冲区。结果会
/// 写入该缓冲区,并保证以零
/// 结尾。若未找到信息,则将首字节设为零。
pub fn mapIpToSrcloc(addr: *const u8, buf64: [64]u8) usize {
return doClientRequestExpr(0, .MapIpToSrcloc, @intFromPtr(addr), @intFromPtr(&buf64[0]), 0, 0, 0);
}
/// 禁用当前线程的错误报告。此操作按栈式方式工作,因此只要随后调用相同次数的 enableErrorReporting() 来重新启用报告,就可以安全地多次调用。
/// 首次调用此宏会禁用报告。后续调用除增加重新启用报告所需的 enableErrorReporting() 调用次数外,没有其他作用。
/// 子线程不继承父线程的此设置,创建时始终启用错误报告。
///
///
///
///
///
pub fn disableErrorReporting() void {
doClientRequestStmt(.ChangeErrDisablement, 1, 0, 0, 0, 0);
}
/// 重新启用错误报告。(参见 disableErrorReporting())
pub fn enableErrorReporting() void {
doClientRequestStmt(.ChangeErrDisablement, math.maxInt(usize), 0, 0, 0, 0);
}
/// 从客户端程序执行监视器命令。
/// 若已建立 GDB 连接,输出将根据
/// 为 vgdb 设置的输出模式发送。
/// 若未建立连接,输出将写入日志输出。
/// 命令无法识别时返回 1,否则返回 0。
pub fn monitorCommand(command: [*]u8) bool {
return doClientRequestExpr(0, .GdbMonitorCommand, @intFromPtr(command), 0, 0, 0, 0) != 0;
}
pub const memcheck = @import("valgrind/memcheck.zig");
pub const callgrind = @import("valgrind/callgrind.zig");
pub const cachegrind = @import("valgrind/cachegrind.zig");
test {
_ = memcheck;
_ = callgrind;
_ = cachegrind;
}