mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-06 05:48:40 +00:00
jump destination symbol name visualization in disassembly
This commit is contained in:
+71
-47
@@ -436,65 +436,72 @@ dasm_parse_thread__entry_point(void *p)
|
|||||||
// rjf: analyze
|
// rjf: analyze
|
||||||
struct ud_operand *first_op = (struct ud_operand *)ud_insn_opr(&udc, 0);
|
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;
|
U64 rel_voff = (first_op != 0 && first_op->type == UD_OP_JIMM) ? ud_syn_rel_target(&udc, first_op) : 0;
|
||||||
|
U64 jump_dst_vaddr = rel_voff;
|
||||||
|
|
||||||
// rjf: push strings derived from voff -> line info
|
// rjf: push strings derived from voff -> line info
|
||||||
if(dbgi != &dbgi_parse_nil)
|
if(params.style_flags & DASM_StyleFlag_SourceFilesNames|DASM_StyleFlag_SourceLines)
|
||||||
{
|
{
|
||||||
U64 voff = (params.vaddr+off) - params.base_vaddr;
|
if(dbgi != &dbgi_parse_nil)
|
||||||
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];
|
U64 voff = (params.vaddr+off) - params.base_vaddr;
|
||||||
RDI_SourceFile *file = rdi_element_from_idx(rdi, source_files, line->file_idx);
|
U32 unit_idx = rdi_vmap_idx_from_voff(rdi->unit_vmap, rdi->unit_vmap_count, voff);
|
||||||
String8 file_normalized_full_path = {0};
|
RDI_Unit *unit = rdi_element_from_idx(rdi, units, unit_idx);
|
||||||
file_normalized_full_path.str = rdi_string_from_idx(rdi, file->normal_full_path_string_idx, &file_normalized_full_path.size);
|
RDI_ParsedLineInfo unit_line_info = {0};
|
||||||
if(file != last_file)
|
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)
|
||||||
{
|
{
|
||||||
if(file->normal_full_path_string_idx != 0 && file_normalized_full_path.size != 0)
|
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)
|
||||||
{
|
{
|
||||||
DASM_Inst inst = {0};
|
if(params.style_flags & DASM_StyleFlag_SourceFilesNames &&
|
||||||
dasm_inst_chunk_list_push(scratch.arena, &inst_list, 1024, &inst);
|
file->normal_full_path_string_idx != 0 && file_normalized_full_path.size != 0)
|
||||||
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);
|
DASM_Inst inst = {0};
|
||||||
if(!u128_match(hash, u128_zero()))
|
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 &&
|
||||||
|
params.style_flags & DASM_StyleFlag_SourceLines &&
|
||||||
|
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;)
|
||||||
{
|
{
|
||||||
break;
|
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)
|
||||||
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};
|
String8 data = hs_data_from_hash(hs_scope, hash);
|
||||||
dasm_inst_chunk_list_push(scratch.arena, &inst_list, 1024, &inst);
|
String8 line_text = str8_skip_chop_whitespace(str8_substr(data, text_info.lines_ranges[line->line_num-1]));
|
||||||
str8_list_pushf(scratch.arena, &inst_strings, "> %S", line_text);
|
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;
|
||||||
}
|
}
|
||||||
last_line = line;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -524,7 +531,24 @@ dasm_parse_thread__entry_point(void *p)
|
|||||||
str8_list_push(scratch.arena, &code_bytes_strings, str8_lit(" "));
|
str8_list_push(scratch.arena, &code_bytes_strings, str8_lit(" "));
|
||||||
code_bytes_part = str8_list_join(scratch.arena, &code_bytes_strings, 0);
|
code_bytes_part = str8_list_join(scratch.arena, &code_bytes_strings, 0);
|
||||||
}
|
}
|
||||||
String8 inst_string = push_str8f(scratch.arena, "%S%S%s", addr_part, code_bytes_part, udc.asm_buf);
|
String8 symbol_part = {0};
|
||||||
|
if(jump_dst_vaddr != 0 && dbgi != &dbgi_parse_nil && params.style_flags & DASM_StyleFlag_SymbolNames)
|
||||||
|
{
|
||||||
|
RDI_U32 scope_idx = rdi_vmap_idx_from_voff(rdi->scope_vmap, rdi->scope_vmap_count, jump_dst_vaddr-params.base_vaddr);
|
||||||
|
if(scope_idx != 0)
|
||||||
|
{
|
||||||
|
RDI_Scope *scope = rdi_element_from_idx(rdi, scopes, scope_idx);
|
||||||
|
RDI_U32 procedure_idx = scope->proc_idx;
|
||||||
|
RDI_Procedure *procedure = rdi_element_from_idx(rdi, procedures, procedure_idx);
|
||||||
|
String8 procedure_name = {0};
|
||||||
|
procedure_name.str = rdi_string_from_idx(rdi, procedure->name_string_idx, &procedure_name.size);
|
||||||
|
if(procedure_name.size != 0)
|
||||||
|
{
|
||||||
|
symbol_part = push_str8f(scratch.arena, " (%S)", procedure_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String8 inst_string = push_str8f(scratch.arena, "%S%S%s%S", addr_part, code_bytes_part, udc.asm_buf, symbol_part);
|
||||||
DASM_Inst inst = {off, rel_voff, r1u64(inst_strings.total_size + inst_strings.node_count,
|
DASM_Inst inst = {off, rel_voff, r1u64(inst_strings.total_size + inst_strings.node_count,
|
||||||
inst_strings.total_size + inst_strings.node_count + inst_string.size)};
|
inst_strings.total_size + inst_strings.node_count + inst_string.size)};
|
||||||
dasm_inst_chunk_list_push(scratch.arena, &inst_list, 1024, &inst);
|
dasm_inst_chunk_list_push(scratch.arena, &inst_list, 1024, &inst);
|
||||||
|
|||||||
@@ -10,8 +10,11 @@
|
|||||||
typedef U32 DASM_StyleFlags;
|
typedef U32 DASM_StyleFlags;
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
DASM_StyleFlag_Addresses = (1<<0),
|
DASM_StyleFlag_Addresses = (1<<0),
|
||||||
DASM_StyleFlag_CodeBytes = (1<<1),
|
DASM_StyleFlag_CodeBytes = (1<<1),
|
||||||
|
DASM_StyleFlag_SourceFilesNames = (1<<2),
|
||||||
|
DASM_StyleFlag_SourceLines = (1<<3),
|
||||||
|
DASM_StyleFlag_SymbolNames = (1<<4),
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum DASM_Syntax
|
typedef enum DASM_Syntax
|
||||||
|
|||||||
@@ -6038,7 +6038,7 @@ DF_VIEW_SETUP_FUNCTION_DEF(Disassembly)
|
|||||||
dv->mark = txt_pt(1, 1);
|
dv->mark = txt_pt(1, 1);
|
||||||
dv->preferred_column = 1;
|
dv->preferred_column = 1;
|
||||||
dv->find_text_arena = df_view_push_arena_ext(view);
|
dv->find_text_arena = df_view_push_arena_ext(view);
|
||||||
dv->style_flags = DASM_StyleFlag_Addresses;
|
dv->style_flags = DASM_StyleFlag_Addresses|DASM_StyleFlag_SourceFilesNames|DASM_StyleFlag_SourceLines|DASM_StyleFlag_SymbolNames;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1146,6 +1146,7 @@ txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed
|
|||||||
B32 escaped = 0;
|
B32 escaped = 0;
|
||||||
B32 string_is_char = 0;
|
B32 string_is_char = 0;
|
||||||
S32 brace_nest = 0;
|
S32 brace_nest = 0;
|
||||||
|
S32 paren_nest = 0;
|
||||||
for(U64 advance = 0; off <= string.size; off += advance)
|
for(U64 advance = 0; off <= string.size; off += advance)
|
||||||
{
|
{
|
||||||
U8 byte = (off+0 < string.size) ? string.str[off+0] : 0;
|
U8 byte = (off+0 < string.size) ? string.str[off+0] : 0;
|
||||||
@@ -1218,6 +1219,14 @@ txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed
|
|||||||
{
|
{
|
||||||
brace_nest -= 1;
|
brace_nest -= 1;
|
||||||
}
|
}
|
||||||
|
if(byte == '(')
|
||||||
|
{
|
||||||
|
paren_nest += 1;
|
||||||
|
}
|
||||||
|
else if(byte == ')')
|
||||||
|
{
|
||||||
|
paren_nest -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1306,6 +1315,10 @@ txt_token_array_from_string__disasm_x64_intel(Arena *arena, U64 *bytes_processed
|
|||||||
{
|
{
|
||||||
active_token_kind = TXT_TokenKind_Numeric;
|
active_token_kind = TXT_TokenKind_Numeric;
|
||||||
}
|
}
|
||||||
|
if(paren_nest != 0 && active_token_kind == TXT_TokenKind_Keyword)
|
||||||
|
{
|
||||||
|
active_token_kind = TXT_TokenKind_Identifier;
|
||||||
|
}
|
||||||
TXT_Token token = {active_token_kind, r1u64(active_token_start_off, off+advance)};
|
TXT_Token token = {active_token_kind, r1u64(active_token_start_off, off+advance)};
|
||||||
txt_token_chunk_list_push(arena, &tokens, 1024, &token);
|
txt_token_chunk_list_push(arena, &tokens, 1024, &token);
|
||||||
active_token_kind = TXT_TokenKind_Null;
|
active_token_kind = TXT_TokenKind_Null;
|
||||||
|
|||||||
Reference in New Issue
Block a user