static void lookup_address(const char *dllpath, size_t modoffs) { drsym_error_t symres; drsym_info_t *sym; char sbuf[sizeof(*sym) + MAX_FUNC_LEN]; sym = (drsym_info_t *) sbuf; sym->struct_size = sizeof(*sym); sym->name_size = MAX_FUNC_LEN; symres = drsym_lookup_address(dllpath, modoffs, sym, DRSYM_DEMANGLE); if (symres == DRSYM_SUCCESS || symres == DRSYM_ERROR_LINE_NOT_AVAILABLE) { if (verbose) print_debug_kind(sym->debug_kind); if (sym->name_available_size >= sym->name_size) printf("WARNING: function name longer than max: %s\n", sym->name); if (show_func) printf("%s+0x%x\n", sym->name, (uint)(modoffs - sym->start_offs)); if (symres == DRSYM_ERROR_LINE_NOT_AVAILABLE) { printf("??:0\n"); } else { printf("%s:%"INT64_FORMAT"u+0x%x\n", sym->file, sym->line, (uint)sym->line_offs); } } else { if (verbose) printf("drsym_lookup_address error %d\n", symres); else if (show_func) printf("?\n"); } }
static void symquery_lookup_address(const char *dllpath, size_t modoffs) { drsym_error_t symres; drsym_info_t sym; char name[MAX_FUNC_LEN]; char file[MAXIMUM_PATH]; sym.struct_size = sizeof(sym); sym.name = name; sym.name_size = MAX_FUNC_LEN; sym.file = file; sym.file_size = MAXIMUM_PATH; symres = drsym_lookup_address(dllpath, modoffs, &sym, demangle_flags); if (symres == DRSYM_SUCCESS || symres == DRSYM_ERROR_LINE_NOT_AVAILABLE) { if (verbose) print_debug_kind(sym.debug_kind); if (sym.name_available_size >= sym.name_size) printf("WARNING: function name longer than max: %s\n", sym.name); if (show_func) printf("%s+"SIZE_FMTX"\n", sym.name, (modoffs - sym.start_offs)); if (symres == DRSYM_ERROR_LINE_NOT_AVAILABLE) { printf("??:0\n"); } else { printf("%s:%"INT64_FORMAT"u+"SIZE_FMTX"\n", sym.file, sym.line, sym.line_offs); } } else { if (verbose) printf("drsym_lookup_address error %d\n", symres); else if (show_func) printf("?\n"); } }
static void print_address(app_pc addr, int bits, double loss, double lossD) { testarr[testcount] = lossD; testcount++; char key_string[KEY_MAX_LENGTH]; snprintf(key_string, KEY_MAX_LENGTH, "%s", "main");//sym->name); const char* prefix = "PRINT ADDRESS: "; drsym_error_t symres; drsym_info_t *sym; char sbuf[sizeof(*sym) + MAX_SYM_RESULT]; module_data_t *data; data = dr_lookup_module(addr); if (data == NULL) { // dr_fprintf(logF, "%s data is null "PFX" \n", prefix, addr); return; } snprintf(process_path, MAXIMUM_PATH,"%s",data->full_path); if(!callgrind_log_created){ writeCallgrind(thread_id_for_log); callgrind_log_created = true; } sym = (drsym_info_t *) sbuf; sym->struct_size = sizeof(*sym); sym->name_size = MAX_SYM_RESULT; symres = drsym_lookup_address(data->full_path, addr - data->start, sym, DRSYM_DEFAULT_FLAGS); /* if (symres == DRSYM_SUCCESS || symres == DRSYM_ERROR_LINE_NOT_AVAILABLE) { const char *modname = dr_module_preferred_name(data); if (modname == NULL) modname = "<noname>"; //dr_fprintf(logF, "%s "PFX" %s, function name is: %s, "PIFX", line off "PFX" \n", prefix, addr, //modname, sym->name, addr - data->start - sym->start_offs, sym->line_offs); //printf("test ins %d\n", testcount); //add check for line not available if (symres == DRSYM_ERROR_LINE_NOT_AVAILABLE) { // dr_fprintf(logF, "%s Line is not available\n", prefix); } else { // dr_fprintf(logF, "Line number is %s:%"UINT64_FORMAT_CODE" %d\n", // sym->file, sym->line, sym->line_offs); } } else // dr_fprintf(logF, "%s some error "PFX" \n", prefix, addr); */ dr_free_module_data(data); }
/* * Make a string representation of the address of an instruction, * including a function name and/or a file+line combination if * possible. These will be logged alongside every act of interest * where we can make one. */ static void instr_format_location(instr_t *instr, char **outloc) { app_pc addr = (app_pc)instr_get_app_pc(instr); char location[2048], symbol[512], fileline[1024]; bool got_sym = false, got_line = false; if (*outloc) return; symbol[0] = '\0'; fileline[0] = '\0'; module_data_t *data = dr_lookup_module(addr); if (data) { drsym_info_t sym; char file[MAXIMUM_PATH]; sym.struct_size = sizeof(sym); sym.name = symbol; sym.name_size = sizeof(symbol); sym.file = file; sym.file_size = sizeof(file); drsym_error_t status = drsym_lookup_address( data->full_path, addr - data->start, &sym, DRSYM_DEFAULT_FLAGS); got_line = (status == DRSYM_SUCCESS); got_sym = got_line || status == DRSYM_ERROR_LINE_NOT_AVAILABLE; if (got_line) snprintf(fileline, sizeof(fileline), " = %s:%"PRIu64, file, (uint64_t)sym.line); } snprintf(location, sizeof(location), "%"PRIx64"%s%s%s", (uint64_t)addr, got_sym ? " = " : "", got_sym ? symbol : "", fileline); size_t len = strlen(location) + 1; char *loc = dr_global_alloc(len); memcpy(loc, location, len); *outloc = loc; }
static void print_address(file_t f, app_pc addr, const char *prefix) { drsym_error_t symres; drsym_info_t sym; char name[MAX_SYM_RESULT]; char file[MAXIMUM_PATH]; module_data_t *data; data = dr_lookup_module(addr); if (data == NULL) { dr_fprintf(f, "%s "PFX" ? ??:0\n", prefix, addr); return; } sym.struct_size = sizeof(sym); sym.name = name; sym.name_size = MAX_SYM_RESULT; sym.file = file; sym.file_size = MAXIMUM_PATH; symres = drsym_lookup_address(data->full_path, addr - data->start, &sym, DRSYM_DEFAULT_FLAGS); if (symres == DRSYM_SUCCESS || symres == DRSYM_ERROR_LINE_NOT_AVAILABLE) { const char *modname = dr_module_preferred_name(data); if (modname == NULL) modname = "<noname>"; dr_fprintf(f, "%s "PFX" %s!%s+"PIFX, prefix, addr, modname, sym.name, addr - data->start - sym.start_offs); if (symres == DRSYM_ERROR_LINE_NOT_AVAILABLE) { dr_fprintf(f, " ??:0\n"); } else { dr_fprintf(f, " %s:%"UINT64_FORMAT_CODE"+"PIFX"\n", sym.file, sym.line, sym.line_offs); } } else dr_fprintf(f, "%s "PFX" ? ??:0\n", prefix, addr); dr_free_module_data(data); }