Merge tag 'v0.9.20-alpha'

This commit is contained in:
2025-06-13 23:07:02 -04:00
306 changed files with 15074 additions and 13393 deletions
+1 -3
View File
@@ -17,9 +17,7 @@ jobs:
target:
- raddbg
- radlink
- rdi_from_pdb
- raddump
- rdi_breakpad_from_pdb
- radbin
compiler:
- msvc
- clang
+7 -8
View File
@@ -24,6 +24,7 @@ cd /D "%~dp0"
::
:: - `asan`: enable address sanitizer
:: - `telemetry`: enable RAD telemetry profiling support
:: - `spall`: enable spall profiling support
:: --- Unpack Arguments -------------------------------------------------------
for %%a in (%*) do set "%%a=1"
@@ -39,21 +40,22 @@ if "%~1"=="release" if "%~2"=="" echo [default mode, assuming `raddbg` build] &&
:: --- Unpack Command Line Build Arguments ------------------------------------
set auto_compile_flags=
if "%telemetry%"=="1" set auto_compile_flags=%auto_compile_flags% -DPROFILE_TELEMETRY=1 && echo [telemetry profiling enabled]
if "%spall%"=="1" set auto_compile_flags=%auto_compile_flags% -DPROFILE_SPALL=1 && echo [spall profiling enabled]
if "%asan%"=="1" set auto_compile_flags=%auto_compile_flags% -fsanitize=address && echo [asan enabled]
if "%opengl%"=="1" set auto_compile_flags=%auto_compile_flags% -DR_BACKEND=R_BACKEND_OPENGL && echo [opengl render backend]
:: --- Compile/Link Line Definitions ------------------------------------------
set cl_common= /I..\src\ /I..\local\ /nologo /FC /Z7
set clang_common= -I..\src\ -I..\local\ -gcodeview -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf -ferror-limit=10000
set cl_debug= call cl /Od /Ob1 /DBUILD_DEBUG=1 %cl_common% %auto_compile_flags%
set cl_release= call cl /O2 /DBUILD_DEBUG=0 %cl_common% %auto_compile_flags%
set cl_link= /link /MANIFEST:EMBED /INCREMENTAL:NO /pdbaltpath:%%%%_PDB%%%% /NATVIS:"%~dp0\src\natvis\base.natvis" /noexp
set cl_out= /out:
set cl_linker=
set clang_common= -I..\src\ -I..\local\ -gcodeview -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-unused-parameter -Wno-writable-strings -Wno-missing-field-initializers -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf -ferror-limit=10000
set clang_debug= call clang -g -O0 -DBUILD_DEBUG=1 %clang_common% %auto_compile_flags%
set clang_release= call clang -g -O2 -DBUILD_DEBUG=0 %clang_common% %auto_compile_flags%
set cl_link= /link /MANIFEST:EMBED /INCREMENTAL:NO /pdbaltpath:%%%%_PDB%%%% /NATVIS:"%~dp0\src\natvis\base.natvis" /noexp
set clang_link= -fuse-ld=lld -Xlinker /MANIFEST:EMBED -Xlinker /pdbaltpath:%%%%_PDB%%%% -Xlinker /NATVIS:"%~dp0\src\natvis\base.natvis"
set cl_out= /out:
set clang_out= -o
set cl_linker=
set clang_linker= -Xlinker
:: --- Per-Build Settings -----------------------------------------------------
@@ -108,11 +110,8 @@ if not "%no_meta%"=="1" (
pushd build
if "%raddbg%"=="1" set didbuild=1 && %compile% ..\src\raddbg\raddbg_main.c %compile_link% %link_icon% %out%raddbg.exe || exit /b 1
if "%radlink%"=="1" set didbuild=1 && %compile% ..\src\linker\lnk.c %compile_link% %linker% /NOIMPLIB %linker% /NATVIS:"%~dp0\src\linker\linker.natvis" %out%radlink.exe || exit /b 1
if "%radcon%"=="1" set didbuild=1 && %compile% ..\src\radcon\radcon_main.c %compile_link% %out%radcon.exe || exit /b 1
if "%radbin%"=="1" set didbuild=1 && %compile% ..\src\radbin\radbin_main.c %compile_link% %out%radbin.exe || exit /b 1
if "%raddump%"=="1" set didbuild=1 && %compile% ..\src\raddump\raddump_main.c %compile_link% %out%raddump.exe || exit /b 1
if "%rdi_from_pdb%"=="1" set didbuild=1 && %compile% ..\src\rdi_from_pdb\rdi_from_pdb_main.c %compile_link% %out%rdi_from_pdb.exe || exit /b 1
if "%rdi_from_dwarf%"=="1" set didbuild=1 && %compile% ..\src\rdi_from_dwarf\rdi_from_dwarf_main.c %compile_link% %out%rdi_from_dwarf.exe || exit /b 1
if "%rdi_breakpad_from_pdb%"=="1" set didbuild=1 && %compile% ..\src\rdi_breakpad_from_pdb\rdi_breakpad_from_pdb_main.c %compile_link% %out%rdi_breakpad_from_pdb.exe || exit /b 1
if "%tester%"=="1" set didbuild=1 && %compile% ..\src\tester\tester_main.c %compile_link% %out%tester.exe || exit /b 1
if "%ryan_scratch%"=="1" set didbuild=1 && %compile% ..\src\scratch\ryan_scratch.c %compile_link% %out%ryan_scratch.exe || exit /b 1
if "%eval_scratch%"=="1" set didbuild=1 && %compile% ..\src\scratch\eval_scratch.c %compile_link% %out%eval_scratch.exe || exit /b 1
+4 -1
View File
@@ -46,7 +46,7 @@ load_paths =
commands =
{
//- rjf: [raddbg]
.f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: [textperf]
// .f1 = { .win = "raddbg_stable --ipc kill_all && build no_meta telemetry textperf && raddbg_stable --ipc bring_to_front && raddbg_stable --ipc run", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
@@ -54,6 +54,9 @@ commands =
//- rjf: [tester]
// .f1 = { .win = "raddbg_stable --ipc kill_all && build no_meta tester", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: [radbin]
.f1 = { .win = "raddbg_stable --ipc kill_all && build radbin", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: running target
.f3 = { .win = "raddbg_stable --ipc run", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f3 = { .win = "pushd build && raddbg --user:dev.raddbg_user && popd", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
+34 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#undef LAYER_COLOR
@@ -234,6 +234,39 @@ async_execute_work(ASYNC_Work work)
}
}
////////////////////////////////
//~ rjf: Root Allocation/Deallocation
internal ASYNC_Root *
async_root_alloc(void)
{
Arena *arena = arena_alloc();
ASYNC_Root *root = push_array(arena, ASYNC_Root, 1);
root->arenas = push_array(arena, Arena *, async_thread_count());
root->arenas[0] = arena;
for(U64 idx = 1; idx < async_thread_count(); idx += 1)
{
root->arenas[idx] = arena_alloc();
}
return root;
}
internal void
async_root_release(ASYNC_Root *root)
{
for(U64 idx = 1; idx < async_thread_count(); idx += 1)
{
arena_release(root->arenas[idx]);
}
arena_release(root->arenas[0]);
}
internal Arena *
async_root_thread_arena(ASYNC_Root *root)
{
return root->arenas[async_work_thread_idx];
}
////////////////////////////////
//~ rjf: Work Thread Entry Point
+17 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef ASYNC_H
@@ -70,6 +70,15 @@ struct ASYNC_TaskList
U64 count;
};
////////////////////////////////
//~ rjf: Root (Per-Worker-Thread Arena Bundle)
typedef struct ASYNC_Root ASYNC_Root;
struct ASYNC_Root
{
Arena **arenas;
};
////////////////////////////////
//~ rjf: Shared State Bundle
@@ -138,6 +147,13 @@ internal void *async_task_join(ASYNC_Task *task);
internal ASYNC_Work async_pop_work(void);
internal void async_execute_work(ASYNC_Work work);
////////////////////////////////
//~ rjf: Root Allocation/Deallocation
internal ASYNC_Root *async_root_alloc(void);
internal void async_root_release(ASYNC_Root *root);
internal Arena *async_root_thread_arena(ASYNC_Root *root);
////////////////////////////////
//~ rjf: Work Thread Entry Point
+7 -2
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
@@ -37,6 +37,7 @@ arena_alloc_(ArenaParams *params)
base = os_reserve(reserve_size);
os_commit(base, commit_size);
}
raddbg_annotate_vaddr_range(base, reserve_size, "arena %s:%i", params->allocation_site_file, params->allocation_site_line);
}
// rjf: panic on arena creation failure
@@ -58,6 +59,8 @@ arena_alloc_(ArenaParams *params)
arena->pos = ARENA_HEADER_SIZE;
arena->cmt = commit_size;
arena->res = reserve_size;
arena->allocation_site_file = params->allocation_site_file;
arena->allocation_site_line = params->allocation_site_line;
#if ARENA_FREE_LIST
arena->free_size = 0;
arena->free_last = 0;
@@ -123,7 +126,9 @@ arena_push(Arena *arena, U64 size, U64 align)
}
new_block = arena_alloc(.reserve_size = res_size,
.commit_size = cmt_size,
.flags = current->flags);
.flags = current->flags,
.allocation_site_file = current->allocation_site_file,
.allocation_site_line = current->allocation_site_line);
}
new_block->base_pos = current->base_pos + current->res;
+6 -2
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_ARENA_H
@@ -26,6 +26,8 @@ struct ArenaParams
U64 reserve_size;
U64 commit_size;
void *optional_backing_buffer;
char *allocation_site_file;
int allocation_site_line;
};
typedef struct Arena Arena;
@@ -40,6 +42,8 @@ struct Arena
U64 pos;
U64 cmt;
U64 res;
char *allocation_site_file;
int allocation_site_line;
#if ARENA_FREE_LIST
U64 free_size;
Arena *free_last;
@@ -66,7 +70,7 @@ global ArenaFlags arena_default_flags = 0;
//- rjf: arena creation/destruction
internal Arena *arena_alloc_(ArenaParams *params);
#define arena_alloc(...) arena_alloc_(&(ArenaParams){.reserve_size = arena_default_reserve_size, .commit_size = arena_default_commit_size, .flags = arena_default_flags, __VA_ARGS__})
#define arena_alloc(...) arena_alloc_(&(ArenaParams){.reserve_size = arena_default_reserve_size, .commit_size = arena_default_commit_size, .flags = arena_default_flags, .allocation_site_file = __FILE__, .allocation_site_line = __LINE__, __VA_ARGS__})
internal void arena_release(Arena *arena);
//- rjf: arena push/pop/pos core functions
+38 -60
View File
@@ -1,19 +1,8 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ NOTE(rjf): Command Line Option Parsing
internal U64
cmd_line_hash_from_string(String8 string)
{
U64 result = 5381;
for(U64 i = 0; i < string.size; i += 1)
{
result = ((result << 5) + result) + string.str[i];
}
return result;
}
//~ rjf: Command Line Parsing Functions
internal CmdLineOpt **
cmd_line_slot_from_string(CmdLine *cmd_line, String8 string)
@@ -21,7 +10,7 @@ cmd_line_slot_from_string(CmdLine *cmd_line, String8 string)
CmdLineOpt **slot = 0;
if(cmd_line->option_table_size != 0)
{
U64 hash = cmd_line_hash_from_string(string);
U64 hash = u64_hash_from_str8(string);
U64 bucket = hash % cmd_line->option_table_size;
slot = &cmd_line->option_table[bucket];
}
@@ -64,7 +53,7 @@ cmd_line_insert_opt(Arena *arena, CmdLine *cmd_line, String8 string, String8List
{
var = push_array(arena, CmdLineOpt, 1);
var->hash_next = *slot;
var->hash = cmd_line_hash_from_string(string);
var->hash = u64_hash_from_str8(string);
var->string = push_str8_copy(arena, string);
var->value_strings = values;
StringJoin join = {0};
@@ -83,28 +72,25 @@ cmd_line_from_string_list(Arena *arena, String8List command_line)
{
CmdLine parsed = {0};
parsed.exe_name = command_line.first->string;
parsed.option_table_size = 64;
parsed.option_table = push_array(arena, CmdLineOpt *, parsed.option_table_size);
// NOTE(rjf): Set up config option table.
{
parsed.option_table_size = 4096;
parsed.option_table = push_array(arena, CmdLineOpt *, parsed.option_table_size);
}
// NOTE(rjf): Parse command line.
//- rjf: parse options / inputs
B32 after_passthrough_option = 0;
B32 first_passthrough = 1;
for(String8Node *node = command_line.first->next, *next = 0; node != 0; node = next)
{
next = node->next;
String8 option_name = node->string;
// NOTE(rjf): Look at --, -, or / (only on Windows) at the start of an
// argument to determine if it's a flag option. All arguments after a
//- rjf: look at --, -, or / (only on Windows) at the start of an
// argument to determine if it's a flag option. all arguments after a
// single "--" (with no trailing string on the command line will be
// considered as input files.
B32 is_option = 1;
if(after_passthrough_option == 0)
// considered as passthrough input strings.
B32 is_option = 0;
String8 option_name = node->string;
if(!after_passthrough_option)
{
is_option = 1;
if(str8_match(node->string, str8_lit("--"), 0))
{
after_passthrough_option = 1;
@@ -128,69 +114,61 @@ cmd_line_from_string_list(Arena *arena, String8List command_line)
is_option = 0;
}
}
else
{
is_option = 0;
}
// NOTE(rjf): This string is an option.
//- rjf: string is an option
if(is_option)
{
B32 has_arguments = 0;
U64 arg_signifier_position1 = str8_find_needle(option_name, 0, str8_lit(":"), 0);
U64 arg_signifier_position2 = str8_find_needle(option_name, 0, str8_lit("="), 0);
U64 arg_signifier_position = Min(arg_signifier_position1, arg_signifier_position2);
String8 arg_portion_this_string = str8_skip(option_name, arg_signifier_position+1);
if(arg_signifier_position < option_name.size)
// rjf: unpack option prefix
B32 has_values = 0;
U64 value_signifier_position1 = str8_find_needle(option_name, 0, str8_lit(":"), 0);
U64 value_signifier_position2 = str8_find_needle(option_name, 0, str8_lit("="), 0);
U64 value_signifier_position = Min(value_signifier_position1, value_signifier_position2);
String8 value_portion_this_string = str8_skip(option_name, value_signifier_position+1);
if(value_signifier_position < option_name.size)
{
has_arguments = 1;
has_values = 1;
}
option_name = str8_prefix(option_name, arg_signifier_position);
option_name = str8_prefix(option_name, value_signifier_position);
String8List arguments = {0};
// NOTE(rjf): Parse arguments.
if(has_arguments)
// rjf: parse option's values
String8List values = {0};
if(has_values)
{
for(String8Node *n = node; n; n = n->next)
{
next = n->next;
String8 string = n->string;
if(n == node)
{
string = arg_portion_this_string;
string = value_portion_this_string;
}
U8 splits[] = { ',' };
String8List args_in_this_string = str8_split(arena, string, splits, ArrayCount(splits), 0);
for(String8Node *sub_arg = args_in_this_string.first; sub_arg; sub_arg = sub_arg->next)
String8List values_in_this_string = str8_split(arena, string, splits, ArrayCount(splits), 0);
for(String8Node *sub_val = values_in_this_string.first; sub_val; sub_val = sub_val->next)
{
str8_list_push(arena, &arguments, sub_arg->string);
str8_list_push(arena, &values, sub_val->string);
}
if(!str8_match(str8_postfix(n->string, 1), str8_lit(","), 0) &&
(n != node || arg_portion_this_string.size != 0))
(n != node || value_portion_this_string.size != 0))
{
break;
}
}
}
// NOTE(rjf): Register config variable.
cmd_line_insert_opt(arena, &parsed, option_name, arguments);
// rjf: store
cmd_line_insert_opt(arena, &parsed, option_name, values);
}
// NOTE(rjf): Default path, treat as a passthrough config option to be
// handled by tool-specific code.
//- rjf: default path - treat as a passthrough input
else if(!str8_match(node->string, str8_lit("--"), 0) || !first_passthrough)
{
str8_list_push(arena, &parsed.inputs, node->string);
after_passthrough_option = 1;
first_passthrough = 0;
}
}
// rjf: fill argc/argv
//- rjf: fill argc/argv
parsed.argc = command_line.node_count;
parsed.argv = push_array(arena, char *, parsed.argc);
{
@@ -239,12 +217,12 @@ internal B32
cmd_line_has_flag(CmdLine *cmd_line, String8 name)
{
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
return(var != 0);
return (var != 0);
}
internal B32
cmd_line_has_argument(CmdLine *cmd_line, String8 name)
{
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
return(var != 0 && var->value_strings.node_count > 0);
return (var != 0 && var->value_strings.node_count > 0);
}
+2 -3
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_COMMAND_LINE_H
@@ -39,9 +39,8 @@ struct CmdLine
};
////////////////////////////////
//~ NOTE(rjf): Command Line Option Parsing
//~ rjf: Command Line Parsing Functions
internal U64 cmd_line_hash_from_string(String8 string);
internal CmdLineOpt** cmd_line_slot_from_string(CmdLine *cmd_line, String8 string);
internal CmdLineOpt* cmd_line_opt_from_slot(CmdLineOpt **slot, String8 string);
internal void cmd_line_push_opt(CmdLineOptList *list, CmdLineOpt *var);
+2 -2
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_CONTEXT_CRACKING_H
@@ -159,7 +159,7 @@
#endif
#if !defined(BUILD_VERSION_PATCH)
# define BUILD_VERSION_PATCH 18
# define BUILD_VERSION_PATCH 20
#endif
#define BUILD_VERSION_STRING_LITERAL Stringify(BUILD_VERSION_MAJOR) "." Stringify(BUILD_VERSION_MINOR) "." Stringify(BUILD_VERSION_PATCH)
+3 -3
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
@@ -523,7 +523,7 @@ date_time_from_unix_time(U64 unix_time)
date.sec = (U32)unix_time % 60;
date.min = (U32)(unix_time / 60) % 60;
date.hour = (U32)(unix_time / 3600) % 24;
for(;;)
{
for(date.month = 0; date.month < 12; ++date.month)
@@ -564,7 +564,7 @@ date_time_from_unix_time(U64 unix_time)
++date.year;
}
exit:;
return date;
}
+11 -9
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_CORE_H
@@ -346,7 +346,7 @@ C_LINKAGE void __asan_unpoison_memory_region(void const volatile *addr, size_t s
#else
# error Missing pointer-to-integer cast for this architecture.
#endif
#define PtrFromInt(i) (void*)((U8*)0 + (i))
#define PtrFromInt(i) (void*)(i)
#define Compose64Bit(a,b) ((((U64)a) << 32) | ((U64)b));
#define AlignPow2(x,b) (((x) + (b) - 1)&(~((b) - 1)))
@@ -487,14 +487,16 @@ typedef enum OperatingSystem
}
OperatingSystem;
typedef enum ImageType
typedef enum ExecutableImageKind
{
Image_Null,
Image_CoffPe,
Image_Elf32,
Image_Elf64,
Image_Macho
} ImageType;
ExecutableImageKind_Null,
ExecutableImageKind_CoffPe,
ExecutableImageKind_Elf32,
ExecutableImageKind_Elf64,
ExecutableImageKind_Macho,
ExecutableImageKind_COUNT
}
ExecutableImageKind;
typedef enum Arch
{
+6 -4
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
global U64 global_update_tick_idx = 0;
@@ -17,6 +17,11 @@ main_thread_base_entry_point(int arguments_count, char **arguments)
tmInitialize(sizeof(tm_data), tm_data);
#endif
//- rjf: set up spall
#if PROFILE_SPALL
spall_profile = spall_init_file_ex("spall_capture", 1, 0);
#endif
//- rjf: parse command line
String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, arguments_count, arguments);
CmdLine cmdline = cmd_line_from_string_list(scratch.arena, command_line_argument_strings);
@@ -36,9 +41,6 @@ main_thread_base_entry_point(int arguments_count, char **arguments)
#if defined(ASYNC_H) && !defined(ASYNC_INIT_MANUAL)
async_init(&cmdline);
#endif
#if defined(RDI_FROM_PDB_H) && !defined(P2R_INIT_MANUAL)
p2r_init();
#endif
#if defined(HASH_STORE_H) && !defined(HS_INIT_MANUAL)
hs_init();
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_ENTRY_POINT_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_INC_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
+3 -3
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_LOG_H
@@ -48,9 +48,9 @@ internal void log_select(Log *log);
internal void log_msg(LogMsgKind kind, String8 string);
internal void log_msgf(LogMsgKind kind, char *fmt, ...);
#define log_info(s) log_msg(LogMsgKind_Info, (s))
#define log_info(s) log_msg(LogMsgKind_Info, (s))
#define log_infof(...) log_msgf(LogMsgKind_Info, __VA_ARGS__)
#define log_user_error(s) log_msg(LogMsgKind_UserError, (s))
#define log_user_error(s) log_msg(LogMsgKind_UserError, (s))
#define log_user_errorf(...) log_msgf(LogMsgKind_UserError, __VA_ARGS__)
#define LogInfoNamedBlock(s) DeferLoop(log_infof("%S:\n{\n", (s)), log_infof("}\n"))
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal void
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_MARKUP_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_MATH_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_META_H
+30 -1
View File
@@ -1,2 +1,31 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#if PROFILE_SPALL
internal inline void
spall_begin(char *fmt, ...)
{
if(spall_buffer.data == 0)
{
spall_buffer.length = MB(1);
spall_buffer.data = os_reserve(spall_buffer.length);
os_commit(spall_buffer.data, spall_buffer.length);
spall_buffer_init(&spall_profile, &spall_buffer);
}
if(spall_pid == 0)
{
spall_pid = os_get_process_info()->pid;
}
if(spall_tid == 0)
{
spall_tid = os_tid();
}
Temp scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 string = push_str8fv(scratch.arena, fmt, args);
spall_buffer_begin_ex(&spall_profile, &spall_buffer, string.str, string.size, os_now_microseconds(), spall_tid, spall_pid);
va_end(args);
scratch_end(scratch);
}
#endif
+34 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_PROFILE_H
@@ -10,6 +10,9 @@
#if !defined(PROFILE_TELEMETRY)
# define PROFILE_TELEMETRY 0
#endif
#if !defined(PROFILE_SPALL)
# define PROFILE_SPALL 0
#endif
////////////////////////////////
//~ rjf: Third Party Includes
@@ -19,6 +22,8 @@
# if OS_WINDOWS
# pragma comment(lib, "rad_tm_win64.lib")
# endif
#elif PROFILE_SPALL
# include "spall.h"
#endif
////////////////////////////////
@@ -61,6 +66,34 @@ scratch_end(scratch); \
}
#endif
////////////////////////////////
//~ rjf: Spall Profile Defines
#if PROFILE_SPALL
global U64 spall_capturing = 0;
global SpallProfile spall_profile = {0};
thread_static SpallBuffer spall_buffer = {0};
thread_static U32 spall_tid = 0;
thread_static U32 spall_pid = 0;
internal inline void spall_begin(char *fmt, ...);
# define ProfBegin(...) (spall_capturing ? (spall_begin(__VA_ARGS__), 0) : 0)
# define ProfBeginDynamic(...) (spall_capturing ? (spall_begin(__VA_ARGS__), 0) : 0)
# define ProfEnd(...) (spall_capturing ? (spall_buffer_end_ex(&spall_profile, &spall_buffer, os_now_microseconds(), spall_tid, spall_pid)), 0 : 0)
# define ProfTick(...)
# define ProfIsCapturing(...) (!!spall_capturing)
# define ProfBeginCapture(...) (spall_capturing = 1)
# define ProfEndCapture(...) (spall_capturing = 0, spall_flush(&spall_profile))
# define ProfThreadName(...)
# define ProfMsg(...)
# define ProfBeginLockWait(...)
# define ProfEndLockWait(...)
# define ProfLockTake(...)
# define ProfLockDrop(...)
# define ProfColor(color)
# define ProfBeginV(...)
# define ProfNoteV(...)
#endif
////////////////////////////////
//~ rjf: Zeroify Undefined Defines
+24 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
@@ -2484,3 +2484,26 @@ str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out)
*block_out = str8_substr(string, range);
return block_out->size;
}
////////////////////////////////
//~ rjf: Basic String Hashes
#if !defined(XXH_IMPLEMENTATION)
# define XXH_IMPLEMENTATION
# define XXH_STATIC_LINKING_ONLY
# include "third_party/xxHash/xxhash.h"
#endif
internal U64
u64_hash_from_seed_str8(U64 seed, String8 string)
{
U64 result = XXH3_64bits_withSeed(string.str, string.size, seed);
return result;
}
internal U64
u64_hash_from_str8(String8 string)
{
U64 result = u64_hash_from_seed_str8(5381, string);
return result;
}
+7 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_STRINGS_H
@@ -433,4 +433,10 @@ internal U64 str8_deserial_read_block(String8 string, U64 off, U64 size, Stri
#define str8_deserial_read_array(string, off, ptr, count) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr))*(count), sizeof(*(ptr)))
#define str8_deserial_read_struct(string, off, ptr) str8_deserial_read_array(string, off, ptr, 1)
////////////////////////////////
//~ rjf: Basic String Hashes
internal U64 u64_hash_from_seed_str8(U64 seed, String8 string);
internal U64 u64_hash_from_str8(String8 string);
#endif // BASE_STRINGS_H
+30 -20
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
@@ -10,10 +10,12 @@ C_LINKAGE thread_static TCTX* tctx_thread_local = 0;
#endif
internal void
tctx_init_and_equip(TCTX *tctx){
tctx_init_and_equip(TCTX *tctx)
{
MemoryZeroStruct(tctx);
Arena **arena_ptr = tctx->arenas;
for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){
for(U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1)
{
*arena_ptr = arena_alloc();
}
tctx_thread_local = tctx;
@@ -28,37 +30,42 @@ tctx_release(void)
}
}
internal TCTX*
tctx_get_equipped(void){
return(tctx_thread_local);
internal TCTX *
tctx_get_equipped(void)
{
return tctx_thread_local;
}
internal Arena*
tctx_get_scratch(Arena **conflicts, U64 count){
internal Arena *
tctx_get_scratch(Arena **conflicts, U64 count)
{
TCTX *tctx = tctx_get_equipped();
Arena *result = 0;
Arena **arena_ptr = tctx->arenas;
for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){
for(U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1)
{
Arena **conflict_ptr = conflicts;
B32 has_conflict = 0;
for (U64 j = 0; j < count; j += 1, conflict_ptr += 1){
if (*arena_ptr == *conflict_ptr){
for(U64 j = 0; j < count; j += 1, conflict_ptr += 1)
{
if(*arena_ptr == *conflict_ptr)
{
has_conflict = 1;
break;
}
}
if (!has_conflict){
if(!has_conflict)
{
result = *arena_ptr;
break;
}
}
return(result);
return result;
}
internal void
tctx_set_thread_name(String8 string){
tctx_set_thread_name(String8 string)
{
TCTX *tctx = tctx_get_equipped();
U64 size = ClampTop(string.size, sizeof(tctx->thread_name));
MemoryCopy(tctx->thread_name, string.str, size);
@@ -66,21 +73,24 @@ tctx_set_thread_name(String8 string){
}
internal String8
tctx_get_thread_name(void){
tctx_get_thread_name(void)
{
TCTX *tctx = tctx_get_equipped();
String8 result = str8(tctx->thread_name, tctx->thread_name_size);
return(result);
return result;
}
internal void
tctx_write_srcloc(char *file_name, U64 line_number){
tctx_write_srcloc(char *file_name, U64 line_number)
{
TCTX *tctx = tctx_get_equipped();
tctx->file_name = file_name;
tctx->line_number = line_number;
}
internal void
tctx_read_srcloc(char **file_name, U64 *line_number){
tctx_read_srcloc(char **file_name, U64 *line_number)
{
TCTX *tctx = tctx_get_equipped();
*file_name = tctx->file_name;
*line_number = tctx->line_number;
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_THREAD_CONTEXT_H
+72 -72
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
@@ -14,30 +14,30 @@ cv_arch_from_coff_machine(COFF_MachineType machine)
CV_Arch arch = 0;
switch(machine)
{
case COFF_MachineType_X64: arch = CV_Arch_X64; break;
case COFF_MachineType_X86: arch = CV_Arch_8086; break;
case COFF_MachineType_Am33: arch = CV_Arch_AM33; break;
case COFF_MachineType_Arm: NotImplemented; break;
case COFF_MachineType_Arm64: arch = CV_Arch_ARM64; break;
case COFF_MachineType_ArmNt: arch = CV_Arch_ARMNT; break;
case COFF_MachineType_Ebc: arch = CV_Arch_EBC; break;
case COFF_MachineType_Ia64: arch = CV_Arch_IA64; break;
case COFF_MachineType_M32R: arch = CV_Arch_M32R; break;
case COFF_MachineType_Mips16: arch = CV_Arch_MIPS16; break;
case COFF_MachineType_MipsFpu: NotImplemented; break;
case COFF_MachineType_MipsFpu16: NotImplemented; break;
case COFF_MachineType_PowerPc: NotImplemented; break;
case COFF_MachineType_PowerPcFp: arch = CV_Arch_PPCFP; break;
case COFF_MachineType_R4000: NotImplemented; break;
case COFF_MachineType_RiscV32: NotImplemented; break;
case COFF_MachineType_RiscV64: NotImplemented; break;
case COFF_MachineType_RiscV128: NotImplemented; break;
case COFF_MachineType_Sh3: arch = CV_Arch_SH3; break;
case COFF_MachineType_Sh3Dsp: arch = CV_Arch_SH3DSP; break;
case COFF_MachineType_Sh4: arch = CV_Arch_SH4; break;
case COFF_MachineType_Sh5: NotImplemented; break;
case COFF_MachineType_Thumb: arch = CV_Arch_THUMB; break;
case COFF_MachineType_WceMipsV2: NotImplemented; break;
case COFF_MachineType_X64: arch = CV_Arch_X64; break;
case COFF_MachineType_X86: arch = CV_Arch_8086; break;
case COFF_MachineType_Am33: arch = CV_Arch_AM33; break;
case COFF_MachineType_Arm: NotImplemented; break;
case COFF_MachineType_Arm64: arch = CV_Arch_ARM64; break;
case COFF_MachineType_ArmNt: arch = CV_Arch_ARMNT; break;
case COFF_MachineType_Ebc: arch = CV_Arch_EBC; break;
case COFF_MachineType_Ia64: arch = CV_Arch_IA64; break;
case COFF_MachineType_M32R: arch = CV_Arch_M32R; break;
case COFF_MachineType_Mips16: arch = CV_Arch_MIPS16; break;
case COFF_MachineType_MipsFpu: NotImplemented; break;
case COFF_MachineType_MipsFpu16: NotImplemented; break;
case COFF_MachineType_PowerPc: NotImplemented; break;
case COFF_MachineType_PowerPcFp: arch = CV_Arch_PPCFP; break;
case COFF_MachineType_R4000: NotImplemented; break;
case COFF_MachineType_RiscV32: NotImplemented; break;
case COFF_MachineType_RiscV64: NotImplemented; break;
case COFF_MachineType_RiscV128: NotImplemented; break;
case COFF_MachineType_Sh3: arch = CV_Arch_SH3; break;
case COFF_MachineType_Sh3Dsp: arch = CV_Arch_SH3DSP; break;
case COFF_MachineType_Sh4: arch = CV_Arch_SH4; break;
case COFF_MachineType_Sh5: NotImplemented; break;
case COFF_MachineType_Thumb: arch = CV_Arch_THUMB; break;
case COFF_MachineType_WceMipsV2: NotImplemented; break;
}
return arch;
}
@@ -47,9 +47,9 @@ cv_size_from_reg(CV_Arch arch, CV_Reg reg)
{
switch(arch)
{
case CV_Arch_8086: return cv_size_from_reg_x86(reg);
case CV_Arch_X64 : return cv_size_from_reg_x64(reg);
default: NotImplemented;
case CV_Arch_8086: return cv_size_from_reg_x86(reg);
case CV_Arch_X64 : return cv_size_from_reg_x64(reg);
default: NotImplemented;
}
return 0;
}
@@ -59,9 +59,9 @@ cv_is_reg_sp(CV_Arch arch, CV_Reg reg)
{
switch(arch)
{
case CV_Arch_8086: return reg == CV_Regx86_ESP;
case CV_Arch_X64: return reg == CV_Regx64_RSP;
default: NotImplemented;
case CV_Arch_8086: return reg == CV_Regx86_ESP;
case CV_Arch_X64: return reg == CV_Regx64_RSP;
default: NotImplemented;
}
return 0;
}
@@ -84,7 +84,7 @@ cv_size_from_reg_x64(CV_Reg reg)
switch(reg)
{
#define X(NAME, CODE, RDI_NAME, BYTE_POS, BYTE_SIZE) case CV_Regx64_##NAME: return BYTE_SIZE;
CV_Reg_X64_XList(X)
CV_Reg_X64_XList(X)
#undef X
}
return 0;
@@ -111,30 +111,30 @@ cv_decode_fp_reg(CV_Arch arch, CV_EncodedFramePtrReg encoded_reg)
CV_Reg fp_reg = 0;
switch (arch)
{
case CV_Arch_8086:
{
switch (encoded_reg)
{
case CV_EncodedFramePtrReg_None : break;
case CV_EncodedFramePtrReg_StackPtr: AssertAlways(!"TODO: not tested, this is a guess");
fp_reg = CV_Regx86_ESP; break;
case CV_EncodedFramePtrReg_FramePtr: fp_reg = CV_Regx86_EBP; break;
case CV_EncodedFramePtrReg_BasePtr : fp_reg = CV_Regx86_EBX; break;
default: InvalidPath;
}
} break;
case CV_Arch_X64:
{
switch (encoded_reg)
{
case CV_EncodedFramePtrReg_None : break;
case CV_EncodedFramePtrReg_StackPtr: fp_reg = CV_Regx64_RSP; break;
case CV_EncodedFramePtrReg_FramePtr: fp_reg = CV_Regx64_RBP; break;
case CV_EncodedFramePtrReg_BasePtr : fp_reg = CV_Regx64_R13; break;
default: InvalidPath;
}
} break;
default: NotImplemented;
case CV_Arch_8086:
{
switch (encoded_reg)
{
case CV_EncodedFramePtrReg_None : break;
case CV_EncodedFramePtrReg_StackPtr: AssertAlways(!"TODO: not tested, this is a guess");
fp_reg = CV_Regx86_ESP; break;
case CV_EncodedFramePtrReg_FramePtr: fp_reg = CV_Regx86_EBP; break;
case CV_EncodedFramePtrReg_BasePtr : fp_reg = CV_Regx86_EBX; break;
default: InvalidPath;
}
} break;
case CV_Arch_X64:
{
switch (encoded_reg)
{
case CV_EncodedFramePtrReg_None : break;
case CV_EncodedFramePtrReg_StackPtr: fp_reg = CV_Regx64_RSP; break;
case CV_EncodedFramePtrReg_FramePtr: fp_reg = CV_Regx64_RBP; break;
case CV_EncodedFramePtrReg_BasePtr : fp_reg = CV_Regx64_R13; break;
default: InvalidPath;
}
} break;
default: NotImplemented;
}
return fp_reg;
}
@@ -144,22 +144,22 @@ cv_map_encoded_base_pointer(CV_Arch arch, U32 encoded_frame_reg)
{
U32 r = 0;
switch (arch) {
case CV_Arch_8086: {
switch (encoded_frame_reg) {
case 0: r = 0; break;
case 1: r = CV_AllReg_VFRAME; break;
case 2: r = CV_Regx86_EBP; break;
case 3: r = CV_Regx86_EBX; break;
}
} break;
case CV_Arch_X64: {
switch (encoded_frame_reg) {
case 0: r = 0; break;
case 1: r = CV_Regx64_RSP; break;
case 2: r = CV_Regx64_RBP; break;
case 3: r = CV_Regx64_R13; break;
}
} break;
case CV_Arch_8086: {
switch (encoded_frame_reg) {
case 0: r = 0; break;
case 1: r = CV_AllReg_VFRAME; break;
case 2: r = CV_Regx86_EBP; break;
case 3: r = CV_Regx86_EBX; break;
}
} break;
case CV_Arch_X64: {
switch (encoded_frame_reg) {
case 0: r = 0; break;
case 1: r = CV_Regx64_RSP; break;
case 2: r = CV_Regx64_RBP; break;
case 3: r = CV_Regx64_R13; break;
}
} break;
default: NotImplemented;
}
return r;
+995 -995
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -588,7 +588,7 @@ CV_LeafKindTable:
{MATRIX - 0x151c}
{VFTABLE - 0x151d}
{FUNC_ID FuncId 0x1601}
{MFUNC_ID MFuncId 0x1602}
{MFUNC_ID MFuncId 0x1602}
{BUILDINFO BuildInfo 0x1603}
{SUBSTR_LIST SubstrList 0x1604}
{STRING_ID StringId 0x1605}
+41 -41
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal String8
@@ -11,10 +11,10 @@ internal String8
cv_string_from_type_index_source(CV_TypeIndexSource ti_source)
{
switch (ti_source) {
case CV_TypeIndexSource_NULL: return str8_lit(""); break;
case CV_TypeIndexSource_TPI: return str8_lit("TPI"); break;
case CV_TypeIndexSource_IPI: return str8_lit("IPI"); break;
case CV_TypeIndexSource_COUNT: break;
case CV_TypeIndexSource_NULL: return str8_lit(""); break;
case CV_TypeIndexSource_TPI: return str8_lit("TPI"); break;
case CV_TypeIndexSource_IPI: return str8_lit("IPI"); break;
case CV_TypeIndexSource_COUNT: break;
}
return str8_zero();
}
@@ -23,9 +23,9 @@ internal String8
cv_string_from_language(CV_Language x)
{
switch (x) {
#define X(_n,_i) case _i: return str8_lit(Stringify(_n));
CV_LanguageXList(X)
#undef X
#define X(_n,_i) case _i: return str8_lit(Stringify(_n));
CV_LanguageXList(X)
#undef X
}
return str8_zero();
}
@@ -57,21 +57,21 @@ cv_string_from_reg_id(Arena *arena, CV_Arch arch, U32 id)
{
String8 result = str8_zero();
switch (arch) {
case CV_Arch_8086: {
case CV_Arch_8086: {
switch (id) {
#define X(_N, _ID, ...) case _ID: result = str8_lit(Stringify(_N)); break;
CV_Reg_X86_XList(X)
#undef X
#define X(_N, _ID, ...) case _ID: result = str8_lit(Stringify(_N)); break;
CV_Reg_X86_XList(X)
#undef X
}
} break;
case CV_Arch_X64: {
} break;
case CV_Arch_X64: {
switch (id) {
#define X(_N, _ID, ...) case _ID: result = str8_lit(Stringify(_N)); break;
CV_Reg_X64_XList(X)
#undef X
#define X(_N, _ID, ...) case _ID: result = str8_lit(Stringify(_N)); break;
CV_Reg_X64_XList(X)
#undef X
}
} break;
default: NotImplemented; break;
} break;
default: NotImplemented; break;
}
if (result.size == 0) {
result = push_str8f(arena, "%x", id);
@@ -327,9 +327,9 @@ internal String8
cv_string_from_c13_subsection_kind(CV_C13SubSectionKind x)
{
switch (x) {
#define X(_N, _ID) case CV_C13SubSectionKind_##_N: return str8_lit(Stringify(_N));
#define X(_N, _ID) case CV_C13SubSectionKind_##_N: return str8_lit(Stringify(_N));
CV_C13SubSectionKindXList(X)
#undef X
#undef X
}
return str8_zero();
}
@@ -357,7 +357,7 @@ internal String8
cv_string_from_pointer_attribs(Arena *arena, CV_PointerAttribs x)
{
Temp scratch = scratch_begin(&arena, 1);
String8List list = {0};
if (x & CV_PointerAttrib_IsFlat) {
x &= ~CV_PointerAttrib_IsFlat;
@@ -391,13 +391,13 @@ cv_string_from_pointer_attribs(Arena *arena, CV_PointerAttribs x)
x &= ~CV_PointerAttrib_RRef;
str8_list_pushf(scratch.arena, &list, "RRef");
}
CV_PointerKind kind = CV_PointerAttribs_Extract_Kind(x);
CV_PointerMode mode = CV_PointerAttribs_Extract_Mode(x);
U64 size = CV_PointerAttribs_Extract_Size(x);
x &= ~(0x1f|(0x7<<5)|(0x3f<<13));
if (kind) {
String8 kind_str = cv_string_from_pointer_kind(kind);
str8_list_pushf(scratch.arena, &list, "Kind=%S", kind_str);
@@ -409,11 +409,11 @@ cv_string_from_pointer_attribs(Arena *arena, CV_PointerAttribs x)
if (size) {
str8_list_pushf(scratch.arena, &list, "Size=%llu", size);
}
if (x != 0) {
str8_list_pushf(scratch.arena, &list, "Unknown=%x", x);
}
String8 result = str8_list_join(arena, &list, &(StringJoin){.sep=str8_lit(", ")});
scratch_end(scratch);
return result;
@@ -591,13 +591,13 @@ internal String8
cv_string_from_type_props(Arena *arena, CV_TypeProps32 x)
{
Temp scratch = scratch_begin(&arena, 1);
U32 hfa = CV_TypeProps_Extract_HFA(x);
U32 mcom = CV_TypeProps_Extract_MOCOM(x);
String8 hfa_str = cv_string_from_hfa(hfa);
String8 mcom_str = cv_string_from_mcom(mcom);
String8 flags_str;
{
String8List list = {0};
@@ -653,7 +653,7 @@ cv_string_from_type_props(Arena *arena, CV_TypeProps32 x)
str8_list_pushf(scratch.arena, &list, "%x", x);
}
flags_str = str8_list_join(scratch.arena, &list, &(StringJoin){.sep=str8_lit(", ") });
if (hfa) {
str8_list_pushf(scratch.arena, &list, "HFA = %S", hfa_str);
}
@@ -663,7 +663,7 @@ cv_string_from_type_props(Arena *arena, CV_TypeProps32 x)
}
String8 result = push_str8f(arena, "%S", flags_str);
scratch_end(scratch);
return result;
}
@@ -785,14 +785,14 @@ internal String8
cv_string_from_field_attribs(Arena *arena, CV_FieldAttribs attribs)
{
Temp scratch = scratch_begin(&arena, 1);
U32 access = CV_FieldAttribs_Extract_Access(attribs);
U32 mprop = CV_FieldAttribs_Extract_MethodProp(attribs);
attribs &= ~(0x3 | 0x7);
String8 access_str = cv_string_from_member_access(access);
String8 mprop_str = cv_string_from_method_prop(mprop);
String8List list = {0};
{
if (attribs & CV_FieldAttrib_Pseudo) {
@@ -819,16 +819,16 @@ cv_string_from_field_attribs(Arena *arena, CV_FieldAttribs attribs)
str8_list_pushf(scratch.arena, &list, "Unknown: %x", attribs);
}
}
if (access) {
str8_list_pushf(scratch.arena, &list, "%S", access_str);
}
if (mprop) {
str8_list_pushf(scratch.arena, &list, "%S", mprop_str);
}
String8 result = str8_list_join(scratch.arena, &list, &(StringJoin){.sep=str8_lit(", ")});
scratch_end(scratch);
return result;
}
@@ -841,7 +841,7 @@ cv_string_from_itype(Arena *arena, CV_TypeIndex min_itype, CV_TypeIndex itype)
String8 n = cv_type_name_from_basic_type((CV_BasicType)itype);
if (n.size) {
Temp scratch = scratch_begin(&arena, 1);
U64 type = CV_BasicTypeFromTypeId(itype);
char *type_str = "???";
switch (type) {
@@ -899,7 +899,7 @@ cv_string_from_itype(Arena *arena, CV_TypeIndex min_itype, CV_TypeIndex itype)
case CV_BasicType_CHAR8: type_str = "CHAR8"; break;
case CV_BasicType_PTR: type_str = "PTR"; break;
}
U64 ptr = CV_BasicPointerKindFromTypeId(itype);
char *ptr_str = "";
switch (ptr) {
@@ -910,7 +910,7 @@ cv_string_from_itype(Arena *arena, CV_TypeIndex min_itype, CV_TypeIndex itype)
case 0x5: ptr_str = "32PF"; break;
case 0x6: ptr_str = "64P"; break;
}
n = upper_from_str8(scratch.arena, n);
result = push_str8f(arena, "T_%s%s(%x)", ptr_str, type_str, itype);
scratch_end(scratch);
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CODEVIEW_ENUM_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- Hasher
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CODEVIEW_PARSE_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
+27 -27
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal U64
@@ -32,20 +32,20 @@ coff_section_flag_from_align_size(U64 align)
{
COFF_SectionFlags flags = 0;
switch (align) {
case 1: flags = COFF_SectionAlign_1Bytes; break;
case 2: flags = COFF_SectionAlign_2Bytes; break;
case 4: flags = COFF_SectionAlign_4Bytes; break;
case 8: flags = COFF_SectionAlign_8Bytes; break;
case 16: flags = COFF_SectionAlign_16Bytes; break;
case 32: flags = COFF_SectionAlign_32Bytes; break;
case 64: flags = COFF_SectionAlign_64Bytes; break;
case 128: flags = COFF_SectionAlign_128Bytes; break;
case 256: flags = COFF_SectionAlign_256Bytes; break;
case 512: flags = COFF_SectionAlign_512Bytes; break;
case 1024: flags = COFF_SectionAlign_1024Bytes; break;
case 2048: flags = COFF_SectionAlign_2048Bytes; break;
case 4096: flags = COFF_SectionAlign_4096Bytes; break;
case 8192: flags = COFF_SectionAlign_8192Bytes; break;
case 1: flags = COFF_SectionAlign_1Bytes; break;
case 2: flags = COFF_SectionAlign_2Bytes; break;
case 4: flags = COFF_SectionAlign_4Bytes; break;
case 8: flags = COFF_SectionAlign_8Bytes; break;
case 16: flags = COFF_SectionAlign_16Bytes; break;
case 32: flags = COFF_SectionAlign_32Bytes; break;
case 64: flags = COFF_SectionAlign_64Bytes; break;
case 128: flags = COFF_SectionAlign_128Bytes; break;
case 256: flags = COFF_SectionAlign_256Bytes; break;
case 512: flags = COFF_SectionAlign_512Bytes; break;
case 1024: flags = COFF_SectionAlign_1024Bytes; break;
case 2048: flags = COFF_SectionAlign_2048Bytes; break;
case 4096: flags = COFF_SectionAlign_4096Bytes; break;
case 8192: flags = COFF_SectionAlign_8192Bytes; break;
}
flags <<= COFF_SectionFlag_AlignShift;
return flags;
@@ -127,12 +127,12 @@ coff_apply_size_from_reloc_x64(COFF_Reloc_X64 x)
case COFF_Reloc_X64_Section: return 2;
case COFF_Reloc_X64_SecRel: return 4;
case COFF_Reloc_X64_SRel32: return 4;
case COFF_Reloc_X64_SecRel7:
case COFF_Reloc_X64_Token:
case COFF_Reloc_X64_Pair:
case COFF_Reloc_X64_SSpan32:
NotImplemented;
NotImplemented;
break;
}
return 0;
@@ -153,7 +153,7 @@ coff_apply_size_from_reloc_x86(COFF_Reloc_X86 x)
case COFF_Reloc_X86_Token: return 4;
case COFF_Reloc_X86_SecRel7: return 1;
case COFF_Reloc_X86_Rel32: return 4;
case COFF_Reloc_X86_Unknown0:
case COFF_Reloc_X86_Unknown2:
case COFF_Reloc_X86_Unknown3:
@@ -162,7 +162,7 @@ coff_apply_size_from_reloc_x86(COFF_Reloc_X86 x)
case COFF_Reloc_X86_Unknown7:
case COFF_Reloc_X86_Unknown8:
case COFF_Reloc_X86_Unknown9:
NotImplemented;
NotImplemented;
break;
}
return 0;
@@ -217,7 +217,7 @@ coff_make_import_header_by_name(Arena *arena,
COFF_ImportHeaderFlags flags = 0;
flags |= (type & COFF_ImportHeader_TypeMask) << COFF_ImportHeader_TypeShift;
flags |= COFF_ImportBy_Name << COFF_ImportHeader_ImportByShift;
COFF_ImportHeader header = {0};
header.sig1 = COFF_MachineType_Unknown;
header.sig2 = max_U16;
@@ -260,7 +260,7 @@ coff_make_import_header_by_ordinal(Arena *arena,
COFF_ImportHeaderFlags flags = 0;
flags |= (type & COFF_ImportHeader_TypeMask) << COFF_ImportHeader_TypeShift;
flags |= COFF_ImportBy_Ordinal << COFF_ImportHeader_ImportByShift;
COFF_ImportHeader header = {0};
header.sig1 = COFF_MachineType_Unknown;
header.sig2 = max_U16;
@@ -296,8 +296,8 @@ coff_word_size_from_machine(COFF_MachineType machine)
{
U64 result = 0;
switch (machine) {
case COFF_MachineType_X64: result = 8; break;
case COFF_MachineType_X86: result = 4; break;
case COFF_MachineType_X64: result = 8; break;
case COFF_MachineType_X86: result = 4; break;
}
return result;
}
@@ -307,8 +307,8 @@ coff_default_exe_base_from_machine(COFF_MachineType machine)
{
U64 exe_base = 0;
switch (coff_word_size_from_machine(machine)) {
case 4: exe_base = 0x400000; break;
case 8: exe_base = 0x140000000; break;
case 4: exe_base = 0x400000; break;
case 8: exe_base = 0x140000000; break;
}
return exe_base;
}
@@ -318,8 +318,8 @@ coff_default_dll_base_from_machine(COFF_MachineType machine)
{
U64 dll_base = 0;
switch (coff_word_size_from_machine(machine)) {
case 4: dll_base = 0x10000000; break;
case 8: dll_base = 0x180000000; break;
case 4: dll_base = 0x10000000; break;
case 8: dll_base = 0x180000000; break;
}
return dll_base;
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef COFF_H
+16 -16
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal String8
@@ -62,13 +62,13 @@ coff_string_from_comdat_select_type(COFF_ComdatSelectType type)
{
String8 result = str8_zero();
switch (type) {
case COFF_ComdatSelect_Null: result = str8_lit("Null"); break;
case COFF_ComdatSelect_NoDuplicates: result = str8_lit("NoDuplicates"); break;
case COFF_ComdatSelect_Any: result = str8_lit("Any"); break;
case COFF_ComdatSelect_SameSize: result = str8_lit("SameSize"); break;
case COFF_ComdatSelect_ExactMatch: result = str8_lit("ExactMatch"); break;
case COFF_ComdatSelect_Associative: result = str8_lit("Associative"); break;
case COFF_ComdatSelect_Largest: result = str8_lit("Largest"); break;
case COFF_ComdatSelect_Null: result = str8_lit("Null"); break;
case COFF_ComdatSelect_NoDuplicates: result = str8_lit("NoDuplicates"); break;
case COFF_ComdatSelect_Any: result = str8_lit("Any"); break;
case COFF_ComdatSelect_SameSize: result = str8_lit("SameSize"); break;
case COFF_ComdatSelect_ExactMatch: result = str8_lit("ExactMatch"); break;
case COFF_ComdatSelect_Associative: result = str8_lit("Associative"); break;
case COFF_ComdatSelect_Largest: result = str8_lit("Largest"); break;
}
return result;
}
@@ -89,7 +89,7 @@ coff_string_from_flags(Arena *arena, COFF_FileHeaderFlags flags)
{
Temp scratch = scratch_begin(&arena, 1);
String8List list = {0};
if (flags & COFF_FileHeaderFlag_RelocStripped) {
str8_list_pushf(scratch.arena, &list, "Relocs Stripped");
}
@@ -126,9 +126,9 @@ coff_string_from_flags(Arena *arena, COFF_FileHeaderFlags flags)
if (flags & COFF_FileHeaderFlag_UpSystemOnly) {
str8_list_pushf(scratch.arena, &list, "Up System Only");
}
String8 result = str8_list_join(arena, &list, &(StringJoin){.sep=str8_lit(", ")});
scratch_end(scratch);
return result;
}
@@ -201,7 +201,7 @@ coff_string_from_section_flags(Arena *arena, COFF_SectionFlags flags)
if (align) {
str8_list_pushf(scratch.arena, &list, "Align=%u", align);
}
if (!list.node_count) {
str8_list_pushf(scratch.arena, &list, "None");
}
@@ -218,9 +218,9 @@ internal String8
coff_string_from_resource_memory_flags(Arena *arena, COFF_ResourceMemoryFlags flags)
{
Temp scratch = scratch_begin(&arena, 1);
String8List list = {0};
if (flags & COFF_ResourceMemoryFlag_Moveable) {
flags &= COFF_ResourceMemoryFlag_Moveable;
str8_list_pushf(scratch.arena, &list, "Moveable");
@@ -236,9 +236,9 @@ coff_string_from_resource_memory_flags(Arena *arena, COFF_ResourceMemoryFlags fl
if (flags != 0) {
str8_list_pushf(scratch.arena, &list, "%#x", flags);
}
String8 result = str8_list_join(arena, &list, &(StringJoin){.sep=str8_lit(", ")});
scratch_end(scratch);
return result;
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef COFF_ENUM_H
+61 -61
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal B32
@@ -8,9 +8,9 @@ coff_is_big_obj(String8 raw_coff)
if (raw_coff.size >= sizeof(COFF_BigObjHeader)) {
COFF_BigObjHeader *file_header32 = (COFF_BigObjHeader*)(raw_coff.str);
is_big_obj = file_header32->sig1 == COFF_MachineType_Unknown &&
file_header32->sig2 == max_U16 &&
file_header32->version >= 2 &&
MemoryCompare(file_header32->magic, g_coff_big_header_magic, sizeof(file_header32->magic)) == 0;
file_header32->sig2 == max_U16 &&
file_header32->version >= 2 &&
MemoryCompare(file_header32->magic, g_coff_big_header_magic, sizeof(file_header32->magic)) == 0;
}
return is_big_obj;
}
@@ -163,11 +163,11 @@ coff_symbol_array_from_data_16(Arena *arena, String8 raw_coff, U64 symbol_array_
Rng1U64 sym16_arr_range = rng_1u64(symbol_array_off, symbol_array_off + sizeof(COFF_Symbol16) * symbol_count);
String8 raw_sym16_arr = str8_substr(raw_coff, sym16_arr_range);
COFF_Symbol16 *sym16_arr = (COFF_Symbol16 *)raw_sym16_arr.str;
for (U64 isymbol = 0, count = raw_sym16_arr.size / sizeof(COFF_Symbol16); isymbol < count; isymbol += 1) {
COFF_Symbol16 *sym16 = &sym16_arr[isymbol];
COFF_Symbol32 *sym32 = &result.v[isymbol];
sym32->name = sym16->name;
sym32->value = sym16->value;
if (sym16->section_number == COFF_Symbol_DebugSection16) {
@@ -185,7 +185,7 @@ coff_symbol_array_from_data_16(Arena *arena, String8 raw_coff, U64 symbol_array_
for (U64 iaux = isymbol+1, iaux_hi = Min(count, iaux+sym16->aux_symbol_count); iaux < iaux_hi; iaux += 1) {
COFF_Symbol16 *aux16 = sym16_arr + iaux;
COFF_Symbol32 *aux32 = result.v + iaux;
// 32bit COFF uses 16bit aux symbols
MemoryCopy(aux32, aux16, sizeof(COFF_Symbol16));
MemoryZero((U8 *)aux32 + sizeof(COFF_Symbol16), sizeof(COFF_Symbol32)-sizeof(COFF_Symbol16));
@@ -286,11 +286,11 @@ coff_resource_string_from_str16(Arena *arena, String16 string)
{
AssertAlways(string.size <= max_U16);
U16 size16 = (U16)string.size;
U16 *buffer = push_array_no_zero(arena, U16, size16 + 1);
MemoryCopy(buffer + 0, &size16, sizeof(size16));
MemoryCopy(buffer + 1, string.str, size16 * sizeof(string.str[0]));
return str8_array(buffer, size16 + 1);
}
@@ -358,14 +358,14 @@ coff_read_resource(Arena *arena, String8 raw_res, U64 off, COFF_ParsedResource *
{
String8 raw_header = str8_skip(raw_res, off);
U64 header_cursor = 0;
// prefix
COFF_ResourceHeaderPrefix prefix = {0};
header_cursor += str8_deserial_read_struct(raw_header, header_cursor, &prefix);
Assert(prefix.header_size >= sizeof(COFF_ResourceHeaderPrefix));
raw_header = str8_prefix(raw_header, prefix.header_size);
// header
COFF_ResourceID16 type_16 = {0};
COFF_ResourceID16 name_16 = {0};
@@ -377,11 +377,11 @@ coff_read_resource(Arena *arena, String8 raw_res, U64 off, COFF_ParsedResource *
header_cursor += str8_deserial_read_struct(raw_header, header_cursor, &res_out->version);
header_cursor += str8_deserial_read_struct(raw_header, header_cursor, &res_out->characteristics);
Assert(prefix.header_size == header_cursor);
// convert utf-16 resource ids to utf-8
res_out->type = coff_utf8_resource_id_from_utf16(arena, &type_16);
res_out->name = coff_utf8_resource_id_from_utf16(arena, &name_16);
// read data
U64 data_read_size = str8_deserial_read_block(raw_res, off + prefix.header_size, prefix.data_size, &res_out->data);
Assert(prefix.data_size == data_read_size);
@@ -411,14 +411,14 @@ coff_write_resource_id(Arena *arena, COFF_ResourceID id)
{
String8 result = str8_zero();
switch (id.type) {
case COFF_ResourceIDType_Null: break;
case COFF_ResourceIDType_Number: {
result = coff_resource_number_from_u16(arena, id.u.number);
} break;
case COFF_ResourceIDType_String: {
result = coff_resource_string_from_str8(arena, id.u.string);
} break;
default: InvalidPath;
case COFF_ResourceIDType_Null: break;
case COFF_ResourceIDType_Number: {
result = coff_resource_number_from_u16(arena, id.u.number);
} break;
case COFF_ResourceIDType_String: {
result = coff_resource_string_from_str8(arena, id.u.string);
} break;
default: InvalidPath;
}
return result;
}
@@ -435,13 +435,13 @@ coff_write_resource(Arena *arena,
String8 data)
{
Temp scratch = scratch_begin(&arena, 1);
String8List list = {0};
COFF_ResourceHeaderPrefix *prefix = push_array(scratch.arena, COFF_ResourceHeaderPrefix, 1);
String8 packed_type = coff_write_resource_id(scratch.arena, type);
String8 packed_name = coff_write_resource_id(scratch.arena, name);
// prefix + header
str8_list_push(scratch.arena, &list, str8_struct(prefix));
str8_list_push(scratch.arena, &list, packed_type);
@@ -451,24 +451,24 @@ coff_write_resource(Arena *arena,
str8_list_push(scratch.arena, &list, str8_struct(&language_id));
str8_list_push(scratch.arena, &list, str8_struct(&version));
str8_list_push(scratch.arena, &list, str8_struct(&characteristics));
prefix->data_size = safe_cast_u32(data.size);
prefix->header_size = safe_cast_u32(list.total_size);
// data
str8_list_push(scratch.arena, &list, data);
// magic
str8_list_push_front(scratch.arena, &list, str8_array_fixed(g_coff_res_magic));
// align
U64 align_size = AlignPow2(list.total_size, COFF_ResourceAlign) - list.total_size;
U8 *align = push_array(scratch.arena, U8, align_size);
str8_list_push(scratch.arena, &list, str8(align, align_size));
// join
String8 res = str8_list_join(arena, &list, 0);
scratch_end(scratch);
return res;
}
@@ -481,10 +481,10 @@ coff_resource_id_compar(void *raw_a, void *raw_b)
COFF_ResourceID *b = raw_b;
if (a->type == b->type) {
switch (a->type) {
default:
case COFF_ResourceIDType_Null: cmp = 0; break;
case COFF_ResourceIDType_Number: cmp = MemoryCompare(&a->u.number, &b->u.number, sizeof(a->u.number)); break;
case COFF_ResourceIDType_String: cmp = strncmp((char *)a->u.string.str, (char *)b->u.string.str, Min(a->u.string.size, b->u.string.size)); break;
default:
case COFF_ResourceIDType_Null: cmp = 0; break;
case COFF_ResourceIDType_Number: cmp = MemoryCompare(&a->u.number, &b->u.number, sizeof(a->u.number)); break;
case COFF_ResourceIDType_String: cmp = strncmp((char *)a->u.string.str, (char *)b->u.string.str, Min(a->u.string.size, b->u.string.size)); break;
}
} else {
cmp = a->type < b->type ? -1 : a->type > b->type ? +1 : 0;
@@ -563,10 +563,10 @@ coff_parse_archive_member_header(String8 raw_archive, U64 offset, COFF_ParsedArc
String8 mode = str8_skip_chop_whitespace(str8_cstring_capped(header->mode, header->mode + sizeof(header->mode) ));
String8 size = str8_skip_chop_whitespace(str8_cstring_capped(header->size, header->size + sizeof(header->size) ));
String8 end = str8_cstring_capped(header->end, header->end + sizeof(header->end));
U32 data_size = u32_from_str8(size, 10);
U64 data_off = offset + sizeof(COFF_ArchiveMemberHeader);
header_out->name = name;
header_out->time_stamp = u32_from_str8(date, 10);
header_out->user_id = u32_from_str8(user_id, 10);
@@ -574,7 +574,7 @@ coff_parse_archive_member_header(String8 raw_archive, U64 offset, COFF_ParsedArc
header_out->mode = mode;
header_out->is_end_correct = str8_match_lit("`\n", end, 0);
header_out->data_range = rng_1u64(data_off, data_off + data_size);
return sizeof(*header);
}
return 0;
@@ -584,7 +584,7 @@ internal COFF_ArchiveFirstMember
coff_parse_first_archive_member(COFF_ArchiveMember *member)
{
Assert(str8_match_lit("/", member->header.name, 0));
U64 cursor = 0;
U32 symbol_count = 0;
@@ -597,17 +597,17 @@ coff_parse_first_archive_member(COFF_ArchiveMember *member)
Rng1U64 string_table_range = rng_1u64(cursor, member->data.size);
cursor += dim_1u64(string_table_range);
String8 raw_member_offsets = str8_substr(member->data, member_offsets_range);
U32 *member_offsets = (U32 *)raw_member_offsets.str;
U64 member_offset_count = raw_member_offsets.size / sizeof(member_offsets[0]);
COFF_ArchiveFirstMember result = {0};
result.symbol_count = symbol_count;
result.member_offset_count = member_offset_count;
result.member_offsets = member_offsets;
result.string_table = str8_substr(member->data, string_table_range);
return result;
}
@@ -615,7 +615,7 @@ internal COFF_ArchiveSecondMember
coff_parse_second_archive_member(COFF_ArchiveMember *member)
{
COFF_ArchiveSecondMember result = {0};
if (str8_match_lit("/", member->header.name, 0)) {
U64 cursor = 0;
@@ -632,13 +632,13 @@ coff_parse_second_archive_member(COFF_ArchiveMember *member)
cursor += dim_1u64(symbol_indices_range);
Rng1U64 string_table_range = rng_1u64(cursor, member->data.size);
String8 raw_member_offsets = str8_substr(member->data, member_offsets_range);
String8 raw_indices = str8_substr(member->data, symbol_indices_range);
U32 *member_offsets = (U32 *)raw_member_offsets.str;
U64 member_offset_count = raw_member_offsets.size / sizeof(member_offsets[0]);
U16 *symbol_indices = (U16 *)raw_indices.str;
U64 symbol_index_count = raw_indices.size / sizeof(symbol_indices[0]);
@@ -650,7 +650,7 @@ coff_parse_second_archive_member(COFF_ArchiveMember *member)
result.symbol_index_count = symbol_index_count;
result.string_table = str8_substr(member->data, string_table_range);
}
return result;
}
@@ -683,7 +683,7 @@ coff_parse_import(String8 raw_archive_member, U64 offset, COFF_ParsedArchiveImpo
Rng1U64 data_range = rng_1u64(offset + sizeof(*header), offset + sizeof(*header) + header->data_size);
String8 raw_data = str8_substr(raw_archive_member, data_range);
U64 data_cursor = 0;
header_out->version = header->version;
header_out->machine = header->machine;
header_out->time_stamp = header->time_stamp;
@@ -744,7 +744,7 @@ coff_regular_archive_member_iter_next(String8 raw_archive, U64 *offset, COFF_Arc
if (member_out->header.is_end_correct) {
member_out->offset = *offset;
member_out->data = str8_substr(raw_archive, member_out->header.data_range);
U64 read_size = AlignPow2(header_size + dim_1u64(member_out->header.data_range), COFF_Archive_MemberAlign);
*offset += read_size;
@@ -771,19 +771,19 @@ coff_thin_archive_member_iter_next(String8 raw_archive, U64 *offset, COFF_Archiv
member_out->header.is_end_correct = 0;
U64 header_size = coff_parse_archive_member_header(raw_archive, *offset, &member_out->header);
if (member_out->header.is_end_correct) {
Rng1U64 data_in_archive_range = {0};
if (str8_match_lit("/", member_out->header.name, 0) || str8_match_lit("//", member_out->header.name, 0)) {
data_in_archive_range = member_out->header.data_range;
}
member_out->offset = *offset;
member_out->data = str8_substr(raw_archive, data_in_archive_range);
U64 read_size = AlignPow2(header_size + dim_1u64(data_in_archive_range), COFF_Archive_MemberAlign);
*offset += read_size;
is_parsed = 1;
}
@@ -806,9 +806,9 @@ coff_archive_parse_from_member_list(COFF_ArchiveMemberList member_list)
COFF_ArchiveMember first_header = {0};
COFF_ArchiveMember second_header = {0};
COFF_ArchiveMember long_names_member = {0};
COFF_ArchiveMemberNode *ptr = member_list.first;
if (ptr) {
if (str8_match_lit("/", ptr->data.header.name, 0)) {
if (ptr->data.header.is_end_correct) {
@@ -821,7 +821,7 @@ coff_archive_parse_from_member_list(COFF_ArchiveMemberList member_list)
} else {
error = str8_lit("missing first header");
}
if (!error.size && ptr) {
if (str8_match_lit("/", ptr->data.header.name, 0)) {
if (ptr->data.header.is_end_correct) {
@@ -833,7 +833,7 @@ coff_archive_parse_from_member_list(COFF_ArchiveMemberList member_list)
}
}
}
if (!error.size && ptr) {
if (str8_match_lit("//", ptr->data.header.name, 0)) {
if (ptr->data.header.is_end_correct) {
@@ -853,7 +853,7 @@ coff_archive_parse_from_member_list(COFF_ArchiveMemberList member_list)
parse.second_member = coff_parse_second_archive_member(&second_header);
parse.long_names = long_names_member.data;
parse.error = error;
return parse;
}
@@ -894,9 +894,9 @@ coff_archive_parse_from_data(String8 raw_archive)
{
COFF_ArchiveType type = coff_archive_type_from_data(raw_archive);
switch (type) {
case COFF_Archive_Null: break;
case COFF_Archive_Regular: return coff_regular_archive_parse_from_data(raw_archive);
case COFF_Archive_Thin: return coff_thin_archive_parse_from_data(raw_archive);
case COFF_Archive_Null: break;
case COFF_Archive_Regular: return coff_regular_archive_parse_from_data(raw_archive);
case COFF_Archive_Thin: return coff_thin_archive_parse_from_data(raw_archive);
}
COFF_ArchiveParse null_parse = {0};
return null_parse;
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef COFF_PARSE_H
+12 -11
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
@@ -7,16 +7,17 @@
@table(name code_name display_string)
CTRL_EntityKindTable:
{
{Root root "Root" }
{Machine machine "Machine" }
{Process process "Process" }
{Thread thread "Thread" }
{Module module "Module" }
{EntryPoint entry_point "Entry Point" }
{DebugInfoPath debug_info_path "Debug Info Path" }
{PendingThreadName pending_thread_name "Pending Thread Name" }
{PendingThreadColor pending_thread_color "Pending Thread Color" }
{Breakpoint breakpoint "Breakpoint" }
{Root root "Root" }
{Machine machine "Machine" }
{Process process "Process" }
{Thread thread "Thread" }
{Module module "Module" }
{EntryPoint entry_point "Entry Point" }
{DebugInfoPath debug_info_path "Debug Info Path" }
{PendingThreadName pending_thread_name "Pending Thread Name" }
{PendingThreadColor pending_thread_color "Pending Thread Color" }
{Breakpoint breakpoint "Breakpoint" }
{AddressRangeAnnotation address_range_annotation "Address Range Annotation" }
}
@enum CTRL_EntityKind:
+123 -99
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
@@ -1399,6 +1399,15 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis
}
}
}break;
//- rjf: address range annotations
case CTRL_EventKind_SetVAddrRangeNote:
{
CTRL_Entity *process = ctrl_entity_from_handle(&store->ctx, event->parent);
CTRL_Entity *annotation = ctrl_entity_alloc(store, process, CTRL_EntityKind_AddressRangeAnnotation, Arch_Null, ctrl_handle_zero(), 0);
annotation->vaddr_range = event->vaddr_rng;
ctrl_entity_equip_string(store, annotation, event->string);
}break;
}
}
}
@@ -1652,14 +1661,13 @@ ctrl_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 vaddr_range, B32
//- rjf: loop: try to look for current results, request if not there, wait if we can, repeat until we can't
U64 mem_gen = ctrl_mem_gen();
B32 key_is_stale = 0;
B32 requested = 0;
for(;;)
{
//- rjf: step 1: [read-only] try to look for current results for key's ID
//- rjf: step 1: [read-only] try to look for current results for key's ID; wait if working & retry
B32 id_exists = 0;
B32 id_stale = 0;
B32 id_working = 0;
OS_MutexScopeR(process_stripe->rw_mutex)
OS_MutexScopeR(process_stripe->rw_mutex) for(;;)
{
for(CTRL_ProcessMemoryCacheNode *process_n = process_slot->first; process_n != 0; process_n = process_n->next)
{
@@ -1680,6 +1688,14 @@ ctrl_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 vaddr_range, B32
}
}
end_fast_lookup:;
if(os_now_microseconds() >= endt_us || !id_working)
{
break;
}
else
{
os_condition_variable_wait_rw_r(process_stripe->cv, process_stripe->rw_mutex, endt_us);
}
}
key_is_stale = id_stale;
@@ -1693,7 +1709,9 @@ ctrl_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 vaddr_range, B32
//- rjf: step 3: if the ID does not exist in the process' cache, then we
// need to build a node for it. if that, or if the ID is stale, then also
// request that that range is streamed.
// request that that range is streamed & wait for its result (for as long
// as we have.)
B32 requested = 0;
if(!id_exists || (id_exists && id_stale && !id_working))
{
B32 node_needs_stream = 0;
@@ -1722,16 +1740,15 @@ ctrl_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 vaddr_range, B32
range_n->vaddr_range = vaddr_range;
range_n->zero_terminated = zero_terminated;
range_n->id = id;
ins_atomic_u64_inc_eval(&range_n->working_count);
node_needs_stream = 1;
}
else
{
node_needs_stream = (range_n->mem_gen < mem_gen);
if(node_needs_stream)
{
ins_atomic_u64_inc_eval(&range_n->working_count);
}
}
if(node_needs_stream)
{
ins_atomic_u64_inc_eval(&range_n->working_count);
}
node_working_count = &range_n->working_count;
break;
@@ -1768,21 +1785,11 @@ ctrl_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 vaddr_range, B32
}
}
//- rjf: step 4: if we have no time to wait, then abort; if we submitted a
// request, but the work is done and we have no results, then abort;
// otherwise, wait on this process' stripe
if(os_now_microseconds() >= endt_us)
//- rjf: step 4: if we didn't request, and if we aren't working, then exit
if(!requested && !id_working)
{
break;
}
else if(!id_working && requested)
{
break;
}
else OS_MutexScopeR(process_stripe->rw_mutex)
{
os_condition_variable_wait_rw_r(process_stripe->cv, process_stripe->rw_mutex, endt_us);
}
}
if(out_is_stale)
{
@@ -3399,85 +3406,93 @@ ctrl_call_stack_from_thread(CTRL_Scope *scope, CTRL_EntityCtx *entity_ctx, CTRL_
//
B32 can_request = !ins_atomic_u64_eval(&ctrl_state->ctrl_thread_run_state);
B32 did_request = 0;
OS_MutexScopeR(stripe->rw_mutex) for(;;)
OS_MutexScopeR(stripe->rw_mutex)
{
////////////////////////////
//- rjf: try to grab cached
//
B32 is_good = 0;
B32 is_stale = 1;
B32 is_working = 0;
CTRL_CallStackCacheNode *node = 0;
CTRL_CallStackCacheNode *taken_node = 0;
for(;;)
{
for(CTRL_CallStackCacheNode *n = slot->first; n != 0; n = n->next)
////////////////////////////
//- rjf: try to grab cached
//
B32 is_good = 0;
B32 is_stale = 1;
B32 is_working = 0;
CTRL_CallStackCacheNode *node = 0;
{
if(ctrl_handle_match(n->thread, handle))
for(CTRL_CallStackCacheNode *n = slot->first; n != 0; n = n->next)
{
node = n;
is_good = 1;
is_stale = (reg_gen > n->reg_gen || mem_gen > n->mem_gen);
is_working = (n->working_count > 0);
call_stack = n->call_stack;
ctrl_scope_touch_call_stack_node__stripe_r_guarded(scope, stripe, n);
break;
if(ctrl_handle_match(n->thread, handle))
{
node = n;
is_good = 1;
is_stale = (reg_gen > n->reg_gen || mem_gen > n->mem_gen);
is_working = (n->working_count > 0);
call_stack = n->call_stack;
taken_node = node;
break;
}
}
}
}
////////////////////////////
//- rjf: create node if needed
//
if(!is_good) OS_MutexScopeRWPromote(stripe->rw_mutex)
{
node = 0;
for(CTRL_CallStackCacheNode *n = slot->first; n != 0; n = n->next)
////////////////////////////
//- rjf: create node if needed
//
if(!is_good) OS_MutexScopeRWPromote(stripe->rw_mutex)
{
if(ctrl_handle_match(n->thread, handle))
node = 0;
for(CTRL_CallStackCacheNode *n = slot->first; n != 0; n = n->next)
{
node = n;
break;
if(ctrl_handle_match(n->thread, handle))
{
node = n;
break;
}
}
if(node == 0)
{
node = push_array(stripe->arena, CTRL_CallStackCacheNode, 1);
DLLPushBack(slot->first, slot->last, node);
node->thread = thread->handle;
}
}
if(node == 0)
////////////////////////////
//- rjf: request if needed
//
if(can_request && node != 0 && !is_working && is_stale)
{
node = push_array(stripe->arena, CTRL_CallStackCacheNode, 1);
DLLPushBack(slot->first, slot->last, node);
node->thread = thread->handle;
if(ctrl_u2csb_enqueue_req(thread->handle, endt_us))
{
did_request = 1;
is_working = 1;
ins_atomic_u64_inc_eval(&node->working_count);
async_push_work(ctrl_call_stack_build_work, .priority = high_priority ? ASYNC_Priority_High : ASYNC_Priority_Low);
}
}
////////////////////////////
//- rjf: good, or timeout? -> exit
//
if(!can_request || !is_stale || os_now_microseconds() >= endt_us)
{
break;
}
////////////////////////////
//- rjf: time to wait for new result? -> wait
//
if(did_request && !is_working)
{
break;
}
else if(did_request)
{
os_condition_variable_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
}
}
////////////////////////////
//- rjf: request if needed
//
if(can_request && node != 0 && !is_working && is_stale)
if(taken_node != 0)
{
if(ctrl_u2csb_enqueue_req(thread->handle, endt_us))
{
did_request = 1;
is_working = 1;
ins_atomic_u64_inc_eval(&node->working_count);
async_push_work(ctrl_call_stack_build_work, .priority = high_priority ? ASYNC_Priority_High : ASYNC_Priority_Low);
}
}
////////////////////////////
//- rjf: good, or timeout? -> exit
//
if(!can_request || !is_stale || os_now_microseconds() >= endt_us)
{
break;
}
////////////////////////////
//- rjf: time to wait for new result? -> wait
//
if(did_request && !is_working)
{
break;
}
else if(did_request)
{
os_condition_variable_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
ctrl_scope_touch_call_stack_node__stripe_r_guarded(scope, stripe, taken_node);
}
}
return call_stack;
@@ -3974,13 +3989,8 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
file_header_off + sizeof(COFF_FileHeader) + opt_ext_size);
//- rjf: read optional header
U16 optional_magic = 0;
U64 image_base = 0;
U64 entry_point = 0;
U32 data_dir_count = 0;
U64 virt_section_align = 0;
U64 file_section_align = 0;
Rng1U64 *data_dir_franges = 0;
if(opt_ext_size > 0)
{
// rjf: read magic number
@@ -3996,10 +4006,7 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
{
PE_OptionalHeader32 pe_optional = {0};
dmn_process_read_struct(process.dmn_handle, vaddr_range.min + opt_ext_off_range.min, &pe_optional);
image_base = pe_optional.image_base;
entry_point = pe_optional.entry_point_va;
virt_section_align = pe_optional.section_alignment;
file_section_align = pe_optional.file_alignment;
reported_data_dir_offset = sizeof(pe_optional);
reported_data_dir_count = pe_optional.data_dir_count;
}break;
@@ -4007,10 +4014,7 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
{
PE_OptionalHeader32Plus pe_optional = {0};
dmn_process_read_struct(process.dmn_handle, vaddr_range.min + opt_ext_off_range.min, &pe_optional);
image_base = pe_optional.image_base;
entry_point = pe_optional.entry_point_va;
virt_section_align = pe_optional.section_alignment;
file_section_align = pe_optional.file_alignment;
reported_data_dir_offset = sizeof(pe_optional);
reported_data_dir_count = pe_optional.data_dir_count;
}break;
@@ -4660,6 +4664,15 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
out_evt->entity_id = event->code;
out_evt->rgba = event->user_data;
}break;
case DMN_EventKind_SetVAddrRangeNote:
{
CTRL_Event *out_evt = ctrl_event_list_push(scratch.arena, &evts);
out_evt->kind = CTRL_EventKind_SetVAddrRangeNote;
out_evt->parent = ctrl_handle_make(CTRL_MachineID_Local, event->process);
out_evt->msg_id = msg->msg_id;
out_evt->vaddr_rng = r1u64(event->address, event->address + event->size);
out_evt->string = event->string;
}
case DMN_EventKind_SetBreakpoint:
{
CTRL_Event *out_evt = ctrl_event_list_push(scratch.arena, &evts);
@@ -6747,7 +6760,7 @@ ASYNC_WORK_DEF(ctrl_mem_stream_work)
{
if(hs_id_match(range_n->id, key.id))
{
if(!u128_match(u128_zero(), hash))
if(pre_read_mem_gen == post_read_mem_gen)
{
range_n->mem_gen = post_read_mem_gen;
}
@@ -6761,6 +6774,13 @@ ASYNC_WORK_DEF(ctrl_mem_stream_work)
//- rjf: broadcast changes
os_condition_variable_broadcast(process_stripe->cv);
if(!u128_match(u128_zero(), hash))
{
if(ctrl_state->wakeup_hook != 0)
{
ctrl_state->wakeup_hook();
}
}
ProfEnd();
ProfEnd();
return 0;
@@ -7004,6 +7024,10 @@ ASYNC_WORK_DEF(ctrl_call_stack_build_work)
//- rjf: broadcast update
os_condition_variable_broadcast(stripe->cv);
if(ctrl_state->wakeup_hook != 0)
{
ctrl_state->wakeup_hook();
}
}
scratch_end(scratch);
+2 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CTRL_CORE_H
@@ -424,6 +424,7 @@ typedef enum CTRL_EventKind
CTRL_EventKind_ThreadColor,
CTRL_EventKind_SetBreakpoint,
CTRL_EventKind_UnsetBreakpoint,
CTRL_EventKind_SetVAddrRangeNote,
//- rjf: memory
CTRL_EventKind_MemReserve,
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#undef LAYER_COLOR
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CTRL_INC_H
+5 -3
View File
@@ -1,10 +1,10 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
C_LINKAGE_BEGIN
String8 ctrl_entity_kind_code_name_table[11] =
String8 ctrl_entity_kind_code_name_table[12] =
{
{0},
str8_lit_comp("root"),
@@ -17,9 +17,10 @@ str8_lit_comp("debug_info_path"),
str8_lit_comp("pending_thread_name"),
str8_lit_comp("pending_thread_color"),
str8_lit_comp("breakpoint"),
str8_lit_comp("address_range_annotation"),
};
String8 ctrl_entity_kind_display_string_table[11] =
String8 ctrl_entity_kind_display_string_table[12] =
{
{0},
str8_lit_comp("Root"),
@@ -32,6 +33,7 @@ str8_lit_comp("DebugInfoPath"),
str8_lit_comp("PendingThreadName"),
str8_lit_comp("PendingThreadColor"),
str8_lit_comp("Breakpoint"),
str8_lit_comp("AddressRangeAnnotation"),
};
U32 ctrl_exception_code_kind_code_table[38] =
+4 -3
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
@@ -19,6 +19,7 @@ CTRL_EntityKind_DebugInfoPath,
CTRL_EntityKind_PendingThreadName,
CTRL_EntityKind_PendingThreadColor,
CTRL_EntityKind_Breakpoint,
CTRL_EntityKind_AddressRangeAnnotation,
CTRL_EntityKind_COUNT,
} CTRL_EntityKind;
@@ -66,8 +67,8 @@ CTRL_ExceptionCodeKind_COUNT,
} CTRL_ExceptionCodeKind;
C_LINKAGE_BEGIN
extern String8 ctrl_entity_kind_code_name_table[11];
extern String8 ctrl_entity_kind_display_string_table[11];
extern String8 ctrl_entity_kind_code_name_table[12];
extern String8 ctrl_entity_kind_display_string_table[12];
extern U32 ctrl_exception_code_kind_code_table[38];
extern String8 ctrl_exception_code_kind_display_string_table[38];
extern String8 ctrl_exception_code_kind_lowercase_code_string_table[38];
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#undef LAYER_COLOR
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DASM_CACHE_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
+11 -7
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#undef LAYER_COLOR
@@ -378,10 +378,12 @@ d_trap_net_from_thread__step_over_line(Arena *arena, CTRL_Entity *thread)
// rjf: line vaddr range => line's machine code
String8 machine_code = {0};
B32 good_machine_code = 0;
if(good_line_info)
{
CTRL_ProcessMemorySlice machine_code_slice = ctrl_process_memory_slice_from_vaddr_range(scratch.arena, process->handle, line_vaddr_rng, os_now_microseconds()+50000);
machine_code = machine_code_slice.data;
good_machine_code = (machine_code.size == dim_1u64(line_vaddr_rng) && !machine_code_slice.any_byte_bad);
LogInfoNamedBlockF("machine_code_slice")
{
log_infof("stale: %i\n", machine_code_slice.stale);
@@ -402,7 +404,7 @@ d_trap_net_from_thread__step_over_line(Arena *arena, CTRL_Entity *thread)
// rjf: machine code => ctrl flow analysis
DASM_CtrlFlowInfo ctrl_flow_info = {0};
if(good_line_info)
if(good_machine_code)
{
ctrl_flow_info = dasm_ctrl_flow_info_from_arch_vaddr_code(scratch.arena,
DASM_InstFlag_Call|
@@ -423,7 +425,7 @@ d_trap_net_from_thread__step_over_line(Arena *arena, CTRL_Entity *thread)
}
// rjf: push traps for all exit points
if(good_line_info) for(DASM_CtrlFlowPointNode *n = ctrl_flow_info.exit_points.first; n != 0; n = n->next)
if(good_machine_code) for(DASM_CtrlFlowPointNode *n = ctrl_flow_info.exit_points.first; n != 0; n = n->next)
{
DASM_CtrlFlowPoint *point = &n->v;
CTRL_TrapFlags flags = 0;
@@ -534,15 +536,17 @@ d_trap_net_from_thread__step_into_line(Arena *arena, CTRL_Entity *thread)
// rjf: line vaddr range => line's machine code
String8 machine_code = {0};
B32 good_machine_code = 0;
if(good_line_info)
{
CTRL_ProcessMemorySlice machine_code_slice = ctrl_process_memory_slice_from_vaddr_range(scratch.arena, process->handle, line_vaddr_rng, os_now_microseconds()+5000);
machine_code = machine_code_slice.data;
good_machine_code = (machine_code.size == dim_1u64(line_vaddr_rng) && !machine_code_slice.any_byte_bad);
}
// rjf: machine code => ctrl flow analysis
DASM_CtrlFlowInfo ctrl_flow_info = {0};
if(good_line_info)
if(good_machine_code)
{
ctrl_flow_info = dasm_ctrl_flow_info_from_arch_vaddr_code(scratch.arena,
DASM_InstFlag_Call|
@@ -557,7 +561,7 @@ d_trap_net_from_thread__step_into_line(Arena *arena, CTRL_Entity *thread)
// rjf: determine last
DASM_CtrlFlowPoint *last_call_point = 0;
if(good_line_info) for(DASM_CtrlFlowPointNode *n = ctrl_flow_info.exit_points.first; n != 0; n = n->next)
if(good_machine_code) for(DASM_CtrlFlowPointNode *n = ctrl_flow_info.exit_points.first; n != 0; n = n->next)
{
if(n->v.inst_flags & DASM_InstFlag_Call)
{
@@ -566,7 +570,7 @@ d_trap_net_from_thread__step_into_line(Arena *arena, CTRL_Entity *thread)
}
// rjf: push traps for all exit points
if(good_line_info) for(DASM_CtrlFlowPointNode *n = ctrl_flow_info.exit_points.first; n != 0; n = n->next)
if(good_machine_code) for(DASM_CtrlFlowPointNode *n = ctrl_flow_info.exit_points.first; n != 0; n = n->next)
{
DASM_CtrlFlowPoint *point = &n->v;
CTRL_TrapFlags flags = 0;
@@ -836,7 +840,7 @@ d_lines_array_from_dbgi_key_file_path_line_range(Arena *arena, DI_Key dbgi_key,
override_n = override_n->next)
{
String8 file_path = override_n->string;
String8 file_path_normalized = lower_from_str8(scratch.arena, file_path);
String8 file_path_normalized = lower_from_str8(scratch.arena, path_normalized_from_string(scratch.arena, file_path));
// rjf: binary -> rdi
RDI_Parsed *rdi = di_rdi_from_key(scope, &dbgi_key, 0);
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DBG_ENGINE_CORE_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "dbg_engine_core.c"
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DBG_ENGINE_INC_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
+4 -3
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#undef LAYER_COLOR
@@ -1026,15 +1026,16 @@ ASYNC_WORK_DEF(di_parse_work)
params.inherit_env = 1;
params.consoleless = 1;
str8_list_pushf(scratch.arena, &params.cmd_line, "raddbg");
str8_list_pushf(scratch.arena, &params.cmd_line, "--convert");
str8_list_pushf(scratch.arena, &params.cmd_line, "--bin");
str8_list_pushf(scratch.arena, &params.cmd_line, "--quiet");
if(should_compress)
{
str8_list_pushf(scratch.arena, &params.cmd_line, "--compress");
}
// str8_list_pushf(scratch.arena, &params.cmd_line, "--capture");
str8_list_pushf(scratch.arena, &params.cmd_line, "--pdb:%S", og_path);
str8_list_pushf(scratch.arena, &params.cmd_line, "--rdi");
str8_list_pushf(scratch.arena, &params.cmd_line, "--out:%S", rdi_path);
str8_list_pushf(scratch.arena, &params.cmd_line, "%S", og_path);
process = os_process_launch(&params);
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DBGI_H
+2 -8
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
@@ -158,31 +158,25 @@ dmn_rsp_from_thread(DMN_Handle thread)
}
////////////////////////////////
//~ Memory Helpers
//~ rjf: Process Reading Helper Functions (Helpers, Implemented Once)
internal String8
dmn_process_read_cstring(Arena *arena, DMN_Handle process, U64 addr)
{
Temp scratch = scratch_begin(&arena, 1);
String8List block_list = {0};
for(U64 cursor = addr, stride = 256; ; cursor += stride)
{
U8 *raw_block = push_array_no_zero(scratch.arena, U8, stride);
U64 read_size = dmn_process_read(process, r1u64(cursor, cursor + stride), raw_block);
String8 block = str8_cstring_capped(raw_block, raw_block + read_size);
str8_list_push(scratch.arena, &block_list, block);
if(read_size != stride || (block.size+1 <= read_size && block.str[block.size] == 0))
{
break;
}
}
String8 result = str8_list_join(arena, &block_list, 0);
scratch_end(scratch);
return result;
}
+6 -2
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_CORE_H
@@ -190,6 +190,11 @@ internal DMN_Event *dmn_event_list_push(Arena *arena, DMN_EventList *list);
internal U64 dmn_rip_from_thread(DMN_Handle thread);
internal U64 dmn_rsp_from_thread(DMN_Handle thread);
////////////////////////////////
//~ rjf: Process Reading Helper Functions (Helpers, Implemented Once)
internal String8 dmn_process_read_cstring(Arena *arena, DMN_Handle process, U64 addr);
////////////////////////////////
//~ rjf: @dmn_os_hooks Main Layer Initialization (Implemented Per-OS)
@@ -236,7 +241,6 @@ internal U64 dmn_process_read(DMN_Handle process, Rng1U64 range, void *dst);
internal B32 dmn_process_write(DMN_Handle process, Rng1U64 range, void *src);
#define dmn_process_read_struct(process, vaddr, ptr) dmn_process_read((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr)
#define dmn_process_write_struct(process, vaddr, ptr) dmn_process_write((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr)
internal String8 dmn_process_read_cstring(Arena *arena, DMN_Handle process, U64 addr);
//- rjf: threads
internal Arch dmn_arch_from_thread(DMN_Handle handle);
+1
View File
@@ -24,6 +24,7 @@ DMN_EventKindTable:
{SetThreadColor}
{SetBreakpoint}
{UnsetBreakpoint}
{SetVAddrRangeNote}
}
@table(name)
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "demon/demon_core.c"
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_INC_H
+3 -2
View File
@@ -1,10 +1,10 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
C_LINKAGE_BEGIN
String8 dmn_event_kind_string_table[20] =
String8 dmn_event_kind_string_table[21] =
{
str8_lit_comp("Null"),
str8_lit_comp("Error"),
@@ -26,6 +26,7 @@ str8_lit_comp("SetThreadName"),
str8_lit_comp("SetThreadColor"),
str8_lit_comp("SetBreakpoint"),
str8_lit_comp("UnsetBreakpoint"),
str8_lit_comp("SetVAddrRangeNote"),
};
String8 dmn_exception_kind_string_table[5] =
+3 -2
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
@@ -28,6 +28,7 @@ DMN_EventKind_SetThreadName,
DMN_EventKind_SetThreadColor,
DMN_EventKind_SetBreakpoint,
DMN_EventKind_UnsetBreakpoint,
DMN_EventKind_SetVAddrRangeNote,
DMN_EventKind_COUNT,
} DMN_EventKind;
@@ -61,7 +62,7 @@ DMN_ExceptionKind_COUNT,
} DMN_ExceptionKind;
C_LINKAGE_BEGIN
extern String8 dmn_event_kind_string_table[20];
extern String8 dmn_event_kind_string_table[21];
extern String8 dmn_exception_kind_string_table[5];
C_LINKAGE_END
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_CORE_LINUX_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
// TODO(allen): run controls: ignore_previous_exception
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_OS_LINUX_H
+16 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
@@ -2560,6 +2560,21 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls)
if(exec) { e->flags |= DMN_TrapFlag_BreakOnExecute; }
}break;
//- rjf: fill set-vaddr-range-note info
case DMN_W32_EXCEPTION_RADDBG_SET_VADDR_RANGE_NOTE:
{
U64 vaddr = exception->ExceptionInformation[0];
U64 size = exception->ExceptionInformation[1];
U64 name_vaddr = exception->ExceptionInformation[2];
U64 name_size = exception->ExceptionInformation[3];
U8 *name_buffer = push_array(arena, U8, name_size);
dmn_w32_process_read(process->handle, r1u64(name_vaddr, name_vaddr+name_size), name_buffer),
e->kind = DMN_EventKind_SetVAddrRangeNote;
e->address = vaddr;
e->size = size;
e->string = str8(name_buffer, name_size);
}break;
//- rjf: unhandled exception case
default:
{
+2 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_CORE_WIN32_H
@@ -58,6 +58,7 @@
#define DMN_w32_EXCEPTION_CLR 0xE0434352u
#define DMN_W32_EXCEPTION_RADDBG_SET_THREAD_COLOR 0x00524144u
#define DMN_W32_EXCEPTION_RADDBG_SET_BREAKPOINT 0x00524145u
#define DMN_W32_EXCEPTION_RADDBG_SET_VADDR_RANGE_NOTE 0x00524156u
////////////////////////////////
//~ rjf: Win32 Register Codes
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DRAW_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
@table(name, name_lower, type, default_init)
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
+90 -90
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal U64
@@ -49,10 +49,10 @@ internal U64
dw_reg_size_from_code(Arch arch, DW_Reg reg_code)
{
switch (arch) {
case Arch_Null: break;
case Arch_x86: return dw_reg_size_from_code_x86(reg_code);
case Arch_x64: return dw_reg_size_from_code_x64(reg_code);
default: NotImplemented; break;
case Arch_Null: break;
case Arch_x86: return dw_reg_size_from_code_x86(reg_code);
case Arch_x64: return dw_reg_size_from_code_x64(reg_code);
default: NotImplemented; break;
}
return 0;
}
@@ -61,10 +61,10 @@ internal U64
dw_reg_pos_from_code(Arch arch, DW_Reg reg_code)
{
switch (arch) {
case Arch_Null: break;
case Arch_x86: return dw_reg_pos_from_code_x86(reg_code);
case Arch_x64: return dw_reg_pos_from_code_x64(reg_code);
default: NotImplemented; break;
case Arch_Null: break;
case Arch_x86: return dw_reg_pos_from_code_x86(reg_code);
case Arch_x64: return dw_reg_pos_from_code_x64(reg_code);
default: NotImplemented; break;
}
return max_U64;
}
@@ -73,9 +73,9 @@ internal DW_AttribClass
dw_attrib_class_from_attrib_kind_v2(DW_AttribKind k)
{
switch (k) {
#define X(_N,_C) case DW_Attrib_##_N: return _C;
#define X(_N,_C) case DW_Attrib_##_N: return _C;
DW_AttribKind_ClassFlags_V2_XList(X)
#undef X
#undef X
}
return DW_AttribClass_Null;
}
@@ -84,9 +84,9 @@ internal DW_AttribClass
dw_attrib_class_from_attrib_kind_v3(DW_AttribKind k)
{
switch (k) {
#define X(_N,_C) case DW_Attrib_##_N: return _C;
#define X(_N,_C) case DW_Attrib_##_N: return _C;
DW_AttribKind_ClassFlags_V3_XList(X)
#undef X
#undef X
}
return DW_AttribClass_Null;
}
@@ -95,9 +95,9 @@ internal DW_AttribClass
dw_attrib_class_from_attrib_kind_v4(DW_AttribKind k)
{
switch (k) {
#define X(_N,_C) case DW_Attrib_##_N: return _C;
#define X(_N,_C) case DW_Attrib_##_N: return _C;
DW_AttribKind_ClassFlags_V4_XList(X)
#undef X
#undef X
}
return DW_AttribClass_Null;
}
@@ -106,9 +106,9 @@ internal DW_AttribClass
dw_attrib_class_from_attrib_kind_v5(DW_AttribKind k)
{
switch (k) {
#define X(_N,_C) case DW_Attrib_##_N: return _C;
#define X(_N,_C) case DW_Attrib_##_N: return _C;
DW_AttribKind_ClassFlags_V5_XList(X)
#undef X
#undef X
}
return DW_AttribClass_Null;
}
@@ -117,9 +117,9 @@ internal DW_AttribClass
dw_attrib_class_from_attrib_kind_gnu(DW_AttribKind k)
{
switch (k) {
#define X(_N,_C) case DW_Attrib_##_N: return _C;
#define X(_N,_C) case DW_Attrib_##_N: return _C;
DW_AttribKind_ClassFlags_GNU_XList(X)
#undef X
#undef X
}
return DW_AttribClass_Null;
}
@@ -128,9 +128,9 @@ internal DW_AttribClass
dw_attrib_class_from_attrib_kind_llvm(DW_AttribKind k)
{
switch (k) {
#define X(_N,_C) case DW_Attrib_##_N: return _C;
#define X(_N,_C) case DW_Attrib_##_N: return _C;
DW_AttribKind_ClassFlags_LLVM_XList(X)
#undef X
#undef X
}
return DW_AttribClass_Null;
}
@@ -139,9 +139,9 @@ internal DW_AttribClass
dw_attrib_class_from_attrib_kind_apple(DW_AttribKind k)
{
switch (k) {
#define X(_N,_C) case DW_Attrib_##_N: return _C;
#define X(_N,_C) case DW_Attrib_##_N: return _C;
DW_AttribKind_ClassFlags_APPLE_XList(X)
#undef X
#undef X
}
return DW_AttribClass_Null;
}
@@ -150,9 +150,9 @@ internal DW_AttribClass
dw_attrib_class_from_attrib_kind_mips(DW_AttribKind k)
{
switch (k) {
#define X(_N,_C) case DW_Attrib_##_N: return _C;
#define X(_N,_C) case DW_Attrib_##_N: return _C;
DW_AttribKind_ClassFlags_MIPS_XList(X)
#undef X
#undef X
}
return DW_AttribClass_Null;
}
@@ -161,7 +161,7 @@ internal DW_AttribClass
dw_attrib_class_from_attrib_kind(DW_Version ver, DW_Ext ext, DW_AttribKind k)
{
DW_AttribClass result = DW_AttribClass_Null;
while (ext) {
U64 z = 64-clz64(ext);
if (z == 0) {
@@ -169,7 +169,7 @@ dw_attrib_class_from_attrib_kind(DW_Version ver, DW_Ext ext, DW_AttribKind k)
}
U64 flag = 1 << (z-1);
ext &= ~flag;
switch (flag) {
case DW_Ext_Null: break;
case DW_Ext_GNU: result = dw_attrib_class_from_attrib_kind_gnu(k); break;
@@ -178,12 +178,12 @@ dw_attrib_class_from_attrib_kind(DW_Version ver, DW_Ext ext, DW_AttribKind k)
case DW_Ext_MIPS: result = dw_attrib_class_from_attrib_kind_mips(k); break;
default: InvalidPath; break;
}
if (result != DW_AttribClass_Null) {
break;
}
}
if (result == DW_AttribClass_Null) {
switch (ver) {
case DW_Version_Null: break;
@@ -195,19 +195,19 @@ dw_attrib_class_from_attrib_kind(DW_Version ver, DW_Ext ext, DW_AttribKind k)
default: InvalidPath; break;
}
}
return result;
}
internal DW_AttribClass
dw_attrib_class_from_form_kind(DW_Version ver, DW_FormKind k)
{
#define X(_N,_C) case DW_Form_##_N: return _C;
#define X(_N,_C) case DW_Form_##_N: return _C;
switch (k) {
DW_Form_AttribClass_GNU_XList(X)
}
switch (ver) {
case DW_Version_5: {
switch (k) {
@@ -233,8 +233,8 @@ dw_attrib_class_from_form_kind(DW_Version ver, DW_FormKind k)
} break;
case DW_Version_Null: break;
}
#undef X
#undef X
return DW_AttribClass_Null;
}
@@ -250,9 +250,9 @@ internal String8
dw_name_string_from_section_kind(DW_SectionKind k)
{
switch (k) {
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_L);
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_L);
DW_SectionKind_XList(X)
#undef X
#undef X
}
return str8_zero();
}
@@ -261,9 +261,9 @@ internal String8
dw_mach_name_string_from_section_kind(DW_SectionKind k)
{
switch (k) {
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_M);
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_M);
DW_SectionKind_XList(X)
#undef X
#undef X
}
return str8_zero();
}
@@ -272,9 +272,9 @@ internal String8
dw_dwo_name_string_from_section_kind(DW_SectionKind k)
{
switch (k) {
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_D);
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_D);
DW_SectionKind_XList(X)
#undef X
#undef X
}
return str8_zero();
}
@@ -301,10 +301,10 @@ dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKin
//
// This function's purpose is to find the overlapping class between an
// DW_AttribKind and DW_FormKind.
DW_AttribClass attrib_class = dw_attrib_class_from_attrib_kind(ver, ext, attrib_kind);
DW_AttribClass form_class = dw_attrib_class_from_form_kind(ver, form_kind);
if(relaxed)
{
if(attrib_class == DW_AttribClass_Null || form_class == DW_AttribClass_Null)
@@ -313,12 +313,12 @@ dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKin
form_class = dw_attrib_class_from_form_kind(DW_Version_Last, form_kind);
}
}
DW_AttribClass result = DW_AttribClass_Null;
if(attrib_class != DW_AttribClass_Null && form_class != DW_AttribClass_Null)
{
result = DW_AttribClass_Undefined;
for(U32 i = 0; i < 32; ++i)
{
U32 n = 1u << i;
@@ -329,7 +329,7 @@ dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKin
}
}
}
return result;
}
@@ -338,50 +338,50 @@ dw_pick_default_lower_bound(DW_Language lang)
{
U64 lower_bound = max_U64;
switch (lang) {
case DW_Language_Null: break;
case DW_Language_C89:
case DW_Language_C:
case DW_Language_CPlusPlus:
case DW_Language_C99:
case DW_Language_CPlusPlus03:
case DW_Language_CPlusPlus11:
case DW_Language_C11:
case DW_Language_CPlusPlus14:
case DW_Language_Java:
case DW_Language_ObjC:
case DW_Language_ObjCPlusPlus:
case DW_Language_UPC:
case DW_Language_D:
case DW_Language_Python:
case DW_Language_OpenCL:
case DW_Language_Go:
case DW_Language_Haskell:
case DW_Language_OCaml:
case DW_Language_Rust:
case DW_Language_Swift:
case DW_Language_Dylan:
case DW_Language_RenderScript:
case DW_Language_BLISS:
lower_bound = 0;
break;
case DW_Language_Ada83:
case DW_Language_Cobol74:
case DW_Language_Cobol85:
case DW_Language_Fortran77:
case DW_Language_Fortran90:
case DW_Language_Pascal83:
case DW_Language_Modula2:
case DW_Language_Ada95:
case DW_Language_Fortran95:
case DW_Language_PLI:
case DW_Language_Modula3:
case DW_Language_Julia:
case DW_Language_Fortran03:
case DW_Language_Fortran08:
lower_bound = 1;
default:
NotImplemented;
break;
case DW_Language_Null: break;
case DW_Language_C89:
case DW_Language_C:
case DW_Language_CPlusPlus:
case DW_Language_C99:
case DW_Language_CPlusPlus03:
case DW_Language_CPlusPlus11:
case DW_Language_C11:
case DW_Language_CPlusPlus14:
case DW_Language_Java:
case DW_Language_ObjC:
case DW_Language_ObjCPlusPlus:
case DW_Language_UPC:
case DW_Language_D:
case DW_Language_Python:
case DW_Language_OpenCL:
case DW_Language_Go:
case DW_Language_Haskell:
case DW_Language_OCaml:
case DW_Language_Rust:
case DW_Language_Swift:
case DW_Language_Dylan:
case DW_Language_RenderScript:
case DW_Language_BLISS:
lower_bound = 0;
break;
case DW_Language_Ada83:
case DW_Language_Cobol74:
case DW_Language_Cobol85:
case DW_Language_Fortran77:
case DW_Language_Fortran90:
case DW_Language_Pascal83:
case DW_Language_Modula2:
case DW_Language_Ada95:
case DW_Language_Fortran95:
case DW_Language_PLI:
case DW_Language_Modula3:
case DW_Language_Julia:
case DW_Language_Fortran03:
case DW_Language_Fortran08:
lower_bound = 1;
default:
NotImplemented;
break;
}
return lower_bound;
}
+1356 -1356
View File
File diff suppressed because it is too large Load Diff
+9 -9
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal B32
@@ -8,22 +8,22 @@ dw_is_dwarf_present_coff_section_table(String8 raw_image,
COFF_SectionHeader *section_table)
{
B32 is_dwarf_present = 0;
for (U64 i = 0; i < section_count; ++i) {
COFF_SectionHeader *header = &section_table[i];
String8 name = coff_name_from_section_header(string_table, header);
DW_SectionKind s = dw_section_kind_from_string(name);
if (s == DW_Section_Null) {
s = dw_section_dwo_kind_from_string(name);
}
is_dwarf_present = s != DW_Section_Null;
if (is_dwarf_present) {
break;
}
}
return is_dwarf_present;
}
@@ -36,19 +36,19 @@ dw_input_from_coff_section_table(Arena *arena,
{
DW_Input input = {0};
B32 sect_status[ArrayCount(input.sec)] = {0};
for (U64 i = 0; i < section_count; ++i) {
COFF_SectionHeader *header = &section_table[i];
Rng1U64 raw_data_range = rng_1u64(header->foff, header->foff + header->fsize);
String8 name = coff_name_from_section_header(string_table, header);
DW_SectionKind s = dw_section_kind_from_string(name);
B32 is_dwo = 0;
if (s == DW_Section_Null) {
s = dw_section_dwo_kind_from_string(name);
is_dwo = 1;
}
if (s != DW_Section_Null) {
if (sect_status[s]) {
Assert(!"too many debug sections with identical name, picking first");
@@ -61,7 +61,7 @@ dw_input_from_coff_section_table(Arena *arena,
}
}
}
return input;
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DWARF_COFF_H
+37 -34
View File
@@ -5,72 +5,75 @@ internal B32
dw_is_dwarf_present_elf_section_table(String8 raw_image, ELF_BinInfo *bin)
{
Temp scratch = scratch_begin(0,0);
B32 is_dwarf_present = 0;
ELF_Shdr64Array sections = elf_shdr64_array_from_bin(scratch.arena, raw_image, &bin->hdr);
for (U64 i = 0; i < sections.count; ++i) {
ELF_Shdr64 *shdr = &sections.v[i];
String8 name = elf_name_from_shdr64(raw_image, &bin->hdr, bin->sh_name_range, shdr);
if (shdr->sh_type != ELF_SectionCode_ProgBits) {
continue;
}
DW_SectionKind s = dw_section_kind_from_string(name);
if (s == DW_Section_Null) {
s = dw_section_dwo_kind_from_string(name);
}
is_dwarf_present = s != DW_Section_Null;
if (is_dwarf_present) {
break;
}
}
scratch_end(scratch);
return is_dwarf_present;
}
#define SINFL_IMPLEMENTATION
#include "third_party/sinfl/sinfl.h"
internal DW_Input
dw_input_from_elf_section_table(Arena *arena, String8 raw_image, ELF_BinInfo *bin)
{
Temp scratch = scratch_begin(&arena, 1);
DW_Input result = {0};
B32 sect_status[ArrayCount(result.sec)] = {0};
ELF_Shdr64Array sections = elf_shdr64_array_from_bin(scratch.arena, raw_image, &bin->hdr);
for (U64 sect_idx = 1; sect_idx < sections.count; ++sect_idx) {
ELF_Shdr64 *shdr = &sections.v[sect_idx];
// skip BSS sections
if (shdr->sh_type != ELF_SectionCode_ProgBits) {
continue;
}
String8 name = elf_name_from_shdr64(raw_image, &bin->hdr, bin->sh_name_range, shdr);
DW_SectionKind s = dw_section_kind_from_string(name);
B32 is_dwo = 0;
if (s == DW_Section_Null) {
s = dw_section_dwo_kind_from_string(name);
is_dwo = 1;
}
if (s != DW_Section_Null) {
if (sect_status[s]) {
Assert(!"too many debug sections with identical name, picking first");
} else {
Rng1U64 raw_data_range = rng_1u64(shdr->sh_offset, shdr->sh_offset + shdr->sh_size);
String8 data = str8_substr(raw_image, raw_data_range);
// ELF was compiled with compressed debug info
if (shdr->sh_flags & ELF_Shf_Compressed) {
String8 comp_data_with_header = data;
// read header
ELF_Chdr64 chdr64 = {0};
U64 chdr_size = 0;
@@ -86,38 +89,38 @@ dw_input_from_elf_section_table(Arena *arena, String8 raw_image, ELF_BinInfo *bi
chdr64 = elf_chdr64_from_chdr32(chdr32);
}
}
AssertAlways(IsPow2(chdr64.ch_addr_align));
// skip header
String8 comp_data = str8_skip(comp_data_with_header, chdr_size);
// push buffer for the decompressor
U8 *decomp_buffer = push_array_no_zero_aligned(arena, U8, chdr64.ch_size, chdr64.ch_addr_align);
U64 actual_decomp_size = 0;
// decompress
switch (chdr64.ch_type) {
case ELF_CompressType_None: {
AssertAlways(!"unexpected compression type");
} break;
case ELF_CompressType_ZLib: {
actual_decomp_size = zsinflate(decomp_buffer, chdr64.ch_size, comp_data.str, comp_data.size);
} break;
case ELF_CompressType_ZStd: {
// TODO: zstd lib
NotImplemented;
} break;
default: InvalidPath; break;
case ELF_CompressType_None: {
AssertAlways(!"unexpected compression type");
} break;
case ELF_CompressType_ZLib: {
actual_decomp_size = zsinflate(decomp_buffer, chdr64.ch_size, comp_data.str, comp_data.size);
} break;
case ELF_CompressType_ZStd: {
// TODO: zstd lib
NotImplemented;
} break;
default: InvalidPath; break;
}
// TODO: error handling
AssertAlways(actual_decomp_size == chdr64.ch_size);
// set decompressed section data
data = str8(decomp_buffer, actual_decomp_size);
}
sect_status[s] = 1;
DW_Section *d = &result.sec[s];
d->name = push_str8_copy(arena, name);
@@ -126,7 +129,7 @@ dw_input_from_elf_section_table(Arena *arena, String8 raw_image, ELF_BinInfo *bi
}
}
}
scratch_end(scratch);
return result;
}
+32 -32
View File
@@ -1,18 +1,18 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal String8
dw_string_from_expr_op(Arena *arena, DW_Version ver, DW_Ext ext, DW_ExprOp op)
{
String8 result = {0};
#define X(_N,...) case DW_ExprOp_##_N: result = str8_lit(Stringify(_N)); goto exit;
#define X(_N,...) case DW_ExprOp_##_N: result = str8_lit(Stringify(_N)); goto exit;
if (ext & DW_Ext_GNU) {
switch (op) {
DW_Expr_GNU_XList(X);
}
}
switch (ver) {
case DW_Version_5: {
switch (op) {
@@ -32,13 +32,13 @@ dw_string_from_expr_op(Arena *arena, DW_Version ver, DW_Ext ext, DW_ExprOp op)
case DW_Version_2:
case DW_Version_1:
case DW_Version_Null:
break;
break;
}
#undef X
#undef X
result = push_str8f(arena, "%x", op);
exit:;
exit:;
return result;
}
@@ -46,12 +46,12 @@ internal String8
dw_string_from_tag_kind(Arena *arena, DW_TagKind kind)
{
switch (kind) {
case DW_Tag_Null: return str8_lit("Null");
#define X(_N,_ID) case DW_Tag_##_N: return str8_lit(Stringify(_N));
case DW_Tag_Null: return str8_lit("Null");
#define X(_N,_ID) case DW_Tag_##_N: return str8_lit(Stringify(_N));
DW_Tag_V3_XList(X)
DW_Tag_V5_XList(X)
DW_Tag_GNU_XList(X)
#undef X
DW_Tag_V5_XList(X)
DW_Tag_GNU_XList(X)
#undef X
}
return push_str8f(arena, "%llx", kind);
}
@@ -59,8 +59,8 @@ dw_string_from_tag_kind(Arena *arena, DW_TagKind kind)
internal String8
dw_string_from_attrib_kind(Arena *arena, DW_Version ver, DW_Ext ext, DW_AttribKind kind)
{
#define X(_N,...) case DW_Attrib_##_N: return str8_lit(Stringify(_N));
#define X(_N,...) case DW_Attrib_##_N: return str8_lit(Stringify(_N));
while (ext) {
U64 z = 64-clz64(ext);
if (z == 0) {
@@ -68,7 +68,7 @@ dw_string_from_attrib_kind(Arena *arena, DW_Version ver, DW_Ext ext, DW_AttribKi
}
U64 flag = 1 << (z-1);
ext &= ~flag;
switch (flag) {
case DW_Ext_Null: break;
case DW_Ext_GNU: switch (kind) { DW_AttribKind_GNU_XList(X) } break;
@@ -78,7 +78,7 @@ dw_string_from_attrib_kind(Arena *arena, DW_Version ver, DW_Ext ext, DW_AttribKi
default: InvalidPath; break;
}
}
switch (ver) {
case DW_Version_5: {
switch (kind) {
@@ -104,15 +104,15 @@ dw_string_from_attrib_kind(Arena *arena, DW_Version ver, DW_Ext ext, DW_AttribKi
} // fall-through
case DW_Version_Null: break;
}
#undef X
#undef X
return str8_zero();
}
internal String8
dw_string_from_form_kind(Arena *arena, DW_Version ver, DW_FormKind kind)
{
#define X(_N,...) case DW_Form_##_N: return str8_lit(Stringify(_N));
#define X(_N,...) case DW_Form_##_N: return str8_lit(Stringify(_N));
switch (ver) {
case DW_Version_5: {
switch (kind) {
@@ -132,7 +132,7 @@ dw_string_from_form_kind(Arena *arena, DW_Version ver, DW_FormKind kind)
} // fall-through
case DW_Version_Null: break;
}
#undef X
#undef X
String8 result = push_str8f(arena, "%x", kind);
return result;
}
@@ -141,9 +141,9 @@ internal String8
dw_string_from_language(Arena *arena, DW_Language kind)
{
switch (kind) {
#define X(_N,_ID) case DW_Language_##_N: return str8_lit(Stringify(_N));
#define X(_N,_ID) case DW_Language_##_N: return str8_lit(Stringify(_N));
DW_Language_XList(X)
#undef X
#undef X
}
return push_str8f(arena, "%x", kind);
}
@@ -196,9 +196,9 @@ internal String8
dw_string_from_std_opcode(Arena *arena, DW_StdOpcode kind)
{
switch (kind) {
#define X(_N,_ID) case DW_StdOpcode_##_N: return str8_lit(Stringify(_N));
#define X(_N,_ID) case DW_StdOpcode_##_N: return str8_lit(Stringify(_N));
DW_StdOpcode_XList(X)
#undef X
#undef X
}
return push_str8f(arena, "%x", kind);
}
@@ -207,9 +207,9 @@ internal String8
dw_string_from_ext_opcode(Arena *arena, DW_ExtOpcode kind)
{
switch (kind) {
#define X(_N,_ID) case DW_ExtOpcode_##_N: return str8_lit(Stringify(_N));
#define X(_N,_ID) case DW_ExtOpcode_##_N: return str8_lit(Stringify(_N));
DW_ExtOpcode_XList(X)
#undef X
#undef X
default: InvalidPath; break;
}
return push_str8f(arena, "%x", kind);
@@ -244,16 +244,16 @@ dw_string_from_register(Arena *arena, Arch arch, U64 reg_id)
case Arch_Null: break;
case Arch_x86: {
switch (reg_id) {
#define X(_N, _ID, ...) case DW_RegX86_##_N: reg_str = str8_lit(Stringify(_N)); break;
#define X(_N, _ID, ...) case DW_RegX86_##_N: reg_str = str8_lit(Stringify(_N)); break;
DW_Regs_X86_XList(X)
#undef X
#undef X
}
} break;
case Arch_x64: {
switch (reg_id) {
#define X(_N, _ID, ...) case DW_RegX64_##_N: reg_str = str8_lit(Stringify(_N)); break;
#define X(_N, _ID, ...) case DW_RegX64_##_N: reg_str = str8_lit(Stringify(_N)); break;
DW_Regs_X64_XList(X)
#undef X
#undef X
}
} break;
case Arch_arm32: NotImplemented; break;
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DWARF_ENUM_H
+16 -16
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- analyzers
@@ -10,7 +10,7 @@ dw_expr__analyze_fast(void *base, Rng1U64 range, U64 text_section_base)
DW_SimpleLoc result = {DW_SimpleLocKind_Empty};
String8 expr_data = str8((U8*)data+range.min, (U8*)data+range.max);
U8 op = 0;
if (str8_deserial_read_struct(expr_data, 0, &op)) {
// step params
@@ -52,11 +52,11 @@ dw_expr__analyze_fast(void *base, Rng1U64 range, U64 text_section_base)
{
U64 x = 0;
step_cursor += dw_based_range_read(base, range, step_cursor, size_param, &x);
if (is_signed) {
x = extend_sign64(x, size_param);
}
result.kind = DW_SimpleLocKind_Address;
result.addr = x;
} break;
@@ -180,7 +180,7 @@ internal DW_ExprAnalysis
dw_expr__analyze_details(void *in_base, Rng1U64 in_range, DW_ExprMachineCallConfig *call_config)
{
Temp scratch = scratch_begin(0, 0);
DW_ExprAnalysis result = {0};
// are we resolving calls?
@@ -560,7 +560,7 @@ dw_expr__eval(Arena *arena_optional, void *expr_base, Rng1U64 expr_range, DW_Exp
{
#if 0
Temp scratch = scratch_begin(&arena_optional, 1);
DW_Location result = {0};
// setup stack
@@ -655,7 +655,7 @@ dw_expr__eval(Arena *arena_optional, void *expr_base, Rng1U64 expr_range, DW_Exp
{
U64 offset = 0;
step_cursor += dw_based_range_read(base, range, step_cursor, 8, &offset);
// earlier versions of GCC emit TLS offset with DW_ExprOp_Addr.
B32 is_text_relative;
{
@@ -663,9 +663,9 @@ dw_expr__eval(Arena *arena_optional, void *expr_base, Rng1U64 expr_range, DW_Exp
dw_based_range_read_struct(base, range, step_cursor, &next_op);
is_text_relative = (next_op != DW_ExprOp_GNU_PushTlsAddress);
}
U64 addr = offset;
if (is_text_relative) {
if (config->text_section_base != 0) {
addr += *config->text_section_base;
@@ -675,7 +675,7 @@ dw_expr__eval(Arena *arena_optional, void *expr_base, Rng1U64 expr_range, DW_Exp
goto finish;
}
}
dw_expr__stack_push(scratch.arena, &stack, addr);
} break;
@@ -748,7 +748,7 @@ dw_expr__eval(Arena *arena_optional, void *expr_base, Rng1U64 expr_range, DW_Exp
U64 reg_idx = 0; S64 offset = 0;
step_cursor += dw_based_range_read_uleb128(base, range, step_cursor, &reg_idx);
step_cursor += dw_based_range_read_sleb128(base, range, step_cursor, &offset);
DW_RegsX64 *regs = config->regs;
if (regs != 0) {
if (reg_idx < ArrayCount(regs->r)) {
@@ -816,7 +816,7 @@ dw_expr__eval(Arena *arena_optional, void *expr_base, Rng1U64 expr_range, DW_Exp
case DW_ExprOp_Deref:
{
U64 addr = dw_expr__stack_pop(&stack);
B32 read_success = 0;
if (config->read_memory) {
U64 x = 0;
@@ -825,7 +825,7 @@ dw_expr__eval(Arena *arena_optional, void *expr_base, Rng1U64 expr_range, DW_Exp
read_success = 1;
}
}
if (!read_success) {
stashed_loc.kind = DW_SimpleLocKind_Fail;
stashed_loc.fail_kind = DW_LocFailKind_MissingMemory;
@@ -838,10 +838,10 @@ dw_expr__eval(Arena *arena_optional, void *expr_base, Rng1U64 expr_range, DW_Exp
{
U64 raw_size = 0;
step_cursor += dw_based_range_read(base, range, step_cursor, 1, &raw_size);
U64 size = ClampTop(raw_size, 8);
U64 addr = dw_expr__stack_pop(&stack);
B32 read_success = 0;
if (config->read_memory) {
U64 x = 0;
@@ -883,7 +883,7 @@ dw_expr__eval(Arena *arena_optional, void *expr_base, Rng1U64 expr_range, DW_Exp
case DW_ExprOp_FormTlsAddress:
{
S64 s = (S64)dw_expr__stack_pop(&stack);
if (config->tls_address != 0) {
U64 x = *config->tls_address + s;
dw_expr__stack_push(scratch.arena, &stack, x);
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DWARF_EXPR_H
+872 -872
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DWARF_PARSE_H
+10 -10
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal U64 dw_based_range_read(void *base, Rng1U64 range, U64 off, U64 size, void *out) { return 0; }
@@ -25,9 +25,9 @@ dw_unwind_x64(String8 raw_text,
{
// TODO: What if ELF has two sections with instructions and pointer is ecnoded relative to .text2?
Temp scratch = scratch_begin(0, 0);
DW_UnwindResult result = {0};
dw_unwind_init_x64();
// rebase
@@ -46,7 +46,7 @@ dw_unwind_x64(String8 raw_text,
//- get frame info range
void *frame_base = raw_eh_frame.str;
Rng1U64 frame_range = rng_1u64(0, raw_eh_frame.size);
//- section vaddrs
U64 text_base_vaddr = text_vrange.min + rebase_voff_to_vaddr;
U64 frame_base_voff = text_vrange.min;
@@ -113,7 +113,7 @@ dw_unwind_x64(String8 raw_text,
result.is_invalid = 1;
}
}
// apply main row to modify the registers
if (main_row != 0) {
result = dw_unwind_x64__apply_frame_rules(raw_eh_frame, main_row, text_base_vaddr, read_memory, read_memory_ud, stack_pointer, regs);
@@ -133,7 +133,7 @@ dw_unwind_x64__apply_frame_rules(String8 raw_eh_frame,
DW_RegsX64 *regs)
{
DW_UnwindResult result = {0};
U64 missed_read_addr = 0;
//- setup a dwarf expression machine
@@ -375,7 +375,7 @@ dw_unwind_parse_pointer_x64(void *frame_base, Rng1U64 frame_range, DW_EhPtrCtx *
case DW_EhPtrEnc_SLEB128:
{
U64 size = dw_based_range_read_sleb128(frame_base, frame_range, pointer_off,
(S64*)&raw_pointer);
(S64*)&raw_pointer);
after_pointer_off = pointer_off + size;
} break;
}
@@ -588,7 +588,7 @@ internal DW_CFIRecords
dw_unwind_eh_frame_cfi_from_ip_slow_x64(String8 raw_eh_frame, DW_EhPtrCtx *ptr_ctx, U64 ip_voff)
{
Temp scratch = scratch_begin(0, 0);
DW_CFIRecords result = {0};
DW_CIEUnpackedNode *cie_first = 0;
@@ -622,7 +622,7 @@ dw_unwind_eh_frame_cfi_from_ip_slow_x64(String8 raw_eh_frame, DW_EhPtrCtx *ptr_c
Rng1U64 rec_range = rng_1u64(rec_off, rec_opl);
String8 raw_rec = str8_substr(raw_eh_frame, rec_range);
// discriminator
U64 discrim_off = after_rec_size_off;
U32 discrim = 0;
@@ -839,7 +839,7 @@ internal B32
dw_unwind_machine_run_to_ip_x64(void *base, Rng1U64 range, DW_CFIMachine *machine, U64 target_ip, DW_CFIRow *row)
{
Temp scratch = scratch_begin(0, 0);
B32 result = 0;
// pull out machine's equipment
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DWARF_UNWIND_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
@table(name)
+171 -59
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
@@ -189,6 +189,13 @@ e_space_make(E_SpaceKind kind)
return space;
}
internal B32
e_space_match(E_Space a, E_Space b)
{
B32 result = MemoryMatchStruct(&a, &b);
return result;
}
////////////////////////////////
//~ rjf: Map Functions
@@ -445,22 +452,61 @@ e_auto_hook_map_insert_new_(Arena *arena, E_AutoHookMap *map, E_AutoHookParams *
type_key = e_type_key_from_expr(parse.expr);
}
// rjf: get type pattern parts
String8List pattern_parts = {0};
// rjf: extract type pattern
E_Pattern pattern = {0};
if(e_type_key_match(e_type_key_zero(), type_key))
{
U8 pattern_split = '?';
pattern_parts = str8_split(arena, params->type_pattern, &pattern_split, 1, StringSplitFlag_KeepEmpties);
U64 start_string_off = 0;
for(U64 off = 0; off <= params->type_pattern.size; off += 1)
{
U8 byte = (off < params->type_pattern.size ? params->type_pattern.str[off] : 0);
if(byte == 0 || byte == '?')
{
String8 new_part = str8_substr(params->type_pattern, r1u64(start_string_off, off));
if(new_part.size != 0)
{
E_PatternPart *p = push_array(arena, E_PatternPart, 1);
SLLQueuePush(pattern.first_part, pattern.last_part, p);
p->string = new_part;
pattern.count += 1;
}
}
if(byte == '?')
{
E_PatternPart *p = push_array(arena, E_PatternPart, 1);
SLLQueuePush(pattern.first_part, pattern.last_part, p);
pattern.count += 1;
if(off+1 < params->type_pattern.size && params->type_pattern.str[off+1] == '{')
{
off += 2;
String8 wildcard_inst_names_string = str8_skip(params->type_pattern, off);
wildcard_inst_names_string = str8_prefix(wildcard_inst_names_string, str8_find_needle(wildcard_inst_names_string, 0, str8_lit("}"), 0));
if(wildcard_inst_names_string.size != 0)
{
Temp scratch = scratch_begin(&arena, 1);
U8 wildcard_inst_name_split_char = ',';
String8List wildcard_inst_names = str8_split(scratch.arena, wildcard_inst_names_string, &wildcard_inst_name_split_char, 1, 0);
for(String8Node *n = wildcard_inst_names.first; n != 0; n = n->next)
{
str8_list_push(arena, &p->wildcard_inst_names, str8_skip_chop_whitespace(n->string));
}
scratch_end(scratch);
off += wildcard_inst_names_string.size;
}
}
start_string_off = off+1;
}
}
}
// rjf: if the type key is nonzero, *or* we have type patterns, then insert
// into map accordingle
// into map accordingly
if(!e_type_key_match(e_type_key_zero(), type_key) ||
pattern_parts.node_count != 0)
pattern.count != 0)
{
E_AutoHookNode *node = push_array(arena, E_AutoHookNode, 1);
node->type_string = str8_skip_chop_whitespace(e_type_string_from_key(arena, type_key));
node->type_pattern_parts = pattern_parts;
node->type_pattern = pattern;
node->expr_string = push_str8_copy(arena, params->tag_expr_string);
if(!e_type_key_match(e_type_key_zero(), type_key))
{
@@ -1037,18 +1083,20 @@ e_value_eval_from_eval(E_Eval eval)
//- rjf: type key -> auto hooks
internal E_ExprList
e_auto_hook_exprs_from_type_key(Arena *arena, E_TypeKey type_key)
internal E_AutoHookMatchList
e_push_auto_hook_matches_from_type_key(Arena *arena, E_TypeKey type_key)
{
ProfBeginFunction();
E_ExprList exprs = {0};
E_AutoHookMatchList matches = {0};
if(e_ir_ctx != 0)
{
Temp scratch = scratch_begin(&arena, 1);
E_AutoHookMap *map = e_ir_ctx->auto_hook_map;
String8 type_string = str8_skip_chop_whitespace(e_type_string_from_key(scratch.arena, type_key));
////////////////////////////
//- rjf: gather exact-type-key-matches from the map
//
if(map != 0 && map->slots_count != 0)
{
U64 hash = e_hash_from_string(5381, type_string);
@@ -1057,44 +1105,132 @@ e_auto_hook_exprs_from_type_key(Arena *arena, E_TypeKey type_key)
{
if(str8_match(n->type_string, type_string, 0))
{
E_Expr *expr = e_parse_from_string(n->expr_string).expr;
e_expr_list_push(arena, &exprs, expr);
E_AutoHookMatch *match = push_array(arena, E_AutoHookMatch, 1);
SLLQueuePush(matches.first, matches.last, match);
match->expr = e_parse_from_string(n->expr_string).expr;
matches.count += 1;
}
}
}
////////////////////////////
//- rjf: gather fuzzy matches from all patterns in the map
//
if(map != 0 && map->first_pattern != 0)
{
for(E_AutoHookNode *auto_hook_node = map->first_pattern;
auto_hook_node != 0;
auto_hook_node = auto_hook_node->pattern_order_next)
{
////////////////////////
//- rjf: determine if this pattern fits this type's string; gather wildcard instances
//
E_AutoHookWildcardInst *first_wildcard_inst = 0;
E_AutoHookWildcardInst *last_wildcard_inst = 0;
B32 fits_this_type_string = 1;
U64 scan_pos = 0;
for(String8Node *n = auto_hook_node->type_pattern_parts.first; n != 0; n = n->next)
{
if(n->string.size == 0)
U64 scan_pos = 0;
for(E_PatternPart *part = auto_hook_node->type_pattern.first_part; part != 0 && fits_this_type_string; part = part->next)
{
continue;
String8 pattern_string = part->string;
//- rjf: skip whitespace
for(;scan_pos < type_string.size;)
{
if(char_is_space(type_string.str[scan_pos]))
{
scan_pos += 1;
}
else
{
break;
}
}
//- rjf: no pattern string -> wildcard. skip wildcard portion
if(pattern_string.size == 0)
{
String8 terminator_pattern_string = part->next ? part->next->string : str8_zero();
U64 brace_nest_depth = 0;
U64 paren_nest_depth = 0;
U64 angle_nest_depth = 0;
U64 brack_nest_depth = 0;
U64 start_inst_off = scan_pos;
String8Node *wildcard_inst_name_node = part->wildcard_inst_names.first;
for(B32 done = 0; !done && scan_pos < type_string.size; scan_pos += 1)
{
if(0){}
else if(type_string.str[scan_pos] == '{') { brace_nest_depth += 1; }
else if(type_string.str[scan_pos] == '(') { paren_nest_depth += 1; }
else if(type_string.str[scan_pos] == '<') { angle_nest_depth += 1; }
else if(type_string.str[scan_pos] == '[') { brack_nest_depth += 1; }
else if(type_string.str[scan_pos] == '}' && brace_nest_depth > 0) { brace_nest_depth -= 1; }
else if(type_string.str[scan_pos] == ')' && paren_nest_depth > 0) { paren_nest_depth -= 1; }
else if(type_string.str[scan_pos] == '>' && angle_nest_depth > 0) { angle_nest_depth -= 1; }
else if(type_string.str[scan_pos] == ']' && brack_nest_depth > 0) { brack_nest_depth -= 1; }
else if(part->next == 0)
{
done = 1;
scan_pos = type_string.size;
}
else if(str8_match(terminator_pattern_string, str8_skip(type_string, scan_pos), StringMatchFlag_RightSideSloppy))
{
done = 1;
}
if((type_string.str[scan_pos] == ',' || done) &&
brace_nest_depth == 0 &&
paren_nest_depth == 0 &&
angle_nest_depth == 0 &&
brack_nest_depth == 0)
{
String8 wildcard_inst_string = str8_skip_chop_whitespace(str8_substr(type_string, r1u64(start_inst_off, scan_pos)));
start_inst_off = scan_pos+1;
E_AutoHookWildcardInst *inst = push_array(arena, E_AutoHookWildcardInst, 1);
SLLQueuePush(first_wildcard_inst, last_wildcard_inst, inst);
inst->name = wildcard_inst_name_node ? wildcard_inst_name_node->string : str8_zero();
inst->inst_expr = e_parse_from_string(wildcard_inst_string).expr;
if(wildcard_inst_name_node)
{
wildcard_inst_name_node = wildcard_inst_name_node->next;
}
}
if(done)
{
break;
}
}
}
//- rjf: pattern string -> find next occurrence.
else if(pattern_string.size != 0)
{
if(!str8_match(str8_substr(type_string, r1u64(scan_pos, scan_pos+pattern_string.size)), pattern_string, 0))
{
fits_this_type_string = 0;
}
else
{
scan_pos += pattern_string.size;
}
}
}
U64 pattern_part_pos = str8_find_needle(type_string, scan_pos, n->string, 0);
if(pattern_part_pos > scan_pos && n == auto_hook_node->type_pattern_parts.first)
if(fits_this_type_string && scan_pos < type_string.size)
{
fits_this_type_string = 0;
break;
}
if(pattern_part_pos >= type_string.size)
{
fits_this_type_string = 0;
break;
}
scan_pos = pattern_part_pos + n->string.size;
}
////////////////////////
//- rjf: push match if this type fits
//
if(fits_this_type_string)
{
E_Expr *expr = e_parse_from_string(auto_hook_node->expr_string).expr;
e_expr_list_push(arena, &exprs, expr);
E_AutoHookMatch *match = push_array(arena, E_AutoHookMatch, 1);
SLLQueuePush(matches.first, matches.last, match);
match->expr = e_parse_from_string(auto_hook_node->expr_string).expr;
match->first_wildcard_inst = first_wildcard_inst;
match->last_wildcard_inst = last_wildcard_inst;
matches.count += 1;
}
}
}
@@ -1102,13 +1238,13 @@ e_auto_hook_exprs_from_type_key(Arena *arena, E_TypeKey type_key)
scratch_end(scratch);
}
ProfEnd();
return exprs;
return matches;
}
internal E_ExprList
e_auto_hook_exprs_from_type_key__cached(E_TypeKey type_key)
internal E_AutoHookMatchList
e_auto_hook_matches_from_type_key(E_TypeKey type_key)
{
E_ExprList exprs = {0};
E_AutoHookMatchList matches = {0};
{
U64 hash = e_hash_from_string(5381, str8_struct(&type_key));
U64 slot_idx = hash%e_cache->type_auto_hook_cache_map->slots_count;
@@ -1127,11 +1263,11 @@ e_auto_hook_exprs_from_type_key__cached(E_TypeKey type_key)
node = push_array(e_cache->arena, E_TypeAutoHookCacheNode, 1);
SLLQueuePush(e_cache->type_auto_hook_cache_map->slots[slot_idx].first, e_cache->type_auto_hook_cache_map->slots[slot_idx].last, node);
node->key = type_key;
node->exprs = e_auto_hook_exprs_from_type_key(e_cache->arena, type_key);
node->matches = e_push_auto_hook_matches_from_type_key(e_cache->arena, type_key);
}
exprs = node->exprs;
matches = node->matches;
}
return exprs;
return matches;
}
//- rjf: string IDs
@@ -1233,30 +1369,6 @@ e_range_size_from_eval(E_Eval eval)
E_TypeKind type_core_kind = e_type_kind_from_key(type_core);
B32 got_size = 0;
// rjf: try getting size from expansions
if(!got_size)
{
E_TypeKey maybe_lens_type_key = e_type_key_unwrap(eval.irtree.type_key, E_TypeUnwrapFlag_Meta);
E_TypeKind maybe_lens_type_kind = e_type_kind_from_key(maybe_lens_type_key);
if(maybe_lens_type_kind == E_TypeKind_Lens)
{
E_TypeExpandRule *expand_rule = e_expand_rule_from_type_key(maybe_lens_type_key);
if(expand_rule->info != 0)
{
Temp scratch = scratch_begin(0, 0);
U64 element_size = e_type_byte_size_from_key(e_type_key_unwrap(type_core, E_TypeUnwrapFlag_All));
E_TypeExpandInfo expand_info = expand_rule->info(scratch.arena, eval, str8_zero());
U64 new_result_maybe = expand_info.expr_count * element_size;
if(new_result_maybe != 0)
{
result = new_result_maybe;
got_size = 1;
}
scratch_end(scratch);
}
}
}
// rjf: try getting size from intrinsic type (e.g. arrays/etc.)
if(!got_size)
{
+49 -5
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef EVAL_CORE_H
@@ -663,13 +663,54 @@ struct E_String2TypeKeyMap
////////////////////////////////
//~ rjf: Type Pattern -> Hook Key Data Structure (Type Views)
typedef struct E_PatternPart E_PatternPart;
struct E_PatternPart
{
E_PatternPart *next;
String8 string;
String8List wildcard_inst_names;
};
typedef struct E_Pattern E_Pattern;
struct E_Pattern
{
E_PatternPart *first_part;
E_PatternPart *last_part;
U64 count;
};
typedef struct E_AutoHookWildcardInst E_AutoHookWildcardInst;
struct E_AutoHookWildcardInst
{
E_AutoHookWildcardInst *next;
String8 name;
E_Expr *inst_expr;
};
typedef struct E_AutoHookMatch E_AutoHookMatch;
struct E_AutoHookMatch
{
E_AutoHookMatch *next;
E_Expr *expr;
E_AutoHookWildcardInst *first_wildcard_inst;
E_AutoHookWildcardInst *last_wildcard_inst;
};
typedef struct E_AutoHookMatchList E_AutoHookMatchList;
struct E_AutoHookMatchList
{
E_AutoHookMatch *first;
E_AutoHookMatch *last;
U64 count;
};
typedef struct E_AutoHookNode E_AutoHookNode;
struct E_AutoHookNode
{
E_AutoHookNode *hash_next;
E_AutoHookNode *pattern_order_next;
String8 type_string;
String8List type_pattern_parts;
E_Pattern type_pattern;
String8 expr_string;
};
@@ -890,7 +931,7 @@ struct E_TypeAutoHookCacheNode
{
E_TypeAutoHookCacheNode *next;
E_TypeKey key;
E_ExprList exprs;
E_AutoHookMatchList matches;
};
typedef struct E_TypeAutoHookCacheSlot E_TypeAutoHookCacheSlot;
@@ -1042,6 +1083,8 @@ struct E_Cache
//- rjf: [ir] ir gen options
B32 disallow_autohooks;
B32 disallow_chained_fastpaths;
E_AutoHookWildcardInst *first_wildcard_inst;
E_AutoHookWildcardInst *last_wildcard_inst;
//- rjf: [ir] ir caches
E_UsedExprMap *used_expr_map;
@@ -1108,6 +1151,7 @@ internal E_MsgList e_msg_list_copy(Arena *arena, E_MsgList *src);
//~ rjf: Space Functions
internal E_Space e_space_make(E_SpaceKind kind);
internal B32 e_space_match(E_Space a, E_Space b);
////////////////////////////////
//~ rjf: Map Functions
@@ -1227,8 +1271,8 @@ internal E_Eval e_value_eval_from_eval(E_Eval eval);
#define e_value_from_expr(expr) e_value_eval_from_eval(e_eval_from_expr(expr)).value
//- rjf: type key -> auto hooks
internal E_ExprList e_auto_hook_exprs_from_type_key(Arena *arena, E_TypeKey type_key);
internal E_ExprList e_auto_hook_exprs_from_type_key__cached(E_TypeKey type_key);
internal E_AutoHookMatchList e_push_auto_hook_matches_from_type_key(Arena *arena, E_TypeKey type_key);
internal E_AutoHookMatchList e_auto_hook_matches_from_type_key(E_TypeKey type_key);
//- rjf: string IDs
internal U64 e_id_from_string(String8 string);
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "eval/eval_core.c"
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef EVAL_INC_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////

Some files were not shown because too many files have changed in this diff Show More