static void instrument_mem(void *drcontext, instrlist_t *ilist, instr_t *where,
int pos, bool write)
{
instr_t *instr, *call, *restore, *end = where;
opnd_t ref, opnd1, opnd2;
reg_id_t reg1, reg2, reg3;
drvector_t allowed;
app_pc pc;
/* Steal two scratch registers.
* reg2 must be ECX or RCX for jecxz.
*/
drreg_init_and_fill_vector(&allowed, false);//initialize allowed variable
drreg_set_vector_entry(&allowed, DR_REG_XCX, true);
if (drreg_reserve_register(drcontext, ilist, where, &allowed, ®2) != DRREG_SUCCESS ||
drreg_reserve_register(drcontext, ilist, where, NULL, ®1) != DRREG_SUCCESS ||
drreg_reserve_register(drcontext, ilist, where, NULL, ®3) != DRREG_SUCCESS) {
DR_ASSERT(false); /* cannot recover */
drvector_delete(&allowed);
return;
}
drvector_delete(&allowed);
...........
/* Store size in memory ref */
opnd1 = OPND_CREATE_MEMPTR(reg2, offsetof(mem_ref_t, size));
/* drutil_opnd_mem_size_in_bytes handles OP_enter */
opnd2 = OPND_CREATE_INT32(drutil_opnd_mem_size_in_bytes(ref, where));
instr = INSTR_CREATE_mov_st(drcontext, opnd1, opnd2);
instrlist_meta_preinsert(ilist, where, instr);
/* Store data to be written/read*/
if(!write){
opnd1 = opnd_create_reg(reg3);
opnd2 = OPND_CREATE_MEMPTR(reg1, 0);
instr = INSTR_CREATE_mov_ld(drcontext, opnd1, opnd2);
instrlist_meta_preinsert(ilist, where, instr);
opnd1 = OPND_CREATE_MEMPTR(reg2, offsetof(mem_ref_t, data));
opnd2 = opnd_create_reg(reg3);
instr = INSTR_CREATE_mov_st(drcontext, opnd1, opnd2);
// instrlist_meta_preinsert(ilist, where, instr);
}
.......
instrlist_meta_preinsert(ilist, where, restore);
if (drreg_unreserve_register(drcontext, ilist, end, reg1) != DRREG_SUCCESS ||
drreg_unreserve_register(drcontext, ilist, end, reg2) != DRREG_SUCCESS ||
drreg_unreserve_register(drcontext, ilist, end, reg3) != DRREG_SUCCESS)
DR_ASSERT(false);
}
kobayashi-y@localhost:~/source/DynamoRIO-Linux-6.2.0-2/samples/bin$ ../../bin64/drrun -c libmemtrace_x86_text.so -- /bin/lsClient memtrace is runningData file /home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/samples/bin/memtrace.ls.16986.0000.log createdInstrumentation results: saw 510 memory references
Segmentation fault static voidevent_exit(){#ifdef SHOW_RESULTS char msg[512]; int len; len = dr_snprintf(msg, sizeof(msg)/sizeof(msg[0]), "Instrumentation results:\n" " saw %llu memory references\n", num_refs); DR_ASSERT(len > 0); NULL_TERMINATE_BUFFER(msg); DISPLAY_STRING(msg);#endif /* SHOW_RESULTS */ code_cache_exit();
if (!drmgr_unregister_tls_field(tls_index) || !drmgr_unregister_thread_init_event(event_thread_init) || !drmgr_unregister_thread_exit_event(event_thread_exit) || !drmgr_unregister_bb_insertion_event(event_bb_insert) || drreg_exit() != DRREG_SUCCESS) DR_ASSERT(false);
dr_mutex_destroy(mutex); drutil_exit(); drmgr_exit();
DISPLAY_STRING(msg); //added }
Data file /home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/samples/bin/memtrace.ls.17217.0000.log createdInstrumentation results: saw 510 memory references
Instrumentation results: saw 510 memory references
Segmentation fault--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-users+unsubscribe@googlegroups.com.
To post to this group, send email to dynamorio-users@googlegroups.com.
Visit this group at https://groups.google.com/group/dynamorio-users.
For more options, visit https://groups.google.com/d/optout.
$ ../../bin64/drrun -debug -loglevel 4 -c libmemtrace_x86_text.so -- /bin/ls<log dir=/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/samples/bin/../../bin64/../logs/ls.13147.00000000><Starting application /usr/bin/ls (13147)><Paste into GDB to debug DynamoRIO clients:set confirm offadd-symbol-file '/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/samples/bin/libmemtrace_x86_text.so' 0x00000000720029d0add-symbol-file '/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/lib64/debug/libdynamorio.so' 0x000000007102d808add-symbol-file '/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/ext/lib64/debug/libdrmgr.so' 0x0000000073002980add-symbol-file '/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/ext/lib64/debug/libdrreg.so' 0x0000000078002720add-symbol-file '/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/ext/lib64/debug/libdrutil.so' 0x0000000075001610add-symbol-file '/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/ext/lib64/debug/libdrx.so' 0x0000000077002950add-symbol-file '/usr/lib64/libc.so.6' 0x00007f6a5bd223b0add-symbol-file '/usr/lib64/ld-linux-x86-64.so.2' 0x00007f6a5bae0af0><Initial options = -no_dynamic_options -loglevel 4 -client_lib '/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/samples/bin/libmemtrace_x86_text.so;0;' -code_api -stack_size 56K -max_elide_jmp 0 -max_elide_call 0 -early_inject -emulate_brk -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_managed_code -no_indcall2direct >Client memtrace is runningData file /home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/samples/bin/memtrace.ls.13147.0000.log created<Application /usr/bin/ls (13147) DynamoRIO usage error : meta-instr faulted? must set translation field and handle fault!><Usage error: meta-instr faulted? must set translation field and handle fault! (/dynamorio_package/core/translate.c, line 720)version 6.2.0, build 2-no_dynamic_options -loglevel 4 -client_lib '/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/samples/bin/libmemtrace_x86_text.so;0;' -code_api -stack_size 56K -max_elide_jmp 0 -max_elide_call 0 -early_inject -emulate_brk -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_managed_code -no_indcall2di0x0000000047665ea0 0x0000000071117d760x0000000047665ef0 0x0000000071223a210x0000000047665fd0 0x0000000071225b690x0000000047666620 0x00000000712260e70x0000000047666660 0x000000007120235e0x00000000476666c0 0x00000000712ebf980x00000000476669a0 0x00000000712f069a0x0000000047666ba0 0x00000000712f31110x0000000047666c30 0x00000000712b89920x00007ffd6621fbb0 0x00007f6a5c0dbe360x0000000000400040 0x0000000000000040/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/samples/bin/libmemtrace_x86_text.so=0x0000000072000000/usr/lib64/libc.so.6=0x00007f6a5bd03000/usr/lib64/ld-linux-x86-64.so.2=0x00007f6a5bae0000/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/ext/lib64/debug/libdrx.so=0x0000000077000000/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/ext/lib64/debug/libdrutil.so=0x0000000075000000/home/kobayashi-y/source/DynamoRIO-Linux-6.2.0-2/ext/lib64/debu>To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To post to this group, send email to dynamor...@googlegroups.com.
Dear Derek,In addition, I have another question.Can this `memtrace_x86` trap all memory access from qemu-kvm?
--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-users+unsubscribe@googlegroups.com.
To post to this group, send email to dynamorio-users@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To post to this group, send email to dynamor...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-users+unsubscribe@googlegroups.com.
To post to this group, send email to dynamorio-users@googlegroups.com.