/* Return line number and filename for an input PC * Note: The input pc has to be in the elf va form. The segment loader API should * resolve this before calling this function * */ bool hsail_dbginfo_get_pc_info(HwDbgInfo_addr pc, HwDbgInfo_linenum* op_line_num, char** op_file_name) { bool ret_code = false; HwDbgInfo_code_location loc = NULL; HwDbgInfo_debug dbg = hsail_init_hwdbginfo(NULL); HwDbgInfo_err err = HWDBGINFO_E_PARAMETER; HwDbgInfo_linenum line_num = 0; char* src_line = NULL; if (op_line_num == NULL || op_file_name == NULL) { return ret_code; } /* Go from PC to line by making a code_location object */ if (dbg != NULL) { size_t out_filename_len =0; size_t in_filename_len =1024; char* out_filename = (char*)malloc(sizeof(char)*in_filename_len); gdb_assert(out_filename != NULL); memset(out_filename, '\0', sizeof(char)*in_filename_len ); // for saxpy //pc += 4096; err = hwdbginfo_addr_to_line(dbg, pc, &loc); if (err != HWDBGINFO_E_SUCCESS) { printf("Debug facilities error %d", err); } err = hwdbginfo_code_location_details(loc, &line_num, in_filename_len, out_filename, &out_filename_len); if (err != HWDBGINFO_E_SUCCESS) { printf("Debug facilities in code location error %d", err); } if (out_filename != NULL) { if (strstr(out_filename, "hsa::self().elf") != NULL) { hsail_utils_copy_string(op_file_name, hsail_dbginfo_get_active_file_name()); } else { *op_file_name = out_filename; } } *op_line_num = line_num; hwdbginfo_release_code_locations(&loc, 1); ret_code = true; } return ret_code; }
static void hsail_step_write_momentary_breakpoints(HwDbgInfo_debug dbg, size_t step_addr_count, HwDbgInfo_addr* step_addrs) { int i = 0; HwDbgInfo_code_location loc = NULL; HwDbgInfo_linenum line_num = 0; HsailMomentaryBP* momentary_bp = NULL; int momentary_bp_data_size = 0; int momentary_bp_shmem_size = 0; gdb_assert(dbg != NULL); gdb_assert(step_addrs != NULL); gdb_assert(step_addr_count > 0); momentary_bp = NULL; /* Size checking for momentary breakpoint buffers */ momentary_bp_data_size = sizeof(HsailMomentaryBP)*step_addr_count; momentary_bp_shmem_size = hsail_get_momentary_bp_buffer_shmem_max_size(); if (momentary_bp_data_size >= momentary_bp_shmem_size) { printf("Momentary breakpoint buffer overflow\n"); printf("No of Step Addresses: %lu\n", step_addr_count); printf("Step Addresses Memory Required: %d\n", momentary_bp_data_size); } gdb_assert(momentary_bp_data_size < momentary_bp_shmem_size); momentary_bp = (HsailMomentaryBP*)hsail_tdep_map_momentary_bp_buffer(); gdb_assert(momentary_bp != NULL); memset(momentary_bp, 0, momentary_bp_shmem_size); for(i=0; i < step_addr_count; i++) { loc = NULL; line_num = 0; hwdbginfo_addr_to_line(dbg, step_addrs[i], &loc); hwdbginfo_code_location_details(loc, &line_num, 0, NULL, NULL); momentary_bp[i].m_pc = step_addrs[i]; momentary_bp[i].m_lineNum = line_num; } hsail_tdep_unmap_momentary_bp_buffer((void*)momentary_bp); }
/* This is a utility function to print the filename information */ int hsail_dbginfo_test_all_mapped_addrs(HwDbgInfo_debug dbg) { HwDbgInfo_addr* addrs = NULL; HwDbgInfo_err err = 0; char* filename_buff = NULL; HwDbgInfo_code_location loc = NULL; size_t i = 0; size_t returned_filename_len = 0; size_t returned_addrCount = 0; /* Just a large buffer size */ const size_t max_filename_len=10240; const size_t max_addrCount=10240; addrs = (HwDbgInfo_addr*)xmalloc(max_addrCount * sizeof(HwDbgInfo_addr)); if (NULL == addrs) return -1; memset(addrs, 0, max_addrCount * sizeof(HwDbgInfo_addr)); err = hwdbginfo_all_mapped_addrs(dbg,max_addrCount,addrs,&returned_addrCount); if (HWDBGINFO_E_SUCCESS != err) { printf("Error \n"); return -1; /* unexpected error */ } /* +1 to append null-terminator '\0' */ filename_buff = (char*)xmalloc((max_filename_len+1)*sizeof(char)); gdb_assert(NULL != filename_buff); if(NULL == filename_buff) return -1; memset(filename_buff, '\0', (max_filename_len+1)*sizeof(char)); printf_filtered("Address count %lu\n",returned_addrCount); for(i=0; i < returned_addrCount; i++) { HwDbgInfo_linenum line_num = 0; err = hwdbginfo_addr_to_line(dbg,addrs[i],&loc); if (err != HWDBGINFO_E_SUCCESS) { printf_filtered("Couldn't resolve address 0x%llx",addrs[i]); break; } err = hwdbginfo_code_location_details(loc, &line_num, max_filename_len, filename_buff, &returned_filename_len); if (err != HWDBGINFO_E_SUCCESS) { printf_filtered("Couldn't resolve code location for address 0x%llx",addrs[i]); break; } printf_filtered("Address is 0x%llx Line is %llu \n",addrs[i], line_num); } printf_filtered("Filename is %s \n",filename_buff); xfree(addrs); xfree(filename_buff); return 0; }