2016-02-20 21 views
1

我想修補valgrind的狗狗示例工具。我想 檢查存儲指令二進制的存儲指令的指針周圍某個字符串序列的出現 。 或者掃描每個存儲上的所有存儲區域,查找此類序列的外觀 。有沒有人知道一個適當的 例子的參考?基本上我想Valgrind檢查內存,修補狗屁

for (i = -8; i <= 8; i++) { 
    if (strncmp(ptr+i, "needle", 6) == 0) 
     printf("Here ip: %x\n", ip); 
} 

但我怎麼能確認在[-8,8]爲有效範圍是PTR?有沒有 跟蹤堆區域的函數?或者我每次都必須跟蹤/ proc/pid/maps?

//康拉德

回答

1

原來,在Valgrind的的EXP-dhat工具爲我工作:

static VG_REGPARM(3) 
    void dh_handle_write (Addr addr, UWord szB) 
{ 
    Block* bk = find_Block_containing(addr); 
    if (bk) { 

    if (is_subinterval_of(bk->payload, bk->req_szB, addr-10, 10*2)) { 
     int i = 0; 
     for (i = -10; i <= 10; i++) { 
     if ((VG_(memcmp)(((char*)addr)+ i, searchfor, 6) == 0)) { 

      ExeContext *ec = VG_(record_ExeContext)(VG_(get_running_tid)(), 0); 
      VG_(pp_ExeContext) (ec); 
      VG_(printf)(" ---------------- ----------- found %08lx @ %08lx --------\n", addr, ip); 
     } 
     } 
    } 


     bk->n_writes += szB; 
     if (bk->histoW) 
     inc_histo_for_block(bk, addr, szB); 
    } 
} 

每次一寫我搜索陣列的次數searchfor並打印stacktrace if if found ...