Skip to content

Commit 804a840

Browse files
committed
eliminate assumptions of module presence in unwinding codepaths, & callstack UI; fixes callstacks for JIT'd code
1 parent 8bf8112 commit 804a840

File tree

4 files changed

+84
-98
lines changed

4 files changed

+84
-98
lines changed

src/df/core/df_core.c

-7
Original file line numberDiff line numberDiff line change
@@ -3621,13 +3621,6 @@ df_push_unwind_from_thread(Arena *arena, DF_Entity *thread)
36213621
DBGI_Parse *dbgi = dbgi_parse_from_exe_path(scope, binary_full_path, 0);
36223622
String8 binary_data = str8((U8 *)dbgi->exe_base, dbgi->exe_props.size);
36233623

3624-
// rjf: cancel on bad data
3625-
if(binary_data.size == 0)
3626-
{
3627-
unwind.error = 1;
3628-
break;
3629-
}
3630-
36313624
// rjf: valid step -> push frame
36323625
DF_UnwindFrame *frame = push_array(arena, DF_UnwindFrame, 1);
36333626
frame->rip = rip;

src/df/gfx/df_views.c

+30-6
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ DF_VIEW_UI_FUNCTION_DEF(Empty)
17971797
UI_Flags(UI_BoxFlag_DrawBorder)
17981798
UI_TextAlignment(UI_TextAlign_Center)
17991799
df_cmd_binding_button(spec);
1800-
ui_labelf(", or start typing, to open command menu");
1800+
ui_labelf("to open command menu");
18011801
}
18021802
}
18031803
scratch_end(scratch);
@@ -3914,8 +3914,8 @@ DF_VIEW_UI_FUNCTION_DEF(CallStack)
39143914
// rjf: rip_vaddr => module
39153915
DF_Entity *module = df_module_from_process_vaddr(process, rip_vaddr);
39163916

3917-
// rjf: module => validity?
3918-
B32 frame_valid = !df_entity_is_nil(module);
3917+
// rjf: rip => validity?
3918+
B32 frame_valid = (rip_vaddr != 0);
39193919

39203920
// rjf: build row
39213921
if(frame_valid) UI_NamedTableVectorF("###callstack_%p_%I64x", view, frame_idx)
@@ -3951,7 +3951,21 @@ DF_VIEW_UI_FUNCTION_DEF(CallStack)
39513951
// rjf: build cell for module
39523952
UI_TableCell UI_FocusHot((row_selected && cs->cursor.x == 1) ? UI_FocusKind_On : UI_FocusKind_Off)
39533953
{
3954-
df_entity_desc_button(ws, module);
3954+
if(df_entity_is_nil(module)) UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText))
3955+
{
3956+
UI_Box *box = ui_build_box_from_stringf(UI_BoxFlag_DrawText|UI_BoxFlag_Clickable, "(No Module)###moduleless_frame_%I64x", frame_idx);
3957+
UI_Signal sig = ui_signal_from_box(box);
3958+
if(sig.pressed)
3959+
{
3960+
next_cursor = v2s64(1, (S64)frame_idx+1);
3961+
DF_CmdParams p = df_cmd_params_from_panel(ws, panel);
3962+
df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_FocusPanel));
3963+
}
3964+
}
3965+
else
3966+
{
3967+
df_entity_desc_button(ws, module);
3968+
}
39553969
}
39563970

39573971
// rjf: build cell for function name
@@ -5628,9 +5642,19 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly)
56285642
default: break;
56295643
case DF_CoreCmdKind_GoToAddress:
56305644
{
5631-
if(!df_entity_is_nil(df_entity_from_handle(params.entity)))
5645+
DF_Entity *entity = df_entity_from_handle(params.entity);
5646+
if(!df_entity_is_nil(entity) &&
5647+
(entity->kind == DF_EntityKind_Process ||
5648+
entity->kind == DF_EntityKind_Thread ||
5649+
entity->kind == DF_EntityKind_Module))
56325650
{
5633-
dv->process = params.entity;
5651+
DF_Entity *process = entity;
5652+
if(entity->kind == DF_EntityKind_Thread ||
5653+
entity->kind == DF_EntityKind_Module)
5654+
{
5655+
process = df_entity_ancestor_from_kind(process, DF_EntityKind_Process);
5656+
}
5657+
dv->process = df_handle_from_entity(process);
56345658
}
56355659
dv->base_vaddr = params.vaddr;
56365660
dv->goto_vaddr = params.vaddr;

src/pe/pe.c

+43-43
Original file line numberDiff line numberDiff line change
@@ -236,56 +236,56 @@ pe_bin_info_from_data(Arena *arena, String8 data)
236236
internal U64
237237
pe_intel_pdata_off_from_voff__binary_search(String8 data, PE_BinInfo *bin, U64 voff)
238238
{
239-
// TODO(allen): cleanup pass.
240-
Assert(bin->arch == Architecture_x86 || bin->arch == Architecture_x64);
241-
Rng1U64 range = bin->data_dir_franges[PE_DataDirectoryIndex_EXCEPTIONS];
242-
U64 pdata_off = range.min;
243-
U64 pdata_count = (range.max - range.min)/sizeof(PE_IntelPdata);
244-
245239
U64 result = 0;
246-
247-
// check if this bin includes a pdata array
248-
if(pdata_count > 0)
240+
if(bin->arch != Architecture_Null)
249241
{
250-
PE_IntelPdata *pdata_array = (PE_IntelPdata*)(data.str + pdata_off);
251-
if(voff >= pdata_array[0].voff_first)
242+
Rng1U64 range = bin->data_dir_franges[PE_DataDirectoryIndex_EXCEPTIONS];
243+
U64 pdata_off = range.min;
244+
U64 pdata_count = (range.max - range.min)/sizeof(PE_IntelPdata);
245+
246+
// check if this bin includes a pdata array
247+
if(pdata_count > 0)
252248
{
253-
// binary search:
254-
// find max index s.t. pdata_array[index].voff_first <= voff
255-
// we assume (i < j) -> (pdata_array[i].voff_first < pdata_array[j].voff_first)
256-
U64 index = pdata_count;
257-
U64 min = 0;
258-
U64 opl = pdata_count;
259-
for(;;)
249+
PE_IntelPdata *pdata_array = (PE_IntelPdata*)(data.str + pdata_off);
250+
if(voff >= pdata_array[0].voff_first)
260251
{
261-
U64 mid = (min + opl)/2;
262-
PE_IntelPdata *pdata = pdata_array + mid;
263-
if(voff < pdata->voff_first)
264-
{
265-
opl = mid;
266-
}
267-
else if(pdata->voff_first < voff)
252+
// binary search:
253+
// find max index s.t. pdata_array[index].voff_first <= voff
254+
// we assume (i < j) -> (pdata_array[i].voff_first < pdata_array[j].voff_first)
255+
U64 index = pdata_count;
256+
U64 min = 0;
257+
U64 opl = pdata_count;
258+
for(;;)
268259
{
269-
min = mid;
270-
}
271-
else
272-
{
273-
index = mid;
274-
break;
275-
}
276-
if(min + 1 >= opl)
277-
{
278-
index = min;
279-
break;
260+
U64 mid = (min + opl)/2;
261+
PE_IntelPdata *pdata = pdata_array + mid;
262+
if(voff < pdata->voff_first)
263+
{
264+
opl = mid;
265+
}
266+
else if(pdata->voff_first < voff)
267+
{
268+
min = mid;
269+
}
270+
else
271+
{
272+
index = mid;
273+
break;
274+
}
275+
if(min + 1 >= opl)
276+
{
277+
index = min;
278+
break;
279+
}
280280
}
281-
}
282-
283-
// if we are in range fill result
284-
{
285-
PE_IntelPdata *pdata = pdata_array + index;
286-
if(pdata->voff_first <= voff && voff < pdata->voff_one_past_last)
281+
282+
// if we are in range fill result
287283
{
288-
result = pdata_off + index*sizeof(PE_IntelPdata);
284+
PE_IntelPdata *pdata = pdata_array + index;
285+
if(pdata->voff_first <= voff && voff < pdata->voff_one_past_last)
286+
{
287+
result = pdata_off + index*sizeof(PE_IntelPdata);
288+
}
289289
}
290290
}
291291
}

src/scratch/ryan_scratch.c

+11-42
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,18 @@
11
// Copyright (c) 2024 Epic Games Tools
22
// Licensed under the MIT license (https://opensource.org/license/mit/)
33

4-
// build with:
5-
// cl /Zi /nologo look_at_raddbg.c
6-
7-
#include <windows.h>
4+
#include <stdio.h>
85
#include <stdint.h>
9-
#include "raddbg_format/raddbg_format.h"
10-
#include "raddbg_format/raddbg_format_parse.h"
11-
#include "raddbg_format/raddbg_format.c"
12-
#include "raddbg_format/raddbg_format_parse.c"
13-
14-
typedef struct Foo Foo;
15-
struct Foo
16-
{
17-
int x;
18-
int y;
19-
int z;
20-
};
6+
#include <windows.h>
217

22-
int main(int argument_count, char **arguments)
23-
{
24-
Foo foo = {123, 456, 789};
25-
HANDLE file = CreateFileA(arguments[1], GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
26-
DWORD size_hi32 = 0;
27-
DWORD size_lo32 = GetFileSize(file, &size_hi32);
28-
HANDLE map = CreateFileMappingA(file, 0, PAGE_READONLY, 0, 0, 0);
29-
uint64_t data_size = (size_lo32 | ((uint64_t)size_hi32 << 32));
30-
uint8_t *data = (uint8_t *)MapViewOfFile(map, FILE_MAP_READ, 0, 0, data_size);
31-
RADDBG_Parsed rdbg = {0};
32-
RADDBG_ParseStatus parse_status = raddbg_parse(data, data_size, &rdbg);
33-
uint64_t foo_count = 0;
34-
for(uint64_t idx = 0; idx < rdbg.type_node_count; idx += 1)
35-
{
36-
RADDBG_TypeNode *type_node = &rdbg.type_nodes[idx];
37-
if(RADDBG_TypeKind_FirstUserDefined <= type_node->kind && type_node->kind <= RADDBG_TypeKind_LastUserDefined)
38-
{
39-
uint64_t name_size = 0;
40-
uint8_t *name = raddbg_string_from_idx(&rdbg, type_node->user_defined.name_string_idx, &name_size);
41-
if(name_size == 3 && name[0] == 'f' && name[1] == 'o' && name[2] == 'o')
42-
{
43-
foo_count += 1;
44-
}
45-
}
46-
}
47-
printf("%s -> %I64u foos\n", arguments[1], foo_count);
8+
int main(void) {
9+
printf("1\n");
10+
11+
VOID *code = VirtualAlloc(0, 0x1000, MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE);
12+
*((uint32_t*)code) = 0xCCCCCCCC;
13+
14+
((void (__fastcall *)()) code)();
15+
16+
printf("2\n");
4817
return 0;
4918
}

0 commit comments

Comments
 (0)