diff --git a/src/dasm_cache/dasm_cache.c b/src/dasm_cache/dasm_cache.c index 283a290d..9490584b 100644 --- a/src/dasm_cache/dasm_cache.c +++ b/src/dasm_cache/dasm_cache.c @@ -249,6 +249,7 @@ dasm_info_from_hash_params(DASM_Scope *scope, U128 hash, DASM_Params *params) DLLPushBack(slot->first, slot->last, node); node->hash = hash; MemoryCopyStruct(&node->params, params); + // TODO(rjf): need to make this releasable - currently all exe_paths just leak node->params.exe_path = push_str8_copy(stripe->arena, node->params.exe_path); node_is_new = 1; } @@ -361,6 +362,7 @@ dasm_parse_thread__entry_point(void *p) dasm_u2p_dequeue_req(scratch.arena, &hash, ¶ms); HS_Scope *hs_scope = hs_scope_open(); DBGI_Scope *dbgi_scope = dbgi_scope_open(); + TXT_Scope *txt_scope = txt_scope_open(); //- rjf: unpack hash U64 slot_idx = hash.u64[1]%dasm_shared->slots_count; @@ -388,6 +390,7 @@ dasm_parse_thread__entry_point(void *p) { dbgi = dbgi_parse_from_exe_path(dbgi_scope, params.exe_path, max_U64); } + RDI_Parsed *rdi = &dbgi->rdi; //- rjf: hash -> data String8 data = {0}; @@ -396,12 +399,6 @@ dasm_parse_thread__entry_point(void *p) data = hs_data_from_hash(hs_scope, hash); } - //- rjf: get first line info - if(got_task) - { - // U32 voff_unit_idx = rdi_vmap_idx_from_voff(); - } - //- rjf: data * arch * addr * dbg -> decode artifacts DASM_InstChunkList inst_list = {0}; String8List inst_strings = {0}; @@ -425,7 +422,8 @@ dasm_parse_thread__entry_point(void *p) ud_set_syntax(&udc, params.syntax == DASM_Syntax_Intel ? UD_SYN_INTEL : UD_SYN_ATT); // rjf: disassemble - U64 byte_process_start_off = 0; + RDI_SourceFile *last_file = &rdi_source_file_nil; + RDI_Line *last_line = 0; for(U64 off = 0; off < data.size;) { // rjf: disassemble one instruction @@ -439,11 +437,73 @@ dasm_parse_thread__entry_point(void *p) struct ud_operand *first_op = (struct ud_operand *)ud_insn_opr(&udc, 0); U64 rel_voff = (first_op != 0 && first_op->type == UD_OP_JIMM) ? ud_syn_rel_target(&udc, first_op) : 0; + // rjf: push strings derived from voff -> line info + if(dbgi != &dbgi_parse_nil) + { + U64 voff = (params.vaddr+off) - params.base_vaddr; + U32 unit_idx = rdi_vmap_idx_from_voff(rdi->unit_vmap, rdi->unit_vmap_count, voff); + RDI_Unit *unit = rdi_element_from_idx(rdi, units, unit_idx); + RDI_ParsedLineInfo unit_line_info = {0}; + rdi_line_info_from_unit(rdi, unit, &unit_line_info); + U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, voff); + if(line_info_idx < unit_line_info.count) + { + RDI_Line *line = &unit_line_info.lines[line_info_idx]; + RDI_SourceFile *file = rdi_element_from_idx(rdi, source_files, line->file_idx); + String8 file_normalized_full_path = {0}; + file_normalized_full_path.str = rdi_string_from_idx(rdi, file->normal_full_path_string_idx, &file_normalized_full_path.size); + if(file != last_file) + { + if(file->normal_full_path_string_idx != 0 && file_normalized_full_path.size != 0) + { + DASM_Inst inst = {0}; + dasm_inst_chunk_list_push(scratch.arena, &inst_list, 1024, &inst); + str8_list_pushf(scratch.arena, &inst_strings, "| %S", file_normalized_full_path); + } + last_file = file; + } + if(line && line != last_line && file->normal_full_path_string_idx != 0 && file_normalized_full_path.size != 0) + { + FileProperties props = os_properties_from_file_path(file_normalized_full_path); + if(props.modified != 0) + { + // TODO(rjf): need redirection path - this may map to a different path on the local machine, + // need frontend to communicate path remapping info to this layer + U128 key = fs_key_from_path(file_normalized_full_path); + TXT_LangKind lang_kind = txt_lang_kind_from_extension(file_normalized_full_path); + U64 endt_us = max_U64; + U128 hash = {0}; + TXT_TextInfo text_info = {0}; + for(;os_now_microseconds() <= endt_us;) + { + text_info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash); + if(!u128_match(hash, u128_zero())) + { + break; + } + } + if(line->line_num < text_info.lines_count) + { + String8 data = hs_data_from_hash(hs_scope, hash); + String8 line_text = str8_skip_chop_whitespace(str8_substr(data, text_info.lines_ranges[line->line_num-1])); + if(line_text.size != 0) + { + DASM_Inst inst = {0}; + dasm_inst_chunk_list_push(scratch.arena, &inst_list, 1024, &inst); + str8_list_pushf(scratch.arena, &inst_strings, "| %S", line_text); + } + } + } + last_line = line; + } + } + } + // rjf: push String8 addr_part = {0}; if(params.style_flags & DASM_StyleFlag_Addresses) { - addr_part = push_str8f(scratch.arena, "%016I64X ", params.vaddr+off); + addr_part = push_str8f(scratch.arena, "%s%016I64X ", dbgi != &dbgi_parse_nil ? " " : "", params.vaddr+off); } String8 code_bytes_part = {0}; if(params.style_flags & DASM_StyleFlag_CodeBytes) @@ -530,6 +590,7 @@ dasm_parse_thread__entry_point(void *p) } } + txt_scope_close(txt_scope); dbgi_scope_close(dbgi_scope); hs_scope_close(hs_scope); scratch_end(scratch); diff --git a/src/df/gfx/df_views.c b/src/df/gfx/df_views.c index 7ddba81d..90404644 100644 --- a/src/df/gfx/df_views.c +++ b/src/df/gfx/df_views.c @@ -6061,6 +6061,8 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly) DF_Entity *process = df_entity_from_handle(dv->process); Architecture arch = df_architecture_from_entity(process); U64 dasm_base_vaddr = AlignDownPow2(dv->base_vaddr, KB(64)); + DF_Entity *dasm_module = df_module_from_process_vaddr(process, dasm_base_vaddr); + DF_Entity *dasm_binary = df_binary_file_from_module(dasm_module); Rng1U64 dasm_vaddr_range = r1u64(dasm_base_vaddr, dasm_base_vaddr+KB(64)); U128 dasm_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, dasm_vaddr_range, 0); U128 dasm_data_hash = {0}; @@ -6070,8 +6072,8 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly) dasm_params.arch = arch; dasm_params.style_flags = dv->style_flags; dasm_params.syntax = DASM_Syntax_Intel; - dasm_params.base_vaddr = 0; - dasm_params.exe_path = str8_zero(); + dasm_params.base_vaddr = dasm_module->vaddr_rng.min; + dasm_params.exe_path = df_full_path_from_entity(scratch.arena, dasm_binary); } DASM_Info dasm_info = dasm_info_from_key_params(dasm_scope, dasm_key, &dasm_params, &dasm_data_hash); U128 dasm_text_hash = {0}; @@ -6313,6 +6315,8 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly) DF_Entity *process = df_entity_from_handle(dv->process); Architecture arch = df_architecture_from_entity(process); U64 dasm_base_vaddr = AlignDownPow2(dv->base_vaddr, KB(64)); + DF_Entity *dasm_module = df_module_from_process_vaddr(process, dasm_base_vaddr); + DF_Entity *dasm_binary = df_binary_file_from_module(dasm_module); Rng1U64 dasm_vaddr_range = r1u64(dasm_base_vaddr, dasm_base_vaddr+KB(64)); U128 dasm_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, dasm_vaddr_range, 0); U128 dasm_data_hash = {0}; @@ -6322,8 +6326,8 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly) dasm_params.arch = arch; dasm_params.style_flags = dv->style_flags; dasm_params.syntax = DASM_Syntax_Intel; - dasm_params.base_vaddr = 0; - dasm_params.exe_path = str8_zero(); + dasm_params.base_vaddr = dasm_module->vaddr_rng.min; + dasm_params.exe_path = df_full_path_from_entity(scratch.arena, dasm_binary); } DASM_Info dasm_info = dasm_info_from_key_params(dasm_scope, dasm_key, &dasm_params, &dasm_data_hash); U128 dasm_text_hash = {0}; diff --git a/src/text_cache/text_cache.c b/src/text_cache/text_cache.c index 231dac34..06011222 100644 --- a/src/text_cache/text_cache.c +++ b/src/text_cache/text_cache.c @@ -1168,6 +1168,12 @@ txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed active_token_kind = TXT_TokenKind_Whitespace; advance = 1; } + else if(byte == '|') + { + active_token_start_off = off; + active_token_kind = TXT_TokenKind_Comment; + advance = 1; + } else if(('a' <= byte && byte <= 'z') || ('A' <= byte && byte <= 'Z') || byte == '_') { active_token_start_off = off; @@ -1287,6 +1293,12 @@ txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed ender_found = 1; advance = 0; }break; + case TXT_TokenKind_Comment: + if(byte == '\n') + { + ender_found = 1; + advance = 1; + }break; } if(ender_found != 0) {