static void options_init(client_id_t id) { const char *opstr = dr_get_options(id); const char *s; char token[OPTION_MAX_LENGTH]; /* default values */ dr_snprintf(options.logdir, BUFFER_SIZE_ELEMENTS(options.logdir), "."); for (s = dr_get_token(opstr, token, BUFFER_SIZE_ELEMENTS(token)); s != NULL; s = dr_get_token(s, token, BUFFER_SIZE_ELEMENTS(token))) { if (strcmp(token, "-logdir") == 0) { s = dr_get_token(s, options.logdir, BUFFER_SIZE_ELEMENTS(options.logdir)); USAGE_CHECK(s != NULL, "missing logdir path"); } else if (strcmp(token, "-verbose") == 0) { s = dr_get_token(s, token, BUFFER_SIZE_ELEMENTS(token)); USAGE_CHECK(s != NULL, "missing -verbose number"); if (s != NULL) { int res = dr_sscanf(token, "%u", &verbose); USAGE_CHECK(res == 1, "invalid -verbose number"); } } else if (strcmp(token, "-symcache_path") == 0) { s = dr_get_token(s, options.sympath, BUFFER_SIZE_ELEMENTS(options.sympath)); USAGE_CHECK(s != NULL, "missing symcache dir path"); ALERT(2, "<drstrace symbol source is %s>\n", options.sympath); } else { ALERT(0, "UNRECOGNIZED OPTION: \"%s\"\n", token); USAGE_CHECK(false, "invalid option"); } } }
/* file I/O */ void md_read_from_file (module_t * head, file_t file, bool extra_info){ uint64 map_size; size_t actual_size; bool ok; void * map = NULL; char * line; /*loop variables*/ int i; int j; /* linked list structure specific variables */ int no_modules; int no_instructions; unsigned int addr; char module_name[MAX_STRING_LENGTH]; /* for filling up the linked list data structure */ module_t * elem; ok = dr_file_size(file,&map_size); if(ok){ actual_size = (size_t)map_size; DR_ASSERT(actual_size == map_size); map = dr_map_file(file, &actual_size, 0, NULL, DR_MEMPROT_READ, 0); } dr_sscanf((char *)map,"%d\n",&no_modules); //dr_printf("%d\n",no_modules); //debug line = (char *)map; for(i=0;i<no_modules;i++){ line = strchr(line,'\n'); line++; //start of the next line //dr_sscanf(line,"%[^\t\n]\n",module_name); dr_get_token(line,module_name,MAX_STRING_LENGTH); //getFinalName(module_name); //dr_printf("%s\n",module_name); //debug line = strchr(line,'\n'); line++; //start of the next line dr_sscanf(line,"%d\n",&no_instructions); //dr_printf("%d\n",no_instructions); //debug //create a new element elem = new_elem(module_name,no_instructions+2); head->next = elem; head = elem; for(j=0;j<no_instructions;j++){ line = strchr(line,'\n'); line++; //start of the next line dr_sscanf(line,"%u\n",&addr); //dr_printf(line,"%x\n",addr); //debug add_bb_to_list(head->bbs,addr, extra_info, head->size_bbs); } } }