gpt4 book ai didi

c - Valgrind 脏 helper 调用次数超出预期

转载 作者:行者123 更新时间:2023-11-30 17:46:39 28 4
gpt4 key购买 nike

我使用基本的 Valgrind 工具时出现了意外行为。对于基本 block 的每个 Put 语句,我使用以下方法注册一个脏助手unsafeIRDirty_0_N。问题是脏助手被调用的次数比预期的多,例如一个基本 block 中有 5 个 Put 语句,但脏助手是打了13次电话。我需要在我的工具中使用肮脏的助手,但我现在陷入困境,任何帮助将不胜感激。

这是代码:

unsigned int g_Put_cnt; // the number of Put statements in the basic block
unsigned int g_helper_Put_cnt; // the number of times helper_Put() was
called

static VG_REGPARM(0) void helper_print_counters()
{
VG_(printf)("g_Put_cnt: %d - g_helper_Put_cnt: %d (%d)\n", g_Put_cnt,
g_helper_Put_cnt, g_helper_Put_cnt-g_Put_cnt);
}

static VG_REGPARM(0) void helper_Put()
{
g_helper_Put_cnt++;
}

static
IRSB* fz_instrument ( VgCallbackClosure* closure,
IRSB* sb_in,
VexGuestLayout* layout,
VexGuestExtents* vge,
IRType gWordTy, IRType hWordTy )
{
IRSB* sb_out;
Int i;

if (gWordTy != hWordTy) {
/* We don't currently support this case. */
VG_(tool_panic)("host/guest word size mismatch");
}

/* Set up sb_out */
sb_out = deepCopyIRSBExceptStmts(sb_in);

// Copy verbatim any IR preamble preceding the first IMark
i = 0;
while (i < sb_in->stmts_used && sb_in->stmts[i]->tag != Ist_IMark) {
addStmtToIRSB(sb_out, sb_in->stmts[i]);
i++;
}

g_Put_cnt = 0;
g_helper_Put_cnt = 0;

for (/*use current i*/; i < sb_in->stmts_used; i++)
{
IRStmt* st = sb_in->stmts[i];
IRDirty* di;

if (!st)
continue;

switch (st->tag)
{
case Ist_Put:
di = unsafeIRDirty_0_N(0,
"helper_Put",
VG_(fnptr_to_fnentry)(&helper_Put),
mkIRExprVec_0());
addStmtToIRSB(sb_out, IRStmt_Dirty(di));

g_Put_cnt++;
break;
}

addStmtToIRSB(sb_out, st);
}

IRDirty* di = unsafeIRDirty_0_N(0, "helper_print_counters",
VG_(fnptr_to_fnentry)(&helper_print_counters), mkIRExprVec_0());
addStmtToIRSB(sb_out, IRStmt_Dirty(di));

return sb_out;
}

输出:

g_Put_cnt: 22 - g_helper_Put_cnt: 22 (0)
g_Put_cnt: 21 - g_helper_Put_cnt: 21 (0)
g_Put_cnt: 8 - g_helper_Put_cnt: 8 (0)
g_Put_cnt: 5 - g_helper_Put_cnt: 13 (8)
g_Put_cnt: 5 - g_helper_Put_cnt: 18 (13)
g_Put_cnt: 6 - g_helper_Put_cnt: 6 (0)
g_Put_cnt: 6 - g_helper_Put_cnt: 6 (0)
g_Put_cnt: 9 - g_helper_Put_cnt: 9 (0)
g_Put_cnt: 9 - g_helper_Put_cnt: 22 (13)
g_Put_cnt: 9 - g_helper_Put_cnt: 35 (26)
g_Put_cnt: 9 - g_helper_Put_cnt: 48 (39)
g_Put_cnt: 9 - g_helper_Put_cnt: 61 (52)
g_Put_cnt: 9 - g_helper_Put_cnt: 74 (65)
g_Put_cnt: 9 - g_helper_Put_cnt: 87 (78)
g_Put_cnt: 9 - g_helper_Put_cnt: 100 (91)
g_Put_cnt: 9 - g_helper_Put_cnt: 113 (104)
g_Put_cnt: 9 - g_helper_Put_cnt: 126 (117)
g_Put_cnt: 9 - g_helper_Put_cnt: 139 (130)
g_Put_cnt: 9 - g_helper_Put_cnt: 152 (143)
g_Put_cnt: 9 - g_helper_Put_cnt: 157 (148)
...

提前谢谢您。

最佳答案

我在 Valgrind 邮件列表上得到了答案:

http://sourceforge.net/mailarchive/message.php?msg_id=31488717

关于c - Valgrind 脏 helper 调用次数超出预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19200863/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com