char* hsail_dbginfo_get_srcline_from_code_loc(const HwDbgInfo_debug dbg, const HwDbgInfo_code_location code_loc) { HwDbgInfo_linenum line_num = 0; char* op_ptr = NULL; size_t buffer_len = 1024; size_t op_buffer_len = 1024; HwDbgInfo_err err = HWDBGINFO_E_SUCCESS; char* file_name = xmalloc(sizeof(char)*buffer_len); gdb_assert(file_name != NULL); memset(file_name, '\0', buffer_len); err = hwdbginfo_code_location_details(code_loc, &line_num, buffer_len ,file_name, &op_buffer_len); gdb_assert(err == HWDBGINFO_E_SUCCESS); if ((file_name == NULL) || (dbg == NULL)) { return op_ptr; } /* if we are doing hsail level debugging, we need to look into memory */ if( (strcmp(file_name, "temp_source") == 0) || (strstr(file_name,"hsa::self().elf") != NULL) ) { op_ptr = hsail_dbginfo_get_srcline_from_buffer(dbg, line_num); } else { op_ptr = hsail_utils_read_line_from_file(file_name, line_num); } xfree(file_name); return op_ptr; }
/* 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); }
bool hsail_dbginfo_search_linemapping(const char* ip_arg) { bool ret_code = false; char* temp = NULL; char* ipStr = NULL; char* ipfileName = NULL; char* lineNoStr = NULL; HwDbgInfo_debug dbg = hsail_init_hwdbginfo(NULL); if (dbg == NULL) { return ret_code; } if (ip_arg == NULL) { return ret_code; } if (strlen(ip_arg) > 4) { if (ip_arg[0] == 'r' && ip_arg[1] == 'o' && ip_arg[2] == 'c' && ip_arg[3] == 'm') { return ret_code; } } /* Copy input arg to a char array so strtok doesn't wreck input */ hsail_utils_copy_string(&ipStr, ip_arg); temp = strtok(ipStr, ": "); if (temp == NULL) { return ret_code; } // Copy strtok op to a separate buffer hsail_utils_copy_string(&ipfileName, temp); lineNoStr = strtok(NULL, ": "); if (lineNoStr != NULL) { HwDbgInfo_linenum line_no = (HwDbgInfo_linenum) strtoull(lineNoStr, NULL, 10); // Create a code location HwDbgInfo_code_location loc = hwdbginfo_make_code_location(ipfileName, line_no); HwDbgInfo_code_location resolvedLoc = NULL; // Get the nearest code location HwDbgInfo_err err = hwdbginfo_nearest_mapped_line(dbg, loc, &resolvedLoc); if (err == HWDBGINFO_E_SUCCESS) { // Maybe compare the 2 ? HwDbgInfo_linenum resolvedLineNum; size_t resolvedfileNameLen = 1024; size_t resolvedfileNameLenOut = 0; char* fileName = (char*)malloc(resolvedfileNameLen*sizeof(char)); gdb_assert(fileName != NULL); memset(fileName, '\0', resolvedfileNameLen); err = hwdbginfo_code_location_details(resolvedLoc, &resolvedLineNum, resolvedfileNameLen, fileName, &resolvedfileNameLenOut); if (abs(resolvedLineNum - line_no) < 2) { printf("Create a GPU Breakpoint "); ret_code =true; } else { printf("Resolved %lld ", resolvedLineNum); printf("Req is %lld \n", line_no); } xfree(fileName); } else { printf("Not a GPU breakpoint %d",err); } } xfree(temp); xfree(ipfileName); return ret_code; }
/* 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; }