DR_EXPORT void dr_client_main(client_id_t id, int argc, const char *argv[]) { /* We need 2 reg slots beyond drreg's eflags slots => 3 slots */ drreg_options_t ops = {sizeof(ops), 3, false}; /* Specify priority relative to other instrumentation operations: */ drmgr_priority_t priority = { sizeof(priority), /* size of struct */ "memtrace", /* name of our operation */ NULL, /* optional name of operation we should precede */ NULL, /* optional name of operation we should follow */ 0}; /* numeric priority */ dr_set_client_name("DynamoRIO Sample Client 'memtrace'", "http://dynamorio.org/issues"); page_size = dr_page_size(); drmgr_init(); drutil_init(); client_id = id; mutex = dr_mutex_create(); dr_register_exit_event(event_exit); if (!drmgr_register_thread_init_event(event_thread_init) || !drmgr_register_thread_exit_event(event_thread_exit) || !drmgr_register_bb_app2app_event(event_bb_app2app, &priority) || !drmgr_register_bb_instrumentation_event(NULL, event_bb_insert, &priority) || drreg_init(&ops) != DRREG_SUCCESS) { /* something is wrong: can't continue */ DR_ASSERT(false); return; } tls_index = drmgr_register_tls_field(); DR_ASSERT(tls_index != -1); code_cache_init(); /* make it easy to tell, by looking at log file, which client executed */ dr_log(NULL, DR_LOG_ALL, 1, "Client 'memtrace' initializing\n"); #ifdef SHOW_RESULTS if (dr_is_notify_on()) { # ifdef WINDOWS /* ask for best-effort printing to cmd window. must be called at init. */ dr_enable_console_printing(); # endif dr_fprintf(STDERR, "Client memtrace is running\n"); } #endif }
void instrace_init(client_id_t id, const char * name, const char * arguments) { file_t in_file; file_t out_file; int i; char logfilename[MAX_STRING_LENGTH]; drmgr_init(); drutil_init(); client_id = id; DR_ASSERT(parse_commandline_args(arguments)==true); head = md_initialize(); instrace_head = md_initialize(); if(client_arg->filter_mode != FILTER_NONE){ in_file = dr_open_file(client_arg->filter_filename,DR_FILE_READ); DR_ASSERT(in_file != INVALID_FILE); md_read_from_file(head,in_file,false); dr_close_file(in_file); } mutex = dr_mutex_create(); tls_index = drmgr_register_tls_field(); DR_ASSERT(tls_index != -1); code_cache_init(); if (log_mode){ populate_conv_filename(logfilename, logdir, name, NULL); logfile = dr_open_file(logfilename, DR_FILE_WRITE_OVERWRITE); } strncpy(ins_pass_name, name, MAX_STRING_LENGTH); for(i=OP_FIRST;i<=OP_LAST; i++){ opcodes_visited[i] = false; } }