initial upload

This commit is contained in:
Ryan Fleury
2024-01-10 19:53:18 -08:00
commit a42ec6aeff
308 changed files with 162362 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
/build/
/local/
*~
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2024 Epic Games Tools
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+226
View File
@@ -0,0 +1,226 @@
# The RAD Debugger Project
---
## Development Setup Instructions
**Note: Currently, only x64 Windows development is supported.**
### 1. Installing the Required Tools (MSVC & Windows SDK)
In order to work with the codebase, you'll need the [Microsoft C/C++ Build Tools
v15 (2017) or later](https://aka.ms/vs/17/release/vs_BuildTools.exe), for both
the Windows SDK and the MSVC compiler and linker.
If the Windows SDK is installed (e.g. via installation of the Microsoft C/C++
Build Tools), you may also build with [Clang](https://releases.llvm.org/).
### 2. Build Environment Setup
Building the codebase can be done in a terminal which is equipped with the
ability to call either MSVC or Clang from command line.
This is generally done by calling `vcvarsall.bat x64`, which is included in the
Microsoft C/C++ Build Tools. This script is automatically called by the `x64
Native Tools Command Prompt for VS <year>` variant of the vanilla `cmd.exe`. If
you've installed the build tools, this command prompt may be easily located by
searching for `Native` from the Windows Start Menu search.
You can ensure that the MSVC compiler is accessible from your command line by
running:
```
cl
```
If everything is set up correctly, you should have output very similar to the
following:
```
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30151 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
```
### 3. Building
Within this terminal, `cd` to the root directory of the codebase, and just run
the `build.bat` script:
```
build
```
You should see the following output:
```
metagen_main.c
searching path/to/codebase/src... 591 files found
parsing metadesk... 25 metadesk files parsed
gathering tables... 37 tables found
generating layer code...
raddbg.cpp
```
If everything worked correctly, there will be a `build` folder in the root
level of the codebase, and it will contain a freshly-built `raddbg.exe`.
---
## Top-Level Directory Descriptions
- `data`: Small binary files which are used when building, either to embed
within build artifacts, or to package with them.
- `src`: All source code.
After setting up the codebase and building, the following directories will
also exist:
- `build`: All build artifacts. Not checked in to version control.
- `local`: Local files, used for local build configuration input files.
---
## Codebase Introduction
The codebase is organized into *layers*. Layers are separated either to isolate
certain problems, and to allow inclusion into various builds without needing to
pull everything in the codebase into a build. Layers correspond with folders
inside of the `src` directory. Sometimes, one folder inside of the `src`
directory will include multiple sub-layers, but the structure is intended to be
fairly flat.
Layers correspond roughly 1-to-1 with *namespaces*. The term "namespaces" in
this context does not refer to specific namespace language features, but rather
a naming convention for C-style namespaces, which are written in the codebase as
a short prefix, usually 1-3 characters, followed by an underscore. These
namespaces are used such that the layer to which certain code belongs may be
quickly understood by glancing at code. The namespaces are generally quite short
to ensure that they aren't much of a hassle to write. Sometimes, multiple sub-
layers will share a namespace. A few layers do not have a namespace, but most
do. Namespaces are either all-caps or lowercase depending on the context in
which they're used. For types, enum values, and some macros, they are
capitalized. For functions and global variables, they are lowercase.
Layers depend on other layers, but circular dependencies would break the
separability and isolation utility of layers (in effect, forming one big layer),
so in other words, layers are arranged into a directed acyclic graph.
A list of the layers in the codebase and their associated namespaces is below:
- `base` (no namespace): Universal, codebase-wide constructs. Strings, math,
memory allocators, helper macros, command-line parsing, and so on. Depends
on no other codebase layers.
- `coff` (`COFF_`): Code for parsing and/or writing the COFF (Common Object File
Format) file format.
- `ctrl` (`CTRL_`): The debugger's "control system" layer. Implements
asynchronous process control, stepping, and breakpoints for all attached
processes. Runs in lockstep with attached processes. When it runs, attached
processes are halted. When attached processes are running, it is halted.
Driven by a debugger frontend on another thread.
- `dasm` (`DASM_`): An asynchronous disassembly decoder and cache. Users ask for
disassembly for a particular virtual address range in a process, and threads
implemented in this layer decode and cache the disassembly for that range.
- `dbgi` (`DBGI_`): An asynchronous debug info loader and cache. Loads debug
info stored in the RADDBG format. Users ask for debug info for a particular
executable, and on separate threads, this layer loads the associated debug
info file. If necessary, it will launch a separate conversion process to
convert original debug info into the RADDBG format.
- `demon` (`DEMON_`): An abstraction layer for local-machine, low-level process
control. The abstraction is used to provide a common interface for process
control on target platforms. Used to implement part of `ctrl`.
- `df/core` (`DF_`): The debugger's non-graphical frontend. Implements a
debugger "entity cache" (where "entities" include processes, threads, modules,
breakpoints, source files, targets, and so on). Implements a command loop
for driving process control, which is used to implement stepping commands and
user breakpoints. Implements extractors and caches for various entity-related
data, like full thread unwinds and local variable maps. Also implements core
building blocks for evaluation and evaluation visualization.
- `df/gfx` (`DF_`): The debugger's graphical frontend. Builds on top of
`df/core` to provide all graphical features, including windows, panels, all
of the various debugger interfaces, and evaluation visualization.
- `draw` (`D_`): Implements a high-level graphics drawing API for the debugger's
purposes, using the underlying `render` abstraction layer. Provides high-level
APIs for various draw commands, but takes care of batching them, and so on.
- `eval` (`EVAL_`): Implements a compiler for an expression language built for
evaluation of variables, registers, and so on from debugger-attached processes
and/or debug info. Broken into several phases mostly corresponding to
traditional compiler phases - lexer, parser, type-checker, IR generation, and
IR evaluation.
- `font_cache` (`F_`): Implements a cache of rasterized font data, both in CPU-
side data for text shaping, and in GPU texture atlases for rasterized glyphs.
All cache information is sourced from the `font_provider` abstraction layer.
- `font_provider` (`FP_`): An abstraction layer for various font file decoding
and font rasterization backends.
- `geo_cache` (`GEO_`): Implements an asynchronously-filled cache for GPU
geometry data, filled by data sourced in the `hash_store` layer's cache. Used
for asynchronously preparing data for memory visualization in the debugger.
- `hash_store` (`HS_`): Implements a cache for general data blobs, keyed by a
128-bit hash of the data. Used as a general data store by other layers.
- `metagen` (`MG_`): A metaprogram which is used to generate primarily code and
data tables. Consumes Metadesk files, stored with the extension `.mc`, and
generates C code which is then included by hand-written C code. Currently, it
does not analyze the codebase's hand-written C code, but in principle this is
possible. This allows easier & less-error-prone management of large data
tables, which are then used to produce e.g. C `enum`s and a number of
associated data tables. There are also a number of other generation features,
like embedding binary files or complex multi-line strings into source code.
This layer cannot depend on any other layer in the codebase directly,
including `base`, because it may be used to generate code for those layers. To
still use `base` and `os` layer features in the `metagen` program, a separate,
duplicate version of `base` and `os` are included in this layer. They are
updated manually, as needed. This is to ensure the stability of the
metaprogram.
- `mule` (no namespace): Test executables for battle testing debugger
functionality.
- `natvis` (no namespace): NatVis files for type visualization of the codebase's
types in other debuggers.
- `os/core` (`OS_`): An abstraction layer providing core, non-graphical
functionality from the operating system under an abstract API, which is
implemented per-target-operating-system.
- `os/gfx` (`OS_`): An abstraction layer, building on `os/core`, providing
graphical operating system features under an abstract API, which is
implemented per-target-operating-system.
- `os/socket` (`OS_`): An abstraction layer, building on `os/core`, providing
networking operating system features under an abstract API, which is
implemented per-target-operating-system.
- `pe` (`PE_`): Code for parsing and/or writing the PE (Portable Executable)
file format.
- `raddbg` (no namespace): The layer which ties everything together for the main
graphical debugger. Not much "meat", just drives `df`, implements command line
options, and so on.
- `raddbg_cons` (`CONS_`): Implements an API for constructing files of the
RADDBG debug info file format.
- `raddbg_dump` (`DUMP_`): A dumper utility program for dumping textualizations
of RADDBG debug info files.
- `raddbg_format` (`RADDBG_`): Standalone types and helper functions for the
RADDBG debug info file format. Does not depend on `base`.
- `raddbg_markup` (`RADDBG_`): Standalone header file for marking up user
programs to work with various features in the `raddbg` debugger. Does not
depend on `base`.
- `regs` (`REGS_`): Types, helper functions, and metadata for registers on
supported architectures. Used in reading/writing registers in `demon`, or in
looking up register metadata.
- `render` (`R_`): An abstraction layer providing an abstract API for rendering
using various GPU APIs under a common interface. Does not implement a high
level drawing API - this layer is strictly for minimally abstracting on an
as-needed basis. Higher level drawing features are implemented in the `draw`
layer.
- `scratch` (no namespace): Scratch space for small and transient test or sample
programs.
- `texture_cache` (`TEX_`): Implements an asynchronously-filled cache for GPU
texture data, filled by data sourced in the `hash_store` layer's cache. Used
for asynchronously preparing data for memory visualization in the debugger.
- `txti` (`TXTI_`): Machinery for asynchronously-loaded, asynchronously hot-
reloaded, asynchronously parsed, and asynchronously mutated source code files.
Used by the debugger to visualize source code files. Users ask for text lines,
tokens, and metadata, and it is prepared on background threads.
- `type_graph` (`TG_`): Code for analyzing and navigating type structures from
RADDBG debug info files, with the additional capability of constructing
synthetic types *not* found in debug info. Used in `eval` and for various
visualization features.
- `ui` (`UI_`): Machinery for building graphical user interfaces. Provides a
core immediate mode hierarchical user interface data structure building
API, and has helper layers for building some higher-level widgets.
- `unwind` (`UNW_`): Code for generating unwind information from threads, for
supported operating systems and architectures.
+105
View File
@@ -0,0 +1,105 @@
@echo off
setlocal
cd /D "%~dp0"
:: --- Usage Notes (2024/1/10) ------------------------------------------------
::
:: This is a central build script for the RAD Debugger project. It takes a list
:: of simple alphanumeric-only arguments which control (a) what is built, (b)
:: which compiler & linker are used, and (c) extra high-level build options. By
:: default, if no options are passed, then the main "raddbg" graphical debugger
:: is built.
::
:: Below is a non-exhaustive list of possible ways to use the script:
:: `build raddbg`
:: `build raddbg clang`
:: `build raddbg release`
:: `build raddbg asan telemetry`
:: `build raddbg_from_pdb`
::
:: For a full list of possible build targets and their build command lines,
:: search for @build_targets in this file.
::
:: Below is a list of all possible non-target command line options:
::
:: - `asan`: enable address sanitizer
:: - `telemetry`: enable RAD telemetry profiling support
:: --- Unpack Arguments -------------------------------------------------------
for %%a in (%*) do set "%%a=1"
if not "%msvc%"=="1" if not "%clang%"=="1" set msvc=1
if not "%release%"=="1" set debug=1
if "%debug%"=="1" set release=0 && echo [debug mode]
if "%release%"=="1" set debug=0 && echo [release mode]
if "%msvc%"=="1" set clang=0 && echo [msvc compile]
if "%clang%"=="1" set msvc=0 && echo [clang compile]
if "%~1"=="" echo [default mode, assuming `raddbg` build] && set raddbg=1
:: --- 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 "%asan%"=="1" set auto_compile_flags=%auto_compile_flags% -fsanitize=address && echo [asan enabled]
:: --- Compile/Link Line Definitions ------------------------------------------
set cl_common= /I..\src\ /I..\local\ /nologo /FC /Z7 /MP
set clang_common= -I..\src\ -I..\local\ -maes -mssse3 -msse4 -gcodeview -fdiagnostics-absolute-paths -Wall -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 -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf
set cl_debug= cl /Od /D_DEBUG %cl_common%
set cl_release= cl /O2 /DNDEBUG %cl_common%
set clang_debug= clang -g -O0 /D_DEBUG %clang_common%
set clang_release= clang -g -O3 /DNDEBUG %clang_common%
set cl_link= /link /natvis:%~dp0\src\natvis\base.natvis
set clang_link= -Xlinker /natvis:%~dp0\src\natvis\base.natvis
set cl_out= /out:
set clang_out= -o
:: --- Per-Build Settings -----------------------------------------------------
set gfx=-DOS_FEATURE_GRAPHICAL=1
set net=-DOS_FEATURE_SOCKET=1
set link_dll=-DLL
:: --- Choose Compile/Link Lines ----------------------------------------------
if "%msvc%"=="1" set compile_debug=%cl_debug%
if "%msvc%"=="1" set compile_release=%cl_release%
if "%msvc%"=="1" set compile_link=%cl_link%
if "%msvc%"=="1" set out=%cl_out%
if "%clang%"=="1" set compile_debug=%clang_debug%
if "%clang%"=="1" set compile_release=%clang_release%
if "%clang%"=="1" set compile_link=%clang_link%
if "%clang%"=="1" set out=%clang_out%
if "%debug%"=="1" set compile=%compile_debug%
if "%release%"=="1" set compile=%compile_release%
set compile=%compile% %auto_compile_flags%
:: --- Prep Directories -------------------------------------------------------
if not exist build mkdir build
if not exist local mkdir local
:: --- Build & Run Metaprogram ------------------------------------------------
if "%no_meta%"=="1" echo [skipping metagen]
if not "%no_meta%"=="1" (
pushd build
%compile_debug% ..\src\metagen\metagen_main.c %compile_link% %out%metagen.exe
metagen.exe
popd
)
:: --- Build Everything (@build_targets) --------------------------------------
pushd build
if "%raddbg%"=="1" %compile% %gfx% ..\src\raddbg\raddbg.cpp %compile_link% %out%raddbg.exe
if "%raddbg_from_pdb%"=="1" %compile% ..\src\raddbg_convert\pdb\raddbg_from_pdb_main.c %compile_link% %out%raddbg_from_pdb.exe
if "%raddbg_from_dwarf%"=="1" %compile% ..\src\raddbg_convert\dwarf\raddbg_from_dwarf.c %compile_link% %out%raddbg_from_dwarf.exe
if "%raddbg_dump%"=="1" %compile% ..\src\raddbg_dump\raddbg_dump.c %compile_link% %out%raddbg_dump.exe
if "%ryan_scratch%"=="1" %compile% ..\src\scratch\ryan_scratch.c %compile_link% %out%ryan_scratch.exe
if "%look_at_raddbg%"=="1" %compile% ..\src\scratch\look_at_raddbg.c %compile_link% %out%look_at_raddbg.exe
if "%mule_main%"=="1" del vc*.pdb mule*.pdb && %cl_release% /c ..\src\mule\mule_inline.cpp && %cl_release% /c ..\src\mule\mule_o2.cpp && %cl_debug% /EHsc ..\src\mule\mule_main.cpp mule\mule_c.c mule_inline.obj mule_o2.obj
if "%mule_module%"=="1" %compile% ..\src\mule\mule_module.cpp %compile_link% %link_dll% %out%mule_module.dll
popd
:: --- Unset ------------------------------------------------------------------
for %%a in (%*) do set "%%a=0"
set raddbg=
set compile=
set compile_link=
set out=
set msvc=
set debug=
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
+118
View File
@@ -0,0 +1,118 @@
version(2);
project_name = "The RAD Debugger";
indent_width = "2";
default_tab_width = "2";
patterns =
{
"*.c",
"*.cpp",
"*.h",
"*.inc",
"*.hpp",
"*.bat",
"*.sh",
"*.4coder",
"*.glsl",
"*.bfs",
"*.html",
"*.txt",
"*.ds",
"*.md",
"*.mc",
"*.asm",
};
blacklist_patterns =
{
".*",
"metagen_base_*",
"metagen_os_*",
};
paths =
{
{ .path = ".", .recursive = false, .relative = true, },
{ .path = "src", .recursive = true , .relative = true, },
{ .path = "local", .recursive = true , .relative = true, },
};
load_paths =
{
.win = paths,
.linux = paths,
};
commands =
{
.rjf_f1 =
{
.win = "build raddbg telemetry",
.linux = "",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = false,
},
.rjf_f3 =
{
.win = "pushd build && raddbg.exe && popd",
.linux = "",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = false,
},
.build_raddbg =
{
.win = "build raddbg",
.linux = "",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = false,
},
.build_raddbg_from_pdb =
{
.win = "build raddbg_from_pdb",
.linux = "",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = false,
},
.build_mule_main =
{
.win = "build mule_main",
.linux = "",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = false,
},
.run_raddbg =
{
.win = "pushd build && raddbg.exe && popd",
.linux = "",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = false,
},
};
fkey_command =
{
.F1 = "build_raddbg",
.F3 = "run_raddbg",
};
fkey_command_override =
{
.rjf =
{
.F1 = "rjf_f1",
.F3 = "rjf_f3",
},
};
+316
View File
@@ -0,0 +1,316 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
// Implementation
internal Arena *
arena_alloc__sized(U64 init_res, U64 init_cmt)
{
ProfBeginFunction();
Assert(ARENA_HEADER_SIZE < init_cmt && init_cmt <= init_res);
void *memory;
U64 res;
U64 cmt;
B32 large_pages = os_large_pages_enabled();
if (large_pages) {
U64 page_size = os_large_page_size();
res = AlignPow2(init_res, page_size);
#if OS_WINDOWS
cmt = res;
#else
cmt AlignPow2(init_cmt, page_size);
#endif
memory = os_reserve_large(res);
if (!os_commit_large(memory, cmt)) {
memory = 0;
os_release(memory, res);
}
} else {
U64 page_size = os_page_size();
res = AlignPow2(init_res, page_size);
cmt = AlignPow2(init_cmt, page_size);
memory = os_reserve(res);
if (!os_commit(memory, cmt)) {
memory = 0;
os_release(memory, res);
}
}
Assert(memory);
AsanPoisonMemoryRegion(memory, cmt);
AsanUnpoisonMemoryRegion(memory, ARENA_HEADER_SIZE);
Arena *arena = (Arena*)memory;
if (arena) {
arena->prev = 0;
arena->current = arena;
arena->base_pos = 0;
arena->pos = ARENA_HEADER_SIZE;
arena->cmt = cmt;
arena->res = res;
arena->align = 8;
#if ENABLE_DEV
arena->dev = 0;
#endif
arena->grow = 1;
arena->large_pages = large_pages;
}
ProfEnd();
return arena;
}
internal Arena *
arena_alloc(void)
{
ProfBeginFunction();
U64 init_res, init_cmt;
if (os_large_pages_enabled()) {
init_res = ARENA_RESERVE_SIZE_LARGE_PAGES;
init_cmt = ARENA_COMMIT_SIZE_LARGE_PAGES;
} else {
init_res = ARENA_RESERVE_SIZE;
init_cmt = ARENA_COMMIT_SIZE;
}
Arena *arena = arena_alloc__sized(init_res, init_cmt);
ProfEnd();
return arena;
}
internal void
arena_release(Arena *arena)
{
for (Arena *node = arena->current, *prev = 0; node != 0; node = prev) {
prev = node->prev;
os_release(node, node->res);
}
}
internal U64
arena_huge_push_threshold(void)
{
U64 reserve_size = os_large_pages_enabled() ? ARENA_RESERVE_SIZE_LARGE_PAGES : ARENA_RESERVE_SIZE;
U64 threshold = (reserve_size - ARENA_HEADER_SIZE) / 2 + 1;
return threshold;
}
internal void *
arena_push__impl(Arena *arena, U64 size)
{
Arena *current = arena->current;
U64 pos_mem = AlignPow2(current->pos, arena->align);
U64 pos_new = pos_mem + size;
if (current->res < pos_new && arena->grow) {
Arena *new_block;
// normal growth path
if (size < arena_huge_push_threshold()) {
new_block = arena_alloc();
}
// huge growth path
else {
U64 new_block_size = size + ARENA_HEADER_SIZE;
new_block = arena_alloc__sized(new_block_size, new_block_size);
}
if (new_block) {
new_block->base_pos = current->base_pos + current->res;
SLLStackPush_N(arena->current, new_block, prev);
current = new_block;
pos_mem = AlignPow2(current->pos, current->align);
pos_new = pos_mem + size;
}
}
if (current->cmt < pos_new) {
U64 cmt_new_aligned, cmt_new_clamped, cmt_new_size;
B32 is_cmt_ok;
if (current->large_pages) {
cmt_new_aligned = AlignPow2(pos_new, ARENA_COMMIT_SIZE_LARGE_PAGES);
cmt_new_clamped = ClampTop(cmt_new_aligned, current->res);
cmt_new_size = cmt_new_clamped - current->cmt;
is_cmt_ok = os_commit_large((U8*)current + current->cmt, cmt_new_size);
} else {
cmt_new_aligned = AlignPow2(pos_new, ARENA_COMMIT_SIZE);
cmt_new_clamped = ClampTop(cmt_new_aligned, current->res);
cmt_new_size = cmt_new_clamped - current->cmt;
is_cmt_ok = os_commit((U8*)current + current->cmt, cmt_new_size);
}
Assert(is_cmt_ok);
if (is_cmt_ok) {
current->cmt = cmt_new_clamped;
}
}
void *memory = 0;
if (current->cmt >= pos_new) {
memory = (U8*)current + pos_mem;
current->pos = pos_new;
AsanUnpoisonMemoryRegion(memory, size);
}
#if OS_FEATURE_GRAPHICAL
if(Unlikely(memory == 0))
{
os_graphical_message(1, str8_lit("Fatal Allocation Failure"), str8_lit("Unexpected memory allocation failure."));
os_exit_process(1);
}
#endif
return memory;
}
internal U64
arena_pos(Arena *arena)
{
Arena *current = arena->current;
U64 pos = current->base_pos + current->pos;
return pos;
}
internal void
arena_pop_to(Arena *arena, U64 big_pos_unclamped)
{
U64 big_pos = ClampBot(ARENA_HEADER_SIZE, big_pos_unclamped);
// unroll the chain
Arena *current = arena->current;
for (Arena *prev = 0; current->base_pos >= big_pos; current = prev) {
prev = current->prev;
os_release(current, current->res);
}
AssertAlways(current);
arena->current = current;
// compute arena-relative position
U64 new_pos = big_pos - current->base_pos;
AssertAlways(new_pos <= current->pos);
// poison popped memory block
AsanPoisonMemoryRegion((U8*)current + new_pos, (current->pos - new_pos));
// update position
current->pos = new_pos;
}
internal void
arena_absorb(Arena *arena, Arena *sub)
{
#if ENABLE_DEV
arena_annotate_absorb__dev(arena, sub);
#endif
// base adjustment
Arena *current = arena->current;
U64 base_adjust = current->base_pos + current->res;
for (Arena *node = sub->current; node != 0; node = node->prev) {
node->base_pos += base_adjust;
}
// attach sub to arena
sub->prev = arena->current;
arena->current = sub->current;
sub->current = sub;
}
////////////////////////////////
// Wrappers
internal void *
arena_push(Arena *arena, U64 size)
{
void *memory = arena_push__impl(arena, size);
#if ENABLE_DEV
arena_annotate_push__dev(arena, size, memory);
#endif
return memory;
}
internal void *
arena_push_contiguous(Arena *arena, U64 size)
{
B32 restore = arena->grow;
arena->grow = 0;
void *memory = arena_push(arena, size);
arena->grow = restore;
#if ENABLE_DEV
arena_annotate_push__dev(arena, size, memory);
#endif
return memory;
}
internal void
arena_push_align(Arena *arena, U64 align)
{
Assert(IsPow2(align));
U64 amt = AlignPadPow2(arena->pos, align);
void *ptr = arena_push(arena, amt);
MemoryZero(ptr, amt);
}
internal void
arena_put_back(Arena *arena, U64 amt)
{
U64 pos_old = arena_pos(arena);
U64 pos_new = pos_old;
if (amt < pos_old) {
pos_new = pos_old - amt;
}
arena_pop_to(arena, pos_new);
}
internal void
arena_clear(Arena *arena)
{
arena_pop_to(arena, 0);
}
internal Temp
temp_begin(Arena *arena)
{
U64 pos = arena_pos(arena);
Temp temp = {arena, pos};
return temp;
}
internal void
temp_end(Temp temp)
{
arena_pop_to(temp.arena, temp.pos);
}
////////////////////////////////
//~ NOTE(allen): "Mini-Arena" Helper
internal B32
ensure_commit(void **cmtptr, void *pos, U64 cmt_block_size){
B32 result = 0;
U8 *cmt = (U8*)*cmtptr;
if (cmt < (U8*)pos){
U64 cmt_size_raw = (U8*)pos - cmt;
U64 cmt_size = AlignPow2(cmt_size_raw, cmt_block_size);
if (os_commit(cmt, cmt_size)){
*cmtptr = cmt + cmt_size;
result = 1;
}
}
else{
result = 1;
}
return(result);
}
+94
View File
@@ -0,0 +1,94 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_ARENA_H
#define BASE_ARENA_H
////////////////////////////////
//~ rjf: Constants
#define ARENA_HEADER_SIZE 128
#ifndef ARENA_RESERVE_SIZE
# define ARENA_RESERVE_SIZE MB(64)
#endif
#ifndef ARENA_COMMIT_SIZE
# define ARENA_COMMIT_SIZE KB(64)
#endif
#ifndef ARENA_RESERVE_SIZE_LARGE_PAGES
# define ARENA_RESERVE_SIZE_LARGE_PAGES MB(8)
#endif
#ifndef ARENA_COMMIT_SIZE_LARGE_PAGES
# define ARENA_COMMIT_SIZE_LARGE_PAGES MB(2)
#endif
////////////////////////////////
//~ rjf: Arena Types
typedef struct Arena Arena;
struct Arena
{
struct Arena *prev;
struct Arena *current;
U64 base_pos;
U64 pos;
U64 cmt;
U64 res;
U64 align;
struct ArenaDev *dev;
B8 grow;
B8 large_pages;
};
typedef struct Temp Temp;
struct Temp
{
Arena *arena;
U64 pos;
};
////////////////////////////////
// Implementation
internal Arena* arena_alloc__sized(U64 init_res, U64 init_cmt);
internal Arena* arena_alloc(void);
internal void arena_release(Arena *arena);
internal void* arena_push__impl(Arena *arena, U64 size);
internal U64 arena_pos(Arena *arena);
internal void arena_pop_to(Arena *arena, U64 pos);
internal void arena_absorb(Arena *arena, Arena *sub);
////////////////////////////////
// Wrappers
internal void* arena_push(Arena *arena, U64 size);
internal void* arena_push_contiguous(Arena *arena, U64 size);
internal void arena_clear(Arena *arena);
internal void arena_push_align(Arena *arena, U64 align);
internal void arena_put_back(Arena *arena, U64 amt);
internal Temp temp_begin(Arena *arena);
internal void temp_end(Temp temp);
////////////////////////////////
//~ NOTE(allen): "Mini-Arena" Helper
internal B32 ensure_commit(void **cmt, void *pos, U64 cmt_block_size);
////////////////////////////////
//~ NOTE(allen): Main API Macros
#if !ENABLE_DEV
# define push_array_no_zero(a,T,c) (T*)arena_push((a), sizeof(T)*(c))
#else
# define push_array_no_zero(a,T,c) (tctx_write_this_srcloc(), (T*)arena_push((a), sizeof(T)*(c)))
#endif
#define push_array_no_zero__no_annotation(a,T,c) (T*)arena_push__impl((a), sizeof(T)*(c))
#define push_array(a,T,c) (T*)MemoryZero(push_array_no_zero(a,T,c), sizeof(T)*(c))
#endif // BASE_ARENA_H
+197
View File
@@ -0,0 +1,197 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
// NOTE(allen): Dev Arena
#if ENABLE_DEV
internal void
arena_annotate_push__dev(Arena *arena, U64 size, void *ptr){
ArenaDev *dev = arena->dev;
if (dev != 0 && ptr != 0){
//- read location
char *file_name = 0;
U64 line_number = 0;
tctx_read_srcloc(&file_name, &line_number);
tctx_write_srcloc(0, 0);
//- profile
ArenaProf *prof = dev->prof;
if (prof != 0){
// c string -> string
String8 file_name_str = str8_lit("(null)");
if (file_name != 0){
file_name_str = str8_cstring(file_name);
}
// record
arena_prof_inc_counters__dev(dev->arena, prof, file_name_str, line_number, size, 1);
}
}
}
internal void
arena_annotate_absorb__dev(Arena *arena, Arena *sub){
ArenaDev *dev = arena->dev;
ArenaDev *sub_dev = sub->dev;
if (dev != 0 && sub_dev != 0){
//- merge profiles
ArenaProf *prof = dev->prof;
ArenaProf *sub_prof = sub_dev->prof;
if (prof != 0 && sub_prof != 0){
for (ArenaProfNode *sub_node = sub_prof->first;
sub_node != 0;
sub_node = sub_node->next){
arena_prof_inc_counters__dev(dev->arena, prof, sub_node->file_name, sub_node->line,
sub_node->size, sub_node->count);
}
}
}
//- release the sub dev memory
if (sub_dev != 0){
arena_release(sub_dev->arena);
}
}
internal ArenaDev*
arena_equip__dev(Arena *arena){
ArenaDev *result = arena->dev;
if (result == 0){
Arena *dev_arena = arena_alloc();
ArenaDev *dev = (ArenaDev*)arena_push__impl(dev_arena, sizeof(ArenaDev));
MemoryZeroStruct(dev);
dev->arena = dev_arena;
arena->dev = dev;
result = dev;
}
return(result);
}
internal void
arena_equip_profile__dev(Arena *arena){
ArenaDev *dev = arena_equip__dev(arena);
if (dev->prof == 0){
dev->prof = (ArenaProf*)arena_push__impl(dev->arena, sizeof(ArenaProf));
MemoryZeroStruct(dev->prof);
}
}
internal void
arena_print_profile__dev(Arena *arena, Arena *out_arena, String8List *out){
Assert(arena != out_arena);
//- get dev & disable
ArenaDev *dev = arena->dev;
arena->dev = 0;
//- get prof
ArenaProf *prof = (dev != 0)?dev->prof:0;
//- not equipped with prof
if (prof == 0){
str8_list_push(out_arena, out, str8_lit("not equipped with a memory profile\n"));
}
//- print prof
if (prof != 0){
Temp scratch = temp_begin(dev->arena);
//- make flat array
U64 note_count = prof->count;
ArenaProfNode **notes = push_array_no_zero__no_annotation(scratch.arena, ArenaProfNode*, note_count);
{
ArenaProfNode **note_ptr = notes;
for (ArenaProfNode *node = prof->first;
node != 0;
node = node->next, note_ptr += 1){
*note_ptr = node;
}
}
//- file name size
U64 max_file_name_size = 0;
{
ArenaProfNode **note_ptr = notes;
for (U64 i = 0; i < note_count; i += 1, note_ptr += 1){
max_file_name_size = Max(max_file_name_size, (**note_ptr).file_name.size);
}
}
//- sort (> size, < [address])
for (U64 i = 0; i < note_count; i += 1){
ArenaProfNode **i_note = notes + i;
ArenaProfNode **min_note = i_note;
for (U64 j = i + 1; j < note_count; j += 1){
ArenaProfNode **j_note = notes + j;
if ((**j_note).size > (**min_note).size ||
((**j_note).size == (**min_note).size && *j_note < *min_note)){
min_note = j_note;
}
}
if (min_note != i_note){
ArenaProfNode *t = *i_note;
*i_note = *min_note;
*min_note = t;
}
}
//- total size
U64 total_size = 0;
{
ArenaProfNode **note_ptr = notes;
for (U64 i = 0; i < note_count; i += 1, note_ptr += 1){
ArenaProfNode *note = *note_ptr;
total_size += note->size;
}
}
//- print
{
str8_list_pushf(out_arena, out, "memory total: %llu\n", total_size);
ArenaProfNode **note_ptr = notes;
for (U64 i = 0; i < note_count; i += 1, note_ptr += 1){
ArenaProfNode *note = *note_ptr;
String8 location = push_str8f(scratch.arena, "%S:%5llu:",
note->file_name, note->line);
F32 percent = 100.f*((F32)note->size)/total_size;
str8_list_pushf(out_arena, out, "%*.*s %12llu %5.2f%% [%5llu]\n",
max_file_name_size + 7, str8_varg(location),
note->size, percent, note->count);
}
}
temp_end(scratch);
}
//- restore dev
arena->dev = dev;
}
internal void
arena_prof_inc_counters__dev(Arena *dev_arena, ArenaProf *prof, String8 file_name, U64 line,
U64 size, U64 count){
// find existing profile node
ArenaProfNode *prof_node = 0;
for (ArenaProfNode *node = prof->first;
node != 0;
node = node->next){
if (node->line == line && str8_match(file_name, node->file_name, 0)){
prof_node = node;
break;
}
}
// make new histogram node if necessary
if (prof_node == 0){
prof_node = (ArenaProfNode*)arena_push(dev_arena, sizeof(*prof_node));
SLLQueuePush(prof->first, prof->last, prof_node);
prof->count += 1;
prof_node->file_name = file_name;
prof_node->line = line;
}
// record this allocation
prof_node->size += size;
prof_node->count += count;
}
#endif
+47
View File
@@ -0,0 +1,47 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_ARENA_DEV_H
#define BASE_ARENA_DEV_H
////////////////////////////////
//~ NOTE(allen): Dev Arena Types
typedef struct ArenaDev ArenaDev;
struct ArenaDev
{
Arena *arena;
struct ArenaProf *prof;
};
typedef struct ArenaProf ArenaProf;
struct ArenaProf
{
struct ArenaProfNode *first;
struct ArenaProfNode *last;
U64 count;
};
typedef struct ArenaProfNode ArenaProfNode;
struct ArenaProfNode
{
ArenaProfNode *next;
String8 file_name;
U64 line;
U64 size;
U64 count;
};
////////////////////////////////
//~ NOTE(allen): Dev Arena Functions
#if ENABLE_DEV
internal void arena_annotate_push__dev(Arena *arena, U64 size, void *ptr);
internal void arena_annotate_absorb__dev(Arena *arena, Arena *sub);
internal ArenaDev* arena_equip__dev(Arena *arena);
internal void arena_equip_profile__dev(Arena *arena);
internal void arena_print_profile__dev(Arena *arena, Arena *out_arena, String8List *out);
internal void arena_prof_inc_counters__dev(Arena *dev_arena, ArenaProf *prof, String8 file_name, U64 line, U64 size, U64 count);
#endif
#endif // BASE_ARENA_DEV_H
+103
View File
@@ -0,0 +1,103 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#if COMPILER_CL || (COMPILER_CLANG && OS_WINDOWS)
internal U64
count_bits_set16(U16 val)
{
return __popcnt16(val);
}
internal U64
count_bits_set32(U32 val)
{
return __popcnt(val);
}
internal U64
count_bits_set64(U64 val)
{
return __popcnt64(val);
}
internal U64
ctz32(U32 mask)
{
unsigned long idx;
_BitScanForward(&idx, mask);
return idx;
}
internal U64
ctz64(U64 mask)
{
unsigned long idx;
_BitScanForward64(&idx, mask);
return idx;
}
internal U64
clz32(U32 mask)
{
unsigned long idx;
_BitScanReverse(&idx, mask);
return 31 - idx;
}
internal U64
clz64(U64 mask)
{
unsigned long idx;
_BitScanReverse64(&idx, mask);
return 63 - idx;
}
#elif COMPILER_CLANG || COMPILER_GCC
internal U64
count_bits_set16(U16 val)
{
NotImplemented;
return 0;
}
internal U64
count_bits_set32(U32 val)
{
NotImplemented;
return 0;
}
internal U64
count_bits_set64(U64 val)
{
NotImplemented;
return 0;
}
internal U64
ctz32(U32 val)
{
NotImplemented;
return 0;
}
internal U64
clz32(U32 val)
{
NotImplemented;
return 0;
}
internal U64
clz64(U64 val)
{
NotImplemented;
return 0;
}
#else
# error "bits not defined for this target"
#endif
+18
View File
@@ -0,0 +1,18 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_BITS_H
#define BASE_BITS_H
#define ExtractBit(word, idx) (((word) >> (idx)) & 1)
internal U64 count_bits_set16(U16 val);
internal U64 count_bits_set32(U32 val);
internal U64 count_bits_set64(U64 val);
internal U64 ctz32(U32 val);
internal U64 ctz64(U64 val);
internal U64 clz32(U32 val);
internal U64 clz64(U64 val);
#endif // BASE_BITS_H
+229
View File
@@ -0,0 +1,229 @@
// Copyright (c) 2024 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;
}
internal CmdLineOpt **
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 bucket = hash % cmd_line->option_table_size;
slot = &cmd_line->option_table[bucket];
}
return slot;
}
internal CmdLineOpt *
cmd_line_opt_from_slot(CmdLineOpt **slot, String8 string)
{
CmdLineOpt *result = 0;
for(CmdLineOpt *var = *slot; var; var = var->hash_next)
{
if(str8_match(string, var->string, 0))
{
result = var;
break;
}
}
return result;
}
internal void
cmd_line_push_opt(CmdLineOptList *list, CmdLineOpt *var)
{
SLLQueuePush(list->first, list->last, var);
list->count += 1;
}
internal CmdLineOpt *
cmd_line_insert_opt(Arena *arena, CmdLine *cmd_line, String8 string, String8List values)
{
CmdLineOpt *var = 0;
CmdLineOpt **slot = cmd_line_slot_from_string(cmd_line, string);
CmdLineOpt *existing_var = cmd_line_opt_from_slot(slot, string);
if(existing_var != 0)
{
var = existing_var;
}
else
{
var = push_array(arena, CmdLineOpt, 1);
var->hash_next = *slot;
var->hash = cmd_line_hash_from_string(string);
var->string = push_str8_copy(arena, string);
var->value_strings = values;
StringJoin join = {0};
join.pre = str8_lit("");
join.sep = str8_lit(",");
join.post = str8_lit("");
var->value_string = str8_list_join(arena, &var->value_strings, &join);
*slot = var;
cmd_line_push_opt(&cmd_line->options, var);
}
return var;
}
internal CmdLine
cmd_line_from_string_list(Arena *arena, String8List command_line)
{
CmdLine parsed = {0};
// 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.
B32 after_passthrough_option = 0;
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 - 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)
{
if(str8_match(node->string, str8_lit("--"), 0))
{
after_passthrough_option = 1;
is_option = 0;
}
else if(str8_match(str8_prefix(node->string, 2), str8_lit("--"), 0))
{
option_name = str8_skip(option_name, 2);
}
else if(str8_match(str8_prefix(node->string, 1), str8_lit("-"), 0))
{
option_name = str8_skip(option_name, 1);
}
else
{
is_option = 0;
}
}
else
{
is_option = 0;
}
// NOTE(rjf): This 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)
{
has_arguments = 1;
}
option_name = str8_prefix(option_name, arg_signifier_position);
String8List arguments = {0};
// NOTE(rjf): Parse arguments.
if(has_arguments)
{
for(String8Node *n = node; n; n = n->next)
{
next = n->next;
String8 string = n->string;
if(n == node)
{
string = arg_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)
{
str8_list_push(arena, &arguments, sub_arg->string);
}
if(!str8_match(str8_postfix(n->string, 1), str8_lit(","), 0) &&
(n != node || arg_portion_this_string.size != 0))
{
break;
}
}
}
// NOTE(rjf): Register config variable.
cmd_line_insert_opt(arena, &parsed, option_name, arguments);
}
// NOTE(rjf): Default path, treat as a passthrough config option to be
// handled by tool-specific code.
else if(!str8_match(node->string, str8_lit("--"), 0))
{
str8_list_push(arena, &parsed.inputs, node->string);
after_passthrough_option = 1;
}
}
return parsed;
}
internal CmdLineOpt *
cmd_line_opt_from_string(CmdLine *cmd_line, String8 name)
{
return cmd_line_opt_from_slot(cmd_line_slot_from_string(cmd_line, name), name);
}
internal String8List
cmd_line_strings(CmdLine *cmd_line, String8 name)
{
String8List result = {0};
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
if(var != 0)
{
result = var->value_strings;
}
return result;
}
internal String8
cmd_line_string(CmdLine *cmd_line, String8 name)
{
String8 result = {0};
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
if(var != 0)
{
result = var->value_string;
}
return result;
}
internal B32
cmd_line_has_flag(CmdLine *cmd_line, String8 name)
{
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
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);
}
+53
View File
@@ -0,0 +1,53 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_COMMAND_LINE_H
#define BASE_COMMAND_LINE_H
////////////////////////////////
//~ rjf: Parsed Command Line Types
typedef struct CmdLineOpt CmdLineOpt;
struct CmdLineOpt
{
CmdLineOpt *next;
CmdLineOpt *hash_next;
U64 hash;
String8 string;
String8List value_strings;
String8 value_string;
};
typedef struct CmdLineOptList CmdLineOptList;
struct CmdLineOptList
{
U64 count;
CmdLineOpt *first;
CmdLineOpt *last;
};
typedef struct CmdLine CmdLine;
struct CmdLine
{
CmdLineOptList options;
String8List inputs;
U64 option_table_size;
CmdLineOpt **option_table;
};
////////////////////////////////
//~ NOTE(rjf): Command Line Option Parsing
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);
internal CmdLineOpt* cmd_line_insert_opt(Arena *arena, CmdLine *cmd_line, String8 string, String8List values);
internal CmdLine cmd_line_from_string_list(Arena *arena, String8List arguments);
internal CmdLineOpt* cmd_line_opt_from_string(CmdLine *cmd_line, String8 name);
internal String8List cmd_line_strings(CmdLine *cmd_line, String8 name);
internal String8 cmd_line_string(CmdLine *cmd_line, String8 name);
internal B32 cmd_line_has_flag(CmdLine *cmd_line, String8 name);
internal B32 cmd_line_has_argument(CmdLine *cmd_line, String8 name);
#endif // BASE_COMMAND_LINE_H
+144
View File
@@ -0,0 +1,144 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_CONTEXT_CRACKING_H
#define BASE_CONTEXT_CRACKING_H
#if defined(__clang__)
# define COMPILER_CLANG 1
# if defined(_WIN32)
# define OS_WINDOWS 1
# elif defined(__gnu_linux__) || defined(__linux__)
# define OS_LINUX 1
# elif defined(__APPLE__) && defined(__MACH__)
# define OS_MAC 1
# else
# error This compiler/platform combo is not supported yet
# endif
# if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
# define ARCH_X64 1
# elif defined(i386) || defined(__i386) || defined(__i386__)
# define ARCH_X86 1
# elif defined(__aarch64__)
# define ARCH_ARM64 1
# elif defined(__arm__)
# define ARCH_ARM32 1
# else
# error architecture not supported yet
# endif
#elif defined(_MSC_VER)
# define COMPILER_CL 1
# if defined(_WIN32)
# define OS_WINDOWS 1
# else
# error This compiler/platform combo is not supported yet
# endif
# if defined(_M_AMD64)
# define ARCH_X64 1
# elif defined(_M_IX86)
# define ARCH_X86 1
# elif defined(_M_ARM64)
# define ARCH_ARM64 1
# elif defined(_M_ARM)
# define ARCH_ARM32 1
# else
# error architecture not supported yet
# endif
#elif defined(__GNUC__) || defined(__GNUG__)
# define COMPILER_GCC 1
# if defined(__gnu_linux__) || defined(__linux__)
# define OS_LINUX 1
# else
# error This compiler/platform combo is not supported yet
# endif
# if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
# define ARCH_X64 1
# elif defined(i386) || defined(__i386) || defined(__i386__)
# define ARCH_X86 1
# elif defined(__aarch64__)
# define ARCH_ARM64 1
# elif defined(__arm__)
# define ARCH_ARM32 1
# else
# error architecture not supported yet
# endif
#else
# error This compiler is not supported yet
#endif
#if defined(ARCH_X64)
# define ARCH_64BIT 1
#elif defined(ARCH_X86)
# define ARCH_32BIT 1
#endif
#if defined(__cplusplus)
# define LANG_CPP 1
#else
# define LANG_C 1
#endif
// zeroify
#if !defined(ARCH_32BIT)
# define ARCH_32BIT 0
#endif
#if !defined(ARCH_64BIT)
# define ARCH_64BIT 0
#endif
#if !defined(ARCH_X64)
# define ARCH_X64 0
#endif
#if !defined(ARCH_X86)
# define ARCH_X86 0
#endif
#if !defined(ARCH_ARM64)
# define ARCH_ARM64 0
#endif
#if !defined(ARCH_ARM32)
# define ARCH_ARM32 0
#endif
#if !defined(COMPILER_CL)
# define COMPILER_CL 0
#endif
#if !defined(COMPILER_GCC)
# define COMPILER_GCC 0
#endif
#if !defined(COMPILER_CLANG)
# define COMPILER_CLANG 0
#endif
#if !defined(OS_WINDOWS)
# define OS_WINDOWS 0
#endif
#if !defined(OS_LINUX)
# define OS_LINUX 0
#endif
#if !defined(OS_MAC)
# define OS_MAC 0
#endif
#if !defined(LANG_CPP)
# define LANG_CPP 0
#endif
#if !defined(LANG_C)
# define LANG_C 0
#endif
#if ARCH_ARM32 || ARCH_ARM64 || ARCH_X64 || ARCH_X86
# define ARCH_LITTLE_ENDIAN 1
#else
# error Endianness of this architecture not understood by context cracker
#endif
#endif // BASE_CONTEXT_CRACKING_H
+18
View File
@@ -0,0 +1,18 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Base Includes
#undef RADDBG_LAYER_COLOR
#define RADDBG_LAYER_COLOR 0.20f, 0.60f, 0.80f
#include "base_types.c"
#include "base_markup.c"
#include "base_arena.c"
#include "base_math.c"
#include "base_string.c"
#include "base_thread_context.c"
#include "base_command_line.c"
#include "base_arena_dev.c"
#include "base_bits.c"
+23
View File
@@ -0,0 +1,23 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_INC_H
#define BASE_INC_H
////////////////////////////////
//~ rjf: Base Includes
#include "base_context_cracking.h"
#include "base_types.h"
#include "base_markup.h"
#include "base_ins.h"
#include "base_linked_lists.h"
#include "base_arena.h"
#include "base_math.h"
#include "base_string.h"
#include "base_thread_context.h"
#include "base_command_line.h"
#include "base_arena_dev.h"
#include "base_bits.h"
#endif // BASE_INC_H
+52
View File
@@ -0,0 +1,52 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_INS_H
#define BASE_INS_H
////////////////////////////////
// NOTE(allen): Implementations of Intrinsics
#if OS_WINDOWS
# include <windows.h>
# include <tmmintrin.h>
# include <wmmintrin.h>
# include <intrin.h>
# if ARCH_X64
# define ins_atomic_u64_eval(x) InterlockedAdd((volatile LONG *)(x), 0)
# define ins_atomic_u64_inc_eval(x) InterlockedIncrement64((volatile __int64 *)(x))
# define ins_atomic_u64_dec_eval(x) InterlockedDecrement64((volatile __int64 *)(x))
# define ins_atomic_u64_eval_assign(x,c) InterlockedExchange64((volatile __int64 *)(x),(c))
# define ins_atomic_u64_add_eval(x,c) InterlockedAdd((volatile LONG *)(x), c)
# define ins_atomic_u32_eval_assign(x,c) InterlockedExchange((volatile LONG *)(x),(c))
# define ins_atomic_u32_eval_cond_assign(x,k,c) InterlockedCompareExchange((volatile LONG *)(x),(k),(c))
# define ins_atomic_ptr_eval_assign(x,c) (void*)ins_atomic_u64_eval_assign((volatile __int64 *)(x), (__int64)(c))
# endif
#elif OS_LINUX
# if ARCH_X64
# define ins_atomic_u64_inc_eval(x) __sync_fetch_and_add((volatile U64 *)(x), 1)
# endif
#else
// TODO(allen):
#endif
////////////////////////////////
// NOTE(allen): Intrinsic Checks
#if ARCH_X64
# if !defined(ins_atomic_u64_inc_eval)
# error missing: ins_atomic_u64_inc_eval
# endif
#else
# error the intrinsic set for this arch is not developed
#endif
#endif //BASE_INS_H
+73
View File
@@ -0,0 +1,73 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_LINKED_LIST_H
#define BASE_LINKED_LIST_H
////////////////////////////////
//~ rjf: Helpers
#define CheckNil(nil,p) ((p) == 0 || (p) == nil)
#define SetNil(nil,p) ((p) = nil)
////////////////////////////////
//~ rjf: Base Macros
//- rjf: Base Doubly-Linked-List Macros
#define DLLInsert_NPZ(nil,f,l,p,n,next,prev) (CheckNil(nil,f) ? \
((f) = (l) = (n), SetNil(nil,(n)->next), SetNil(nil,(n)->prev)) :\
CheckNil(nil,p) ? \
((n)->next = (f), (f)->prev = (n), (f) = (n), SetNil(nil,(n)->prev)) :\
((p)==(l)) ? \
((l)->next = (n), (n)->prev = (l), (l) = (n), SetNil(nil, (n)->next)) :\
(((!CheckNil(nil,p) && CheckNil(nil,(p)->next)) ? (0) : ((p)->next->prev = (n))), ((n)->next = (p)->next), ((p)->next = (n)), ((n)->prev = (p))))
#define DLLPushBack_NPZ(nil,f,l,n,next,prev) DLLInsert_NPZ(nil,f,l,l,n,next,prev)
#define DLLPushFront_NPZ(nil,f,l,n,next,prev) DLLInsert_NPZ(nil,l,f,f,n,prev,next)
#define DLLRemove_NPZ(nil,f,l,n,next,prev) (((n) == (f) ? (f) = (n)->next : (0)),\
((n) == (l) ? (l) = (l)->prev : (0)),\
(CheckNil(nil,(n)->prev) ? (0) :\
((n)->prev->next = (n)->next)),\
(CheckNil(nil,(n)->next) ? (0) :\
((n)->next->prev = (n)->prev)))
//- rjf: Base Singly-Linked-List Queue Macros
#define SLLQueuePush_NZ(nil,f,l,n,next) (CheckNil(nil,f)?\
((f)=(l)=(n),SetNil(nil,(n)->next)):\
((l)->next=(n),(l)=(n),SetNil(nil,(n)->next)))
#define SLLQueuePushFront_NZ(nil,f,l,n,next) (CheckNil(nil,f)?\
((f)=(l)=(n),SetNil(nil,(n)->next)):\
((n)->next=(f),(f)=(n)))
#define SLLQueuePop_NZ(nil,f,l,next) ((f)==(l)?\
(SetNil(nil,f),SetNil(nil,l)):\
((f)=(f)->next))
//- rjf: Base Singly-Linked-List Stack Macros
#define SLLStackPush_N(f,n,next) ((n)->next=(f), (f)=(n))
#define SLLStackPop_N(f,next) ((f)=(f)->next)
////////////////////////////////
//~ rjf: Convenience Wrappers
//- rjf: Doubly-Linked-List Wrappers
#define DLLInsert_NP(f,l,p,n,next,prev) DLLInsert_NPZ(0,f,l,p,n,next,prev)
#define DLLPushBack_NP(f,l,n,next,prev) DLLPushBack_NPZ(0,f,l,n,next,prev)
#define DLLPushFront_NP(f,l,n,next,prev) DLLPushFront_NPZ(0,f,l,n,next,prev)
#define DLLRemove_NP(f,l,n,next,prev) DLLRemove_NPZ(0,f,l,n,next,prev)
#define DLLInsert(f,l,p,n) DLLInsert_NPZ(0,f,l,p,n,next,prev)
#define DLLPushBack(f,l,n) DLLPushBack_NPZ(0,f,l,n,next,prev)
#define DLLPushFront(f,l,n) DLLPushFront_NPZ(0,f,l,n,next,prev)
#define DLLRemove(f,l,n) DLLRemove_NPZ(0,f,l,n,next,prev)
//- rjf: Singly-Linked-List Queue Wrappers
#define SLLQueuePush_N(f,l,n,next) SLLQueuePush_NZ(0,f,l,n,next)
#define SLLQueuePushFront_N(f,l,n,next) SLLQueuePushFront_NZ(0,f,l,n,next)
#define SLLQueuePop_N(f,l,next) SLLQueuePop_NZ(0,f,l,next)
#define SLLQueuePush(f,l,n) SLLQueuePush_NZ(0,f,l,n,next)
#define SLLQueuePushFront(f,l,n) SLLQueuePushFront_NZ(0,f,l,n,next)
#define SLLQueuePop(f,l) SLLQueuePop_NZ(0,f,l,next)
//- rjf: Singly-Linked-List Stack Wrappers
#define SLLStackPush(f,n) SLLStackPush_N(f,n,next)
#define SLLStackPop(f) SLLStackPop_N(f,next)
#endif //BASE_LINKED_LIST_H
+2
View File
@@ -0,0 +1,2 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
+79
View File
@@ -0,0 +1,79 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_MARKUP_H
#define BASE_MARKUP_H
////////////////////////////////
//~ rjf: Zero Settings
#if !defined(PROFILE_TELEMETRY)
# define PROFILE_TELEMETRY 0
#endif
#if !defined(MARKUP_LAYER_COLOR)
# define MARKUP_LAYER_COLOR 1.00f, 0.00f, 1.00f
#endif
////////////////////////////////
//~ rjf: Third Party Includes
#if PROFILE_TELEMETRY
# include "rad_tm.h"
# if OS_WINDOWS
# pragma comment(lib, "rad_tm_win64.lib")
# endif
#endif
////////////////////////////////
//~ rjf: Telemetry Profile Defines
#if PROFILE_TELEMETRY
# define ProfBegin(...) tmEnter(0, 0, __VA_ARGS__)
# define ProfBeginDynamic(...) (TM_API_PTR ? TM_API_PTR->_tmEnterZoneV_Core(0, 0, __FILE__, &g_telemetry_filename_id, __LINE__, __VA_ARGS__) : (void)0)
# define ProfEnd(...) (TM_API_PTR ? TM_API_PTR->_tmLeaveZone(0) : (void)0)
# define ProfTick(...) tmTick(0)
# define ProfIsCapturing(...) tmRunning()
# define ProfBeginCapture(...) tmOpen(0, __VA_ARGS__, __DATE__, "localhost", TMCT_TCP, TELEMETRY_DEFAULT_PORT, TMOF_INIT_NETWORKING|TMOF_CAPTURE_CONTEXT_SWITCHES, 100)
# define ProfEndCapture(...) tmClose(0)
# define ProfThreadName(...) (TM_API_PTR ? TM_API_PTR->_tmThreadName(0, 0, __VA_ARGS__) : (void)0)
# define ProfMsg(...) (TM_API_PTR ? TM_API_PTR->_tmMessageV_Core(0, TMMF_ICON_NOTE, __FILE__, &g_telemetry_filename_id, __LINE__, __VA_ARGS__) : (void)0)
# define ProfBeginLockWait(...) tmStartWaitForLock(0, 0, __VA_ARGS__)
# define ProfEndLockWait(...) tmEndWaitForLock(0)
# define ProfLockTake(...) tmAcquiredLock(0, 0, __VA_ARGS__)
# define ProfLockDrop(...) tmReleasedLock(0, __VA_ARGS__)
# define ProfColor(color) tmZoneColorSticky(color)
#endif
////////////////////////////////
//~ rjf: Zeroify Undefined Defines
#if !defined(ProfBegin)
# define ProfBegin(...) (0)
# define ProfBeginDynamic(...) (0)
# define ProfEnd(...) (0)
# define ProfTick(...) (0)
# define ProfIsCapturing(...) (0)
# define ProfBeginCapture(...) (0)
# define ProfEndCapture(...) (0)
# define ProfThreadName(...) (0)
# define ProfMsg(...) (0)
# define ProfBeginLockWait(...) (0)
# define ProfEndLockWait(...) (0)
# define ProfLockTake(...) (0)
# define ProfLockDrop(...) (0)
# define ProfColor(...) (0)
#endif
////////////////////////////////
//~ rjf: Helper Wrappers
#define ProfBeginFunction(...) ProfBegin(this_function_name)
#define ProfScope(...) DeferLoop(ProfBeginDynamic(__VA_ARGS__), ProfEnd())
////////////////////////////////
//~ rjf: General Markup
#define ThreadName(...) (ProfThreadName(__VA_ARGS__))
#endif // BASE_MARKUP_H
+607
View File
@@ -0,0 +1,607 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Scalar Ops
internal F32
mix_1f32(F32 a, F32 b, F32 t)
{
F32 c = (a + (b-a) * Clamp(0.f, t, 1.f));
return c;
}
internal F64
mix_1f64(F64 a, F64 b, F64 t)
{
F64 c = (a + (b-a) * Clamp(0.0, t, 1.0));
return c;
}
////////////////////////////////
//~ rjf: Vector Ops
internal Vec2F32 vec_2f32(F32 x, F32 y) {Vec2F32 v = {x, y}; return v;}
internal Vec2F32 add_2f32(Vec2F32 a, Vec2F32 b) {Vec2F32 c = {a.x+b.x, a.y+b.y}; return c;}
internal Vec2F32 sub_2f32(Vec2F32 a, Vec2F32 b) {Vec2F32 c = {a.x-b.x, a.y-b.y}; return c;}
internal Vec2F32 mul_2f32(Vec2F32 a, Vec2F32 b) {Vec2F32 c = {a.x*b.x, a.y*b.y}; return c;}
internal Vec2F32 div_2f32(Vec2F32 a, Vec2F32 b) {Vec2F32 c = {a.x/b.x, a.y/b.y}; return c;}
internal Vec2F32 scale_2f32(Vec2F32 v, F32 s) {Vec2F32 c = {v.x*s, v.y*s}; return c;}
internal F32 dot_2f32(Vec2F32 a, Vec2F32 b) {F32 c = a.x*b.x + a.y*b.y; return c;}
internal F32 length_squared_2f32(Vec2F32 v) {F32 c = v.x*v.x + v.y*v.y; return c;}
internal F32 length_2f32(Vec2F32 v) {F32 c = sqrt_f32(v.x*v.x + v.y*v.y); return c;}
internal Vec2F32 normalize_2f32(Vec2F32 v) {v = scale_2f32(v, 1.f/length_2f32(v)); return v;}
internal Vec2F32 mix_2f32(Vec2F32 a, Vec2F32 b, F32 t) {Vec2F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t)}; return c;}
internal Vec2S64 vec_2s64(S64 x, S64 y) {Vec2S64 v = {x, y}; return v;}
internal Vec2S64 add_2s64(Vec2S64 a, Vec2S64 b) {Vec2S64 c = {a.x+b.x, a.y+b.y}; return c;}
internal Vec2S64 sub_2s64(Vec2S64 a, Vec2S64 b) {Vec2S64 c = {a.x-b.x, a.y-b.y}; return c;}
internal Vec2S64 mul_2s64(Vec2S64 a, Vec2S64 b) {Vec2S64 c = {a.x*b.x, a.y*b.y}; return c;}
internal Vec2S64 div_2s64(Vec2S64 a, Vec2S64 b) {Vec2S64 c = {a.x/b.x, a.y/b.y}; return c;}
internal Vec2S64 scale_2s64(Vec2S64 v, S64 s) {Vec2S64 c = {v.x*s, v.y*s}; return c;}
internal S64 dot_2s64(Vec2S64 a, Vec2S64 b) {S64 c = a.x*b.x + a.y*b.y; return c;}
internal S64 length_squared_2s64(Vec2S64 v) {S64 c = v.x*v.x + v.y*v.y; return c;}
internal S64 length_2s64(Vec2S64 v) {S64 c = (S64)sqrt_f64((F64)(v.x*v.x + v.y*v.y)); return c;}
internal Vec2S64 normalize_2s64(Vec2S64 v) {v = scale_2s64(v, (S64)(1.f/length_2s64(v))); return v;}
internal Vec2S64 mix_2s64(Vec2S64 a, Vec2S64 b, F32 t) {Vec2S64 c = {(S64)mix_1f32((F32)a.x, (F32)b.x, t), (S64)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;}
internal Vec2S32 vec_2s32(S32 x, S32 y) {Vec2S32 v = {x, y}; return v;}
internal Vec2S32 add_2s32(Vec2S32 a, Vec2S32 b) {Vec2S32 c = {a.x+b.x, a.y+b.y}; return c;}
internal Vec2S32 sub_2s32(Vec2S32 a, Vec2S32 b) {Vec2S32 c = {a.x-b.x, a.y-b.y}; return c;}
internal Vec2S32 mul_2s32(Vec2S32 a, Vec2S32 b) {Vec2S32 c = {a.x*b.x, a.y*b.y}; return c;}
internal Vec2S32 div_2s32(Vec2S32 a, Vec2S32 b) {Vec2S32 c = {a.x/b.x, a.y/b.y}; return c;}
internal Vec2S32 scale_2s32(Vec2S32 v, S32 s) {Vec2S32 c = {v.x*s, v.y*s}; return c;}
internal S32 dot_2s32(Vec2S32 a, Vec2S32 b) {S32 c = a.x*b.x + a.y*b.y; return c;}
internal S32 length_squared_2s32(Vec2S32 v) {S32 c = v.x*v.x + v.y*v.y; return c;}
internal S32 length_2s32(Vec2S32 v) {S32 c = (S32)sqrt_f32((F32)v.x*(F32)v.x + (F32)v.y*(F32)v.y); return c;}
internal Vec2S32 normalize_2s32(Vec2S32 v) {v = scale_2s32(v, (S32)(1.f/length_2s32(v))); return v;}
internal Vec2S32 mix_2s32(Vec2S32 a, Vec2S32 b, F32 t) {Vec2S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;}
internal Vec2S16 vec_2s16(S16 x, S16 y) {Vec2S16 v = {x, y}; return v;}
internal Vec2S16 add_2s16(Vec2S16 a, Vec2S16 b) {Vec2S16 c = {(S16)(a.x+b.x), (S16)(a.y+b.y)}; return c;}
internal Vec2S16 sub_2s16(Vec2S16 a, Vec2S16 b) {Vec2S16 c = {(S16)(a.x-b.x), (S16)(a.y-b.y)}; return c;}
internal Vec2S16 mul_2s16(Vec2S16 a, Vec2S16 b) {Vec2S16 c = {(S16)(a.x*b.x), (S16)(a.y*b.y)}; return c;}
internal Vec2S16 div_2s16(Vec2S16 a, Vec2S16 b) {Vec2S16 c = {(S16)(a.x/b.x), (S16)(a.y/b.y)}; return c;}
internal Vec2S16 scale_2s16(Vec2S16 v, S16 s) {Vec2S16 c = {(S16)(v.x*s), (S16)(v.y*s)}; return c;}
internal S16 dot_2s16(Vec2S16 a, Vec2S16 b) {S16 c = a.x*b.x + a.y*b.y; return c;}
internal S16 length_squared_2s16(Vec2S16 v) {S16 c = v.x*v.x + v.y*v.y; return c;}
internal S16 length_2s16(Vec2S16 v) {S16 c = (S16)sqrt_f32((F32)(v.x*v.x + v.y*v.y)); return c;}
internal Vec2S16 normalize_2s16(Vec2S16 v) {v = scale_2s16(v, (S16)(1.f/length_2s16(v))); return v;}
internal Vec2S16 mix_2s16(Vec2S16 a, Vec2S16 b, F32 t) {Vec2S16 c = {(S16)mix_1f32((F32)a.x, (F32)b.x, t), (S16)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;}
internal Vec3F32 vec_3f32(F32 x, F32 y, F32 z) {Vec3F32 v = {x, y, z}; return v;}
internal Vec3F32 add_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.x+b.x, a.y+b.y, a.z+b.z}; return c;}
internal Vec3F32 sub_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.x-b.x, a.y-b.y, a.z-b.z}; return c;}
internal Vec3F32 mul_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.x*b.x, a.y*b.y, a.z*b.z}; return c;}
internal Vec3F32 div_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.x/b.x, a.y/b.y, a.z/b.z}; return c;}
internal Vec3F32 scale_3f32(Vec3F32 v, F32 s) {Vec3F32 c = {v.x*s, v.y*s, v.z*s}; return c;}
internal F32 dot_3f32(Vec3F32 a, Vec3F32 b) {F32 c = a.x*b.x + a.y*b.y + a.z*b.z; return c;}
internal F32 length_squared_3f32(Vec3F32 v) {F32 c = v.x*v.x + v.y*v.y + v.z*v.z; return c;}
internal F32 length_3f32(Vec3F32 v) {F32 c = sqrt_f32(v.x*v.x + v.y*v.y + v.z*v.z); return c;}
internal Vec3F32 normalize_3f32(Vec3F32 v) {v = scale_3f32(v, 1.f/length_3f32(v)); return v;}
internal Vec3F32 mix_3f32(Vec3F32 a, Vec3F32 b, F32 t) {Vec3F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t), mix_1f32(a.z, b.z, t)}; return c;}
internal Vec3F32 cross_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; return c;}
internal Vec3S32 vec_3s32(S32 x, S32 y, S32 z) {Vec3S32 v = {x, y, z}; return v;}
internal Vec3S32 add_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.x+b.x, a.y+b.y, a.z+b.z}; return c;}
internal Vec3S32 sub_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.x-b.x, a.y-b.y, a.z-b.z}; return c;}
internal Vec3S32 mul_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.x*b.x, a.y*b.y, a.z*b.z}; return c;}
internal Vec3S32 div_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.x/b.x, a.y/b.y, a.z/b.z}; return c;}
internal Vec3S32 scale_3s32(Vec3S32 v, S32 s) {Vec3S32 c = {v.x*s, v.y*s, v.z*s}; return c;}
internal S32 dot_3s32(Vec3S32 a, Vec3S32 b) {S32 c = a.x*b.x + a.y*b.y + a.z*b.z; return c;}
internal S32 length_squared_3s32(Vec3S32 v) {S32 c = v.x*v.x + v.y*v.y + v.z*v.z; return c;}
internal S32 length_3s32(Vec3S32 v) {S32 c = (S32)sqrt_f32((F32)(v.x*v.x + v.y*v.y + v.z*v.z)); return c;}
internal Vec3S32 normalize_3s32(Vec3S32 v) {v = scale_3s32(v, (S32)(1.f/length_3s32(v))); return v;}
internal Vec3S32 mix_3s32(Vec3S32 a, Vec3S32 b, F32 t) {Vec3S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t), (S32)mix_1f32((F32)a.z, (F32)b.z, t)}; return c;}
internal Vec3S32 cross_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; return c;}
internal Vec4F32 vec_4f32(F32 x, F32 y, F32 z, F32 w) {Vec4F32 v = {x, y, z, w}; return v;}
internal Vec4F32 add_4f32(Vec4F32 a, Vec4F32 b) {Vec4F32 c = {a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w}; return c;}
internal Vec4F32 sub_4f32(Vec4F32 a, Vec4F32 b) {Vec4F32 c = {a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w}; return c;}
internal Vec4F32 mul_4f32(Vec4F32 a, Vec4F32 b) {Vec4F32 c = {a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w}; return c;}
internal Vec4F32 div_4f32(Vec4F32 a, Vec4F32 b) {Vec4F32 c = {a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w}; return c;}
internal Vec4F32 scale_4f32(Vec4F32 v, F32 s) {Vec4F32 c = {v.x*s, v.y*s, v.z*s, v.w*s}; return c;}
internal F32 dot_4f32(Vec4F32 a, Vec4F32 b) {F32 c = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; return c;}
internal F32 length_squared_4f32(Vec4F32 v) {F32 c = v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w; return c;}
internal F32 length_4f32(Vec4F32 v) {F32 c = sqrt_f32(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); return c;}
internal Vec4F32 normalize_4f32(Vec4F32 v) {v = scale_4f32(v, 1.f/length_4f32(v)); return v;}
internal Vec4F32 mix_4f32(Vec4F32 a, Vec4F32 b, F32 t) {Vec4F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t), mix_1f32(a.z, b.z, t), mix_1f32(a.w, b.w, t)}; return c;}
internal Vec4S32 vec_4s32(S32 x, S32 y, S32 z, S32 w) {Vec4S32 v = {x, y, z, w}; return v;}
internal Vec4S32 add_4s32(Vec4S32 a, Vec4S32 b) {Vec4S32 c = {a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w}; return c;}
internal Vec4S32 sub_4s32(Vec4S32 a, Vec4S32 b) {Vec4S32 c = {a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w}; return c;}
internal Vec4S32 mul_4s32(Vec4S32 a, Vec4S32 b) {Vec4S32 c = {a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w}; return c;}
internal Vec4S32 div_4s32(Vec4S32 a, Vec4S32 b) {Vec4S32 c = {a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w}; return c;}
internal Vec4S32 scale_4s32(Vec4S32 v, S32 s) {Vec4S32 c = {v.x*s, v.y*s, v.z*s, v.w*s}; return c;}
internal S32 dot_4s32(Vec4S32 a, Vec4S32 b) {S32 c = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; return c;}
internal S32 length_squared_4s32(Vec4S32 v) {S32 c = v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w; return c;}
internal S32 length_4s32(Vec4S32 v) {S32 c = (S32)sqrt_f32((F32)(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w)); return c;}
internal Vec4S32 normalize_4s32(Vec4S32 v) {v = scale_4s32(v, (S32)(1.f/length_4s32(v))); return v;}
internal Vec4S32 mix_4s32(Vec4S32 a, Vec4S32 b, F32 t) {Vec4S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t), (S32)mix_1f32((F32)a.z, (F32)b.z, t), (S32)mix_1f32((F32)a.w, (F32)b.w, t)}; return c;}
////////////////////////////////
//~ rjf: Matrix Ops
internal Mat3x3F32
mat_3x3f32(F32 diagonal)
{
Mat3x3F32 result = {0};
result.v[0][0] = diagonal;
result.v[1][1] = diagonal;
result.v[2][2] = diagonal;
return result;
}
internal Mat3x3F32
make_translate_3x3f32(Vec2F32 delta)
{
Mat3x3F32 mat = mat_3x3f32(1.f);
mat.v[2][0] = delta.x;
mat.v[2][1] = delta.y;
return mat;
}
internal Mat3x3F32
mul_3x3f32(Mat3x3F32 a, Mat3x3F32 b)
{
Mat3x3F32 c = {0};
for(int j = 0; j < 3; j += 1)
{
for(int i = 0; i < 3; i += 1)
{
c.v[i][j] = (a.v[0][j]*b.v[i][0] +
a.v[1][j]*b.v[i][1] +
a.v[2][j]*b.v[i][2]);
}
}
return c;
}
internal Mat4x4F32
mat_4x4f32(F32 diagonal)
{
Mat4x4F32 result = {0};
result.v[0][0] = diagonal;
result.v[1][1] = diagonal;
result.v[2][2] = diagonal;
result.v[3][3] = diagonal;
return result;
}
internal Mat4x4F32
make_translate_4x4f32(Vec3F32 delta)
{
Mat4x4F32 result = mat_4x4f32(1.f);
result.v[3][0] = delta.x;
result.v[3][1] = delta.y;
result.v[3][2] = delta.z;
return result;
}
internal Mat4x4F32
make_scale_4x4f32(Vec3F32 scale)
{
Mat4x4F32 result = mat_4x4f32(1.f);
result.v[0][0] = scale.x;
result.v[1][1] = scale.y;
result.v[2][2] = scale.z;
return result;
}
internal Mat4x4F32
make_perspective_4x4f32(F32 fov, F32 aspect_ratio, F32 near_z, F32 far_z)
{
Mat4x4F32 result = mat_4x4f32(1.f);
F32 tan_theta_over_2 = tan_f32(fov / 2);
result.v[0][0] = 1.f / tan_theta_over_2;
result.v[1][1] = aspect_ratio / tan_theta_over_2;
result.v[2][3] = 1.f;
result.v[2][2] = -(near_z + far_z) / (near_z - far_z);
result.v[3][2] = (2.f * near_z * far_z) / (near_z - far_z);
result.v[3][3] = 0.f;
return result;
}
internal Mat4x4F32
make_orthographic_4x4f32(F32 left, F32 right, F32 bottom, F32 top, F32 near_z, F32 far_z)
{
Mat4x4F32 result = mat_4x4f32(1.f);
result.v[0][0] = 2.f / (right - left);
result.v[1][1] = 2.f / (top - bottom);
result.v[2][2] = 2.f / (far_z - near_z);
result.v[3][3] = 1.f;
result.v[3][0] = (left + right) / (left - right);
result.v[3][1] = (bottom + top) / (bottom - top);
result.v[3][2] = (near_z + far_z) / (near_z - far_z);
return result;
}
internal Mat4x4F32
make_look_at_4x4f32(Vec3F32 eye, Vec3F32 center, Vec3F32 up)
{
Mat4x4F32 result;
Vec3F32 f = normalize_3f32(sub_3f32(eye, center));
Vec3F32 s = normalize_3f32(cross_3f32(f, up));
Vec3F32 u = cross_3f32(s, f);
result.v[0][0] = s.x;
result.v[0][1] = u.x;
result.v[0][2] = -f.x;
result.v[0][3] = 0.0f;
result.v[1][0] = s.y;
result.v[1][1] = u.y;
result.v[1][2] = -f.y;
result.v[1][3] = 0.0f;
result.v[2][0] = s.z;
result.v[2][1] = u.z;
result.v[2][2] = -f.z;
result.v[2][3] = 0.0f;
result.v[3][0] = -dot_3f32(s, eye);
result.v[3][1] = -dot_3f32(u, eye);
result.v[3][2] = dot_3f32(f, eye);
result.v[3][3] = 1.0f;
return result;
}
internal Mat4x4F32
make_rotate_4x4f32(Vec3F32 axis, F32 turns)
{
Mat4x4F32 result = mat_4x4f32(1.f);
axis = normalize_3f32(axis);
F32 sin_theta = sin_f32(turns);
F32 cos_theta = cos_f32(turns);
F32 cos_value = 1.f - cos_theta;
result.v[0][0] = (axis.x * axis.x * cos_value) + cos_theta;
result.v[0][1] = (axis.x * axis.y * cos_value) + (axis.z * sin_theta);
result.v[0][2] = (axis.x * axis.z * cos_value) - (axis.y * sin_theta);
result.v[1][0] = (axis.y * axis.x * cos_value) - (axis.z * sin_theta);
result.v[1][1] = (axis.y * axis.y * cos_value) + cos_theta;
result.v[1][2] = (axis.y * axis.z * cos_value) + (axis.x * sin_theta);
result.v[2][0] = (axis.z * axis.x * cos_value) + (axis.y * sin_theta);
result.v[2][1] = (axis.z * axis.y * cos_value) - (axis.x * sin_theta);
result.v[2][2] = (axis.z * axis.z * cos_value) + cos_theta;
return result;
}
internal Mat4x4F32
mul_4x4f32(Mat4x4F32 a, Mat4x4F32 b)
{
Mat4x4F32 c = {0};
for(int j = 0; j < 4; j += 1)
{
for(int i = 0; i < 4; i += 1)
{
c.v[i][j] = (a.v[0][j]*b.v[i][0] +
a.v[1][j]*b.v[i][1] +
a.v[2][j]*b.v[i][2] +
a.v[3][j]*b.v[i][3]);
}
}
return c;
}
internal Mat4x4F32
scale_4x4f32(Mat4x4F32 m, F32 scale)
{
for(int j = 0; j < 4; j += 1)
{
for(int i = 0; i < 4; i += 1)
{
m.v[i][j] *= scale;
}
}
return m;
}
internal Mat4x4F32
inverse_4x4f32(Mat4x4F32 m)
{
F32 coef00 = m.v[2][2] * m.v[3][3] - m.v[3][2] * m.v[2][3];
F32 coef02 = m.v[1][2] * m.v[3][3] - m.v[3][2] * m.v[1][3];
F32 coef03 = m.v[1][2] * m.v[2][3] - m.v[2][2] * m.v[1][3];
F32 coef04 = m.v[2][1] * m.v[3][3] - m.v[3][1] * m.v[2][3];
F32 coef06 = m.v[1][1] * m.v[3][3] - m.v[3][1] * m.v[1][3];
F32 coef07 = m.v[1][1] * m.v[2][3] - m.v[2][1] * m.v[1][3];
F32 coef08 = m.v[2][1] * m.v[3][2] - m.v[3][1] * m.v[2][2];
F32 coef10 = m.v[1][1] * m.v[3][2] - m.v[3][1] * m.v[1][2];
F32 coef11 = m.v[1][1] * m.v[2][2] - m.v[2][1] * m.v[1][2];
F32 coef12 = m.v[2][0] * m.v[3][3] - m.v[3][0] * m.v[2][3];
F32 coef14 = m.v[1][0] * m.v[3][3] - m.v[3][0] * m.v[1][3];
F32 coef15 = m.v[1][0] * m.v[2][3] - m.v[2][0] * m.v[1][3];
F32 coef16 = m.v[2][0] * m.v[3][2] - m.v[3][0] * m.v[2][2];
F32 coef18 = m.v[1][0] * m.v[3][2] - m.v[3][0] * m.v[1][2];
F32 coef19 = m.v[1][0] * m.v[2][2] - m.v[2][0] * m.v[1][2];
F32 coef20 = m.v[2][0] * m.v[3][1] - m.v[3][0] * m.v[2][1];
F32 coef22 = m.v[1][0] * m.v[3][1] - m.v[3][0] * m.v[1][1];
F32 coef23 = m.v[1][0] * m.v[2][1] - m.v[2][0] * m.v[1][1];
Vec4F32 fac0 = { coef00, coef00, coef02, coef03 };
Vec4F32 fac1 = { coef04, coef04, coef06, coef07 };
Vec4F32 fac2 = { coef08, coef08, coef10, coef11 };
Vec4F32 fac3 = { coef12, coef12, coef14, coef15 };
Vec4F32 fac4 = { coef16, coef16, coef18, coef19 };
Vec4F32 fac5 = { coef20, coef20, coef22, coef23 };
Vec4F32 vec0 = { m.v[1][0], m.v[0][0], m.v[0][0], m.v[0][0] };
Vec4F32 vec1 = { m.v[1][1], m.v[0][1], m.v[0][1], m.v[0][1] };
Vec4F32 vec2 = { m.v[1][2], m.v[0][2], m.v[0][2], m.v[0][2] };
Vec4F32 vec3 = { m.v[1][3], m.v[0][3], m.v[0][3], m.v[0][3] };
Vec4F32 inv0 = add_4f32(sub_4f32(mul_4f32(vec1, fac0), mul_4f32(vec2, fac1)), mul_4f32(vec3, fac2));
Vec4F32 inv1 = add_4f32(sub_4f32(mul_4f32(vec0, fac0), mul_4f32(vec2, fac3)), mul_4f32(vec3, fac4));
Vec4F32 inv2 = add_4f32(sub_4f32(mul_4f32(vec0, fac1), mul_4f32(vec1, fac3)), mul_4f32(vec3, fac5));
Vec4F32 inv3 = add_4f32(sub_4f32(mul_4f32(vec0, fac2), mul_4f32(vec1, fac4)), mul_4f32(vec2, fac5));
Vec4F32 sign_a = { +1, -1, +1, -1 };
Vec4F32 sign_b = { -1, +1, -1, +1 };
Mat4x4F32 inverse;
for(U32 i = 0; i < 4; i += 1)
{
inverse.v[0][i] = inv0.v[i] * sign_a.v[i];
inverse.v[1][i] = inv1.v[i] * sign_b.v[i];
inverse.v[2][i] = inv2.v[i] * sign_a.v[i];
inverse.v[3][i] = inv3.v[i] * sign_b.v[i];
}
Vec4F32 row0 = { inverse.v[0][0], inverse.v[1][0], inverse.v[2][0], inverse.v[3][0] };
Vec4F32 m0 = { m.v[0][0], m.v[0][1], m.v[0][2], m.v[0][3] };
Vec4F32 dot0 = mul_4f32(m0, row0);
F32 dot1 = (dot0.x + dot0.y) + (dot0.z + dot0.w);
F32 one_over_det = 1 / dot1;
return scale_4x4f32(inverse, one_over_det);
}
internal Mat4x4F32
derotate_4x4f32(Mat4x4F32 mat)
{
Vec3F32 scale =
{
length_3f32(v3f32(mat.v[0][0], mat.v[0][1], mat.v[0][2])),
length_3f32(v3f32(mat.v[1][0], mat.v[1][1], mat.v[1][2])),
length_3f32(v3f32(mat.v[2][0], mat.v[2][1], mat.v[2][2])),
};
mat.v[0][0] = scale.x;
mat.v[1][0] = 0.f;
mat.v[2][0] = 0.f;
mat.v[0][1] = 0.f;
mat.v[1][1] = scale.y;
mat.v[2][1] = 0.f;
mat.v[0][2] = 0.f;
mat.v[1][2] = 0.f;
mat.v[2][2] = scale.z;
return mat;
}
////////////////////////////////
//~ rjf: Range Ops
internal Rng1U32 rng_1u32(U32 min, U32 max) {Rng1U32 r = {min, max}; if(r.min > r.max) { Swap(U32, r.min, r.max); } return r;}
internal Rng1U32 shift_1u32(Rng1U32 r, U32 x) {r.min += x; r.max += x; return r;}
internal Rng1U32 pad_1u32(Rng1U32 r, U32 x) {r.min -= x; r.max += x; return r;}
internal U32 center_1u32(Rng1U32 r) {U32 c = (r.min+r.max)/2; return c;}
internal B32 contains_1u32(Rng1U32 r, U32 x) {B32 c = (r.min <= x && x < r.max); return c;}
internal U32 dim_1u32(Rng1U32 r) {U32 c = r.max-r.min; return c;}
internal Rng1U32 union_1u32(Rng1U32 a, Rng1U32 b) {Rng1U32 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;}
internal Rng1U32 intersect_1u32(Rng1U32 a, Rng1U32 b) {Rng1U32 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;}
internal U32 clamp_1u32(Rng1U32 r, U32 v) {v = Clamp(r.min, v, r.max); return v;}
internal Rng1S32 rng_1s32(S32 min, S32 max) {Rng1S32 r = {min, max}; if(r.min > r.max) { Swap(S32, r.min, r.max); } return r;}
internal Rng1S32 shift_1s32(Rng1S32 r, S32 x) {r.min += x; r.max += x; return r;}
internal Rng1S32 pad_1s32(Rng1S32 r, S32 x) {r.min -= x; r.max += x; return r;}
internal S32 center_1s32(Rng1S32 r) {S32 c = (r.min+r.max)/2; return c;}
internal B32 contains_1s32(Rng1S32 r, S32 x) {B32 c = (r.min <= x && x < r.max); return c;}
internal S32 dim_1s32(Rng1S32 r) {S32 c = r.max-r.min; return c;}
internal Rng1S32 union_1s32(Rng1S32 a, Rng1S32 b) {Rng1S32 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;}
internal Rng1S32 intersect_1s32(Rng1S32 a, Rng1S32 b) {Rng1S32 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;}
internal S32 clamp_1s32(Rng1S32 r, S32 v) {v = Clamp(r.min, v, r.max); return v;}
internal Rng1U64 rng_1u64(U64 min, U64 max) {Rng1U64 r = {min, max}; if(r.min > r.max) { Swap(U64, r.min, r.max); } return r;}
internal Rng1U64 shift_1u64(Rng1U64 r, U64 x) {r.min += x; r.max += x; return r;}
internal Rng1U64 pad_1u64(Rng1U64 r, U64 x) {r.min -= x; r.max += x; return r;}
internal U64 center_1u64(Rng1U64 r) {U64 c = (r.min+r.max)/2; return c;}
internal B32 contains_1u64(Rng1U64 r, U64 x) {B32 c = (r.min <= x && x < r.max); return c;}
internal U64 dim_1u64(Rng1U64 r) {U64 c = r.max-r.min; return c;}
internal Rng1U64 union_1u64(Rng1U64 a, Rng1U64 b) {Rng1U64 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;}
internal Rng1U64 intersect_1u64(Rng1U64 a, Rng1U64 b) {Rng1U64 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;}
internal U64 clamp_1u64(Rng1U64 r, U64 v) {v = Clamp(r.min, v, r.max); return v;}
internal Rng1S64 rng_1s64(S64 min, S64 max) {Rng1S64 r = {min, max}; if(r.min > r.max) { Swap(S64, r.min, r.max); } return r;}
internal Rng1S64 shift_1s64(Rng1S64 r, S64 x) {r.min += x; r.max += x; return r;}
internal Rng1S64 pad_1s64(Rng1S64 r, S64 x) {r.min -= x; r.max += x; return r;}
internal S64 center_1s64(Rng1S64 r) {S64 c = (r.min+r.max)/2; return c;}
internal B32 contains_1s64(Rng1S64 r, S64 x) {B32 c = (r.min <= x && x < r.max); return c;}
internal S64 dim_1s64(Rng1S64 r) {S64 c = r.max-r.min; return c;}
internal Rng1S64 union_1s64(Rng1S64 a, Rng1S64 b) {Rng1S64 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;}
internal Rng1S64 intersect_1s64(Rng1S64 a, Rng1S64 b) {Rng1S64 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;}
internal S64 clamp_1s64(Rng1S64 r, S64 v) {v = Clamp(r.min, v, r.max); return v;}
internal Rng1F32 rng_1f32(F32 min, F32 max) {Rng1F32 r = {min, max}; if(r.min > r.max) { Swap(F32, r.min, r.max); } return r;}
internal Rng1F32 shift_1f32(Rng1F32 r, F32 x) {r.min += x; r.max += x; return r;}
internal Rng1F32 pad_1f32(Rng1F32 r, F32 x) {r.min -= x; r.max += x; return r;}
internal F32 center_1f32(Rng1F32 r) {F32 c = (r.min+r.max)/2; return c;}
internal B32 contains_1f32(Rng1F32 r, F32 x) {B32 c = (r.min <= x && x < r.max); return c;}
internal F32 dim_1f32(Rng1F32 r) {F32 c = r.max-r.min; return c;}
internal Rng1F32 union_1f32(Rng1F32 a, Rng1F32 b) {Rng1F32 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;}
internal Rng1F32 intersect_1f32(Rng1F32 a, Rng1F32 b) {Rng1F32 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;}
internal F32 clamp_1f32(Rng1F32 r, F32 v) {v = Clamp(r.min, v, r.max); return v;}
internal Rng2S16 rng_2s16(Vec2S16 min, Vec2S16 max) {Rng2S16 r = {min, max}; return r;}
internal Rng2S16 shift_2s16(Rng2S16 r, Vec2S16 x) {r.min = add_2s16(r.min, x); r.max = add_2s16(r.max, x); return r;}
internal Rng2S16 pad_2s16(Rng2S16 r, S16 x) {Vec2S16 xv = {x, x}; r.min = sub_2s16(r.min, xv); r.max = add_2s16(r.max, xv); return r;}
internal Vec2S16 center_2s16(Rng2S16 r) {Vec2S16 c = {(S16)((r.min.x+r.max.x)/2), (S16)((r.min.y+r.max.y)/2)}; return c;}
internal B32 contains_2s16(Rng2S16 r, Vec2S16 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;}
internal Vec2S16 dim_2s16(Rng2S16 r) {Vec2S16 dim = {(S16)(r.max.x-r.min.x), (S16)(r.max.y-r.min.y)}; return dim;}
internal Rng2S16 union_2s16(Rng2S16 a, Rng2S16 b) {Rng2S16 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;}
internal Rng2S16 intersect_2s16(Rng2S16 a, Rng2S16 b) {Rng2S16 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;}
internal Vec2S16 clamp_2s16(Rng2S16 r, Vec2S16 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;}
internal Rng2S32 rng_2s32(Vec2S32 min, Vec2S32 max) {Rng2S32 r = {min, max}; return r;}
internal Rng2S32 shift_2s32(Rng2S32 r, Vec2S32 x) {r.min = add_2s32(r.min, x); r.max = add_2s32(r.max, x); return r;}
internal Rng2S32 pad_2s32(Rng2S32 r, S32 x) {Vec2S32 xv = {x, x}; r.min = sub_2s32(r.min, xv); r.max = add_2s32(r.max, xv); return r;}
internal Vec2S32 center_2s32(Rng2S32 r) {Vec2S32 c = {(r.min.x+r.max.x)/2, (r.min.y+r.max.y)/2}; return c;}
internal B32 contains_2s32(Rng2S32 r, Vec2S32 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;}
internal Vec2S32 dim_2s32(Rng2S32 r) {Vec2S32 dim = {r.max.x-r.min.x, r.max.y-r.min.y}; return dim;}
internal Rng2S32 union_2s32(Rng2S32 a, Rng2S32 b) {Rng2S32 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;}
internal Rng2S32 intersect_2s32(Rng2S32 a, Rng2S32 b) {Rng2S32 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;}
internal Vec2S32 clamp_2s32(Rng2S32 r, Vec2S32 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;}
internal Rng2S64 rng_2s64(Vec2S64 min, Vec2S64 max) {Rng2S64 r = {min, max}; return r;}
internal Rng2S64 shift_2s64(Rng2S64 r, Vec2S64 x) {r.min = add_2s64(r.min, x); r.max = add_2s64(r.max, x); return r;}
internal Rng2S64 pad_2s64(Rng2S64 r, S64 x) {Vec2S64 xv = {x, x}; r.min = sub_2s64(r.min, xv); r.max = add_2s64(r.max, xv); return r;}
internal Vec2S64 center_2s64(Rng2S64 r) {Vec2S64 c = {(r.min.x+r.max.x)/2, (r.min.y+r.max.y)/2}; return c;}
internal B32 contains_2s64(Rng2S64 r, Vec2S64 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;}
internal Vec2S64 dim_2s64(Rng2S64 r) {Vec2S64 dim = {r.max.x-r.min.x, r.max.y-r.min.y}; return dim;}
internal Rng2S64 union_2s64(Rng2S64 a, Rng2S64 b) {Rng2S64 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;}
internal Rng2S64 intersect_2s64(Rng2S64 a, Rng2S64 b) {Rng2S64 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;}
internal Vec2S64 clamp_2s64(Rng2S64 r, Vec2S64 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;}
internal Rng2F32 rng_2f32(Vec2F32 min, Vec2F32 max) {Rng2F32 r = {min, max}; return r;}
internal Rng2F32 shift_2f32(Rng2F32 r, Vec2F32 x) {r.min = add_2f32(r.min, x); r.max = add_2f32(r.max, x); return r;}
internal Rng2F32 pad_2f32(Rng2F32 r, F32 x) {Vec2F32 xv = {x, x}; r.min = sub_2f32(r.min, xv); r.max = add_2f32(r.max, xv); return r;}
internal Vec2F32 center_2f32(Rng2F32 r) {Vec2F32 c = {(r.min.x+r.max.x)/2, (r.min.y+r.max.y)/2}; return c;}
internal B32 contains_2f32(Rng2F32 r, Vec2F32 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;}
internal Vec2F32 dim_2f32(Rng2F32 r) {Vec2F32 dim = {r.max.x-r.min.x, r.max.y-r.min.y}; return dim;}
internal Rng2F32 union_2f32(Rng2F32 a, Rng2F32 b) {Rng2F32 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;}
internal Rng2F32 intersect_2f32(Rng2F32 a, Rng2F32 b) {Rng2F32 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;}
internal Vec2F32 clamp_2f32(Rng2F32 r, Vec2F32 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;}
////////////////////////////////
//~ rjf: Miscellaneous Ops
internal Vec3F32
hsv_from_rgb(Vec3F32 rgb)
{
F32 c_max = Max(rgb.x, Max(rgb.y, rgb.z));
F32 c_min = Min(rgb.x, Min(rgb.y, rgb.z));
F32 delta = c_max - c_min;
F32 h = ((delta == 0.f) ? 0.f :
(c_max == rgb.x) ? mod_f32((rgb.y - rgb.z)/delta + 6.f, 6.f) :
(c_max == rgb.y) ? (rgb.z - rgb.x)/delta + 2.f :
(c_max == rgb.z) ? (rgb.x - rgb.y)/delta + 4.f :
0.f);
F32 s = (c_max == 0.f) ? 0.f : (delta/c_max);
F32 v = c_max;
Vec3F32 hsv = {h/6.f, s, v};
return hsv;
}
internal Vec3F32
rgb_from_hsv(Vec3F32 hsv)
{
F32 h = mod_f32(hsv.x * 360.f, 360.f);
F32 s = hsv.y;
F32 v = hsv.z;
F32 c = v*s;
F32 x = c*(1.f - abs_f32(mod_f32(h/60.f, 2.f) - 1.f));
F32 m = v - c;
F32 r = 0;
F32 g = 0;
F32 b = 0;
if ((h >= 0.f && h < 60.f) || (h >= 360.f && h < 420.f)){
r = c;
g = x;
b = 0;
}
else if (h >= 60.f && h < 120.f){
r = x;
g = c;
b = 0;
}
else if (h >= 120.f && h < 180.f){
r = 0;
g = c;
b = x;
}
else if (h >= 180.f && h < 240.f){
r = 0;
g = x;
b = c;
}
else if (h >= 240.f && h < 300.f){
r = x;
g = 0;
b = c;
}
else if ((h >= 300.f && h <= 360.f) || (h >= -60.f && h <= 0.f)){
r = c;
g = 0;
b = x;
}
Vec3F32 rgb = {r + m, g + m, b + m};
return(rgb);
}
internal Vec4F32
hsva_from_rgba(Vec4F32 rgba)
{
Vec3F32 rgb = v3f32(rgba.x, rgba.y, rgba.z);
Vec3F32 hsv = hsv_from_rgb(rgb);
Vec4F32 hsva = v4f32(hsv.x, hsv.y, hsv.z, rgba.w);
return hsva;
}
internal Vec4F32
rgba_from_hsva(Vec4F32 hsva)
{
Vec3F32 hsv = v3f32(hsva.x, hsva.y, hsva.z);
Vec3F32 rgb = rgb_from_hsv(hsv);
Vec4F32 rgba = v4f32(rgb.x, rgb.y, rgb.z, hsva.w);
return rgba;
}
internal Vec4F32
rgba_from_u32(U32 hex)
{
Vec4F32 result = v4f32(((hex&0xff000000)>>24)/255.f,
((hex&0x00ff0000)>>16)/255.f,
((hex&0x0000ff00)>> 8)/255.f,
((hex&0x000000ff)>> 0)/255.f);
return result;
}
internal U32
u32_from_rgba(Vec4F32 rgba)
{
U32 result = 0;
result |= ((U32)((U8)(rgba.x*255.f))) << 24;
result |= ((U32)((U8)(rgba.y*255.f))) << 16;
result |= ((U32)((U8)(rgba.z*255.f))) << 8;
result |= ((U32)((U8)(rgba.w*255.f))) << 0;
return result;
}
////////////////////////////////
//~ rjf: List Type Functions
internal void
rng1s64_list_push(Arena *arena, Rng1S64List *list, Rng1S64 rng)
{
Rng1S64Node *n = push_array(arena, Rng1S64Node, 1);
MemoryCopyStruct(&n->v, &rng);
SLLQueuePush(list->first, list->last, n);
list->count += 1;
}
internal Rng1S64Array
rng1s64_array_from_list(Arena *arena, Rng1S64List *list)
{
Rng1S64Array arr = {0};
arr.count = list->count;
arr.v = push_array_no_zero(arena, Rng1S64, arr.count);
U64 idx = 0;
for(Rng1S64Node *n = list->first; n != 0; n = n->next)
{
arr.v[idx] = n->v;
idx += 1;
}
return arr;
}
+648
View File
@@ -0,0 +1,648 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_MATH_H
#define BASE_MATH_H
////////////////////////////////
//~ rjf: Vector Types
//- rjf: 2-vectors
typedef union Vec2F32 Vec2F32;
union Vec2F32
{
struct
{
F32 x;
F32 y;
};
F32 v[2];
};
typedef union Vec2S64 Vec2S64;
union Vec2S64
{
struct
{
S64 x;
S64 y;
};
S64 v[2];
};
typedef union Vec2S32 Vec2S32;
union Vec2S32
{
struct
{
S32 x;
S32 y;
};
S32 v[2];
};
typedef union Vec2S16 Vec2S16;
union Vec2S16
{
struct
{
S16 x;
S16 y;
};
S16 v[2];
};
//- rjf: 3-vectors
typedef union Vec3F32 Vec3F32;
union Vec3F32
{
struct
{
F32 x;
F32 y;
F32 z;
};
struct
{
Vec2F32 xy;
F32 _z0;
};
struct
{
F32 _x0;
Vec2F32 yz;
};
F32 v[3];
};
typedef union Vec3S32 Vec3S32;
union Vec3S32
{
struct
{
S32 x;
S32 y;
S32 z;
};
struct
{
Vec2S32 xy;
S32 _z0;
};
struct
{
S32 _x0;
Vec2S32 yz;
};
S32 v[3];
};
//- rjf: 4-vectors
typedef union Vec4F32 Vec4F32;
union Vec4F32
{
struct
{
F32 x;
F32 y;
F32 z;
F32 w;
};
struct
{
Vec2F32 xy;
Vec2F32 zw;
};
struct
{
Vec3F32 xyz;
F32 _z0;
};
struct
{
F32 _x0;
Vec3F32 yzw;
};
F32 v[4];
};
typedef union Vec4S32 Vec4S32;
union Vec4S32
{
struct
{
S32 x;
S32 y;
S32 z;
S32 w;
};
struct
{
Vec2S32 xy;
Vec2S32 zw;
};
struct
{
Vec3S32 xyz;
S32 _z0;
};
struct
{
S32 _x0;
Vec3S32 yzw;
};
S32 v[4];
};
////////////////////////////////
//~ rjf: Matrix Types
typedef struct Mat3x3F32 Mat3x3F32;
struct Mat3x3F32
{
F32 v[3][3];
};
typedef struct Mat4x4F32 Mat4x4F32;
struct Mat4x4F32
{
F32 v[4][4];
};
////////////////////////////////
//~ rjf: Range Types
//- rjf: 1-range
typedef union Rng1U32 Rng1U32;
union Rng1U32
{
struct
{
U32 min;
U32 max;
};
U32 v[2];
};
typedef union Rng1S32 Rng1S32;
union Rng1S32
{
struct
{
S32 min;
S32 max;
};
S32 v[2];
};
typedef union Rng1U64 Rng1U64;
union Rng1U64
{
struct
{
U64 min;
U64 max;
};
U64 v[2];
};
typedef union Rng1S64 Rng1S64;
union Rng1S64
{
struct
{
S64 min;
S64 max;
};
S64 v[2];
};
typedef union Rng1F32 Rng1F32;
union Rng1F32
{
struct
{
F32 min;
F32 max;
};
F32 v[2];
};
//- rjf: 2-range (rectangles)
typedef union Rng2S16 Rng2S16;
union Rng2S16
{
struct
{
Vec2S16 min;
Vec2S16 max;
};
struct
{
Vec2S16 p0;
Vec2S16 p1;
};
struct
{
S16 x0;
S16 y0;
S16 x1;
S16 y1;
};
Vec2S16 v[2];
};
typedef union Rng2S32 Rng2S32;
union Rng2S32
{
struct
{
Vec2S32 min;
Vec2S32 max;
};
struct
{
Vec2S32 p0;
Vec2S32 p1;
};
struct
{
S32 x0;
S32 y0;
S32 x1;
S32 y1;
};
Vec2S32 v[2];
};
typedef union Rng2F32 Rng2F32;
union Rng2F32
{
struct
{
Vec2F32 min;
Vec2F32 max;
};
struct
{
Vec2F32 p0;
Vec2F32 p1;
};
struct
{
F32 x0;
F32 y0;
F32 x1;
F32 y1;
};
Vec2F32 v[2];
};
typedef union Rng2S64 Rng2S64;
union Rng2S64
{
struct
{
Vec2S64 min;
Vec2S64 max;
};
struct
{
Vec2S64 p0;
Vec2S64 p1;
};
struct
{
S64 x0;
S64 y0;
S64 x1;
S64 y1;
};
Vec2S64 v[2];
};
////////////////////////////////
//~ rjf: List Types
typedef struct Rng1S64Node Rng1S64Node;
struct Rng1S64Node
{
Rng1S64Node *next;
Rng1S64 v;
};
typedef struct Rng1S64List Rng1S64List;
struct Rng1S64List
{
Rng1S64Node *first;
Rng1S64Node *last;
U64 count;
};
typedef struct Rng1S64Array Rng1S64Array;
struct Rng1S64Array
{
Rng1S64 *v;
U64 count;
};
////////////////////////////////
//~ rjf: Scalar Ops
#define abs_s64(v) (S64)llabs(v)
#define sqrt_f32(v) sqrtf(v)
#define mod_f32(a, b) fmodf((a), (b))
#define pow_f32(b, e) powf((b), (e))
#define ceil_f32(v) ceilf(v)
#define floor_f32(v) floorf(v)
#define round_f32(v) roundf(v)
#define abs_f32(v) fabsf(v)
#define radians_from_turns_f32(v) ((v)*2*3.1415926535897f)
#define turns_from_radians_f32(v) ((v)/2*3.1415926535897f)
#define degrees_from_turns_f32(v) ((v)*360.f)
#define turns_from_degrees_f32(v) ((v)/360.f)
#define degrees_from_radians_f32(v) (degrees_from_turns_f32(turns_from_radians_f32(v)))
#define radians_from_degrees_f32(v) (radians_from_turns_f32(turns_from_degrees_f32(v)))
#define sin_f32(v) sinf(radians_from_turns_f32(v))
#define cos_f32(v) cosf(radians_from_turns_f32(v))
#define tan_f32(v) tanf(radians_from_turns_f32(v))
#define sqrt_f64(v) sqrt(v)
#define mod_f64(a, b) fmod((a), (b))
#define pow_f64(b, e) pow((b), (e))
#define ceil_f64(v) ceil(v)
#define floor_f64(v) floor(v)
#define round_f64(v) round(v)
#define abs_f64(v) fabs(v)
#define radians_from_turns_f64(v) ((v)*2*3.1415926535897)
#define turns_from_radians_f64(v) ((v)/2*3.1415926535897)
#define degrees_from_turns_f64(v) ((v)*360.0)
#define turns_from_degrees_f64(v) ((v)/360.0)
#define degrees_from_radians_f64(v) (degrees_from_turns_f64(turns_from_radians_f64(v)))
#define radians_from_degrees_f64(v) (radians_from_turns_f64(turns_from_degrees_f64(v)))
#define sin_f64(v) sin(radians_from_turns_f64(v))
#define cos_f64(v) cos(radians_from_turns_f64(v))
#define tan_f64(v) tan(radians_from_turns_f64(v))
internal F32 mix_1f32(F32 a, F32 b, F32 t);
internal F64 mix_1f64(F64 a, F64 b, F64 t);
////////////////////////////////
//~ rjf: Vector Ops
#define v2f32(x, y) vec_2f32((x), (y))
internal Vec2F32 vec_2f32(F32 x, F32 y);
internal Vec2F32 add_2f32(Vec2F32 a, Vec2F32 b);
internal Vec2F32 sub_2f32(Vec2F32 a, Vec2F32 b);
internal Vec2F32 mul_2f32(Vec2F32 a, Vec2F32 b);
internal Vec2F32 div_2f32(Vec2F32 a, Vec2F32 b);
internal Vec2F32 scale_2f32(Vec2F32 v, F32 s);
internal F32 dot_2f32(Vec2F32 a, Vec2F32 b);
internal F32 length_squared_2f32(Vec2F32 v);
internal F32 length_2f32(Vec2F32 v);
internal Vec2F32 normalize_2f32(Vec2F32 v);
internal Vec2F32 mix_2f32(Vec2F32 a, Vec2F32 b, F32 t);
#define v2s64(x, y) vec_2s64((x), (y))
internal Vec2S64 vec_2s64(S64 x, S64 y);
internal Vec2S64 add_2s64(Vec2S64 a, Vec2S64 b);
internal Vec2S64 sub_2s64(Vec2S64 a, Vec2S64 b);
internal Vec2S64 mul_2s64(Vec2S64 a, Vec2S64 b);
internal Vec2S64 div_2s64(Vec2S64 a, Vec2S64 b);
internal Vec2S64 scale_2s64(Vec2S64 v, S64 s);
internal S64 dot_2s64(Vec2S64 a, Vec2S64 b);
internal S64 length_squared_2s64(Vec2S64 v);
internal S64 length_2s64(Vec2S64 v);
internal Vec2S64 normalize_2s64(Vec2S64 v);
internal Vec2S64 mix_2s64(Vec2S64 a, Vec2S64 b, F32 t);
#define v2s32(x, y) vec_2s32((x), (y))
internal Vec2S32 vec_2s32(S32 x, S32 y);
internal Vec2S32 add_2s32(Vec2S32 a, Vec2S32 b);
internal Vec2S32 sub_2s32(Vec2S32 a, Vec2S32 b);
internal Vec2S32 mul_2s32(Vec2S32 a, Vec2S32 b);
internal Vec2S32 div_2s32(Vec2S32 a, Vec2S32 b);
internal Vec2S32 scale_2s32(Vec2S32 v, S32 s);
internal S32 dot_2s32(Vec2S32 a, Vec2S32 b);
internal S32 length_squared_2s32(Vec2S32 v);
internal S32 length_2s32(Vec2S32 v);
internal Vec2S32 normalize_2s32(Vec2S32 v);
internal Vec2S32 mix_2s32(Vec2S32 a, Vec2S32 b, F32 t);
#define v2s16(x, y) vec_2s16((x), (y))
internal Vec2S16 vec_2s16(S16 x, S16 y);
internal Vec2S16 add_2s16(Vec2S16 a, Vec2S16 b);
internal Vec2S16 sub_2s16(Vec2S16 a, Vec2S16 b);
internal Vec2S16 mul_2s16(Vec2S16 a, Vec2S16 b);
internal Vec2S16 div_2s16(Vec2S16 a, Vec2S16 b);
internal Vec2S16 scale_2s16(Vec2S16 v, S16 s);
internal S16 dot_2s16(Vec2S16 a, Vec2S16 b);
internal S16 length_squared_2s16(Vec2S16 v);
internal S16 length_2s16(Vec2S16 v);
internal Vec2S16 normalize_2s16(Vec2S16 v);
internal Vec2S16 mix_2s16(Vec2S16 a, Vec2S16 b, F32 t);
#define v3f32(x, y, z) vec_3f32((x), (y), (z))
internal Vec3F32 vec_3f32(F32 x, F32 y, F32 z);
internal Vec3F32 add_3f32(Vec3F32 a, Vec3F32 b);
internal Vec3F32 sub_3f32(Vec3F32 a, Vec3F32 b);
internal Vec3F32 mul_3f32(Vec3F32 a, Vec3F32 b);
internal Vec3F32 div_3f32(Vec3F32 a, Vec3F32 b);
internal Vec3F32 scale_3f32(Vec3F32 v, F32 s);
internal F32 dot_3f32(Vec3F32 a, Vec3F32 b);
internal F32 length_squared_3f32(Vec3F32 v);
internal F32 length_3f32(Vec3F32 v);
internal Vec3F32 normalize_3f32(Vec3F32 v);
internal Vec3F32 mix_3f32(Vec3F32 a, Vec3F32 b, F32 t);
internal Vec3F32 cross_3f32(Vec3F32 a, Vec3F32 b);
#define v3s32(x, y, z) vec_3s32((x), (y), (z))
internal Vec3S32 vec_3s32(S32 x, S32 y, S32 z);
internal Vec3S32 add_3s32(Vec3S32 a, Vec3S32 b);
internal Vec3S32 sub_3s32(Vec3S32 a, Vec3S32 b);
internal Vec3S32 mul_3s32(Vec3S32 a, Vec3S32 b);
internal Vec3S32 div_3s32(Vec3S32 a, Vec3S32 b);
internal Vec3S32 scale_3s32(Vec3S32 v, S32 s);
internal S32 dot_3s32(Vec3S32 a, Vec3S32 b);
internal S32 length_squared_3s32(Vec3S32 v);
internal S32 length_3s32(Vec3S32 v);
internal Vec3S32 normalize_3s32(Vec3S32 v);
internal Vec3S32 mix_3s32(Vec3S32 a, Vec3S32 b, F32 t);
internal Vec3S32 cross_3s32(Vec3S32 a, Vec3S32 b);
#define v4f32(x, y, z, w) vec_4f32((x), (y), (z), (w))
internal Vec4F32 vec_4f32(F32 x, F32 y, F32 z, F32 w);
internal Vec4F32 add_4f32(Vec4F32 a, Vec4F32 b);
internal Vec4F32 sub_4f32(Vec4F32 a, Vec4F32 b);
internal Vec4F32 mul_4f32(Vec4F32 a, Vec4F32 b);
internal Vec4F32 div_4f32(Vec4F32 a, Vec4F32 b);
internal Vec4F32 scale_4f32(Vec4F32 v, F32 s);
internal F32 dot_4f32(Vec4F32 a, Vec4F32 b);
internal F32 length_squared_4f32(Vec4F32 v);
internal F32 length_4f32(Vec4F32 v);
internal Vec4F32 normalize_4f32(Vec4F32 v);
internal Vec4F32 mix_4f32(Vec4F32 a, Vec4F32 b, F32 t);
#define v4s32(x, y, z, w) vec_4s32((x), (y), (z), (w))
internal Vec4S32 vec_4s32(S32 x, S32 y, S32 z, S32 w);
internal Vec4S32 add_4s32(Vec4S32 a, Vec4S32 b);
internal Vec4S32 sub_4s32(Vec4S32 a, Vec4S32 b);
internal Vec4S32 mul_4s32(Vec4S32 a, Vec4S32 b);
internal Vec4S32 div_4s32(Vec4S32 a, Vec4S32 b);
internal Vec4S32 scale_4s32(Vec4S32 v, S32 s);
internal S32 dot_4s32(Vec4S32 a, Vec4S32 b);
internal S32 length_squared_4s32(Vec4S32 v);
internal S32 length_4s32(Vec4S32 v);
internal Vec4S32 normalize_4s32(Vec4S32 v);
internal Vec4S32 mix_4s32(Vec4S32 a, Vec4S32 b, F32 t);
////////////////////////////////
//~ rjf: Matrix Ops
internal Mat3x3F32 mat_3x3f32(F32 diagonal);
internal Mat3x3F32 make_translate_3x3f32(Vec2F32 delta);
internal Mat3x3F32 mul_3x3f32(Mat3x3F32 a, Mat3x3F32 b);
internal Mat4x4F32 mat_4x4f32(F32 diagonal);
internal Mat4x4F32 make_translate_4x4f32(Vec3F32 delta);
internal Mat4x4F32 make_scale_4x4f32(Vec3F32 scale);
internal Mat4x4F32 make_perspective_4x4f32(F32 fov, F32 aspect_ratio, F32 near_z, F32 far_z);
internal Mat4x4F32 make_orthographic_4x4f32(F32 left, F32 right, F32 bottom, F32 top, F32 near_z, F32 far_z);
internal Mat4x4F32 make_look_at_4x4f32(Vec3F32 eye, Vec3F32 center, Vec3F32 up);
internal Mat4x4F32 make_rotate_4x4f32(Vec3F32 axis, F32 turns);
internal Mat4x4F32 mul_4x4f32(Mat4x4F32 a, Mat4x4F32 b);
internal Mat4x4F32 scale_4x4f32(Mat4x4F32 m, F32 scale);
internal Mat4x4F32 inverse_4x4f32(Mat4x4F32 m);
internal Mat4x4F32 derotate_4x4f32(Mat4x4F32 mat);
////////////////////////////////
//~ rjf: Range Ops
#define r1u32(min, max) rng_1u32((min), (max))
internal Rng1U32 rng_1u32(U32 min, U32 max);
internal Rng1U32 shift_1u32(Rng1U32 r, U32 x);
internal Rng1U32 pad_1u32(Rng1U32 r, U32 x);
internal U32 center_1u32(Rng1U32 r);
internal B32 contains_1u32(Rng1U32 r, U32 x);
internal U32 dim_1u32(Rng1U32 r);
internal Rng1U32 union_1u32(Rng1U32 a, Rng1U32 b);
internal Rng1U32 intersect_1u32(Rng1U32 a, Rng1U32 b);
internal U32 clamp_1u32(Rng1U32 r, U32 v);
#define r1s32(min, max) rng_1s32((min), (max))
internal Rng1S32 rng_1s32(S32 min, S32 max);
internal Rng1S32 shift_1s32(Rng1S32 r, S32 x);
internal Rng1S32 pad_1s32(Rng1S32 r, S32 x);
internal S32 center_1s32(Rng1S32 r);
internal B32 contains_1s32(Rng1S32 r, S32 x);
internal S32 dim_1s32(Rng1S32 r);
internal Rng1S32 union_1s32(Rng1S32 a, Rng1S32 b);
internal Rng1S32 intersect_1s32(Rng1S32 a, Rng1S32 b);
internal S32 clamp_1s32(Rng1S32 r, S32 v);
#define r1u64(min, max) rng_1u64((min), (max))
internal Rng1U64 rng_1u64(U64 min, U64 max);
internal Rng1U64 shift_1u64(Rng1U64 r, U64 x);
internal Rng1U64 pad_1u64(Rng1U64 r, U64 x);
internal U64 center_1u64(Rng1U64 r);
internal B32 contains_1u64(Rng1U64 r, U64 x);
internal U64 dim_1u64(Rng1U64 r);
internal Rng1U64 union_1u64(Rng1U64 a, Rng1U64 b);
internal Rng1U64 intersect_1u64(Rng1U64 a, Rng1U64 b);
internal U64 clamp_1u64(Rng1U64 r, U64 v);
#define r1s64(min, max) rng_1s64((min), (max))
internal Rng1S64 rng_1s64(S64 min, S64 max);
internal Rng1S64 shift_1s64(Rng1S64 r, S64 x);
internal Rng1S64 pad_1s64(Rng1S64 r, S64 x);
internal S64 center_1s64(Rng1S64 r);
internal B32 contains_1s64(Rng1S64 r, S64 x);
internal S64 dim_1s64(Rng1S64 r);
internal Rng1S64 union_1s64(Rng1S64 a, Rng1S64 b);
internal Rng1S64 intersect_1s64(Rng1S64 a, Rng1S64 b);
internal S64 clamp_1s64(Rng1S64 r, S64 v);
#define r1f32(min, max) rng_1f32((min), (max))
internal Rng1F32 rng_1f32(F32 min, F32 max);
internal Rng1F32 shift_1f32(Rng1F32 r, F32 x);
internal Rng1F32 pad_1f32(Rng1F32 r, F32 x);
internal F32 center_1f32(Rng1F32 r);
internal B32 contains_1f32(Rng1F32 r, F32 x);
internal F32 dim_1f32(Rng1F32 r);
internal Rng1F32 union_1f32(Rng1F32 a, Rng1F32 b);
internal Rng1F32 intersect_1f32(Rng1F32 a, Rng1F32 b);
internal F32 clamp_1f32(Rng1F32 r, F32 v);
#define r2s16(min, max) rng_2s16((min), (max))
#define r2s16p(x, y, z, w) r2s16(v2s16((x), (y)), v2s16((z), (w)))
internal Rng2S16 rng_2s16(Vec2S16 min, Vec2S16 max);
internal Rng2S16 shift_2s16(Rng2S16 r, Vec2S16 x);
internal Rng2S16 pad_2s16(Rng2S16 r, S16 x);
internal Vec2S16 center_2s16(Rng2S16 r);
internal B32 contains_2s16(Rng2S16 r, Vec2S16 x);
internal Vec2S16 dim_2s16(Rng2S16 r);
internal Rng2S16 union_2s16(Rng2S16 a, Rng2S16 b);
internal Rng2S16 intersect_2s16(Rng2S16 a, Rng2S16 b);
internal Vec2S16 clamp_2s16(Rng2S16 r, Vec2S16 v);
#define r2s32(min, max) rng_2s32((min), (max))
#define r2s32p(x, y, z, w) r2s32(v2s32((x), (y)), v2s32((z), (w)))
internal Rng2S32 rng_2s32(Vec2S32 min, Vec2S32 max);
internal Rng2S32 shift_2s32(Rng2S32 r, Vec2S32 x);
internal Rng2S32 pad_2s32(Rng2S32 r, S32 x);
internal Vec2S32 center_2s32(Rng2S32 r);
internal B32 contains_2s32(Rng2S32 r, Vec2S32 x);
internal Vec2S32 dim_2s32(Rng2S32 r);
internal Rng2S32 union_2s32(Rng2S32 a, Rng2S32 b);
internal Rng2S32 intersect_2s32(Rng2S32 a, Rng2S32 b);
internal Vec2S32 clamp_2s32(Rng2S32 r, Vec2S32 v);
#define r2s64(min, max) rng_2s64((min), (max))
#define r2s64p(x, y, z, w) r2s64(v2s64((x), (y)), v2s64((z), (w)))
internal Rng2S64 rng_2s64(Vec2S64 min, Vec2S64 max);
internal Rng2S64 shift_2s64(Rng2S64 r, Vec2S64 x);
internal Rng2S64 pad_2s64(Rng2S64 r, S64 x);
internal Vec2S64 center_2s64(Rng2S64 r);
internal B32 contains_2s64(Rng2S64 r, Vec2S64 x);
internal Vec2S64 dim_2s64(Rng2S64 r);
internal Rng2S64 union_2s64(Rng2S64 a, Rng2S64 b);
internal Rng2S64 intersect_2s64(Rng2S64 a, Rng2S64 b);
internal Vec2S64 clamp_2s64(Rng2S64 r, Vec2S64 v);
#define r2f32(min, max) rng_2f32((min), (max))
#define r2f32p(x, y, z, w) r2f32(v2f32((x), (y)), v2f32((z), (w)))
internal Rng2F32 rng_2f32(Vec2F32 min, Vec2F32 max);
internal Rng2F32 shift_2f32(Rng2F32 r, Vec2F32 x);
internal Rng2F32 pad_2f32(Rng2F32 r, F32 x);
internal Vec2F32 center_2f32(Rng2F32 r);
internal B32 contains_2f32(Rng2F32 r, Vec2F32 x);
internal Vec2F32 dim_2f32(Rng2F32 r);
internal Rng2F32 union_2f32(Rng2F32 a, Rng2F32 b);
internal Rng2F32 intersect_2f32(Rng2F32 a, Rng2F32 b);
internal Vec2F32 clamp_2f32(Rng2F32 r, Vec2F32 v);
////////////////////////////////
//~ rjf: Miscellaneous Ops
internal Vec3F32 hsv_from_rgb(Vec3F32 rgb);
internal Vec3F32 rgb_from_hsv(Vec3F32 hsv);
internal Vec4F32 hsva_from_rgba(Vec4F32 rgba);
internal Vec4F32 rgba_from_hsva(Vec4F32 hsva);
internal Vec4F32 rgba_from_u32(U32 hex);
internal U32 u32_from_rgba(Vec4F32 rgba);
#define rgba_from_u32_lit_comp(h) { (((h)&0xff000000)>>24)/255.f, (((h)&0x00ff0000)>>16)/255.f, (((h)&0x0000ff00)>> 8)/255.f, (((h)&0x000000ff)>> 0)/255.f }
////////////////////////////////
//~ rjf: List Type Functions
internal void rng1s64_list_push(Arena *arena, Rng1S64List *list, Rng1S64 rng);
internal Rng1S64Array rng1s64_array_from_list(Arena *arena, Rng1S64List *list);
#endif // BASE_MATH_H
File diff suppressed because it is too large Load Diff
+351
View File
@@ -0,0 +1,351 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_STRING_H
#define BASE_STRING_H
////////////////////////////////
//~ rjf: Third Party Includes
#define STB_SPRINTF_DECORATE(name) raddbg_##name
#include "third_party/stb/stb_sprintf.h"
////////////////////////////////
//~ rjf: String Types
typedef struct String8 String8;
struct String8
{
U8 *str;
U64 size;
};
typedef struct String16 String16;
struct String16
{
U16 *str;
U64 size;
};
typedef struct String32 String32;
struct String32
{
U32 *str;
U64 size;
};
////////////////////////////////
//~ rjf: String List & Array Types
typedef struct String8Node String8Node;
struct String8Node
{
String8Node *next;
String8 string;
};
typedef struct String8MetaNode String8MetaNode;
struct String8MetaNode
{
String8MetaNode *next;
String8Node *node;
};
typedef struct String8List String8List;
struct String8List
{
String8Node *first;
String8Node *last;
U64 node_count;
U64 total_size;
};
typedef struct String8Array String8Array;
struct String8Array
{
String8 *strings;
U64 count;
};
////////////////////////////////
//~ rjf: String Matching, Splitting, & Joining Types
typedef U32 StringMatchFlags;
enum
{
StringMatchFlag_CaseInsensitive = (1 << 0),
StringMatchFlag_RightSideSloppy = (1 << 1),
StringMatchFlag_SlashInsensitive = (1 << 2),
};
typedef U32 StringSplitFlags;
enum
{
StringSplitFlag_KeepEmpties = (1 << 0),
};
typedef enum PathStyle
{
PathStyle_Relative,
PathStyle_WindowsAbsolute,
PathStyle_UnixAbsolute,
#if OS_WINDOWS
PathStyle_SystemAbsolute = PathStyle_WindowsAbsolute
#elif OS_LINUX
PathStyle_SystemAbsolute = PathStyle_UnixAbsolute
#else
# error "absolute path style is undefined for this OS"
#endif
}
PathStyle;
typedef struct StringJoin StringJoin;
struct StringJoin
{
String8 pre;
String8 sep;
String8 post;
};
////////////////////////////////
//~ rjf: String Pair Types
typedef struct String8TxtPtPair String8TxtPtPair;
struct String8TxtPtPair
{
String8 string;
TxtPt pt;
};
////////////////////////////////
//~ rjf: UTF Decoding Types
typedef struct UnicodeDecode UnicodeDecode;
struct UnicodeDecode
{
U32 inc;
U32 codepoint;
};
////////////////////////////////
//~ rjf: Character Classification & Conversion Functions
internal B32 char_is_space(U8 c);
internal B32 char_is_upper(U8 c);
internal B32 char_is_lower(U8 c);
internal B32 char_is_alpha(U8 c);
internal B32 char_is_slash(U8 c);
internal B32 char_is_digit(U8 c, U32 base);
internal U8 char_to_lower(U8 c);
internal U8 char_to_upper(U8 c);
internal U8 char_to_correct_slash(U8 c);
////////////////////////////////
//~ rjf: C-String Measurement
internal U64 cstring8_length(U8 *c);
internal U64 cstring16_length(U16 *c);
internal U64 cstring32_length(U32 *c);
////////////////////////////////
//~ rjf: String Constructors
#define str8_lit(S) str8((U8*)(S), sizeof(S) - 1)
#define str8_lit_comp(S) {(U8*)(S), sizeof(S) - 1,}
#define str8_varg(S) (int)((S).size), ((S).str)
#define str8_array(S,C) str8((U8*)(S), sizeof(*(S))*(C))
#define str8_array_fixed(S) str8((U8*)(S), sizeof(S))
#define str8_struct(S) str8((U8*)(S), sizeof(*(S)))
internal String8 str8(U8 *str, U64 size);
internal String8 str8_range(U8 *first, U8 *one_past_last);
internal String8 str8_zero(void);
internal String16 str16(U16 *str, U64 size);
internal String16 str16_range(U16 *first, U16 *one_past_last);
internal String16 str16_zero(void);
internal String32 str32(U32 *str, U64 size);
internal String32 str32_range(U32 *first, U32 *one_past_last);
internal String32 str32_zero(void);
internal String8 str8_cstring(char *c);
internal String16 str16_cstring(U16 *c);
internal String32 str32_cstring(U32 *c);
internal String8 str8_cstring_capped(void *cstr, void *cap);
////////////////////////////////
//~ rjf: String Stylization
internal String8 upper_from_str8(Arena *arena, String8 string);
internal String8 lower_from_str8(Arena *arena, String8 string);
internal String8 backslashed_from_str8(Arena *arena, String8 string);
////////////////////////////////
//~ rjf: String Matching
internal B32 str8_match(String8 a, String8 b, StringMatchFlags flags);
internal U64 str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
internal B32 str8_ends_with(String8 string, String8 end, StringMatchFlags flags);
////////////////////////////////
//~ rjf: String Slicing
internal String8 str8_substr(String8 str, Rng1U64 range);
internal String8 str8_prefix(String8 str, U64 size);
internal String8 str8_skip(String8 str, U64 amt);
internal String8 str8_postfix(String8 str, U64 size);
internal String8 str8_chop(String8 str, U64 amt);
internal String8 str8_skip_chop_whitespace(String8 string);
////////////////////////////////
//~ rjf: String Formatting & Copying
internal String8 push_str8_cat(Arena *arena, String8 s1, String8 s2);
internal String8 push_str8_copy(Arena *arena, String8 s);
internal String8 push_str8fv(Arena *arena, char *fmt, va_list args);
internal String8 push_str8f(Arena *arena, char *fmt, ...);
////////////////////////////////
//~ rjf: String <=> Integer Conversions
//- rjf: string -> integer
internal S64 sign_from_str8(String8 string, String8 *string_tail);
internal B32 str8_is_integer(String8 string, U32 radix);
internal U64 u64_from_str8(String8 string, U32 radix);
internal S64 s64_from_str8(String8 string, U32 radix);
internal B32 try_u64_from_str8_c_rules(String8 string, U64 *x);
internal B32 try_s64_from_str8_c_rules(String8 string, S64 *x);
//- rjf: string -> integer (base64 & base16)
internal U64 base64_size_from_data_size(U64 size_in_bytes);
internal U64 base64_from_data(U8 *dst, U8 *src, U64 src_size);
internal U64 base16_size_from_data_size(U64 size_in_bytes);
internal U64 base16_from_data(U8 *dst, U8 *src, U64 src_size);
//- rjf: integer -> string
internal String8 str8_from_memory_size(Arena *arena, U64 z);
internal String8 str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
internal String8 str8_from_s64(Arena *arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator);
////////////////////////////////
//~ rjf: String <=> Float Conversions
internal F64 f64_from_str8(String8 string);
////////////////////////////////
//~ rjf: String List Construction Functions
internal String8Node* str8_list_push_node(String8List *list, String8Node *node);
internal String8Node* str8_list_push_node_set_string(String8List *list, String8Node *node, String8 string);
internal String8Node* str8_list_push_node_front(String8List *list, String8Node *node);
internal String8Node* str8_list_push_node_front_set_string(String8List *list, String8Node *node, String8 string);
internal String8Node* str8_list_push(Arena *arena, String8List *list, String8 string);
internal String8Node* str8_list_push_front(Arena *arena, String8List *list, String8 string);
internal void str8_list_concat_in_place(String8List *list, String8List *to_push);
internal String8Node* str8_list_push_aligner(Arena *arena, String8List *list, U64 min, U64 align);
internal String8Node* str8_list_pushf(Arena *arena, String8List *list, char *fmt, ...);
internal String8Node* str8_list_push_frontf(Arena *arena, String8List *list, char *fmt, ...);
internal String8List str8_list_copy(Arena *arena, String8List *list);
#define str8_list_first(list) ((list)->first ? (list)->first->string : str8_zero())
////////////////////////////////
//~ rjf: String Splitting & Joining
internal String8List str8_split(Arena *arena, String8 string, U8 *split_chars, U64 split_char_count, StringSplitFlags flags);
internal String8List str8_split_by_string_chars(Arena *arena, String8 string, String8 split_chars, StringSplitFlags flags);
internal String8List str8_list_split_by_string_chars(Arena *arena, String8List list, String8 split_chars, StringSplitFlags flags);
internal String8 str8_list_join(Arena *arena, String8List *list, StringJoin *optional_params);
internal void str8_list_from_flags(Arena *arena, String8List *list, U32 flags, String8 *flag_string_table, U32 flag_string_count);
////////////////////////////////
//~ rjf; String Arrays
internal String8Array str8_array_from_list(Arena *arena, String8List *list);
internal String8Array str8_array_reserve(Arena *arena, U64 count);
////////////////////////////////
//~ rjf: String Path Helpers
internal String8 str8_chop_last_slash(String8 string);
internal String8 str8_skip_last_slash(String8 string);
internal String8 str8_chop_last_dot(String8 string);
internal String8 str8_skip_last_dot(String8 string);
internal PathStyle path_style_from_str8(String8 string);
internal String8List str8_split_path(Arena *arena, String8 string);
internal void str8_path_list_resolve_dots_in_place(String8List *path, PathStyle style);
internal String8 str8_path_list_join_by_style(Arena *arena, String8List *path, PathStyle style);
internal String8TxtPtPair str8_txt_pt_pair_from_string(String8 string);
////////////////////////////////
//~ rjf: UTF-8 & UTF-16 Decoding/Encoding
internal UnicodeDecode utf8_decode(U8 *str, U64 max);
internal UnicodeDecode utf16_decode(U16 *str, U64 max);
internal U32 utf8_encode(U8 *str, U32 codepoint);
internal U32 utf16_encode(U16 *str, U32 codepoint);
internal U32 utf8_from_utf32_single(U8 *buffer, U32 character);
////////////////////////////////
//~ rjf: Unicode String Conversions
internal String8 str8_from_16(Arena *arena, String16 in);
internal String16 str16_from_8(Arena *arena, String8 in);
internal String8 str8_from_32(Arena *arena, String32 in);
internal String32 str32_from_8(Arena *arena, String8 in);
////////////////////////////////
//~ rjf: Basic Types & Space Enum -> String Conversions
internal String8 string_from_dimension(Dimension dimension);
internal String8 string_from_side(Side side);
internal String8 string_from_operating_system(OperatingSystem os);
internal String8 string_from_architecture(Architecture arch);
////////////////////////////////
//~ rjf: Time Types -> String
internal String8 string_from_week_day(WeekDay week_day);
internal String8 string_from_month(Month month);
internal String8 push_date_time_string(Arena *arena, DateTime *date_time);
internal String8 push_file_name_date_time_string(Arena *arena, DateTime *date_time);
internal String8 string_from_elapsed_time(Arena *arena, DateTime dt);
////////////////////////////////
//~ rjf: String <-> Color
internal String8 hex_string_from_rgba_4f32(Arena *arena, Vec4F32 rgba);
internal Vec4F32 rgba_from_hex_string_4f32(String8 hex_string);
////////////////////////////////
//~ NOTE(allen): Serialization Helpers
internal void str8_serial_begin(Arena *arena, String8List *srl);
internal String8 str8_serial_end(Arena *arena, String8List *srl);
internal void str8_serial_write_to_dst(String8List *srl, void *out);
internal U64 str8_serial_push_align(Arena *arena, String8List *srl, U64 align);
internal void * str8_serial_push_size(Arena *arena, String8List *srl, U64 size);
internal void * str8_serial_push_data(Arena *arena, String8List *srl, void *data, U64 size);
internal void str8_serial_push_data_list(Arena *arena, String8List *srl, String8Node *first);
internal void str8_serial_push_u64(Arena *arena, String8List *srl, U64 x);
internal void str8_serial_push_u32(Arena *arena, String8List *srl, U32 x);
internal void str8_serial_push_u16(Arena *arena, String8List *srl, U16 x);
internal void str8_serial_push_u8(Arena *arena, String8List *srl, U8 x);
internal void str8_serial_push_cstr(Arena *arena, String8List *srl, String8 str);
internal void str8_serial_push_string(Arena *arena, String8List *srl, String8 str);
#define str8_serial_push_array(arena, srl, ptr, count) str8_serial_push_data(arena, srl, ptr, sizeof(*(ptr)) * (count))
#define str8_serial_push_struct(arena, srl, ptr) str8_serial_push_array(arena, srl, ptr, 1)
////////////////////////////////
//~ rjf: Deserialization Helpers
internal U64 str8_deserial_read(String8 string, U64 off, void *read_dst, U64 read_size, U64 granularity);
internal U64 str8_deserial_find_first_match(String8 string, U64 off, U16 scan_val);
internal void * str8_deserial_get_raw_ptr(String8 string, U64 off, U64 size);internal U64 str8_deserial_read_cstr(String8 string, U64 off, String8 *cstr_out);
internal U64 str8_deserial_read_windows_utf16_string16(String8 string, U64 off, String16 *str_out);
internal U64 str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out);
#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((string), (off), (ptr), sizeof(*(ptr)), sizeof(*(ptr)))
#endif // BASE_STRING_H
+78
View File
@@ -0,0 +1,78 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
// NOTE(allen): Thread Context Functions
C_LINKAGE thread_static TCTX* tctx_thread_local;
#if !SUPPLEMENT_UNIT
C_LINKAGE thread_static TCTX* tctx_thread_local = 0;
#endif
internal void
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){
*arena_ptr = arena_alloc();
}
tctx_thread_local = tctx;
}
internal TCTX*
tctx_get_equipped(void){
return(tctx_thread_local);
}
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){
Arena **conflict_ptr = conflicts;
B32 has_conflict = 0;
for (U64 j = 0; j < count; j += 1, conflict_ptr += 1){
if (*arena_ptr == *conflict_ptr){
has_conflict = 1;
break;
}
}
if (!has_conflict){
result = *arena_ptr;
break;
}
}
return(result);
}
internal void
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);
tctx->thread_name_size = size;
}
internal String8
tctx_get_thread_name(void){
TCTX *tctx = tctx_get_equipped();
String8 result = str8(tctx->thread_name, tctx->thread_name_size);
return(result);
}
internal void
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 *tctx = tctx_get_equipped();
*file_name = tctx->file_name;
*line_number = tctx->line_number;
}
+40
View File
@@ -0,0 +1,40 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_THREAD_CONTEXT_H
#define BASE_THREAD_CONTEXT_H
////////////////////////////////
// NOTE(allen): Thread Context
typedef struct TCTX TCTX;
struct TCTX
{
Arena *arenas[2];
U8 thread_name[32];
U64 thread_name_size;
char *file_name;
U64 line_number;
};
////////////////////////////////
// NOTE(allen): Thread Context Functions
internal void tctx_init_and_equip(TCTX *tctx);
internal TCTX* tctx_get_equipped(void);
internal Arena* tctx_get_scratch(Arena **conflicts, U64 count);
internal void tctx_set_thread_name(String8 name);
internal String8 tctx_get_thread_name(void);
internal void tctx_write_srcloc(char *file_name, U64 line_number);
internal void tctx_read_srcloc(char **file_name, U64 *line_number);
#define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__)
#define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count)))
#define scratch_end(scratch) temp_end(scratch)
#endif //BASE_THREAD_CONTEXT_H
+454
View File
@@ -0,0 +1,454 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ Safe Casts
internal U16
safe_cast_u16(U32 x)
{
AssertAlways(x <= max_U16);
U16 result = (U16)x;
return result;
}
internal U32
safe_cast_u32(U64 x)
{
AssertAlways(x <= max_U32);
U32 result = (U32)x;
return result;
}
internal S32
safe_cast_s32(S64 x)
{
AssertAlways(x <= max_S32);
S32 result = (S32)x;
return result;
}
////////////////////////////////
//~ rjf: Large Base Type Functions
internal U128
u128_zero(void)
{
U128 v = {0};
return v;
}
internal U128
u128_make(U64 v0, U64 v1)
{
U128 v = {v0, v1};
return v;
}
internal B32
u128_match(U128 a, U128 b)
{
return MemoryMatchStruct(&a, &b);
}
////////////////////////////////
//~ rjf: Bit Patterns
internal U32
u32_from_u64_saturate(U64 x){
U32 x32 = (x > max_U32)?max_U32:(U32)x;
return(x32);
}
internal U64
u64_up_to_pow2(U64 x){
if (x == 0){
x = 1;
}
else{
x -= 1;
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
x |= (x >> 32);
x += 1;
}
return(x);
}
internal S32
extend_sign32(U32 x, U32 size){
U32 high_bit = size * 8;
U32 shift = 32 - high_bit;
S32 result = ((S32)x << shift) >> shift;
return result;
}
internal S64
extend_sign64(U64 x, U64 size){
U64 high_bit = size * 8;
U64 shift = 64 - high_bit;
S64 result = ((S64)x << shift) >> shift;
return result;
}
internal F32
inf32(void){
union { U32 u; F32 f; } x;
x.u = exponent32;
return(x.f);
}
internal F32
neg_inf32(void){
union { U32 u; F32 f; } x;
x.u = sign32 | exponent32;
return(x.f);
}
internal U16
bswap_u16(U16 x)
{
U16 result = (((x & 0xFF00) >> 8) |
((x & 0x00FF) << 8));
return result;
}
internal U32
bswap_u32(U32 x)
{
U32 result = (((x & 0xFF000000) >> 24) |
((x & 0x00FF0000) >> 8) |
((x & 0x0000FF00) << 8) |
((x & 0x000000FF) << 24));
return result;
}
internal U64
bswap_u64(U64 x)
{
// TODO(nick): naive bswap, replace with something that is faster like an intrinsic
U64 result = (((x & 0xFF00000000000000ULL) >> 56) |
((x & 0x00FF000000000000ULL) >> 40) |
((x & 0x0000FF0000000000ULL) >> 24) |
((x & 0x000000FF00000000ULL) >> 8) |
((x & 0x00000000FF000000ULL) << 8) |
((x & 0x0000000000FF0000ULL) << 24) |
((x & 0x000000000000FF00ULL) << 40) |
((x & 0x00000000000000FFULL) << 56));
return result;
}
////////////////////////////////
//~ rjf: Enum -> Sign
internal S32
sign_from_side_S32(Side side){
return((side == Side_Min)?-1:1);
}
internal F32
sign_from_side_F32(Side side){
return((side == Side_Min)?-1.f:1.f);
}
////////////////////////////////
//~ rjf: Memory Functions
internal B32
memory_is_zero(void *ptr, U64 size){
B32 result = 1;
// break down size
U64 extra = (size&0x7);
U64 count8 = (size >> 3);
// check with 8-byte stride
U64 *p64 = (U64*)ptr;
if(result)
{
for (U64 i = 0; i < count8; i += 1, p64 += 1){
if (*p64 != 0){
result = 0;
goto done;
}
}
}
// check extra
if(result)
{
U8 *p8 = (U8*)p64;
for (U64 i = 0; i < extra; i += 1, p8 += 1){
if (*p8 != 0){
result = 0;
goto done;
}
}
}
done:;
return(result);
}
////////////////////////////////
//~ rjf: Text 2D Coordinate/Range Functions
internal TxtPt
txt_pt(S64 line, S64 column)
{
TxtPt p = {0};
p.line = line;
p.column = column;
return p;
}
internal B32
txt_pt_match(TxtPt a, TxtPt b)
{
return a.line == b.line && a.column == b.column;
}
internal B32
txt_pt_less_than(TxtPt a, TxtPt b)
{
B32 result = 0;
if(a.line < b.line)
{
result = 1;
}
else if(a.line == b.line)
{
result = a.column < b.column;
}
return result;
}
internal TxtPt
txt_pt_min(TxtPt a, TxtPt b)
{
TxtPt result = b;
if(txt_pt_less_than(a, b))
{
result = a;
}
return result;
}
internal TxtPt
txt_pt_max(TxtPt a, TxtPt b)
{
TxtPt result = a;
if(txt_pt_less_than(a, b))
{
result = b;
}
return result;
}
internal TxtRng
txt_rng(TxtPt min, TxtPt max)
{
TxtRng range = {0};
if(txt_pt_less_than(min, max))
{
range.min = min;
range.max = max;
}
else
{
range.min = max;
range.max = min;
}
return range;
}
internal TxtRng
txt_rng_intersect(TxtRng a, TxtRng b)
{
TxtRng result = {0};
result.min = txt_pt_max(a.min, b.min);
result.max = txt_pt_min(a.max, b.max);
if(txt_pt_less_than(result.max, result.min))
{
MemoryZeroStruct(&result);
}
return result;
}
internal TxtRng
txt_rng_union(TxtRng a, TxtRng b)
{
TxtRng result = {0};
result.min = txt_pt_min(a.min, b.min);
result.max = txt_pt_max(a.max, b.max);
return result;
}
////////////////////////////////
//~ rjf: Toolchain/Environment Enum Functions
internal U64
bit_size_from_arch(Architecture arch)
{
// TODO(rjf): metacode
U64 arch_bitsize = 0;
switch(arch)
{
case Architecture_x64: arch_bitsize = 64; break;
case Architecture_x86: arch_bitsize = 32; break;
case Architecture_arm64: arch_bitsize = 64; break;
case Architecture_arm32: arch_bitsize = 32; break;
default: break;
}
return arch_bitsize;
}
internal U64
max_instruction_size_from_arch(Architecture arch)
{
// TODO(rjf): make this real
return 64;
}
internal OperatingSystem
operating_system_from_context(void){
OperatingSystem os = OperatingSystem_Null;
#if OS_WINDOWS
os = OperatingSystem_Windows;
#elif OS_LINUX
os = OperatingSystem_Linux;
#elif OS_MAC
os = OperatingSystem_Mac;
#endif
return os;
}
internal Architecture
architecture_from_context(void){
Architecture arch = Architecture_Null;
#if ARCH_X64
arch = Architecture_x64;
#elif ARCH_X86
arch = Architecture_x86;
#elif ARCH_ARM64
arch = Architecture_arm64;
#elif ARCH_ARM32
arch = Architecture_arm32;
#endif
return arch;
}
internal Compiler
compiler_from_context(void){
Compiler compiler = Compiler_Null;
#if COMPILER_CL
compiler = Compiler_cl;
#elif COMPILER_GCC
compiler = Compiler_gcc;
#elif COMPILER_CLANG
compiler = Compiler_clang;
#endif
return compiler;
}
////////////////////////////////
//~ rjf: Time Functions
internal DenseTime
dense_time_from_date_time(DateTime date_time){
DenseTime result = 0;
result += date_time.year;
result *= 12;
result += date_time.mon;
result *= 31;
result += date_time.day;
result *= 24;
result += date_time.hour;
result *= 60;
result += date_time.min;
result *= 61;
result += date_time.sec;
result *= 1000;
result += date_time.msec;
return(result);
}
internal DateTime
date_time_from_dense_time(DenseTime time){
DateTime result = {0};
result.msec = time%1000;
time /= 1000;
result.sec = time%61;
time /= 61;
result.min = time%60;
time /= 60;
result.hour = time%24;
time /= 24;
result.day = time%31;
time /= 31;
result.mon = time%12;
time /= 12;
Assert(time <= max_U32);
result.year = (U32)time;
return(result);
}
internal DateTime
date_time_from_micro_seconds(U64 time){
DateTime result = {0};
result.micro_sec = time%1000;
time /= 1000;
result.msec = time%1000;
time /= 1000;
result.sec = time%60;
time /= 60;
result.min = time%60;
time /= 60;
result.hour = time%24;
time /= 24;
result.day = time%31;
time /= 31;
result.mon = time%12;
time /= 12;
Assert(time <= max_U32);
result.year = (U32)time;
return(result);
}
////////////////////////////////
//~ rjf: Non-Fancy Ring Buffer Reads/Writes
internal U64
ring_write(U8 *ring_base, U64 ring_size, U64 ring_pos, void *src_data, U64 src_data_size)
{
Assert(src_data_size <= ring_size);
{
U64 ring_off = ring_pos%ring_size;
U64 bytes_before_split = ring_size-ring_off;
U64 pre_split_bytes = Min(bytes_before_split, src_data_size);
U64 pst_split_bytes = src_data_size-pre_split_bytes;
void *pre_split_data = src_data;
void *pst_split_data = ((U8 *)src_data + pre_split_bytes);
MemoryCopy(ring_base+ring_off, pre_split_data, pre_split_bytes);
MemoryCopy(ring_base+0, pst_split_data, pst_split_bytes);
}
return src_data_size;
}
internal U64
ring_read(U8 *ring_base, U64 ring_size, U64 ring_pos, void *dst_data, U64 read_size)
{
Assert(read_size <= ring_size);
{
U64 ring_off = ring_pos%ring_size;
U64 bytes_before_split = ring_size-ring_off;
U64 pre_split_bytes = Min(bytes_before_split, read_size);
U64 pst_split_bytes = read_size-pre_split_bytes;
MemoryCopy(dst_data, ring_base+ring_off, pre_split_bytes);
MemoryCopy((U8 *)dst_data + pre_split_bytes, ring_base+0, pst_split_bytes);
}
return read_size;
}
+683
View File
@@ -0,0 +1,683 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_TYPES_H
#define BASE_TYPES_H
////////////////////////////////
//~ rjf: Foreign Includes
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <string.h>
#include <stdint.h>
////////////////////////////////
//~ rjf: Build Configuration
#if !defined(ENABLE_DEV)
# define ENABLE_DEV 0
#endif
#if !defined(SUPPLEMENT_UNIT)
# define SUPPLEMENT_UNIT 0
#endif
////////////////////////////////
//~ rjf: Codebase Keywords
#define internal static
#define global static
#define local_persist static
#if COMPILER_CL || (COMPILER_CLANG && OS_WINDOWS)
# pragma section(".rdata$", read)
# define read_only __declspec(allocate(".rdata$"))
#elif (COMPILER_CLANG && OS_LINUX)
# define read_only __attribute__((section(".rodata")))
#else
// NOTE(rjf): I don't know of a useful way to do this in GCC land.
// __attribute__((section(".rodata"))) looked promising, but it introduces a
// strange warning about malformed section attributes, and it doesn't look
// like writing to that section reliably produces access violations, strangely
// enough. (It does on Clang)
# define read_only
#endif
////////////////////////////////
//~ rjf: Memory Operation Macros
#define MemoryCopy(dst, src, size) memmove((dst), (src), (size))
#define MemorySet(dst, byte, size) memset((dst), (byte), (size))
#define MemoryCompare(a, b, size) memcmp((a), (b), (size))
#define MemoryStrlen(ptr) strlen(ptr)
#define MemoryCopyStruct(d,s) MemoryCopy((d),(s),sizeof(*(d)))
#define MemoryCopyArray(d,s) MemoryCopy((d),(s),sizeof(d))
#define MemoryCopyTyped(d,s,c) MemoryCopy((d),(s),sizeof(*(d))*(c))
#define MemoryZero(s,z) memset((s),0,(z))
#define MemoryZeroStruct(s) MemoryZero((s),sizeof(*(s)))
#define MemoryZeroArray(a) MemoryZero((a),sizeof(a))
#define MemoryZeroTyped(m,c) MemoryZero((m),sizeof(*(m))*(c))
#define MemoryMatch(a,b,z) (MemoryCompare((a),(b),(z)) == 0)
#define MemoryMatchStruct(a,b) MemoryMatch((a),(b),sizeof(*(a)))
#define MemoryMatchArray(a,b) MemoryMatch((a),(b),sizeof(a))
#define MemoryRead(T,p,e) ( ((p)+sizeof(T)<=(e))?(*(T*)(p)):(0) )
#define MemoryConsume(T,p,e) \
( ((p)+sizeof(T)<=(e))?((p)+=sizeof(T),*(T*)((p)-sizeof(T))):((p)=(e),0) )
////////////////////////////////
//~ rjf: Units
#define KB(n) (((U64)(n)) << 10)
#define MB(n) (((U64)(n)) << 20)
#define GB(n) (((U64)(n)) << 30)
#define TB(n) (((U64)(n)) << 40)
#define Thousand(n) ((n)*1000)
#define Million(n) ((n)*1000000)
#define Billion(n) ((n)*1000000000)
////////////////////////////////
//~ rjf: Asserts
#if COMPILER_CL
# define Trap() __debugbreak()
#elif COMPILER_CLANG || COMPILER_GCC
# define Trap() __builtin_trap()
# else
# error "undefined trap"
#endif
#define AssertAlways(x) do{if(!(x)) {Trap();}}while(0)
#if !defined(NDEBUG)
# define Assert(x) AssertAlways(x)
#else
# define Assert(x) (void)(x)
#endif
#define AssertImplies(a,b) Assert(!(a) || b)
#define AssertIff(a,b) Assert(!!(a) == !!(b))
#define InvalidPath Assert(!"Invalid Path!")
#define NotImplemented Assert(!"Not Implemented!")
#define StaticAssert(C,ID) global U8 Glue(ID,__LINE__)[(C)?1:-1]
////////////////////////////////
//~ rjf: Branch Predictor Hints
#if defined(__clang__)
# define Expect(expr, val) __builtin_expect((expr), (val))
#else
# define Expect(expr, val) (expr)
#endif
#define Likely(expr) Expect(expr,1)
#define Unlikely(expr) Expect(expr,0)
////////////////////////////////
//~ rjf: Misc. Helper Macros
#define ArrayCount(a) (sizeof(a) / sizeof((a)[0]))
#define Stmnt(S) do{ S }while(0)
#define Stringify_(S) #S
#define Stringify(S) Stringify_(S)
#define Glue_(A,B) A##B
#define Glue(A,B) Glue_(A,B)
#define Min(A,B) ( ((A)<(B))?(A):(B) )
#define Max(A,B) ( ((A)>(B))?(A):(B) )
#define ClampTop(A,X) Min(A,X)
#define ClampBot(X,B) Max(X,B)
#define Clamp(A,X,B) ( ((X)<(A))?(A):((X)>(B))?(B):(X) )
#define PtrClampTop(A,X) ClampTop(A,X)
#define PtrClampBot(X,B) ClampBot(X,B)
#define PtrClamp(A,X,B) Clamp(A,X,B)
#define CeilIntegerDiv(a,b) (((a) + (b) - 1)/(b))
#define Swap(T,a,b) Stmnt( T t__ = a; a = b; b = t__; )
#if ARCH_64BIT
# define IntFromPtr(ptr) ((U64)(ptr))
#elif ARCH_32BIT
# define IntFromPtr(ptr) ((U32)(ptr))
#else
# error missing ptr cast for this architecture
#endif
#define PtrFromInt(i) (void*)((U8*)0 + (i))
#define Member(T,m) (((T*)0)->m)
#define OffsetOf(T,m) IntFromPtr(&Member(T,m))
#define MemberFromOffset(T,ptr,off) (T)((((U8 *)ptr)+(off)))
#define CastFromMember(T,m,ptr) (T*)(((U8*)ptr) - OffsetOf(T,m))
#define Compose64Bit(a,b) ((((U64)a) << 32) | ((U64)b));
#define AlignPow2(x,b) (((x) + (b) - 1)&(~((b) - 1)))
#define AlignDownPow2(x,b) ((x)&(~((b) - 1)))
#define AlignPadPow2(x,b) ((0-(x)) & ((b) - 1))
#define IsPow2(x) ((x)!=0 && ((x)&((x)-1))==0)
#define IsPow2OrZero(x) ((((x) - 1)&(x)) == 0)
#define DeferLoop(begin, end) for(int _i_ = ((begin), 0); !_i_; _i_ += 1, (end))
#define DeferLoopChecked(begin, end) for(int _i_ = 2 * !(begin); (_i_ == 2 ? ((end), 0) : !_i_); _i_ += 1, (end))
#define B8 S8
#define B32 rrbool
#if LANG_CPP
# define zero_struct {}
#else
# define zero_struct {0}
#endif
#if COMPILER_MSVC && COMPILER_MSVC_YEAR < 2015
# define this_function_name "unknown"
#else
# define this_function_name __func__
#endif
#if LANG_CPP
# define C_LINKAGE_BEGIN extern "C"{
# define C_LINKAGE_END }
# define C_LINKAGE extern "C"
#else
# define C_LINKAGE_BEGIN
# define C_LINKAGE_END
# define C_LINKAGE
#endif
#if COMPILER_CL
# define thread_static __declspec(thread)
#elif COMPILER_CLANG || COMPILER_GCC
# define thread_static __thread
#endif
#if OS_WINDOWS
# define shared_function C_LINKAGE __declspec(dllexport)
#else
# define shared_function C_LINKAGE
#endif
////////////////////////////////
//~ ASAN
#if COMPILER_CL
# if defined(__SANITIZE_ADDRESS__)
# define ASAN_ENABLED 1
# define NO_ASAN __declspec(no_sanitize_address)
# else
# define NO_ASAN
# endif
#elif COMPILER_CLANG
# if defined(__has_feature)
# if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
# define ASAN_ENABLED 1
# endif
# endif
# define NO_ASAN __attribute__((no_sanitize("address")))
#else
# error "NO_ASAN is not defined"
#endif
#if ASAN_ENABLED
#pragma comment(lib, "clang_rt.asan-x86_64.lib")
C_LINKAGE_BEGIN
void __asan_poison_memory_region(void const volatile *addr, size_t size);
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
C_LINKAGE_END
# define AsanPoisonMemoryRegion(addr, size) __asan_poison_memory_region((addr), (size))
# define AsanUnpoisonMemoryRegion(addr, size) __asan_unpoison_memory_region((addr), (size))
#else
# define AsanPoisonMemoryRegion(addr, size) ((void)(addr), (void)(size))
# define AsanUnpoisonMemoryRegion(addr, size) ((void)(addr), (void)(size))
#endif
////////////////////////////////
//~ rjf: Base Types
typedef uint8_t U8;
typedef uint16_t U16;
typedef uint32_t U32;
typedef uint64_t U64;
typedef int8_t S8;
typedef int16_t S16;
typedef int32_t S32;
typedef int64_t S64;
typedef S8 B8;
typedef S16 B16;
typedef S32 B32;
typedef S64 B64;
typedef float F32;
typedef double F64;
////////////////////////////////
//~ rjf: Large Base Types
typedef struct U128 U128;
struct U128
{
U64 u64[2];
};
////////////////////////////////
//~ rjf: Basic Types & Spaces
typedef void VoidProc(void);
typedef enum Dimension
{
Dimension_X,
Dimension_Y,
Dimension_Z,
Dimension_W,
}
Dimension;
typedef enum Side
{
Side_Invalid = -1,
Side_Min,
Side_Max,
Side_COUNT,
}
Side;
#define side_flip(s) ((Side)(!(s)))
typedef enum Axis2
{
Axis2_Invalid = -1,
Axis2_X,
Axis2_Y,
Axis2_COUNT,
}
Axis2;
#define axis2_flip(a) ((Axis2)(!(a)))
typedef enum Corner
{
Corner_Invalid = -1,
Corner_00,
Corner_01,
Corner_10,
Corner_11,
Corner_COUNT
}
Corner;
////////////////////////////////
//~ rjf: Toolchain/Environment Enums
typedef enum OperatingSystem
{
OperatingSystem_Null,
OperatingSystem_Windows,
OperatingSystem_Linux,
OperatingSystem_Mac,
OperatingSystem_COUNT,
}
OperatingSystem;
typedef enum Architecture
{
Architecture_Null,
Architecture_x64,
Architecture_x86,
Architecture_arm64,
Architecture_arm32,
Architecture_COUNT,
}
Architecture;
typedef enum Compiler
{
Compiler_Null,
Compiler_cl,
Compiler_gcc,
Compiler_clang,
Compiler_COUNT,
}
Compiler;
////////////////////////////////
//~ rjf: Text 2D Coordinates & Ranges
typedef struct TxtPt TxtPt;
struct TxtPt
{
S64 line;
S64 column;
};
typedef struct TxtRng TxtRng;
struct TxtRng
{
TxtPt min;
TxtPt max;
};
////////////////////////////////
//~ NOTE(allen): Constants
global U32 sign32 = 0x80000000;
global U32 exponent32 = 0x7F800000;
global U32 mantissa32 = 0x007FFFFF;
global F32 big_golden32 = 1.61803398875f;
global F32 small_golden32 = 0.61803398875f;
global F32 pi32 = 3.1415926535897f;
global F64 machine_epsilon64 = 4.94065645841247e-324;
global U64 max_U64 = 0xffffffffffffffffull;
global U32 max_U32 = 0xffffffff;
global U16 max_U16 = 0xffff;
global U8 max_U8 = 0xff;
global S64 max_S64 = (S64)0x7fffffffffffffffull;
global S32 max_S32 = (S32)0x7fffffff;
global S16 max_S16 = (S16)0x7fff;
global S8 max_S8 = (S8)0x7f;
global S64 min_S64 = (S64)0xffffffffffffffffull;
global S32 min_S32 = (S32)0xffffffff;
global S16 min_S16 = (S16)0xffff;
global S8 min_S8 = (S8)0xff;
global const U32 bitmask1 = 0x00000001;
global const U32 bitmask2 = 0x00000003;
global const U32 bitmask3 = 0x00000007;
global const U32 bitmask4 = 0x0000000f;
global const U32 bitmask5 = 0x0000001f;
global const U32 bitmask6 = 0x0000003f;
global const U32 bitmask7 = 0x0000007f;
global const U32 bitmask8 = 0x000000ff;
global const U32 bitmask9 = 0x000001ff;
global const U32 bitmask10 = 0x000003ff;
global const U32 bitmask11 = 0x000007ff;
global const U32 bitmask12 = 0x00000fff;
global const U32 bitmask13 = 0x00001fff;
global const U32 bitmask14 = 0x00003fff;
global const U32 bitmask15 = 0x00007fff;
global const U32 bitmask16 = 0x0000ffff;
global const U32 bitmask17 = 0x0001ffff;
global const U32 bitmask18 = 0x0003ffff;
global const U32 bitmask19 = 0x0007ffff;
global const U32 bitmask20 = 0x000fffff;
global const U32 bitmask21 = 0x001fffff;
global const U32 bitmask22 = 0x003fffff;
global const U32 bitmask23 = 0x007fffff;
global const U32 bitmask24 = 0x00ffffff;
global const U32 bitmask25 = 0x01ffffff;
global const U32 bitmask26 = 0x03ffffff;
global const U32 bitmask27 = 0x07ffffff;
global const U32 bitmask28 = 0x0fffffff;
global const U32 bitmask29 = 0x1fffffff;
global const U32 bitmask30 = 0x3fffffff;
global const U32 bitmask31 = 0x7fffffff;
global const U32 bitmask32 = 0xffffffff;
global const U64 bitmask33 = 0x00000001ffffffffull;
global const U64 bitmask34 = 0x00000003ffffffffull;
global const U64 bitmask35 = 0x00000007ffffffffull;
global const U64 bitmask36 = 0x0000000fffffffffull;
global const U64 bitmask37 = 0x0000001fffffffffull;
global const U64 bitmask38 = 0x0000003fffffffffull;
global const U64 bitmask39 = 0x0000007fffffffffull;
global const U64 bitmask40 = 0x000000ffffffffffull;
global const U64 bitmask41 = 0x000001ffffffffffull;
global const U64 bitmask42 = 0x000003ffffffffffull;
global const U64 bitmask43 = 0x000007ffffffffffull;
global const U64 bitmask44 = 0x00000fffffffffffull;
global const U64 bitmask45 = 0x00001fffffffffffull;
global const U64 bitmask46 = 0x00003fffffffffffull;
global const U64 bitmask47 = 0x00007fffffffffffull;
global const U64 bitmask48 = 0x0000ffffffffffffull;
global const U64 bitmask49 = 0x0001ffffffffffffull;
global const U64 bitmask50 = 0x0003ffffffffffffull;
global const U64 bitmask51 = 0x0007ffffffffffffull;
global const U64 bitmask52 = 0x000fffffffffffffull;
global const U64 bitmask53 = 0x001fffffffffffffull;
global const U64 bitmask54 = 0x003fffffffffffffull;
global const U64 bitmask55 = 0x007fffffffffffffull;
global const U64 bitmask56 = 0x00ffffffffffffffull;
global const U64 bitmask57 = 0x01ffffffffffffffull;
global const U64 bitmask58 = 0x03ffffffffffffffull;
global const U64 bitmask59 = 0x07ffffffffffffffull;
global const U64 bitmask60 = 0x0fffffffffffffffull;
global const U64 bitmask61 = 0x1fffffffffffffffull;
global const U64 bitmask62 = 0x3fffffffffffffffull;
global const U64 bitmask63 = 0x7fffffffffffffffull;
global const U64 bitmask64 = 0xffffffffffffffffull;
global const U32 bit1 = (1<<0);
global const U32 bit2 = (1<<1);
global const U32 bit3 = (1<<2);
global const U32 bit4 = (1<<3);
global const U32 bit5 = (1<<4);
global const U32 bit6 = (1<<5);
global const U32 bit7 = (1<<6);
global const U32 bit8 = (1<<7);
global const U32 bit9 = (1<<8);
global const U32 bit10 = (1<<9);
global const U32 bit11 = (1<<10);
global const U32 bit12 = (1<<11);
global const U32 bit13 = (1<<12);
global const U32 bit14 = (1<<13);
global const U32 bit15 = (1<<14);
global const U32 bit16 = (1<<15);
global const U32 bit17 = (1<<16);
global const U32 bit18 = (1<<17);
global const U32 bit19 = (1<<18);
global const U32 bit20 = (1<<19);
global const U32 bit21 = (1<<20);
global const U32 bit22 = (1<<21);
global const U32 bit23 = (1<<22);
global const U32 bit24 = (1<<23);
global const U32 bit25 = (1<<24);
global const U32 bit26 = (1<<25);
global const U32 bit27 = (1<<26);
global const U32 bit28 = (1<<27);
global const U32 bit29 = (1<<28);
global const U32 bit30 = (1<<29);
global const U32 bit31 = (1<<30);
global const U32 bit32 = (1<<31);
global const U64 bit33 = (1ull<<32);
global const U64 bit34 = (1ull<<33);
global const U64 bit35 = (1ull<<34);
global const U64 bit36 = (1ull<<35);
global const U64 bit37 = (1ull<<36);
global const U64 bit38 = (1ull<<37);
global const U64 bit39 = (1ull<<38);
global const U64 bit40 = (1ull<<39);
global const U64 bit41 = (1ull<<40);
global const U64 bit42 = (1ull<<41);
global const U64 bit43 = (1ull<<42);
global const U64 bit44 = (1ull<<43);
global const U64 bit45 = (1ull<<44);
global const U64 bit46 = (1ull<<45);
global const U64 bit47 = (1ull<<46);
global const U64 bit48 = (1ull<<47);
global const U64 bit49 = (1ull<<48);
global const U64 bit50 = (1ull<<49);
global const U64 bit51 = (1ull<<50);
global const U64 bit52 = (1ull<<51);
global const U64 bit53 = (1ull<<52);
global const U64 bit54 = (1ull<<53);
global const U64 bit55 = (1ull<<54);
global const U64 bit56 = (1ull<<55);
global const U64 bit57 = (1ull<<56);
global const U64 bit58 = (1ull<<57);
global const U64 bit59 = (1ull<<58);
global const U64 bit60 = (1ull<<59);
global const U64 bit61 = (1ull<<60);
global const U64 bit62 = (1ull<<61);
global const U64 bit63 = (1ull<<62);
global const U64 bit64 = (1ull<<63);
////////////////////////////////
//~ allen: Time
typedef enum WeekDay
{
WeekDay_Sun,
WeekDay_Mon,
WeekDay_Tue,
WeekDay_Wed,
WeekDay_Thu,
WeekDay_Fri,
WeekDay_Sat,
WeekDay_COUNT,
}
WeekDay;
typedef enum Month
{
Month_Jan,
Month_Feb,
Month_Mar,
Month_Apr,
Month_May,
Month_Jun,
Month_Jul,
Month_Aug,
Month_Sep,
Month_Oct,
Month_Nov,
Month_Dec,
Month_COUNT,
}
Month;
typedef struct DateTime DateTime;
struct DateTime
{
U16 micro_sec; // [0,999]
U16 msec; // [0,999]
U16 sec; // [0,60]
U16 min; // [0,59]
U16 hour; // [0,24]
U16 day; // [0,30]
union{
WeekDay week_day;
U32 wday;
};
union{
Month month;
U32 mon;
};
U32 year; // 1 = 1 CE, 0 = 1 BC
};
typedef U64 DenseTime;
////////////////////////////////
//~ allen: Files
typedef U32 FilePropertyFlags;
enum
{
FilePropertyFlag_IsFolder = (1 << 0),
};
typedef struct FileProperties FileProperties;
struct FileProperties
{
U64 size;
DenseTime modified;
DenseTime created;
FilePropertyFlags flags;
};
////////////////////////////////
//~ Safe Casts
internal U16 safe_cast_u16(U32 x);
internal U32 safe_cast_u32(U64 x);
internal S32 safe_cast_s32(S64 x);
////////////////////////////////
//~ rjf: Large Base Type Functions
internal U128 u128_zero(void);
internal U128 u128_make(U64 v0, U64 v1);
internal B32 u128_match(U128 a, U128 b);
////////////////////////////////
//~ rjf: Bit Patterns
internal U32 u32_from_u64_saturate(U64 x);
internal U64 u64_up_to_pow2(U64 x);
internal S32 extend_sign32(U32 x, U32 size);
internal S64 extend_sign64(U64 x, U64 size);
internal F32 inf32(void);
internal F32 neg_inf32(void);
internal U16 bswap_u16(U16 x);
internal U32 bswap_u32(U32 x);
internal U64 bswap_u64(U64 x);
////////////////////////////////
//~ rjf: Enum -> Sign
internal S32 sign_from_side_S32(Side side);
internal F32 sign_from_side_F32(Side side);
////////////////////////////////
//~ rjf: Memory Functions
internal B32 memory_is_zero(void *ptr, U64 size);
////////////////////////////////
//~ rjf: Text 2D Coordinate/Range Functions
internal TxtPt txt_pt(S64 line, S64 column);
internal B32 txt_pt_match(TxtPt a, TxtPt b);
internal B32 txt_pt_less_than(TxtPt a, TxtPt b);
internal TxtPt txt_pt_min(TxtPt a, TxtPt b);
internal TxtPt txt_pt_max(TxtPt a, TxtPt b);
internal TxtRng txt_rng(TxtPt min, TxtPt max);
internal TxtRng txt_rng_intersect(TxtRng a, TxtRng b);
internal TxtRng txt_rng_union(TxtRng a, TxtRng b);
////////////////////////////////
//~ rjf: Toolchain/Environment Enum Functions
internal U64 bit_size_from_arch(Architecture arch);
internal U64 max_instruction_size_from_arch(Architecture arch);
internal OperatingSystem operating_system_from_context(void);
internal Architecture architecture_from_context(void);
internal Compiler compiler_from_context(void);
////////////////////////////////
//~ rjf: Time Functions
internal DenseTime dense_time_from_date_time(DateTime date_time);
internal DateTime date_time_from_dense_time(DenseTime time);
internal DateTime date_time_from_micro_seconds(U64 time);
////////////////////////////////
//~ rjf: Non-Fancy Ring Buffer Reads/Writes
internal U64 ring_write(U8 *ring_base, U64 ring_size, U64 ring_pos, void *src_data, U64 src_data_size);
internal U64 ring_read(U8 *ring_base, U64 ring_size, U64 ring_pos, void *dst_data, U64 read_size);
#define ring_write_struct(ring_base, ring_size, ring_pos, ptr) ring_write((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr)))
#define ring_read_struct(ring_base, ring_size, ring_pos, ptr) ring_read((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr)))
#endif // BASE_TYPES_H
+1119
View File
File diff suppressed because it is too large Load Diff
+872
View File
@@ -0,0 +1,872 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef COFF_H
#define COFF_H
typedef U32 COFF_TimeStamp;
////////////////////////////////
//~ rjf: Coff Format Types
#pragma pack(push,1)
typedef U16 COFF_Flags;
enum
{
COFF_Flag_RELOC_STRIPPED = (1 << 0),
COFF_Flag_EXECUTABLE_IMAGE = (1 << 1),
COFF_Flag_LINE_NUMS_STRIPPED = (1 << 2),
COFF_Flag_SYM_STRIPPED = (1 << 3),
COFF_Flag_RESERVED_0 = (1 << 4),
COFF_Flag_LARGE_ADDRESS_AWARE = (1 << 5),
COFF_Flag_RESERVED_1 = (1 << 6),
COFF_Flag_RESERVED_2 = (1 << 7),
COFF_Flag_32BIT_MACHINE = (1 << 8),
COFF_Flag_DEBUG_STRIPPED = (1 << 9),
COFF_Flag_REMOVABLE_RUN_FROM_SWAP = (1 << 10),
COFF_Flag_NET_RUN_FROM_SWAP = (1 << 11),
COFF_Flag_SYSTEM = (1 << 12),
COFF_Flag_DLL = (1 << 13),
COFF_Flag_UP_SYSTEM_ONLY = (1 << 14),
COFF_Flag_BYTES_RESERVED_HI = (1 << 15),
};
typedef U16 COFF_MachineType;
enum
{
COFF_MachineType_UNKNOWN = 0x0,
COFF_MachineType_X86 = 0x14c,
COFF_MachineType_X64 = 0x8664,
COFF_MachineType_ARM33 = 0x1d3,
COFF_MachineType_ARM = 0x1c0,
COFF_MachineType_ARM64 = 0xaa64,
COFF_MachineType_ARMNT = 0x1c4,
COFF_MachineType_EBC = 0xebc,
COFF_MachineType_IA64 = 0x200,
COFF_MachineType_M32R = 0x9041,
COFF_MachineType_MIPS16 = 0x266,
COFF_MachineType_MIPSFPU = 0x366,
COFF_MachineType_MIPSFPU16 = 0x466,
COFF_MachineType_POWERPC = 0x1f0,
COFF_MachineType_POWERPCFP = 0x1f1,
COFF_MachineType_R4000 = 0x166,
COFF_MachineType_RISCV32 = 0x5032,
COFF_MachineType_RISCV64 = 0x5064,
COFF_MachineType_RISCV128 = 0x5128,
COFF_MachineType_SH3 = 0x1a2,
COFF_MachineType_SH3DSP = 0x1a3,
COFF_MachineType_SH4 = 0x1a6,
COFF_MachineType_SH5 = 0x1a8,
COFF_MachineType_THUMB = 0x1c2,
COFF_MachineType_WCEMIPSV2 = 0x169,
COFF_MachineType_COUNT = 25
};
typedef struct COFF_Header COFF_Header;
struct COFF_Header
{
COFF_MachineType machine;
U16 section_count;
COFF_TimeStamp time_stamp;
U32 symbol_table_foff;
U32 symbol_count;
U16 optional_header_size;
COFF_Flags flags;
};
typedef U32 COFF_SectionAlign;
enum
{
COFF_SectionAlign_1BYTES = 0x1,
COFF_SectionAlign_2BYTES = 0x2,
COFF_SectionAlign_4BYTES = 0x3,
COFF_SectionAlign_8BYTES = 0x4,
COFF_SectionAlign_16BYTES = 0x5,
COFF_SectionAlign_32BYTES = 0x6,
COFF_SectionAlign_64BYTES = 0x7,
COFF_SectionAlign_128BYTES = 0x8,
COFF_SectionAlign_256BYTES = 0x9,
COFF_SectionAlign_512BYTES = 0xA,
COFF_SectionAlign_1024BYTES = 0xB,
COFF_SectionAlign_2048BYTES = 0xC,
COFF_SectionAlign_4096BYTES = 0xD,
COFF_SectionAlign_8192BYTES = 0xE,
COFF_SectionAlign_COUNT = 14
};
typedef U32 COFF_SectionFlags;
enum
{
COFF_SectionFlag_TYPE_NO_PAD = (1 << 3),
COFF_SectionFlag_CNT_CODE = (1 << 5),
COFF_SectionFlag_CNT_INITIALIZED_DATA = (1 << 6),
COFF_SectionFlag_CNT_UNINITIALIZED_DATA = (1 << 7),
COFF_SectionFlag_LNK_OTHER = (1 << 8),
COFF_SectionFlag_LNK_INFO = (1 << 9),
COFF_SectionFlag_LNK_REMOVE = (1 << 11),
COFF_SectionFlag_LNK_COMDAT = (1 << 12),
COFF_SectionFlag_GPREL = (1 << 15),
COFF_SectionFlag_MEM_16BIT = (1 << 17),
COFF_SectionFlag_MEM_LOCKED = (1 << 18),
COFF_SectionFlag_MEM_PRELOAD = (1 << 19),
COFF_SectionFlag_ALIGN_SHIFT = 20, COFF_SectionFlag_ALIGN_MASK = 0xf,
COFF_SectionFlag_LNK_NRELOC_OVFL = (1 << 24),
COFF_SectionFlag_MEM_DISCARDABLE = (1 << 25),
COFF_SectionFlag_MEM_NOT_CACHED = (1 << 26),
COFF_SectionFlag_MEM_NOT_PAGED = (1 << 27),
COFF_SectionFlag_MEM_SHARED = (1 << 28),
COFF_SectionFlag_MEM_EXECUTE = (1 << 29),
COFF_SectionFlag_MEM_READ = (1 << 30),
COFF_SectionFlag_MEM_WRITE = (1 << 31),
};
#define COFF_SectionFlags_Extract_ALIGN(f) (COFF_SectionAlign)(((f) >> COFF_SectionFlag_ALIGN_SHIFT) & COFF_SectionFlag_ALIGN_MASK)
#define COFF_SectionFlags_LNK_FLAGS ((COFF_SectionFlag_ALIGN_MASK << COFF_SectionFlag_ALIGN_SHIFT) | COFF_SectionFlag_LNK_COMDAT | COFF_SectionFlag_LNK_INFO | COFF_SectionFlag_LNK_OTHER | COFF_SectionFlag_LNK_REMOVE | COFF_SectionFlag_LNK_NRELOC_OVFL)
typedef struct COFF_SectionHeader COFF_SectionHeader;
struct COFF_SectionHeader
{
U8 name[8];
U32 vsize;
U32 voff;
U32 fsize;
U32 foff;
U32 relocs_foff;
U32 lines_foff;
U16 reloc_count;
U16 line_count;
COFF_SectionFlags flags;
};
typedef U16 COFF_RelocTypeX64;
enum
{
COFF_RelocTypeX64_ABS = 0x0,
COFF_RelocTypeX64_ADDR64 = 0x1,
COFF_RelocTypeX64_ADDR32 = 0x2,
COFF_RelocTypeX64_ADDR32NB = 0x3,
// NB => No Base
COFF_RelocTypeX64_REL32 = 0x4,
COFF_RelocTypeX64_REL32_1 = 0x5,
COFF_RelocTypeX64_REL32_2 = 0x6,
COFF_RelocTypeX64_REL32_3 = 0x7,
COFF_RelocTypeX64_REL32_4 = 0x8,
COFF_RelocTypeX64_REL32_5 = 0x9,
COFF_RelocTypeX64_SECTION = 0xA,
COFF_RelocTypeX64_SECREL = 0xB,
COFF_RelocTypeX64_SECREL7 = 0xC,
// TODO(nick): MSDN doesn't specify size for CLR token
COFF_RelocTypeX64_TOKEN = 0xD,
COFF_RelocTypeX64_SREL32 = 0xE,
// TODO(nick): MSDN doesn't specify size for PAIR
COFF_RelocTypeX64_PAIR = 0xF,
COFF_RelocTypeX64_SSPAN32 = 0x10,
COFF_RelocTypeX64_COUNT = 17
};
typedef U16 COFF_RelocTypeX86;
enum
{
COFF_RelocTypeX86_ABS = 0x0,
// relocation is ignored
COFF_RelocTypeX86_DIR16 = 0x1,
// no support
COFF_RelocTypeX86_REL16 = 0x2,
// no support
COFF_RelocTypeX86_UNKNOWN0 = 0x3,
COFF_RelocTypeX86_UNKNOWN2 = 0x4,
COFF_RelocTypeX86_UNKNOWN3 = 0x5,
COFF_RelocTypeX86_DIR32 = 0x6,
// 32-bit virtual address
COFF_RelocTypeX86_DIR32NB = 0x7,
// 32-bit virtual offset
COFF_RelocTypeX86_SEG12 = 0x9,
// no support
COFF_RelocTypeX86_SECTION = 0xA,
// 16-bit section index, used for debug info purposes
COFF_RelocTypeX86_SECREL = 0xB,
// 32-bit offset from start of a section
COFF_RelocTypeX86_TOKEN = 0xC,
// CLR token? (for managed languages)
COFF_RelocTypeX86_SECREL7 = 0xD,
// 7-bit offset from the base of the section that contains the target.
COFF_RelocTypeX86_UNKNOWN4 = 0xE,
COFF_RelocTypeX86_UNKNOWN5 = 0xF,
COFF_RelocTypeX86_UNKNOWN6 = 0x10,
COFF_RelocTypeX86_UNKNOWN7 = 0x11,
COFF_RelocTypeX86_UNKNOWN8 = 0x12,
COFF_RelocTypeX86_UNKNOWN9 = 0x13,
COFF_RelocTypeX86_REL32 = 0x14,
COFF_RelocTypeX86_COUNT = 20
};
typedef U16 COFF_RelocTypeARM;
enum
{
COFF_RelocTypeARM_ABS = 0x0,
COFF_RelocTypeARM_ADDR32 = 0x1,
COFF_RelocTypeARM_ADDR32NB = 0x2,
COFF_RelocTypeARM_BRANCH24 = 0x3,
COFF_RelocTypeARM_BRANCH11 = 0x4,
COFF_RelocTypeARM_UNKNOWN1 = 0x5,
COFF_RelocTypeARM_UNKNOWN2 = 0x6,
COFF_RelocTypeARM_UNKNOWN3 = 0x7,
COFF_RelocTypeARM_UNKNOWN4 = 0x8,
COFF_RelocTypeARM_UNKNOWN5 = 0x9,
COFF_RelocTypeARM_REL32 = 0xA,
COFF_RelocTypeARM_SECTION = 0xE,
COFF_RelocTypeARM_SECREL = 0xF,
COFF_RelocTypeARM_MOV32 = 0x10,
COFF_RelocTypeARM_THUMB_MOV32 = 0x11,
COFF_RelocTypeARM_THUMB_BRANCH20 = 0x12,
COFF_RelocTypeARM_UNUSED = 0x13,
COFF_RelocTypeARM_THUMB_BRANCH24 = 0x14,
COFF_RelocTypeARM_THUMB_BLX23 = 0x15,
COFF_RelocTypeARM_PAIR = 0x16,
COFF_RelocTypeARM_COUNT = 20
};
typedef U16 COFF_RelocTypeARM64;
enum
{
COFF_RelocTypeARM64_ABS = 0x0,
COFF_RelocTypeARM64_ADDR32 = 0x1,
COFF_RelocTypeARM64_ADDR32NB = 0x2,
COFF_RelocTypeARM64_BRANCH26 = 0x3,
COFF_RelocTypeARM64_PAGEBASE_REL21 = 0x4,
COFF_RelocTypeARM64_REL21 = 0x5,
COFF_RelocTypeARM64_PAGEOFFSET_12A = 0x6,
COFF_RelocTypeARM64_SECREL = 0x8,
COFF_RelocTypeARM64_SECREL_LOW12A = 0x9,
COFF_RelocTypeARM64_SECREL_HIGH12A = 0xA,
COFF_RelocTypeARM64_SECREL_LOW12L = 0xB,
COFF_RelocTypeARM64_TOKEN = 0xC,
COFF_RelocTypeARM64_SECTION = 0xD,
COFF_RelocTypeARM64_ADDR64 = 0xE,
COFF_RelocTypeARM64_BRANCH19 = 0xF,
COFF_RelocTypeARM64_BRANCH14 = 0x10,
COFF_RelocTypeARM64_REL32 = 0x11,
COFF_RelocTypeARM64_COUNT = 17
};
typedef U8 COFF_SymType;
enum
{
COFF_SymType_NULL,
COFF_SymType_VOID,
COFF_SymType_CHAR,
COFF_SymType_SHORT,
COFF_SymType_INT,
COFF_SymType_LONG,
COFF_SymType_FLOAT,
COFF_SymType_DOUBLE,
COFF_SymType_STRUCT,
COFF_SymType_UNION,
COFF_SymType_ENUM,
COFF_SymType_MOE,
// member of enumeration
COFF_SymType_BYTE,
COFF_SymType_WORD,
COFF_SymType_UINT,
COFF_SymType_DWORD,
COFF_SymType_COUNT = 16
};
typedef U8 COFF_SymStorageClass;
enum
{
COFF_SymStorageClass_END_OF_FUNCTION = 0xff,
COFF_SymStorageClass_NULL = 0,
COFF_SymStorageClass_AUTOMATIC = 1,
COFF_SymStorageClass_EXTERNAL = 2,
COFF_SymStorageClass_STATIC = 3,
COFF_SymStorageClass_REGISTER = 4,
COFF_SymStorageClass_EXTERNAL_DEF = 5,
COFF_SymStorageClass_LABEL = 6,
COFF_SymStorageClass_UNDEFINED_LABEL = 7,
COFF_SymStorageClass_MEMBER_OF_STRUCT = 8,
COFF_SymStorageClass_ARGUMENT = 9,
COFF_SymStorageClass_STRUCT_TAG = 10,
COFF_SymStorageClass_MEMBER_OF_UNION = 11,
COFF_SymStorageClass_UNION_TAG = 12,
COFF_SymStorageClass_TYPE_DEFINITION = 13,
COFF_SymStorageClass_UNDEFINED_STATIC = 14,
COFF_SymStorageClass_ENUM_TAG = 15,
COFF_SymStorageClass_MEMBER_OF_ENUM = 16,
COFF_SymStorageClass_REGISTER_PARAM = 17,
COFF_SymStorageClass_BIT_FIELD = 18,
COFF_SymStorageClass_BLOCK = 100,
COFF_SymStorageClass_FUNCTION = 101,
COFF_SymStorageClass_END_OF_STRUCT = 102,
COFF_SymStorageClass_FILE = 103,
COFF_SymStorageClass_SECTION = 104,
COFF_SymStorageClass_WEAK_EXTERNAL = 105,
COFF_SymStorageClass_CLR_TOKEN = 107,
COFF_SymStorageClass_COUNT = 27
};
typedef U16 COFF_SymSecNumber;
enum
{
COFF_SymSecNumber_NUMBER_UNDEFINED = 0,
COFF_SymSecNumber_ABSOLUTE = 0xffff,
COFF_SymSecNumber_DEBUG = 0xfffe,
COFF_SymSecNumber_COUNT = 3
};
typedef U8 COFF_SymDType;
enum
{
COFF_SymDType_NULL = 0,
COFF_SymDType_PTR = 16,
COFF_SymDType_FUNC = 32,
COFF_SymDType_ARRAY = 48,
COFF_SymDType_COUNT = 4
};
typedef U32 COFF_WeakExtType;
enum
{
COFF_WeakExtType_NOLIBRARY = 1,
COFF_WeakExtType_SEARCH_LIBRARY = 2,
COFF_WeakExtType_SEARCH_ALIAS = 3,
COFF_WeakExtType_COUNT = 3
};
typedef U32 COFF_ImportHeaderType;
enum
{
COFF_ImportHeaderType_CODE = 0,
COFF_ImportHeaderType_DATA = 1,
COFF_ImportHeaderType_CONST = 2,
COFF_ImportHeaderType_COUNT = 3
};
typedef U32 COFF_ImportHeaderNameType;
enum
{
COFF_ImportHeaderNameType_ORDINAL = 0,
COFF_ImportHeaderNameType_NAME = 1,
COFF_ImportHeaderNameType_NAME_NOPREFIX = 2,
COFF_ImportHeaderNameType_UNDECORATE = 3,
COFF_ImportHeaderNameType_COUNT = 4
};
#define COFF_IMPORT_HEADER_TYPE_MASK 0x03
#define COFF_IMPORT_HEADER_TYPE_SHIFT 0
#define COFF_IMPORT_HEADER_NAME_TYPE_MASK 0x1c
#define COFF_IMPORT_HEADER_NAME_TYPE_SHIFT 2
#define COFF_IMPORT_HEADER_GET_TYPE(x) (((x) & COFF_IMPORT_HEADER_TYPE_MASK) >> COFF_IMPORT_HEADER_TYPE_SHIFT)
#define COFF_IMPORT_HEADER_GET_NAME_TYPE(x) (((x) & COFF_IMPORT_HEADER_NAME_TYPE_MASK) >> COFF_IMPORT_HEADER_NAME_TYPE_SHIFT)
typedef struct COFF_ImportHeader
{
U16 sig1;
U16 sig2;
U16 version;
U16 machine;
COFF_TimeStamp time_stamp;
U32 data_size;
U16 hint;
U16 type;
U16 name_type;
// type : 2
// name type : 3
// reserved : 11
//U16 flags;
String8 func_name;
String8 dll_name;
} COFF_ImportHeader;
typedef U8 COFF_ComdatSelectType;
enum
{
COFF_ComdatSelectType_NULL = 0,
// Only one symbol is allowed to be in global symbol table, otherwise multiply defintion error is thrown.
COFF_ComdatSelectType_NODUPLICATES = 1,
// Select any symbol, even if there are multiple definitions. (we default to first declaration)
COFF_ComdatSelectType_ANY = 2,
// Sections that symbols reference must match in size, otherwise multiply definition error is thrown.
COFF_ComdatSelectType_SAME_SIZE = 3,
// Sections that symbols reference must have identical checksums, otherwise multiply defintion error is thrown.
COFF_ComdatSelectType_EXACT_MATCH = 4,
// Symbols with associative type form a chain of sections are related to each other. (next link is indicated in COFF_SecDef in 'number')
COFF_ComdatSelectType_ASSOCIATIVE = 5,
// Linker selects section with largest size.
COFF_ComdatSelectType_LARGEST = 6,
COFF_ComdatSelectType_COUNT = 7
};
#define COFF_MIN_BIG_OBJ_VERSION 2
global U8 coff_big_obj_magic[] =
{
0xC7,0xA1,0xBA,0xD1,0xEE,0xBA,0xA9,0x4B,
0xAF,0x20,0xFA,0xF6,0x6A,0xA4,0xDC,0xB8,
};
typedef struct COFF_HeaderBigObj COFF_HeaderBigObj;
struct COFF_HeaderBigObj
{
U16 sig1; // COFF_MachineType_UNKNOWN
U16 sig2; // U16_MAX
U16 version;
U16 machine;
U32 time_stamp;
U8 magic[16];
U32 unused[4];
U32 section_count;
U32 pointer_to_symbol_table;
U32 number_of_symbols;
};
// Special values for section number field in coff symbol
#define COFF_SYMBOL_UNDEFINED_SECTION 0
#define COFF_SYMBOL_ABS_SECTION ((U32)-1)
#define COFF_SYMBOL_DEBUG_SECTION ((U32)-2)
#define COFF_SYMBOL_ABS_SECTION_16 ((U16)-1)
#define COFF_SYMBOL_DEBUG_SECTION_16 ((U16)-2)
typedef union COFF_SymbolName COFF_SymbolName;
union COFF_SymbolName
{
U8 short_name[8];
struct
{
// if this field is filled with zeroes we have a long name,
// which means name is stored in the string table
// and we need to use the offset to look it up...
U32 zeroes;
U32 string_table_offset;
}long_name;
};
typedef struct COFF_Symbol16 COFF_Symbol16;
struct COFF_Symbol16
{
COFF_SymbolName name;
U32 value;
U16 section_number;
union
{
struct
{
COFF_SymDType msb;
COFF_SymType lsb;
}u;
U16 v;
}type;
COFF_SymStorageClass storage_class;
U8 aux_symbol_count;
};
typedef struct COFF_Symbol32 COFF_Symbol32;
struct COFF_Symbol32
{
COFF_SymbolName name;
U32 value;
U32 section_number;
union
{
struct
{
COFF_SymDType msb;
COFF_SymType lsb;
}u;
U16 v;
}type;
COFF_SymStorageClass storage_class;
U8 aux_symbol_count;
};
// Auxilary symbols are allocated with fixed size so that symbol table could be maintaned as array of regular size.
#define COFF_AUX_SYMBOL_SIZE 18
// storage class: FUNCTION
typedef struct COFF_SymbolFunc
{
U8 unused[4];
U16 ln;
U8 unused2[2];
U32 ptr_to_next_func;
U8 unused3[2];
} COFF_SymbolFunc;
// storage class: WEAK_EXTERNAL
typedef struct COFF_SymbolWeakExt
{
U32 tag_index;
U32 characteristics;
U8 unused[10];
} COFF_SymbolWeakExt;
typedef struct COFF_SymbolFile
{
char name[18];
} COFF_SymbolFile;
// provides information about section to which symbol refers to.
// storage class: STATIC
typedef struct COFF_SymbolSecDef
{
U32 length;
U16 number_of_relocations;
U16 number_of_ln;
U32 check_sum;
U16 number; // one-based section index
U8 selection;
U8 unused[3];
} COFF_SymbolSecDef;
// specifies how section data should be modified when placed in the image file.
typedef struct COFF_Reloc COFF_Reloc;
struct COFF_Reloc
{
U32 apply_off; // section relative offset where relocation is placed
U32 isymbol; // zero based index into coff symbol table
U16 type; // relocation type that depends on the arch
};
#pragma pack(pop)
// feature flags in absolute symbol @feat.00
enum
{
COFF_FeatFlag_HAS_SAFE_SEH = (1 << 0), // /safeseh
COFF_FeatFlag_UNKNOWN_4 = (1 << 4),
COFF_FeatFlag_GUARD_STACK = (1 << 8), // /GS
COFF_FeatFlag_SDL = (1 << 9), // /sdl
COFF_FeatFlag_GUARD_CF = (1 << 11), // /guard:cf
COFF_FeatFlag_GUARD_EH_CONT = (1 << 14), // /guard:ehcont
COFF_FeatFlag_NO_RTTI = (1 << 17), // /GR-
COFF_FeatFlag_KERNEL = (1 << 30), // /kernel
};
typedef U32 COFF_FeatFlags;
////////////////////////////////
#define COFF_RES_ALIGN 4u
typedef struct COFF_ResourceHeaderPrefix
{
U32 data_size;
U32 header_size;
} COFF_ResourceHeaderPrefix;
typedef U16 COFF_ResourceMemoryFlags;
enum
{
COFF_ResourceMemoryFlag_MOVEABLE = 0x10,
COFF_ResourceMemoryFlag_PURE = 0x20,
COFF_ResourceMemoryFlag_PRELOAD = 0x40,
COFF_ResourceMemoryFlag_DISCARDABLE = 0x1000,
};
typedef enum
{
COFF_ResourceIDType_NULL,
COFF_ResourceIDType_NUMBER,
COFF_ResourceIDType_STRING,
COFF_ResourceIDType_COUNT
} COFF_ResourceIDType;
typedef struct COFF_ResourceID_16
{
COFF_ResourceIDType type;
union
{
U16 number;
String16 string;
} u;
} COFF_ResourceID_16;
typedef struct COFF_ResourceID
{
COFF_ResourceIDType type;
union
{
U16 number;
String8 string;
} u;
} COFF_ResourceID;
typedef struct COFF_Resource
{
COFF_ResourceID type;
COFF_ResourceID name;
U16 language_id;
U32 data_version;
U32 version;
COFF_ResourceMemoryFlags memory_flags;
String8 data;
} COFF_Resource;
typedef struct COFF_ResourceDataEntry
{
U32 data_voff;
U32 data_size;
U32 code_page;
U32 reserved;
} COFF_ResourceDataEntry;
typedef struct COFF_ResourceDirTable
{
U32 characteristics;
COFF_TimeStamp time_stamp;
U16 major_version;
U16 minor_version;
U16 name_entry_count;
U16 id_entry_count;
} COFF_ResourceDirTable;
#define COFF_RESOURCE_SUB_DIR_FLAG (1u << 31u)
typedef struct COFF_ResourceDirEntry
{
union {
U32 offset;
U32 id;
} name;
union {
U32 data_entry_offset;
U32 sub_dir_offset;
} id;
} COFF_ResourceDirEntry;
////////////////////////////////
// !<arch>\n
#define COFF_ARCHIVE_SIG 0x0A3E686372613C21ULL
// !<thin>\n
#define COFF_THIN_ARCHIVE_SIG 0xA3E6E6968743C21ULL
#define COFF_ARCHIVE_MAX_SHORT_NAME_SIZE 15
#define COFF_ARCHIVE_ALIGN 2
typedef struct COFF_ArchiveMemberHeader
{
String8 name; // padded to 16 bytes with spaces
U32 date; // unix time
U32 user_id; // unix artifact that does not have meaning on windows
U32 group_id; // unix artifact that does not have meaning on windows
String8 mode; // octal representation the members file mode
U32 size; // size of the member data, not including header
B32 is_end_correct; // set to true if found correct signature after header
} COFF_ArchiveMemberHeader;
////////////////////////////////
// Helpers
enum
{
COFF_DataType_NULL,
COFF_DataType_BIG_OBJ,
COFF_DataType_OBJ,
COFF_DataType_IMPORT,
};
typedef U32 COFF_DataType;
typedef struct COFF_HeaderInfo
{
COFF_MachineType machine;
U64 section_array_off;
U64 section_count_no_null;
U64 string_table_off;
U64 symbol_size;
U64 symbol_off;
U64 symbol_count;
} COFF_HeaderInfo;
enum
{
// symbol has section and offset.
COFF_SymbolValueInterp_REGULAR,
// symbol is overridable
COFF_SymbolValueInterp_WEAK,
// symbol doesn't have a reference section.
COFF_SymbolValueInterp_UNDEFINED,
// symbol has no section but still has size.
COFF_SymbolValueInterp_COMMON,
// symbol has an absolute (non-relocatable) value and is not an address.
COFF_SymbolValueInterp_ABS,
// symbol is used to provide general type of debugging information.
COFF_SymbolValueInterp_DEBUG
};
typedef U32 COFF_SymbolValueInterpType;
typedef struct COFF_Symbol16Node
{
struct COFF_Symbol16Node *next;
COFF_Symbol16 data;
} COFF_Symbol16Node;
typedef struct COFF_Symbol16List
{
U64 count;
COFF_Symbol16Node *first;
COFF_Symbol16Node *last;
} COFF_Symbol16List;
typedef struct COFF_Symbol32Array
{
U64 count;
COFF_Symbol32 *v;
} COFF_Symbol32Array;
typedef struct COFF_RelocNode
{
struct COFF_RelocNode *next;
COFF_Reloc data;
} COFF_RelocNode;
typedef struct COFF_RelocList
{
U64 count;
COFF_RelocNode *first;
COFF_RelocNode *last;
} COFF_RelocList;
typedef struct COFF_RelocArray
{
U64 count;
COFF_Reloc *v;
} COFF_RelocArray;
typedef struct COFF_RelocInfo
{
U64 array_off;
U64 count;
} COFF_RelocInfo;
typedef struct COFF_ResourceNode
{
struct COFF_ResourceNode *next;
COFF_Resource data;
} COFF_ResourceNode;
typedef struct COFF_ResourceList
{
U64 count;
COFF_ResourceNode *first;
COFF_ResourceNode *last;
} COFF_ResourceList;
////////////////////////////////
typedef struct COFF_ArchiveMember
{
COFF_ArchiveMemberHeader header;
U64 offset;
String8 data;
} COFF_ArchiveMember;
typedef struct COFF_ArchiveFirstMember
{
U32 symbol_count;
String8 member_offsets;
String8 string_table;
} COFF_ArchiveFirstMember;
typedef struct COFF_ArchiveSecondMember
{
U32 member_count;
U32 symbol_count;
String8 member_offsets;
String8 symbol_indices;
String8 string_table;
} COFF_ArchiveSecondMember;
typedef struct COFF_ArchiveMemberNode
{
struct COFF_ArchiveMemberNode *next;
COFF_ArchiveMember data;
} COFF_ArchiveMemberNode;
typedef struct COFF_ArchiveMemberList
{
U64 count;
COFF_ArchiveMemberNode *first;
COFF_ArchiveMemberNode *last;
} COFF_ArchiveMemberList;
typedef enum
{
COFF_Archive_Null,
COFF_Archive_Regular,
COFF_Archive_Thin
} COFF_ArchiveType;
typedef struct COFF_ArchiveParse
{
COFF_ArchiveFirstMember first_member;
COFF_ArchiveSecondMember second_member;
String8 long_names;
} COFF_ArchiveParse;
////////////////////////////////
//~ rjf: Globals
read_only global COFF_SectionHeader coff_section_header_nil = {0};
////////////////////////////////
//~ rjf: Helper Functions
internal B32 coff_is_big_obj(String8 data);
internal B32 coff_is_obj(String8 data);
internal COFF_HeaderInfo coff_header_info_from_data(String8 data);
internal U64 coff_align_size_from_section_flags(COFF_SectionFlags flags);
internal COFF_SymbolValueInterpType coff_interp_symbol(COFF_Symbol32 *symbol);
internal U64 coff_foff_from_voff(COFF_SectionHeader *sections, U64 section_count, U64 voff);
internal COFF_SectionHeader *coff_section_header_from_num(String8 data, U64 section_headers_off, U64 n);
internal String8 coff_section_header_get_name(COFF_SectionHeader *header, String8 coff_data, U64 string_table_base);
internal void coff_parse_section_name(String8 full_name, String8 *name_out, String8 *postfix_out);
internal String8 coff_read_symbol_name(String8 data, U64 string_table_base_offset, COFF_SymbolName *name);
internal void coff_symbol32_from_coff_symbol16(COFF_Symbol32 *sym32, COFF_Symbol16 *sym16);
internal COFF_Symbol32Array coff_symbol_array_from_data_16(Arena *arena, String8 data, U64 symbol_array_off, U64 symbol_count);
internal COFF_Symbol32Array coff_symbol_array_from_data_32(Arena *arena, String8 data, U64 symbol_array_off, U64 symbol_count);
internal COFF_Symbol32Array coff_symbol_array_from_data(Arena *arena, String8 data, U64 symbol_off, U64 symbol_count, U64 symbol_size);
internal COFF_Symbol16Node * coff_symbol16_list_push(Arena *arena, COFF_Symbol16List *list, COFF_Symbol16 symbol);
internal COFF_RelocInfo coff_reloc_info_from_section_header(String8 data, COFF_SectionHeader *header);
internal U64 coff_word_size_from_machine(COFF_MachineType machine);
internal String8 coff_make_import_lookup(Arena *arena, U16 hint, String8 name);
internal U32 coff_make_ordinal_32(U16 hint);
internal U64 coff_make_ordinal_64(U16 hint);
internal B32 coff_resource_id_is_equal(COFF_ResourceID a, COFF_ResourceID b);
internal COFF_ResourceID coff_resource_id_copy(Arena *arena, COFF_ResourceID id);
internal COFF_ResourceID coff_convert_resource_id(Arena *arena, COFF_ResourceID_16 *id_16);
internal U64 coff_read_resource_id(String8 res, U64 off, COFF_ResourceID_16 *id_out);
internal U64 coff_read_resource(String8 data, U64 off, Arena *arena, COFF_Resource *res_out);
internal COFF_ResourceList coff_resource_list_from_data(Arena *arena, String8 data);
internal COFF_DataType coff_data_type_from_data(String8 data);
internal B32 coff_is_import(String8 data);
internal B32 coff_is_archive(String8 data);
internal B32 coff_is_thin_archive(String8 data);
internal U64 coff_read_archive_member_header(String8 data, U64 offset, COFF_ArchiveMemberHeader *header_out);
internal COFF_ArchiveMember coff_read_archive_member(String8 data, U64 offset);
internal U64 coff_read_archive_import(String8 data, U64 offset, COFF_ImportHeader *header_out);
internal String8 coff_read_archive_long_name(String8 long_names, String8 name);
internal COFF_ArchiveMember coff_archive_member_from_data(String8 data);
internal U64 coff_archive_member_iter_init(String8 data);
internal B32 coff_archive_member_iter_next(String8 data, U64 *offset, COFF_ArchiveMember *member_out);
internal COFF_ArchiveParse coff_archive_parse_from_member_list(COFF_ArchiveMemberList list);
internal COFF_ArchiveParse coff_archive_from_data(Arena *arena, String8 data);
internal U64 coff_thin_archive_member_iter_init(String8 data);
internal B32 coff_thin_archive_member_iter_next(String8 data, U64 *offset, COFF_ArchiveMember *member_out);
internal COFF_ArchiveParse coff_thin_archive_from_data(Arena *arena, String8 data);
internal COFF_ArchiveType coff_archive_type_from_data(String8 data);
internal COFF_ArchiveParse coff_archive_parse_from_data(Arena *arena, String8 data);
internal String8 coff_string_from_comdat_select_type(COFF_ComdatSelectType select);
internal String8 coff_string_from_machine_type(COFF_MachineType machine);
internal String8 coff_string_from_section_flags(Arena *arena, COFF_SectionFlags flags);
#endif //COFF_H
+84
View File
@@ -0,0 +1,84 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Tables
@table(name lower_name code default display_string)
CTRL_ExceptionCodeKindTable:
{
{Win32CtrlC win32_ctrl_c 0x40010005 1 "(Win32) Control-C" }
{Win32CtrlBreak win32_ctrl_break 0x40010008 1 "(Win32) Control-Break" }
{Win32WinRTOriginateError win32_win_rt_originate_error 0x40080201 0 "(Win32) WinRT Originate Error" }
{Win32WinRTTransformError win32_win_rt_transform_error 0x40080202 0 "(Win32) WinRT Transform Error" }
{Win32RPCCallCancelled win32_rpc_call_cancelled 0x0000071a 0 "(Win32) RPC Call Cancelled" }
{Win32DatatypeMisalignment win32_datatype_misalignment 0x80000002 0 "(Win32) Data Type Misalignment" }
{Win32AccessViolation win32_access_violation 0xc0000005 1 "(Win32) Access Violation" }
{Win32InPageError win32_in_page_error 0xc0000006 0 "(Win32) In Page Error" }
{Win32InvalidHandle win32_invalid_handle 0xc0000008 1 "(Win32) Invalid Handle Specified" }
{Win32NotEnoughQuota win32_not_enough_quota 0xc0000017 0 "(Win32) Not Enough Quota" }
{Win32IllegalInstruction win32_illegal_instruction 0xc000001d 0 "(Win32) Illegal Instruction" }
{Win32CannotContinueException win32_cannot_continue_exception 0xc0000025 0 "(Win32) Cannot Continue From Exception" }
{Win32InvalidExceptionDisposition win32_invalid_exception_disposition 0xc0000026 0 "(Win32) Invalid Exception Disposition Returned By Handler" }
{Win32ArrayBoundsExceeded win32_array_bounds_exceeded 0xc000008c 0 "(Win32) Array Bounds Exceeded" }
{Win32FloatingPointDenormalOperand win32_floating_point_denormal_operand 0xc000008d 0 "(Win32) Floating-Point Denormal Operand" }
{Win32FloatingPointDivisionByZero win32_floating_point_division_by_zero 0xc000008e 0 "(Win32) Floating-Point Division By Zero" }
{Win32FloatingPointInexactResult win32_floating_point_inexact_result 0xc000008f 0 "(Win32) Floating-Point Inexact Result" }
{Win32FloatingPointInvalidOperation win32_floating_point_invalid_operation 0xc0000090 0 "(Win32) Floating-Point Invalid Operation" }
{Win32FloatingPointOverflow win32_floating_point_overflow 0xc0000091 0 "(Win32) Floating-Point Overflow" }
{Win32FloatingPointStackCheck win32_floating_point_stack_check 0xc0000092 0 "(Win32) Floating-Point Stack Check" }
{Win32FloatingPointUnderflow win32_floating_point_underflow 0xc0000093 0 "(Win32) Floating-Point Underflow" }
{Win32IntegerDivisionByZero win32_integer_division_by_zero 0xc0000094 0 "(Win32) Integer Division By Zero" }
{Win32IntegerOverflow win32_integer_overflow 0xc0000095 0 "(Win32) Integer Overflow" }
{Win32PrivilegedInstruction win32_privileged_instruction 0xc0000096 0 "(Win32) Privileged Instruction" }
{Win32StackOverflow win32_stack_overflow 0xc00000fd 0 "(Win32) Stack Overflow" }
{Win32UnableToLocateDLL win32_unable_to_locate_dll 0xc0000135 0 "(Win32) Unable To Locate DLL" }
{Win32OrdinalNotFound win32_ordinal_not_found 0xc0000138 0 "(Win32) Ordinal Not Found" }
{Win32EntryPointNotFound win32_entry_point_not_found 0xc0000139 0 "(Win32) Entry Point Not Found" }
{Win32DLLInitializationFailed win32_dll_initialization_failed 0xc0000142 0 "(Win32) DLL Initialization Failed" }
{Win32FloatingPointSSEMultipleFaults win32_floating_point_sse_multiple_faults 0xc00002b4 0 "(Win32) Floating Point SSE Multiple Faults" }
{Win32FloatingPointSSEMultipleTraps win32_floating_point_sse_multiple_traps 0xc00002b5 0 "(Win32) Floating Point SSE Multiple Traps" }
{Win32AssertionFailed win32_assertion_failed 0xc0000420 1 "(Win32) Assertion Failed" }
{Win32ModuleNotFound win32_module_not_found 0xc06d007e 0 "(Win32) Module Not Found" }
{Win32ProcedureNotFound win32_procedure_not_found 0xc06d007f 0 "(Win32) Procedure Not Found" }
{Win32SanitizerErrorDetected win32_sanitizer_error_detected 0xe073616e 1 "(Win32) Sanitizer Error Detected" }
{Win32SanitizerRawAccessViolation win32_sanitizer_raw_access_violation 0xe0736171 0 "(Win32) Sanitizer Raw Access Violation" }
}
////////////////////////////////
//~ rjf: Generators
@table_gen_enum CTRL_ExceptionCodeKind:
{
`CTRL_ExceptionCodeKind_Null,`;
@expand(CTRL_ExceptionCodeKindTable a) `CTRL_ExceptionCodeKind_$(a.name),`;
`CTRL_ExceptionCodeKind_COUNT`;
}
@table_gen_data(type:U32, fallback:0)
ctrl_exception_code_kind_code_table:
{
`0,`;
@expand(CTRL_ExceptionCodeKindTable a) `$(a.code),`;
}
@table_gen_data(type:String8, fallback:`{0}`)
ctrl_exception_code_kind_display_string_table:
{
`{0},`;
@expand(CTRL_ExceptionCodeKindTable a) `str8_lit_comp("$(a.display_string)"),`;
}
@table_gen_data(type:String8, fallback:`{0}`)
ctrl_exception_code_kind_lowercase_code_string_table:
{
`{0},`;
@expand(CTRL_ExceptionCodeKindTable a) `str8_lit_comp("$(a.lower_name)"),`;
}
@table_gen_data(type:B8, fallback:0)
ctrl_exception_code_kind_default_enable_table:
{
`0,`;
@expand(CTRL_ExceptionCodeKindTable a) `$(a.default),`;
}
+3020
View File
File diff suppressed because it is too large Load Diff
+601
View File
@@ -0,0 +1,601 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CTRL_CORE_H
#define CTRL_CORE_H
////////////////////////////////
//~ rjf: ID Types
typedef U64 CTRL_MsgID;
typedef U64 CTRL_MachineID;
#define CTRL_MachineID_Client (1)
////////////////////////////////
//~ rjf: Handle Type
typedef struct CTRL_Handle CTRL_Handle;
struct CTRL_Handle
{
U64 u64[1];
};
////////////////////////////////
//~ rjf: Machine/Handle Pair Types
typedef struct CTRL_MachineIDHandlePair CTRL_MachineIDHandlePair;
struct CTRL_MachineIDHandlePair
{
CTRL_MachineID machine_id;
CTRL_Handle handle;
};
typedef struct CTRL_MachineIDHandlePairNode CTRL_MachineIDHandlePairNode;
struct CTRL_MachineIDHandlePairNode
{
CTRL_MachineIDHandlePairNode *next;
CTRL_MachineIDHandlePair v;
};
typedef struct CTRL_MachineIDHandlePairList CTRL_MachineIDHandlePairList;
struct CTRL_MachineIDHandlePairList
{
CTRL_MachineIDHandlePairNode *first;
CTRL_MachineIDHandlePairNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Trap Types
typedef U32 CTRL_TrapFlags;
enum
{
CTRL_TrapFlag_IgnoreStackPointerCheck = (1<<0),
CTRL_TrapFlag_SingleStepAfterHit = (1<<1),
CTRL_TrapFlag_SaveStackPointer = (1<<2),
CTRL_TrapFlag_BeginSpoofMode = (1<<3),
CTRL_TrapFlag_EndStepping = (1<<4),
};
typedef struct CTRL_Trap CTRL_Trap;
struct CTRL_Trap
{
CTRL_TrapFlags flags;
U64 vaddr;
};
typedef struct CTRL_TrapNode CTRL_TrapNode;
struct CTRL_TrapNode
{
CTRL_TrapNode *next;
CTRL_Trap v;
};
typedef struct CTRL_TrapList CTRL_TrapList;
struct CTRL_TrapList
{
CTRL_TrapNode *first;
CTRL_TrapNode *last;
U64 count;
};
typedef struct CTRL_Spoof CTRL_Spoof;
struct CTRL_Spoof
{
CTRL_Handle process;
U64 vaddr;
U64 new_ip_value;
};
////////////////////////////////
//~ rjf: User Breakpoint Types
typedef enum CTRL_UserBreakpointKind
{
CTRL_UserBreakpointKind_FileNameAndLineColNumber,
CTRL_UserBreakpointKind_SymbolNameAndOffset,
CTRL_UserBreakpointKind_VirtualAddress,
CTRL_UserBreakpointKind_COUNT
}
CTRL_UserBreakpointKind;
typedef struct CTRL_UserBreakpoint CTRL_UserBreakpoint;
struct CTRL_UserBreakpoint
{
CTRL_UserBreakpointKind kind;
String8 string;
TxtPt pt;
U64 u64;
String8 condition;
};
typedef struct CTRL_UserBreakpointNode CTRL_UserBreakpointNode;
struct CTRL_UserBreakpointNode
{
CTRL_UserBreakpointNode *next;
CTRL_UserBreakpoint v;
};
typedef struct CTRL_UserBreakpointList CTRL_UserBreakpointList;
struct CTRL_UserBreakpointList
{
CTRL_UserBreakpointNode *first;
CTRL_UserBreakpointNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Generated Code
#include "generated/ctrl.meta.h"
////////////////////////////////
//~ rjf: Message Types
typedef enum CTRL_MsgKind
{
CTRL_MsgKind_Null,
CTRL_MsgKind_LaunchAndHandshake,
CTRL_MsgKind_LaunchAndInit,
CTRL_MsgKind_Attach,
CTRL_MsgKind_Kill,
CTRL_MsgKind_Detach,
CTRL_MsgKind_Run,
CTRL_MsgKind_SingleStep,
CTRL_MsgKind_SetUserEntryPoints,
CTRL_MsgKind_COUNT,
}
CTRL_MsgKind;
typedef struct CTRL_Msg CTRL_Msg;
struct CTRL_Msg
{
CTRL_MsgKind kind;
CTRL_MsgID msg_id;
CTRL_MachineID machine_id;
CTRL_Handle entity;
CTRL_Handle parent;
U32 entity_id;
U32 exit_code;
B32 env_inherit;
U64 exception_code_filters[(CTRL_ExceptionCodeKind_COUNT+63)/64];
String8 path;
String8List strings;
String8List cmd_line_string_list;
String8List env_string_list;
CTRL_TrapList traps;
CTRL_UserBreakpointList user_bps;
CTRL_MachineIDHandlePairList freeze_state_threads; // NOTE(rjf): can be frozen or unfrozen, depending on `freeze_state_is_frozen`
B32 freeze_state_is_frozen;
};
typedef struct CTRL_MsgNode CTRL_MsgNode;
struct CTRL_MsgNode
{
CTRL_MsgNode *next;
CTRL_Msg v;
};
typedef struct CTRL_MsgList CTRL_MsgList;
struct CTRL_MsgList
{
CTRL_MsgNode *first;
CTRL_MsgNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Event Types
typedef enum CTRL_EventKind
{
CTRL_EventKind_Null,
CTRL_EventKind_Error,
//- rjf: starts/stops
CTRL_EventKind_Started,
CTRL_EventKind_Stopped,
//- rjf: entity creation/deletion
CTRL_EventKind_NewProc,
CTRL_EventKind_NewThread,
CTRL_EventKind_NewModule,
CTRL_EventKind_EndProc,
CTRL_EventKind_EndThread,
CTRL_EventKind_EndModule,
//- rjf: debug strings
CTRL_EventKind_DebugString,
CTRL_EventKind_ThreadName,
//- rjf: memory
CTRL_EventKind_MemReserve,
CTRL_EventKind_MemCommit,
CTRL_EventKind_MemDecommit,
CTRL_EventKind_MemRelease,
//- rjf: ctrl requests
CTRL_EventKind_LaunchAndHandshakeDone,
CTRL_EventKind_LaunchAndInitDone,
CTRL_EventKind_AttachDone,
CTRL_EventKind_KillDone,
CTRL_EventKind_DetachDone,
CTRL_EventKind_COUNT
}
CTRL_EventKind;
typedef enum CTRL_EventCause
{
CTRL_EventCause_Null,
CTRL_EventCause_Error,
CTRL_EventCause_Finished,
CTRL_EventCause_UserBreakpoint,
CTRL_EventCause_InterruptedByTrap,
CTRL_EventCause_InterruptedByException,
CTRL_EventCause_InterruptedByHalt,
CTRL_EventCause_COUNT
}
CTRL_EventCause;
typedef enum CTRL_ExceptionKind
{
CTRL_ExceptionKind_Null,
CTRL_ExceptionKind_MemoryRead,
CTRL_ExceptionKind_MemoryWrite,
CTRL_ExceptionKind_MemoryExecute,
CTRL_ExceptionKind_CppThrow,
CTRL_ExceptionKind_COUNT
}
CTRL_ExceptionKind;
typedef struct CTRL_Event CTRL_Event;
struct CTRL_Event
{
CTRL_EventKind kind;
CTRL_EventCause cause;
CTRL_ExceptionKind exception_kind;
CTRL_MsgID msg_id;
CTRL_MachineID machine_id;
CTRL_Handle entity;
CTRL_Handle parent;
Architecture arch;
U64 u64_code;
U32 entity_id;
Rng1U64 vaddr_rng;
U64 rip_vaddr;
U64 stack_base;
U64 tls_root;
U32 exception_code;
String8 string;
};
typedef struct CTRL_EventNode CTRL_EventNode;
struct CTRL_EventNode
{
CTRL_EventNode *next;
CTRL_Event v;
};
typedef struct CTRL_EventList CTRL_EventList;
struct CTRL_EventList
{
CTRL_EventNode *first;
CTRL_EventNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Process Memory Cache Types
// NOTE(rjf):
//
// Process memory is cached with a 5-level page table. Each level has 256
// slots, and is indexed into with 8 bits. Each index is extracted from a
// virtual address in the following manner:
//
// |1------||2------||3------||4------||5------||byte-n-page|
// xxxxxxxx xxxx0000 00000000 00000000 00000000 00000000 0000xxxx xxxxxxxx
//
// The top 12 bits are not used (a 52-bit address space is supported at most).
// The next 8 most-significant-bits are used to index into the level 1 table.
// The next 8 are used to index into the level 2. Then the level 3. Then the
// level 4. At the level 4 table, instead of pointing to other tables, each
// slot points at the base address of a cached 4KB page. The next 8 bits are
// used to index into that table. The final 12 bits in the address are used
// to refer to unique bytes within each page.
typedef struct CTRL_ProcessMemoryCacheNode4 CTRL_ProcessMemoryCacheNode4;
struct CTRL_ProcessMemoryCacheNode4
{
U64 page_memgen_idxs[256];
U128 page_hashes[256];
};
typedef struct CTRL_ProcessMemoryCacheNode3 CTRL_ProcessMemoryCacheNode3;
struct CTRL_ProcessMemoryCacheNode3
{
CTRL_ProcessMemoryCacheNode4 *children[256];
};
typedef struct CTRL_ProcessMemoryCacheNode2 CTRL_ProcessMemoryCacheNode2;
struct CTRL_ProcessMemoryCacheNode2
{
CTRL_ProcessMemoryCacheNode3 *children[256];
};
typedef struct CTRL_ProcessMemoryCacheNode1 CTRL_ProcessMemoryCacheNode1;
struct CTRL_ProcessMemoryCacheNode1
{
CTRL_ProcessMemoryCacheNode2 *children[256];
};
typedef struct CTRL_ProcessMemoryRangeHashNode CTRL_ProcessMemoryRangeHashNode;
struct CTRL_ProcessMemoryRangeHashNode
{
CTRL_ProcessMemoryRangeHashNode *next;
Rng1U64 vaddr_range;
B32 zero_terminated;
U128 hash;
U64 memgen_idx;
B32 is_taken;
};
typedef struct CTRL_ProcessMemoryRangeHashSlot CTRL_ProcessMemoryRangeHashSlot;
struct CTRL_ProcessMemoryRangeHashSlot
{
CTRL_ProcessMemoryRangeHashNode *first;
CTRL_ProcessMemoryRangeHashNode *last;
};
typedef struct CTRL_ProcessMemoryCacheNode CTRL_ProcessMemoryCacheNode;
struct CTRL_ProcessMemoryCacheNode
{
CTRL_ProcessMemoryCacheNode *next;
CTRL_ProcessMemoryCacheNode *prev;
Arena *arena;
CTRL_MachineID machine_id;
CTRL_Handle process;
CTRL_ProcessMemoryCacheNode1 *children[256];
U64 range_hash_slots_count;
CTRL_ProcessMemoryRangeHashSlot *range_hash_slots;
};
typedef struct CTRL_ProcessMemoryCacheSlot CTRL_ProcessMemoryCacheSlot;
struct CTRL_ProcessMemoryCacheSlot
{
CTRL_ProcessMemoryCacheNode *first;
CTRL_ProcessMemoryCacheNode *last;
};
typedef struct CTRL_ProcessMemoryCacheStripe CTRL_ProcessMemoryCacheStripe;
struct CTRL_ProcessMemoryCacheStripe
{
OS_Handle rw_mutex;
};
typedef struct CTRL_ProcessMemoryCache CTRL_ProcessMemoryCache;
struct CTRL_ProcessMemoryCache
{
U64 slots_count;
CTRL_ProcessMemoryCacheSlot *slots;
U64 stripes_count;
CTRL_ProcessMemoryCacheStripe *stripes;
};
////////////////////////////////
//~ rjf: Wakeup Hook Function Types
#define CTRL_WAKEUP_FUNCTION_DEF(name) void name(void)
typedef CTRL_WAKEUP_FUNCTION_DEF(CTRL_WakeupFunctionType);
////////////////////////////////
//~ rjf: Main State Types
typedef struct CTRL_State CTRL_State;
struct CTRL_State
{
Arena *arena;
CTRL_WakeupFunctionType *wakeup_hook;
U64 run_idx;
U64 memgen_idx;
// rjf: name -> register/alias hash tables for eval
EVAL_String2NumMap arch_string2reg_tables[Architecture_COUNT];
EVAL_String2NumMap arch_string2alias_tables[Architecture_COUNT];
// rjf: process memory cache
CTRL_ProcessMemoryCache process_memory_cache;
// rjf: user -> ctrl msg ring buffer
U64 u2c_ring_size;
U8 *u2c_ring_base;
U64 u2c_ring_write_pos;
U64 u2c_ring_read_pos;
OS_Handle u2c_ring_mutex;
OS_Handle u2c_ring_cv;
// rjf: ctrl -> user event ring buffer
U64 c2u_ring_size;
U8 *c2u_ring_base;
U64 c2u_ring_write_pos;
U64 c2u_ring_read_pos;
OS_Handle c2u_ring_mutex;
OS_Handle c2u_ring_cv;
// rjf: ctrl thread state
OS_Handle ctrl_thread;
Arena *demon_event_arena;
DEMON_EventNode *first_demon_event_node;
DEMON_EventNode *last_demon_event_node;
DEMON_EventNode *free_demon_event_node;
Arena *user_entry_point_arena;
String8List user_entry_points;
U64 exception_code_filters[(CTRL_ExceptionCodeKind_COUNT+63)/64];
U64 process_counter;
// rjf: user -> memstream ring buffer
U64 u2ms_ring_size;
U8 *u2ms_ring_base;
U64 u2ms_ring_write_pos;
U64 u2ms_ring_read_pos;
OS_Handle u2ms_ring_mutex;
OS_Handle u2ms_ring_cv;
// rjf: memory stream threads
U64 ms_thread_count;
OS_Handle *ms_threads;
};
////////////////////////////////
//~ rjf: Globals
global CTRL_State *ctrl_state = 0;
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void ctrl_init(CTRL_WakeupFunctionType *wakeup_hook);
////////////////////////////////
//~ rjf: Basic Type Functions
internal U64 ctrl_hash_from_string(String8 string);
internal CTRL_EventCause ctrl_event_cause_from_demon_event_kind(DEMON_EventKind event_kind);
internal B32 ctrl_handle_match(CTRL_Handle a, CTRL_Handle b);
////////////////////////////////
//~ rjf: Ctrl <-> Demon Handle Translation Functions
internal DEMON_Handle ctrl_demon_handle_from_ctrl(CTRL_Handle h);
internal CTRL_Handle ctrl_handle_from_demon(DEMON_Handle h);
////////////////////////////////
//~ rjf: Machine/Handle Pair Type Functions
internal void ctrl_machine_id_handle_pair_list_push(Arena *arena, CTRL_MachineIDHandlePairList *list, CTRL_MachineIDHandlePair *pair);
internal CTRL_MachineIDHandlePairList ctrl_machine_id_handle_pair_list_copy(Arena *arena, CTRL_MachineIDHandlePairList *src);
////////////////////////////////
//~ rjf: Trap Type Functions
internal void ctrl_trap_list_push(Arena *arena, CTRL_TrapList *list, CTRL_Trap *trap);
internal CTRL_TrapList ctrl_trap_list_copy(Arena *arena, CTRL_TrapList *src);
////////////////////////////////
//~ rjf: User Breakpoint Type Functions
internal void ctrl_user_breakpoint_list_push(Arena *arena, CTRL_UserBreakpointList *list, CTRL_UserBreakpoint *bp);
internal CTRL_UserBreakpointList ctrl_user_breakpoint_list_copy(Arena *arena, CTRL_UserBreakpointList *src);
internal void ctrl_append_resolved_module_user_bp_traps(Arena *arena, DEMON_Handle process, DEMON_Handle module, CTRL_UserBreakpointList *user_bps, DEMON_TrapChunkList *traps_out);
internal void ctrl_append_resolved_process_user_bp_traps(Arena *arena, DEMON_Handle process, CTRL_UserBreakpointList *user_bps, DEMON_TrapChunkList *traps_out);
////////////////////////////////
//~ rjf: Message Type Functions
//- rjf: deep copying
internal void ctrl_msg_deep_copy(Arena *arena, CTRL_Msg *dst, CTRL_Msg *src);
//- rjf: list building
internal CTRL_Msg *ctrl_msg_list_push(Arena *arena, CTRL_MsgList *list);
//- rjf: serialization
internal String8 ctrl_serialized_string_from_msg_list(Arena *arena, CTRL_MsgList *msgs);
internal CTRL_MsgList ctrl_msg_list_from_serialized_string(Arena *arena, String8 string);
////////////////////////////////
//~ rjf: Event Type Functions
//- rjf: list building
internal CTRL_Event *ctrl_event_list_push(Arena *arena, CTRL_EventList *list);
internal void ctrl_event_list_concat_in_place(CTRL_EventList *dst, CTRL_EventList *to_push);
//- rjf: serialization
internal String8 ctrl_serialized_string_from_event(Arena *arena, CTRL_Event *event);
internal CTRL_Event ctrl_event_from_serialized_string(Arena *arena, String8 string);
////////////////////////////////
//~ rjf: Shared Functions
//- rjf: run index
internal U64 ctrl_run_idx(void);
internal U64 ctrl_memgen_idx(void);
//- rjf: halt everything
internal void ctrl_halt(void);
//- rjf: exe -> dbg path mapping
internal String8 ctrl_inferred_og_dbg_path_from_exe_path(Arena *arena, String8 exe_path);
internal String8 ctrl_forced_og_dbg_path_from_exe_path(Arena *arena, String8 exe_path);
internal String8 ctrl_natural_og_dbg_path_from_exe_path(Arena *arena, String8 exe_path);
internal String8 ctrl_og_dbg_path_from_exe_path(Arena *arena, String8 exe_path);
//- rjf: handle -> arch
internal Architecture ctrl_arch_from_handle(CTRL_MachineID machine, CTRL_Handle handle);
//- rjf: process memory reading/writing
internal U64 ctrl_process_read(CTRL_MachineID machine_id, CTRL_Handle process, Rng1U64 range, void *dst);
internal String8 ctrl_query_cached_data_from_process_vaddr_range(Arena *arena, CTRL_MachineID machine_id, CTRL_Handle process, Rng1U64 range);
internal String8 ctrl_query_cached_zero_terminated_data_from_process_vaddr_limit(Arena *arena, CTRL_MachineID machine_id, CTRL_Handle process, U64 vaddr, U64 limit);
internal B32 ctrl_process_write_data(CTRL_MachineID machine_id, CTRL_Handle process, U64 vaddr, String8 data);
internal U128 ctrl_stored_hash_from_process_vaddr_range(CTRL_MachineID machine_id, CTRL_Handle process, Rng1U64 range, B32 zero_terminated);
//- rjf: register reading/writing
internal void *ctrl_reg_block_from_thread(CTRL_MachineID machine_id, CTRL_Handle thread);
internal B32 ctrl_thread_write_reg_block(CTRL_MachineID machine_id, CTRL_Handle thread, void *block);
internal U64 ctrl_rip_from_thread(CTRL_MachineID machine_id, CTRL_Handle thread);
internal B32 ctrl_thread_write_rip(CTRL_MachineID machine_id, CTRL_Handle thread, U64 rip);
internal U64 ctrl_tls_root_vaddr_from_thread(CTRL_MachineID machine_id, CTRL_Handle thread);
//- rjf: name -> register/alias hash tables, for eval
internal EVAL_String2NumMap *ctrl_string2reg_from_arch(Architecture arch);
internal EVAL_String2NumMap *ctrl_string2alias_from_arch(Architecture arch);
////////////////////////////////
//~ rjf: User -> Ctrl Communication
internal B32 ctrl_u2c_push_msgs(CTRL_MsgList *msgs, U64 endt_us);
internal CTRL_MsgList ctrl_u2c_pop_msgs(Arena *arena);
////////////////////////////////
//~ rjf: Ctrl -> User Communication
internal void ctrl_c2u_push_events(CTRL_EventList *events);
internal CTRL_EventList ctrl_c2u_pop_events(Arena *arena);
////////////////////////////////
//~ rjf: User -> Memory Stream Communication
internal B32 ctrl_u2ms_enqueue_req(CTRL_MachineID machine_id, CTRL_Handle process, Rng1U64 vaddr_range, B32 zero_terminated, U64 endt_us);
internal void ctrl_u2ms_dequeue_req(CTRL_MachineID *out_machine_id, CTRL_Handle *out_process, Rng1U64 *out_vaddr_range, B32 *out_zero_terminated);
////////////////////////////////
//~ rjf: Control-Thread-Only Functions
//- rjf: entry point
internal void ctrl_thread__entry_point(void *p);
//- rjf: attached process running/event gathering
internal DEMON_Event *ctrl_thread__next_demon_event(Arena *arena, CTRL_Msg *msg, DEMON_RunCtrls *run_ctrls, CTRL_Spoof *spoof);
//- rjf: eval helpers
internal B32 ctrl_eval_memory_read(void *u, void *out, U64 addr, U64 size);
//- rjf: msg kind implementations
internal void ctrl_thread__launch_and_handshake(CTRL_Msg *msg);
internal void ctrl_thread__launch_and_init(CTRL_Msg *msg);
internal void ctrl_thread__attach(CTRL_Msg *msg);
internal void ctrl_thread__kill(CTRL_Msg *msg);
internal void ctrl_thread__detach(CTRL_Msg *msg);
internal void ctrl_thread__run(CTRL_Msg *msg);
internal void ctrl_thread__single_step(CTRL_Msg *msg);
////////////////////////////////
//~ rjf: Memory-Stream-Thread-Only Functions
//- rjf: entry point
internal void ctrl_mem_stream_thread__entry_point(void *p);
#endif //CTRL_CORE_H
+4
View File
@@ -0,0 +1,4 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "ctrl_core.c"
+77
View File
@@ -0,0 +1,77 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CTRL_INC_H
#define CTRL_INC_H
////////////////////////////////
//~ NOTE(rjf): Control Layer Overview (2023/8/29)
//
// This layer's purpose is to provide access to the asynchronously-running, low
// level parts of a debugger, running on the debugger client. This primarily
// consists of process control, using the Demon layer (the lower level
// abstraction layer for process control, across multiple OSes), but including
// higher-level concepts, like stepping, breakpoint resolution, conditional
// breakpoint evaluation, and so on. Right now, this just includes process
// control *local to the debugger client machine*. But in the future, this can
// also include communication to multiple target machines, all running their
// own process controller, using the Demon layer.
//
// This part of a debugger must run asynchronously to prevent blocking the UI -
// ideally our debugger is designed such that, if targets are running, the
// debugger frontend is still usable for a variety of purposes. So, in short,
// the asynchronously-running "control thread", implemented by this layer, is
// tasked with communicating with a separately executing "user thread". This
// communication happens in two directions - `user -> ctrl`, and the reverse,
// `ctrl -> user`.
//
// In the case of `user -> ctrl` communication, this is done with a ring buffer
// of "messages" (`CTRL_Msg`), pushed via `ctrl_u2c_push_msgs`. These messages
// include commands like: launching targets, attaching to targets, killing
// targets, detaching from targets, stepping/running, or single stepping.
//
// In the case of `ctrl -> user` communication, this is done with a ring buffer
// of "events" (`CTRL_Event`), popped via `ctrl_c2u_pop_events`. These events
// include information about what happened during the execution of targets -
// including: process/module/thread creation, process/module/thread deletion,
// debug strings, thread name events, memory allocation events, and stop events
// (where stops can be caused by: user breakpoints, traps set for stepping,
// exceptions, halts, or errors).
//
// The various stepping algorithms are implemented with two concepts: (a) the
// "trap net", and (b) "spoofs".
//
// A "trap net" is a term which refers to a set of addresses paired with a set
// of behavioral flags. Before targets run, trap instructions are written to
// these addresses. After targets stop, these addresses are reset to their
// original bytes. These trap instructions cause the debugger's targets to
// stop executing, and based on which behavioral flags are associated with
// the instruction causing the stop, the control thread may adjust parameters
// used for running, then continue execution, or it will not resume target
// execution, and will report stopped events. These behavioral flags can
// include: single-stepping the stopped thread to execute the instruction at
// the trap location, saving a stack pointer "check value" (where this check
// value is compared against when making decisions about whether to continue
// running or not), and so on. It's complicated to unpack why exactly these
// behaviors are useful, but the TL;DR of it is that they are used for a
// variety of stepping behaviors. For example, when doing a "step into" step,
// a `call` instruction can have a trap set at it, and will be marked with
// a "single-step-after" trap flag, as well as the "end stepping" trap flag,
// such that the step operation will complete after the `call` has executed.
//
// A "spoof" is a feature the control layer uses to detect when some thread
// returns from a particular sub-callstack. This is useful when implementing
// "step over" in functions that may be recursive. In short, unlike a trap,
// which writes a trap instruction (like `int3`) into an instruction stream,
// a spoof overwrites a *return address* on some thread's *stack*. This return
// address is not a valid address for executing code -- it is simply a value
// that the debugger can recognize, such that it is notified when the thread
// returns from some level in a callstack. When the thread exits some function,
// it will return to the "spoofed" address, and it will immediately hit an
// exception, because the spoofed address will not be a valid address for
// code execution. At that point, the debugger can move the thread back to
// the pre-spoof return address, and resume execution.
#include "ctrl_core.h"
#endif //CTRL_INC_H
+5
View File
@@ -0,0 +1,5 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
+216
View File
@@ -0,0 +1,216 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
#ifndef CTRL_META_H
#define CTRL_META_H
typedef enum CTRL_ExceptionCodeKind
{
CTRL_ExceptionCodeKind_Null,
CTRL_ExceptionCodeKind_Win32CtrlC,
CTRL_ExceptionCodeKind_Win32CtrlBreak,
CTRL_ExceptionCodeKind_Win32WinRTOriginateError,
CTRL_ExceptionCodeKind_Win32WinRTTransformError,
CTRL_ExceptionCodeKind_Win32RPCCallCancelled,
CTRL_ExceptionCodeKind_Win32DatatypeMisalignment,
CTRL_ExceptionCodeKind_Win32AccessViolation,
CTRL_ExceptionCodeKind_Win32InPageError,
CTRL_ExceptionCodeKind_Win32InvalidHandle,
CTRL_ExceptionCodeKind_Win32NotEnoughQuota,
CTRL_ExceptionCodeKind_Win32IllegalInstruction,
CTRL_ExceptionCodeKind_Win32CannotContinueException,
CTRL_ExceptionCodeKind_Win32InvalidExceptionDisposition,
CTRL_ExceptionCodeKind_Win32ArrayBoundsExceeded,
CTRL_ExceptionCodeKind_Win32FloatingPointDenormalOperand,
CTRL_ExceptionCodeKind_Win32FloatingPointDivisionByZero,
CTRL_ExceptionCodeKind_Win32FloatingPointInexactResult,
CTRL_ExceptionCodeKind_Win32FloatingPointInvalidOperation,
CTRL_ExceptionCodeKind_Win32FloatingPointOverflow,
CTRL_ExceptionCodeKind_Win32FloatingPointStackCheck,
CTRL_ExceptionCodeKind_Win32FloatingPointUnderflow,
CTRL_ExceptionCodeKind_Win32IntegerDivisionByZero,
CTRL_ExceptionCodeKind_Win32IntegerOverflow,
CTRL_ExceptionCodeKind_Win32PrivilegedInstruction,
CTRL_ExceptionCodeKind_Win32StackOverflow,
CTRL_ExceptionCodeKind_Win32UnableToLocateDLL,
CTRL_ExceptionCodeKind_Win32OrdinalNotFound,
CTRL_ExceptionCodeKind_Win32EntryPointNotFound,
CTRL_ExceptionCodeKind_Win32DLLInitializationFailed,
CTRL_ExceptionCodeKind_Win32FloatingPointSSEMultipleFaults,
CTRL_ExceptionCodeKind_Win32FloatingPointSSEMultipleTraps,
CTRL_ExceptionCodeKind_Win32AssertionFailed,
CTRL_ExceptionCodeKind_Win32ModuleNotFound,
CTRL_ExceptionCodeKind_Win32ProcedureNotFound,
CTRL_ExceptionCodeKind_Win32SanitizerErrorDetected,
CTRL_ExceptionCodeKind_Win32SanitizerRawAccessViolation,
CTRL_ExceptionCodeKind_COUNT
} CTRL_ExceptionCodeKind;
U32 ctrl_exception_code_kind_code_table[] =
{
0,
0x40010005,
0x40010008,
0x40080201,
0x40080202,
0x0000071a,
0x80000002,
0xc0000005,
0xc0000006,
0xc0000008,
0xc0000017,
0xc000001d,
0xc0000025,
0xc0000026,
0xc000008c,
0xc000008d,
0xc000008e,
0xc000008f,
0xc0000090,
0xc0000091,
0xc0000092,
0xc0000093,
0xc0000094,
0xc0000095,
0xc0000096,
0xc00000fd,
0xc0000135,
0xc0000138,
0xc0000139,
0xc0000142,
0xc00002b4,
0xc00002b5,
0xc0000420,
0xc06d007e,
0xc06d007f,
0xe073616e,
0xe0736171,
};
String8 ctrl_exception_code_kind_display_string_table[] =
{
{0},
str8_lit_comp("(Win32) Control-C"),
str8_lit_comp("(Win32) Control-Break"),
str8_lit_comp("(Win32) WinRT Originate Error"),
str8_lit_comp("(Win32) WinRT Transform Error"),
str8_lit_comp("(Win32) RPC Call Cancelled"),
str8_lit_comp("(Win32) Data Type Misalignment"),
str8_lit_comp("(Win32) Access Violation"),
str8_lit_comp("(Win32) In Page Error"),
str8_lit_comp("(Win32) Invalid Handle Specified"),
str8_lit_comp("(Win32) Not Enough Quota"),
str8_lit_comp("(Win32) Illegal Instruction"),
str8_lit_comp("(Win32) Cannot Continue From Exception"),
str8_lit_comp("(Win32) Invalid Exception Disposition Returned By Handler"),
str8_lit_comp("(Win32) Array Bounds Exceeded"),
str8_lit_comp("(Win32) Floating-Point Denormal Operand"),
str8_lit_comp("(Win32) Floating-Point Division By Zero"),
str8_lit_comp("(Win32) Floating-Point Inexact Result"),
str8_lit_comp("(Win32) Floating-Point Invalid Operation"),
str8_lit_comp("(Win32) Floating-Point Overflow"),
str8_lit_comp("(Win32) Floating-Point Stack Check"),
str8_lit_comp("(Win32) Floating-Point Underflow"),
str8_lit_comp("(Win32) Integer Division By Zero"),
str8_lit_comp("(Win32) Integer Overflow"),
str8_lit_comp("(Win32) Privileged Instruction"),
str8_lit_comp("(Win32) Stack Overflow"),
str8_lit_comp("(Win32) Unable To Locate DLL"),
str8_lit_comp("(Win32) Ordinal Not Found"),
str8_lit_comp("(Win32) Entry Point Not Found"),
str8_lit_comp("(Win32) DLL Initialization Failed"),
str8_lit_comp("(Win32) Floating Point SSE Multiple Faults"),
str8_lit_comp("(Win32) Floating Point SSE Multiple Traps"),
str8_lit_comp("(Win32) Assertion Failed"),
str8_lit_comp("(Win32) Module Not Found"),
str8_lit_comp("(Win32) Procedure Not Found"),
str8_lit_comp("(Win32) Sanitizer Error Detected"),
str8_lit_comp("(Win32) Sanitizer Raw Access Violation"),
};
String8 ctrl_exception_code_kind_lowercase_code_string_table[] =
{
{0},
str8_lit_comp("win32_ctrl_c"),
str8_lit_comp("win32_ctrl_break"),
str8_lit_comp("win32_win_rt_originate_error"),
str8_lit_comp("win32_win_rt_transform_error"),
str8_lit_comp("win32_rpc_call_cancelled"),
str8_lit_comp("win32_datatype_misalignment"),
str8_lit_comp("win32_access_violation"),
str8_lit_comp("win32_in_page_error"),
str8_lit_comp("win32_invalid_handle"),
str8_lit_comp("win32_not_enough_quota"),
str8_lit_comp("win32_illegal_instruction"),
str8_lit_comp("win32_cannot_continue_exception"),
str8_lit_comp("win32_invalid_exception_disposition"),
str8_lit_comp("win32_array_bounds_exceeded"),
str8_lit_comp("win32_floating_point_denormal_operand"),
str8_lit_comp("win32_floating_point_division_by_zero"),
str8_lit_comp("win32_floating_point_inexact_result"),
str8_lit_comp("win32_floating_point_invalid_operation"),
str8_lit_comp("win32_floating_point_overflow"),
str8_lit_comp("win32_floating_point_stack_check"),
str8_lit_comp("win32_floating_point_underflow"),
str8_lit_comp("win32_integer_division_by_zero"),
str8_lit_comp("win32_integer_overflow"),
str8_lit_comp("win32_privileged_instruction"),
str8_lit_comp("win32_stack_overflow"),
str8_lit_comp("win32_unable_to_locate_dll"),
str8_lit_comp("win32_ordinal_not_found"),
str8_lit_comp("win32_entry_point_not_found"),
str8_lit_comp("win32_dll_initialization_failed"),
str8_lit_comp("win32_floating_point_sse_multiple_faults"),
str8_lit_comp("win32_floating_point_sse_multiple_traps"),
str8_lit_comp("win32_assertion_failed"),
str8_lit_comp("win32_module_not_found"),
str8_lit_comp("win32_procedure_not_found"),
str8_lit_comp("win32_sanitizer_error_detected"),
str8_lit_comp("win32_sanitizer_raw_access_violation"),
};
B8 ctrl_exception_code_kind_default_enable_table[] =
{
0,
1,
1,
0,
0,
0,
0,
1,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
1,
0,
};
#endif // CTRL_META_H
+539
View File
@@ -0,0 +1,539 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void
dasm_init(void)
{
Arena *arena = arena_alloc();
dasm_shared = push_array(arena, DASM_Shared, 1);
dasm_shared->arena = arena;
dasm_shared->entity_map.slots_count = 1024;
dasm_shared->entity_map.slots = push_array(arena, DASM_EntitySlot, dasm_shared->entity_map.slots_count);
dasm_shared->entity_map_stripes.count = 64;
dasm_shared->entity_map_stripes.v = push_array(arena, DASM_Stripe, dasm_shared->entity_map_stripes.count);
for(U64 idx = 0; idx < dasm_shared->entity_map_stripes.count; idx += 1)
{
dasm_shared->entity_map_stripes.v[idx].arena = arena_alloc();
dasm_shared->entity_map_stripes.v[idx].rw_mutex = os_rw_mutex_alloc();
dasm_shared->entity_map_stripes.v[idx].cv = os_condition_variable_alloc();
}
dasm_shared->u2d_ring_mutex = os_mutex_alloc();
dasm_shared->u2d_ring_cv = os_condition_variable_alloc();
dasm_shared->u2d_ring_size = KB(64);
dasm_shared->u2d_ring_base = push_array_no_zero(arena, U8, dasm_shared->u2d_ring_size);
dasm_shared->decode_thread_count = Max(1, os_logical_core_count()-1);
dasm_shared->decode_threads = push_array(arena, OS_Handle, dasm_shared->decode_thread_count);
for(U64 idx = 0; idx < dasm_shared->decode_thread_count; idx += 1)
{
dasm_shared->decode_threads[idx] = os_launch_thread(dasm_decode_thread_entry_point, (void *)idx, 0);
}
}
////////////////////////////////
//~ rjf: Basic Helpers
internal U64
dasm_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: Instruction Type Functions
internal void
dasm_inst_chunk_list_push(Arena *arena, DASM_InstChunkList *list, U64 cap, DASM_Inst *inst)
{
DASM_InstChunkNode *node = list->last;
if(node == 0 || node->count >= node->cap)
{
node = push_array(arena, DASM_InstChunkNode, 1);
node->v = push_array_no_zero(arena, DASM_Inst, cap);
node->cap = cap;
SLLQueuePush(list->first, list->last, node);
list->node_count += 1;
}
MemoryCopyStruct(&node->v[node->count], inst);
node->count += 1;
list->inst_count += 1;
}
internal DASM_InstArray
dasm_inst_array_from_chunk_list(Arena *arena, DASM_InstChunkList *list)
{
DASM_InstArray array = {0};
array.count = list->inst_count;
array.v = push_array_no_zero(arena, DASM_Inst, array.count);
U64 idx = 0;
for(DASM_InstChunkNode *n = list->first; n != 0; n = n->next)
{
MemoryCopy(array.v+idx, n->v, sizeof(DASM_Inst)*n->count);
idx += n->count;
}
return array;
}
internal U64
dasm_inst_array_idx_from_off__linear_scan(DASM_InstArray *array, U64 off)
{
U64 result = 0;
for(U64 idx = 0; idx < array->count; idx += 1)
{
if(array->v[idx].off == off)
{
result = idx;
break;
}
}
return result;
}
internal U64
dasm_inst_array_off_from_idx(DASM_InstArray *array, U64 idx)
{
U64 off = 0;
if(idx < array->count)
{
off = array->v[idx].off;
}
return off;
}
////////////////////////////////
//~ rjf: Disassembly Functions
#include "third_party/udis86/config.h"
#include "third_party/udis86/udis86.h"
#include "third_party/udis86/libudis86/decode.c"
#include "third_party/udis86/libudis86/itab.c"
#include "third_party/udis86/libudis86/syn-att.c"
#include "third_party/udis86/libudis86/syn-intel.c"
#include "third_party/udis86/libudis86/syn.c"
#include "third_party/udis86/libudis86/udis86.c"
internal DASM_InstChunkList
dasm_inst_chunk_list_from_arch_addr_data(Arena *arena, U64 *bytes_processed_counter, Architecture arch, U64 addr, String8 data)
{
DASM_InstChunkList inst_list = {0};
switch(arch)
{
default:{}break;
//- rjf: x86/x64 decoding
case Architecture_x64:
case Architecture_x86:
{
// rjf: grab context
struct ud udc;
ud_init(&udc);
ud_set_mode(&udc, bit_size_from_arch(arch));
ud_set_pc(&udc, addr);
ud_set_input_buffer(&udc, data.str, data.size);
ud_set_vendor(&udc, UD_VENDOR_ANY);
ud_set_syntax(&udc, UD_SYN_INTEL);
// rjf: disassemble
U64 byte_process_start_off = 0;
for(U64 off = 0; off < data.size;)
{
// rjf: disassemble one instruction
U64 size = ud_disassemble(&udc);
if(size == 0)
{
break;
}
// rjf: analyze
struct ud_operand *first_op = (struct ud_operand *)ud_insn_opr(&udc, 0);
U64 rel_voff = (first_op != 0 && first_op->type == UD_OP_JIMM) ? ud_syn_rel_target(&udc, first_op) : 0;
// rjf: push
String8 string = push_str8f(arena, "%s", udc.asm_buf);
DASM_Inst inst = {string, off, rel_voff};
dasm_inst_chunk_list_push(arena, &inst_list, 1024, &inst);
// rjf: increment
off += size;
if(bytes_processed_counter != 0 && (off-byte_process_start_off >= 1000))
{
ins_atomic_u64_add_eval(bytes_processed_counter, (off-byte_process_start_off));
byte_process_start_off = off;
}
}
}break;
}
return inst_list;
}
////////////////////////////////
//~ rjf: Cache Lookups
//- rjf: opening handles & correllation with module
internal DASM_Handle
dasm_handle_from_ctrl_process_range(CTRL_MachineID machine, CTRL_Handle process, Rng1U64 vaddr_range)
{
DASM_Handle result = {0};
if(machine != 0 && process.u64[0] != 0)
{
U64 hash = dasm_hash_from_string(str8_struct(&process));
U64 slot_idx = hash%dasm_shared->entity_map.slots_count;
U64 stripe_idx = slot_idx%dasm_shared->entity_map_stripes.count;
DASM_EntitySlot *slot = &dasm_shared->entity_map.slots[slot_idx];
DASM_Stripe *stripe = &dasm_shared->entity_map_stripes.v[stripe_idx];
OS_MutexScopeW(stripe->rw_mutex)
{
DASM_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next)
{
if(e->machine_id == machine &&
ctrl_handle_match(e->process, process) &&
MemoryMatchStruct(&e->vaddr_range, &vaddr_range))
{
entity = e;
break;
}
}
if(entity == 0)
{
entity = push_array(stripe->arena, DASM_Entity, 1);
SLLQueuePush(slot->first, slot->last, entity);
entity->machine_id = machine;
entity->process = process;
entity->vaddr_range= vaddr_range;
entity->id = ins_atomic_u64_inc_eval(&dasm_shared->entity_id_gen);
entity->decode_inst_arena = arena_alloc__sized(MB(256), KB(64));
entity->decode_string_arena = arena_alloc__sized(GB(1), KB(64));
}
result.u64[0] = hash;
result.u64[1] = entity->id;
}
}
return result;
}
//- rjf: asking for top-level info of a handle
internal DASM_BinaryInfo
dasm_binary_info_from_handle(Arena *arena, DASM_Handle handle)
{
DASM_BinaryInfo info = {0};
{
U64 hash = handle.u64[0];
U64 id = handle.u64[1];
U64 slot_idx = hash%dasm_shared->entity_map.slots_count;
U64 stripe_idx = slot_idx%dasm_shared->entity_map_stripes.count;
DASM_EntitySlot *slot = &dasm_shared->entity_map.slots[slot_idx];
DASM_Stripe *stripe = &dasm_shared->entity_map_stripes.v[stripe_idx];
OS_MutexScopeR(stripe->rw_mutex)
{
DASM_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next)
{
if(e->id == id)
{
entity = e;
break;
}
}
if(entity != 0)
{
info.machine_id = entity->machine_id;
info.process = entity->process;
info.vaddr_range = entity->vaddr_range;
info.bytes_processed = ins_atomic_u64_eval(&entity->bytes_processed);
info.bytes_to_process = ins_atomic_u64_eval(&entity->bytes_to_process);
}
}
}
return info;
}
//- rjf: asking for decoded instructions
internal DASM_InstArray
dasm_inst_array_from_handle(Arena *arena, DASM_Handle handle, U64 endt_us)
{
DASM_InstArray result = {0};
{
U64 hash = handle.u64[0];
U64 id = handle.u64[1];
U64 slot_idx = hash%dasm_shared->entity_map.slots_count;
U64 stripe_idx = slot_idx%dasm_shared->entity_map_stripes.count;
DASM_EntitySlot *slot = &dasm_shared->entity_map.slots[slot_idx];
DASM_Stripe *stripe = &dasm_shared->entity_map_stripes.v[stripe_idx];
B32 sent = 0;
OS_MutexScopeR(stripe->rw_mutex) for(;;)
{
DASM_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next)
{
if(e->id == id)
{
entity = e;
break;
}
}
U64 last_time_sent_us = 0;
if(entity != 0)
{
U64 bytes_processed = ins_atomic_u64_eval(&entity->bytes_processed);
U64 bytes_to_process = ins_atomic_u64_eval(&entity->bytes_to_process);
last_time_sent_us = ins_atomic_u64_eval(&entity->last_time_sent_us);
if(bytes_processed == bytes_to_process && bytes_processed != 0)
{
result.count = entity->decode_inst_array.count;
result.v = push_array_no_zero(arena, DASM_Inst, result.count);
MemoryCopy(result.v, entity->decode_inst_array.v, sizeof(DASM_Inst)*result.count);
for(U64 idx = 0; idx < result.count; idx += 1)
{
result.v[idx].string = push_str8_copy(arena, result.v[idx].string);
}
break;
}
}
if(!sent && entity != 0 && last_time_sent_us+10000 <= os_now_microseconds())
{
DASM_DecodeRequest req = {handle};
sent = dasm_u2d_enqueue_request(&req, endt_us);
ins_atomic_u64_eval_assign(&entity->last_time_sent_us, os_now_microseconds());
}
if(os_now_microseconds() >= endt_us)
{
break;
}
os_condition_variable_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
}
}
return result;
}
////////////////////////////////
//~ rjf: Decode Threads
internal B32
dasm_u2d_enqueue_request(DASM_DecodeRequest *req, U64 endt_us)
{
B32 result = 0;
OS_MutexScope(dasm_shared->u2d_ring_mutex) for(;;)
{
U64 unconsumed_size = (dasm_shared->u2d_ring_write_pos-dasm_shared->u2d_ring_read_pos);
U64 available_size = (dasm_shared->u2d_ring_size-unconsumed_size);
if(available_size >= sizeof(*req))
{
result = 1;
dasm_shared->u2d_ring_write_pos += ring_write_struct(dasm_shared->u2d_ring_base, dasm_shared->u2d_ring_size, dasm_shared->u2d_ring_write_pos, req);
dasm_shared->u2d_ring_write_pos += 7;
dasm_shared->u2d_ring_write_pos -= dasm_shared->u2d_ring_write_pos%8;
break;
}
if(os_now_microseconds() >= endt_us)
{
break;
}
os_condition_variable_wait(dasm_shared->u2d_ring_cv, dasm_shared->u2d_ring_mutex, endt_us);
}
if(result)
{
os_condition_variable_broadcast(dasm_shared->u2d_ring_cv);
}
return result;
}
internal DASM_DecodeRequest
dasm_u2d_dequeue_request(void)
{
DASM_DecodeRequest req = {0};
OS_MutexScope(dasm_shared->u2d_ring_mutex) for(;;)
{
U64 unconsumed_size = (dasm_shared->u2d_ring_write_pos-dasm_shared->u2d_ring_read_pos);
if(unconsumed_size >= sizeof(DASM_DecodeRequest))
{
dasm_shared->u2d_ring_read_pos += ring_read_struct(dasm_shared->u2d_ring_base, dasm_shared->u2d_ring_size, dasm_shared->u2d_ring_read_pos, &req);
dasm_shared->u2d_ring_read_pos += 7;
dasm_shared->u2d_ring_read_pos -= dasm_shared->u2d_ring_read_pos%8;
break;
}
os_condition_variable_wait(dasm_shared->u2d_ring_cv, dasm_shared->u2d_ring_mutex, max_U64);
}
os_condition_variable_broadcast(dasm_shared->u2d_ring_cv);
return req;
}
internal void
dasm_decode_thread_entry_point(void *p)
{
TCTX tctx_;
tctx_init_and_equip(&tctx_);
for(;;)
{
Temp scratch = scratch_begin(0, 0);
//- rjf: get next request & unpack
DASM_DecodeRequest req = dasm_u2d_dequeue_request();
DASM_Handle handle = req.handle;
U64 hash = handle.u64[0];
U64 id = handle.u64[1];
U64 slot_idx = hash%dasm_shared->entity_map.slots_count;
U64 stripe_idx = slot_idx%dasm_shared->entity_map_stripes.count;
DASM_EntitySlot *slot = &dasm_shared->entity_map.slots[slot_idx];
DASM_Stripe *stripe = &dasm_shared->entity_map_stripes.v[stripe_idx];
//- rjf: request -> ctrl info
B32 is_first_to_task = 0;
CTRL_MachineID ctrl_machine_id = 0;
CTRL_Handle ctrl_process = {0};
Rng1U64 vaddr_range = {0};
Architecture arch = Architecture_Null;
U64 *bytes_processed_counter = 0;
OS_MutexScopeR(stripe->rw_mutex)
{
DASM_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next)
{
if(e->id == id)
{
entity = e;
break;
}
}
if(entity != 0)
{
U64 initial_working_count = ins_atomic_u32_eval_cond_assign(&entity->working_count, 1, 0);
if(initial_working_count == 0)
{
is_first_to_task = 1;
ctrl_machine_id = entity->machine_id;
ctrl_process = entity->process;
vaddr_range = entity->vaddr_range;
arch = ctrl_arch_from_handle(ctrl_machine_id, ctrl_process);
bytes_processed_counter = &entity->bytes_processed;
U64 bytes_to_process = dim_1u64(vaddr_range);
ins_atomic_u64_eval_assign(&entity->bytes_processed, 0);
ins_atomic_u64_eval_assign(&entity->bytes_to_process, bytes_to_process);
}
}
}
//- rjf: bad handle or machine id -> bad task
B32 good_task = (is_first_to_task && ctrl_process.u64[0] != 0 && ctrl_machine_id != 0 && arch != Architecture_Null && bytes_processed_counter != 0);
//- rjf: good task -> clear entity's info
if(good_task)
{
OS_MutexScopeW(stripe->rw_mutex)
{
DASM_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next)
{
if(e->id == id)
{
entity = e;
break;
}
}
if(entity != 0)
{
arena_clear(entity->decode_inst_arena);
arena_clear(entity->decode_string_arena);
MemoryZeroStruct(&entity->decode_inst_array);
}
}
}
//- rjf: good task -> read process memory & decode instructions - stop each
// 4k and write into cache, so users can read incremental results
if(good_task)
{
U64 chunk_size = KB(4);
for(U64 off = 0; vaddr_range.min+off < vaddr_range.max; off += chunk_size)
{
Rng1U64 chunk_vaddr_range = r1u64(vaddr_range.min+off, vaddr_range.min+off+chunk_size);
chunk_vaddr_range.min = ClampTop(chunk_vaddr_range.min, vaddr_range.max);
chunk_vaddr_range.max = ClampTop(chunk_vaddr_range.max, vaddr_range.max);
//- rjf: read next chunk & decode
String8 data = {0};
DASM_InstChunkList inst_list = {0};
if(good_task)
{
data.str = push_array_no_zero(scratch.arena, U8, dim_1u64(chunk_vaddr_range));
data.size = ctrl_process_read(ctrl_machine_id, ctrl_process, chunk_vaddr_range, data.str);
if(data.size != 0)
{
inst_list = dasm_inst_chunk_list_from_arch_addr_data(scratch.arena, bytes_processed_counter, arch, chunk_vaddr_range.min, data);
}
}
//- rjf: write into cache
{
OS_MutexScopeW(stripe->rw_mutex)
{
DASM_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next)
{
if(e->id == id)
{
entity = e;
break;
}
}
if(entity != 0)
{
DASM_Inst *new_chunk_base = push_array(entity->decode_inst_arena, DASM_Inst, inst_list.inst_count);
U64 off = 0;
for(DASM_InstChunkNode *node = inst_list.first; node != 0; node = node->next)
{
MemoryCopy(new_chunk_base+off, node->v, sizeof(DASM_Inst)*node->count);
off += node->count;
}
for(U64 idx = 0; idx < inst_list.inst_count; idx += 1)
{
new_chunk_base[idx].string = push_str8_copy(entity->decode_string_arena, new_chunk_base[idx].string);
}
entity->decode_inst_array.count += inst_list.inst_count;
if(entity->decode_inst_array.v == 0)
{
entity->decode_inst_array.v = new_chunk_base;
}
}
}
os_condition_variable_broadcast(stripe->cv);
}
}
}
//- rjf: mark task as complete
if(good_task)
{
OS_MutexScopeR(stripe->rw_mutex)
{
DASM_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next)
{
if(e->id == id)
{
entity = e;
break;
}
}
if(entity != 0)
{
U64 bytes_to_process = ins_atomic_u64_eval(&entity->bytes_to_process);
ins_atomic_u64_eval_assign(&entity->bytes_processed, bytes_to_process);
ins_atomic_u64_eval_assign(&entity->working_count, 0);
}
}
}
scratch_end(scratch);
}
}
+206
View File
@@ -0,0 +1,206 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DASM_H
#define DASM_H
////////////////////////////////
//~ rjf: Handle Type
typedef struct DASM_Handle DASM_Handle;
struct DASM_Handle
{
U64 u64[2];
};
////////////////////////////////
//~ rjf: Instruction Types
typedef struct DASM_Inst DASM_Inst;
struct DASM_Inst
{
String8 string;
U64 off;
U64 addr;
};
typedef struct DASM_InstChunkNode DASM_InstChunkNode;
struct DASM_InstChunkNode
{
DASM_InstChunkNode *next;
DASM_Inst *v;
U64 cap;
U64 count;
};
typedef struct DASM_InstChunkNode DASM_InstChunkNode;
struct DASM_InstChunkList
{
DASM_InstChunkNode *first;
DASM_InstChunkNode *last;
U64 node_count;
U64 inst_count;
};
typedef struct DASM_InstArray DASM_InstArray;
struct DASM_InstArray
{
DASM_Inst *v;
U64 count;
};
////////////////////////////////
//~ rjf: Striped Access Types
typedef struct DASM_Stripe DASM_Stripe;
struct DASM_Stripe
{
Arena *arena;
OS_Handle cv;
OS_Handle rw_mutex;
};
typedef struct DASM_StripeTable DASM_StripeTable;
struct DASM_StripeTable
{
U64 count;
DASM_Stripe *v;
};
////////////////////////////////
//~ rjf: Entity Cache Types
typedef struct DASM_Entity DASM_Entity;
struct DASM_Entity
{
DASM_Entity *next;
// rjf: key info
CTRL_MachineID machine_id;
CTRL_Handle process;
Rng1U64 vaddr_range;
U64 id;
// rjf: top-level info
U64 last_time_sent_us;
U64 working_count;
U64 bytes_processed;
U64 bytes_to_process;
// rjf: decoded instruction data
Arena *decode_inst_arena;
Arena *decode_string_arena;
DASM_InstArray decode_inst_array;
};
typedef struct DASM_EntitySlot DASM_EntitySlot;
struct DASM_EntitySlot
{
DASM_Entity *first;
DASM_Entity *last;
};
typedef struct DASM_EntityMap DASM_EntityMap;
struct DASM_EntityMap
{
U64 slots_count;
DASM_EntitySlot *slots;
};
////////////////////////////////
//~ rjf: Introspection Info Types
typedef struct DASM_BinaryInfo DASM_BinaryInfo;
struct DASM_BinaryInfo
{
CTRL_MachineID machine_id;
CTRL_Handle process;
Rng1U64 vaddr_range;
U64 bytes_processed;
U64 bytes_to_process;
};
////////////////////////////////
//~ rjf: Decode Request Types
typedef struct DASM_DecodeRequest DASM_DecodeRequest;
struct DASM_DecodeRequest
{
DASM_Handle handle;
};
////////////////////////////////
//~ rjf: Shared State
typedef struct DASM_Shared DASM_Shared;
struct DASM_Shared
{
Arena *arena;
// rjf: entity table
DASM_EntityMap entity_map;
DASM_StripeTable entity_map_stripes;
U64 entity_id_gen;
// rjf: user -> decode ring
OS_Handle u2d_ring_mutex;
OS_Handle u2d_ring_cv;
U64 u2d_ring_size;
U8 *u2d_ring_base;
U64 u2d_ring_write_pos;
U64 u2d_ring_read_pos;
// rjf: decode threads
U64 decode_thread_count;
OS_Handle *decode_threads;
};
////////////////////////////////
//~ rjf: Globals
global DASM_Shared *dasm_shared = 0;
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void dasm_init(void);
////////////////////////////////
//~ rjf: Basic Helpers
internal U64 dasm_hash_from_string(String8 string);
////////////////////////////////
//~ rjf: Instruction Type Functions
internal void dasm_inst_chunk_list_push(Arena *arena, DASM_InstChunkList *list, U64 cap, DASM_Inst *inst);
internal DASM_InstArray dasm_inst_array_from_chunk_list(Arena *arena, DASM_InstChunkList *list);
internal U64 dasm_inst_array_idx_from_off__linear_scan(DASM_InstArray *array, U64 off);
internal U64 dasm_inst_array_off_from_idx(DASM_InstArray *array, U64 idx);
////////////////////////////////
//~ rjf: Disassembly Functions
internal DASM_InstChunkList dasm_inst_chunk_list_from_arch_addr_data(Arena *arena, U64 *bytes_processed_counter, Architecture arch, U64 addr, String8 data);
////////////////////////////////
//~ rjf: Cache Lookups
//- rjf: opening handles & correllation with module
internal DASM_Handle dasm_handle_from_ctrl_process_range(CTRL_MachineID machine, CTRL_Handle process, Rng1U64 vaddr_range);
//- rjf: asking for top-level info of a handle
internal DASM_BinaryInfo dasm_binary_info_from_handle(Arena *arena, DASM_Handle handle);
//- rjf: asking for decoded instructions
internal DASM_InstArray dasm_inst_array_from_handle(Arena *arena, DASM_Handle handle, U64 endt_us);
////////////////////////////////
//~ rjf: Decode Threads
internal B32 dasm_u2d_enqueue_request(DASM_DecodeRequest *req, U64 endt_us);
internal DASM_DecodeRequest dasm_u2d_dequeue_request(void);
internal void dasm_decode_thread_entry_point(void *p);
#endif //DASM_H
+888
View File
@@ -0,0 +1,888 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void
dbgi_init(void)
{
Arena *arena = arena_alloc();
dbgi_shared = push_array(arena, DBGI_Shared, 1);
dbgi_shared->arena = arena;
dbgi_shared->force_slots_count = 1024;
dbgi_shared->force_stripes_count = 64;
dbgi_shared->force_slots = push_array(arena, DBGI_ForceSlot, dbgi_shared->force_slots_count);
dbgi_shared->force_stripes = push_array(arena, DBGI_ForceStripe, dbgi_shared->force_stripes_count);
for(U64 idx = 0; idx < dbgi_shared->force_stripes_count; idx += 1)
{
dbgi_shared->force_stripes[idx].arena = arena_alloc();
dbgi_shared->force_stripes[idx].rw_mutex = os_rw_mutex_alloc();
dbgi_shared->force_stripes[idx].cv = os_condition_variable_alloc();
}
dbgi_shared->binary_slots_count = 1024;
dbgi_shared->binary_stripes_count = 64;
dbgi_shared->binary_slots = push_array(arena, DBGI_BinarySlot, dbgi_shared->binary_slots_count);
dbgi_shared->binary_stripes = push_array(arena, DBGI_BinaryStripe, dbgi_shared->binary_stripes_count);
for(U64 idx = 0; idx < dbgi_shared->binary_stripes_count; idx += 1)
{
dbgi_shared->binary_stripes[idx].arena = arena_alloc();
dbgi_shared->binary_stripes[idx].rw_mutex = os_rw_mutex_alloc();
dbgi_shared->binary_stripes[idx].cv = os_condition_variable_alloc();
}
dbgi_shared->u2p_ring_mutex = os_mutex_alloc();
dbgi_shared->u2p_ring_cv = os_condition_variable_alloc();
dbgi_shared->u2p_ring_size = KB(64);
dbgi_shared->u2p_ring_base = push_array_no_zero(arena, U8, dbgi_shared->u2p_ring_size);
dbgi_shared->p2u_ring_mutex = os_mutex_alloc();
dbgi_shared->p2u_ring_cv = os_condition_variable_alloc();
dbgi_shared->p2u_ring_size = KB(64);
dbgi_shared->p2u_ring_base = push_array_no_zero(arena, U8, dbgi_shared->p2u_ring_size);
dbgi_shared->parse_thread_count = Max(os_logical_core_count()-1, 1);
dbgi_shared->parse_threads = push_array(arena, OS_Handle, dbgi_shared->parse_thread_count);
for(U64 idx = 0; idx < dbgi_shared->parse_thread_count; idx += 1)
{
dbgi_shared->parse_threads[idx] = os_launch_thread(dbgi_parse_thread_entry_point, (void *)idx, 0);
}
dbgi_shared->evictor_thread = os_launch_thread(dbgi_evictor_thread_entry_point, 0, 0);
}
////////////////////////////////
//~ rjf: Thread-Context Idempotent Initialization
internal void
dbgi_ensure_tctx_inited(void)
{
if(dbgi_tctx == 0)
{
Arena *arena = arena_alloc();
dbgi_tctx = push_array(arena, DBGI_ThreadCtx, 1);
dbgi_tctx->arena = arena;
}
}
////////////////////////////////
//~ rjf: Helpers
internal U64
dbgi_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: Forced Override Cache Functions
internal void
dbgi_force_exe_path_dbg_path(String8 exe_path, String8 dbg_path)
{
U64 hash = dbgi_hash_from_string(exe_path);
U64 slot_idx = hash%dbgi_shared->force_slots_count;
U64 stripe_idx = slot_idx%dbgi_shared->force_stripes_count;
DBGI_ForceSlot *slot = &dbgi_shared->force_slots[slot_idx];
DBGI_ForceStripe *stripe = &dbgi_shared->force_stripes[stripe_idx];
OS_MutexScopeW(stripe->rw_mutex)
{
DBGI_ForceNode *node = 0;
for(DBGI_ForceNode *n = slot->first; n != 0; n = n->next)
{
if(str8_match(n->exe_path, exe_path, 0))
{
node = n;
break;
}
}
if(node == 0)
{
node = push_array(stripe->arena, DBGI_ForceNode, 1);
SLLQueuePush(slot->first, slot->first, node);
node->exe_path = push_str8_copy(stripe->arena, exe_path);
node->dbg_path_cap = 1024;
node->dbg_path_base = push_array_no_zero(stripe->arena, U8, node->dbg_path_cap);
}
String8 dbg_path_clamped = dbg_path;
dbg_path_clamped.size = Min(dbg_path_clamped.size, node->dbg_path_cap);
MemoryCopy(node->dbg_path_base, dbg_path_clamped.str, dbg_path_clamped.size);
node->dbg_path_size = dbg_path_clamped.size;
}
}
internal String8
dbgi_forced_dbg_path_from_exe_path(Arena *arena, String8 exe_path)
{
String8 result = {0};
U64 hash = dbgi_hash_from_string(exe_path);
U64 slot_idx = hash%dbgi_shared->force_slots_count;
U64 stripe_idx = slot_idx%dbgi_shared->force_stripes_count;
DBGI_ForceSlot *slot = &dbgi_shared->force_slots[slot_idx];
DBGI_ForceStripe *stripe = &dbgi_shared->force_stripes[stripe_idx];
OS_MutexScopeR(stripe->rw_mutex)
{
DBGI_ForceNode *node = 0;
for(DBGI_ForceNode *n = slot->first; n != 0; n = n->next)
{
if(str8_match(exe_path, n->exe_path, 0))
{
node = n;
break;
}
}
if(node != 0)
{
String8 dbg_path = str8(node->dbg_path_base, node->dbg_path_size);
result = push_str8_copy(arena, dbg_path);
}
}
return result;
}
////////////////////////////////
//~ rjf: Scope Functions
internal DBGI_Scope *
dbgi_scope_open(void)
{
dbgi_ensure_tctx_inited();
DBGI_Scope *scope = dbgi_tctx->free_scope;
if(scope != 0)
{
SLLStackPop(dbgi_tctx->free_scope);
MemoryZeroStruct(scope);
}
else
{
scope = push_array(dbgi_tctx->arena, DBGI_Scope, 1);
}
return scope;
}
internal void
dbgi_scope_close(DBGI_Scope *scope)
{
for(DBGI_TouchedBinary *tb = scope->first_tb, *next = 0; tb != 0; tb = next)
{
next = tb->next;
ins_atomic_u64_dec_eval(&tb->binary->scope_touch_count);
SLLStackPush(dbgi_tctx->free_tb, tb);
}
SLLStackPush(dbgi_tctx->free_scope, scope);
}
internal void
dbgi_scope_touch_binary__stripe_mutex_r_guarded(DBGI_Scope *scope, DBGI_Binary *binary)
{
DBGI_TouchedBinary *tb = dbgi_tctx->free_tb;
ins_atomic_u64_inc_eval(&binary->scope_touch_count);
if(tb != 0)
{
SLLStackPop(dbgi_tctx->free_tb);
}
else
{
tb = push_array(dbgi_tctx->arena, DBGI_TouchedBinary, 1);
}
tb->binary = binary;
SLLQueuePush(scope->first_tb, scope->last_tb, tb);
}
////////////////////////////////
//~ rjf: Binary Cache Functions
internal void
dbgi_binary_open(String8 exe_path)
{
Temp scratch = scratch_begin(0, 0);
exe_path = path_normalized_from_string(scratch.arena, exe_path);
U64 hash = dbgi_hash_from_string(exe_path);
U64 slot_idx = hash%dbgi_shared->binary_slots_count;
U64 stripe_idx = slot_idx%dbgi_shared->binary_stripes_count;
DBGI_BinarySlot *slot = &dbgi_shared->binary_slots[slot_idx];
DBGI_BinaryStripe *stripe = &dbgi_shared->binary_stripes[stripe_idx];
B32 is_new = 0;
OS_MutexScopeW(stripe->rw_mutex)
{
DBGI_Binary *binary = 0;
for(DBGI_Binary *bin = slot->first; bin != 0; bin = bin->next)
{
if(str8_match(bin->exe_path, exe_path, 0))
{
binary = bin;
break;
}
}
if(binary == 0)
{
binary = push_array(stripe->arena, DBGI_Binary, 1);
SLLQueuePush(slot->first, slot->last, binary);
binary->exe_path = push_str8_copy(stripe->arena, exe_path);
binary->gen += 1;
}
binary->refcount += 1;
is_new = (binary->refcount == 1);
}
if(is_new)
{
dbgi_u2p_enqueue_exe_path(exe_path, 0);
}
scratch_end(scratch);
}
internal void
dbgi_binary_close(String8 exe_path)
{
Temp scratch = scratch_begin(0, 0);
exe_path = path_normalized_from_string(scratch.arena, exe_path);
U64 hash = dbgi_hash_from_string(exe_path);
U64 slot_idx = hash%dbgi_shared->binary_slots_count;
U64 stripe_idx = slot_idx%dbgi_shared->binary_stripes_count;
DBGI_BinarySlot *slot = &dbgi_shared->binary_slots[slot_idx];
DBGI_BinaryStripe *stripe = &dbgi_shared->binary_stripes[stripe_idx];
OS_MutexScopeW(stripe->rw_mutex)
{
DBGI_Binary *binary = 0;
for(DBGI_Binary *bin = slot->first; bin != 0; bin = bin->next)
{
if(str8_match(bin->exe_path, exe_path, 0))
{
binary = bin;
break;
}
}
if(binary != 0 && binary->refcount>0)
{
binary->refcount -= 1;
}
}
scratch_end(scratch);
}
internal DBGI_Parse *
dbgi_parse_from_exe_path(DBGI_Scope *scope, String8 exe_path, U64 endt_us)
{
Temp scratch = scratch_begin(0, 0);
exe_path = path_normalized_from_string(scratch.arena, exe_path);
DBGI_Parse *parse = &dbgi_parse_nil;
{
U64 hash = dbgi_hash_from_string(exe_path);
U64 slot_idx = hash%dbgi_shared->binary_slots_count;
U64 stripe_idx = slot_idx%dbgi_shared->binary_stripes_count;
DBGI_BinarySlot *slot = &dbgi_shared->binary_slots[slot_idx];
DBGI_BinaryStripe *stripe = &dbgi_shared->binary_stripes[stripe_idx];
B32 sent = 0;
OS_MutexScopeR(stripe->rw_mutex) for(;;)
{
DBGI_Binary *binary = 0;
for(DBGI_Binary *bin = slot->first; bin != 0; bin = bin->next)
{
if(str8_match(bin->exe_path, exe_path, 0))
{
binary = bin;
break;
}
}
if(binary != 0 && !(binary->flags & DBGI_BinaryFlag_ParseInFlight))
{
if(binary->parse.gen == binary->gen)
{
dbgi_scope_touch_binary__stripe_mutex_r_guarded(scope, binary);
parse = &binary->parse;
break;
}
else if(!sent &&
os_now_microseconds() >= ins_atomic_u64_eval(&binary->last_time_enqueued_for_parse_us)+1000000 &&
dbgi_u2p_enqueue_exe_path(exe_path, endt_us))
{
sent = 1;
ins_atomic_u64_eval_assign(&binary->last_time_enqueued_for_parse_us, os_now_microseconds());
}
}
if(os_now_microseconds() >= endt_us)
{
break;
}
os_condition_variable_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
}
}
scratch_end(scratch);
return parse;
}
////////////////////////////////
//~ rjf: Analysis Threads
internal B32
dbgi_u2p_enqueue_exe_path(String8 exe_path, U64 endt_us)
{
B32 sent = 0;
OS_MutexScope(dbgi_shared->u2p_ring_mutex) for(;;)
{
U64 unconsumed_size = (dbgi_shared->u2p_ring_write_pos-dbgi_shared->u2p_ring_read_pos);
U64 available_size = dbgi_shared->u2p_ring_size-unconsumed_size;
U64 needed_size = sizeof(U64)+exe_path.size;
needed_size += 7;
needed_size -= needed_size%8;
if(available_size >= needed_size)
{
dbgi_shared->u2p_ring_write_pos += ring_write_struct(dbgi_shared->u2p_ring_base, dbgi_shared->u2p_ring_size, dbgi_shared->u2p_ring_write_pos, &exe_path.size);
dbgi_shared->u2p_ring_write_pos += ring_write(dbgi_shared->u2p_ring_base, dbgi_shared->u2p_ring_size, dbgi_shared->u2p_ring_write_pos, exe_path.str, exe_path.size);
dbgi_shared->u2p_ring_write_pos += 7;
dbgi_shared->u2p_ring_write_pos -= dbgi_shared->u2p_ring_write_pos%8;
sent = 1;
break;
}
if(os_now_microseconds() >= endt_us)
{
break;
}
os_condition_variable_wait(dbgi_shared->u2p_ring_cv, dbgi_shared->u2p_ring_mutex, endt_us);
}
os_condition_variable_broadcast(dbgi_shared->u2p_ring_cv);
return sent;
}
internal String8
dbgi_u2p_dequeue_exe_path(Arena *arena)
{
String8 result = {0};
OS_MutexScope(dbgi_shared->u2p_ring_mutex) for(;;)
{
U64 unconsumed_size = (dbgi_shared->u2p_ring_write_pos-dbgi_shared->u2p_ring_read_pos);
if(unconsumed_size != 0)
{
dbgi_shared->u2p_ring_read_pos += ring_read_struct(dbgi_shared->u2p_ring_base, dbgi_shared->u2p_ring_size, dbgi_shared->u2p_ring_read_pos, &result.size);
result.str = push_array_no_zero(arena, U8, result.size);
dbgi_shared->u2p_ring_read_pos += ring_read(dbgi_shared->u2p_ring_base, dbgi_shared->u2p_ring_size, dbgi_shared->u2p_ring_read_pos, result.str, result.size);
dbgi_shared->u2p_ring_read_pos += 7;
dbgi_shared->u2p_ring_read_pos -= dbgi_shared->u2p_ring_read_pos%8;
break;
}
os_condition_variable_wait(dbgi_shared->u2p_ring_cv, dbgi_shared->u2p_ring_mutex, max_U64);
}
os_condition_variable_broadcast(dbgi_shared->u2p_ring_cv);
return result;
}
internal void
dbgi_p2u_push_event(DBGI_Event *event)
{
OS_MutexScope(dbgi_shared->p2u_ring_mutex) for(;;)
{
U64 unconsumed_size = (dbgi_shared->p2u_ring_write_pos-dbgi_shared->p2u_ring_read_pos);
U64 available_size = dbgi_shared->p2u_ring_size-unconsumed_size;
U64 needed_size = sizeof(DBGI_EventKind) + sizeof(U64) + event->string.size;
if(available_size >= needed_size)
{
dbgi_shared->p2u_ring_write_pos += ring_write_struct(dbgi_shared->p2u_ring_base, dbgi_shared->p2u_ring_size, dbgi_shared->p2u_ring_write_pos, &event->kind);
dbgi_shared->p2u_ring_write_pos += ring_write_struct(dbgi_shared->p2u_ring_base, dbgi_shared->p2u_ring_size, dbgi_shared->p2u_ring_write_pos, &event->string.size);
dbgi_shared->p2u_ring_write_pos += ring_write(dbgi_shared->p2u_ring_base, dbgi_shared->p2u_ring_size, dbgi_shared->p2u_ring_write_pos, event->string.str, event->string.size);
dbgi_shared->p2u_ring_write_pos += 7;
dbgi_shared->p2u_ring_write_pos -= dbgi_shared->p2u_ring_write_pos%8;
break;
}
os_condition_variable_wait(dbgi_shared->p2u_ring_cv, dbgi_shared->p2u_ring_mutex, max_U64);
}
os_condition_variable_broadcast(dbgi_shared->p2u_ring_cv);
}
internal DBGI_EventList
dbgi_p2u_pop_events(Arena *arena, U64 endt_us)
{
DBGI_EventList events = {0};
OS_MutexScope(dbgi_shared->p2u_ring_mutex) for(;;)
{
U64 unconsumed_size = (dbgi_shared->p2u_ring_write_pos-dbgi_shared->p2u_ring_read_pos);
if(unconsumed_size >= sizeof(DBGI_EventKind) + sizeof(U64))
{
DBGI_EventNode *n = push_array(arena, DBGI_EventNode, 1);
SLLQueuePush(events.first, events.last, n);
events.count += 1;
dbgi_shared->p2u_ring_read_pos += ring_read_struct(dbgi_shared->p2u_ring_base, dbgi_shared->p2u_ring_size, dbgi_shared->p2u_ring_read_pos, &n->v.kind);
dbgi_shared->p2u_ring_read_pos += ring_read_struct(dbgi_shared->p2u_ring_base, dbgi_shared->p2u_ring_size, dbgi_shared->p2u_ring_read_pos, &n->v.string.size);
n->v.string.str = push_array_no_zero(arena, U8, n->v.string.size);
dbgi_shared->p2u_ring_read_pos += ring_read(dbgi_shared->p2u_ring_base, dbgi_shared->p2u_ring_size, dbgi_shared->p2u_ring_read_pos, n->v.string.str, n->v.string.size);
dbgi_shared->p2u_ring_read_pos += 7;
dbgi_shared->p2u_ring_read_pos -= dbgi_shared->p2u_ring_read_pos%8;
}
else if(os_now_microseconds() >= endt_us)
{
break;
}
os_condition_variable_wait(dbgi_shared->p2u_ring_cv, dbgi_shared->p2u_ring_mutex, endt_us);
}
os_condition_variable_broadcast(dbgi_shared->p2u_ring_cv);
return events;
}
internal void
dbgi_parse_thread_entry_point(void *p)
{
TCTX tctx_;
tctx_init_and_equip(&tctx_);
ProfThreadName("[dbgi] parse #%I64U", (U64)p);
for(;;)
{
Temp scratch = scratch_begin(0, 0);
//- rjf: grab next path & unpack
String8 exe_path = dbgi_u2p_dequeue_exe_path(scratch.arena);
ProfBegin("begin task for \"%.*s\"", str8_varg(exe_path));
U64 hash = dbgi_hash_from_string(exe_path);
U64 slot_idx = hash%dbgi_shared->binary_slots_count;
U64 stripe_idx = slot_idx%dbgi_shared->binary_stripes_count;
DBGI_BinarySlot *slot = &dbgi_shared->binary_slots[slot_idx];
DBGI_BinaryStripe *stripe = &dbgi_shared->binary_stripes[stripe_idx];
//- rjf: determine if binary's analysis work is taken by another thread.
// if not, take it
B32 task_is_taken_by_other_thread = 0;
OS_MutexScopeW(stripe->rw_mutex)
{
DBGI_Binary *binary = 0;
for(DBGI_Binary *bin = slot->first; bin != 0; bin = bin->next)
{
if(str8_match(bin->exe_path, exe_path, 0))
{
binary = bin;
break;
}
}
if(binary == 0 || binary->flags&DBGI_BinaryFlag_ParseInFlight)
{
task_is_taken_by_other_thread = 1;
}
else if(binary != 0)
{
binary->flags |= DBGI_BinaryFlag_ParseInFlight;
}
}
//- rjf: is the work taken? -> abort
B32 do_task = 1;
if(task_is_taken_by_other_thread)
{
do_task = 0;
}
//- rjf: open exe file & map into address space
OS_Handle exe_file = {0};
FileProperties exe_file_props = {0};
OS_Handle exe_file_map = {0};
void *exe_file_base = 0;
if(do_task)
{
exe_file = os_file_open(OS_AccessFlag_Read|OS_AccessFlag_Shared, exe_path);
exe_file_props = os_properties_from_file(exe_file);
exe_file_map = os_file_map_open(OS_AccessFlag_Read, exe_file);
exe_file_base = os_file_map_view_open(exe_file_map, OS_AccessFlag_Read, r1u64(0, exe_file_props.size));
}
//- rjf: parse exe file info
Arena *parse_arena = 0;
PE_BinInfo exe_pe_info = {0};
String8 exe_dbg_path_embedded = {0};
if(do_task)
{
parse_arena = arena_alloc();
if(exe_file_props.size >= 2 && *(U16 *)exe_file_base == PE_DOS_MAGIC)
{
String8 exe_data = str8((U8 *)exe_file_base, exe_file_props.size);
exe_pe_info = pe_bin_info_from_data(parse_arena, exe_data);
exe_dbg_path_embedded = str8_cstring_capped((char *)exe_data.str+exe_pe_info.dbg_path_off, (char *)exe_data.str+exe_pe_info.dbg_path_off+Min(exe_data.size-exe_pe_info.dbg_path_off, 4096));
}
}
//- rjf: determine O.G. (may or may not be RADDBG) dbg path
String8 og_dbg_path = {0};
if(do_task) ProfScope("determine O.G. dbg path")
{
String8 forced_og_dbg_path = dbgi_forced_dbg_path_from_exe_path(scratch.arena, exe_path);
if(forced_og_dbg_path.size != 0)
{
og_dbg_path = forced_og_dbg_path;
}
else
{
String8 possible_og_dbg_paths[] =
{
/* inferred: */ exe_dbg_path_embedded,
/* "foo.exe" -> "foo.pdb" */ push_str8f(scratch.arena, "%S.pdb", str8_chop_last_dot(exe_path)),
/* "foo.exe" -> "foo.exe.pdb" */ push_str8f(scratch.arena, "%S.pdb", exe_path),
};
for(U64 idx = 0; idx < ArrayCount(possible_og_dbg_paths); idx += 1)
{
FileProperties props = os_properties_from_file_path(possible_og_dbg_paths[idx]);
if(props.modified != 0 && props.size != 0)
{
og_dbg_path = possible_og_dbg_paths[idx];
break;
}
}
}
}
//- rjf: analyze O.G. dbg file
B32 og_dbg_format_is_known = 0;
B32 og_dbg_is_pe = 0;
B32 og_dbg_is_pdb = 0;
B32 og_dbg_is_elf = 0;
B32 og_dbg_is_raddbg = 0;
FileProperties og_dbg_props = {0};
if(do_task) ProfScope("analyze O.G. dbg file")
{
OS_Handle file = os_file_open(OS_AccessFlag_Read|OS_AccessFlag_Shared, og_dbg_path);
OS_Handle file_map = os_file_map_open(OS_AccessFlag_Read, file);
FileProperties props = og_dbg_props = os_properties_from_file(file);
void *base = os_file_map_view_open(file_map, OS_AccessFlag_Read, r1u64(0, props.size));
String8 data = str8((U8 *)base, props.size);
if(!og_dbg_format_is_known)
{
String8 msf20_magic = str8_lit("Microsoft C/C++ program database 2.00\r\n\x1aJG\0\0");
String8 msf70_magic = str8_lit("Microsoft C/C++ MSF 7.00\r\n\032DS\0\0");
String8 msfxx_magic = str8_lit("Microsoft C/C++");
if((data.size >= msf20_magic.size && str8_match(data, msf20_magic, StringMatchFlag_RightSideSloppy)) ||
(data.size >= msf70_magic.size && str8_match(data, msf70_magic, StringMatchFlag_RightSideSloppy)) ||
(data.size >= msfxx_magic.size && str8_match(data, msfxx_magic, StringMatchFlag_RightSideSloppy)))
{
og_dbg_format_is_known = 1;
og_dbg_is_pdb = 1;
}
}
if(!og_dbg_format_is_known)
{
if(data.size >= 8 && *(U64 *)data.str == RADDBG_MAGIC_CONSTANT)
{
og_dbg_format_is_known = 1;
og_dbg_is_raddbg = 1;
}
}
if(!og_dbg_format_is_known)
{
if(data.size >= 4 &&
data.str[0] == 0x7f &&
data.str[1] == 'E' &&
data.str[2] == 'L' &&
data.str[3] == 'F')
{
og_dbg_format_is_known = 1;
og_dbg_is_elf = 1;
}
}
if(!og_dbg_format_is_known)
{
if(data.size >= 2 && *(U16 *)data.str == PE_DOS_MAGIC)
{
og_dbg_format_is_known = 1;
og_dbg_is_pe = 1;
}
}
os_file_map_view_close(file_map, base);
os_file_map_close(file_map);
os_file_close(file);
}
//- rjf: given O.G. path & analysis, determine RADDBG file path
String8 raddbg_path = {0};
if(do_task)
{
if(og_dbg_is_raddbg)
{
raddbg_path = og_dbg_path;
}
else if(og_dbg_format_is_known && og_dbg_is_pdb)
{
raddbg_path = push_str8f(scratch.arena, "%S.raddbg", str8_chop_last_dot(og_dbg_path));
}
}
//- rjf: check if raddbg file is up-to-date
B32 raddbg_file_is_up_to_date = 0;
if(do_task)
{
if(raddbg_path.size != 0)
{
FileProperties props = os_properties_from_file_path(raddbg_path);
raddbg_file_is_up_to_date = (props.modified > og_dbg_props.modified);
}
}
//- rjf: raddbg file not up-to-date? we need to generate it
if(do_task)
{
if(!raddbg_file_is_up_to_date) ProfScope("generate raddbg file")
{
if(og_dbg_is_pdb)
{
// rjf: push conversion task begin event
{
DBGI_Event event = {DBGI_EventKind_ConversionStarted};
event.string = raddbg_path;
dbgi_p2u_push_event(&event);
}
// rjf: kick off process
OS_Handle process = {0};
{
OS_LaunchOptions opts = {0};
opts.path = os_string_from_system_path(scratch.arena, OS_SystemPath_Binary);
opts.inherit_env = 1;
opts.consoleless = 1;
str8_list_pushf(scratch.arena, &opts.cmd_line, "raddbg");
str8_list_pushf(scratch.arena, &opts.cmd_line, "--convert");
//str8_list_pushf(scratch.arena, &opts.cmd_line, "--capture");
str8_list_pushf(scratch.arena, &opts.cmd_line, "--exe:%S", exe_path);
str8_list_pushf(scratch.arena, &opts.cmd_line, "--pdb:%S", og_dbg_path);
str8_list_pushf(scratch.arena, &opts.cmd_line, "--out:%S", raddbg_path);
os_launch_process(&opts, &process);
}
// rjf: wait for process to complete
{
U64 start_wait_t = os_now_microseconds();
for(;;)
{
B32 wait_done = os_process_wait(process, os_now_microseconds()+1000);
if(wait_done)
{
raddbg_file_is_up_to_date = 1;
break;
}
if(os_now_microseconds()-start_wait_t > 10000000 && og_dbg_props.size < MB(64))
{
os_graphical_message(1, str8_lit("RADDBG INTERNAL DEVELOPMENT MESSAGE"), str8_lit("this is taking a while... indicative of something that seemed like a bug that Jeff hit before. attach with debugger now & see where the callstack is?"));
}
}
}
// rjf: push conversion task end event
{
DBGI_Event event = {DBGI_EventKind_ConversionEnded};
event.string = raddbg_path;
dbgi_p2u_push_event(&event);
}
}
else
{
// NOTE(rjf): we cannot convert from this O.G. debug info format right now.
// rjf: push conversion task failure event
{
DBGI_Event event = {DBGI_EventKind_ConversionFailureUnsupportedFormat};
event.string = raddbg_path;
dbgi_p2u_push_event(&event);
}
}
}
}
//- rjf: open raddbg file & gather info
OS_Handle raddbg_file = {0};
OS_Handle raddbg_file_map = {0};
FileProperties raddbg_file_props = {0};
void *raddbg_file_base = 0;
if(do_task && raddbg_file_is_up_to_date)
{
raddbg_file = os_file_open(OS_AccessFlag_Read|OS_AccessFlag_Shared, raddbg_path);
raddbg_file_map = os_file_map_open(OS_AccessFlag_Read, raddbg_file);
raddbg_file_props = os_properties_from_file(raddbg_file);
raddbg_file_base = os_file_map_view_open(raddbg_file_map, OS_AccessFlag_Read, r1u64(0, raddbg_file_props.size));
}
//- rjf: cache write, step 0: busy-loop-wait for all scope touches to be done
if(do_task) ProfScope("cache write, step 0: busy-loop-wait for all scope touches to be done")
{
for(B32 done = 0; done == 0;)
{
OS_MutexScopeR(stripe->rw_mutex) for(DBGI_Binary *bin = slot->first; bin != 0; bin = bin->next)
{
if(str8_match(bin->exe_path, exe_path, 0) &&
bin->scope_touch_count == 0)
{
done = 1;
break;
}
}
}
}
//- rjf: cache write, step 1: check if either EXE or raddbg file is new. if
// so, clear all old results & store new top-level info
B32 raddbg_or_exe_file_is_updated = 0;
if(do_task) ProfScope("cache write, step 1: check if raddbg is new & clear")
{
OS_MutexScopeW(stripe->rw_mutex) for(DBGI_Binary *bin = slot->first; bin != 0; bin = bin->next)
{
if(str8_match(bin->exe_path, exe_path, 0))
{
if(bin->parse.dbg_props.modified != raddbg_file_props.modified ||
bin->parse.exe_props.modified != exe_file_props.modified)
{
raddbg_or_exe_file_is_updated = 1;
// rjf: clean up old stuff
if(bin->parse.arena != 0) { arena_release(bin->parse.arena); }
if(bin->parse.exe_base != 0) {os_file_map_view_close(bin->exe_file_map, bin->parse.exe_base);}
if(!os_handle_match(os_handle_zero(), bin->exe_file_map)) {os_file_map_close(bin->exe_file_map);}
if(!os_handle_match(os_handle_zero(), bin->exe_file)) {os_file_close(bin->exe_file);}
if(bin->parse.dbg_base != 0) {os_file_map_view_close(bin->dbg_file_map, bin->parse.dbg_base);}
if(!os_handle_match(os_handle_zero(), bin->dbg_file_map)) {os_file_map_close(bin->dbg_file_map);}
if(!os_handle_match(os_handle_zero(), bin->dbg_file)) {os_file_close(bin->dbg_file);}
MemoryZeroStruct(&bin->parse);
bin->last_time_enqueued_for_parse_us = 0;
// rjf: store new handles & props
bin->exe_file = exe_file;
bin->exe_file_map = exe_file_map;
bin->parse.exe_base = exe_file_base;
bin->parse.exe_props = exe_file_props;
bin->dbg_file = raddbg_file;
bin->dbg_file_map = raddbg_file_map;
bin->parse.dbg_base = raddbg_file_base;
bin->parse.dbg_props = raddbg_file_props;
bin->gen += 1;
}
break;
}
}
}
//- rjf: raddbg file or exe is not new? cache can stay unmodified, close
// handles & skip to end.
if(do_task) if(!raddbg_or_exe_file_is_updated) if(raddbg_file_is_up_to_date)
{
os_file_map_view_close(raddbg_file_map, raddbg_file_base);
os_file_map_close(raddbg_file_map);
os_file_close(raddbg_file);
os_file_map_view_close(exe_file_map, exe_file_base);
os_file_map_close(exe_file_map);
os_file_close(exe_file);
do_task = 0;
}
//- rjf: parse raddbg info
RADDBG_Parsed raddbg_parsed = {0};
U64 arch_addr_size = 8;
if(do_task)
{
RADDBG_ParseStatus parse_status = raddbg_parse((U8 *)raddbg_file_base, raddbg_file_props.size, &raddbg_parsed);
if(raddbg_parsed.top_level_info != 0)
{
arch_addr_size = raddbg_addr_size_from_arch(raddbg_parsed.top_level_info->architecture);
}
}
//- rjf: cache write, step 2: store parse artifacts
B32 parse_store_good = 0;
if(do_task) ProfScope("cache write, step 2: store parse")
{
OS_MutexScopeW(stripe->rw_mutex) for(DBGI_Binary *bin = slot->first; bin != 0; bin = bin->next)
{
if(str8_match(bin->exe_path, exe_path, 0))
{
String8 dbg_path = og_dbg_path;
if(dbg_path.size == 0)
{
dbg_path = exe_dbg_path_embedded;
}
if(dbg_path.size == 0)
{
dbg_path = push_str8f(scratch.arena, "%S.pdb", str8_chop_last_dot(exe_path));
}
parse_store_good = 1;
bin->parse.arena = parse_arena;
bin->parse.dbg_path = push_str8_copy(parse_arena, dbg_path);
MemoryCopyStruct(&bin->parse.pe, &exe_pe_info);
MemoryCopyStruct(&bin->parse.rdbg, &raddbg_parsed);
bin->parse.gen = bin->gen;
break;
}
}
}
//- rjf: bad parse store? abort
if(do_task && !parse_store_good)
{
arena_release(parse_arena);
}
//- rjf: cache write, step 3: mark binary work as complete
if(!task_is_taken_by_other_thread) ProfScope("cache write, step 4: mark binary work as complete")
{
OS_MutexScopeW(stripe->rw_mutex) for(DBGI_Binary *bin = slot->first; bin != 0; bin = bin->next)
{
if(str8_match(bin->exe_path, exe_path, 0))
{
bin->flags &= ~DBGI_BinaryFlag_ParseInFlight;
break;
}
}
os_condition_variable_broadcast(stripe->cv);
}
ProfEnd();
scratch_end(scratch);
}
}
////////////////////////////////
//~ rjf: Evictor Thread
internal void
dbgi_evictor_thread_entry_point(void *p)
{
TCTX tctx_;
tctx_init_and_equip(&tctx_);
ProfThreadName("[dbgi] evictor");
for(;;)
{
ProfBegin("eviction scan");
U64 slots_per_stripe = dbgi_shared->binary_slots_count/dbgi_shared->binary_stripes_count;
for(U64 stripe_idx = 0; stripe_idx < dbgi_shared->binary_stripes_count; stripe_idx += 1)
{
DBGI_BinaryStripe *stripe = &dbgi_shared->binary_stripes[stripe_idx];
for(U64 slot_in_stripe_idx = 0; slot_in_stripe_idx < slots_per_stripe; slot_in_stripe_idx += 1)
{
U64 slot_idx = slots_per_stripe*stripe_idx + slot_in_stripe_idx;
DBGI_BinarySlot *slot = &dbgi_shared->binary_slots[slot_idx];
B32 slot_needs_work = 0;
OS_MutexScopeR(stripe->rw_mutex)
{
for(DBGI_Binary *bin = slot->first; bin != 0; bin = bin->next)
{
if(bin->refcount == 0 && bin->scope_touch_count == 0 && bin->flags == 0 && bin->gen > 1)
{
slot_needs_work = 1;
break;
}
}
}
if(slot_needs_work) ProfScope("eviction task (slot %I64u)", slot_idx) OS_MutexScopeW(stripe->rw_mutex)
{
for(DBGI_Binary *bin = slot->first; bin != 0; bin = bin->next)
{
if(bin->refcount == 0 && bin->scope_touch_count == 0 && bin->flags == 0)
{
if(bin->parse.arena != 0) { arena_release(bin->parse.arena); }
if(bin->parse.exe_base != 0) { os_file_map_view_close(bin->exe_file_map, bin->parse.exe_base); }
if(!os_handle_match(os_handle_zero(), bin->exe_file_map)) { os_file_map_close(bin->exe_file_map); }
if(!os_handle_match(os_handle_zero(), bin->exe_file)) { os_file_close(bin->exe_file); }
if(bin->parse.dbg_base != 0) { os_file_map_view_close(bin->dbg_file_map, bin->parse.dbg_base); }
if(!os_handle_match(os_handle_zero(), bin->dbg_file_map)) { os_file_map_close(bin->dbg_file_map); }
if(!os_handle_match(os_handle_zero(), bin->dbg_file)) { os_file_close(bin->dbg_file); }
bin->exe_file_map = bin->exe_file = os_handle_zero();
bin->dbg_file_map = bin->dbg_file = os_handle_zero();
MemoryZeroStruct(&bin->parse);
bin->last_time_enqueued_for_parse_us = 0;
bin->gen = 1;
}
}
}
}
}
ProfEnd();
os_sleep_milliseconds(250);
}
}
+262
View File
@@ -0,0 +1,262 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DBGI_H
#define DBGI_H
////////////////////////////////
//~ rjf: Info Bundle Types
typedef struct DBGI_Parse DBGI_Parse;
struct DBGI_Parse
{
U64 gen;
Arena *arena;
void *exe_base;
FileProperties exe_props;
String8 dbg_path;
void *dbg_base;
FileProperties dbg_props;
PE_BinInfo pe;
RADDBG_Parsed rdbg;
};
////////////////////////////////
//~ rjf: Exe -> Debug Forced Override Cache Types
typedef struct DBGI_ForceNode DBGI_ForceNode;
struct DBGI_ForceNode
{
DBGI_ForceNode *next;
String8 exe_path;
U64 dbg_path_cap;
U64 dbg_path_size;
U8 *dbg_path_base;
};
typedef struct DBGI_ForceSlot DBGI_ForceSlot;
struct DBGI_ForceSlot
{
DBGI_ForceNode *first;
DBGI_ForceNode *last;
};
typedef struct DBGI_ForceStripe DBGI_ForceStripe;
struct DBGI_ForceStripe
{
Arena *arena;
OS_Handle rw_mutex;
OS_Handle cv;
};
////////////////////////////////
//~ rjf: Binary Cache State Types
typedef U32 DBGI_BinaryFlags;
enum
{
DBGI_BinaryFlag_ParseInFlight = (1<<0),
};
typedef struct DBGI_Binary DBGI_Binary;
struct DBGI_Binary
{
// rjf: links & metadata
DBGI_Binary *next;
String8 exe_path;
U64 refcount;
U64 scope_touch_count;
U64 last_time_enqueued_for_parse_us;
DBGI_BinaryFlags flags;
U64 gen;
// rjf: exe handles
OS_Handle exe_file;
OS_Handle exe_file_map;
// rjf: debug handles
OS_Handle dbg_file;
OS_Handle dbg_file_map;
// rjf: analysis results
DBGI_Parse parse;
};
typedef struct DBGI_BinarySlot DBGI_BinarySlot;
struct DBGI_BinarySlot
{
DBGI_Binary *first;
DBGI_Binary *last;
};
typedef struct DBGI_BinaryStripe DBGI_BinaryStripe;
struct DBGI_BinaryStripe
{
Arena *arena;
OS_Handle rw_mutex;
OS_Handle cv;
};
////////////////////////////////
//~ rjf: Weak Access Scope Types
typedef struct DBGI_TouchedBinary DBGI_TouchedBinary;
struct DBGI_TouchedBinary
{
DBGI_TouchedBinary *next;
DBGI_Binary *binary;
};
typedef struct DBGI_Scope DBGI_Scope;
struct DBGI_Scope
{
DBGI_Scope *next;
DBGI_TouchedBinary *first_tb;
DBGI_TouchedBinary *last_tb;
};
typedef struct DBGI_ThreadCtx DBGI_ThreadCtx;
struct DBGI_ThreadCtx
{
Arena *arena;
DBGI_Scope *free_scope;
DBGI_TouchedBinary *free_tb;
};
////////////////////////////////
//~ rjf: Event Types
typedef enum DBGI_EventKind
{
DBGI_EventKind_Null,
DBGI_EventKind_ConversionStarted,
DBGI_EventKind_ConversionEnded,
DBGI_EventKind_ConversionFailureUnsupportedFormat,
DBGI_EventKind_COUNT
}
DBGI_EventKind;
typedef struct DBGI_Event DBGI_Event;
struct DBGI_Event
{
DBGI_EventKind kind;
String8 string;
};
typedef struct DBGI_EventNode DBGI_EventNode;
struct DBGI_EventNode
{
DBGI_EventNode *next;
DBGI_Event v;
};
typedef struct DBGI_EventList DBGI_EventList;
struct DBGI_EventList
{
DBGI_EventNode *first;
DBGI_EventNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Cross-Thread Shared State
typedef struct DBGI_Shared DBGI_Shared;
struct DBGI_Shared
{
// rjf: arena
Arena *arena;
// rjf: forced override table
U64 force_slots_count;
U64 force_stripes_count;
DBGI_ForceSlot *force_slots;
DBGI_ForceStripe *force_stripes;
// rjf: binary table
U64 binary_slots_count;
U64 binary_stripes_count;
DBGI_BinarySlot *binary_slots;
DBGI_BinaryStripe *binary_stripes;
// rjf: user -> parse ring
OS_Handle u2p_ring_mutex;
OS_Handle u2p_ring_cv;
U64 u2p_ring_size;
U8 *u2p_ring_base;
U64 u2p_ring_write_pos;
U64 u2p_ring_read_pos;
// rjf: parse -> user event ring
OS_Handle p2u_ring_mutex;
OS_Handle p2u_ring_cv;
U64 p2u_ring_size;
U8 *p2u_ring_base;
U64 p2u_ring_write_pos;
U64 p2u_ring_read_pos;
// rjf: threads
U64 parse_thread_count;
OS_Handle *parse_threads;
OS_Handle evictor_thread;
};
////////////////////////////////
//~ rjf: Globals
global DBGI_Shared *dbgi_shared = 0;
thread_static DBGI_ThreadCtx *dbgi_tctx = 0;
global DBGI_Parse dbgi_parse_nil = {0};
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void dbgi_init(void);
////////////////////////////////
//~ rjf: Thread-Context Idempotent Initialization
internal void dbgi_ensure_tctx_inited(void);
////////////////////////////////
//~ rjf: Helpers
internal U64 dbgi_hash_from_string(String8 string);
////////////////////////////////
//~ rjf: Forced Override Cache Functions
internal void dbgi_force_exe_path_dbg_path(String8 exe_path, String8 dbg_path);
internal String8 dbgi_forced_dbg_path_from_exe_path(Arena *arena, String8 exe_path);
////////////////////////////////
//~ rjf: Scope Functions
internal DBGI_Scope *dbgi_scope_open(void);
internal void dbgi_scope_close(DBGI_Scope *scope);
internal void dbgi_scope_touch_binary__stripe_mutex_r_guarded(DBGI_Scope *scope, DBGI_Binary *binary);
////////////////////////////////
//~ rjf: Binary Cache Functions
internal void dbgi_binary_open(String8 exe_path);
internal void dbgi_binary_close(String8 exe_path);
internal DBGI_Parse *dbgi_parse_from_exe_path(DBGI_Scope *scope, String8 exe_path, U64 endt_us);
////////////////////////////////
//~ rjf: Parse Threads
internal B32 dbgi_u2p_enqueue_exe_path(String8 exe_path, U64 endt_us);
internal String8 dbgi_u2p_dequeue_exe_path(Arena *arena);
internal void dbgi_p2u_push_event(DBGI_Event *event);
internal DBGI_EventList dbgi_p2u_pop_events(Arena *arena, U64 endt_us);
internal void dbgi_parse_thread_entry_point(void *p);
////////////////////////////////
//~ rjf: Evictor Thread
internal void dbgi_evictor_thread_entry_point(void *p);
#endif //DBGI_H
+235
View File
@@ -0,0 +1,235 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//- allen: Acceleration Layer Functions
//- accel helpers
internal DEMON_AccelModule*
demon_accel_module_alloc(void){
DEMON_AccelModule *result = demon_free_module_accel;
if (result != 0){
SLLStackPop(demon_free_module_accel);
}
else{
result = push_array_no_zero(demon_ent_arena, DEMON_AccelModule, 1);
}
MemoryZeroStruct(result);
return(result);
}
internal void
demon_accel_module_free(DEMON_AccelModule *module){
SLLStackPush(demon_free_module_accel, module);
}
internal DEMON_AccelThread*
demon_accel_thread_alloc(void){
DEMON_AccelThread *result = demon_free_thread_accel;
if (result != 0){
SLLStackPop(demon_free_thread_accel);
}
else{
result = push_array_no_zero(demon_ent_arena, DEMON_AccelThread, 1);
}
MemoryZeroStruct(result);
return(result);
}
internal void
demon_accel_thread_free(DEMON_AccelThread *thread){
SLLStackPush(demon_free_thread_accel, thread);
}
internal DEMON_AccelThread*
demon_accel_from_thread(DEMON_Entity *thread){
DEMON_AccelThread *accel = (DEMON_AccelThread*)thread->accel;
if (accel == 0){
accel = demon_accel_thread_alloc();
thread->accel = accel;
}
return(accel);
}
//- operations on demon objects
internal String8
demon_accel_full_path_from_module(Arena *arena, DEMON_Entity *module){
DEMON_AccelModule *accel = (DEMON_AccelModule*)module->accel;
String8 result = {0};
// first time
if (accel == 0){
result = demon_os_full_path_from_module(arena, module);
// build chain
DEMON_AccelModule *last_accel = 0;
U8 *ptr = result.str;
U8 *opl = result.str + result.size;
for (;ptr < opl;){
U64 size = (U64)(ptr - opl);
U64 clamped_size = ClampTop(result.size, sizeof(Member(DEMON_AccelModule, buf)));
DEMON_AccelModule *node = demon_accel_module_alloc();
SLLQueuePush(accel, last_accel, node);
node->total_size = result.size;
MemoryCopy(node->buf, ptr, clamped_size);
ptr += clamped_size;
}
// store in module
module->accel = accel;
}
// read from accel
else{
U64 size = accel->total_size;
U8 *str = push_array_no_zero(arena, U8, size + 1);
// copy chain contents to buffer
U8 *ptr = str;
for (DEMON_AccelModule *node = accel;
node != 0;
node = node->next){
U64 total_size = node->total_size;
U64 clamped_size = ClampTop(total_size, sizeof(node->buf));
MemoryCopy(ptr, node->buf, clamped_size);
ptr += clamped_size;
}
*ptr = 0;
// fill result
result.str = str;
result.size = size;
}
return(result);
}
internal U64
demon_accel_stack_base_vaddr_from_thread(DEMON_Entity *thread){
// get accel data
DEMON_AccelThread *accel = demon_accel_from_thread(thread);
// fill stack base
if (!accel->has_stack_base){
accel->has_stack_base = 1;
accel->stack_base = demon_os_stack_base_vaddr_from_thread(thread);
}
return(accel->stack_base);
}
internal U64
demon_accel_tls_root_vaddr_from_thread(DEMON_Entity *thread){
// get accel data
DEMON_AccelThread *accel = demon_accel_from_thread(thread);
// fill tls root
if (!accel->has_tls_root){
accel->has_tls_root = 1;
accel->tls_root = demon_os_tls_root_vaddr_from_thread(thread);
}
return(accel->tls_root);
}
internal void*
demon_accel_read_regs(DEMON_Entity *thread){
// get accel data
DEMON_AccelThread *accel = demon_accel_from_thread(thread);
// update reg cache
if (accel->reg_cache_time != demon_time){
accel->reg_cache_time = demon_time;
B32 success = 0;
switch (thread->arch){
case Architecture_x86:{success = demon_os_read_regs_x86(thread, &accel->regs.x86);}break;
case Architecture_x64:{success = demon_os_read_regs_x64(thread, &accel->regs.x64);}break;
}
if (!success){
MemoryZeroStruct(&accel->regs);
}
}
return(&accel->regs);
}
internal void
demon_accel_write_regs(DEMON_Entity *thread, void *data){
// get accel data
DEMON_AccelThread *accel = demon_accel_from_thread(thread);
// low level write
B32 success = 0;
U64 data_size = 0;
switch (thread->arch){
case Architecture_x86:
{
data_size = sizeof(REGS_RegBlockX86);
success = demon_os_write_regs_x86(thread, (REGS_RegBlockX86*)data);
}break;
case Architecture_x64:
{
data_size = sizeof(REGS_RegBlockX64);
success = demon_os_write_regs_x64(thread, (REGS_RegBlockX64*)data);
}break;
}
// update cache
if (success){
accel->reg_cache_time = demon_time;
MemoryCopy(&accel->regs, data, data_size);
}
}
internal void
demon_accel_low_level_write_regs(DEMON_Entity *thread){
// NOTE(allen): This is a tricky one. It's just a way to enable some internal
// optimizations. Instead of forcing the user to pass in register data
// to write out and copy to the cache, the "user" is other demon code that
// knows what it's doing. So it grabs the cache memory (through a call to
// `demon_accel_read_regs`) modifies it in place and then calls this.
// So we just have to write the cache contents directly out to OS.
// get accel data
DEMON_AccelThread *accel = demon_accel_from_thread(thread);
switch (thread->arch){
case Architecture_x86:
{
demon_os_write_regs_x86(thread, &accel->regs.x86);
}break;
case Architecture_x64:
{
demon_os_write_regs_x64(thread, &accel->regs.x64);
}break;
}
}
//- entity accel free
internal void
demon_accel_free(DEMON_Entity *entity){
switch (entity->kind){
case DEMON_EntityKind_Module:
{
if (entity->accel != 0){
for (DEMON_AccelModule *node = (DEMON_AccelModule*)entity->accel, *next = 0;
node != 0;
node = next){
next = node->next;
demon_accel_module_free(node);
}
}
}break;
case DEMON_EntityKind_Thread:
{
if (entity->accel != 0){
demon_accel_thread_free((DEMON_AccelThread*)entity->accel);
}
}break;
}
}
+66
View File
@@ -0,0 +1,66 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_ACCEL_H
#define DEMON_ACCEL_H
////////////////////////////////
//~ allen: Acceleration Data
typedef struct DEMON_AccelModule DEMON_AccelModule;
struct DEMON_AccelModule
{
DEMON_AccelModule *next;
U64 total_size;
U8 buf[240];
};
typedef union DEMON_AccelThread DEMON_AccelThread;
union DEMON_AccelThread
{
DEMON_AccelThread *next;
struct{
B32 has_stack_base;
B32 has_tls_root;
U64 stack_base;
U64 tls_root;
U64 reg_cache_time;
union{
REGS_RegBlockX64 x64;
REGS_RegBlockX86 x86;
} regs;
};
};
////////////////////////////////
//~ allen: Acceleration Globals
global DEMON_AccelModule *demon_free_module_accel = 0;
global DEMON_AccelThread *demon_free_thread_accel = 0;
////////////////////////////////
//~ allen: Acceleration Layer Functions
//- accel helpers
internal DEMON_AccelModule *demon_accel_module_alloc(void);
internal void demon_accel_module_free(DEMON_AccelModule *module);
internal DEMON_AccelThread *demon_accel_thread_alloc(void);
internal void demon_accel_thread_free(DEMON_AccelThread *thread);
internal DEMON_AccelThread *demon_accel_from_thread(DEMON_Entity *thread);
//- operations on demon objects
internal String8 demon_accel_full_path_from_module(Arena *arena, DEMON_Entity *module);
internal U64 demon_accel_stack_base_vaddr_from_thread(DEMON_Entity *thread);
internal U64 demon_accel_tls_root_vaddr_from_thread(DEMON_Entity *thread);
internal void* demon_accel_read_regs(DEMON_Entity *thread);
internal void demon_accel_write_regs(DEMON_Entity *thread, void *data);
internal void demon_accel_low_level_write_regs(DEMON_Entity *thread);
//- entity accel free
internal void demon_accel_free(DEMON_Entity *entity);
#endif //DEMON_ACCEL_H
+270
View File
@@ -0,0 +1,270 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
// NOTE(allen): State Safety Helper
internal B32
demon_access_begin(void){
B32 result = 0;
if (demon_primary_thread){
Assert(demon_run_state);
result = 1;
}
else{
os_mutex_take(demon_state_mutex);
if (demon_run_state){
os_mutex_drop(demon_state_mutex);
}
else{
result = 1;
}
}
return(result);
}
internal void
demon_access_end(void){
if (!demon_primary_thread){
os_mutex_drop(demon_state_mutex);
}
}
////////////////////////////////
// NOTE(allen): Entity System
internal void
demon_common_init(void){
// access control mechanism
demon_state_mutex = os_mutex_alloc();
// time
demon_time = 1;
// setup arena
demon_ent_arena = arena_alloc();
// setup map
demon_ent_map = push_array(demon_ent_arena, DEMON_Map, 1);
demon_ent_map->bucket_count = 4093;
demon_ent_map->buckets = push_array(demon_ent_arena, DEMON_MapSlot*, demon_ent_map->bucket_count);
// setup entity memory
U64 reserve_size_unaligned = (DEMON_ENTITY_CAP)*sizeof(DEMON_Entity);
U64 reserve_size = AlignPow2(reserve_size_unaligned, DEMON_ENTITY_CMT_SIZE);
demon_ent_cmt = demon_ent_pos = demon_ent_base = (DEMON_Entity*)os_reserve(reserve_size);
demon_ent_opl = demon_ent_base + (reserve_size/sizeof(DEMON_Entity));
Assert(demon_ent_base != 0);
// setup root
demon_ent_root = demon_ent_alloc();
demon_ent_root->kind = DEMON_EntityKind_Root;
}
internal DEMON_Entity*
demon_ent_alloc(void){
DEMON_Entity *result = demon_ent_free;
if (result != 0){
SLLStackPop(demon_ent_free);
}
else{
if (demon_ent_pos < demon_ent_opl){
if (ensure_commit(&demon_ent_cmt, demon_ent_pos + 1, DEMON_ENTITY_CMT_SIZE)){
result = demon_ent_pos;
demon_ent_pos += 1;
}
}
}
if (result != 0){
U32 gen = result->gen;
MemoryZeroStruct(result);
result->gen = gen;
}
return(result);
}
//- handle <-> entity pointer
internal DEMON_Entity*
demon_ent_ptr_from_handle(DEMON_Handle handle){
Assert(demon_ent_base != 0);
DEMON_Entity *result = 0;
U32 index = (U32)(handle & 0xFFFFFFFF);
U64 count = (U64)(demon_ent_pos - demon_ent_base);
if (0 < index && index < count){
DEMON_Entity *entity = demon_ent_base + index;
U32 gen = (U32)(handle >> 32);
if (gen == entity->gen){
result = entity;
}
}
return(result);
}
internal DEMON_Handle
demon_ent_handle_from_ptr(DEMON_Entity *entity){
Assert(demon_ent_base != 0);
DEMON_Handle result = {0};
if (demon_ent_base < entity && entity < demon_ent_pos){
U32 index = (U32)(entity - demon_ent_base);
U64 gen = entity->gen;
result = (gen << 32) | index;
}
return(result);
}
//- high level entity alloc,init,release
internal DEMON_Entity*
demon_ent_new(DEMON_Entity *parent, DEMON_EntityKind kind, U64 id){
Assert(demon_ent_base != 0);
DEMON_Entity *result = demon_ent_alloc();
if (result != 0){
result->kind = kind;
result->id = id;
result->arch = parent->arch;
result->parent = parent;
DLLPushBack(parent->first, parent->last, result);
demon_ent_map_save(kind, id, result);
}
return(result);
}
internal void
demon_ent_release_single(DEMON_Entity *entity){
switch (entity->kind){
case DEMON_EntityKind_Process: demon_proc_count -= 1; break;
case DEMON_EntityKind_Thread: demon_thread_count -= 1; break;
case DEMON_EntityKind_Module: demon_module_count -= 1; break;
}
demon_accel_free(entity);
demon_os_entity_cleanup(entity);
DEMON_MapRef ref = demon_ent_map_find(entity->kind, entity->id);
demon_ent_map_erase(ref);
entity->gen += 1;
}
internal void
demon_ent_release_children(DEMON_Entity *root){
Assert(demon_ent_base != 0);
if (root->first != 0){
for (DEMON_Entity *node = root->first;
node != 0;
node = node->next){
demon_ent_release_children(node);
demon_ent_release_single(node);
}
root->last->next = demon_ent_free;
demon_ent_free = root->first;
root->first = 0;
root->last = 0;
}
}
internal void
demon_ent_release_root_and_children(DEMON_Entity *root){
Assert(demon_ent_base != 0);
Assert(root->parent != 0);
// release children
demon_ent_release_children(root);
// release root
DEMON_Entity *parent = root->parent;
demon_ent_release_single(root);
DLLRemove(parent->first, parent->last, root);
SLLStackPush(demon_ent_free, root);
}
//- entity map
internal U64
demon_ent_map_hash(U16 kind, U64 id){
U64 result = ((U64)kind << 32) ^ id;
return(result);
}
internal void
demon_ent_map_save(U16 kind, U64 id, DEMON_Entity *entity){
Assert(demon_ent_base != 0);
DEMON_Map *map = demon_ent_map;
// allocate a new slot
DEMON_MapSlot *slot = map->free_slots;
if (slot != 0){
SLLStackPop(map->free_slots);
}
else{
slot = push_array_no_zero(demon_ent_arena, DEMON_MapSlot, 1);
}
// fill slot
slot->kind = kind;
slot->id = id;
slot->entity = entity;
// insert into bucket
U64 hash = demon_ent_map_hash(kind, id);
U64 bucket_index = hash%map->bucket_count;
SLLStackPush(map->buckets[bucket_index], slot);
}
internal DEMON_MapRef
demon_ent_map_find(U16 kind, U64 id){
Assert(demon_ent_base != 0);
DEMON_Map *map = demon_ent_map;
// scan bucket
DEMON_MapRef result = {0};
U64 hash = demon_ent_map_hash(kind, id);
U64 bucket_index = hash%map->bucket_count;
for (DEMON_MapSlot **ptr = &map->buckets[bucket_index], *slot = 0;
*ptr != 0;
ptr = &slot->next){
slot = *ptr;
if (slot->kind == kind && slot->id == id){
result.slot = slot;
result.ptr_to_slot = ptr;
break;
}
}
return(result);
}
internal DEMON_Entity*
demon_ent_map_entity_from_id(U16 kind, U64 id){
DEMON_Entity *result = 0;
DEMON_MapRef ref = demon_ent_map_find(kind, id);
if (ref.slot != 0){
result = ref.slot->entity;
}
return(result);
}
internal void
demon_ent_map_erase(DEMON_MapRef ref){
Assert(demon_ent_base != 0);
DEMON_Map *map = demon_ent_map;
// move slot to free list
if (ref.slot != 0){
*ref.ptr_to_slot = ref.slot->next;
SLLStackPush(map->free_slots, ref.slot);
}
}
////////////////////////////////
// NOTE(allen): Event Helpers
internal DEMON_Event*
demon_push_event(Arena *arena, DEMON_EventList *list, DEMON_EventKind kind){
DEMON_EventNode *n = push_array(arena, DEMON_EventNode, 1);
DEMON_Event *result = &n->v;
SLLQueuePush(list->first, list->last, n);
list->count += 1;
result->kind = kind;
return(result);
}
+150
View File
@@ -0,0 +1,150 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_COMMON_H
#define DEMON_COMMON_H
////////////////////////////////
//~ allen: DEMON Entity System
typedef enum DEMON_EntityKind
{
DEMON_EntityKind_NULL,
DEMON_EntityKind_Root,
DEMON_EntityKind_Process,
DEMON_EntityKind_Thread,
DEMON_EntityKind_Module,
DEMON_EntityKind_COUNT
}
DEMON_EntityKind;
typedef struct DEMON_Entity DEMON_Entity;
struct DEMON_Entity
{
// TODO(allen): these could be U32s
DEMON_Entity *next;
DEMON_Entity *prev;
DEMON_Entity *parent;
DEMON_Entity *first;
DEMON_Entity *last;
U16 kind;
U16 arch;
U32 gen;
U64 id;
U64 addr_range_dim;
// each OS backend decides how to use `ext` for each entity kind
union{
void *ext;
U64 ext_u64;
};
// the accel layer attaches some extra information to some entities
void *accel;
};
//- id -> entity map
typedef struct DEMON_MapSlot DEMON_MapSlot;
struct DEMON_MapSlot
{
DEMON_MapSlot *next;
U16 kind;
U64 id;
DEMON_Entity *entity;
};
typedef struct DEMON_Map DEMON_Map;
struct DEMON_Map
{
DEMON_MapSlot **buckets;
U64 bucket_count;
DEMON_MapSlot *free_slots;
};
typedef struct DEMON_MapRef DEMON_MapRef;
struct DEMON_MapRef
{
DEMON_MapSlot *slot;
DEMON_MapSlot **ptr_to_slot;
};
//- rjf: entity extrusive list
typedef struct DEMON_EntityNode DEMON_EntityNode;
struct DEMON_EntityNode
{
DEMON_EntityNode *next;
DEMON_Entity *entity;
};
////////////////////////////////
//~ allen: Demon Globals
thread_static B32 demon_primary_thread = 0;
global B32 demon_run_state = 0;
global OS_Handle demon_state_mutex = {0};
global U64 demon_time = 0;
global Arena *demon_ent_arena = 0;
global DEMON_Map *demon_ent_map = 0;
global DEMON_Entity *demon_ent_free = 0;
global DEMON_Entity *demon_ent_root = 0;
global DEMON_Entity *demon_ent_base = 0;
global DEMON_Entity *demon_ent_pos = 0;
global DEMON_Entity *demon_ent_opl = 0;
global void *demon_ent_cmt = 0;
global U64 demon_proc_count = 0;
global U64 demon_thread_count = 0;
global U64 demon_module_count = 0;
#if !defined(DEMON_ENTITY_CMT_SIZE)
# define DEMON_ENTITY_CMT_SIZE KB(64)
#endif
#if !defined(DEMON_ENTITY_CAP)
# define DEMON_ENTITY_CAP 65536
#endif
StaticAssert(IsPow2(DEMON_ENTITY_CMT_SIZE), check_demon_entity_cmt_size);
////////////////////////////////
//~ allen: State Safety Helper
internal B32 demon_access_begin(void);
internal void demon_access_end(void);
////////////////////////////////
//~ allen: Entity System
internal void demon_common_init(void);
internal DEMON_Entity* demon_ent_alloc(void);
//- handle <-> entity pointer
internal DEMON_Entity* demon_ent_ptr_from_handle(DEMON_Handle handle);
internal DEMON_Handle demon_ent_handle_from_ptr(DEMON_Entity *entity);
//- high level entity alloc,init,release
internal DEMON_Entity* demon_ent_new(DEMON_Entity *parent, DEMON_EntityKind kind, U64 id);
internal void demon_ent_release_single(DEMON_Entity *entity);
internal void demon_ent_release_children(DEMON_Entity *root);
internal void demon_ent_release_root_and_children(DEMON_Entity *root);
//- entity map
internal U64 demon_ent_map_hash(U16 kind, U64 id);
internal void demon_ent_map_save(U16 kind, U64 id, DEMON_Entity *entity);
internal DEMON_MapRef demon_ent_map_find(U16 kind, U64 id);
internal DEMON_Entity* demon_ent_map_entity_from_id(U16 kind, U64 id);
internal void demon_ent_map_erase(DEMON_MapRef map_ref);
////////////////////////////////
//~ allen: Event Helpers
internal DEMON_Event* demon_push_event(Arena *arena, DEMON_EventList *list, DEMON_EventKind kind);
#endif //DEMON_COMMON_H
+871
View File
@@ -0,0 +1,871 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void
demon_init(void){
demon_common_init();
demon_os_init();
}
////////////////////////////////
//~ rjf: Basic Type Functions
//- rjf: stringizing
internal String8
demon_string_from_event_kind(DEMON_EventKind kind){
String8 result = str8_lit("unknown");
switch (kind){
default: break;
case DEMON_EventKind_Error: result = str8_lit("Error"); break;
case DEMON_EventKind_HandshakeComplete: result = str8_lit("HandshakeComplete"); break;
case DEMON_EventKind_CreateProcess: result = str8_lit("CreateProcess"); break;
case DEMON_EventKind_ExitProcess: result = str8_lit("ExitProcess"); break;
case DEMON_EventKind_CreateThread: result = str8_lit("CreateThread"); break;
case DEMON_EventKind_ExitThread: result = str8_lit("ExitThread"); break;
case DEMON_EventKind_LoadModule: result = str8_lit("LoadModule"); break;
case DEMON_EventKind_UnloadModule: result = str8_lit("UnloadModule"); break;
case DEMON_EventKind_Breakpoint: result = str8_lit("Breakpoint"); break;
case DEMON_EventKind_Trap: result = str8_lit("Trap"); break;
case DEMON_EventKind_SingleStep: result = str8_lit("SingleStep"); break;
case DEMON_EventKind_Exception: result = str8_lit("Exception"); break;
case DEMON_EventKind_Halt: result = str8_lit("Halt"); break;
case DEMON_EventKind_Memory: result = str8_lit("Memory"); break;
case DEMON_EventKind_DebugString: result = str8_lit("DebugString"); break;
case DEMON_EventKind_SetThreadName: result = str8_lit("SetThreadName"); break;
}
return(result);
}
internal String8
demon_string_from_memory_event_kind(DEMON_MemoryEventKind kind){
String8 result = str8_lit("unknown");
switch (kind){
default: break;
case DEMON_MemoryEventKind_Commit: result = str8_lit("Commit"); break;
case DEMON_MemoryEventKind_Reserve: result = str8_lit("Reserve"); break;
case DEMON_MemoryEventKind_Decommit: result = str8_lit("Decommit"); break;
case DEMON_MemoryEventKind_Release: result = str8_lit("Release"); break;
}
return(result);
}
internal String8
demon_string_from_exception_kind(DEMON_ExceptionKind kind){
String8 result = str8_lit("unknown");
switch (kind){
default: break;
case DEMON_ExceptionKind_MemoryRead: result = str8_lit("MemoryRead"); break;
case DEMON_ExceptionKind_MemoryWrite: result = str8_lit("MemoryWrite"); break;
case DEMON_ExceptionKind_MemoryExecute: result = str8_lit("MemoryExecute"); break;
case DEMON_ExceptionKind_CppThrow: result = str8_lit("CppThrow"); break;
}
return(result);
}
internal void
demon_string_list_from_event(Arena *arena, String8List *out, DEMON_Event *event){
B32 need_exception_info = (event->kind == DEMON_EventKind_Exception ||
event->kind == DEMON_EventKind_Breakpoint ||
event->kind == DEMON_EventKind_Halt ||
event->kind == DEMON_EventKind_SingleStep);
// allen: kind
String8 kind_string = demon_string_from_event_kind(event->kind);
str8_list_pushf(arena, out, "%S: { (%i)", kind_string, event->kind);
// rjf: basics
{
str8_list_pushf(arena, out, " process: (%I64x)", event->process);
str8_list_pushf(arena, out, " thread: (%I64x)", event->thread);
str8_list_pushf(arena, out, " module: (%I64x)", event->module);
str8_list_pushf(arena, out, " address: (%I64x)", event->address, event->address);
str8_list_pushf(arena, out, " size: (0x%I64x, %I64u)", event->size, event->size);
}
// rjf: string
if (event->string.size != 0){
str8_list_pushf(arena, out, " string: \"%S\"", event->string);
}
// rjf: exception info
if (need_exception_info){
str8_list_pushf(arena, out, " code: (0x%x, %i)", event->code, event->code);
str8_list_pushf(arena, out, " flags: (0x%x, %i)", event->flags, event->flags);
str8_list_pushf(arena, out, " signo: (0x%x, %i)", event->signo, event->signo);
str8_list_pushf(arena, out, " sigcode: (0x%x, %i)", event->sigcode, event->sigcode);
}
// rjf: need error info
if (event->kind == DEMON_EventKind_Error){
str8_list_pushf(arena, out, " error_kind: (0x%x, %i)", event->error_kind, event->error_kind);
}
// rjf: memory event kind info
if (event->memory_kind != DEMON_MemoryEventKind_Null){
String8 memory_kind_string = demon_string_from_memory_event_kind(event->memory_kind);
str8_list_pushf(arena, out, " memory_kind: (%S, %i)",
memory_kind_string, event->memory_kind);
}
// rjf: exception kind
if (need_exception_info){
String8 exception_kind_string = demon_string_from_exception_kind(event->exception_kind);
str8_list_pushf(arena, out, " exception_kind: (%S, %i)",
exception_kind_string, event->exception_kind);
}
// rjf: instruction ptr
if (event->instruction_pointer != 0){
str8_list_pushf(arena, out, " instruction_pointer: (%I64x)", event->instruction_pointer);
}
// rjf: stack ptr
if (event->stack_pointer != 0){
str8_list_pushf(arena, out, " stack_pointer: (%I64x)", event->stack_pointer);
}
str8_list_pushf(arena, out, " user_data: (0x%I64x, %I64u)",
event->user_data, event->user_data);
str8_list_pushf(arena, out, "}");
}
//- rjf: trap chunk lists
internal void
demon_trap_chunk_list_push(Arena *arena, DEMON_TrapChunkList *list, U64 cap, DEMON_Trap *trap)
{
DEMON_TrapChunkNode *node = list->last;
if(node == 0 || node->count >= node->cap)
{
node = push_array(arena, DEMON_TrapChunkNode, 1);
node->cap = cap;
node->v = push_array_no_zero(arena, DEMON_Trap, node->cap);
SLLQueuePush(list->first, list->last, node);
list->node_count += 1;
}
MemoryCopyStruct(&node->v[node->count], trap);
node->count += 1;
list->trap_count += 1;
}
internal void
demon_trap_chunk_list_concat_in_place(DEMON_TrapChunkList *dst, DEMON_TrapChunkList *to_push)
{
if(dst->last == 0)
{
MemoryCopyStruct(dst, to_push);
}
else if(to_push->first != 0)
{
dst->last->next = to_push->first;
dst->last = to_push->last;
dst->node_count += to_push->node_count;
dst->trap_count += to_push->trap_count;
}
MemoryZeroStruct(to_push);
}
internal void
demon_trap_chunk_list_concat_shallow_copy(Arena *arena, DEMON_TrapChunkList *dst, DEMON_TrapChunkList *to_push)
{
for(DEMON_TrapChunkNode *src_n = to_push->first; src_n != 0; src_n = src_n->next)
{
DEMON_TrapChunkNode *dst_n = push_array(arena, DEMON_TrapChunkNode, 1);
dst_n->v = src_n->v;
dst_n->cap = src_n->cap;
dst_n->count = src_n->count;
SLLQueuePush(dst->first, dst->last, dst_n);
dst->node_count += 1;
dst->trap_count += dst_n->count;
}
}
//- rjf: handle lists
internal void
demon_handle_list_push(Arena *arena, DEMON_HandleList *list, DEMON_Handle handle)
{
DEMON_HandleNode *node = push_array(arena, DEMON_HandleNode, 1);
SLLQueuePush(list->first, list->last, node);
node->v = handle;
list->count += 1;
}
internal DEMON_HandleArray
demon_handle_array_from_list(Arena *arena, DEMON_HandleList *list)
{
DEMON_HandleArray array = {0};
array.count = list->count;
array.handles = push_array_no_zero(arena, DEMON_Handle, array.count);
U64 idx = 0;
for(DEMON_HandleNode *n = list->first; n != 0; n = n->next, idx += 1)
{
array.handles[idx] = n->v;
}
return array;
}
internal DEMON_HandleArray
demon_handle_array_copy(Arena *arena, DEMON_HandleArray *src)
{
DEMON_HandleArray dst = {0};
dst.count = src->count;
dst.handles = push_array_no_zero(arena, DEMON_Handle, dst.count);
MemoryCopy(dst.handles, src->handles, sizeof(DEMON_Handle)*dst.count);
return dst;
}
////////////////////////////////
//~ rjf: Primary Thread & Exclusive Mode Controls
internal void
demon_primary_thread_begin(void){
demon_primary_thread = 1;
}
internal void
demon_exclusive_mode_begin(void){
Assert(demon_primary_thread);
os_mutex_take(demon_state_mutex);
demon_run_state = 1;
os_mutex_drop(demon_state_mutex);
}
internal void
demon_exclusive_mode_end(void){
Assert(demon_primary_thread);
os_mutex_take(demon_state_mutex);
demon_run_state = 0;
os_mutex_drop(demon_state_mutex);
}
////////////////////////////////
//~ rjf: Running/Halting
internal DEMON_EventList
demon_run(Arena *arena, DEMON_RunCtrls *ctrls)
{
Assert(demon_primary_thread);
Temp scratch = scratch_begin(&arena, 1);
// convert controls to os controls
B32 full_conversion = 1;
DEMON_OS_RunCtrls os_ctrls = {0};
{
// convert single_step_thread
if (ctrls->single_step_thread != 0){
DEMON_Entity *sst_entity = demon_ent_ptr_from_handle(ctrls->single_step_thread);
if (sst_entity != 0 &&
sst_entity->kind == DEMON_EntityKind_Thread){
os_ctrls.single_step_thread = sst_entity;
}
else{
full_conversion = 0;
goto finish_conversion;
}
}
// convert exception handling flag
os_ctrls.ignore_previous_exception = ctrls->ignore_previous_exception;
// convert fronzen threads
os_ctrls.run_entities_are_unfrozen = ctrls->run_entities_are_unfrozen;
os_ctrls.run_entities_are_processes = ctrls->run_entities_are_processes;
os_ctrls.run_entity_count = ctrls->run_entity_count;
os_ctrls.run_entities = push_array_no_zero(scratch.arena, DEMON_Entity*, ctrls->run_entity_count);
{
DEMON_EntityKind expected_entity_kind = DEMON_EntityKind_Thread;
if (os_ctrls.run_entities_are_processes){
expected_entity_kind = DEMON_EntityKind_Process;
}
DEMON_Handle *src = ctrls->run_entities;
DEMON_Entity **dst = os_ctrls.run_entities;
for (U64 i = 0; i < ctrls->run_entity_count; i += 1, src += 1, dst += 1){
DEMON_Entity *frozen_thread = demon_ent_ptr_from_handle(*src);
if (frozen_thread != 0 &&
frozen_thread->kind == expected_entity_kind){
*dst = frozen_thread;
}
else{
full_conversion = 0;
goto finish_conversion;
}
}
}
// convert traps
os_ctrls.traps = push_array_no_zero(scratch.arena, DEMON_OS_Trap, ctrls->traps.trap_count);
{
DEMON_OS_Trap *dst = os_ctrls.traps;
for (DEMON_TrapChunkNode *node = ctrls->traps.first;
node != 0;
node = node->next){
DEMON_Trap *src = node->v;
U64 node_trap_count = node->count;
for (U64 i = 0; i < node_trap_count; i += 1, src += 1){
if (src->process != 0){
DEMON_Entity *trap_process = demon_ent_ptr_from_handle(src->process);
if (trap_process != 0 &&
trap_process->kind == DEMON_EntityKind_Process){
dst->process = trap_process;
dst->address = src->address;
dst += 1;
}
else{
full_conversion = 0;
goto finish_conversion;
}
}
}
}
os_ctrls.trap_count = (U64)(dst - os_ctrls.traps);
}
finish_conversion:;
}
// call the OS implementation of run
DEMON_EventList result = {0};
if (full_conversion){
result = demon_os_run(arena, &os_ctrls);
}
else{
DEMON_Event *event = demon_push_event(arena, &result, DEMON_EventKind_Error);
event->error_kind = DEMON_ErrorKind_InvalidHandle;
}
scratch_end(scratch);
return(result);
}
internal void
demon_halt(U64 code, U64 user_data){
demon_os_halt(code, user_data);
}
internal U64
demon_get_time_counter(void){
return(demon_time);
}
////////////////////////////////
//~ rjf: Target Process Launching/Attaching/Killing/Detaching/Halting
internal U32
demon_launch_process(OS_LaunchOptions *options){
Assert(demon_primary_thread);
U32 result = demon_os_launch_process(options);
return(result);
}
internal B32
demon_attach_process(U32 pid){
Assert(demon_primary_thread);
B32 result = demon_os_attach_process(pid);
return(result);
}
internal B32
demon_kill_process(DEMON_Handle process, U32 exit_code){
Assert(demon_primary_thread);
B32 result = 0;
DEMON_Entity *entity = demon_ent_ptr_from_handle(process);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Process){
result = demon_os_kill_process(entity, exit_code);
}
return(result);
}
internal B32
demon_detach_process(DEMON_Handle process){
Assert(demon_primary_thread);
B32 result = 0;
DEMON_Entity *entity = demon_ent_ptr_from_handle(process);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Process){
result = demon_os_detach_process(entity);
}
return(result);
}
////////////////////////////////
//~ rjf: Entity Functions
//- rjf: basics
internal B32
demon_object_exists(DEMON_Handle object){
B32 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(object);
result = (entity != 0);
demon_access_end();
}
return(result);
}
//- rjf: introspection
internal Architecture
demon_arch_from_object(DEMON_Handle object){
Architecture result = Architecture_Null;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(object);
if (entity != 0){
result = (Architecture)entity->arch;
}
demon_access_end();
}
return(result);
}
internal U64
demon_base_vaddr_from_module(DEMON_Handle module){
U64 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(module);
if (entity != 0 && entity->kind == DEMON_EntityKind_Module){
result = entity->id;
}
demon_access_end();
}
return(result);
}
internal Rng1U64
demon_vaddr_range_from_module(DEMON_Handle module)
{
Rng1U64 result = {0};
if(demon_access_begin())
{
DEMON_Entity *entity = demon_ent_ptr_from_handle(module);
if(entity != 0 && entity->kind == DEMON_EntityKind_Module)
{
result = r1u64(entity->id, entity->id+entity->addr_range_dim);
}
demon_access_end();
}
return(result);
}
internal String8
demon_full_path_from_module(Arena *arena, DEMON_Handle module){
String8 result = {0};
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(module);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Module){
result = demon_accel_full_path_from_module(arena, entity);
}
demon_access_end();
}
return(result);
}
internal U64
demon_stack_base_vaddr_from_thread(DEMON_Handle thread){
U64 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(thread);
if (entity != 0 && entity->kind == DEMON_EntityKind_Thread){
result = demon_accel_stack_base_vaddr_from_thread(entity);
}
demon_access_end();
}
return(result);
}
internal U64
demon_tls_root_vaddr_from_thread(DEMON_Handle handle){
U64 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(handle);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Thread){
result = demon_accel_tls_root_vaddr_from_thread(entity);
}
demon_access_end();
}
return(result);
}
internal DEMON_HandleArray
demon_all_processes(Arena *arena){
DEMON_HandleArray result = {0};
if (demon_access_begin()){
DEMON_Handle *handles = push_array_no_zero(arena, DEMON_Handle, demon_proc_count);
DEMON_Handle *handle_opl = handles + demon_proc_count;
DEMON_Handle *handle_ptr = handles;
for (DEMON_Entity *process = demon_ent_root->first;
process != 0 && handle_ptr < handle_opl;
process = process->next){
if (process->kind == DEMON_EntityKind_Process){
*handle_ptr = demon_ent_handle_from_ptr(process);
handle_ptr += 1;
}
}
result.handles = handles;
result.count = (U64)(handle_ptr - handles);
U64 unused_count = demon_proc_count - result.count;
arena_put_back(arena, sizeof(DEMON_Handle)*unused_count);
demon_access_end();
}
return(result);
}
internal DEMON_HandleArray
demon_threads_from_process(Arena *arena, DEMON_Handle process){
DEMON_HandleArray result = {0};
if (demon_access_begin()){
DEMON_Handle *handles = push_array_no_zero(arena, DEMON_Handle, demon_thread_count);
DEMON_Handle *handle_opl = handles + demon_thread_count;
DEMON_Handle *handle_ptr = handles;
DEMON_Entity *process_ptr = demon_ent_ptr_from_handle(process);
if (process_ptr != 0 && process_ptr->kind == DEMON_EntityKind_Process){
for (DEMON_Entity *thread = process_ptr->first;
thread != 0 && handle_ptr < handle_opl;
thread = thread->next){
if (thread->kind == DEMON_EntityKind_Thread){
*handle_ptr = demon_ent_handle_from_ptr(thread);
handle_ptr += 1;
}
}
}
result.handles = handles;
result.count = (U64)(handle_ptr - handles);
U64 unused_count = demon_thread_count - result.count;
arena_put_back(arena, sizeof(DEMON_Handle)*unused_count);
demon_access_end();
}
return(result);
}
internal DEMON_HandleArray
demon_modules_from_process(Arena *arena, DEMON_Handle process){
DEMON_HandleArray result = {0};
if (demon_access_begin()){
DEMON_Handle *handles = push_array_no_zero(arena, DEMON_Handle, demon_module_count);
DEMON_Handle *handle_opl = handles + demon_module_count;
DEMON_Handle *handle_ptr = handles;
DEMON_Entity *process_ptr = demon_ent_ptr_from_handle(process);
if (process_ptr != 0 && process_ptr->kind == DEMON_EntityKind_Process){
for (DEMON_Entity *module = process_ptr->first;
module != 0 && handle_ptr < handle_opl;
module = module->next){
if (module->kind == DEMON_EntityKind_Module){
*handle_ptr = demon_ent_handle_from_ptr(module);
handle_ptr += 1;
}
}
}
result.handles = handles;
result.count = (U64)(handle_ptr - handles);
U64 unused_count = demon_module_count - result.count;
arena_put_back(arena, sizeof(DEMON_Handle)*unused_count);
demon_access_end();
}
return(result);
}
//- rjf: target process memory allocation/protection
internal U64
demon_reserve_memory(DEMON_Handle process, U64 size){
U64 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(process);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Process){
result = demon_os_reserve_memory(entity, size);
}
demon_access_end();
}
return(result);
}
internal B32
demon_set_memory_protect_flags(DEMON_Handle process, U64 page_vaddr, U64 size, DEMON_MemoryProtectFlags flags){
B32 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(process);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Process){
demon_os_set_memory_protect_flags(entity, page_vaddr, size, flags);
result = 1;
}
demon_access_end();
}
return(result);
}
internal B32
demon_release_memory(DEMON_Handle process, U64 vaddr, U64 size){
B32 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(process);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Process){
demon_os_release_memory(entity, vaddr, size);
result = 1;
}
demon_access_end();
}
return(result);
}
//- rjf: target process memory reading/writing
internal U64
demon_read_memory(DEMON_Handle process, void *dst, U64 src_address, U64 size){
U64 bytes_read = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(process);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Process){
bytes_read = demon_os_read_memory(entity, dst, src_address, size);
}
demon_access_end();
}
return(bytes_read);
}
internal B32
demon_write_memory(DEMON_Handle process, U64 dst_address, void *src, U64 size){
B32 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(process);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Process){
result = demon_os_write_memory(entity, dst_address, src, size);
}
demon_access_end();
}
return(result);
}
#define READ_BLOCK_SIZE 4096
internal U64
demon_read_memory_amap_aligned(DEMON_Handle process, void *dst, U64 src_address, U64 size){
// Algorithm:
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ^ ^ ^
// MIN MAX SMAX
// [MIN,MAX) - range attempting to read
// [MAX,SMAX) - range not yet proven to be impossible to read
Assert(src_address%READ_BLOCK_SIZE == 0);
Assert(size%READ_BLOCK_SIZE == 0);
U64 read_size = 0;
U64 min = 0;
U64 max = size;
U64 smax = max;
for (;;){
if (max <= min){
break;
}
// attempt to read range
U64 attempt_size = max - min;
B32 success = demon_read_memory(process, (U8*)dst + min, src_address + min, attempt_size);
if (success){
// increase successful read size
read_size += attempt_size;
// adjust range up
min = max;
max = smax;
}
else{
// mark this point as too far
smax = max - READ_BLOCK_SIZE;
// bisect the range for the next read attempt
U64 mid = (min + max)/2;
U64 aligned_mid = AlignDownPow2(mid, READ_BLOCK_SIZE);
max = aligned_mid;
}
}
U64 result = read_size;
return(result);
}
internal U64
demon_read_memory_amap(DEMON_Handle process, void *dst, U64 src_address, U64 size){
U64 read_size = 0;
if (demon_access_begin()){
B32 done = 0;
U64 read_opl = src_address + size;
// pre-aligned part -- [SRC,PRE_OPL)
U64 src_block_opl = AlignPow2(src_address, READ_BLOCK_SIZE);
U64 pre_opl = Min(src_block_opl, read_opl);
if(src_address < pre_opl)
{
U64 attempt_size = pre_opl - src_address;
if(!demon_read_memory(process, dst, src_address, attempt_size))
{
done = 1;
}
else
{
read_size += attempt_size;
}
}
// aligned part -- [PRE_OPL,POST_FIRST)
U64 read_opl_block_base = AlignDownPow2(read_opl, READ_BLOCK_SIZE);
U64 post_first = Max(read_opl_block_base, pre_opl);
if (!done && pre_opl < post_first){
U64 off = pre_opl - src_address;
U64 attempt_size = post_first - pre_opl;
U64 actual_size = demon_read_memory_amap_aligned(process, (U8*)dst + off,
pre_opl, attempt_size);
read_size += actual_size;
if (actual_size < attempt_size){
done = 1;
}
}
// post-aligned part -- [POST_FIRST,READ_OPL)
if (!done && post_first < read_opl){
U64 off = post_first - src_address;
U64 attempt_size = read_opl - post_first;
if (!demon_read_memory(process, (U8*)dst + off, post_first, attempt_size)){
done = 1;
}
else
{
read_size += attempt_size;
}
}
demon_access_end();
}
U64 result = read_size;
return(result);
}
#undef READ_BLOCK_SIZE
//- rjf: thread registers reading/writing
internal void*
demon_read_regs(DEMON_Handle thread){
void *result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(thread);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Thread){
result = demon_accel_read_regs(entity);
}
demon_access_end();
}
return(result);
}
internal B32
demon_write_regs(DEMON_Handle thread, void *data){
B32 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(thread);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Thread){
demon_accel_write_regs(entity, data);
result = 1;
}
demon_access_end();
}
return(result);
}
internal U64
demon_read_ip(DEMON_Handle thread){
U64 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(thread);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Thread){
void *regs = demon_accel_read_regs(entity);
result = regs_rip_from_arch_block((Architecture)entity->arch, regs);
}
demon_access_end();
}
return(result);
}
internal U64
demon_read_sp(DEMON_Handle thread){
U64 result = 0;
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(thread);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Thread){
void *regs = demon_accel_read_regs(entity);
result = regs_rsp_from_arch_block((Architecture)entity->arch, regs);
}
demon_access_end();
}
return(result);
}
internal void
demon_write_ip(DEMON_Handle thread, U64 ip){
if (demon_access_begin()){
DEMON_Entity *entity = demon_ent_ptr_from_handle(thread);
if (entity != 0 &&
entity->kind == DEMON_EntityKind_Thread){
void *regs = demon_accel_read_regs(entity);
regs_arch_block_write_rip((Architecture)entity->arch, regs, ip);
demon_accel_write_regs(entity, regs);
}
demon_access_end();
}
}
////////////////////////////////
//~ rjf: Process Listing
internal void
demon_proc_iter_begin(DEMON_ProcessIter *iter){
demon_os_proc_iter_begin(iter);
}
internal B32
demon_proc_iter_next(Arena *arena, DEMON_ProcessIter *iter, DEMON_ProcessInfo *info_out){
return(demon_os_proc_iter_next(arena, iter, info_out));
}
internal void
demon_proc_iter_end(DEMON_ProcessIter *iter){
demon_os_proc_iter_end(iter);
}
+293
View File
@@ -0,0 +1,293 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_CORE_H
#define DEMON_CORE_H
////////////////////////////////
//~ allen: Demon Low Level Entities
typedef U64 DEMON_Handle;
typedef struct DEMON_HandleNode DEMON_HandleNode;
struct DEMON_HandleNode
{
DEMON_HandleNode *next;
DEMON_Handle v;
};
typedef struct DEMON_HandleList DEMON_HandleList;
struct DEMON_HandleList
{
DEMON_HandleNode *first;
DEMON_HandleNode *last;
U64 count;
};
typedef struct DEMON_HandleArray DEMON_HandleArray;
struct DEMON_HandleArray
{
DEMON_Handle *handles;
U64 count;
};
////////////////////////////////
//~ rjf: Memory Protection Flags
typedef U32 DEMON_MemoryProtectFlags;
enum{
DEMON_MemoryProtectFlag_Read = (1<<0),
DEMON_MemoryProtectFlag_Write = (1<<1),
DEMON_MemoryProtectFlag_Execute = (1<<2),
};
////////////////////////////////
//~ allen: Demon Event Types
typedef enum DEMON_EventKind
{
DEMON_EventKind_Null,
DEMON_EventKind_Error,
DEMON_EventKind_HandshakeComplete,
DEMON_EventKind_CreateProcess,
DEMON_EventKind_ExitProcess,
DEMON_EventKind_CreateThread,
DEMON_EventKind_ExitThread,
DEMON_EventKind_LoadModule,
DEMON_EventKind_UnloadModule,
DEMON_EventKind_Breakpoint,
DEMON_EventKind_Trap,
DEMON_EventKind_SingleStep,
DEMON_EventKind_Exception,
DEMON_EventKind_Halt,
DEMON_EventKind_Memory,
DEMON_EventKind_DebugString,
DEMON_EventKind_SetThreadName,
DEMON_EventKind_COUNT
}
DEMON_EventKind;
typedef enum DEMON_ErrorKind
{
DEMON_ErrorKind_Null,
DEMON_ErrorKind_NotInitialized,
DEMON_ErrorKind_NotAttached,
DEMON_ErrorKind_UnexpectedFailure,
DEMON_ErrorKind_InvalidHandle,
}
DEMON_ErrorKind;
typedef enum DEMON_MemoryEventKind
{
DEMON_MemoryEventKind_Null,
DEMON_MemoryEventKind_Commit,
DEMON_MemoryEventKind_Reserve,
DEMON_MemoryEventKind_Decommit,
DEMON_MemoryEventKind_Release,
DEMON_MemoryEventKind_COUNT
}
DEMON_MemoryEventKind;
typedef enum DEMON_ExceptionKind
{
DEMON_ExceptionKind_Null,
DEMON_ExceptionKind_MemoryRead,
DEMON_ExceptionKind_MemoryWrite,
DEMON_ExceptionKind_MemoryExecute,
DEMON_ExceptionKind_CppThrow,
DEMON_ExceptionKind_COUNT
}
DEMON_ExceptionKind;
typedef struct DEMON_Event DEMON_Event;
struct DEMON_Event
{
// TODO(allen): condense
DEMON_EventKind kind;
DEMON_ErrorKind error_kind;
DEMON_MemoryEventKind memory_kind;
DEMON_ExceptionKind exception_kind;
DEMON_Handle process;
DEMON_Handle thread;
DEMON_Handle module;
U64 address;
U64 size;
String8 string;
U32 code; // code gives pid & tid on CreateProcess and CreateThread (respectfully)
U32 flags;
S32 signo;
S32 sigcode;
U64 instruction_pointer;
U64 stack_pointer;
U64 user_data;
B32 exception_repeated;
};
typedef struct DEMON_EventNode DEMON_EventNode;
struct DEMON_EventNode
{
DEMON_EventNode *next;
DEMON_Event v;
};
typedef struct DEMON_EventList DEMON_EventList;
struct DEMON_EventList
{
DEMON_EventNode *first;
DEMON_EventNode *last;
U64 count;
};
////////////////////////////////
//~ allen: Demon Run Control Types
typedef struct DEMON_Trap DEMON_Trap;
struct DEMON_Trap
{
DEMON_Handle process;
U64 address;
U64 id;
};
typedef struct DEMON_TrapChunkNode DEMON_TrapChunkNode;
struct DEMON_TrapChunkNode
{
DEMON_TrapChunkNode *next;
DEMON_Trap *v;
U64 cap;
U64 count;
};
typedef struct DEMON_TrapChunkList DEMON_TrapChunkList;
struct DEMON_TrapChunkList
{
DEMON_TrapChunkNode *first;
DEMON_TrapChunkNode *last;
U64 node_count;
U64 trap_count;
};
typedef struct DEMON_RunCtrls DEMON_RunCtrls;
struct DEMON_RunCtrls
{
DEMON_Handle single_step_thread;
B8 ignore_previous_exception;
B8 run_entities_are_unfrozen;
B8 run_entities_are_processes;
DEMON_Handle *run_entities;
U64 run_entity_count;
DEMON_TrapChunkList traps;
};
////////////////////////////////
//~ allen: Demon Process Listing
typedef struct DEMON_ProcessIter DEMON_ProcessIter;
struct DEMON_ProcessIter
{
U64 v[2];
};
typedef struct DEMON_ProcessInfo DEMON_ProcessInfo;
struct DEMON_ProcessInfo
{
String8 name;
U32 pid;
};
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void demon_init(void);
////////////////////////////////
//~ rjf: Basic Type Functions
//- rjf: stringizing
internal String8 demon_string_from_event_kind(DEMON_EventKind kind);
internal String8 demon_string_from_memory_event_kind(DEMON_MemoryEventKind kind);
internal String8 demon_string_from_exception_kind(DEMON_ExceptionKind kind);
internal void demon_string_list_from_event(Arena *arena, String8List *out, DEMON_Event *event);
//- rjf: trap chunk lists
internal void demon_trap_chunk_list_push(Arena *arena, DEMON_TrapChunkList *list, U64 cap, DEMON_Trap *trap);
internal void demon_trap_chunk_list_concat_in_place(DEMON_TrapChunkList *dst, DEMON_TrapChunkList *to_push);
internal void demon_trap_chunk_list_concat_shallow_copy(Arena *arena, DEMON_TrapChunkList *dst, DEMON_TrapChunkList *to_push);
//- rjf: handle lists
internal void demon_handle_list_push(Arena *arena, DEMON_HandleList *list, DEMON_Handle handle);
internal DEMON_HandleArray demon_handle_array_from_list(Arena *arena, DEMON_HandleList *list);
internal DEMON_HandleArray demon_handle_array_copy(Arena *arena, DEMON_HandleArray *src);
////////////////////////////////
//~ rjf: Primary Thread & Exclusive Mode Controls
internal void demon_primary_thread_begin(void);
internal void demon_exclusive_mode_begin(void);
internal void demon_exclusive_mode_end(void);
////////////////////////////////
//~ rjf: Running/Halting
internal DEMON_EventList demon_run(Arena *arena, DEMON_RunCtrls *ctrls);
internal void demon_halt(U64 code, U64 user_data);
internal U64 demon_get_time_counter(void);
////////////////////////////////
//~ rjf: Target Process Launching/Attaching/Killing/Detaching/Halting
internal U32 demon_launch_process(OS_LaunchOptions *options);
internal B32 demon_attach_process(U32 pid);
internal B32 demon_kill_process(DEMON_Handle process, U32 exit_code);
internal B32 demon_detach_process(DEMON_Handle process);
////////////////////////////////
//~ rjf: Entity Functions
//- rjf: basics
internal B32 demon_object_exists(DEMON_Handle object);
//- rjf: introspection
internal Architecture demon_arch_from_object(DEMON_Handle object);
internal U64 demon_base_vaddr_from_module(DEMON_Handle module);
internal Rng1U64 demon_vaddr_range_from_module(DEMON_Handle module);
internal String8 demon_full_path_from_module(Arena *arena, DEMON_Handle module);
internal U64 demon_stack_base_vaddr_from_thread(DEMON_Handle thread);
internal U64 demon_tls_root_vaddr_from_thread(DEMON_Handle thread);
internal DEMON_HandleArray demon_all_processes(Arena *arena);
internal DEMON_HandleArray demon_threads_from_process(Arena *arena, DEMON_Handle process);
internal DEMON_HandleArray demon_modules_from_process(Arena *arena, DEMON_Handle process);
//- rjf: target process memory allocation/protection
internal U64 demon_reserve_memory(DEMON_Handle process, U64 size);
internal B32 demon_set_memory_protect_flags(DEMON_Handle process, U64 page_vaddr, U64 size, DEMON_MemoryProtectFlags flags);
internal B32 demon_release_memory(DEMON_Handle process, U64 vaddr, U64 size);
//- rjf: target process memory reading/writing
internal U64 demon_read_memory(DEMON_Handle process, void *dst, U64 src_address, U64 size);
internal B32 demon_write_memory(DEMON_Handle process, U64 dst_address, void *src, U64 size);
internal U64 demon_read_memory_amap_aligned(DEMON_Handle process, void *dst, U64 src_address, U64 size);
internal U64 demon_read_memory_amap(DEMON_Handle process, void *dst, U64 src_address, U64 size);
//- rjf: thread registers reading/writing
// IMPORTANT(allen): This API is _trusting_ you. You should never modify the data pointed
// at by that void pointer! It is pointing to the internal cache of the registers, so it
// will become invalid after a call to demon_write_regs, or demon_run. Use it to read
// what you need and be done ASAP and we can avoid an extra copy baked into the API.
internal void *demon_read_regs(DEMON_Handle thread);
internal B32 demon_write_regs(DEMON_Handle thread, void *data);
// TODO(allen): These might be a bad idea when we try to extend to ARM
// They make sense for x86/x64 abstraction, which often needs identical
// code paths except for these parts. Revisit this when ARM is integrated.
internal U64 demon_read_ip(DEMON_Handle thread);
internal U64 demon_read_sp(DEMON_Handle thread);
internal void demon_write_ip(DEMON_Handle thread, U64 ip);
////////////////////////////////
//~ rjf: Process Listing
internal void demon_proc_iter_begin(DEMON_ProcessIter *iter);
internal B32 demon_proc_iter_next(Arena *arena, DEMON_ProcessIter *iter, DEMON_ProcessInfo *info_out);
internal void demon_proc_iter_end(DEMON_ProcessIter *iter);
#endif //DEMON_CORE_H
+14
View File
@@ -0,0 +1,14 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "demon_core.c"
#include "demon_common.c"
#include "demon_accel.c"
#if OS_WINDOWS
# include "win32/demon_os_win32.c"
#elif OS_LINUX
# include "linux/demon_os_linux.c"
#else
# error No Demon Implementation for This OS
#endif
+20
View File
@@ -0,0 +1,20 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_INC_H
#define DEMON_INC_H
#include "demon_core.h"
#include "demon_common.h"
#include "demon_accel.h"
#include "demon_os.h"
#if OS_WINDOWS
# include "win32/demon_os_win32.h"
#elif OS_LINUX
# include "linux/demon_os_linux.h"
#else
# error No Demon Implementation for This OS
#endif
#endif //DEMON_INC_H
+92
View File
@@ -0,0 +1,92 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_OS_H
#define DEMON_OS_H
// NOTE(allen):
// These are the functions that the OS backends actually implement.
// Demon objects go through a handle validation layer but it is a lot more
// convenient in the OS backends to implement these versions which take the
// already validated DEMON_Entity*. These are also more convenient to call from
// the backend layer, which lets us avoid converting back and forth between
// handles and pointers a lot.
////////////////////////////////
//~ NOTE(allen): Demon OS Run Control Types
typedef struct DEMON_OS_Trap DEMON_OS_Trap;
struct DEMON_OS_Trap
{
DEMON_Entity *process;
U64 address;
};
typedef struct DEMON_OS_RunCtrls DEMON_OS_RunCtrls;
struct DEMON_OS_RunCtrls
{
DEMON_Entity *single_step_thread;
B8 ignore_previous_exception;
B8 run_entities_are_unfrozen;
B8 run_entities_are_processes;
DEMON_Entity **run_entities;
U64 run_entity_count;
DEMON_OS_Trap *traps;
U64 trap_count;
};
////////////////////////////////
//~ rjf: @demon_os_hooks Main Layer Initialization
internal void demon_os_init(void);
////////////////////////////////
//~ rjf: @demon_os_hooks Running/Halting
internal DEMON_EventList demon_os_run(Arena *arena, DEMON_OS_RunCtrls *controls);
internal void demon_os_halt(U64 code, U64 user_data);
////////////////////////////////
//~ rjf: @demon_os_hooks Target Process Launching/Attaching/Killing/Detaching/Halting
internal U32 demon_os_launch_process(OS_LaunchOptions *options);
internal B32 demon_os_attach_process(U32 pid);
internal B32 demon_os_kill_process(DEMON_Entity *process, U32 exit_code);
internal B32 demon_os_detach_process(DEMON_Entity *process);
////////////////////////////////
//~ rjf: @demon_os_hooks Entity Functions
//- rjf: cleanup
internal void demon_os_entity_cleanup(DEMON_Entity *entity);
//- rjf: introspection
internal String8 demon_os_full_path_from_module(Arena *arena, DEMON_Entity *module);
internal U64 demon_os_stack_base_vaddr_from_thread(DEMON_Entity *thread);
internal U64 demon_os_tls_root_vaddr_from_thread(DEMON_Entity *thread);
//- rjf: target process memory allocation/protection
internal U64 demon_os_reserve_memory(DEMON_Entity *process, U64 size);
internal void demon_os_set_memory_protect_flags(DEMON_Entity *process, U64 page_vaddr, U64 size, DEMON_MemoryProtectFlags flags);
internal void demon_os_release_memory(DEMON_Entity *process, U64 vaddr, U64 size);
//- rjf: target process memory reading/writing
internal U64 demon_os_read_memory(DEMON_Entity *process, void *dst, U64 src_address, U64 size);
internal B32 demon_os_write_memory(DEMON_Entity *process, U64 dst_address, void *src, U64 size);
#define demon_os_read_struct(p,dst,src) demon_os_read_memory((p), (dst), (src), sizeof(*(dst)))
#define demon_os_write_struct(p,dst,src) demon_os_write_memory((p), (dst), (src), sizeof(*(src)))
//- rjf: thread registers reading/writing
internal B32 demon_os_read_regs_x86(DEMON_Entity *thread, REGS_RegBlockX86 *dst);
internal B32 demon_os_write_regs_x86(DEMON_Entity *thread, REGS_RegBlockX86 *src);
internal B32 demon_os_read_regs_x64(DEMON_Entity *thread, REGS_RegBlockX64 *dst);
internal B32 demon_os_write_regs_x64(DEMON_Entity *thread, REGS_RegBlockX64 *src);
////////////////////////////////
//~ rjf: @demon_os_hooks Process Listing
internal void demon_os_proc_iter_begin(DEMON_ProcessIter *iter);
internal B32 demon_os_proc_iter_next(Arena *arena, DEMON_ProcessIter *iter, DEMON_ProcessInfo *info_out);
internal void demon_os_proc_iter_end(DEMON_ProcessIter *iter);
#endif //DEMON_OS_H
File diff suppressed because it is too large Load Diff
+222
View File
@@ -0,0 +1,222 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_OS_LINUX_H
#define DEMON_OS_LINUX_H
// TODO(allen): Potential Upgrades:
//
// memory fd upgrade - Right now for each process we hold open a file
// descriptor for the process's memory (/proc/%d/mem) for the entire lifetime
// of the process; it could be opened and closed with some kind of LRU cache
// to put a finite cap on the number of handles the demon holds
//
////////////////////////////////
//~ NOTE(allen): Get The Linux Includes
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <elf.h>
#include <dirent.h>
#include <errno.h>
////////////////////////////////
//~ NOTE(allen): Linux Demon Types
//- entities
// Demon Linux Entity Extensions
// Process: ext_u64 set to memory file descriptor
// Thread : ext_u64 cast to DEMON_LNX_ThreadExt
// Module : ext_u64 set to U64 (address of name)
struct DEMON_LNX_ThreadExt{
B32 expecting_dummy_sigstop;
};
StaticAssert(sizeof(DEMON_LNX_ThreadExt) <= sizeof(Member(DEMON_Entity, ext_u64)), check_demon_lnx_thread_ext);
//- helpers
struct DEMON_LNX_AttachNode{
DEMON_LNX_AttachNode *next;
pid_t pid;
};
struct DEMON_LNX_ProcessAux{
B32 filled;
U64 phnum;
U64 phent;
U64 phdr;
U64 execfn;
};
struct DEMON_LNX_PhdrInfo{
Rng1U64 range;
U64 dynamic;
};
struct DEMON_LNX_ModuleNode{
DEMON_LNX_ModuleNode *next;
U64 vaddr;
U64 size;
U64 name;
U64 already_known;
};
struct DEMON_LNX_EntityNode{
DEMON_LNX_EntityNode *next;
DEMON_Entity *entity;
};
////////////////////////////////
//~ NOTE(allen): Linux Demon Register Layouts
// these are defined in <sys/user.h> but only for one architecture at a time
// (and we can't really trick it into giving us both in any obvious way)
// we define them here so that we have them all "at once"
struct DEMON_LNX_UserRegsX64{
U64 r15;
U64 r14;
U64 r13;
U64 r12;
U64 rbp;
U64 rbx;
U64 r11;
U64 r10;
U64 r9;
U64 r8;
U64 rax;
U64 rcx;
U64 rdx;
U64 rsi;
U64 rdi;
U64 orig_rax;
U64 rip;
U64 cs;
U64 rflags;
U64 rsp;
U64 ss;
U64 fsbase;
U64 gsbase;
U64 ds;
U64 es;
U64 fs;
U64 gs;
};
struct DEMON_LNX_UserX64{
DEMON_LNX_UserRegsX64 regs;
S32 u_fpvalid, _pad0;
SYMS_XSaveLegacy i387;
U64 u_tsize, u_dsize, u_ssize, start_code, start_stack;
U64 signal;
S32 reserved, _pad1;
U64 u_ar0, u_fpstate;
U64 magic;
U8 u_comm[32];
U64 u_debugreg[8];
};
struct DEMON_LNX_UserRegsX86{
U32 ebx;
U32 ecx;
U32 edx;
U32 esi;
U32 edi;
U32 ebp;
U32 eax;
U32 ds;
U32 es;
U32 fs;
U32 gs;
U32 orig_eax;
U32 eip;
U32 cs;
U32 eflags;
U32 sp;
U32 ss;
};
struct DEMON_LNX_UserX86{
DEMON_LNX_UserRegsX86 regs;
S32 u_fpvalid;
SYMS_FSave i387;
U32 u_tsize, u_dsize, u_ssize, start_code, start_stack;
S32 signal, reserved;
U32 u_ar0, u_fpstate;
U32 magic;
U8 u_comm[32];
U32 u_debugreg[8];
};
////////////////////////////////
enum
{
DEMON_LNX_PermFlags_Read = (1 << 0),
DEMON_LNX_PermFlags_Write = (1 << 1),
DEMON_LNX_PermFlags_Exec = (1 << 2),
DEMON_LNX_PermFlags_Private = (1 << 3)
};
typedef int DEMON_LNX_PermFlags;
enum
{
DEMON_LNX_MapsEntryType_Null,
DEMON_LNX_MapsEntryType_Path,
DEMON_LNX_MapsEntryType_Heap,
DEMON_LNX_MapsEntryType_Stack,
DEMON_LNX_MapsEntryType_VDSO,
};
typedef int DEMON_LNX_MapsEntryType;
struct DEMON_LNX_MapsEntry
{
U64 address_lo;
U64 address_hi;
DEMON_LNX_PermFlags perms;
U64 offset;
U32 dev_major;
U32 dev_minor;
U64 inode;
String8 pathname;
DEMON_LNX_MapsEntryType type;
pid_t stack_tid;
};
////////////////////////////////
//~ rjf: Helpers
internal DEMON_LNX_ThreadExt* demon_lnx_thread_ext(DEMON_Entity *entity);
internal B32 demon_lnx_attach_pid(Arena *arena, pid_t pid, DEMON_LNX_AttachNode **new_node);
internal String8 demon_lnx_executable_path_from_pid(Arena *arena, pid_t pid);
internal int demon_lnx_open_memory_fd_for_pid(pid_t pid);
internal Architecture demon_lnx_arch_from_pid(pid_t pid);
internal DEMON_LNX_ProcessAux demon_lnx_aux_from_pid(pid_t pid, Architecture arch);
internal DEMON_LNX_PhdrInfo demon_lnx_phdr_info_from_memory(int memory_fd, B32 is_32bit,
U64 phvaddr, U64 phstride, U64 phcount);
internal DEMON_LNX_ModuleNode* demon_lnx_module_list_from_process(Arena *arena, DEMON_Entity *process);
internal U64 demon_lnx_read_memory(int memory_fd, void *dst, U64 src, U64 size);
internal B32 demon_lnx_write_memory(int memory_fd, U64 dst, void *src, U64 size);
internal String8 demon_lnx_read_memory_str(Arena *arena, int memory_fd, U64 address);
internal void demon_lnx_regs_x64_from_usr_regs_x64(SYMS_RegX64 *dst, DEMON_LNX_UserRegsX64 *src);
internal void demon_lnx_usr_regs_x64_from_regs_x64(DEMON_LNX_UserRegsX64 *dst, SYMS_RegX64 *src);
internal String8 demon_lnx_read_int_string(int fd);
internal B32 demon_lnx_read_expect(int fd, char expect);
internal int demon_lnx_read_whitespace(int fd);
internal String8 demon_lnx_read_string(Arena *arena, int fd);
internal int demon_lnx_open_maps(pid_t pid);
internal B32 demon_lnx_next_map(Arena *arena, int maps, DEMON_LNX_MapsEntry *entry_out);
#endif //DEMON_OS_LINUX_H
+65
View File
@@ -0,0 +1,65 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
// exe //
#include "base/base_inc.h"
#include "os/os_inc.h"
#include "demon/demon_inc.h"
#include "syms_helpers/syms_internal_overrides.h"
#include "syms/syms_inc.h"
#include "syms_helpers/syms_helpers.h"
#include "base/base_inc.c"
#include "os/os_inc.c"
#include "demon/demon_inc.c"
#include "syms_helpers/syms_internal_overrides.c"
#include "syms/syms_inc.c"
#include "syms_helpers/syms_helpers.c"
int
main(int argument_count, char **arguments)
{
os_init(argument_count, arguments);
Arena *arena = arena_alloc();
demon_init();
//- rjf: find PID of mule_loop.exe
String8 attach_process_name = str8_lit("mule_loop.exe");
U32 pid = 0;
{
DEMON_ProcessIter it = {0};
demon_proc_iter_begin(&it);
for(DEMON_ProcessInfo info = {0}; demon_proc_iter_next(arena, &it, &info);)
{
if(str8_match(info.name, attach_process_name, 0))
{
pid = info.pid;
break;
}
}
demon_proc_iter_end(&it);
}
//- rjf: attach
B32 attach_good = demon_attach_process(pid);
//- rjf: get events
DEMON_RunCtrls ctrls = {0};
DEMON_EventList events = demon_run(arena, ctrls);
for(DEMON_Event *event = events.first; event != 0; event = event->next)
{
int x = 0;
}
#if 0
//- rjf: try to break in the loop
DEMON_RunCtrls ctrls = {0};
DEMON_Trap trap = {0};
{
U64 loop_bp = 0x0000000140001074;
ctrls.trap_count = 1;
ctrls.traps = &trap;
}
#endif
}
+166
View File
@@ -0,0 +1,166 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "base/base_inc.h"
#include "os/os_inc.h"
#include "demon/demon_inc.h"
#include "syms_helpers/syms_internal_overrides.h"
#include "syms/syms_inc.h"
#include "syms_helpers/syms_helpers.h"
#include "base/base_inc.c"
#include "os/os_inc.c"
#include "demon/demon_inc.c"
#include "syms_helpers/syms_internal_overrides.c"
#include "syms/syms_inc.c"
#include "syms_helpers/syms_helpers.c"
internal SYMS_String8
file_load_func_for_syms(void *user, SYMS_Arena *arena, SYMS_String8 file_name){
String8 data = os_read_file(arena, str8_from_syms(file_name));
SYMS_String8 result = syms_from_str8(data);
return(result);
}
int
main(int argument_count, char **arguments)
{
os_init(argument_count, arguments);
Temp scratch = scratch_begin(0, 0);
// setup
demon_init();
// parse arguments
String8 executable_file_name = {0};
U64 bp_address = 0;
{
String8List command_line_arguments = os_get_command_line_arguments();
CmdLine cmd_line = cmd_line_from_string_list(scratch.arena, command_line_arguments);
if (cmd_line.inputs.first != 0){
executable_file_name = cmd_line.inputs.first->string;
}
String8 bp_string = cmd_line_string(cmd_line, str8_lit("bp"));
try_u64_from_str8_c_rules(bp_string, &bp_address);
}
// check parameters
if (bp_address == 0 || executable_file_name.size == 0){
printf("bad parameters\n");
exit(0);
}
// demon launch
OS_LaunchOptions launch_opts = {0};
str8_list_push(scratch.arena, &launch_opts.cmd_line, executable_file_name);
launch_opts.path = os_get_path(scratch.arena, OS_SystemPath_Current);
U32 process_id = demon_launch_process(&launch_opts);
if (process_id == 0){
printf("could not launch: '%.*s'\n", str8_varg(executable_file_name));
exit(0);
}
// demon loop
{
DEMON_Handle process = 0;
DEMON_Handle thread = 0;
B32 hit_bp = false;
U64 single_step_counter = 0;
U64 counter = 0;
for (;;){
Temp temp = temp_begin(scratch.arena);
DEMON_RunCtrls run_controls = {0};
DEMON_Trap traps[1];
if (!hit_bp){
if (process != 0){
run_controls.trap_count = 1;
run_controls.traps = traps;
run_controls.traps[0].process = process;
run_controls.traps[0].address = bp_address;
}
}
else{
run_controls.single_step_thread = thread;
}
DEMON_EventList events = demon_run(temp.arena, run_controls);
for (DEMON_Event *event = events.first;
event != 0;
event = event->next, counter += 1){
// update tracking state
switch (event->kind){
case DEMON_EventKind_CreateProcess:
{
process = event->process;
}break;
case DEMON_EventKind_ExitProcess:
{
if (event->process == process){
process = 0;
}
}break;
case DEMON_EventKind_CreateThread:
{
thread = event->thread;
}break;
case DEMON_EventKind_Breakpoint:
{
hit_bp = true;
}break;
case DEMON_EventKind_SingleStep:
{
single_step_counter += 1;
SYMS_RegX64 regs1 = {0};
demon_read_x64_regs(thread, &regs1);
demon_write_x64_regs(thread, &regs1);
SYMS_RegX64 regs2 = {0};
demon_read_x64_regs(thread, &regs2);
if (!MemoryMatchStruct(&regs1, &regs2)){
printf("mismatch at single_step_counter=%llu\n", single_step_counter);
}
if (single_step_counter == 1000){
goto end_loop;
}
}break;
case DEMON_EventKind_NotAttached:
{
fprintf(stderr, "not attached - exiting\n");
goto end_loop;
}break;
case DEMON_EventKind_NotInitialized:
case DEMON_EventKind_UnexpectedFailure:
{
fprintf(stderr, "unexpected error - exiting\n");
goto end_loop;
}break;
}
}
goto end_it;
end_loop:
temp_end(temp);
goto loop_exit;
end_it:;
}
loop_exit:;
}
printf("[done]\n");
scratch_end(scratch);
}
+250
View File
@@ -0,0 +1,250 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "base/base_inc.h"
#include "os/os_inc.h"
#include "demon/demon_inc.h"
#include "syms_helpers/syms_internal_overrides.h"
#include "syms/syms_inc.h"
#include "syms_helpers/syms_helpers.h"
#include "base/base_inc.c"
#include "os/os_inc.c"
#include "demon/demon_inc.c"
#include "syms_helpers/syms_internal_overrides.c"
#include "syms/syms_inc.c"
#include "syms_helpers/syms_helpers.c"
internal SYMS_String8
file_load_func_for_syms(void *user, SYMS_Arena *arena, SYMS_String8 file_name){
String8 data = os_read_file(arena, str8_from_syms(file_name));
SYMS_String8 result = syms_from_str8(data);
return(result);
}
int
main(int argument_count, char **arguments)
{
os_init(argument_count, arguments);
demon_init();
String8Node node[2];
#define TARGET_EXE "C:\\devel\\projects\\debugger\\build\\mule_unwind_20210511_clang11_lldlink.exe"
OS_LaunchOptions options = {0};
#if OS_WINDOWS
str8_list_push(&options.cmd_line, &node[0], str8_lit(TARGET_EXE));
options.path = str8_lit("C:\\devel\\projects\\debugger\\build\\");
#else
str8_list_push(&options.cmd_line, &node[0], str8_lit("/home/allenw/projects_copy/debugger/build/mule_main"));
options.path = str8_lit("/home/allenw/projects_copy/debugger/build/");
#endif
U32 process_id = demon_launch_process(&options);
if (process_id == 0){
printf("Could not launch process\n");
exit(1);
}
#if OS_WINDOWS
U64 bp_addr = 0x140001134;
#else
U64 bp_addr = 0x400918;
#endif
DEMON_Handle process = 0;
DEMON_Handle thread = 0;
DEMON_Handle module = 0;
U64 module_base = 0;
SYMS_Group *group = 0;
B32 hit_bp = false;
U64 counter = 0;
for (;;){
DEMON_RunCtrls run_controls = {0};
DEMON_Trap trap_memory[2];
DEMON_Trap *trap_ptr = trap_memory;
if (process != 0 && !hit_bp){
trap_ptr->process = process;
trap_ptr->address = bp_addr;
trap_ptr += 1;
}
run_controls.traps = trap_memory;
run_controls.trap_count = (U64)(trap_ptr - trap_memory);
Temp scratch = scratch_begin(0, 0);
DEMON_EventList events = demon_run(scratch.arena, run_controls);
for (DEMON_Event *event = events.first;
event != 0;
event = event->next){
printf("STEP[%05llx] -- ", counter);
counter += 1;
switch (event->kind){
case DEMON_EventKind_NotInitialized:
{
printf("Not Initialized\n");
exit(1);
}break;
case DEMON_EventKind_NotAttached:
{
printf("Not Attached\n");
exit(1);
}break;
case DEMON_EventKind_UnexpectedFailure:
{
printf("Unexpected Failure\n");
exit(1);
}break;
case DEMON_EventKind_CreateProcess:
{
printf("Create Process\n");
if (process == 0){
process = event->process;
}
}break;
case DEMON_EventKind_CreateThread:
{
printf("Create Thread\n");
if (thread == 0){
thread = event->thread;
}
}break;
case DEMON_EventKind_LoadModule:
{
Temp temp = temp_begin(scratch.arena);
String8 file_name = demon_full_path_from_module(scratch.arena, event->module);
printf("Load Module: %.*s\n", str8_varg(file_name));
if (module == 0 && str8_match(file_name, str8_lit(TARGET_EXE), 0)){
module = event->module;
module_base = event->address;
// setup syms group
group = syms_group_alloc();
SYMS_FileLoadCtx ctx = {0};
ctx.file_load_func = file_load_func_for_syms;
SYMS_String8List file_names = {0};
syms_string_list_push(group->arena, &file_names, syms_from_str8(file_name));
SYMS_FileInfOptions opts = {0};
SYMS_FileInfResult inf_result = syms_file_inf_infer_from_file_list(group->arena, ctx, file_names, &opts);
syms_group_init(group, &inf_result.data_parsed);
}
temp_end(temp);
}break;
case DEMON_EventKind_ExitProcess:
{
printf("Exit Process\n");
exit(0);
}break;
case DEMON_EventKind_ExitThread:
{
printf("Exit Thread\n");
}break;
case DEMON_EventKind_UnloadModule:
{
printf("Unload Module\n");
}break;
case DEMON_EventKind_Breakpoint:
{
Architecture arch = demon_arch_from_object(event->process);
U64 ip = event->instruction_pointer;
printf("Breakpoint: %llx\n", ip);
hit_bp = true;
//- unwind
// setup bin
SYMS_String8 bin_data = group->bin_data;
SYMS_BinAccel *generic_bin = group->bin;
SYMS_PeBinAccel *pe_bin = 0;
if (generic_bin->format == SYMS_FileFormat_PE){
pe_bin = (SYMS_PeBinAccel*)generic_bin;
}
if (pe_bin != 0){
// read regs
SYMS_RegX64 regs = {0};
demon_read_x64_regs(event->thread, &regs);
// read stack
SYMS_U64 sp = regs.rsp.u64;
SYMS_U64 sp_rounded_down = sp&~(KB(4) - 1);
SYMS_String8 stack_memory = {0};
stack_memory.size = KB(8);
stack_memory.str = push_array_no_zero(scratch.arena, U8, stack_memory.size);
SYMS_U64 stack_memory_addr = sp_rounded_down;
stack_memory.size = demon_read_memory_amap(event->process, stack_memory.str,
stack_memory_addr, stack_memory.size);
// unwind loop
U64 counter = 1;
for (;; counter += 1){
printf("%02llu: ip=%llx; sp=%llx\n", counter, regs.rip.u64, regs.rsp.u64);
SYMS_MemoryView memview = syms_memory_view_make(stack_memory, stack_memory_addr);
SYMS_UnwindResult unwind_result = syms_unwind_pe_x64(bin_data, pe_bin, module_base, &memview, &regs);
if (unwind_result.dead){
break;
}
}
}
}break;
case DEMON_EventKind_Trap:
{
Architecture arch = demon_arch_from_object(event->process);
U64 ip = event->instruction_pointer;
printf("Trap: %llx\n", ip);
}break;
case DEMON_EventKind_SingleStep:
{
printf("Single Step: %llx\n", event->instruction_pointer);
}break;
case DEMON_EventKind_Exception:
{
printf("Exception: %llx\n", event->instruction_pointer);
}break;
case DEMON_EventKind_Halt:
{
printf("Halt\n");
}break;
case DEMON_EventKind_Memory:
{
printf("Memory\n");
}break;
default:
{
printf("Unhandled Event\n");
exit(1);
}break;
}
}
scratch_end(scratch);
}
printf("Done\n");
}
+935
View File
@@ -0,0 +1,935 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
// NOTE(rjf): (18 October 2021) Notes on Win32 process halting via
// DebugBreakProcess:
//
// Calling DebugBreakProcess seems to cause a few events to come back:
// 1. Thread Creation Event
// 2. Breakpoint Event (with the thread matching that of #1)
// 3. Thread Exiting Event (matching #1)
//
// Having done this experiment on a single-threaded program (mule_loop.exe),
// I can only infer that what is happening here is that when DebugBreakProcess
// is called, it first injects a thread into the target process that runs
// code with an int3. This is very similar to the old approach that Demon
// took.
//
// It's going to be difficult to distinguish between these CreateThreads and
// ExitThreads from others (not caused by halting), even though we can match
// the hit breakpoint to the associated thread.
//
// What could be possible (in order to distinguish the hit breakpoint as a
// halt event, instead of an arbitrary breakpoint) is looking at the breakpoint
// address. This injected thread has a breakpoint that's different from the
// initial breakpoint that the kernel automatically hits when a process is
// first being debugged.
//
// With DebugBreakProcess:
// - first breakpoint that is hit: 0x7ff8ad9806b0 in kernel code
// - last breakpoint that is hit: 0x7ff8ad950860 in kernel code (halt)
//
// Without DebugBreakProcess:
// - first breakpoint that is hit: 0x7ff8ad9806b0
//
// NOTE(rjf): (18 October 2021) Notes on suspending processes via
// NtSuspendProcess:
//
// NtSuspendProcess is an undocumented API that is exported by ntdll. It is
// fairly simple but could be unstable. To call it, the main trick is that
// you need a handle with certain privileges (PROCESS_SUSPEND_RESUME), so
// you can't just take any handle and use it.
//
// To use it, we can manually load it from ntdll, grab an elevated handle
// for a given process HANDLE, and then call it. We can resume, then, with
// NtResumeProcess.
//
// Other than this, our options seem to more-or-less lie in individually
// suspending all of the threads in the process-to-be-halted.
#include <windows.h>
#include "base/base_inc.h"
#include "os/os_inc.h"
#include "syms_helpers/syms_internal_overrides.h"
#include "syms/syms_inc.h"
#include "syms_helpers/syms_helpers.h"
#include "base/base_inc.c"
#include "os/os_inc.c"
#include "syms_helpers/syms_internal_overrides.c"
#include "syms/syms_inc.c"
#include "syms_helpers/syms_helpers.c"
typedef LONG NtSuspendProcessFunction(HANDLE ProcessHandle);
global NtSuspendProcessFunction *NtSuspendProcess = 0;
////////////////////////////////
// NOTE(allen): Win32 Demon Exceptions
#define DEMON_W32_EXCEPTION_BREAKPOINT 0x80000003u
#define DEMON_W32_EXCEPTION_SINGLE_STEP 0x80000004u
#define DEMON_W32_EXCEPTION_LONG_JUMP 0x80000026u
#define DEMON_W32_EXCEPTION_ACCESS_VIOLATION 0xC0000005u
#define DEMON_W32_EXCEPTION_ARRAY_BOUNDS_EXCEEDED 0xC000008Cu
#define DEMON_W32_EXCEPTION_DATA_TYPE_MISALIGNMENT 0x80000002u
#define DEMON_W32_EXCEPTION_GUARD_PAGE_VIOLATION 0x80000001u
#define DEMON_W32_EXCEPTION_FLT_DENORMAL_OPERAND 0xC000008Du
#define DEMON_W32_EXCEPTION_FLT_DEVIDE_BY_ZERO 0xC000008Eu
#define DEMON_W32_EXCEPTION_FLT_INEXACT_RESULT 0xC000008Fu
#define DEMON_W32_EXCEPTION_FLT_INVALID_OPERATION 0xC0000090u
#define DEMON_W32_EXCEPTION_FLT_OVERFLOW 0xC0000091u
#define DEMON_W32_EXCEPTION_FLT_STACK_CHECK 0xC0000092u
#define DEMON_W32_EXCEPTION_FLT_UNDERFLOW 0xC0000093u
#define DEMON_W32_EXCEPTION_INT_DIVIDE_BY_ZERO 0xC0000094u
#define DEMON_W32_EXCEPTION_INT_OVERFLOW 0xC0000095u
#define DEMON_W32_EXCEPTION_PRIVILEGED_INSTRUCTION 0xC0000096u
#define DEMON_W32_EXCEPTION_ILLEGAL_INSTRUCTION 0xC000001Du
#define DEMON_W32_EXCEPTION_IN_PAGE_ERROR 0xC0000006u
#define DEMON_W32_EXCEPTION_INVALID_DISPOSITION 0xC0000026u
#define DEMON_W32_EXCEPTION_NONCONTINUABLE 0xC0000025u
#define DEMON_W32_EXCEPTION_STACK_OVERFLOW 0xC00000FDu
#define DEMON_W32_EXCEPTION_INVALID_HANDLE 0xC0000008u
#define DEMON_W32_EXCEPTION_UNWIND_CONSOLIDATE 0x80000029u
#define DEMON_W32_EXCEPTION_DLL_NOT_FOUND 0xC0000135u
#define DEMON_W32_EXCEPTION_ORDINAL_NOT_FOUND 0xC0000138u
#define DEMON_W32_EXCEPTION_ENTRY_POINT_NOT_FOUND 0xC0000139u
#define DEMON_W32_EXCEPTION_DLL_INIT_FAILED 0xC0000142u
#define DEMON_W32_EXCEPTION_CONTROL_C_EXIT 0xC000013Au
#define DEMON_W32_EXCEPTION_FLT_MULTIPLE_FAULTS 0xC00002B4u
#define DEMON_W32_EXCEPTION_FLT_MULTIPLE_TRAPS 0xC00002B5u
#define DEMON_W32_EXCEPTION_NAT_CONSUMPTION 0xC00002C9u
#define DEMON_W32_EXCEPTION_HEAP_CORRUPTION 0xC0000374u
#define DEMON_W32_EXCEPTION_STACK_BUFFER_OVERRUN 0xC0000409u
#define DEMON_W32_EXCEPTION_INVALID_CRUNTIME_PARAM 0xC0000417u
#define DEMON_W32_EXCEPTION_ASSERT_FAILURE 0xC0000420u
#define DEMON_W32_EXCEPTION_NO_MEMORY 0xC0000017u
#define DEMON_W32_EXCEPTION_THROW 0xE06D7363u
////////////////////////////////
// NOTE(allen): Win32 Demon Register API Codes
#define DEMON_W32_CTX_X86 0x00010000
#define DEMON_W32_CTX_X64 0x00100000
#define DEMON_W32_CTX_INTEL_CONTROL 0x0001
#define DEMON_W32_CTX_INTEL_INTEGER 0x0002
#define DEMON_W32_CTX_INTEL_SEGMENTS 0x0004
#define DEMON_W32_CTX_INTEL_FLOATS 0x0008
#define DEMON_W32_CTX_INTEL_DEBUG 0x0010
#define DEMON_W32_CTX_INTEL_EXTENDED 0x0020
#define DEMON_W32_CTX_INTEL_XSTATE 0x0040
#define DEMON_W32_CTX_X86_ALL (DEMON_W32_CTX_X86 | \
DEMON_W32_CTX_INTEL_CONTROL | DEMON_W32_CTX_INTEL_INTEGER | \
DEMON_W32_CTX_INTEL_SEGMENTS | DEMON_W32_CTX_INTEL_DEBUG | \
DEMON_W32_CTX_INTEL_EXTENDED)
#define DEMON_W32_CTX_X64_ALL (DEMON_W32_CTX_X64 | \
DEMON_W32_CTX_INTEL_CONTROL | DEMON_W32_CTX_INTEL_INTEGER | \
DEMON_W32_CTX_INTEL_SEGMENTS | DEMON_W32_CTX_INTEL_FLOATS | \
DEMON_W32_CTX_INTEL_DEBUG)
struct TEST_DebugEvent
{
String8 name;
U64 process_id;
U64 thread_id;
HANDLE process;
HANDLE thread;
U64 addr;
DEBUG_EVENT evt;
};
struct TEST_Trap
{
HANDLE process;
U64 address;
};
internal U16
test_w32_real_tag_word_from_xsave(XSAVE_FORMAT *fxsave)
{
U16 result = 0;
U32 top = (fxsave->StatusWord >> 11) & 7;
for (U32 fpr = 0; fpr < 8; fpr += 1){
U32 tag = 3;
if (fxsave->TagWord & (1 << fpr)){
U32 st = (fpr - top)&7;
SYMS_Reg80 *fp = (SYMS_Reg80*)&fxsave->FloatRegisters[st*16];
U16 exponent = fp->sign1_exp15 & bitmask15;
U64 integer_part = fp->int1_frac63 >> 63;
U64 fraction_part = fp->int1_frac63 & bitmask63;
// tag: 0 - normal; 1 - zero; 2 - special
tag = 2;
if (exponent == 0){
if (integer_part == 0 && fraction_part == 0){
tag = 1;
}
}
else if (exponent != bitmask15 && integer_part != 0){
tag = 0;
}
}
result |= tag << (2 * fpr);
}
return(result);
}
internal U16
test_w32_xsave_tag_word_from_real_tag_word(U16 ftw)
{
U16 compact = 0;
for (U32 fpr = 0; fpr < 8; fpr++){
U32 tag = (ftw >> (fpr * 2)) & 3;
if (tag != 3){
compact |= (1 << fpr);
}
}
return(compact);
}
internal B32
test_w32_read_x64_regs(HANDLE thread, SYMS_RegX64 *dst)
{
Temp scratch = scratch_begin(0, 0);
// NOTE(allen): Check available features
U32 feature_mask = GetEnabledXStateFeatures();
B32 avx_enabled = !!(feature_mask & XSTATE_MASK_AVX);
// NOTE(allen): Setup the context
CONTEXT *ctx = 0;
U32 ctx_flags = DEMON_W32_CTX_X64_ALL;
if (avx_enabled){
ctx_flags |= DEMON_W32_CTX_INTEL_XSTATE;
}
DWORD size = 0;
InitializeContext(0, ctx_flags, 0, &size);
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER){
void *ctx_memory = push_array(scratch.arena, U8, size);
if (!InitializeContext(ctx_memory, ctx_flags, &ctx, &size)){
ctx = 0;
}
}
B32 avx_available = false;
if (ctx != 0){
// NOTE(allen): Finish Context Setup
if (avx_enabled){
SetXStateFeaturesMask(ctx, XSTATE_MASK_AVX);
}
// NOTE(allen): Determine what features are available on this particular ctx
// TODO(allen): Experiment carefully with this nonsense.
// Does avx_enabled = avx_available in all circumstances or not?
DWORD64 xstate_flags = 0;
if (GetXStateFeaturesMask(ctx, &xstate_flags)){
if (xstate_flags & XSTATE_MASK_AVX){
avx_available = true;
}
}
}
// get thread context
HANDLE thread_handle = thread;
if (!GetThreadContext(thread_handle, ctx)){
ctx = 0;
}
B32 result = false;
if (ctx != 0){
result = true;
// NOTE(allen): Convert CONTEXT -> SYMS_RegX64
dst->rax.u64 = ctx->Rax;
dst->rcx.u64 = ctx->Rcx;
dst->rdx.u64 = ctx->Rdx;
dst->rbx.u64 = ctx->Rbx;
dst->rsp.u64 = ctx->Rsp;
dst->rbp.u64 = ctx->Rbp;
dst->rsi.u64 = ctx->Rsi;
dst->rdi.u64 = ctx->Rdi;
dst->r8.u64 = ctx->R8;
dst->r9.u64 = ctx->R9;
dst->r10.u64 = ctx->R10;
dst->r11.u64 = ctx->R11;
dst->r12.u64 = ctx->R12;
dst->r13.u64 = ctx->R13;
dst->r14.u64 = ctx->R14;
dst->r15.u64 = ctx->R15;
dst->rip.u64 = ctx->Rip;
dst->cs.u16 = ctx->SegCs;
dst->ds.u16 = ctx->SegDs;
dst->es.u16 = ctx->SegEs;
dst->fs.u16 = ctx->SegFs;
dst->gs.u16 = ctx->SegGs;
dst->ss.u16 = ctx->SegSs;
dst->dr0.u32 = ctx->Dr0;
dst->dr1.u32 = ctx->Dr1;
dst->dr2.u32 = ctx->Dr2;
dst->dr3.u32 = ctx->Dr3;
dst->dr6.u32 = ctx->Dr6;
dst->dr7.u32 = ctx->Dr7;
// NOTE(allen): This bit is "supposed to always be 1" I guess.
// TODO(allen): Not sure what this is all about but I haven't investigated it yet.
// This might be totally not necessary or something.
dst->rflags.u64 = ctx->EFlags | 0x2;
XSAVE_FORMAT *xsave = &ctx->FltSave;
dst->fcw.u16 = xsave->ControlWord;
dst->fsw.u16 = xsave->StatusWord;
dst->ftw.u16 = test_w32_real_tag_word_from_xsave(xsave);
dst->fop.u16 = xsave->ErrorOpcode;
dst->fcs.u16 = xsave->ErrorSelector;
dst->fds.u16 = xsave->DataSelector;
dst->fip.u32 = xsave->ErrorOffset;
dst->fdp.u32 = xsave->DataOffset;
dst->mxcsr.u32 = xsave->MxCsr;
dst->mxcsr_mask.u32 = xsave->MxCsr_Mask;
M128A *float_s = xsave->FloatRegisters;
SYMS_Reg80 *float_d = &dst->fpr0;
for (U32 n = 0; n < 8; n += 1, float_s += 1, float_d += 1){
MemoryCopy(float_d, float_s, sizeof(*float_d));
}
if (!avx_available){
M128A *xmm_s = xsave->XmmRegisters;
SYMS_Reg256 *xmm_d = &dst->ymm0;
for (U32 n = 0; n < 16; n += 1, xmm_s += 1, xmm_d += 1){
MemoryCopy(xmm_d, xmm_s, sizeof(*xmm_s));
}
}
if (avx_available){
DWORD part0_length = 0;
M128A *part0 = (M128A*)LocateXStateFeature(ctx, XSTATE_LEGACY_SSE, &part0_length);
DWORD part1_length = 0;
M128A *part1 = (M128A*)LocateXStateFeature(ctx, XSTATE_AVX, &part1_length);
Assert(part0_length == part1_length);
DWORD count = part0_length/sizeof(part0[0]);
count = ClampTop(count, 16);
SYMS_Reg256 *ymm_d = &dst->ymm0;
for (DWORD i = 0;
i < count;
i += 1, part0 += 1, part1 += 1, ymm_d += 1){
// TODO(allen): Are we writing these out in the right order? Seems weird right?
ymm_d->u64[3] = part0->Low;
ymm_d->u64[2] = part0->High;
ymm_d->u64[1] = part1->Low;
ymm_d->u64[0] = part1->High;
}
}
}
scratch_end(scratch);
return(result);
}
internal B32
test_w32_write_x64_regs(HANDLE thread, SYMS_RegX64 *src)
{
Temp scratch = scratch_begin(0, 0);
// NOTE(allen): Check available features
U32 feature_mask = GetEnabledXStateFeatures();
B32 avx_enabled = !!(feature_mask & XSTATE_MASK_AVX);
// NOTE(allen): Setup the context
CONTEXT *ctx = 0;
U32 ctx_flags = DEMON_W32_CTX_X64_ALL;
if (avx_enabled){
ctx_flags |= DEMON_W32_CTX_INTEL_XSTATE;
}
DWORD size = 0;
InitializeContext(0, ctx_flags, 0, &size);
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER){
void *ctx_memory = push_array(scratch.arena, U8, size);
if (!InitializeContext(ctx_memory, ctx_flags, &ctx, &size)){
ctx = 0;
}
}
B32 avx_available = false;
if (ctx != 0){
// NOTE(allen): Finish Context Setup
if (avx_enabled){
SetXStateFeaturesMask(ctx, XSTATE_MASK_AVX);
}
// NOTE(allen): Determine what features are available on this particular ctx
// TODO(allen): Experiment carefully with this nonsense.
// Does avx_enabled = avx_available in all circumstances or not?
DWORD64 xstate_flags = 0;
if (GetXStateFeaturesMask(ctx, &xstate_flags)){
if (xstate_flags & XSTATE_MASK_AVX){
avx_available = true;
}
}
}
B32 result = false;
if (ctx != 0){
// NOTE(allen): Convert SYMS_RegX64 -> CONTEXT
ctx->ContextFlags = ctx_flags;
ctx->MxCsr = src->mxcsr.u32 & src->mxcsr_mask.u32;
ctx->Rax = src->rax.u64;
ctx->Rcx = src->rcx.u64;
ctx->Rdx = src->rdx.u64;
ctx->Rbx = src->rbx.u64;
ctx->Rsp = src->rsp.u64;
ctx->Rbp = src->rbp.u64;
ctx->Rsi = src->rsi.u64;
ctx->Rdi = src->rdi.u64;
ctx->R8 = src->r8.u64;
ctx->R9 = src->r9.u64;
ctx->R10 = src->r10.u64;
ctx->R11 = src->r11.u64;
ctx->R12 = src->r12.u64;
ctx->R13 = src->r13.u64;
ctx->R14 = src->r14.u64;
ctx->R15 = src->r15.u64;
ctx->Rip = src->rip.u64;
ctx->SegCs = src->cs.u16;
ctx->SegDs = src->ds.u16;
ctx->SegEs = src->es.u16;
ctx->SegFs = src->fs.u16;
ctx->SegGs = src->gs.u16;
ctx->SegSs = src->ss.u16;
ctx->Dr0 = src->dr0.u32;
ctx->Dr1 = src->dr1.u32;
ctx->Dr2 = src->dr2.u32;
ctx->Dr3 = src->dr3.u32;
ctx->Dr6 = src->dr6.u32;
ctx->Dr7 = src->dr7.u32;
ctx->EFlags = src->rflags.u64;
XSAVE_FORMAT *fxsave = &ctx->FltSave;
fxsave->ControlWord = src->fcw.u16;
fxsave->StatusWord = src->fsw.u16;
fxsave->TagWord = test_w32_xsave_tag_word_from_real_tag_word(src->ftw.u16);
fxsave->ErrorOpcode = src->fop.u16;
fxsave->ErrorSelector = src->fcs.u16;
fxsave->DataSelector = src->fds.u16;
fxsave->ErrorOffset = src->fip.u32;
fxsave->DataOffset = src->fdp.u32;
M128A *float_d = fxsave->FloatRegisters;
SYMS_Reg80 *float_s = &src->fpr0;
for (U32 n = 0;
n < 8;
n += 1, float_s += 1, float_d += 1){
MemoryCopy(float_d, float_s, 10);
}
if (!avx_available){
M128A *xmm_d = fxsave->XmmRegisters;
SYMS_Reg256 *xmm_s = &src->ymm0;
for (U32 n = 0;
n < 8;
n += 1, xmm_d += 1, xmm_s += 1){
MemoryCopy(xmm_d, xmm_s, sizeof(*xmm_d));
}
}
if (avx_available){
DWORD part0_length = 0;
M128A *part0 = (M128A*)LocateXStateFeature(ctx, XSTATE_LEGACY_SSE, &part0_length);
DWORD part1_length = 0;
M128A *part1 = (M128A*)LocateXStateFeature(ctx, XSTATE_AVX, &part1_length);
Assert(part0_length == part1_length);
DWORD count = part0_length/sizeof(part0[0]);
count = ClampTop(count, 16);
SYMS_Reg256 *ymm_d = &src->ymm0;
for (DWORD i = 0;
i < count;
i += 1, part0 += 1, part1 += 1, ymm_d += 1){
// TODO(allen): Are we writing these out in the right order? Seems weird right?
part0->Low = ymm_d->u64[3];
part0->High = ymm_d->u64[2];
part1->Low = ymm_d->u64[1];
part1->High = ymm_d->u64[0];
}
}
//- set thread context
HANDLE thread_handle = thread;
if (SetThreadContext(thread_handle, ctx)){
result = true;
}
}
scratch_end(scratch);
return(result);
}
internal B32
test_w32_read_memory(HANDLE process_handle, void *dst, U64 src_address, U64 size)
{
B32 result = true;
U8 *ptr = (U8*)dst;
U8 *opl = ptr + size;
U64 cursor = src_address;
for (;ptr < opl;){
SIZE_T to_read = (SIZE_T)(opl - ptr);
SIZE_T actual_read = 0;
if (!ReadProcessMemory(process_handle, (LPCVOID)cursor, ptr, to_read, &actual_read)){
result = false;
break;
}
ptr += actual_read;
cursor += actual_read;
}
return(result);
}
internal B32
test_w32_write_memory(HANDLE process_handle, U64 dst_address, void *src, U64 size)
{
B32 result = true;
U8 *ptr = (U8*)src;
U8 *opl = ptr + size;
U64 cursor = dst_address;
for (;ptr < opl;){
SIZE_T to_write = (SIZE_T)(opl - ptr);
SIZE_T actual_write = 0;
if (!WriteProcessMemory(process_handle, (LPVOID)cursor, ptr, to_write, &actual_write)){
result = false;
break;
}
ptr += actual_write;
cursor += actual_write;
}
return(result);
}
internal B32
test_launch_process(OS_LaunchOptions *options)
{
B32 result = false;
Temp scratch = scratch_begin(0, 0);
StringJoin join_params = {0};
join_params.pre = str8_lit("\"");
join_params.sep = str8_lit("\" \"");
join_params.post = str8_lit("\"");
String8 cmd = str8_list_join(scratch.arena, &options->cmd_line, &join_params);
StringJoin join_params2 = {0};
join_params2.sep = str8_lit("\0");
join_params2.post = str8_lit("\0");
String8 env = str8_list_join(scratch.arena, &options->env, &join_params2);
String16 cmd16 = str16_from_8(scratch.arena, cmd);
String16 dir16 = str16_from_8(scratch.arena, options->path);
String16 env16 = str16_from_8(scratch.arena, env);
DWORD access_flags = PROCESS_QUERY_INFORMATION | DEBUG_PROCESS | PROCESS_VM_READ | PROCESS_VM_WRITE;
STARTUPINFOW startup_info = {sizeof(startup_info)};
PROCESS_INFORMATION process_info = {0};
if (CreateProcessW(0, (WCHAR*)cmd16.str, 0, 0, 0, access_flags, (WCHAR*)env16.str, (WCHAR*)dir16.str,
&startup_info, &process_info))
{
CloseHandle(process_info.hProcess);
CloseHandle(process_info.hThread);
result = true;
}
scratch_end(scratch);
return(result);
}
global HANDLE g_process_1 = 0;
global DWORD g_process_id_1 = 0;
global U64 g_process_injection_addr_1 = 0;
global HANDLE g_process_2 = 0;
global DWORD g_process_id_2 = 0;
internal B32
test_w32_inject_thread(HANDLE process, U64 start_address)
{
B32 result = false;
LPTHREAD_START_ROUTINE start = (LPTHREAD_START_ROUTINE)start_address;
HANDLE thread = CreateRemoteThread(process, 0, 0, start, 0, 0, 0);
if(thread != 0)
{
CloseHandle(thread);
result = true;
}
return result;
}
internal void
test_halt(void)
{
test_w32_inject_thread(g_process_1, g_process_injection_addr_1);
}
internal TEST_DebugEvent
test_run_process(HANDLE step_thread, HANDLE suspend_thread, U64 traps_count, TEST_Trap *traps)
{
Temp scratch = scratch_begin(0, 0);
TEST_DebugEvent result = {0};
//- rjf: freeze thread
if(suspend_thread)
{
DWORD result = SuspendThread(suspend_thread);
DWORD error = GetLastError();
int x = 0;
}
//- rjf: write traps
U8 *trap_swap_bytes = push_array_no_zero(scratch.arena, U8, traps_count);
{
TEST_Trap *trap = traps;
for(U64 i = 0; i < traps_count; i += 1, trap += 1)
{
if(test_w32_read_memory(trap->process, trap_swap_bytes + i, trap->address, 1))
{
U8 int3 = 0xCC;
test_w32_write_memory(trap->process, trap->address, &int3, 1);
}
else
{
trap_swap_bytes[i] = 0xCC;
}
}
}
//- rjf: set single step bit
if(step_thread != 0)
{
SYMS_RegX64 regs = {0};
test_w32_read_x64_regs(step_thread, &regs);
regs.rflags.u64 |= 0x100;
test_w32_write_x64_regs(step_thread, &regs);
}
//- rjf: continue
local_persist B32 need_resume = 0;
local_persist DWORD resume_pid = 0;
local_persist DWORD resume_tid = 0;
if(need_resume)
{
need_resume = 0;
ContinueDebugEvent(resume_pid, resume_tid, DBG_CONTINUE);
}
//- rjf: get event
DEBUG_EVENT evt = {0};
if(WaitForDebugEvent(&evt, INFINITE))
{
need_resume = 1;
resume_pid = evt.dwProcessId;
resume_tid = evt.dwThreadId;
result.evt = evt;
switch(evt.dwDebugEventCode)
{
default:break;
case CREATE_PROCESS_DEBUG_EVENT:
{
result.name = str8_lit("create process");
result.process_id = evt.dwProcessId;
result.process = evt.u.CreateProcessInfo.hProcess;
result.thread_id = evt.dwThreadId;
result.thread = evt.u.CreateProcessInfo.hThread;
if(g_process_1 == 0)
{
g_process_1 = result.process;
g_process_id_1 = result.process_id;
// injection memory
{
U8 injection_code[64];
injection_code[0] = 0xCC;
injection_code[1] = 0xC3;
for (U64 i = 2; i < 64; i += 1){
injection_code[i] = 0xCC;
}
U64 injection_size = 64;
U64 injection_address = (U64)VirtualAllocEx(g_process_1, 0, injection_size, MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE);
test_w32_write_memory(g_process_1, injection_address, injection_code, sizeof(injection_code));
g_process_injection_addr_1 = injection_address;
}
}
else
{
g_process_2 = result.process;
g_process_id_2 = result.process_id;
}
}break;
case EXIT_PROCESS_DEBUG_EVENT:
{
result.name = str8_lit("exit process");
result.process_id = evt.dwProcessId;
}break;
case CREATE_THREAD_DEBUG_EVENT:
{
result.name = str8_lit("create thread");
result.thread_id = evt.dwThreadId;
result.thread = evt.u.CreateThread.hThread;
}break;
case EXIT_THREAD_DEBUG_EVENT:
{
result.name = str8_lit("exit thread");
result.thread_id = evt.dwThreadId;
}break;
case LOAD_DLL_DEBUG_EVENT:
{
result.name = str8_lit("load dll");
}break;
case UNLOAD_DLL_DEBUG_EVENT:
{
result.name = str8_lit("unload dll");
}break;
case EXCEPTION_DEBUG_EVENT:
{
result.name = str8_lit("exception");
EXCEPTION_DEBUG_INFO *edi = &evt.u.Exception;
EXCEPTION_RECORD *exception = &edi->ExceptionRecord;
switch(exception->ExceptionCode)
{
case DEMON_W32_EXCEPTION_BREAKPOINT:
{
result.name = str8_lit("breakpoint");
result.addr = (U64)exception->ExceptionAddress;
}break;
case DEMON_W32_EXCEPTION_SINGLE_STEP:
{
result.name = str8_lit("single_step");
}break;
case DEMON_W32_EXCEPTION_THROW:
{
result.name = str8_lit("exception throw");
}break;
case DEMON_W32_EXCEPTION_ACCESS_VIOLATION:
case DEMON_W32_EXCEPTION_IN_PAGE_ERROR:
{
result.name = str8_lit("exception access violation");
}break;
default:
{
}break;
}
}break;
case OUTPUT_DEBUG_STRING_EVENT:
{
Temp scratch = scratch_begin(0, 0);
result.name = str8_lit("output debug string");
U64 string_address = (U64)evt.u.DebugString.lpDebugStringData;
U64 string_size = (U64)evt.u.DebugString.nDebugStringLength;
// TODO(allen): is the string in UTF-8 or UTF-16?
U8 *buffer = push_array_no_zero(scratch.arena, U8, string_size + 1);
test_w32_read_memory(g_process_id_1 == evt.dwProcessId ? g_process_1 : g_process_2, buffer, string_address, string_size);
buffer[string_size] = 0;
printf("%s\n", buffer);
scratch_end(scratch);
}break;
case RIP_EVENT:
{
result.name = str8_lit("rip event");
}break;
}
}
//- rjf: set single step bit
if(step_thread != 0)
{
SYMS_RegX64 regs = {0};
test_w32_read_x64_regs(step_thread, &regs);
regs.rflags.u64 &= ~0x100;
test_w32_write_x64_regs(step_thread, &regs);
}
//- rjf: unset traps
{
TEST_Trap *trap = traps;
for(U64 i = 0; i < traps_count; i += 1, trap += 1)
{
U8 og_byte = trap_swap_bytes[i];
if(og_byte != 0xCC)
{
test_w32_write_memory(trap->process, trap->address, &og_byte, 1);
}
}
}
//- rjf: resume thread
if(suspend_thread)
{
ResumeThread(suspend_thread);
}
scratch_end(scratch);
return result;
}
internal DWORD
test_halter_thread(void *params)
{
HANDLE original_process_handle = params;
Sleep(1500);
test_halt();
#if 0
DWORD process_id = GetProcessId(original_process_handle);
HANDLE elevated_process_handle = OpenProcess(PROCESS_SUSPEND_RESUME, 0, process_id);
LONG result = NtSuspendProcess(elevated_process_handle);
CloseHandle(elevated_process_handle);
DebugBreakProcess(process);
#endif
return 0;
}
int
main(int argument_count, char **arguments)
{
os_init(argument_count, arguments);
Arena *arena = arena_alloc();
NtSuspendProcess = (NtSuspendProcessFunction *)GetProcAddress(GetModuleHandle("ntdll"), "NtSuspendProcess");
// rjf: launch
{
OS_LaunchOptions opts = {0};
opts.path = os_get_path(arena, OS_SystemPath_Current);
str8_list_push(arena, &opts.cmd_line, str8_lit("R:\\projects\\debugger\\build\\mule_loop.exe"));
B32 launch_good = test_launch_process(&opts);
int x = 0;
}
// rjf: get process/thread handles
HANDLE process = 0;
HANDLE thread1 = 0;
U64 thread1_id = 0;
{
for(TEST_DebugEvent evt = {0};;)
{
evt = test_run_process(0, 0, 0, 0);
if(evt.process)
{
process = evt.process;
}
if(evt.thread)
{
thread1 = evt.thread;
thread1_id = evt.thread_id;
}
if(process != 0 && thread1 != 0)
{
break;
}
}
}
// rjf: get first breakpoint
{
for(TEST_DebugEvent evt = {0};;)
{
evt = test_run_process(0, 0, 0, 0);
if(evt.evt.dwDebugEventCode == EXCEPTION_DEBUG_EVENT)
{
break;
}
}
}
// rjf: launch halter thread
DWORD halter_id = 0;
{
CreateThread(0, 0, test_halter_thread, process, 0, &halter_id);
}
// rjf: run + wait for event
for(;;)
{
TEST_DebugEvent evt = test_run_process(0, 0, 0, 0);
int x = 0;
}
#if 0
//- rjf: run until 2nd thread starts up
HANDLE thread2 = 0;
U64 thread2_id = 0;
{
for(TEST_DebugEvent evt = {0};;)
{
evt = test_run_process(0, 0, 0, 0/*ArrayCount(traps), traps*/);
if(evt.thread)
{
thread2 = evt.thread;
thread2_id = evt.thread_id;
break;
}
}
}
//- rjf: wait for first output string
{
for(TEST_DebugEvent evt = {0};;)
{
evt = test_run_process(0, 0, 0, 0);
if(evt.evt.dwDebugEventCode == OUTPUT_DEBUG_STRING_EVENT)
{
break;
}
}
}
//- rjf: wait for bps
{
// U64 thread1_stop_vaddr = 0x0000000140001119;
// U64 thread2_stop_vaddr = 0x00000001400010C8;
// TEST_Trap traps[] =
{
// {process, thread1_stop_vaddr},
//{process, thread2_stop_vaddr},
};
TEST_DebugEvent evt = {0};
//for(;;)
{
evt = test_run_process(0, thread2, 0, 0/*ArrayCount(traps), traps*/);
int x = 0;
}
for(;;) {}
}
#endif
}
+874
View File
@@ -0,0 +1,874 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include <windows.h>
#include "base/base_inc.h"
#include "os/os_inc.h"
#include "syms_helpers/syms_internal_overrides.h"
#include "syms/syms_inc.h"
#include "syms_helpers/syms_helpers.h"
#include "base/base_inc.c"
#include "os/os_inc.c"
#include "syms_helpers/syms_internal_overrides.c"
#include "syms/syms_inc.c"
#include "syms_helpers/syms_helpers.c"
////////////////////////////////
// NOTE(allen): Win32 Demon Exceptions
#define DEMON_W32_EXCEPTION_BREAKPOINT 0x80000003u
#define DEMON_W32_EXCEPTION_SINGLE_STEP 0x80000004u
#define DEMON_W32_EXCEPTION_LONG_JUMP 0x80000026u
#define DEMON_W32_EXCEPTION_ACCESS_VIOLATION 0xC0000005u
#define DEMON_W32_EXCEPTION_ARRAY_BOUNDS_EXCEEDED 0xC000008Cu
#define DEMON_W32_EXCEPTION_DATA_TYPE_MISALIGNMENT 0x80000002u
#define DEMON_W32_EXCEPTION_GUARD_PAGE_VIOLATION 0x80000001u
#define DEMON_W32_EXCEPTION_FLT_DENORMAL_OPERAND 0xC000008Du
#define DEMON_W32_EXCEPTION_FLT_DEVIDE_BY_ZERO 0xC000008Eu
#define DEMON_W32_EXCEPTION_FLT_INEXACT_RESULT 0xC000008Fu
#define DEMON_W32_EXCEPTION_FLT_INVALID_OPERATION 0xC0000090u
#define DEMON_W32_EXCEPTION_FLT_OVERFLOW 0xC0000091u
#define DEMON_W32_EXCEPTION_FLT_STACK_CHECK 0xC0000092u
#define DEMON_W32_EXCEPTION_FLT_UNDERFLOW 0xC0000093u
#define DEMON_W32_EXCEPTION_INT_DIVIDE_BY_ZERO 0xC0000094u
#define DEMON_W32_EXCEPTION_INT_OVERFLOW 0xC0000095u
#define DEMON_W32_EXCEPTION_PRIVILEGED_INSTRUCTION 0xC0000096u
#define DEMON_W32_EXCEPTION_ILLEGAL_INSTRUCTION 0xC000001Du
#define DEMON_W32_EXCEPTION_IN_PAGE_ERROR 0xC0000006u
#define DEMON_W32_EXCEPTION_INVALID_DISPOSITION 0xC0000026u
#define DEMON_W32_EXCEPTION_NONCONTINUABLE 0xC0000025u
#define DEMON_W32_EXCEPTION_STACK_OVERFLOW 0xC00000FDu
#define DEMON_W32_EXCEPTION_INVALID_HANDLE 0xC0000008u
#define DEMON_W32_EXCEPTION_UNWIND_CONSOLIDATE 0x80000029u
#define DEMON_W32_EXCEPTION_DLL_NOT_FOUND 0xC0000135u
#define DEMON_W32_EXCEPTION_ORDINAL_NOT_FOUND 0xC0000138u
#define DEMON_W32_EXCEPTION_ENTRY_POINT_NOT_FOUND 0xC0000139u
#define DEMON_W32_EXCEPTION_DLL_INIT_FAILED 0xC0000142u
#define DEMON_W32_EXCEPTION_CONTROL_C_EXIT 0xC000013Au
#define DEMON_W32_EXCEPTION_FLT_MULTIPLE_FAULTS 0xC00002B4u
#define DEMON_W32_EXCEPTION_FLT_MULTIPLE_TRAPS 0xC00002B5u
#define DEMON_W32_EXCEPTION_NAT_CONSUMPTION 0xC00002C9u
#define DEMON_W32_EXCEPTION_HEAP_CORRUPTION 0xC0000374u
#define DEMON_W32_EXCEPTION_STACK_BUFFER_OVERRUN 0xC0000409u
#define DEMON_W32_EXCEPTION_INVALID_CRUNTIME_PARAM 0xC0000417u
#define DEMON_W32_EXCEPTION_ASSERT_FAILURE 0xC0000420u
#define DEMON_W32_EXCEPTION_NO_MEMORY 0xC0000017u
#define DEMON_W32_EXCEPTION_THROW 0xE06D7363u
////////////////////////////////
// NOTE(allen): Win32 Demon Register API Codes
#define DEMON_W32_CTX_X86 0x00010000
#define DEMON_W32_CTX_X64 0x00100000
#define DEMON_W32_CTX_INTEL_CONTROL 0x0001
#define DEMON_W32_CTX_INTEL_INTEGER 0x0002
#define DEMON_W32_CTX_INTEL_SEGMENTS 0x0004
#define DEMON_W32_CTX_INTEL_FLOATS 0x0008
#define DEMON_W32_CTX_INTEL_DEBUG 0x0010
#define DEMON_W32_CTX_INTEL_EXTENDED 0x0020
#define DEMON_W32_CTX_INTEL_XSTATE 0x0040
#define DEMON_W32_CTX_X86_ALL (DEMON_W32_CTX_X86 | \
DEMON_W32_CTX_INTEL_CONTROL | DEMON_W32_CTX_INTEL_INTEGER | \
DEMON_W32_CTX_INTEL_SEGMENTS | DEMON_W32_CTX_INTEL_DEBUG | \
DEMON_W32_CTX_INTEL_EXTENDED)
#define DEMON_W32_CTX_X64_ALL (DEMON_W32_CTX_X64 | \
DEMON_W32_CTX_INTEL_CONTROL | DEMON_W32_CTX_INTEL_INTEGER | \
DEMON_W32_CTX_INTEL_SEGMENTS | DEMON_W32_CTX_INTEL_FLOATS | \
DEMON_W32_CTX_INTEL_DEBUG)
struct TEST_DebugEvent
{
String8 name;
U64 process_id;
U64 thread_id;
HANDLE process;
HANDLE thread;
U64 addr;
DEBUG_EVENT evt;
};
struct TEST_Trap
{
HANDLE process;
U64 address;
};
internal U16
test_w32_real_tag_word_from_xsave(XSAVE_FORMAT *fxsave)
{
U16 result = 0;
U32 top = (fxsave->StatusWord >> 11) & 7;
for (U32 fpr = 0; fpr < 8; fpr += 1){
U32 tag = 3;
if (fxsave->TagWord & (1 << fpr)){
U32 st = (fpr - top)&7;
SYMS_Reg80 *fp = (SYMS_Reg80*)&fxsave->FloatRegisters[st*16];
U16 exponent = fp->sign1_exp15 & bitmask15;
U64 integer_part = fp->int1_frac63 >> 63;
U64 fraction_part = fp->int1_frac63 & bitmask63;
// tag: 0 - normal; 1 - zero; 2 - special
tag = 2;
if (exponent == 0){
if (integer_part == 0 && fraction_part == 0){
tag = 1;
}
}
else if (exponent != bitmask15 && integer_part != 0){
tag = 0;
}
}
result |= tag << (2 * fpr);
}
return(result);
}
internal U16
test_w32_xsave_tag_word_from_real_tag_word(U16 ftw)
{
U16 compact = 0;
for (U32 fpr = 0; fpr < 8; fpr++){
U32 tag = (ftw >> (fpr * 2)) & 3;
if (tag != 3){
compact |= (1 << fpr);
}
}
return(compact);
}
internal B32
test_w32_read_x64_regs(HANDLE thread, SYMS_RegX64 *dst)
{
Temp scratch = scratch_begin(0, 0);
// NOTE(allen): Check available features
U32 feature_mask = GetEnabledXStateFeatures();
B32 avx_enabled = !!(feature_mask & XSTATE_MASK_AVX);
// NOTE(allen): Setup the context
CONTEXT *ctx = 0;
U32 ctx_flags = DEMON_W32_CTX_X64_ALL;
if (avx_enabled){
ctx_flags |= DEMON_W32_CTX_INTEL_XSTATE;
}
DWORD size = 0;
InitializeContext(0, ctx_flags, 0, &size);
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER){
void *ctx_memory = push_array(scratch.arena, U8, size);
if (!InitializeContext(ctx_memory, ctx_flags, &ctx, &size)){
ctx = 0;
}
}
B32 avx_available = false;
if (ctx != 0){
// NOTE(allen): Finish Context Setup
if (avx_enabled){
SetXStateFeaturesMask(ctx, XSTATE_MASK_AVX);
}
// NOTE(allen): Determine what features are available on this particular ctx
// TODO(allen): Experiment carefully with this nonsense.
// Does avx_enabled = avx_available in all circumstances or not?
DWORD64 xstate_flags = 0;
if (GetXStateFeaturesMask(ctx, &xstate_flags)){
if (xstate_flags & XSTATE_MASK_AVX){
avx_available = true;
}
}
}
// get thread context
HANDLE thread_handle = thread;
if (!GetThreadContext(thread_handle, ctx)){
ctx = 0;
}
B32 result = false;
if (ctx != 0){
result = true;
// NOTE(allen): Convert CONTEXT -> SYMS_RegX64
dst->rax.u64 = ctx->Rax;
dst->rcx.u64 = ctx->Rcx;
dst->rdx.u64 = ctx->Rdx;
dst->rbx.u64 = ctx->Rbx;
dst->rsp.u64 = ctx->Rsp;
dst->rbp.u64 = ctx->Rbp;
dst->rsi.u64 = ctx->Rsi;
dst->rdi.u64 = ctx->Rdi;
dst->r8.u64 = ctx->R8;
dst->r9.u64 = ctx->R9;
dst->r10.u64 = ctx->R10;
dst->r11.u64 = ctx->R11;
dst->r12.u64 = ctx->R12;
dst->r13.u64 = ctx->R13;
dst->r14.u64 = ctx->R14;
dst->r15.u64 = ctx->R15;
dst->rip.u64 = ctx->Rip;
dst->cs.u16 = ctx->SegCs;
dst->ds.u16 = ctx->SegDs;
dst->es.u16 = ctx->SegEs;
dst->fs.u16 = ctx->SegFs;
dst->gs.u16 = ctx->SegGs;
dst->ss.u16 = ctx->SegSs;
dst->dr0.u32 = ctx->Dr0;
dst->dr1.u32 = ctx->Dr1;
dst->dr2.u32 = ctx->Dr2;
dst->dr3.u32 = ctx->Dr3;
dst->dr6.u32 = ctx->Dr6;
dst->dr7.u32 = ctx->Dr7;
// NOTE(allen): This bit is "supposed to always be 1" I guess.
// TODO(allen): Not sure what this is all about but I haven't investigated it yet.
// This might be totally not necessary or something.
dst->rflags.u64 = ctx->EFlags | 0x2;
XSAVE_FORMAT *xsave = &ctx->FltSave;
dst->fcw.u16 = xsave->ControlWord;
dst->fsw.u16 = xsave->StatusWord;
dst->ftw.u16 = test_w32_real_tag_word_from_xsave(xsave);
dst->fop.u16 = xsave->ErrorOpcode;
dst->fcs.u16 = xsave->ErrorSelector;
dst->fds.u16 = xsave->DataSelector;
dst->fip.u32 = xsave->ErrorOffset;
dst->fdp.u32 = xsave->DataOffset;
dst->mxcsr.u32 = xsave->MxCsr;
dst->mxcsr_mask.u32 = xsave->MxCsr_Mask;
M128A *float_s = xsave->FloatRegisters;
SYMS_Reg80 *float_d = &dst->fpr0;
for (U32 n = 0; n < 8; n += 1, float_s += 1, float_d += 1){
MemoryCopy(float_d, float_s, sizeof(*float_d));
}
if (!avx_available){
M128A *xmm_s = xsave->XmmRegisters;
SYMS_Reg256 *xmm_d = &dst->ymm0;
for (U32 n = 0; n < 16; n += 1, xmm_s += 1, xmm_d += 1){
MemoryCopy(xmm_d, xmm_s, sizeof(*xmm_s));
}
}
if (avx_available){
DWORD part0_length = 0;
M128A *part0 = (M128A*)LocateXStateFeature(ctx, XSTATE_LEGACY_SSE, &part0_length);
DWORD part1_length = 0;
M128A *part1 = (M128A*)LocateXStateFeature(ctx, XSTATE_AVX, &part1_length);
Assert(part0_length == part1_length);
DWORD count = part0_length/sizeof(part0[0]);
count = ClampTop(count, 16);
SYMS_Reg256 *ymm_d = &dst->ymm0;
for (DWORD i = 0;
i < count;
i += 1, part0 += 1, part1 += 1, ymm_d += 1){
// TODO(allen): Are we writing these out in the right order? Seems weird right?
ymm_d->u64[3] = part0->Low;
ymm_d->u64[2] = part0->High;
ymm_d->u64[1] = part1->Low;
ymm_d->u64[0] = part1->High;
}
}
}
scratch_end(scratch);
return(result);
}
internal B32
test_w32_write_x64_regs(HANDLE thread, SYMS_RegX64 *src)
{
Temp scratch = scratch_begin(0, 0);
// NOTE(allen): Check available features
U32 feature_mask = GetEnabledXStateFeatures();
B32 avx_enabled = !!(feature_mask & XSTATE_MASK_AVX);
// NOTE(allen): Setup the context
CONTEXT *ctx = 0;
U32 ctx_flags = DEMON_W32_CTX_X64_ALL;
if (avx_enabled){
ctx_flags |= DEMON_W32_CTX_INTEL_XSTATE;
}
DWORD size = 0;
InitializeContext(0, ctx_flags, 0, &size);
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER){
void *ctx_memory = push_array(scratch.arena, U8, size);
if (!InitializeContext(ctx_memory, ctx_flags, &ctx, &size)){
ctx = 0;
}
}
B32 avx_available = false;
if (ctx != 0){
// NOTE(allen): Finish Context Setup
if (avx_enabled){
SetXStateFeaturesMask(ctx, XSTATE_MASK_AVX);
}
// NOTE(allen): Determine what features are available on this particular ctx
// TODO(allen): Experiment carefully with this nonsense.
// Does avx_enabled = avx_available in all circumstances or not?
DWORD64 xstate_flags = 0;
if (GetXStateFeaturesMask(ctx, &xstate_flags)){
if (xstate_flags & XSTATE_MASK_AVX){
avx_available = true;
}
}
}
B32 result = false;
if (ctx != 0){
// NOTE(allen): Convert SYMS_RegX64 -> CONTEXT
ctx->ContextFlags = ctx_flags;
ctx->MxCsr = src->mxcsr.u32 & src->mxcsr_mask.u32;
ctx->Rax = src->rax.u64;
ctx->Rcx = src->rcx.u64;
ctx->Rdx = src->rdx.u64;
ctx->Rbx = src->rbx.u64;
ctx->Rsp = src->rsp.u64;
ctx->Rbp = src->rbp.u64;
ctx->Rsi = src->rsi.u64;
ctx->Rdi = src->rdi.u64;
ctx->R8 = src->r8.u64;
ctx->R9 = src->r9.u64;
ctx->R10 = src->r10.u64;
ctx->R11 = src->r11.u64;
ctx->R12 = src->r12.u64;
ctx->R13 = src->r13.u64;
ctx->R14 = src->r14.u64;
ctx->R15 = src->r15.u64;
ctx->Rip = src->rip.u64;
ctx->SegCs = src->cs.u16;
ctx->SegDs = src->ds.u16;
ctx->SegEs = src->es.u16;
ctx->SegFs = src->fs.u16;
ctx->SegGs = src->gs.u16;
ctx->SegSs = src->ss.u16;
ctx->Dr0 = src->dr0.u32;
ctx->Dr1 = src->dr1.u32;
ctx->Dr2 = src->dr2.u32;
ctx->Dr3 = src->dr3.u32;
ctx->Dr6 = src->dr6.u32;
ctx->Dr7 = src->dr7.u32;
ctx->EFlags = src->rflags.u64;
XSAVE_FORMAT *fxsave = &ctx->FltSave;
fxsave->ControlWord = src->fcw.u16;
fxsave->StatusWord = src->fsw.u16;
fxsave->TagWord = test_w32_xsave_tag_word_from_real_tag_word(src->ftw.u16);
fxsave->ErrorOpcode = src->fop.u16;
fxsave->ErrorSelector = src->fcs.u16;
fxsave->DataSelector = src->fds.u16;
fxsave->ErrorOffset = src->fip.u32;
fxsave->DataOffset = src->fdp.u32;
M128A *float_d = fxsave->FloatRegisters;
SYMS_Reg80 *float_s = &src->fpr0;
for (U32 n = 0;
n < 8;
n += 1, float_s += 1, float_d += 1){
MemoryCopy(float_d, float_s, 10);
}
if (!avx_available){
M128A *xmm_d = fxsave->XmmRegisters;
SYMS_Reg256 *xmm_s = &src->ymm0;
for (U32 n = 0;
n < 8;
n += 1, xmm_d += 1, xmm_s += 1){
MemoryCopy(xmm_d, xmm_s, sizeof(*xmm_d));
}
}
if (avx_available){
DWORD part0_length = 0;
M128A *part0 = (M128A*)LocateXStateFeature(ctx, XSTATE_LEGACY_SSE, &part0_length);
DWORD part1_length = 0;
M128A *part1 = (M128A*)LocateXStateFeature(ctx, XSTATE_AVX, &part1_length);
Assert(part0_length == part1_length);
DWORD count = part0_length/sizeof(part0[0]);
count = ClampTop(count, 16);
SYMS_Reg256 *ymm_d = &src->ymm0;
for (DWORD i = 0;
i < count;
i += 1, part0 += 1, part1 += 1, ymm_d += 1){
// TODO(allen): Are we writing these out in the right order? Seems weird right?
part0->Low = ymm_d->u64[3];
part0->High = ymm_d->u64[2];
part1->Low = ymm_d->u64[1];
part1->High = ymm_d->u64[0];
}
}
//- set thread context
HANDLE thread_handle = thread;
if (SetThreadContext(thread_handle, ctx)){
result = true;
}
}
scratch_end(scratch);
return(result);
}
internal B32
test_w32_read_memory(HANDLE process_handle, void *dst, U64 src_address, U64 size)
{
B32 result = true;
U8 *ptr = (U8*)dst;
U8 *opl = ptr + size;
U64 cursor = src_address;
for (;ptr < opl;){
SIZE_T to_read = (SIZE_T)(opl - ptr);
SIZE_T actual_read = 0;
if (!ReadProcessMemory(process_handle, (LPCVOID)cursor, ptr, to_read, &actual_read)){
result = false;
break;
}
ptr += actual_read;
cursor += actual_read;
}
return(result);
}
internal B32
test_w32_write_memory(HANDLE process_handle, U64 dst_address, void *src, U64 size)
{
B32 result = true;
U8 *ptr = (U8*)src;
U8 *opl = ptr + size;
U64 cursor = dst_address;
for (;ptr < opl;){
SIZE_T to_write = (SIZE_T)(opl - ptr);
SIZE_T actual_write = 0;
if (!WriteProcessMemory(process_handle, (LPVOID)cursor, ptr, to_write, &actual_write)){
result = false;
break;
}
ptr += actual_write;
cursor += actual_write;
}
return(result);
}
internal B32
test_launch_process(OS_LaunchOptions *options)
{
B32 result = false;
Temp scratch = scratch_begin(0, 0);
StringJoin join_params = {0};
join_params.pre = str8_lit("\"");
join_params.sep = str8_lit("\" \"");
join_params.post = str8_lit("\"");
String8 cmd = str8_list_join(scratch.arena, &options->cmd_line, &join_params);
StringJoin join_params2 = {0};
join_params2.sep = str8_lit("\0");
join_params2.post = str8_lit("\0");
String8 env = str8_list_join(scratch.arena, &options->env, &join_params2);
String16 cmd16 = str16_from_8(scratch.arena, cmd);
String16 dir16 = str16_from_8(scratch.arena, options->path);
String16 env16 = str16_from_8(scratch.arena, env);
DWORD access_flags = PROCESS_QUERY_INFORMATION | DEBUG_PROCESS | PROCESS_VM_READ | PROCESS_VM_WRITE;
STARTUPINFOW startup_info = {sizeof(startup_info)};
PROCESS_INFORMATION process_info = {0};
if (CreateProcessW(0, (WCHAR*)cmd16.str, 0, 0, 0, access_flags, (WCHAR*)env16.str, (WCHAR*)dir16.str,
&startup_info, &process_info))
{
CloseHandle(process_info.hProcess);
CloseHandle(process_info.hThread);
result = true;
}
scratch_end(scratch);
return(result);
}
global HANDLE g_process = 0;
global DWORD g_process_id = 0;
global HANDLE g_thread1 = 0;
global DWORD g_thread1_id = 0;
global HANDLE g_thread2 = 0;
global DWORD g_thread2_id = 0;
internal TEST_DebugEvent
test_run_process(HANDLE step_thread, HANDLE suspend_thread, U64 traps_count, TEST_Trap *traps)
{
Temp scratch = scratch_begin(0, 0);
TEST_DebugEvent result = {0};
//- rjf: freeze thread
if(suspend_thread)
{
DWORD result = SuspendThread(suspend_thread);
DWORD error = GetLastError();
int x = 0;
}
//- rjf: write traps
U8 *trap_swap_bytes = push_array_no_zero(scratch.arena, U8, traps_count);
{
TEST_Trap *trap = traps;
for(U64 i = 0; i < traps_count; i += 1, trap += 1)
{
if(test_w32_read_memory(trap->process, trap_swap_bytes + i, trap->address, 1))
{
U8 int3 = 0xCC;
test_w32_write_memory(trap->process, trap->address, &int3, 1);
}
else
{
trap_swap_bytes[i] = 0xCC;
}
}
}
//- rjf: set single step bit
if(step_thread != 0)
{
SYMS_RegX64 regs = {0};
test_w32_read_x64_regs(step_thread, &regs);
regs.rflags.u64 |= 0x100;
test_w32_write_x64_regs(step_thread, &regs);
}
//- rjf: continue
local_persist B32 need_resume = 0;
local_persist DWORD resume_pid = 0;
local_persist DWORD resume_tid = 0;
if(need_resume)
{
need_resume = 0;
ContinueDebugEvent(resume_pid, resume_tid, DBG_CONTINUE);
}
//- rjf: get event
DEBUG_EVENT evt = {0};
if(WaitForDebugEvent(&evt, INFINITE))
{
need_resume = 1;
resume_pid = evt.dwProcessId;
resume_tid = evt.dwThreadId;
result.evt = evt;
switch(evt.dwDebugEventCode)
{
default:break;
case CREATE_PROCESS_DEBUG_EVENT:
{
result.name = str8_lit("create process");
result.process_id = evt.dwProcessId;
result.process = evt.u.CreateProcessInfo.hProcess;
result.thread_id = evt.dwThreadId;
result.thread = evt.u.CreateProcessInfo.hThread;
if(g_process == 0)
{
g_process = result.process;
g_process_id = result.process_id;
}
if(g_thread1 == 0)
{
g_thread1 = result.thread;
g_thread1_id = result.thread_id;
}
}break;
case EXIT_PROCESS_DEBUG_EVENT:
{
result.name = str8_lit("exit process");
result.process_id = evt.dwProcessId;
}break;
case CREATE_THREAD_DEBUG_EVENT:
{
result.name = str8_lit("create thread");
result.thread_id = evt.dwThreadId;
result.thread = evt.u.CreateThread.hThread;
g_thread2 = result.thread;
g_thread2_id = result.thread_id;
}break;
case EXIT_THREAD_DEBUG_EVENT:
{
result.name = str8_lit("exit thread");
result.thread_id = evt.dwThreadId;
}break;
case LOAD_DLL_DEBUG_EVENT:
{
result.name = str8_lit("load dll");
}break;
case UNLOAD_DLL_DEBUG_EVENT:
{
result.name = str8_lit("unload dll");
}break;
case EXCEPTION_DEBUG_EVENT:
{
result.name = str8_lit("exception");
EXCEPTION_DEBUG_INFO *edi = &evt.u.Exception;
EXCEPTION_RECORD *exception = &edi->ExceptionRecord;
switch(exception->ExceptionCode)
{
case DEMON_W32_EXCEPTION_BREAKPOINT:
{
result.name = str8_lit("breakpoint");
result.addr = (U64)exception->ExceptionAddress;
local_persist B32 did_first_bp = 0;
if(did_first_bp != 0)
{
HANDLE thread = evt.dwThreadId == g_thread1_id ? g_thread1 : g_thread2;
SYMS_RegX64 regs = {0};
test_w32_read_x64_regs(thread, &regs);
regs.rip.u64 = result.addr;
test_w32_write_x64_regs(thread, &regs);
}
did_first_bp = 1;
}break;
case DEMON_W32_EXCEPTION_SINGLE_STEP:
{
result.name = str8_lit("single_step");
}break;
case DEMON_W32_EXCEPTION_THROW:
{
result.name = str8_lit("exception throw");
}break;
case DEMON_W32_EXCEPTION_ACCESS_VIOLATION:
case DEMON_W32_EXCEPTION_IN_PAGE_ERROR:
{
result.name = str8_lit("exception access violation");
}break;
default:
{
}break;
}
}break;
case OUTPUT_DEBUG_STRING_EVENT:
{
Temp scratch = scratch_begin(0, 0);
result.name = str8_lit("output debug string");
U64 string_address = (U64)evt.u.DebugString.lpDebugStringData;
U64 string_size = (U64)evt.u.DebugString.nDebugStringLength;
// TODO(allen): is the string in UTF-8 or UTF-16?
U8 *buffer = push_array_no_zero(scratch.arena, U8, string_size + 1);
test_w32_read_memory(g_process, buffer, string_address, string_size);
buffer[string_size] = 0;
printf("%s\n", buffer);
scratch_end(scratch);
}break;
case RIP_EVENT:
{
result.name = str8_lit("rip event");
}break;
}
}
//- rjf: set single step bit
if(step_thread != 0)
{
SYMS_RegX64 regs = {0};
test_w32_read_x64_regs(step_thread, &regs);
regs.rflags.u64 &= ~0x100;
test_w32_write_x64_regs(step_thread, &regs);
}
//- rjf: unset traps
{
TEST_Trap *trap = traps;
for(U64 i = 0; i < traps_count; i += 1, trap += 1)
{
U8 og_byte = trap_swap_bytes[i];
if(og_byte != 0xCC)
{
test_w32_write_memory(trap->process, trap->address, &og_byte, 1);
}
}
}
//- rjf: check for more events
for(int i = 0; i < 100; i += 1)
{
DEBUG_EVENT evt = {0};
if(WaitForDebugEvent(&evt, 0))
{
int x = 0;
}
}
//- rjf: resume thread
if(suspend_thread)
{
ResumeThread(suspend_thread);
}
scratch_end(scratch);
return result;
}
int
main(int argument_count, char **arguments)
{
os_init(argument_count, arguments);
Arena *arena = arena_alloc();
U64 before_loop_stop_vaddr = 0x0000000140001089;
U64 inner_loop_stop_vaddr = 0x0000000140001098;
// rjf: launch
{
OS_LaunchOptions opts = {0};
opts.path = os_get_path(arena, OS_SystemPath_Current);
str8_list_push(arena, &opts.cmd_line, str8_lit("R:\\projects\\debugger\\build\\mule_loop_threads_win32.exe"));
B32 launch_good = test_launch_process(&opts);
int x = 0;
}
// rjf: get process/thread handles
HANDLE process = 0;
HANDLE thread1 = 0;
U64 thread1_id = 0;
{
for(TEST_DebugEvent evt = {0};;)
{
evt = test_run_process(0, 0, 0, 0);
if(evt.process)
{
process = evt.process;
}
if(evt.thread)
{
thread1 = evt.thread;
thread1_id = evt.thread_id;
}
if(process != 0 && thread1 != 0)
{
break;
}
}
}
// rjf: get first breakpoint
{
for(TEST_DebugEvent evt = {0};;)
{
evt = test_run_process(0, 0, 0, 0);
if(evt.evt.dwDebugEventCode == EXCEPTION_DEBUG_EVENT)
{
break;
}
}
}
//- rjf: run until 2nd thread starts up
HANDLE thread2 = 0;
U64 thread2_id = 0;
{
TEST_Trap traps[] =
{
{process, before_loop_stop_vaddr},
};
int trap_count = 0; //ArrayCount(traps);
for(TEST_DebugEvent evt = {0};;)
{
evt = test_run_process(0, 0, trap_count, traps);
if(str8_match(evt.name, str8_lit("breakpoint"), 0))
{
trap_count = 0;
}
if(evt.thread)
{
thread2 = evt.thread;
thread2_id = evt.thread_id;
break;
}
}
}
//- rjf: wait for bps
{
Temp scratch = scratch_begin(0, 0);
TEST_Trap traps[] =
{
{process, 0x0000000140001098},
{process, 0x00000001400010fb},
{process, 0x00000001400010bc},
{process, 0x00000001400010d7},
};
for(int i = 0;; i += 1)
{
TEST_DebugEvent evt = test_run_process(0, 0, 1, &traps[i % ArrayCount(traps)]);
// rjf: check regs
{
U64 rip = 0;
SYMS_RegX64 *regs = push_array(scratch.arena, SYMS_RegX64, 1);
if(evt.evt.dwThreadId == g_thread1_id && test_w32_read_x64_regs(thread1, regs))
{
rip = regs->rip.u64;
}
if(evt.evt.dwThreadId == g_thread2_id && test_w32_read_x64_regs(thread2, regs))
{
rip = regs->rip.u64;
}
for(int i = 0; i < ArrayCount(traps); i += 1)
{
if(traps[i].address == rip)
{
printf("WRONG BP! 0x%I64x\n", rip);
break;
}
}
}
if(str8_match(evt.name, str8_lit("breakpoint"), 0))
{
HANDLE step = 0;
HANDLE suspend = 0;
step = evt.evt.dwThreadId == thread2_id ? thread2 : thread1;
suspend = step == thread2 ? thread1 : thread2;
evt = test_run_process(step, suspend, 0, 0);
}
}
scratch_end(scratch);
}
return 0;
}
File diff suppressed because it is too large Load Diff
+378
View File
@@ -0,0 +1,378 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_OS_WIN32_H
#define DEMON_OS_WIN32_H
////////////////////////////////
//~ NOTE(allen): Win32 Demon Headers Negotation
// windows headers
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <psapi.h>
#include <tlhelp32.h>
////////////////////////////////
//~ NOTE(allen): Win32 Demon Types
//- entities
// Demon Win32 Entity Extensions
// Process: ext points to independently allocated DEMON_W32_Ext
// Thread : ext points to independently allocated DEMON_W32_Ext
// Module : ext set to HANDLE
typedef union DEMON_W32_Ext DEMON_W32_Ext;
union DEMON_W32_Ext
{
DEMON_W32_Ext *next;
struct{
HANDLE handle;
U64 injection_address;
B32 did_first_bp;
} proc;
struct{
HANDLE handle;
U64 thread_local_base;
} thread;
struct{
HANDLE handle;
U64 address_of_name_pointer;
B32 is_main;
B32 name_is_unicode;
} module;
};
//- helpers
typedef struct DEMON_W32_InjectedBreak DEMON_W32_InjectedBreak;
struct DEMON_W32_InjectedBreak
{
U64 code;
U64 user_data;
};
#define DEMON_W32_INJECTED_CODE_SIZE 32
typedef struct DEMON_W32_ImageInfo DEMON_W32_ImageInfo;
struct DEMON_W32_ImageInfo
{
Architecture arch;
U32 size;
};
typedef struct DEMON_W32_EntityNode DEMON_W32_EntityNode;
struct DEMON_W32_EntityNode
{
DEMON_W32_EntityNode *next;
DEMON_Entity *entity;
};
////////////////////////////////
//~ NOTE(allen): Win32 Demon Exceptions
#define DEMON_W32_EXCEPTION_BREAKPOINT 0x80000003u
#define DEMON_W32_EXCEPTION_SINGLE_STEP 0x80000004u
#define DEMON_W32_EXCEPTION_LONG_JUMP 0x80000026u
#define DEMON_W32_EXCEPTION_ACCESS_VIOLATION 0xC0000005u
#define DEMON_W32_EXCEPTION_ARRAY_BOUNDS_EXCEEDED 0xC000008Cu
#define DEMON_W32_EXCEPTION_DATA_TYPE_MISALIGNMENT 0x80000002u
#define DEMON_W32_EXCEPTION_GUARD_PAGE_VIOLATION 0x80000001u
#define DEMON_W32_EXCEPTION_FLT_DENORMAL_OPERAND 0xC000008Du
#define DEMON_W32_EXCEPTION_FLT_DEVIDE_BY_ZERO 0xC000008Eu
#define DEMON_W32_EXCEPTION_FLT_INEXACT_RESULT 0xC000008Fu
#define DEMON_W32_EXCEPTION_FLT_INVALID_OPERATION 0xC0000090u
#define DEMON_W32_EXCEPTION_FLT_OVERFLOW 0xC0000091u
#define DEMON_W32_EXCEPTION_FLT_STACK_CHECK 0xC0000092u
#define DEMON_W32_EXCEPTION_FLT_UNDERFLOW 0xC0000093u
#define DEMON_W32_EXCEPTION_INT_DIVIDE_BY_ZERO 0xC0000094u
#define DEMON_W32_EXCEPTION_INT_OVERFLOW 0xC0000095u
#define DEMON_W32_EXCEPTION_PRIVILEGED_INSTRUCTION 0xC0000096u
#define DEMON_W32_EXCEPTION_ILLEGAL_INSTRUCTION 0xC000001Du
#define DEMON_W32_EXCEPTION_IN_PAGE_ERROR 0xC0000006u
#define DEMON_W32_EXCEPTION_INVALID_DISPOSITION 0xC0000026u
#define DEMON_W32_EXCEPTION_NONCONTINUABLE 0xC0000025u
#define DEMON_W32_EXCEPTION_STACK_OVERFLOW 0xC00000FDu
#define DEMON_W32_EXCEPTION_INVALID_HANDLE 0xC0000008u
#define DEMON_W32_EXCEPTION_UNWIND_CONSOLIDATE 0x80000029u
#define DEMON_W32_EXCEPTION_DLL_NOT_FOUND 0xC0000135u
#define DEMON_W32_EXCEPTION_ORDINAL_NOT_FOUND 0xC0000138u
#define DEMON_W32_EXCEPTION_ENTRY_POINT_NOT_FOUND 0xC0000139u
#define DEMON_W32_EXCEPTION_DLL_INIT_FAILED 0xC0000142u
#define DEMON_W32_EXCEPTION_CONTROL_C_EXIT 0xC000013Au
#define DEMON_W32_EXCEPTION_FLT_MULTIPLE_FAULTS 0xC00002B4u
#define DEMON_W32_EXCEPTION_FLT_MULTIPLE_TRAPS 0xC00002B5u
#define DEMON_W32_EXCEPTION_NAT_CONSUMPTION 0xC00002C9u
#define DEMON_W32_EXCEPTION_HEAP_CORRUPTION 0xC0000374u
#define DEMON_W32_EXCEPTION_STACK_BUFFER_OVERRUN 0xC0000409u
#define DEMON_W32_EXCEPTION_INVALID_CRUNTIME_PARAM 0xC0000417u
#define DEMON_W32_EXCEPTION_ASSERT_FAILURE 0xC0000420u
#define DEMON_W32_EXCEPTION_NO_MEMORY 0xC0000017u
#define DEMON_W32_EXCEPTION_THROW 0xE06D7363u
#define DEMON_W32_EXCEPTION_SET_THREAD_NAME 0x406d1388u
////////////////////////////////
//~ NOTE(allen): Win32 Demon Register API Codes
#define DEMON_W32_CTX_X86 0x00010000
#define DEMON_W32_CTX_X64 0x00100000
#define DEMON_W32_CTX_INTEL_CONTROL 0x0001
#define DEMON_W32_CTX_INTEL_INTEGER 0x0002
#define DEMON_W32_CTX_INTEL_SEGMENTS 0x0004
#define DEMON_W32_CTX_INTEL_FLOATS 0x0008
#define DEMON_W32_CTX_INTEL_DEBUG 0x0010
#define DEMON_W32_CTX_INTEL_EXTENDED 0x0020
#define DEMON_W32_CTX_INTEL_XSTATE 0x0040
#define DEMON_W32_CTX_X86_ALL (DEMON_W32_CTX_X86 | \
DEMON_W32_CTX_INTEL_CONTROL | DEMON_W32_CTX_INTEL_INTEGER | \
DEMON_W32_CTX_INTEL_SEGMENTS | DEMON_W32_CTX_INTEL_DEBUG | \
DEMON_W32_CTX_INTEL_EXTENDED)
#define DEMON_W32_CTX_X64_ALL (DEMON_W32_CTX_X64 | \
DEMON_W32_CTX_INTEL_CONTROL | DEMON_W32_CTX_INTEL_INTEGER | \
DEMON_W32_CTX_INTEL_SEGMENTS | DEMON_W32_CTX_INTEL_FLOATS | \
DEMON_W32_CTX_INTEL_DEBUG)
////////////////////////////////
//~ rjf: DOS Header Types
// this is the "MZ" as a 16-bit short
#define DEMON_DOS_MAGIC 0x5a4d
#pragma pack(push,1)
typedef struct DEMON_DosHeader DEMON_DosHeader;
struct DEMON_DosHeader
{
U16 magic;
U16 last_page_size;
U16 page_count;
U16 reloc_count;
U16 paragraph_header_size;
U16 min_paragraph;
U16 max_paragraph;
U16 init_ss;
U16 init_sp;
U16 checksum;
U16 init_ip;
U16 init_cs;
U16 reloc_table_file_off;
U16 overlay_number;
U16 reserved[4];
U16 oem_id;
U16 oem_info;
U16 reserved2[10];
U32 coff_file_offset;
};
#pragma pack(pop)
////////////////////////////////
//~ rjf: Coff Header Types
#define DEMON_PE_MAGIC 0x00004550u
typedef U16 DEMON_CoffMachineType;
enum{
DEMON_CoffMachineType_UNKNOWN = 0x0,
DEMON_CoffMachineType_X86 = 0x14c,
DEMON_CoffMachineType_X64 = 0x8664,
DEMON_CoffMachineType_ARM33 = 0x1d3,
DEMON_CoffMachineType_ARM = 0x1c0,
DEMON_CoffMachineType_ARM64 = 0xaa64,
DEMON_CoffMachineType_ARMNT = 0x1c4,
DEMON_CoffMachineType_EBC = 0xebc,
DEMON_CoffMachineType_IA64 = 0x200,
DEMON_CoffMachineType_M32R = 0x9041,
DEMON_CoffMachineType_MIPS16 = 0x266,
DEMON_CoffMachineType_MIPSFPU = 0x366,
DEMON_CoffMachineType_MIPSFPU16 = 0x466,
DEMON_CoffMachineType_POWERPC = 0x1f0,
DEMON_CoffMachineType_POWERPCFP = 0x1f1,
DEMON_CoffMachineType_R4000 = 0x166,
DEMON_CoffMachineType_RISCV32 = 0x5032,
DEMON_CoffMachineType_RISCV64 = 0x5064,
DEMON_CoffMachineType_RISCV128 = 0x5128,
DEMON_CoffMachineType_SH3 = 0x1a2,
DEMON_CoffMachineType_SH3DSP = 0x1a3,
DEMON_CoffMachineType_SH4 = 0x1a6,
DEMON_CoffMachineType_SH5 = 0x1a8,
DEMON_CoffMachineType_THUMB = 0x1c2,
DEMON_CoffMachineType_WCEMIPSV2 = 0x169,
DEMON_CoffMachineType_COUNT = 25
};
typedef U16 DEMON_CoffFlags;
enum{
DEMON_CoffFlag_RELOC_STRIPPED = (1 << 0),
DEMON_CoffFlag_EXECUTABLE_IMAGE = (1 << 1),
DEMON_CoffFlag_LINE_NUMS_STRIPPED = (1 << 2),
DEMON_CoffFlag_SYM_STRIPPED = (1 << 3),
DEMON_CoffFlag_RESERVED_0 = (1 << 4),
DEMON_CoffFlag_LARGE_ADDRESS_AWARE = (1 << 5),
DEMON_CoffFlag_RESERVED_1 = (1 << 6),
DEMON_CoffFlag_RESERVED_2 = (1 << 7),
DEMON_CoffFlag_32BIT_MACHINE = (1 << 8),
DEMON_CoffFlag_DEBUG_STRIPPED = (1 << 9),
DEMON_CoffFlag_REMOVABLE_RUN_FROM_SWAP = (1 << 10),
DEMON_CoffFlag_NET_RUN_FROM_SWAP = (1 << 11),
DEMON_CoffFlag_SYSTEM = (1 << 12),
DEMON_CoffFlag_DLL = (1 << 13),
DEMON_CoffFlag_UP_SYSTEM_ONLY = (1 << 14),
DEMON_CoffFlag_BYTES_RESERVED_HI = (1 << 15),
};
#pragma pack(push,1)
typedef struct DEMON_CoffHeader DEMON_CoffHeader;
struct DEMON_CoffHeader
{
DEMON_CoffMachineType machine;
U16 section_count;
U32 time_date_stamp;
// TODO: rename to "unix_timestamp"
U32 pointer_to_symbol_table;
U32 number_of_symbols;
// TODO: rename to "symbol_count"
U16 size_of_optional_header;
// TODO: rename to "optional_header_size"
DEMON_CoffFlags flags;
};
#pragma pack(pop)
////////////////////////////////
//~ rjf: PE Header Types
#pragma pack(push, 1)
typedef U16 DEMON_PeWindowsSubsystem;
enum{
DEMON_PeWindowsSubsystem_UNKNOWN = 0,
DEMON_PeWindowsSubsystem_NATIVE = 1,
DEMON_PeWindowsSubsystem_WINDOWS_GUI = 2,
DEMON_PeWindowsSubsystem_WINDOWS_CUI = 3,
DEMON_PeWindowsSubsystem_OS2_CUI = 5,
DEMON_PeWindowsSubsystem_POSIX_CUI = 7,
DEMON_PeWindowsSubsystem_NATIVE_WINDOWS = 8,
DEMON_PeWindowsSubsystem_WINDOWS_CE_GUI = 9,
DEMON_PeWindowsSubsystem_EFI_APPLICATION = 10,
DEMON_PeWindowsSubsystem_EFI_BOOT_SERVICE_DRIVER = 11,
DEMON_PeWindowsSubsystem_EFI_RUNTIME_DRIVER = 12,
DEMON_PeWindowsSubsystem_EFI_ROM = 13,
DEMON_PeWindowsSubsystem_XBOX = 14,
DEMON_PeWindowsSubsystem_WINDOWS_BOOT_APPLICATION = 16,
DEMON_PeWindowsSubsystem_COUNT = 14
};
typedef U16 DEMON_DllCharacteristics;
enum{
DEMON_DllCharacteristic_HIGH_ENTROPY_VA = (1 << 5),
DEMON_DllCharacteristic_DYNAMIC_BASE = (1 << 6),
DEMON_DllCharacteristic_FORCE_INTEGRITY = (1 << 7),
DEMON_DllCharacteristic_NX_COMPAT = (1 << 8),
DEMON_DllCharacteristic_NO_ISOLATION = (1 << 9),
DEMON_DllCharacteristic_NO_SEH = (1 << 10),
DEMON_DllCharacteristic_NO_BIND = (1 << 11),
DEMON_DllCharacteristic_APPCONTAINER = (1 << 12),
DEMON_DllCharacteristic_WDM_DRIVER = (1 << 13),
DEMON_DllCharacteristic_GUARD_CF = (1 << 14),
DEMON_DllCharacteristic_TERMINAL_SERVER_AWARE = (1 << 15),
};
typedef struct DEMON_PeOptionalHeader32 DEMON_PeOptionalHeader32;
struct DEMON_PeOptionalHeader32
{
U16 magic;
U8 major_linker_version;
U8 minor_linker_version;
U32 sizeof_code;
U32 sizeof_inited_data;
U32 sizeof_uninited_data;
U32 entry_point_va;
U32 code_base;
U32 data_base;
U32 image_base;
U32 section_alignment;
U32 file_alignment;
U16 major_os_ver;
U16 minor_os_ver;
U16 major_img_ver;
U16 minor_img_ver;
U16 major_subsystem_ver;
U16 minor_subsystem_ver;
U32 win32_version_value;
U32 sizeof_image;
U32 sizeof_headers;
U32 check_sum;
DEMON_PeWindowsSubsystem subsystem;
DEMON_DllCharacteristics dll_characteristics;
U32 sizeof_stack_reserve;
U32 sizeof_stack_commit;
U32 sizeof_heap_reserve;
U32 sizeof_heap_commit;
U32 loader_flags;
U32 data_dir_count;
};
typedef struct DEMON_PeOptionalHeader32Plus DEMON_PeOptionalHeader32Plus;
struct DEMON_PeOptionalHeader32Plus
{
U16 magic;
U8 major_linker_version;
U8 minor_linker_version;
U32 sizeof_code;
U32 sizeof_inited_data;
U32 sizeof_uninited_data;
U32 entry_point_va;
U32 code_base;
U64 image_base;
U32 section_alignment;
U32 file_alignment;
U16 major_os_ver;
U16 minor_os_ver;
U16 major_img_ver;
U16 minor_img_ver;
U16 major_subsystem_ver;
U16 minor_subsystem_ver;
U32 win32_version_value;
U32 sizeof_image;
U32 sizeof_headers;
U32 check_sum;
DEMON_PeWindowsSubsystem subsystem;
DEMON_DllCharacteristics dll_characteristics;
U64 sizeof_stack_reserve;
U64 sizeof_stack_commit;
U64 sizeof_heap_reserve;
U64 sizeof_heap_commit;
U32 loader_flags;
U32 data_dir_count;
};
#pragma pack(pop)
////////////////////////////////
//~ rjf: Helpers
internal DEMON_W32_Ext* demon_w32_ext_alloc(void);
internal DEMON_W32_Ext* demon_w32_ext(DEMON_Entity *entity);
internal U64 demon_w32_read_memory(HANDLE process_handle, void *dst, U64 src_address, U64 size);
internal B32 demon_w32_write_memory(HANDLE process_handle, U64 dst_address, void *src, U64 size);
internal String8 demon_w32_read_memory_str(Arena *arena, HANDLE process_handle, U64 address);
internal String16 demon_w32_read_memory_str16(Arena *arena, HANDLE process_handle, U64 address);
#define demon_w32_read_struct(h,dst,src) demon_w32_read_memory((h), (dst), (src), sizeof(*(dst)))
internal DEMON_W32_ImageInfo demon_w32_image_info_from_base(HANDLE process_handle, U64 base);
internal DWORD demon_w32_inject_thread(DEMON_Entity *process, U64 start_address);
internal U16 demon_w32_real_tag_word_from_xsave(XSAVE_FORMAT *fxsave);
internal U16 demon_w32_xsave_tag_word_from_real_tag_word(U16 ftw);
internal DWORD demon_w32_win32_from_memory_protect_flags(DEMON_MemoryProtectFlags flags);
////////////////////////////////
//~ rjf: Experiments
internal void demon_w32_peak_at_tls(DEMON_Handle handle);
#endif //DEMON_OS_WIN32_H
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+225
View File
@@ -0,0 +1,225 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[] =
{
{ str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("exit"), str8_lit_comp("Exits the debugger."), str8_lit_comp("quit,close,abort"), str8_lit_comp("Exit"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_X, {0, 0}},
{ str8_lit_comp("command_fast_path"), str8_lit_comp("Performs the fast path for the command named by the argument."), str8_lit_comp(""), str8_lit_comp("Command Fast Path"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_CmdSpec, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("error"), str8_lit_comp("Notifies of an error."), str8_lit_comp(""), str8_lit_comp("Error"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_String, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("launch_and_run"), str8_lit_comp("Starts debugging a new instance of a target, then runs."), str8_lit_comp("launch,start,run,target"), str8_lit_comp("Launch and Run"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_EntityList, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Play, {DF_EntityKind_Target, 0}},
{ str8_lit_comp("launch_and_init"), str8_lit_comp("Starts debugging a new instance of a target, then stops at the program's entry point."), str8_lit_comp("launch,start,entry,point"), str8_lit_comp("Launch and Initialize"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_EntityList, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_PlayStepForward, {DF_EntityKind_Target, 0}},
{ str8_lit_comp("kill"), str8_lit_comp("Kills the specified existing debugged process(es)."), str8_lit_comp("stop,kill"), str8_lit_comp("Kill"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_EntityList, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Stop, {DF_EntityKind_Process, 0}},
{ str8_lit_comp("kill_all"), str8_lit_comp("Kills all debugged child processes."), str8_lit_comp("stop,kill,all"), str8_lit_comp("Kill All"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Stop, {0, 0}},
{ str8_lit_comp("detach"), str8_lit_comp("Detaches the specified debugged process."), str8_lit_comp("detach"), str8_lit_comp("Detach"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_EntityList, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Null, {DF_EntityKind_Process, 0}},
{ str8_lit_comp("continue"), str8_lit_comp("Continues all halted threads."), str8_lit_comp(""), str8_lit_comp("Continue"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Play, {0, 0}},
{ str8_lit_comp("step_into_inst"), str8_lit_comp("Performs a step that goes into calls, at the instruction level."), str8_lit_comp("single,step,thread"), str8_lit_comp("Step Into (Assembly)"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_StepInto, {0, 0}},
{ str8_lit_comp("step_over_inst"), str8_lit_comp("Performs a step that skips calls, at the instruction level."), str8_lit_comp("single,step,thread"), str8_lit_comp("Step Over (Assembly)"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_StepOver, {0, 0}},
{ str8_lit_comp("step_into_line"), str8_lit_comp("Performs a step that goes into calls, at the source code line level."), str8_lit_comp("step,thread"), str8_lit_comp("Step Into (Line)"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_StepInto, {0, 0}},
{ str8_lit_comp("step_over_line"), str8_lit_comp("Performs a step that skips calls, at the source code line level."), str8_lit_comp("step,thread"), str8_lit_comp("Step Over (Line)"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_StepOver, {0, 0}},
{ str8_lit_comp("step_out"), str8_lit_comp("Runs to the end of the current function and exits it."), str8_lit_comp(""), str8_lit_comp("Step Out"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_StepOut, {0, 0}},
{ str8_lit_comp("run_to_address"), str8_lit_comp("Runs the selected thread to the specified address."), str8_lit_comp(""), str8_lit_comp("Run To Address"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_VirtualAddr, DF_CmdParamSlot_Null}, DF_CmdQueryRule_VirtualAddr, DF_IconKind_PlayStepForward, {0, 0}},
{ str8_lit_comp("run_to_module_offset"), str8_lit_comp("Runs the selected thread to the specified offset within the current module."), str8_lit_comp(""), str8_lit_comp("Run To Module Offset"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_VirtualOff, DF_CmdParamSlot_Null}, DF_CmdQueryRule_VirtualOff, DF_IconKind_PlayStepForward, {0, 0}},
{ str8_lit_comp("halt"), str8_lit_comp("Halts all running processes."), str8_lit_comp("pause"), str8_lit_comp("Halt"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Pause, {0, 0}},
{ str8_lit_comp("soft_halt_refresh"), str8_lit_comp("Interrupts all running processes to collect data, and then resumes them."), str8_lit_comp(""), str8_lit_comp("Soft Halt Refresh"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Refresh, {0, 0}},
{ str8_lit_comp("set_thread_ip"), str8_lit_comp("Sets the passed thread's instruction pointer at the passed address."), str8_lit_comp(""), str8_lit_comp("Set Thread IP"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_VirtualAddr, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("run"), str8_lit_comp("Runs all targets after starting them if they have not been started yet."), str8_lit_comp("play"), str8_lit_comp("Run"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Play, {0, 0}},
{ str8_lit_comp("restart"), str8_lit_comp("Kills all running processes, then restarts the targets which were used to launch all current processes (if any)."), str8_lit_comp("restart,retry"), str8_lit_comp("Restart"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Redo, {0, 0}},
{ str8_lit_comp("step_into"), str8_lit_comp("Steps once, possibly into function calls, for either line or instructions."), str8_lit_comp(""), str8_lit_comp("Step Into"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_StepInto, {0, 0}},
{ str8_lit_comp("step_over"), str8_lit_comp("Steps once, always over function calls, for either line or instructions."), str8_lit_comp(""), str8_lit_comp("Step Over"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_StepOver, {0, 0}},
{ str8_lit_comp("run_to_cursor"), str8_lit_comp("Runs the selected thread to the current cursor."), str8_lit_comp(""), str8_lit_comp("Run To Cursor"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_View, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Play, {0, 0}},
{ str8_lit_comp("set_next_statement"), str8_lit_comp("Sets the selected thread's instruction pointer to the cursor's position."), str8_lit_comp(""), str8_lit_comp("Set Next Statement"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_View, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_RightArrow, {0, 0}},
{ str8_lit_comp("enable_solo_stepping_mode"), str8_lit_comp("Enables 'solo stepping mode', which suspends all non-selected threads before stepping."), str8_lit_comp("solo,stepping,mode,suspend"), str8_lit_comp("Enable Solo Stepping Mode"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Thread, {0, 0}},
{ str8_lit_comp("disable_solo_stepping_mode"), str8_lit_comp("Disables 'solo stepping mode', which suspends all non-selected threads before stepping."), str8_lit_comp("solo,stepping,mode,suspend"), str8_lit_comp("Disable Solo Stepping Mode"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Thread, {0, 0}},
{ str8_lit_comp("select_thread"), str8_lit_comp("Selects a thread."), str8_lit_comp(""), str8_lit_comp("Select Thread"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Null, {DF_EntityKind_Thread, 0}},
{ str8_lit_comp("select_thread_window"), str8_lit_comp("Selects a thread for the active window, overriding the global selected thread."), str8_lit_comp(""), str8_lit_comp("Select Thread On Window"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Window, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Null, {DF_EntityKind_Thread, 0}},
{ str8_lit_comp("select_thread_view"), str8_lit_comp("Selects a thread for the active view, overriding the global and per-window selected threads."), str8_lit_comp(""), str8_lit_comp("Select Thread On View"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_View, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Null, {DF_EntityKind_Thread, 0}},
{ str8_lit_comp("select_unwind"), str8_lit_comp("Selects an unwind frame number for the selected thread."), str8_lit_comp(""), str8_lit_comp("Select Unwind"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Index, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("up_one_frame"), str8_lit_comp("Selects the callstack frame above the currently selected."), str8_lit_comp(""), str8_lit_comp("Up One Frame"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_UpArrow, {0, 0}},
{ str8_lit_comp("down_one_frame"), str8_lit_comp("Selects the callstack frame below the currently selected."), str8_lit_comp(""), str8_lit_comp("Down One Frame"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_DownArrow, {0, 0}},
{ str8_lit_comp("freeze_thread"), str8_lit_comp("Freezes the passed thread."), str8_lit_comp(""), str8_lit_comp("Freeze Thread"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Locked, {DF_EntityKind_Thread, 0}},
{ str8_lit_comp("thaw_thread"), str8_lit_comp("Thaws the passed thread."), str8_lit_comp(""), str8_lit_comp("Thaw Thread"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Unlocked, {DF_EntityKind_Thread, 0}},
{ str8_lit_comp("freeze_process"), str8_lit_comp("Freezes the passed process."), str8_lit_comp(""), str8_lit_comp("Freeze Process"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Locked, {DF_EntityKind_Process, 0}},
{ str8_lit_comp("thaw_process"), str8_lit_comp("Thaws the passed process."), str8_lit_comp(""), str8_lit_comp("Thaw Process"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Unlocked, {DF_EntityKind_Process, 0}},
{ str8_lit_comp("freeze_machine"), str8_lit_comp("Freezes the passed machine."), str8_lit_comp(""), str8_lit_comp("Freeze Machine"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Locked, {DF_EntityKind_Machine, 0}},
{ str8_lit_comp("thaw_machine"), str8_lit_comp("Thaws the passed machine."), str8_lit_comp(""), str8_lit_comp("Thaw Machine"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Unlocked, {DF_EntityKind_Machine, 0}},
{ str8_lit_comp("freeze_local_machine"), str8_lit_comp("Freezes the local machine."), str8_lit_comp(""), str8_lit_comp("Freeze Local Machine"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Machine, {0, 0}},
{ str8_lit_comp("thaw_local_machine"), str8_lit_comp("Thaws the local machine."), str8_lit_comp(""), str8_lit_comp("Thaw Local Machine"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Machine, {0, 0}},
{ str8_lit_comp("inc_ui_font_scale"), str8_lit_comp("Increases the font size used for UI."), str8_lit_comp(""), str8_lit_comp("Increase UI Font Scale"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("dec_ui_font_scale"), str8_lit_comp("Decreases the font size used for UI."), str8_lit_comp(""), str8_lit_comp("Decrease UI Font Scale"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("inc_code_font_scale"), str8_lit_comp("Increases the font size used for code."), str8_lit_comp(""), str8_lit_comp("Increase Code Font Scale"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("dec_code_font_scale"), str8_lit_comp("Decreases the font size used for code."), str8_lit_comp(""), str8_lit_comp("Decrease Code Font Scale"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("open_window"), str8_lit_comp("Opens a new window."), str8_lit_comp(""), str8_lit_comp("Open New Window"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Window, {0, 0}},
{ str8_lit_comp("close_window"), str8_lit_comp("Closes an opened window."), str8_lit_comp(""), str8_lit_comp("Close Window"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Window, {0, 0}},
{ str8_lit_comp("toggle_fullscreen"), str8_lit_comp("Toggles fullscreen view on the active window."), str8_lit_comp(""), str8_lit_comp("Toggle Fullscreen"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Window, {0, 0}},
{ str8_lit_comp("reset_to_default_panels"), str8_lit_comp("Resets the window to the default panel layout."), str8_lit_comp("panel"), str8_lit_comp("Reset To Default Panel Layout"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Window, {0, 0}},
{ str8_lit_comp("new_panel_right"), str8_lit_comp("Creates a new panel to the right of the active panel."), str8_lit_comp("panel"), str8_lit_comp("Split Panel Vertically"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Panel, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_XSplit, {0, 0}},
{ str8_lit_comp("new_panel_down"), str8_lit_comp("Creates a new panel at the bottom of the active panel."), str8_lit_comp("panel"), str8_lit_comp("Split Panel Horizontally"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Panel, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_YSplit, {0, 0}},
{ str8_lit_comp("rotate_panel_columns"), str8_lit_comp("Rotates all panels at the closest column level of the panel hierarchy."), str8_lit_comp(""), str8_lit_comp("Rotate Panel Columns"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Panel, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("next_panel"), str8_lit_comp("Cycles the active panel forward."), str8_lit_comp(""), str8_lit_comp("Focus Next Panel"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_RightArrow, {0, 0}},
{ str8_lit_comp("prev_panel"), str8_lit_comp("Cycles the active panel backwards."), str8_lit_comp(""), str8_lit_comp("Focus Previous Panel"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_LeftArrow, {0, 0}},
{ str8_lit_comp("focus_panel"), str8_lit_comp("Focuses a new panel."), str8_lit_comp(""), str8_lit_comp("Focus Panel"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Panel, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("focus_panel_right"), str8_lit_comp("Focuses a panel rightward of the currently focused panel."), str8_lit_comp(""), str8_lit_comp("Focus Panel Right"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_RightArrow, {0, 0}},
{ str8_lit_comp("focus_panel_left"), str8_lit_comp("Focuses a panel leftward of the currently focused panel."), str8_lit_comp(""), str8_lit_comp("Focus Panel Left"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_LeftArrow, {0, 0}},
{ str8_lit_comp("focus_panel_up"), str8_lit_comp("Focuses a panel upward of the currently focused panel."), str8_lit_comp(""), str8_lit_comp("Focus Panel Up"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_UpArrow, {0, 0}},
{ str8_lit_comp("focus_panel_down"), str8_lit_comp("Focuses a panel downward of the currently focused panel."), str8_lit_comp(""), str8_lit_comp("Focus Panel Down"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_DownArrow, {0, 0}},
{ str8_lit_comp("undo"), str8_lit_comp("Undoes the previous action."), str8_lit_comp(""), str8_lit_comp("Undo"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Undo, {0, 0}},
{ str8_lit_comp("redo"), str8_lit_comp("Redoes the first previously undone action."), str8_lit_comp(""), str8_lit_comp("Redo"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Redo, {0, 0}},
{ str8_lit_comp("go_back"), str8_lit_comp("Returns to the previously selected panel and tab in recorded history."), str8_lit_comp(""), str8_lit_comp("Go Back"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Panel, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_LeftArrow, {0, 0}},
{ str8_lit_comp("go_forward"), str8_lit_comp("Returns to the next selected panel and tab in recorded history."), str8_lit_comp(""), str8_lit_comp("Go Forward"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Panel, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_RightArrow, {0, 0}},
{ str8_lit_comp("close_panel"), str8_lit_comp("Closes the currently active panel."), str8_lit_comp(""), str8_lit_comp("Close Panel"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Panel, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_ClosePanel, {0, 0}},
{ str8_lit_comp("next_tab"), str8_lit_comp("Focuses the next tab on the active panel."), str8_lit_comp(""), str8_lit_comp("Focus Next Tab"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_RightArrow, {0, 0}},
{ str8_lit_comp("prev_tab"), str8_lit_comp("Focuses the previous tab on the active panel."), str8_lit_comp(""), str8_lit_comp("Focus Previous Tab"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_LeftArrow, {0, 0}},
{ str8_lit_comp("move_tab_right"), str8_lit_comp("Moves the selected tab right one slot."), str8_lit_comp(""), str8_lit_comp("Move Tab Right"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_RightArrow, {0, 0}},
{ str8_lit_comp("move_tab_left"), str8_lit_comp("Moves the selected tab left one slot."), str8_lit_comp(""), str8_lit_comp("Move Tab Left"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_LeftArrow, {0, 0}},
{ str8_lit_comp("close_tab"), str8_lit_comp("Closes the currently opened tab."), str8_lit_comp(""), str8_lit_comp("Close Tab"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_X, {0, 0}},
{ str8_lit_comp("move_tab"), str8_lit_comp("Moves a tab to a new panel."), str8_lit_comp(""), str8_lit_comp("Move Tab"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("tab_bar_top"), str8_lit_comp("Anchors a panel's tab bar to the top of the panel."), str8_lit_comp(""), str8_lit_comp("Anchor Tab Bar To Top"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_UpArrow, {0, 0}},
{ str8_lit_comp("tab_bar_bottom"), str8_lit_comp("Anchors a panel's tab bar to the bottom of the panel."), str8_lit_comp(""), str8_lit_comp("Anchor Tab Bar To Bottom"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_DownArrow, {0, 0}},
{ str8_lit_comp("tab_bar_enable"), str8_lit_comp("Enables a panel's tab bar."), str8_lit_comp(""), str8_lit_comp("Enable Tab Bar"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("tab_bar_disable"), str8_lit_comp("Disables a panel's tab bar."), str8_lit_comp(""), str8_lit_comp("Disable Tab Bar"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("tab_bar_history_mode_enable"), str8_lit_comp("Enables history mode for a panel's tab bar, which orders and manages tabs as recorded history of views."), str8_lit_comp(""), str8_lit_comp("Enable Tab Bar History Mode"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("tab_bar_history_mode_disable"), str8_lit_comp("Disables history mode for a panel's tab bar."), str8_lit_comp(""), str8_lit_comp("Disable Tab Bar History Mode"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("set_current_path"), str8_lit_comp("Sets the debugger's current path, which is used as a starting point when browsing for files."), str8_lit_comp(""), str8_lit_comp("Set Current Path"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_FilePath, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_FilePath, DF_IconKind_FileOutline, {0, 0}},
{ str8_lit_comp("open"), str8_lit_comp("Opens a file."), str8_lit_comp("code,source,file"), str8_lit_comp("Open"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_FilePath, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_FilePath, DF_IconKind_FileOutline, {0, 0}},
{ str8_lit_comp("reload"), str8_lit_comp("Reloads a loaded file."), str8_lit_comp("code,source,file,reload"), str8_lit_comp("Reload"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_FileOutline, {DF_EntityKind_File, 0}},
{ str8_lit_comp("reload_active"), str8_lit_comp("Reloads the active file."), str8_lit_comp("code,source,file,reload"), str8_lit_comp("Reload Active File"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Panel, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_FileOutline, {0, 0}},
{ str8_lit_comp("switch"), str8_lit_comp("Switches to a loaded file."), str8_lit_comp("code,source,file"), str8_lit_comp("Switch"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Window, DF_CmdParamSlot_Panel, DF_CmdParamSlot_Entity}, DF_CmdQueryRule_Entity, DF_IconKind_FileOutline, {DF_EntityKind_File, DF_EntityFlag_IsFolder}},
{ str8_lit_comp("set_file_override_link_src"), str8_lit_comp("Sets the source path for an override file link."), str8_lit_comp(""), str8_lit_comp("Set File Override Link Source"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("set_file_override_link_dst"), str8_lit_comp("Sets the destination path for an override file link."), str8_lit_comp(""), str8_lit_comp("Set File Override Link Destination"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("set_file_replacement_path"), str8_lit_comp("Sets the path which should be used as the replacement for the passed file."), str8_lit_comp(""), str8_lit_comp("Set File Replacement Path"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("load_user"), str8_lit_comp("Loads and applies a user file."), str8_lit_comp("load,user,profile,layout"), str8_lit_comp("Load User"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_FilePath, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_FilePath, DF_IconKind_Person, {0, 0}},
{ str8_lit_comp("load_profile"), str8_lit_comp("Loads and applies a profile file."), str8_lit_comp("profile,project,session"), str8_lit_comp("Load Profile"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_FilePath, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_FilePath, DF_IconKind_Briefcase, {0, 0}},
{ str8_lit_comp("apply_user_data"), str8_lit_comp("Applies user data from the active user file."), str8_lit_comp(""), str8_lit_comp("Apply User Data"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("apply_profile_data"), str8_lit_comp("Applies profile data from the active profile file."), str8_lit_comp(""), str8_lit_comp("Apply Profile Data"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("write_user_data"), str8_lit_comp("Writes user data to the active user file."), str8_lit_comp(""), str8_lit_comp("Write User Data"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("write_profile_data"), str8_lit_comp("Writes profile data to the active profile file."), str8_lit_comp(""), str8_lit_comp("Write Profile Data"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_left"), str8_lit_comp("Moves the cursor or selection left."), str8_lit_comp(""), str8_lit_comp("Move Left"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_right"), str8_lit_comp("Moves the cursor or selection right."), str8_lit_comp(""), str8_lit_comp("Move Right"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_up"), str8_lit_comp("Moves the cursor or selection up."), str8_lit_comp(""), str8_lit_comp("Move Up"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_down"), str8_lit_comp("Moves the cursor or selection down."), str8_lit_comp(""), str8_lit_comp("Move Down"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_left_select"), str8_lit_comp("Moves the cursor or selection left, while selecting."), str8_lit_comp(""), str8_lit_comp("Move Left Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_right_select"), str8_lit_comp("Moves the cursor or selection right, while selecting."), str8_lit_comp(""), str8_lit_comp("Move Right Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_up_select"), str8_lit_comp("Moves the cursor or selection up, while selecting."), str8_lit_comp(""), str8_lit_comp("Move Up Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_down_select"), str8_lit_comp("Moves the cursor or selection down, while selecting."), str8_lit_comp(""), str8_lit_comp("Move Down Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_left_chunk"), str8_lit_comp("Moves the cursor or selection left one chunk."), str8_lit_comp(""), str8_lit_comp("Move Left Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_right_chunk"), str8_lit_comp("Moves the cursor or selection right one chunk."), str8_lit_comp(""), str8_lit_comp("Move Right Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_up_chunk"), str8_lit_comp("Moves the cursor or selection up one chunk."), str8_lit_comp(""), str8_lit_comp("Move Up Chunk"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_down_chunk"), str8_lit_comp("Moves the cursor or selection down one chunk."), str8_lit_comp(""), str8_lit_comp("Move Down Chunk"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_up_page"), str8_lit_comp("Moves the cursor or selection up one page."), str8_lit_comp(""), str8_lit_comp("Move Up Page"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_down_page"), str8_lit_comp("Moves the cursor or selection down one page."), str8_lit_comp(""), str8_lit_comp("Move Down Page"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_up_whole"), str8_lit_comp("Moves the cursor or selection to the beginning of the relevant content."), str8_lit_comp(""), str8_lit_comp("Move Up Whole"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_down_whole"), str8_lit_comp("Moves the cursor or selection to the end of the relevant content."), str8_lit_comp(""), str8_lit_comp("Move Down Whole"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_left_chunk_select"), str8_lit_comp("Moves the cursor or selection left one chunk."), str8_lit_comp(""), str8_lit_comp("Move Left Chunk Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_right_chunk_select"), str8_lit_comp("Moves the cursor or selection right one chunk."), str8_lit_comp(""), str8_lit_comp("Move Right Chunk Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_up_chunk_select"), str8_lit_comp("Moves the cursor or selection up one chunk."), str8_lit_comp(""), str8_lit_comp("Move Up Chunk Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_down_chunk_select"), str8_lit_comp("Moves the cursor or selection down one chunk."), str8_lit_comp(""), str8_lit_comp("Move Down Chunk Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_up_page_select"), str8_lit_comp("Moves the cursor or selection up one page, while selecting."), str8_lit_comp(""), str8_lit_comp("Move Up Page Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_down_page_select"), str8_lit_comp("Moves the cursor or selection down one page, while selecting."), str8_lit_comp(""), str8_lit_comp("Move Down Page Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_up_whole_select"), str8_lit_comp("Moves the cursor or selection to the beginning of the relevant content, while selecting."), str8_lit_comp(""), str8_lit_comp("Move Up Whole Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_down_whole_select"), str8_lit_comp("Moves the cursor or selection to the end of the relevant content, while selecting."), str8_lit_comp(""), str8_lit_comp("Move Down Whole Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_home"), str8_lit_comp("Moves the cursor to the beginning of the line."), str8_lit_comp(""), str8_lit_comp("Move Home"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_end"), str8_lit_comp("Moves the cursor to the end of the line."), str8_lit_comp(""), str8_lit_comp("Move End"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_home_select"), str8_lit_comp("Moves the cursor to the beginning of the line, while selecting."), str8_lit_comp(""), str8_lit_comp("Move Home Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("move_end_select"), str8_lit_comp("Moves the cursor to the end of the line, while selecting."), str8_lit_comp(""), str8_lit_comp("Move End Select"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("select_all"), str8_lit_comp("Selects everything possible."), str8_lit_comp(""), str8_lit_comp("Select All"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("delete_single"), str8_lit_comp("Deletes a single element to the right of the cursor, or the active selection."), str8_lit_comp(""), str8_lit_comp("Delete Single"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("delete_chunk"), str8_lit_comp("Deletes a chunk to the right of the cursor, or the active selection."), str8_lit_comp(""), str8_lit_comp("Delete Chunk"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("backspace_single"), str8_lit_comp("Deletes a single element to the left of the cursor, or the active selection."), str8_lit_comp(""), str8_lit_comp("Backspace Single"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("backspace_chunk"), str8_lit_comp("Deletes a chunk to the left of the cursor, or the active selection."), str8_lit_comp(""), str8_lit_comp("Backspace Chunk"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("copy"), str8_lit_comp("Copies the active selection to the clipboard."), str8_lit_comp(""), str8_lit_comp("Copy"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Clipboard, {0, 0}},
{ str8_lit_comp("cut"), str8_lit_comp("Copies the active selection to the clipboard, then deletes it."), str8_lit_comp(""), str8_lit_comp("Cut"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Clipboard, {0, 0}},
{ str8_lit_comp("paste"), str8_lit_comp("Pastes the current contents of the clipboard."), str8_lit_comp(""), str8_lit_comp("Paste"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Clipboard, {0, 0}},
{ str8_lit_comp("insert_text"), str8_lit_comp("Inserts the text that was used to cause this command."), str8_lit_comp(""), str8_lit_comp("Insert Text"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("goto_line"), str8_lit_comp("Jumps to a line number in the current code file."), str8_lit_comp(""), str8_lit_comp("Go To Line"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_TextPoint, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_TextPoint, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("goto_address"), str8_lit_comp("Jumps to an address in the current memory or disassembly view."), str8_lit_comp(""), str8_lit_comp("Go To Address"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*1), {DF_CmdParamSlot_VirtualAddr, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_VirtualAddr, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("center_cursor"), str8_lit_comp("Snaps the current code view to center the cursor."), str8_lit_comp(""), str8_lit_comp("Center Cursor"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("contain_cursor"), str8_lit_comp("Snaps the current code view to contain the cursor."), str8_lit_comp(""), str8_lit_comp("Contain Cursor"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("find_text_forward"), str8_lit_comp("Searches the current code file forward (from the cursor) for a string."), str8_lit_comp(""), str8_lit_comp("Find Text (Forward)"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*1) | (DF_CmdSpecFlag_QueryUsesOldInput*1) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*1), {DF_CmdParamSlot_String, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_SearchString, DF_IconKind_Find, {0, 0}},
{ str8_lit_comp("find_text_backward"), str8_lit_comp("Searches the current code file backwards (from the cursor) for a string."), str8_lit_comp(""), str8_lit_comp("Find Text (Backwards)"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*1) | (DF_CmdSpecFlag_QueryUsesOldInput*1) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*1), {DF_CmdParamSlot_String, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_SearchString, DF_IconKind_Find, {0, 0}},
{ str8_lit_comp("find_next"), str8_lit_comp("Searches the current code file forward (from the cursor) for the last searched string."), str8_lit_comp(""), str8_lit_comp("Find Next"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*1) | (DF_CmdSpecFlag_QueryUsesOldInput*1) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_String, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Find, {0, 0}},
{ str8_lit_comp("find_prev"), str8_lit_comp("Searches the current code file backwards (from the cursor) for the last searched string."), str8_lit_comp(""), str8_lit_comp("Find Previous"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*1) | (DF_CmdSpecFlag_QueryUsesOldInput*1) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_String, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Find, {0, 0}},
{ str8_lit_comp("find_thread"), str8_lit_comp("Jumps to the passed thread in either source code, disassembly, or both if they're already open."), str8_lit_comp(""), str8_lit_comp("Find Thread"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Find, {DF_EntityKind_Thread, 0}},
{ str8_lit_comp("find_selected_thread"), str8_lit_comp("Jumps to the selected thread in either source code, disassembly, or both if they're already open."), str8_lit_comp(""), str8_lit_comp("Find Selected Thread"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Find, {0, 0}},
{ str8_lit_comp("goto_name"), str8_lit_comp("Searches for the passed string as a file, a symbol in debug info, and more, then jumps to it if possible."), str8_lit_comp(""), str8_lit_comp("Go To Name"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*1), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_String, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("goto_name_at_cursor"), str8_lit_comp("Searches for the text at the cursor as a file, a symbol in debug info, and more, then jumps to it if possible."), str8_lit_comp(""), str8_lit_comp("Go To Name At Cursor"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("toggle_watch_expr"), str8_lit_comp("Adds or removes an expression to an opened watch view."), str8_lit_comp(""), str8_lit_comp("Toggle Watch Expression"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Binoculars, {0, 0}},
{ str8_lit_comp("toggle_watch_expr_at_cursor"), str8_lit_comp("Adds or removes the expression that the cursor or selection is currently over to an opened watch view."), str8_lit_comp(""), str8_lit_comp("Toggle Watch Expression At Cursor"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Binoculars, {0, 0}},
{ str8_lit_comp("open_file_memory"), str8_lit_comp("Opens a memory view for the passed file."), str8_lit_comp(""), str8_lit_comp("Open File Memory"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Grid, {DF_EntityKind_File, 0}},
{ str8_lit_comp("open_process_memory"), str8_lit_comp("Opens a memory view for the passed process."), str8_lit_comp(""), str8_lit_comp("Open Process Memory"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Grid, {DF_EntityKind_Process, 0}},
{ str8_lit_comp("open_selected_process_memory"), str8_lit_comp("Opens a memory view for the selected process."), str8_lit_comp(""), str8_lit_comp("Open Selected Process Memory"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Grid, {0, 0}},
{ str8_lit_comp("set_columns"), str8_lit_comp("Sets the number of columns for a memory view."), str8_lit_comp(""), str8_lit_comp("Set Columns"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Index, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Index, DF_IconKind_Thumbnails, {0, 0}},
{ str8_lit_comp("toggle_address_visibility"), str8_lit_comp("Toggles the visibility of addresses in a disassembly view."), str8_lit_comp(""), str8_lit_comp("Toggle Address Visibility"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Thumbnails, {0, 0}},
{ str8_lit_comp("toggle_code_bytes_visibility"), str8_lit_comp("Toggles the visibility of machine code bytes in a disassembly view."), str8_lit_comp(""), str8_lit_comp("Toggle Code Bytes Visibility"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Thumbnails, {0, 0}},
{ str8_lit_comp("enable_entity"), str8_lit_comp("Enables an entity."), str8_lit_comp(""), str8_lit_comp("Enable Entity"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("disable_entity"), str8_lit_comp("Disables an entity."), str8_lit_comp(""), str8_lit_comp("Disable Entity"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("freeze_entity"), str8_lit_comp("Freezes an entity."), str8_lit_comp(""), str8_lit_comp("Freeze Entity"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("thaw_entity"), str8_lit_comp("Thaws an entity."), str8_lit_comp(""), str8_lit_comp("Thaw Entity"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("remove_entity"), str8_lit_comp("Removes an entity."), str8_lit_comp(""), str8_lit_comp("Remove Entity"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("name_entity"), str8_lit_comp("Equips an entity with a name."), str8_lit_comp(""), str8_lit_comp("Name Entity"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_String, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("edit_entity"), str8_lit_comp("Opens the editor for an entity."), str8_lit_comp(""), str8_lit_comp("Edit Entity"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("duplicate_entity"), str8_lit_comp("Duplicates an entity."), str8_lit_comp(""), str8_lit_comp("Duplicate Entity"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("text_breakpoint"), str8_lit_comp("Places or removes a breakpoint on the specified line of source code."), str8_lit_comp(""), str8_lit_comp("Text Breakpoint"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_CircleFilled, {0, 0}},
{ str8_lit_comp("address_breakpoint"), str8_lit_comp("Places or removes a breakpoint on the specified address."), str8_lit_comp(""), str8_lit_comp("Address Breakpoint"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*1), {DF_CmdParamSlot_VirtualAddr, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_VirtualAddr, DF_IconKind_CircleFilled, {0, 0}},
{ str8_lit_comp("function_breakpoint"), str8_lit_comp("Places or removes a breakpoint on the first address(es) of the specified function."), str8_lit_comp(""), str8_lit_comp("Function Breakpoint"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*1), {DF_CmdParamSlot_String, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_String, DF_IconKind_CircleFilled, {0, 0}},
{ str8_lit_comp("toggle_breakpoint_cursor"), str8_lit_comp("Places or removes a breakpoint on the line on which the active cursor sits."), str8_lit_comp(""), str8_lit_comp("Toggle Breakpoint At Cursor"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_CircleFilled, {0, 0}},
{ str8_lit_comp("remove_breakpoint"), str8_lit_comp("Removes an existing breakpoint."), str8_lit_comp(""), str8_lit_comp("Remove Breakpoint"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Trash, {DF_EntityKind_Breakpoint, 0}},
{ str8_lit_comp("enable_breakpoint"), str8_lit_comp("Enables a breakpoint."), str8_lit_comp(""), str8_lit_comp("Enable Breakpoint"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_CheckFilled, {DF_EntityKind_Breakpoint, 0}},
{ str8_lit_comp("disable_breakpoint"), str8_lit_comp("Disables a breakpoint."), str8_lit_comp(""), str8_lit_comp("Disable Breakpoint"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_CheckHollow, {DF_EntityKind_Breakpoint, 0}},
{ str8_lit_comp("toggle_watch_pin"), str8_lit_comp("Places or removes a watch pin on a textual location on a particular entity."), str8_lit_comp(""), str8_lit_comp("Toggle Watch Pin"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*1), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_TextPoint, DF_CmdParamSlot_String}, DF_CmdQueryRule_String, DF_IconKind_Binoculars, {0, 0}},
{ str8_lit_comp("toggle_watch_pin_at_cursor"), str8_lit_comp("Places or removes a watch pin at the cursor on the currently active file."), str8_lit_comp(""), str8_lit_comp("Toggle Watch Pin At Cursor"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*1), {DF_CmdParamSlot_String, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_String, DF_IconKind_Binoculars, {0, 0}},
{ str8_lit_comp("add_target"), str8_lit_comp("Adds a new target."), str8_lit_comp("application,executable,debug"), str8_lit_comp("Add Target"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_FilePath, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_FilePath, DF_IconKind_Target, {0, 0}},
{ str8_lit_comp("remove_target"), str8_lit_comp("Removes an existing target."), str8_lit_comp("delete,remove,target"), str8_lit_comp("Remove Target"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Trash, {DF_EntityKind_Target, 0}},
{ str8_lit_comp("edit_target"), str8_lit_comp("Edits an existing target."), str8_lit_comp(""), str8_lit_comp("Edit Target"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Pencil, {DF_EntityKind_Target, 0}},
{ str8_lit_comp("retry_ended_process"), str8_lit_comp("Launches a new process with the same options as the passed ended process."), str8_lit_comp(""), str8_lit_comp("Retry Ended Process"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Entity, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Entity, DF_IconKind_Null, {DF_EntityKind_EndedProcess, 0}},
{ str8_lit_comp("attach"), str8_lit_comp("Attaches to a process that is already running on the local machine."), str8_lit_comp(""), str8_lit_comp("Attach"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_String, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_String, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("register_as_jit_debugger"), str8_lit_comp("Registers the RAD debugger as the just-in-time (JIT) debugger used by the operating system."), str8_lit_comp(""), str8_lit_comp("Register As Just-In-Time (JIT) Debugger"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("entity_ref_fast_path"), str8_lit_comp("Activates the default behavior when clicking an entity reference."), str8_lit_comp(""), str8_lit_comp("Entity Reference Fast Path"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("spawn_entity_view"), str8_lit_comp("Spawns a new view, given an entity and other parameterizations."), str8_lit_comp(""), str8_lit_comp("Spawn Entity View"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("find_code_location"), str8_lit_comp("Finds a specific source code location given file, line, and column coordinates. Opens the file if necessary."), str8_lit_comp(""), str8_lit_comp("Find Code Location"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_FilePath, DF_CmdParamSlot_TextPoint, DF_CmdParamSlot_Null}, DF_CmdQueryRule_FilePathAndTextPoint, DF_IconKind_FileOutline, {0, 0}},
{ str8_lit_comp("commands"), str8_lit_comp("Opens the list of all commands."), str8_lit_comp(""), str8_lit_comp("Commands"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_String, DF_IconKind_List, {0, 0}},
{ str8_lit_comp("target_editor"), str8_lit_comp("Opens the editor for a target."), str8_lit_comp(""), str8_lit_comp("Target"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Target, {0, 0}},
{ str8_lit_comp("targets"), str8_lit_comp("Opens the list of all targets."), str8_lit_comp(""), str8_lit_comp("Targets"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Target, {0, 0}},
{ str8_lit_comp("file_path_map"), str8_lit_comp("Opens the file path mapping editor."), str8_lit_comp(""), str8_lit_comp("File Path Map"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_FileOutline, {0, 0}},
{ str8_lit_comp("scheduler"), str8_lit_comp("Opens the scheduler view, for process and thread controls."), str8_lit_comp(""), str8_lit_comp("Scheduler"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Scheduler, {0, 0}},
{ str8_lit_comp("call_stack"), str8_lit_comp("Opens the call stack view."), str8_lit_comp("callstack,thread"), str8_lit_comp("Call Stack"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Thread, {0, 0}},
{ str8_lit_comp("modules"), str8_lit_comp("Opens the modules view."), str8_lit_comp(""), str8_lit_comp("Modules"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Module, {0, 0}},
{ str8_lit_comp("pending_entity"), str8_lit_comp("Opens a view which waits for the passed entity to be completely loaded, then replaces itself with a new view."), str8_lit_comp(""), str8_lit_comp("Pending Entity"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_FileOutline, {0, 0}},
{ str8_lit_comp("code"), str8_lit_comp("Opens the code view for an already-loaded file."), str8_lit_comp(""), str8_lit_comp("Code"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_FileOutline, {0, 0}},
{ str8_lit_comp("watch"), str8_lit_comp("Opens a watch view."), str8_lit_comp(""), str8_lit_comp("Watch"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Binoculars, {0, 0}},
{ str8_lit_comp("locals"), str8_lit_comp("Opens a locals view."), str8_lit_comp(""), str8_lit_comp("Locals"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Binoculars, {0, 0}},
{ str8_lit_comp("registers"), str8_lit_comp("Opens a registers view for the currently selected thread."), str8_lit_comp(""), str8_lit_comp("Registers"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Binoculars, {0, 0}},
{ str8_lit_comp("output"), str8_lit_comp("Opens an output view."), str8_lit_comp(""), str8_lit_comp("Output"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_List, {0, 0}},
{ str8_lit_comp("memory"), str8_lit_comp("Opens a memory view."), str8_lit_comp(""), str8_lit_comp("Memory"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Grid, {0, 0}},
{ str8_lit_comp("disassembly"), str8_lit_comp("Opens the disassembly view."), str8_lit_comp("disasm"), str8_lit_comp("Disassembly"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Glasses, {0, 0}},
{ str8_lit_comp("breakpoints"), str8_lit_comp("Opens the breakpoints view."), str8_lit_comp(""), str8_lit_comp("Breakpoints"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_CircleFilled, {0, 0}},
{ str8_lit_comp("watch_pins"), str8_lit_comp("Opens the watch pins view."), str8_lit_comp(""), str8_lit_comp("Watch Pins"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Pin, {0, 0}},
{ str8_lit_comp("exception_filters"), str8_lit_comp("Opens the exception filters view."), str8_lit_comp("exceptions,filters"), str8_lit_comp("Exception Filters"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Gear, {0, 0}},
{ str8_lit_comp("theme"), str8_lit_comp("Opens the theme view."), str8_lit_comp("theme,color,scheme,palette"), str8_lit_comp("Theme"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Palette, {0, 0}},
{ str8_lit_comp("pick_file"), str8_lit_comp("Opens the file browser to pick a file."), str8_lit_comp(""), str8_lit_comp("Pick File"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*1) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_FilePath, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_FilePath, DF_IconKind_FileOutline, {0, 0}},
{ str8_lit_comp("complete_view"), str8_lit_comp("Completes a view, passing all parameters to a new command matching the passed command spec."), str8_lit_comp(""), str8_lit_comp("Complete View"), (DF_CmdSpecFlag_OmitFromLists*1) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
{ str8_lit_comp("toggle_dev_menu"), str8_lit_comp("Opens and closes the developer menu."), str8_lit_comp(""), str8_lit_comp("Toggle Developer Menu"), (DF_CmdSpecFlag_OmitFromLists*0) | (DF_CmdSpecFlag_RunKeepsQuery*0) | (DF_CmdSpecFlag_QueryUsesOldInput*0) | (DF_CmdSpecFlag_AppliesToView*0) | (DF_CmdSpecFlag_QueryIsCode*0), {DF_CmdParamSlot_Null, DF_CmdParamSlot_Null, DF_CmdParamSlot_Null}, DF_CmdQueryRule_Null, DF_IconKind_Null, {0, 0}},
};
DF_CoreViewRuleSpecInfo df_g_core_view_rule_spec_info_table[] =
{
{str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, },
{str8_lit_comp("array"), str8_lit_comp("Array"), str8_lit_comp("Specifies that a pointer points to N elements, rather than only 1."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(array) , 0, },
{str8_lit_comp("list"), str8_lit_comp("List"), str8_lit_comp("Specifies that some struct, union, or class forms the top of a linked list, and the member which points at the following element in the list."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(list) , },
{str8_lit_comp("bswap"), str8_lit_comp("Byte Swap"), str8_lit_comp("Specifies that all integer primitives should be byte-swapped, such that their endianness is reversed."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EVAL_RESOLUTION_FUNCTION_NAME(bswap) , 0, },
{str8_lit_comp("dec"), str8_lit_comp("Decimal Base (Base 10)"), str8_lit_comp("Specifies that all integral evaluations should appear in base-10 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, },
{str8_lit_comp("bin"), str8_lit_comp("Binary Base (Base 2)"), str8_lit_comp("Specifies that all integral evaluations should appear in base-2 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, },
{str8_lit_comp("oct"), str8_lit_comp("Octal Base (Base 8)"), str8_lit_comp("Specifies that all integral evaluations should appear in base-8 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, },
{str8_lit_comp("hex"), str8_lit_comp("Hexadecimal Base (Base 16)"), str8_lit_comp("Specifies that all integral evaluations should appear in base-16 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, },
{str8_lit_comp("only"), str8_lit_comp("Only Specified Members"), str8_lit_comp("Specifies that only the specified members should appear in struct, union, or class evaluations."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(only) , },
{str8_lit_comp("omit"), str8_lit_comp("Omit Specified Members"), str8_lit_comp("Omits a list of member names from appearing in struct, union, or class evaluations."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(omit) , },
{str8_lit_comp("no_addr"), str8_lit_comp("Disable Address Values"), str8_lit_comp("Displays only what pointers point to, if possible, without the pointer's address value."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, },
{str8_lit_comp("rgba"), str8_lit_comp("Color (RGBA)"), str8_lit_comp("Displays as a color, interpreting the data as encoding R, G, B, and A values."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(rgba) , },
{str8_lit_comp("text"), str8_lit_comp("Text"), str8_lit_comp("Displays as text."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(text) , },
{str8_lit_comp("disasm"), str8_lit_comp("Disassembly"), str8_lit_comp("Displays as disassembled instructions, interpreting the data as raw machine code."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(disasm) , },
{str8_lit_comp("bitmap"), str8_lit_comp("Bitmap"), str8_lit_comp("Displays as a bitmap, interpreting the data as raw pixel data."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(bitmap) , },
{str8_lit_comp("geo"), str8_lit_comp("Geometry"), str8_lit_comp("Displays as geometry, interpreting the data as vertex data."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*1)|(DF_CoreViewRuleSpecInfoFlag_EvalResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(geo) , },
};
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "df/core/df_core.c"
#include "df/gfx/df_gfx.c"
#include "df/gfx/df_views.c"
#include "df/gfx/df_view_rule_hooks.c"
+12
View File
@@ -0,0 +1,12 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEBUG_FRONTEND_INC_H
#define DEBUG_FRONTEND_INC_H
#include "df/core/df_core.h"
#include "df/gfx/df_gfx.h"
#include "df/gfx/df_views.h"
#include "df/gfx/df_view_rule_hooks.h"
#endif // DEBUG_FRONTEND_INC_H
+11760
View File
File diff suppressed because it is too large Load Diff
+1053
View File
File diff suppressed because it is too large Load Diff
+721
View File
@@ -0,0 +1,721 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Embedded Data
@embed_file df_g_icon_font_bytes: "../data/icons.ttf"
@embed_file df_g_default_main_font_bytes: "../data/Roboto-Regular.ttf"
@embed_file df_g_default_code_font_bytes: "../data/liberation-mono.ttf"
//@embed_file df_g_default_code_font_bytes: "../data/Inconsolata-Regular.ttf"
////////////////////////////////
//~ rjf: Default Bindings
@table(name key ctrl shift alt)
DF_DefaultBindingTable:
{
//- rjf: low-level target control operations
{ "kill_all" F5 0 shift 0 }
{ "step_into_inst" F11 0 0 alt }
{ "step_over_inst" F10 0 0 alt }
{ "step_out" F11 0 shift 0 }
{ "halt" X ctrl shift 0 }
{ "halt" Pause 0 0 0 }
{ "soft_halt_refresh" R 0 0 alt }
//- rjf: high-level composite target control operations
{ "run" F5 0 0 0 }
{ "restart" F5 ctrl shift 0 }
{ "step_into" F11 0 0 0 }
{ "step_over" F10 0 0 0 }
{ "run_to_cursor" F10 ctrl 0 0 }
{ "set_next_statement" F10 ctrl shift 0 }
//- rjf: font sizes
{ "inc_ui_font_scale" Equal 0 0 alt }
{ "dec_ui_font_scale" Minus 0 0 alt }
{ "inc_code_font_scale" Equal 0 shift alt }
{ "dec_code_font_scale" Minus 0 shift alt }
//- rjf: windows
{ "window" N ctrl shift 0 }
{ "toggle_fullscreen" Return ctrl 0 0 }
//- rjf: panel splitting
{ "new_panel_right" P ctrl 0 0 }
{ "new_panel_down" Minus ctrl 0 0 }
//- rjf: panel rotation
{ "rotate_panel_columns" 2 ctrl 0 0 }
//- rjf: focused panel changing
{ "next_panel" Comma ctrl 0 0 }
{ "prev_panel" Comma ctrl shift 0 }
{ "focus_panel_right" Right ctrl shift alt }
{ "focus_panel_left" Left ctrl shift alt }
{ "focus_panel_up" Up ctrl shift alt }
{ "focus_panel_down" Down ctrl shift alt }
//- rjf: undo/redo
//{ "undo" Z ctrl 0 0 }
//{ "redo" Y ctrl 0 0 }
//- rjf: focus history
//{ "go_back" Left 0 0 alt }
//{ "go_forward" Right 0 0 alt }
//- rjf: panel removal
{ "close_panel" P ctrl shift 0 }
//- rjf: panel tab
{ "next_tab" PageDown ctrl 0 0 }
{ "prev_tab" PageUp ctrl 0 0 }
{ "next_tab" Tab ctrl 0 0 }
{ "prev_tab" Tab ctrl shift 0 }
{ "move_tab_right" PageDown ctrl shift 0 }
{ "move_tab_left" PageUp ctrl shift 0 }
{ "close_tab" W ctrl 0 0 }
{ "tab_bar_top" Up ctrl 0 alt }
{ "tab_bar_bottom" Down ctrl 0 alt }
//- rjf: files
{ "open" O ctrl 0 0 }
{ "reload_active" R ctrl shift 0 }
{ "switch" I ctrl 0 0 }
//- rjf: setting config paths
{ "load_user" O ctrl shift alt }
{ "load_profile" O ctrl 0 alt }
//- rjf: directional movement & text controls
{ "move_left" Left 0 0 0 }
{ "move_right" Right 0 0 0 }
{ "move_up" Up 0 0 0 }
{ "move_down" Down 0 0 0 }
{ "move_left_select" Left 0 shift 0 }
{ "move_right_select" Right 0 shift 0 }
{ "move_up_select" Up 0 shift 0 }
{ "move_down_select" Down 0 shift 0 }
{ "move_left_chunk" Left ctrl 0 0 }
{ "move_right_chunk" Right ctrl 0 0 }
{ "move_up_chunk" Up ctrl 0 0 }
{ "move_down_chunk" Down ctrl 0 0 }
{ "move_up_page" PageUp 0 0 0 }
{ "move_down_page" PageDown 0 0 0 }
{ "move_up_whole" Home ctrl 0 0 }
{ "move_down_whole" End ctrl 0 0 }
{ "move_left_chunk_select" Left ctrl shift 0 }
{ "move_right_chunk_select" Right ctrl shift 0 }
{ "move_up_chunk_select" Up ctrl shift 0 }
{ "move_down_chunk_select" Down ctrl shift 0 }
{ "move_up_page_select" PageUp 0 shift 0 }
{ "move_down_page_select" PageDown 0 shift 0 }
{ "move_up_whole_select" Home ctrl shift 0 }
{ "move_down_whole_select" End ctrl shift 0 }
{ "move_home" Home 0 0 0 }
{ "move_end" End 0 0 0 }
{ "move_home_select" Home 0 shift 0 }
{ "move_end_select" End 0 shift 0 }
{ "select_all" A ctrl 0 0 }
{ "delete_single" Delete 0 0 0 }
{ "delete_chunk" Delete ctrl 0 0 }
{ "backspace_single" Backspace 0 0 0 }
{ "backspace_chunk" Backspace ctrl 0 0 }
{ "copy" C ctrl 0 0 }
{ "cut" X ctrl 0 0 }
{ "paste" V ctrl 0 0 }
{ "insert_text" Null 0 0 0 }
//- rjf: code navigation
{ "goto_line" G ctrl 0 0 }
{ "goto_address" G 0 0 alt }
{ "find_text_forward" F ctrl 0 0 }
{ "find_text_backward" R ctrl 0 0 }
{ "find_next" F3 0 0 0 }
{ "find_prev" F3 shift 0 0 }
//- rjf: thread finding
{ "find_selected_thread" F4 0 0 0 }
//- rjf: name finding
{ "goto_name" J ctrl 0 0 }
{ "goto_name_at_cursor" F12 0 0 0 }
//- rjf: watch expressions
{ "toggle_watch_expr_at_cursor" W 0 0 alt }
{ "toggle_watch_pin_at_cursor" F9 ctrl 0 0 }
//- rjf: breakpoints
{ "toggle_breakpoint_cursor" F9 0 0 0 }
//- rjf: targets
{ "add_target" T ctrl 0 0 }
//- rjf: attaching
{ "attach" F6 0 shift 0 }
//- rjf: view drivers
{ "commands" F1 0 0 0 }
{ "scheduler" S 0 0 alt }
//- rjf: developer commands
{ "clear_diag_log" D ctrl 0 alt }
{ "open_diag_log" D ctrl 0 0 }
}
////////////////////////////////
//~ rjf: Gfx Layer View Kinds
@table(name, name_lower, display_string, name_kind, parameterized_by_entity, can_serialize, can_serialize_entity_path, inc_in_docs, docs_desc)
DF_GfxViewTable:
{
{ Null "null" "" Null 0 0 0 0 "" }
{ Empty "empty" "" Null 0 0 0 0 "" }
{ Commands "commands" "Commands" Null 0 0 0 0 "" }
{ FileSystem "file_system" "File System" Null 0 0 0 0 "" }
{ SystemProcesses "system_processes" "System Processes" Null 0 0 0 0 "" }
{ EntityLister "entity_lister" "Entity List" EntityKindName 0 0 0 0 "" }
{ Target "target" "Target" EntityName 1 0 0 0 "" }
{ Targets "targets" "Targets" Null 0 1 0 1 "Displays a list of all targets, as well as controls for enabling, disabling, launching, editing, or deleting each target. For more information on targets, read the `Targets` section." }
{ FilePathMap "file_path_map" "File Path Map" Null 0 1 0 1 "Displays a table of *path maps*. Each path map is a pair of file or folder paths, one being a 'source' path, and one being a 'destination' path. These pairs are used by the debugger when automatically searching for specific files - for instance, when attempting to snap to a source code location specified by debug info. If debug info refers to a path on the machine on which a target executable was originally built, but that path is not valid on the debugger machine, but some alternative path exists, then path maps may be used to redirect the debugger from the debug info's specified paths to the associated appropriate debugger machine file paths." }
{ Scheduler "scheduler" "Scheduler" Null 0 1 0 1 "Displays all processes and threads to which the debugger is currently attached, and contains controls for selecting and freezing threads." }
{ CallStack "call_stack" "Call Stack" Null 0 1 0 1 "Displays the call stack of the currently selected thread. Each frame in the call stack contains the associated module, function name, and return address. Allows selection of a particular call stack frame other than the top." }
{ Modules "modules" "Modules" Null 0 1 0 1 "Displays a table of all modules currently loaded by any process to which the debugger is attached. This table displays each module's name, virtual address range in the containing process' address space, and which debug info file is being used by the debugger for the associated module." }
{ PendingEntity "pending_entity" "Pending Entity" EntityName 1 0 0 0 "" }
{ Code "code" "Code" EntityName 1 1 1 0 "" }
{ Disassembly "disassembly" "Disassembly" Null 0 1 0 1 "Displays disassembled instructions in a textual form from the selected thread's containing process virtual address space." }
{ Watch "watch" "Watch" Null 0 1 0 1 "The familiar 'watch window' debugger interface. Allows the inputting of a number of expressions. Each expression in the table is evaluated within the context of the selected thread's selected call stack frame. If applicable (depending on visualization rules and the expression's type), these expressions may be hierarchically expanded, which displays children as more rows in the table. The values of these expressions may also be edited, and if possible, can be used to write to registers or memory in attached processes. Also contains a new *view rule* column, not found in other major debuggers, which allows per-row specification of various visualization rules. These view rules may be used to visualize and inspect the evaluation of expressions in a variety of ways. To learn more, read the 'View Rules' section." }
{ Locals "locals" "Locals" Null 0 1 0 1 "Nearly identical to `Watch`, but automatically filled with local variables found within the selected call stack frame of the selected thread, according to the associated debug info. View rules and evaluation values can be edited, like in `Watch`, but unlike `Watch`, expressions cannot be edited or added to the table." }
{ Registers "registers" "Registers" Null 0 1 0 1 "Nearly identical to `Watch`, but automatically filled with all register names according to the selected thread's architecture. View rules and evaluation values can be edited, like in `Watch`, but unlike `Watch`, expressions cannot be edited or added to the table." }
{ Output "output" "Output" Null 0 1 0 1 "Displays textual output from the selected thread's containing process." }
{ Memory "memory" "Memory" Null 0 1 1 1 "A familiar hex-editor-like interface for viewing memory of attached processes." }
{ Breakpoints "breakpoints" "Breakpoints" Null 0 1 0 1 "Displays a table of all breakpoints, containing information about each breakpoint's name, location, and hit count. Also contains per-breakpoint controls for enabling, deleting, or editing each breakpoint. For more information on breakpoints and their features, read the 'Breakpoints' section." }
{ WatchPins "watch_pins" "Watch Pins" Null 0 1 0 1 "Displays a table of all watch pins (watched expressions, like those found in `Watch`, but instead of being within a table, being pinned to some source code location, like breakpoints). This table contains each pin's name, location, and controls for editing or deleting each pin." }
{ ExceptionFilters "exception_filters" "Exception Filters" Null 0 1 0 1 "An interface which controls whether or not the debugger will halt attached processes upon encountering specific exception codes for the first time." }
{ Theme "theme" "Theme" Null 0 1 0 1 "An interface for modifying the colors used in the debugger's UI. Allows selecting a theme preset, loading a theme from a file, and modifying individual colors within a theme." }
}
////////////////////////////////
//~ rjf: Default Command -> View Map
@table(cmd view entity_kind_lock)
DF_CmdSpec2ViewSpecMap:
{
{"launch_and_run" "entity_lister" Target }
{"launch_and_init" "entity_lister" Target }
{"kill" "entity_lister" Process }
{"detach" "entity_lister" Process }
{"select_thread" "entity_lister" Thread }
{"select_thread_window" "entity_lister" Thread }
{"select_thread_view" "entity_lister" Thread }
{"freeze_thread" "entity_lister" Thread }
{"thaw_thread" "entity_lister" Thread }
{"freeze_process" "entity_lister" Process }
{"thaw_process" "entity_lister" Process }
{"freeze_machine" "entity_lister" Machine }
{"thaw_machine" "entity_lister" Machine }
{"set_current_path" "file_system" Null }
{"open" "file_system" Null }
{"reload" "entity_lister" File }
{"switch" "entity_lister" File }
{"load_user" "file_system" Null }
{"load_profile" "file_system" Null }
{"find_thread" "entity_lister" Thread }
{"open_thread_disasm" "entity_lister" Thread }
{"open_file_memory" "entity_lister" File }
{"open_process_memory" "entity_lister" Process }
{"remove_breakpoint" "entity_lister" Breakpoint }
{"edit_breakpoint" "entity_lister" Breakpoint }
{"enable_breakpoint" "entity_lister" Breakpoint }
{"disable_breakpoint" "entity_lister" Breakpoint }
{"edit_breakpoint" "entity_lister" Breakpoint }
{"add_target" "file_system" Null }
{"remove_target" "entity_lister" Target }
{"edit_target" "entity_lister" Target }
{"retry_ended_process" "entity_lister" EndedProcess }
{"attach" "system_processes" Null }
{"commands" "commands" Null }
{"target_editor" "target" Null }
{"targets" "targets" Null }
{"file_path_map" "file_path_map" Null }
{"scheduler" "scheduler" Null }
{"call_stack" "call_stack" Null }
{"modules" "modules" Null }
{"pending_entity" "pending_entity" Null }
{"code" "code" Null }
{"watch" "watch" Null }
{"locals" "locals" Null }
{"registers" "registers" Null }
{"output" "output" Null }
{"memory" "memory" Null }
{"disassembly" "disassembly" Null }
{"breakpoints" "breakpoints" Null }
{"watch_pins" "watch_pins" Null }
{"exception_filters" "exception_filters" Null }
{"theme" "theme" Null }
{"pick_file" "file_system" Null }
{"clear_diag_log" "entity_lister" DiagLog }
{"open_diag_log" "entity_lister" DiagLog }
}
////////////////////////////////
//~ rjf: Built-In Graphical View Rule Extensions
//
// NOTE(rjf): see @view_rule_info
@table(string vr ls ru bu)
DF_GfxViewRuleTable:
{
{"array" - - - -}
{"list" x - - -}
{"dec" - x - -}
{"bin" - x - -}
{"oct" - x - -}
{"hex" - x - -}
{"only" x x - -}
{"omit" x x - -}
{"no_addr" - x - -}
{"rgba" - - x x}
{"text" - - - x}
{"disasm" - - - x}
{"bitmap" - - x x}
{"geo" - - x x}
}
////////////////////////////////
//~ rjf: Theme Color Codes
@table(name display_name name_lower r g b a)
DF_ThemeTable:
{
{Null "Null" null }
{PlainText "Plain Text" plain_text }
{PlainBackground "Plain Background" plain_background }
{PlainBorder "Plain Border" plain_border }
{PlainOverlay "Plain Overlay" plain_overlay }
{CodeDefault "Code (Default)" code_default }
{CodeFunction "Code (Function)" code_function }
{CodeType "Code (Type)" code_type }
{CodeLocal "Code (Local)" code_local }
{CodeKeyword "Code (Keyword)" code_keyword }
{CodeSymbol "Code (Symbol)" code_symbol }
{CodeNumeric "Code (Numeric)" code_numeric }
{CodeString "Code (String)" code_string }
{CodeMeta "Code (Meta)" code_meta }
{CodeComment "Code (Comment)" code_comment }
{LineInfo0 "Line Info (0)" line_info_0 }
{LineInfo1 "Line Info (1)" line_info_1 }
{LineInfo2 "Line Info (2)" line_info_2 }
{LineInfo3 "Line Info (3)" line_info_3 }
{AltText "Alt Text" alt_text }
{AltBackground "Alt Background" alt_background }
{AltBorder "Alt Border" alt_border }
{AltOverlay "Alt Overlay" alt_overlay }
{TabInactive "Inactive Tab" tab_inactive }
{TabActive "Active Tab" tab_active }
{EntityBackground "Entity Background" entity_background }
{QueryBar "Query Bar" query_bar }
{WeakText "Weak Text" weak_text }
{TextSelection "Text Selection" text_selection }
{Cursor "Cursor" cursor }
{Highlight0 "Highlight (0)" highlight_0 }
{Highlight1 "Highlight (1)" highlight_1 }
{SuccessText "Success Text" success_text }
{SuccessBackground "Success Background" success_background }
{SuccessBorder "Success Border" success_border }
{FailureText "Failure Text" failure_text }
{FailureBackground "Failure Background" failure_background }
{FailureBorder "Failure Border" failure_border }
{ActionText "Action Text" action_text }
{ActionBackground "Action Background" action_background }
{ActionBorder "Action Border" action_border }
{DropSiteOverlay "Drop Site Overlay" drop_site_overlay }
{Thread0 "Thread (0)" thread_0 }
{Thread1 "Thread (1)" thread_1 }
{Thread2 "Thread (2)" thread_2 }
{Thread3 "Thread (3)" thread_3 }
{Thread4 "Thread (4)" thread_4 }
{Thread5 "Thread (5)" thread_5 }
{Thread6 "Thread (6)" thread_6 }
{Thread7 "Thread (7)" thread_7 }
{ThreadUnwound "Thread (Unwound)" thread_unwound }
{InactivePanelOverlay "Inactive Panel Overlay" inactive_panel_overlay }
{DropShadow "Drop Shadow" drop_shadow }
}
////////////////////////////////
//~ rjf: Theme Presets
@table(name_upper name_lower display_string)
DF_ThemePresetTable:
{
{ DefaultDark default_dark "Default (Dark)" }
{ DefaultLight default_light "Default (Light)" }
{ VSDark vs_dark "VS (Dark)" }
{ VSLight vs_light "VS (Light)" }
{ SolarizedDark solarized_dark "Solarized (Dark)" }
{ SolarizedLight solarized_light "Solarized (Light)" }
{ HandmadeHero handmade_hero "Handmade Hero" }
{ FourCoder four_coder "4coder" }
{ FarManager far_manager "Far Manager" }
}
@table(name default_dark default_light vs_dark vs_light solarized_dark solarized_light handmade_hero four_coder far_manager)
DF_ThemePresetColorTable:
{
(null 0xff00ffff 0xff00ffff 0xff00ffff 0xff00ffff 0xff00ffff 0xff00ffff 0xff00ffff 0xff00ffff 0xff00ffff )
(plain_text 0xe5e5e5ff 0x383838ff 0xe5e5e5ff 0x1e1e1eff 0xe5e5e5ff 0x1e1e1eff 0xa08563ff 0x90b080ff 0x00ffffff )
(plain_background 0x3333337f 0xedededfe 0x1e1e1eff 0xffffffff 0x002b36ff 0xfcf6e2ff 0x0c0c0cff 0x0c0c0cff 0x000082ff )
(plain_border 0xffffff19 0x0000001d 0xffffff19 0xcccedb1d 0xffffff19 0xcccedb1d 0xffffff19 0x181818a0 0xffffff19 )
(plain_overlay 0xffffff33 0x00000033 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 )
(code_default 0xe5e5e5ff 0x282828ff 0xd4d4d4ff 0x000000ff 0x839496ff 0x74878cff 0xa08563ff 0x90b080ff 0x00ffffff )
(code_function 0x7fcc99ff 0x2a7a45ff 0xdcdcaaff 0x74531fff 0x1c7dd1ff 0xc39d36ff 0xcc5735ff 0x7fcc99ff 0x49b2ffff )
(code_type 0x66b2e5ff 0x2c688fff 0x4ec9b0ff 0x2b91afff 0x1c7dd1ff 0x66b2e5ff 0xd8a51dff 0x66b2e5ff 0x49b2ffff )
(code_local 0xfe9548ff 0xfe9548ff 0xfe9548ff 0xfe9548ff 0xfe9548ff 0xfe9548ff 0xfe9548ff 0xfe9548ff 0xfe9548ff )
(code_keyword 0xf7bf5eff 0xa47729ff 0x569cd6ff 0x0000ffff 0x63980fff 0xc39d36ff 0xac7b0bff 0xd08f20ff 0xff0000ff )
(code_symbol 0x994c32ff 0x6c2d18ff 0xb4b4b4ff 0x000000ff 0x839496ff 0x2e5256ff 0x994c32ff 0x994c32ff 0xffffffff )
(code_numeric 0x4ce54cff 0x2c7d2cff 0xb5cea8ff 0x000000ff 0xcb4b20ff 0x657b83ff 0x6b8e23ff 0x50ff30ff 0x2cff50ff )
(code_string 0xe5cc66ff 0xcc5a0fff 0xd69d85ff 0xc11515ff 0x2aa198ff 0x5ab4a9ff 0x6b8e23ff 0x50ff30ff 0xe5cc66ff )
(code_meta 0xe54c4cff 0x8a0c0cff 0x9b9b9bff 0x808080ff 0xe54c4cff 0xe54c4cff 0xdab98fff 0x50ff30ff 0xffff00ff )
(code_comment 0x7f7f7fff 0x7f7f7fff 0x6a9955ff 0x008000ff 0x7f7f7fff 0xadafb2ff 0x686868ff 0x2090f0ff 0x7f7f7fff )
(line_info_0 0x3f72993f 0x3e71993f 0xbeb7ff3f 0x3f72993f 0x3f72993f 0x3f72993f 0xaf60103f 0x3f72993f 0x3f72993f )
(line_info_1 0x3f72994c 0x3f72994c 0xbeb7ff4c 0x3f72994c 0x3f72994c 0x3f72994c 0xaf60104c 0x3f72994c 0x3f72994c )
(line_info_2 0x3f729972 0x3f729972 0xbeb7ff72 0x3f729972 0x3f729972 0x3f729972 0xaf601072 0x3f729972 0x3f729972 )
(line_info_3 0x3f72997f 0x3f72997f 0xbeb7ff7f 0x3f72997f 0x3f72997f 0x3f72997f 0xaf60107f 0x3f72997f 0x3f72997f )
(alt_text 0xe5e5e5ff 0x535353ff 0xf1f1f1ff 0x535353ff 0xe5e5e5ff 0x535353ff 0xa08563ff 0x90b080ff 0x000000ff )
(alt_background 0x42474c7f 0xfefefebc 0x1b1b1cff 0xfefefebc 0x002b36ff 0xfcf6e2ff 0x0c0c0cff 0x0c0c0cff 0x008184ff )
(alt_border 0xffffff19 0xffffff19 0x333337ff 0xffffff19 0xffffff19 0xffffff19 0xffffff19 0xffffff19 0xffffff19 )
(alt_overlay 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 )
(tab_inactive 0x42474c7f 0x42474c7f 0x42474c7f 0x42474c7f 0x42474c7f 0x42474c7f 0x42474c7f 0x42474c7f 0x42474c7f )
(tab_active 0xa87a4c99 0xc7a27dff 0x007accff 0x007accff 0x28515eff 0xa87a4c99 0xa87a4c99 0xa87a4c99 0xa87a4c99 )
(entity_background 0x4293cc99 0x4293cc99 0x4293cc99 0x4293cc99 0x4293cc99 0x4293cc99 0x4293cc99 0x4293cc99 0x4293cc99 )
(query_bar 0x8e2d4ccc 0xd76489cc 0x8e2d4ccc 0x8e2d4ccc 0x8e2d4ccc 0x8e2d4ccc 0x8e2d4ccc 0x8e2d4ccc 0x8e2d4ccc )
(weak_text 0xffffff7f 0x0000007f 0xffffff7f 0x0000007f 0xffffff7f 0x0000007f 0xa08563af 0x90b080af 0xffffff7f )
(text_selection 0x99ccff4c 0x7d98b34c 0x99ccff4c 0x7d98b34c 0x99ccff4c 0x7d98b34c 0x99ccff4c 0x99ccff4c 0x99ccff4c )
(cursor 0x66e566e5 0x101010ff 0x66e566e5 0x101010ff 0x66e566e5 0x101010ff 0x66e566e5 0x66e566e5 0x66e566e5 )
(highlight_0 0xb27219ff 0xb272189b 0xb27219ff 0xb27219ff 0xb27219ff 0xb27219ff 0xb27219ff 0xb27219ff 0xb27219ff )
(highlight_1 0x327f19ff 0x327f19ff 0x327f19ff 0x327f19ff 0x327f19ff 0x327f19ff 0x327f19ff 0x327f19ff 0x327f19ff )
(success_text 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff )
(success_background 0x32b219ff 0x75db61ff 0x32b219ff 0x32b219ff 0x32b219ff 0x32b219ff 0x32b219ff 0x32b219ff 0x32b219ff )
(success_border 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 )
(failure_text 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff 0xe5e5e5ff )
(failure_background 0xb23219ff 0xf27961ff 0xb23219ff 0xb23219ff 0xb23219ff 0xb23219ff 0xb23219ff 0xb23219ff 0xb23219ff )
(failure_border 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 )
(action_text 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff )
(action_background 0x327fb2ff 0x327fb2ff 0x327fb2ff 0x327fb2ff 0x327fb2ff 0x327fb2ff 0x327fb2ff 0x327fb2ff 0x327fb2ff )
(action_border 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 0xffffff33 )
(drop_site_overlay 0xffffff0c 0xffffff0c 0xffffff0c 0xffffff0c 0xffffff0c 0xffffff0c 0xffffff0c 0xffffff0c 0xffffff0c )
(thread_0 0xffcb7fff 0xad7c34ff 0xffcb7fff 0xad7c34ff 0xffcb7fff 0xad7c34ff 0xffcb7fff 0xffcb7fff 0xffcb7fff )
(thread_1 0xb2ff65ff 0x639b2aff 0xb2ff65ff 0x639b2aff 0xb2ff65ff 0x639b2aff 0xb2ff65ff 0xb2ff65ff 0xb2ff65ff )
(thread_2 0xff99e5ff 0xa94c91ff 0xff99e5ff 0xa94c91ff 0xff99e5ff 0xa94c91ff 0xff99e5ff 0xff99e5ff 0xff99e5ff )
(thread_3 0x6598ffff 0x305398ff 0x6598ffff 0x305398ff 0x6598ffff 0x305398ff 0x6598ffff 0x6598ffff 0x6598ffff )
(thread_4 0x65ffcbff 0x339574ff 0x65ffcbff 0x339574ff 0x65ffcbff 0x339574ff 0x65ffcbff 0x65ffcbff 0x65ffcbff )
(thread_5 0xff9819ff 0xbf7416ff 0xff9819ff 0xbf7416ff 0xff9819ff 0xbf7416ff 0xff9819ff 0xff9819ff 0xff9819ff )
(thread_6 0x9932ffff 0x57238bff 0x9932ffff 0x57238bff 0x9932ffff 0x57238bff 0x9932ffff 0x9932ffff 0x9932ffff )
(thread_7 0x65ff4cff 0x2a7e1cff 0x65ff4cff 0x2a7e1cff 0x65ff4cff 0x2a7e1cff 0x65ff4cff 0x65ff4cff 0x65ff4cff )
(thread_unwound 0xb2ccd8ff 0x236481ff 0xb2ccd8ff 0x236481ff 0xb2ccd8ff 0x236481ff 0xb2ccd8ff 0xb2ccd8ff 0xb2ccd8ff )
(inactive_panel_overlay 0x0000003f 0x0000000d 0x0000003f 0x0000000d 0x0000003f 0x0000000d 0x0000003f 0x0000003f 0x0000003f )
(drop_shadow 0x0000007f 0x0000003b 0x0000007f 0x0000003b 0x0000007f 0x0000003b 0x0000007f 0x0000007f 0x0000007f )
}
////////////////////////////////
//~ rjf: Generators
//- rjf: enums
@table_gen_enum
DF_GfxViewKind:
{
@expand(DF_GfxViewTable a)
`DF_GfxViewKind_$(a.name),`
`DF_GfxViewKind_COUNT`;
}
@table_gen_enum
DF_ThemeColor:
{
@expand(DF_ThemeTable, a)
`DF_ThemeColor_$(a.name),`;
`DF_ThemeColor_COUNT`;
}
@table_gen_enum
DF_ThemePreset:
{
@expand(DF_ThemePresetTable a)
`DF_ThemePreset_$(a.name),`;
`DF_ThemePreset_COUNT`;
}
//- rjf: theme preset color tables
@table_gen_data(type: String8, fallback: `{0}`)
df_g_theme_preset_display_string_table:
{
@expand(DF_ThemePresetTable a) `str8_lit_comp("$(a.display_string)"),`;
}
@table_gen_data(type: Vec4F32, fallback: `{1, 0, 1, 1}`)
df_g_theme_preset_colors__default_dark:
{
@expand(DF_ThemePresetColorTable a) `rgba_from_u32_lit_comp($(a.default_dark)),`;
}
@table_gen_data(type: Vec4F32, fallback: `{1, 0, 1, 1}`)
df_g_theme_preset_colors__default_light:
{
@expand(DF_ThemePresetColorTable a) `rgba_from_u32_lit_comp($(a.default_light)),`;
}
@table_gen_data(type: Vec4F32, fallback: `{1, 0, 1, 1}`)
df_g_theme_preset_colors__vs_dark:
{
@expand(DF_ThemePresetColorTable a) `rgba_from_u32_lit_comp($(a.vs_dark)),`;
}
@table_gen_data(type: Vec4F32, fallback: `{1, 0, 1, 1}`)
df_g_theme_preset_colors__vs_light:
{
@expand(DF_ThemePresetColorTable a) `rgba_from_u32_lit_comp($(a.vs_light)),`;
}
@table_gen_data(type: Vec4F32, fallback: `{1, 0, 1, 1}`)
df_g_theme_preset_colors__solarized_dark:
{
@expand(DF_ThemePresetColorTable a) `rgba_from_u32_lit_comp($(a.solarized_dark)),`;
}
@table_gen_data(type: Vec4F32, fallback: `{1, 0, 1, 1}`)
df_g_theme_preset_colors__solarized_light:
{
@expand(DF_ThemePresetColorTable a) `rgba_from_u32_lit_comp($(a.solarized_light)),`;
}
@table_gen_data(type: Vec4F32, fallback: `{1, 0, 1, 1}`)
df_g_theme_preset_colors__handmade_hero:
{
@expand(DF_ThemePresetColorTable a) `rgba_from_u32_lit_comp($(a.handmade_hero)),`;
}
@table_gen_data(type: Vec4F32, fallback: `{1, 0, 1, 1}`)
df_g_theme_preset_colors__four_coder:
{
@expand(DF_ThemePresetColorTable a) `rgba_from_u32_lit_comp($(a.four_coder)),`;
}
@table_gen_data(type: Vec4F32, fallback: `{1, 0, 1, 1}`)
df_g_theme_preset_colors__far_manager:
{
@expand(DF_ThemePresetColorTable a) `rgba_from_u32_lit_comp($(a.far_manager)),`;
}
@table_gen_data(type: `Vec4F32 *`, fallback: `0`)
df_g_theme_preset_colors_table:
{
@expand(DF_ThemePresetTable a) `df_g_theme_preset_colors__$(a.name_lower),`;
}
//- rjf: default cmd -> view tables
@table_gen_data(type: String8, fallback:`{0}`)
df_g_cmd2view_table_src:
{
@expand(DF_CmdSpec2ViewSpecMap a) `str8_lit_comp("$(a.cmd)"),`
}
@table_gen_data(type: String8, fallback:`{0}`)
df_g_cmd2view_table_dst:
{
@expand(DF_CmdSpec2ViewSpecMap a) `str8_lit_comp("$(a.view)"),`
}
//- rjf: default bindings table
@table_gen_data(type: DF_StringBindingPair, fallback: `{0}`)
df_g_default_binding_table:
{
@expand(DF_DefaultBindingTable a) ```{str8_lit_comp("$(a.name)"), {OS_Key_$(a.key), 0 $(a.ctrl != 0 -> `|OS_EventFlag_Ctrl`) $(a.shift != 0 -> `|OS_EventFlag_Shift`) $(a.alt != 0 -> `|OS_EventFlag_Alt`)}},```;
}
//- rjf: view hook forward declares
@table_gen
{
@expand(DF_GfxViewTable a) `DF_VIEW_SETUP_FUNCTION_DEF($(a.name));`;
@expand(DF_GfxViewTable a) `DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF($(a.name));`;
@expand(DF_GfxViewTable a) `DF_VIEW_CMD_FUNCTION_DEF($(a.name));`;
@expand(DF_GfxViewTable a) `DF_VIEW_UI_FUNCTION_DEF($(a.name));`;
}
//- rjf: gfx view rule function forward declares
@table_gen
{
``;
@expand(DF_GfxViewRuleTable a)
`$(a.vr == "x" -> "DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_DEF(" .. a.name_lower .. ");")`;
@expand(DF_GfxViewRuleTable a)
`$(a.ls == "x" -> "DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_DEF(" .. a.name_lower .. ");")`;
@expand(DF_GfxViewRuleTable a)
`$(a.ru == "x" -> "DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_DEF(" .. a.name_lower .. ");")`;
@expand(DF_GfxViewRuleTable a)
`$(a.bu == "x" -> "DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(" .. a.name_lower .. ");")`;
}
//- rjf: gfx view rule tables
@table_gen_data(type: DF_GfxViewRuleSpecInfo, fallback: `{0}`) @c_file
df_g_gfx_view_rule_spec_info_table:
{
@expand(DF_GfxViewRuleTable a)
```{ str8_lit_comp("$(a.string)"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*$(a.vr == "x"))|(DF_GfxViewRuleSpecInfoFlag_LineStringize*$(a.ls == "x"))|(DF_GfxViewRuleSpecInfoFlag_RowUI*$(a.ru == "x"))|(DF_GfxViewRuleSpecInfoFlag_BlockUI*$(a.bu == "x")), $(a.vr == "x" -> "DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME("..a.name_lower..")") $(a.vr != "x" -> 0), $(a.ls == "x" -> "DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME("..a.name_lower..")") $(a.ls != "x" -> 0), $(a.ru == "x" -> "DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME("..a.name_lower..")") $(a.ru != "x" -> 0), $(a.bu == "x" -> "DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME("..a.name_lower..")") $(a.bu != "x" -> 0), },```;
}
//- rjf: default view spec info table
@table_gen_data(type: DF_ViewSpecInfo, fallback: `{0}`)
df_g_gfx_view_kind_spec_info_table:
{
@expand(DF_GfxViewTable a) ```{(0|$(a.parameterized_by_entity)*DF_ViewSpecFlag_ParameterizedByEntity|$(a.can_serialize)*DF_ViewSpecFlag_CanSerialize|$(a.can_serialize_entity_path)*DF_ViewSpecFlag_CanSerializeEntityPath), str8_lit_comp("$(a.name_lower)"), str8_lit_comp("$(a.display_string)"), DF_NameKind_$(a.name_kind), DF_VIEW_SETUP_FUNCTION_NAME($(a.name)), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME($(a.name)), DF_VIEW_CMD_FUNCTION_NAME($(a.name)), DF_VIEW_UI_FUNCTION_NAME($(a.name))},```;
}
//- rjf: theme color string tables
@table_gen_data(type: String8, fallback: `str8_lit_comp("")`)
df_g_theme_color_display_string_table:
{
@expand(DF_ThemeTable a) `str8_lit_comp("$(a.display_name)"),`;
}
@table_gen_data(type: String8, fallback: `str8_lit_comp("")`)
df_g_theme_color_cfg_string_table:
{
@expand(DF_ThemeTable a) `str8_lit_comp("$(a.name_lower)"),`;
}
////////////////////////////////
//~ rjf: Help/Docs/README
@markdown
raddbg_readme:
{
@title "The RAD Debugger (ALPHA)";
@p "The RAD Debugger is a native, user-mode, multi-process, graphical debugger. It currently only supports local-machine Windows x64 debugging, with plans to expand and port in the future.";
@subtitle "Getting Started";
@p "To launch the RAD Debugger with your executable and command line arguments, run `raddbg` from the command line like so:";
@p "```raddbg my_program.exe --foo --bar --baz```";
@p "For more information, see the 'Command-Line Usage' section.";
@p "Default keyboard shortcuts for common debugger controls include:";
@unordered_list
{
@p "**Ctrl + O**: Open Source Code File";
@p "**F10**: Step Over";
@p "**F11**: Step Into";
@p "**Shift + F11**: Step Out";
@p "**F5**: Run";
@p "**Ctrl + Shift + X**, or **Pause**: Halt All Processes";
@p "**Shift + F5**: Kill All Processes";
@p "**Shift + F6**: Attach To Process";
@p "**Ctrl + F**: Search For Text (Forwards)";
@p "**F9**: Toggle Breakpoint At Cursor";
@p "**Ctrl + Comma**: Focus Next Panel";
@p "**Ctrl + Shift + Comma**: Focus Previous Panel";
@p "**Ctrl + Shift + Alt + Arrow Key**: Focus Panel In Direction";
@p "**Ctrl + Tab**: Focus Next Tab";
@p "**Ctrl + Shift + Tab**: Focus Previous Tab";
@p "**Ctrl + W**: Close Tab";
@p "**F1**: Open Command Palette";
}
@p "For more information, see the 'Commands' section.";
@p "View rules can be used to visualize expressions differently in the watch window. Here are some examples:";
@unordered_list
{
@p "`array:16`: Visualize a pointer as pointing to a 16-element array.";
@p "`array:(count*2)`: Visualize a pointer as pointing to a `count*2`-element array.";
@p "`list:next`: Visualize a linked list flatly, where each node has a `next` pointer, which points to the next node in the list.";
@p "`hex`: Visualize numeric literals as base-16 (hexadecimal).";
@p "`dec`: Visualize numeric literals as base-10 (decimal).";
@p "`oct`: Visualize numeric literals as base-8 (octal).";
@p "`bin`: Visualize numeric literals as base-2 (binary).";
@p "`omit:(foo bar baz)`: Prohibits members named `foo`, `bar`, and `baz` from being displayed.";
@p "`only:(foo bar baz)`: Only allows members named `foo`, `bar`, and `baz` to be displayed.";
}
@p "Multiple view rules can be specified on one line, so they can be combined like so:";
@p "```list:next, hex, omit:next```";
@p "For more information, see the 'View Rules' section.";
@subtitle "Command-Line Usage";
@p "When run normally, either by launching through a file explorer or running from a command line without arguments, `raddbg` will open a new instance of the debugger. But it also supports a number of command line options for a number of other purposes. These options are specified with a `-` or `--` prefix, followed by the name of the option, and if the option requires a parameter, followed by a `:` or `=`, followed by the parameter's content. A list of the possible options follows:";
@unordered_list
{
@p "`--help` Displays a help menu which documents the possible command line options.";
@p "`--user:<path>` Specifies a path to the user file which the debugger should use instead of the default. The default user file is stored at `%appdata%/raddbg/default.raddbg_user`. For more information on user files, read the 'User & Profile Files' section.";
@p "`--profile:<path>` Specifies a path to the profile file which the debugger should use instead of the default. The default profile file is stored at `%appdata%/raddbg/default.raddbg_profile`. For more information on profile files, read the 'User & Profile Files' section.";
@p "`--auto_run` Specifies that the debugger should immediately run its selected targets upon launching.";
@p "`--auto_step` Specifies that the debugger should immediately step into its selected targets upon launching.";
//@p "`--ipc` Specifies that the launched debugger instance is for communicating a command to another instance of the debugger. In this mode, any non-argument command line contents will be used to express a command. For more information on commands, read the 'Commands' section. For more information on driving another debugger instance with this argument, read the 'Driving Another Debugger Instance' section."
}
@p "On the command line, non-options (meaning any command line arguments *not* prefixed with a `-` or `--`) can also be specified. with normal usage, they are interpreted as the command line for a target (see the 'Targets' section)."
// add when --ipc support is ready: "When driving another debugger instance (using the `--ipc` argument), this additional command line text is used to encode a debugger command.";
@p "The debugger will stop parsing `-` and `--` prefixes as arguments after seeing a standalone `--`, *or* after seeing the first non-option argument, when reading the command line left-to-right. Some examples of command line usage and their interpretations are below:";
@unordered_list
{
@p "`raddbg --foo --bar --a:b --c=d test.exe` All options are used to configure `raddbg`. `test.exe` is interpreted as a target executable. `b` is interpreted as the parameter for the `a` option. `d` is interpreted as the parameter for the `c` option.";
@p "`raddbg test.exe --foo --bar` `test.exe` is interpreted as a target executable. `--foo --bar` is interpreted as arguments for `test.exe`, and thus are *not* used to configure `raddbg`.";
@p "`raddbg -- test.exe` `test.exe` is interpreted as a target executable.";
//@p "`raddbg --ipc find_code_location \"c:/foo/bar/baz.c:123:1\"` `--ipc` configures `raddbg` to drive another instance of `raddbg`. The remainder of the text is interpreted as a command.";
@p "`raddbg \"C:/path with spaces/test.exe\" --foo --bar` A target is formed from the `test.exe` path, and `--foo --bar` are interpreted as arguments to the `test.exe` target.";
}
@subtitle "Windows, Panels, & Tabs";
@p "Each opened *window* in the debugger frontend is subdivided into *panels*. Panels subdivide regions of their window without overlapping. Each panel can contain multiple *tabs*, and can have one tab selected at any time. Tabs can be dragged and dropped between panels. Each tab is used to view one of the many supported debugger interfaces, including source code, disassembly, memory, or watches. When a tab is selected, that interface will fill the tab's containing panel's region of the containing window.";
@p "There are no 'special' windows, panels, or tabs; the debugger is written such that the number of windows, each window's panel organization, and the placement and arrangement of tabs can all be organized in a large variety of ways.";
@p "A list of debugger interfaces, which can occupy tabs, are below:";
@unordered_list
{
@expand(DF_GfxViewTable a) @p "$(a.inc_in_docs -> '`'..a.display_string..'` '..a.docs_desc)";
}
@subtitle "Commands";
@p "The debugger is operated with *commands*. Commands may be manually executed in the debugger UI through the `Commands` menu (which you can open either in the `View` menu bar list, or by using the keybinding, which is F1 by default). Operations in the debugger UI are implemented with commands, so if it's ever unclear how to accomplish some operation through the UI, a useful fallback is searching for and running the command through the command menu.";
//@p "Commands are also how a debugger instance launched with `--ipc` may communicate with a primary debugger instance.";
//@p "A list of commands, how they're referred to textually (for the purposes of `--ipc` debugger instances), and their descriptions are below:";
@p "A list of commands and their descriptions are below:";
@unordered_list
{
@expand(DF_CoreCmdTable a) @p "$(a.lister_omit == 0 -> '`'..a.display_name..'` '..'(`'..a.string..'`) '..a.desc)";
}
@subtitle "Targets";
@p "A *target* is one executable and configuration for launching that executable, including command line arguments and working directory (the directory from which the executable is launched). Each target may also have a custom label (replaces the executable path when visualizing the target), and the name of a custom entry point function (when the default entry points - `main`, `WinMain`, etc. - are not desired when stepping into the program upon launch). The debugger can have several targets at once. Each target can also be enabled or disabled. Some operations work on all enabled targets - for instance, the `Run` or `Kill All` commands (standardly bound as F5 or Shift + F5). Enabling and disabling targets allows one to filter which targets are currently being worked with.";
@p "To add a target, you can run the `Add Target` command. A target is also created automatically from command line arguments - the rules for how this happens can be found in the `Command-Line Usage` section.";
@p "Targets created through command line usage are temporary, meaning they are not persistently saved across runs of the debugger. To change this, you can right click the command-line-created target in the `Targets` view, and click `Save To Profile`. After doing so, the target will be restored across runs, and will no longer need to be specified on the command-line.";
@subtitle "View Rules";
@p "*View Rules* are used to transform the way that evaluations in the debugger are visualized. An evaluation is produced by taking an expression string - for instance, the name of a variable - and using debug info and information from an attached process' live runtime (memory, registers, and so on) to interpret it.";
@p "Evaluations may be visualized in a variety of ways. A 64-bit unsigned integer may be visualized as a textual representation of the value with a radix of 10. A 32-bit floating-point value may be visualized as a textual representation of the value. An array of 32-bit floating-point values can be visualized as a list of textual representations of those values.";
@p "But all of these cases may be visualized in a number of other ways, as well. A 64-bit unsigned integer may be more usefully represented with a radix of 16, 8, or 2. An array of 32-bit floating-point values may encode the R, G, B, and A components of a color, or vertex positions for 3D geometry, or samples for a waveform. An array of bytes may encode raw pixel data for an image, or image data in a compressed format. A struct may have several members which are not useful to look at all the time. A struct may form the head of a linked list, and a flat linked list representation may be more preferable than the traditional watch view representation, which adds an additional layer of hierarchical nesting with the expansion of each 'next' pointer in a linked list. When designing the debugger, we felt that the traditional memory view and watch view representations of data in a debugged-process were not sufficient. View rules were added to the traditional watch view structure to allow per-row specification of extra visualization parameters.";
@p "View rules are specified with the name of a view rule, and depending on the view rule, a `:`, followed by parameters for the view rule. These parameters may be whitespace delimited, but importantly, multiple view rules may be specified per-row in a watch view. To explicitly separate the parameters of one view rule from the name of another - for instance, in a case like `array:16 bin`, where `bin` will not be interpreted as a view rule, but as a parameter of `array` - then commas and semicolons may be used to separate the two view rules (`array:16, bin`), or parentheses/braces/brackets may also be used to explicitly delimit the view rule parameters (`array:(16) bin`).";
@p "A list of currently-supported view rules are below:";
@unordered_list
{
@expand(DF_CoreViewRuleTable a) @p "$(a.docs == 'x' -> '`'..a.string..'` ('..a.display_name..') '..a.description)";
}
@subtitle "Breakpoints";
@p "Breakpoints interrupt execution of attached processes. They may be placed on specific code addresses, lines of source code, on specific symbol names. In the latter two cases, the higher level locations are resolved to code addresses. If there is no code associated with a line of source code, then the resolution path chooses to use the next closest line of source code in the same file. A symbol name breakpoint will only work if the symbol name is found within loaded debug info.";
@p "Breakpoints may have stop conditions attached to them. When a breakpoint is hit by a thread, before it stops execution, the stop condition is evaluated, and if it evaluates to a nonzero value, only then is execution stopped.";
@p "Each breakpoint has a hit count. Every time a breakpoint causes execution to stop, this counter is increased.";
@p "Processor breakpoints are not currently supported, but planned to be in the future.";
@subtitle "User & Profile Files";
@p "Applicable state controlling the debugger's appearance, behavior, targets, breakpoints, and other configurations is saved and reloaded across runs of the debugger through both *user files* and *profile files*. These files are auto-saved. These files are written in a textual format which can be hand-edited as necessary, but they're also continuously re-read and re-written by the debugger. By default, the debugger uses `%appdata%/raddbg/default.raddbg_user` for its user file path, and `%appdata%/raddbg/default.raddbg_profile` for its profile file path. These paths can be overridden on the command line (see the 'Command-Line Usage' section).";
@p "The *user file* defaultly stores file path maps, windows (including their preferred monitor, placement, and size), each window's panel layout and tabs, keybindings, theme colors, and fonts.";
@p "The *profile file* defaultly stores targets, breakpoints, watch pins, and exception code filters.";
@p "Because both can be hand-edited, however, if you want to store something normally stored in a user file in a profile file, or vice versa, this can be done by hand transferring the textual data from one file to another. There is no path in the debugger's UI to support this transfer, currently, although this is planned.";
//@subtitle "Driving Another Debugger Instance";
//@p "When the debugger is launched with the `--ipc` command-line argument, it does not launch another instance of the graphical debugger. Instead, it launches, sends a string encoding a command to a running instance of the graphical debugger, and then terminates. The set of commands which can be sent are identical to those which can be run from the debugger's UI itself, but these commands must be encoded textually (through the other command-line arguments). These commands are described in the 'Commands' section.";
}
File diff suppressed because it is too large Load Diff
+41
View File
@@ -0,0 +1,41 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DF_VIEW_RULE_HOOKS_H
#define DF_VIEW_RULE_HOOKS_H
////////////////////////////////
//~ rjf: Helper Types
typedef struct DF_BitmapTopologyInfo DF_BitmapTopologyInfo;
struct DF_BitmapTopologyInfo
{
U64 width;
U64 height;
R_Tex2DFormat fmt;
};
typedef struct DF_GeoTopologyInfo DF_GeoTopologyInfo;
struct DF_GeoTopologyInfo
{
U64 index_count;
Rng1U64 vertices_vaddr_range;
};
typedef struct DF_TxtTopologyInfo DF_TxtTopologyInfo;
struct DF_TxtTopologyInfo
{
TXT_LangKind lang;
U64 size_cap;
};
////////////////////////////////
//~ rjf: Helpers
internal Vec4F32 df_view_rule_hooks__rgba_from_eval(DF_Eval eval, TG_Graph *graph, RADDBG_Parsed *raddbg);
internal void df_view_rule_hooks__eval_commit_rgba(DF_Eval eval, TG_Graph *graph, RADDBG_Parsed *raddbg, DF_CtrlCtx *ctrl_ctx, Vec4F32 rgba);
internal DF_BitmapTopologyInfo df_view_rule_hooks__bitmap_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CfgNode *cfg);
internal DF_GeoTopologyInfo df_view_rule_hooks__geo_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CfgNode *cfg);
internal DF_TxtTopologyInfo df_view_rule_hooks__txt_topology_info_from_cfg(DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CfgNode *cfg);
#endif //DF_VIEW_RULE_HOOKS_H
File diff suppressed because it is too large Load Diff
+464
View File
@@ -0,0 +1,464 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEBUG_FRONTEND_VIEWS_H
#define DEBUG_FRONTEND_VIEWS_H
////////////////////////////////
//~ rjf: FileSystem @view_types
typedef enum DF_FileSortKind
{
DF_FileSortKind_Null,
DF_FileSortKind_Filename,
DF_FileSortKind_LastModified,
DF_FileSortKind_Size,
DF_FileSortKind_COUNT
}
DF_FileSortKind;
typedef struct DF_FileInfo DF_FileInfo;
struct DF_FileInfo
{
String8 filename;
FileProperties props;
DF_FuzzyMatchRangeList match_ranges;
};
typedef struct DF_FileInfoNode DF_FileInfoNode;
struct DF_FileInfoNode
{
DF_FileInfoNode *next;
DF_FileInfo file_info;
};
typedef struct DF_FileSystemViewPathState DF_FileSystemViewPathState;
struct DF_FileSystemViewPathState
{
DF_FileSystemViewPathState *hash_next;
String8 normalized_path;
Vec2S64 cursor;
};
typedef struct DF_FileSystemViewState DF_FileSystemViewState;
struct DF_FileSystemViewState
{
B32 initialized;
U64 path_state_table_size;
DF_FileSystemViewPathState **path_state_table;
DF_FileSortKind sort_kind;
Side sort_side;
Arena *cached_files_arena;
String8 cached_files_path;
DF_FileSortKind cached_files_sort_kind;
Side cached_files_sort_side;
U64 cached_file_count;
DF_FileInfo *cached_files;
F32 col_pcts[3];
};
////////////////////////////////
//~ rjf: Commands @view_types
typedef struct DF_CmdListerItem DF_CmdListerItem;
struct DF_CmdListerItem
{
DF_CmdSpec *cmd_spec;
U64 registrar_idx;
U64 ordering_idx;
DF_FuzzyMatchRangeList name_match_ranges;
DF_FuzzyMatchRangeList desc_match_ranges;
DF_FuzzyMatchRangeList tags_match_ranges;
};
typedef struct DF_CmdListerItemNode DF_CmdListerItemNode;
struct DF_CmdListerItemNode
{
DF_CmdListerItemNode *next;
DF_CmdListerItem item;
};
typedef struct DF_CmdListerItemList DF_CmdListerItemList;
struct DF_CmdListerItemList
{
DF_CmdListerItemNode *first;
DF_CmdListerItemNode *last;
U64 count;
};
typedef struct DF_CmdListerItemArray DF_CmdListerItemArray;
struct DF_CmdListerItemArray
{
DF_CmdListerItem *v;
U64 count;
};
////////////////////////////////
//~ rjf: PendingEntity @view_types
typedef struct DF_PendingEntityViewState DF_PendingEntityViewState;
struct DF_PendingEntityViewState
{
Arena *deferred_cmd_arena;
DF_CmdList deferred_cmds;
DF_Handle pick_file_override_target;
Arena *complete_cfg_arena;
DF_CfgNode *complete_cfg_root;
};
////////////////////////////////
//~ rjf: EntityLister @view_types
typedef struct DF_EntityListerItem DF_EntityListerItem;
struct DF_EntityListerItem
{
DF_Entity *entity;
DF_FuzzyMatchRangeList name_match_ranges;
};
typedef struct DF_EntityListerItemNode DF_EntityListerItemNode;
struct DF_EntityListerItemNode
{
DF_EntityListerItemNode *next;
DF_EntityListerItem item;
};
typedef struct DF_EntityListerItemList DF_EntityListerItemList;
struct DF_EntityListerItemList
{
DF_EntityListerItemNode *first;
DF_EntityListerItemNode *last;
U64 count;
};
typedef struct DF_EntityListerItemArray DF_EntityListerItemArray;
struct DF_EntityListerItemArray
{
DF_EntityListerItem *v;
U64 count;
};
////////////////////////////////
//~ rjf: SystemProcesses @view_types
typedef struct DF_ProcessInfo DF_ProcessInfo;
struct DF_ProcessInfo
{
DEMON_ProcessInfo info;
B32 is_attached;
DF_FuzzyMatchRangeList attached_match_ranges;
DF_FuzzyMatchRangeList name_match_ranges;
DF_FuzzyMatchRangeList pid_match_ranges;
};
typedef struct DF_ProcessInfoNode DF_ProcessInfoNode;
struct DF_ProcessInfoNode
{
DF_ProcessInfoNode *next;
DF_ProcessInfo info;
};
typedef struct DF_ProcessInfoList DF_ProcessInfoList;
struct DF_ProcessInfoList
{
DF_ProcessInfoNode *first;
DF_ProcessInfoNode *last;
U64 count;
};
typedef struct DF_ProcessInfoArray DF_ProcessInfoArray;
struct DF_ProcessInfoArray
{
DF_ProcessInfo *v;
U64 count;
};
////////////////////////////////
//~ rjf: Breakpoint @view_types
typedef struct DF_BreakpointViewState DF_BreakpointViewState;
struct DF_BreakpointViewState
{
B32 initialized;
Vec2S32 selected_p;
F32 key_pct;
F32 val_pct;
};
////////////////////////////////
//~ rjf: Target @view_types
typedef struct DF_TargetViewState DF_TargetViewState;
struct DF_TargetViewState
{
B32 initialized;
// rjf: pick file kind
DF_EntityKind pick_dst_kind;
// rjf: selection cursor
Vec2S64 cursor;
// rjf: text input state
TxtPt input_cursor;
TxtPt input_mark;
U8 input_buffer[1024];
U64 input_size;
B32 input_editing;
// rjf: table column pcts
F32 key_pct;
F32 value_pct;
};
////////////////////////////////
//~ rjf: FilePathMap @view_types
typedef struct DF_FilePathMapViewState DF_FilePathMapViewState;
struct DF_FilePathMapViewState
{
B32 initialized;
Vec2S64 cursor;
TxtPt input_cursor;
TxtPt input_mark;
U8 input_buffer[1024];
U64 input_size;
B32 input_editing;
DF_Handle pick_file_dst_map;
Side pick_file_dst_side;
F32 src_column_pct;
F32 dst_column_pct;
};
////////////////////////////////
//~ rjf: Modules @view_types
typedef struct DF_ModulesViewState DF_ModulesViewState;
struct DF_ModulesViewState
{
B32 initialized;
DF_Handle selected_entity;
S64 selected_column;
B32 txt_editing;
TxtPt txt_cursor;
TxtPt txt_mark;
U8 txt_buffer[1024];
U64 txt_size;
DF_Handle pick_file_dst_entity;
F32 idx_col_pct;
F32 desc_col_pct;
F32 range_col_pct;
F32 dbg_col_pct;
};
////////////////////////////////
//~ rjf: Watch, Locals, Registers @view_types
typedef struct DF_EvalRoot DF_EvalRoot;
struct DF_EvalRoot
{
DF_EvalRoot *next;
DF_EvalRoot *prev;
U64 expr_buffer_string_size;
U64 expr_buffer_cap;
U8 *expr_buffer;
};
typedef enum DF_EvalWatchViewColumnKind
{
DF_EvalWatchViewColumnKind_Expr,
DF_EvalWatchViewColumnKind_Value,
DF_EvalWatchViewColumnKind_Type,
DF_EvalWatchViewColumnKind_ViewRule,
DF_EvalWatchViewColumnKind_COUNT
}
DF_EvalWatchViewColumnKind;
typedef struct DF_EvalWatchViewState DF_EvalWatchViewState;
struct DF_EvalWatchViewState
{
B32 initialized;
// rjf; selection state
DF_EvalWatchViewColumnKind selected_column;
DF_ExpandKey selected_parent_key;
DF_ExpandKey selected_key;
// rjf: text input state
TxtPt input_cursor;
TxtPt input_mark;
U8 input_buffer[1024];
U64 input_size;
B32 input_editing;
// rjf: table column width state
F32 expr_column_pct;
F32 value_column_pct;
F32 type_column_pct;
F32 view_rule_column_pct;
// rjf: top-level expression state
DF_EvalRoot *first_root;
DF_EvalRoot *last_root;
DF_EvalRoot *first_free_root;
U64 root_count;
};
typedef struct DF_EvalThreadDerivedReadOnlyWatchViewState DF_EvalThreadDerivedReadOnlyWatchViewState;
struct DF_EvalThreadDerivedReadOnlyWatchViewState
{
Architecture cached_architecture;
DF_Handle cached_binary;
U64 cached_vaddr;
DF_EvalWatchViewState ewv;
};
typedef struct DF_RegistersViewArchState DF_RegistersViewArchState;
struct DF_RegistersViewArchState
{
B32 initialized;
DF_EvalWatchViewState ewv;
};
typedef struct DF_RegistersViewState DF_RegistersViewState;
struct DF_RegistersViewState
{
DF_RegistersViewArchState arch_state[Architecture_COUNT];
};
////////////////////////////////
//~ rjf: Code @view_types
typedef struct DF_CodeViewState DF_CodeViewState;
struct DF_CodeViewState
{
// rjf: stable state
B32 initialized;
TxtPt cursor;
TxtPt mark;
S64 preferred_column;
B32 drifted_for_search;
DF_Handle pick_file_override_target;
// rjf: per-frame command info
S64 goto_line_num;
B32 center_cursor;
B32 contain_cursor;
Arena *find_text_arena;
String8 find_text_fwd;
String8 find_text_bwd;
};
////////////////////////////////
//~ rjf: Disassembly @view_types
typedef struct DF_DisasmViewState DF_DisasmViewState;
struct DF_DisasmViewState
{
// rjf: stable state
B32 initialized;
DF_Handle process;
U64 base_vaddr;
TxtPt cursor;
TxtPt mark;
S64 preferred_column;
B32 drifted_for_search;
// rjf: per-frame command info
S64 goto_line_num;
U64 goto_vaddr;
B32 center_cursor;
B32 contain_cursor;
Arena *find_text_arena;
String8 find_text_fwd;
String8 find_text_bwd;
};
////////////////////////////////
//~ rjf: Memory @view_types
typedef struct DF_MemoryViewState DF_MemoryViewState;
struct DF_MemoryViewState
{
B32 initialized;
// rjf: last-viewed-memory cache
Arena *last_viewed_memory_cache_arena;
U8 *last_viewed_memory_cache_buffer;
Rng1U64 last_viewed_memory_cache_range;
U64 last_viewed_memory_cache_run_idx;
// rjf: control state
U64 cursor;
U64 mark;
// rjf: organization state
U64 num_columns;
U64 bytes_per_cell;
// rjf: command pass-through data
B32 center_cursor;
B32 contain_cursor;
};
////////////////////////////////
//~ rjf: Quick Sort Comparisons
internal int df_qsort_compare_file_info__default(DF_FileInfo *a, DF_FileInfo *b);
internal int df_qsort_compare_file_info__default_filtered(DF_FileInfo *a, DF_FileInfo *b);
internal int df_qsort_compare_file_info__filename(DF_FileInfo *a, DF_FileInfo *b);
internal int df_qsort_compare_file_info__last_modified(DF_FileInfo *a, DF_FileInfo *b);
internal int df_qsort_compare_file_info__size(DF_FileInfo *a, DF_FileInfo *b);
internal int df_qsort_compare_process_info(DF_ProcessInfo *a, DF_ProcessInfo *b);
internal int df_qsort_compare_cmd_lister__strength(DF_CmdListerItem *a, DF_CmdListerItem *b);
internal int df_qsort_compare_entity_lister__strength(DF_EntityListerItem *a, DF_EntityListerItem *b);
////////////////////////////////
//~ rjf: Command Lister
internal DF_CmdListerItemList df_cmd_lister_item_list_from_needle(Arena *arena, String8 needle);
internal DF_CmdListerItemArray df_cmd_lister_item_array_from_list(Arena *arena, DF_CmdListerItemList list);
internal void df_cmd_lister_item_array_sort_by_strength__in_place(DF_CmdListerItemArray array);
////////////////////////////////
//~ rjf: System Process Lister
internal DF_ProcessInfoList df_process_info_list_from_query(Arena *arena, String8 query);
internal DF_ProcessInfoArray df_process_info_array_from_list(Arena *arena, DF_ProcessInfoList list);
internal void df_process_info_array_sort_by_strength__in_place(DF_ProcessInfoArray array);
////////////////////////////////
//~ rjf: Entity Lister
internal DF_EntityListerItemList df_entity_lister_item_list_from_needle(Arena *arena, DF_EntityKind kind,
DF_EntityFlags omit_flags,
String8 needle);
internal DF_EntityListerItemArray df_entity_lister_item_array_from_list(Arena *arena, DF_EntityListerItemList list);
internal void df_entity_lister_item_array_sort_by_strength__in_place(DF_EntityListerItemArray array);
////////////////////////////////
//~ rjf: Disassembly View
internal TXTI_TokenArray df_txti_token_array_from_dasm_arch_string(Arena *arena, Architecture arch, String8 string);
////////////////////////////////
//~ rjf: Eval/Watch Views
//- rjf: root allocation/deallocation/mutation
internal DF_EvalRoot * df_eval_root_alloc(DF_View *view, DF_EvalWatchViewState *ews);
internal void df_eval_root_release(DF_EvalWatchViewState *ews, DF_EvalRoot *root);
internal void df_eval_root_equip_string(DF_EvalRoot *root, String8 string);
internal DF_EvalRoot * df_eval_root_from_string(DF_EvalWatchViewState *ews, String8 string);
internal DF_EvalRoot * df_eval_root_from_expand_key(DF_EvalWatchViewState *ews, DF_ExpandKey expand_key);
internal String8 df_string_from_eval_root(DF_EvalRoot *root);
internal DF_ExpandKey df_expand_key_from_eval_root(DF_EvalRoot *root);
//- rjf: windowed watch tree visualization
internal DF_EvalVizBlockList df_eval_viz_block_list_from_watch_view_state(Arena *arena, DBGI_Scope *scope, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_EvalWatchViewState *ews);
//- rjf: eval/watch views main hooks
internal void df_eval_watch_view_init(DF_EvalWatchViewState *ewv, DF_View *view);
internal void df_eval_watch_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalWatchViewState *ewv, DF_CmdList *cmds);
internal void df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalWatchViewState *ewv, B32 modifiable, U32 default_radix, Rng2F32 rect);
#endif // DEBUG_FRONTEND_VIEWS_H
+23
View File
@@ -0,0 +1,23 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
DF_GfxViewRuleSpecInfo df_g_gfx_view_rule_spec_info_table[] =
{
{ str8_lit_comp("array"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, 0, 0, 0, },
{ str8_lit_comp("list"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*1)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME(list) , 0, 0, 0, },
{ str8_lit_comp("dec"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(dec) , 0, 0, },
{ str8_lit_comp("bin"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(bin) , 0, 0, },
{ str8_lit_comp("oct"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(oct) , 0, 0, },
{ str8_lit_comp("hex"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(hex) , 0, 0, },
{ str8_lit_comp("only"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*1)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME(only) , DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(only) , 0, 0, },
{ str8_lit_comp("omit"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*1)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), DF_GFX_VIEW_RULE_VIZ_ROW_PROD_FUNCTION_NAME(omit) , DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(omit) , 0, 0, },
{ str8_lit_comp("no_addr"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*1)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*0), 0, DF_GFX_VIEW_RULE_LINE_STRINGIZE_FUNCTION_NAME(no_addr) , 0, 0, },
{ str8_lit_comp("rgba"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*1)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(rgba) , DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(rgba) , },
{ str8_lit_comp("text"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, 0, DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(text) , },
{ str8_lit_comp("disasm"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*0)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, 0, DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(disasm) , },
{ str8_lit_comp("bitmap"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*1)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(bitmap) , DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(bitmap) , },
{ str8_lit_comp("geo"), (DF_GfxViewRuleSpecInfoFlag_VizRowProd*0)|(DF_GfxViewRuleSpecInfoFlag_LineStringize*0)|(DF_GfxViewRuleSpecInfoFlag_RowUI*1)|(DF_GfxViewRuleSpecInfoFlag_BlockUI*1), 0, 0, DF_GFX_VIEW_RULE_ROW_UI_FUNCTION_NAME(geo) , DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_NAME(geo) , },
};
File diff suppressed because it is too large Load Diff
+679
View File
@@ -0,0 +1,679 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Generated Code
#define D_StackPushImpl(name_upper, name_lower, type, val) \
D_Bucket *bucket = d_top_bucket();\
type old_val = bucket->top_##name_lower->v;\
D_##name_upper##Node *node = push_array(d_thread_ctx->arena, D_##name_upper##Node, 1);\
node->v = (val);\
SLLStackPush(bucket->top_##name_lower, node);\
bucket->stack_gen += 1;\
return old_val
#define D_StackPopImpl(name_upper, name_lower, type) \
D_Bucket *bucket = d_top_bucket();\
type popped_val = bucket->top_##name_lower->v;\
SLLStackPop(bucket->top_##name_lower);\
bucket->stack_gen += 1;\
return popped_val
#define D_StackTopImpl(name_upper, name_lower, type) \
D_Bucket *bucket = d_top_bucket();\
type top_val = bucket->top_##name_lower->v;\
return top_val
#include "generated/draw.meta.c"
////////////////////////////////
//~ rjf: Basic Helpers
internal U64
d_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: Fancy String Type Functions
internal void
d_fancy_string_list_push(Arena *arena, D_FancyStringList *list, D_FancyString *str)
{
D_FancyStringNode *n = push_array_no_zero(arena, D_FancyStringNode, 1);
MemoryCopyStruct(&n->v, str);
SLLQueuePush(list->first, list->last, n);
list->node_count += 1;
list->total_size += str->string.size;
}
internal String8
d_string_from_fancy_string_list(Arena *arena, D_FancyStringList *list)
{
String8 result = {0};
result.size = list->total_size;
result.str = push_array_no_zero(arena, U8, result.size);
U64 idx = 0;
for(D_FancyStringNode *n = list->first; n != 0; n = n->next)
{
MemoryCopy(result.str+idx, n->v.string.str, n->v.string.size);
idx += n->v.string.size;
}
return result;
}
internal D_FancyRunList
d_fancy_run_list_from_fancy_string_list(Arena *arena, D_FancyStringList *strs)
{
ProfBeginFunction();
D_FancyRunList run_list = {0};
for(D_FancyStringNode *n = strs->first; n != 0; n = n->next)
{
D_FancyRunNode *dst_n = push_array(arena, D_FancyRunNode, 1);
dst_n->v.run = f_push_run_from_string(arena, n->v.font, n->v.size, 0, n->v.string);
dst_n->v.color = n->v.color;
dst_n->v.underline_thickness = n->v.underline_thickness;
dst_n->v.strikethrough_thickness = n->v.strikethrough_thickness;
SLLQueuePush(run_list.first, run_list.last, dst_n);
run_list.node_count += 1;
run_list.dim.x += dst_n->v.run.dim.x;
run_list.dim.y = Max(run_list.dim.y, dst_n->v.run.dim.y);
}
ProfEnd();
return run_list;
}
////////////////////////////////
//~ rjf: Top-Level API
//
// (Frame boundaries)
internal void
d_begin_frame(void)
{
if(d_thread_ctx == 0)
{
Arena *arena = arena_alloc__sized(GB(64), MB(8));
d_thread_ctx = push_array(arena, D_ThreadCtx, 1);
d_thread_ctx->arena = arena;
d_thread_ctx->arena_frame_start_pos = arena_pos(arena);
}
arena_pop_to(d_thread_ctx->arena, d_thread_ctx->arena_frame_start_pos);
d_thread_ctx->free_bucket_selection = 0;
d_thread_ctx->top_bucket = 0;
}
internal void
d_submit_bucket(OS_Handle os_window, R_Handle r_window, D_Bucket *bucket)
{
r_window_submit(os_window, r_window, &bucket->passes);
}
////////////////////////////////
//~ rjf: Bucket Construction & Selection API
//
// (Bucket: Handle to sequence of many render passes, constructed by this layer)
internal D_Bucket *
d_bucket_make(void)
{
D_Bucket *bucket = push_array(d_thread_ctx->arena, D_Bucket, 1);
D_BucketStackInits(bucket);
return bucket;
}
internal void
d_push_bucket(D_Bucket *bucket)
{
D_BucketSelectionNode *node = d_thread_ctx->free_bucket_selection;
if(node)
{
SLLStackPop(d_thread_ctx->free_bucket_selection);
}
else
{
node = push_array(d_thread_ctx->arena, D_BucketSelectionNode, 1);
}
SLLStackPush(d_thread_ctx->top_bucket, node);
node->bucket = bucket;
}
internal void
d_pop_bucket(void)
{
D_BucketSelectionNode *node = d_thread_ctx->top_bucket;
SLLStackPop(d_thread_ctx->top_bucket);
SLLStackPush(d_thread_ctx->free_bucket_selection, node);
}
internal D_Bucket *
d_top_bucket(void)
{
D_Bucket *bucket = 0;
if(d_thread_ctx->top_bucket != 0)
{
bucket = d_thread_ctx->top_bucket->bucket;
}
return bucket;
}
////////////////////////////////
//~ rjf: Bucket Stacks
//
// (Pushing/popping implicit draw parameters)
// NOTE(rjf): (The implementation of the push/pop/top functions is auto-generated)
////////////////////////////////
//~ rjf: Draw Calls
//
// (Apply to the calling thread's currently selected bucket)
//- rjf: rectangles
internal inline R_Rect2DInst *
d_rect(Rng2F32 dst, Vec4F32 color, F32 corner_radius, F32 border_thickness, F32 edge_softness)
{
Arena *arena = d_thread_ctx->arena;
D_Bucket *bucket = d_top_bucket();
R_Pass *pass = r_pass_from_kind(arena, &bucket->passes, R_PassKind_UI);
R_PassParams_UI *params = pass->params_ui;
R_BatchGroup2DList *rects = &params->rects;
R_BatchGroup2DNode *node = rects->last;
if(node == 0 || bucket->stack_gen != bucket->last_cmd_stack_gen)
{
node = push_array(arena, R_BatchGroup2DNode, 1);
SLLQueuePush(rects->first, rects->last, node);
rects->count += 1;
node->batches = r_batch_list_make(sizeof(R_Rect2DInst));
node->params.tex = r_handle_zero();
node->params.tex_sample_kind = bucket->top_tex2d_sample_kind->v;
node->params.xform = bucket->top_xform2d->v;
node->params.clip = bucket->top_clip->v;
node->params.transparency = bucket->top_transparency->v;
}
R_Rect2DInst *inst = (R_Rect2DInst *)r_batch_list_push_inst(arena, &node->batches, 256);
inst->dst = dst;
inst->src = r2f32p(0, 0, 0, 0);
inst->colors[Corner_00] = color;
inst->colors[Corner_01] = color;
inst->colors[Corner_10] = color;
inst->colors[Corner_11] = color;
inst->corner_radii[Corner_00] = corner_radius;
inst->corner_radii[Corner_01] = corner_radius;
inst->corner_radii[Corner_10] = corner_radius;
inst->corner_radii[Corner_11] = corner_radius;
inst->border_thickness = border_thickness;
inst->edge_softness = edge_softness;
inst->white_texture_override = 1.f;
bucket->last_cmd_stack_gen = bucket->stack_gen;
return inst;
}
//- rjf: images
internal inline R_Rect2DInst *
d_img(Rng2F32 dst, Rng2F32 src, R_Handle texture, Vec4F32 color, F32 corner_radius, F32 border_thickness, F32 edge_softness)
{
Arena *arena = d_thread_ctx->arena;
D_Bucket *bucket = d_top_bucket();
R_Pass *pass = r_pass_from_kind(arena, &bucket->passes, R_PassKind_UI);
R_PassParams_UI *params = pass->params_ui;
R_BatchGroup2DList *rects = &params->rects;
R_BatchGroup2DNode *node = rects->last;
if(node != 0 && bucket->stack_gen == bucket->last_cmd_stack_gen && r_handle_match(node->params.tex, r_handle_zero()))
{
node->params.tex = texture;
}
else if(node == 0 || bucket->stack_gen != bucket->last_cmd_stack_gen || !r_handle_match(texture, node->params.tex))
{
node = push_array(arena, R_BatchGroup2DNode, 1);
SLLQueuePush(rects->first, rects->last, node);
rects->count += 1;
node->batches = r_batch_list_make(sizeof(R_Rect2DInst));
node->params.tex = texture;
node->params.tex_sample_kind = bucket->top_tex2d_sample_kind->v;
node->params.xform = bucket->top_xform2d->v;
node->params.clip = bucket->top_clip->v;
node->params.transparency = bucket->top_transparency->v;
}
R_Rect2DInst *inst = (R_Rect2DInst *)r_batch_list_push_inst(arena, &node->batches, 256);
inst->dst = dst;
inst->src = src;
inst->colors[Corner_00] = color;
inst->colors[Corner_01] = color;
inst->colors[Corner_10] = color;
inst->colors[Corner_11] = color;
inst->corner_radii[Corner_00] = corner_radius;
inst->corner_radii[Corner_01] = corner_radius;
inst->corner_radii[Corner_10] = corner_radius;
inst->corner_radii[Corner_11] = corner_radius;
inst->border_thickness = border_thickness;
inst->edge_softness = edge_softness;
inst->white_texture_override = 0.f;
bucket->last_cmd_stack_gen = bucket->stack_gen;
return inst;
}
//- rjf: blurs
internal R_PassParams_Blur *
d_blur(Rng2F32 rect, F32 blur_size, F32 corner_radius)
{
Arena *arena = d_thread_ctx->arena;
D_Bucket *bucket = d_top_bucket();
R_Pass *pass = r_pass_from_kind(arena, &bucket->passes, R_PassKind_Blur);
R_PassParams_Blur *params = pass->params_blur;
params->rect = rect;
params->blur_size = blur_size;
params->corner_radii[Corner_00] = corner_radius;
params->corner_radii[Corner_01] = corner_radius;
params->corner_radii[Corner_10] = corner_radius;
params->corner_radii[Corner_11] = corner_radius;
return params;
}
//- rjf: 3d rendering pass params
internal R_PassParams_Geo3D *
d_geo3d_begin(Rng2F32 viewport, Mat4x4F32 view, Mat4x4F32 projection)
{
Arena *arena = d_thread_ctx->arena;
D_Bucket *bucket = d_top_bucket();
R_Pass *pass = r_pass_from_kind(arena, &bucket->passes, R_PassKind_Geo3D);
R_PassParams_Geo3D *params = pass->params_geo3d;
params->viewport = viewport;
params->view = view;
params->projection = projection;
return params;
}
//- rjf: meshes
internal R_Mesh3DInst *
d_mesh(R_Handle mesh_vertices, R_Handle mesh_indices, R_GeoTopologyKind mesh_geo_topology, R_GeoVertexFlags mesh_geo_vertex_flags, R_Handle albedo_tex, Mat4x4F32 inst_xform)
{
Arena *arena = d_thread_ctx->arena;
D_Bucket *bucket = d_top_bucket();
R_Pass *pass = r_pass_from_kind(arena, &bucket->passes, R_PassKind_Geo3D);
R_PassParams_Geo3D *params = pass->params_geo3d;
// rjf: mesh batch map not made yet -> make
if(params->mesh_batches.slots_count == 0)
{
params->mesh_batches.slots_count = 64;
params->mesh_batches.slots = push_array(arena, R_BatchGroup3DMapNode *, params->mesh_batches.slots_count);
}
// rjf: hash batch group 3d params
U64 hash = 0;
U64 slot_idx = 0;
{
U64 buffer[] =
{
mesh_vertices.u64[0],
mesh_vertices.u64[1],
mesh_indices.u64[0],
mesh_indices.u64[1],
(U64)mesh_geo_topology,
(U64)mesh_geo_vertex_flags,
albedo_tex.u64[0],
albedo_tex.u64[1],
(U64)d_top_tex2d_sample_kind(),
};
hash = d_hash_from_string(str8((U8 *)buffer, sizeof(buffer)));
slot_idx = hash%params->mesh_batches.slots_count;
}
// rjf: map hash -> existing batch group node
R_BatchGroup3DMapNode *node = 0;
{
for(R_BatchGroup3DMapNode *n = params->mesh_batches.slots[slot_idx]; n != 0; n = n->next)
{
if(n->hash == hash)
{
node = n;
break;
}
}
}
// rjf: no batch group node? -> make one
if(node == 0)
{
node = push_array(arena, R_BatchGroup3DMapNode, 1);
SLLStackPush(params->mesh_batches.slots[slot_idx], node);
node->hash = hash;
node->batches = r_batch_list_make(sizeof(R_Mesh3DInst));
node->params.mesh_vertices = mesh_vertices;
node->params.mesh_indices = mesh_indices;
node->params.mesh_geo_topology = mesh_geo_topology;
node->params.mesh_geo_vertex_flags = mesh_geo_vertex_flags;
node->params.albedo_tex = albedo_tex;
node->params.albedo_tex_sample_kind = d_top_tex2d_sample_kind();
node->params.xform = mat_4x4f32(1.f);
}
// rjf: push new instance to batch group
R_Mesh3DInst *inst = (R_Mesh3DInst *)r_batch_list_push_inst(arena, &node->batches, 256);
inst->xform = inst_xform;
return inst;
}
//- rjf: collating one pre-prepped bucket into parent bucket
internal void
d_sub_bucket(D_Bucket *bucket)
{
Arena *arena = d_thread_ctx->arena;
D_Bucket *src = bucket;
D_Bucket *dst = d_top_bucket();
Rng2F32 dst_clip = d_top_clip();
B32 dst_clip_is_set = !(dst_clip.x0 == 0 && dst_clip.x1 == 0 &&
dst_clip.y0 == 0 && dst_clip.y1 == 0);
for(R_PassNode *n = src->passes.first; n != 0; n = n->next)
{
R_Pass *src_pass = &n->v;
R_Pass *dst_pass = r_pass_from_kind(arena, &dst->passes, src_pass->kind);
switch(dst_pass->kind)
{
default:{dst_pass->params = src_pass->params;}break;
case R_PassKind_UI:
{
R_PassParams_UI *src_ui = src_pass->params_ui;
R_PassParams_UI *dst_ui = dst_pass->params_ui;
for(R_BatchGroup2DNode *src_group_n = src_ui->rects.first;
src_group_n != 0;
src_group_n = src_group_n->next)
{
R_BatchGroup2DNode *dst_group_n = push_array(arena, R_BatchGroup2DNode, 1);
SLLQueuePush(dst_ui->rects.first, dst_ui->rects.last, dst_group_n);
dst_ui->rects.count += 1;
MemoryCopyStruct(&dst_group_n->params, &src_group_n->params);
dst_group_n->batches = src_group_n->batches;
dst_group_n->params.xform = d_top_xform2d();
if(dst_clip_is_set)
{
B32 clip_is_set = !(dst_group_n->params.clip.x0 == 0 &&
dst_group_n->params.clip.y0 == 0 &&
dst_group_n->params.clip.x1 == 0 &&
dst_group_n->params.clip.y1 == 0);
dst_group_n->params.clip = clip_is_set ? intersect_2f32(dst_clip, dst_group_n->params.clip) : dst_clip;
}
}
}break;
}
}
}
////////////////////////////////
//~ rjf: Draw Call Helpers
//- rjf: text
internal void
d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run trailer_run)
{
ProfBeginFunction();
// rjf: grab total advance
F32 run_list_total_advance = list->dim.x;
// rjf: total advance > max? -> enable trailer
B32 trailer_enabled = (run_list_total_advance >= max_x && trailer_run.dim.x < max_x);
// rjf: draw runs
F32 advance = 0;
B32 trailer_found = 0;
Vec4F32 last_color = {0};
for(D_FancyRunNode *n = list->first; n != 0; n = n->next)
{
D_FancyRun *fr = &n->v;
F_Piece *piece_first = fr->run.pieces.v;
F_Piece *piece_opl = piece_first + fr->run.pieces.count;
F32 pre_advance = advance;
last_color = fr->color;
for(F_Piece *piece = piece_first;
piece < piece_opl;
piece += 1)
{
if(trailer_enabled && advance + piece->advance >= (max_x - trailer_run.dim.x))
{
trailer_found = 1;
break;
}
if(!trailer_enabled && advance + piece->advance >= max_x)
{
goto end_draw;
}
R_Handle texture = piece->texture;
Rng2F32 src = r2f32p((F32)piece->subrect.x0, (F32)piece->subrect.y0, (F32)piece->subrect.x1, (F32)piece->subrect.y1);
Vec2F32 size = dim_2f32(src);
Rng2F32 dst = r2f32p(p.x + piece->offset.x + advance,
p.y + piece->offset.y,
p.x + piece->offset.x + advance + size.x,
p.y + piece->offset.y + size.y);
if(!r_handle_match(texture, r_handle_zero()))
{
d_img(dst, src, texture, fr->color, 0, 0, 0);
}
advance += piece->advance;
}
if(fr->underline_thickness > 0)
{
d_rect(r2f32p(p.x+pre_advance, p.y+fr->run.descent-fr->underline_thickness/2, p.x+advance, p.y+fr->run.descent+fr->underline_thickness/2), fr->color, 0, 0, 1.f);
}
if(fr->strikethrough_thickness > 0)
{
d_rect(r2f32p(p.x+pre_advance, p.y+fr->run.descent - fr->run.ascent/2, p.x+advance, p.y+fr->run.descent - fr->run.ascent/2 + fr->strikethrough_thickness), fr->color, 0, 0, 1.f);
}
if(trailer_found)
{
break;
}
}
end_draw:;
// rjf: draw trailer
if(trailer_found)
{
F_Piece *piece_first = trailer_run.pieces.v;
F_Piece *piece_opl = piece_first + trailer_run.pieces.count;
F32 pre_advance = advance;
Vec4F32 trailer_piece_color = last_color;
for(F_Piece *piece = piece_first;
piece < piece_opl;
piece += 1)
{
R_Handle texture = piece->texture;
Rng2F32 src = r2f32p((F32)piece->subrect.x0, (F32)piece->subrect.y0, (F32)piece->subrect.x1, (F32)piece->subrect.y1);
Vec2F32 size = dim_2f32(src);
Rng2F32 dst = r2f32p(p.x + piece->offset.x + advance,
p.y + piece->offset.y,
p.x + piece->offset.x + advance + size.x,
p.y + piece->offset.y + size.y);
if(!r_handle_match(texture, r_handle_zero()))
{
d_img(dst, src, texture, trailer_piece_color, 0, 0, 0);
trailer_piece_color.w *= 0.5f;
}
advance += piece->advance;
}
}
ProfEnd();
}
internal void
d_text_run(Vec2F32 p, Vec4F32 color, F_Run run)
{
F32 advance = 0;
F_Piece *piece_first = run.pieces.v;
F_Piece *piece_opl = piece_first + run.pieces.count;
for(F_Piece *piece = piece_first;
piece < piece_opl;
piece += 1)
{
R_Handle texture = piece->texture;
Rng2F32 src = r2f32p((F32)piece->subrect.x0, (F32)piece->subrect.y0, (F32)piece->subrect.x1, (F32)piece->subrect.y1);
Vec2F32 size = dim_2f32(src);
Rng2F32 dst = r2f32p(p.x + piece->offset.x + advance,
p.y + piece->offset.y,
p.x + piece->offset.x + advance + size.x,
p.y + piece->offset.y + size.y);
if(!r_handle_match(texture, r_handle_zero()))
{
d_img(dst, src, texture, color, 0, 0, 0);
}
advance += piece->advance;
}
}
internal void
d_truncated_text_run(Vec2F32 p, Vec4F32 color, F32 max_x, F_Run text_run, F_Run trailer_run)
{
B32 truncated = 0;
B32 set_truncation = 0;
F32 truncation_p = p.x;
F32 max_x_minus_ellipses = max_x - trailer_run.dim.x;
F32 available_space = max_x - p.x;
// rjf: find last piece before truncation
B32 truncation_needed = 0;
F_Piece *last_piece_before_truncation = 0;
F32 truncation_offset = 0;
if(available_space > text_run.dim.x || available_space > trailer_run.dim.x)
{
F32 advance = 0;
F_Piece *text_run_first = text_run.pieces.v;
F_Piece *text_run_opl = text_run_first + text_run.pieces.count;
for(F_Piece *piece = text_run_first;
piece < text_run_opl;
piece += 1)
{
Rng2F32 src = r2f32p((F32)piece->subrect.x0, (F32)piece->subrect.y0, (F32)piece->subrect.x1, (F32)piece->subrect.y1);
Vec2F32 size = dim_2f32(src);
Rng2F32 dst = r2f32p(p.x + piece->offset.x + advance,
p.y + piece->offset.y,
p.x + piece->offset.x + advance + size.x,
p.y + piece->offset.y + size.y);
advance += piece->advance;
if(last_piece_before_truncation == 0 && p.x + advance > max_x_minus_ellipses)
{
truncation_offset = advance - piece->advance;
last_piece_before_truncation = piece;
}
if(p.x + advance > max_x)
{
truncation_needed = 1;
}
}
}
// rjf: draw pieces
if(available_space > text_run.dim.x || available_space > trailer_run.dim.x)
{
F32 advance = 0;
F_Piece *text_run_first = text_run.pieces.v;
F_Piece *text_run_opl = text_run_first + text_run.pieces.count;
for(F_Piece *piece = text_run_first;
piece < text_run_opl;
piece += 1)
{
if(truncation_needed && piece == last_piece_before_truncation)
{
break;
}
R_Handle texture = piece->texture;
Rng2F32 src = r2f32p((F32)piece->subrect.x0, (F32)piece->subrect.y0, (F32)piece->subrect.x1, (F32)piece->subrect.y1);
Vec2F32 size = dim_2f32(src);
Rng2F32 dst = r2f32p(p.x + piece->offset.x + advance,
p.y + piece->offset.y,
p.x + piece->offset.x + advance + size.x,
p.y + piece->offset.y + size.y);
if(!r_handle_match(texture, r_handle_zero()))
{
d_img(dst, src, texture, color, 0, 0, 0);
}
advance += piece->advance;
}
}
// rjf: draw truncation ellipses
if(truncation_needed && last_piece_before_truncation != 0)
{
Vec2F32 ellipses_p = {p.x + truncation_offset, p.y};
Vec4F32 ellipses_color = color;
F32 advance = 0;
F_Piece *trailer_run_first = trailer_run.pieces.v;
F_Piece *trailer_run_opl = trailer_run_first + trailer_run.pieces.count;
for(F_Piece *piece = trailer_run_first;
piece < trailer_run_opl;
piece += 1)
{
R_Handle texture = piece->texture;
Rng2F32 src = r2f32p((F32)piece->subrect.x0, (F32)piece->subrect.y0, (F32)piece->subrect.x1, (F32)piece->subrect.y1);
Vec2F32 size = dim_2f32(src);
Rng2F32 dst = r2f32p(ellipses_p.x + piece->offset.x + advance,
ellipses_p.y + piece->offset.y,
ellipses_p.x + piece->offset.x + advance + size.x,
ellipses_p.y + piece->offset.y + size.y);
if(!r_handle_match(texture, r_handle_zero()))
{
d_img(dst, src, texture, ellipses_color, 0, 0, 0);
}
ellipses_color.w *= 0.5f;
advance += piece->advance;
}
}
}
internal void
d_text(F_Tag font, F32 size, Vec2F32 p, Vec4F32 color, String8 string)
{
Temp scratch = scratch_begin(0, 0);
F_Run run = f_push_run_from_string(scratch.arena, font, size, 0, string);
d_text_run(p, color, run);
scratch_end(scratch);
}
internal void
d_textf(F_Tag font, F32 size, Vec2F32 p, Vec4F32 color, char *fmt, ...)
{
Temp scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 string = push_str8fv(scratch.arena, fmt, args);
va_end(args);
d_text(font, size, p, color, string);
scratch_end(scratch);
}
internal void
d_truncated_text(F_Tag font, F32 size, Vec2F32 p, Vec4F32 color, F32 max_x, String8 string)
{
Temp scratch = scratch_begin(0, 0);
F_Run run = f_push_run_from_string(scratch.arena, font, size, 0, string);
F_Run ellipses_run = f_push_run_from_string(scratch.arena, font, size, 0, str8_lit("..."));
d_truncated_text_run(p, color, max_x, run, ellipses_run);
scratch_end(scratch);
}
internal void
d_truncated_textf(F_Tag font, F32 size, Vec2F32 p, Vec4F32 color, F32 max_x, char *fmt, ...)
{
Temp scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 string = push_str8f(scratch.arena, fmt, args);
d_truncated_text(font, size, p, color, max_x, string);
va_end(args);
scratch_end(scratch);
}
+192
View File
@@ -0,0 +1,192 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DRAW_H
#define DRAW_H
////////////////////////////////
//~ rjf: Fancy String Types
typedef struct D_FancyString D_FancyString;
struct D_FancyString
{
F_Tag font;
String8 string;
Vec4F32 color;
F32 size;
F32 underline_thickness;
F32 strikethrough_thickness;
};
typedef struct D_FancyStringNode D_FancyStringNode;
struct D_FancyStringNode
{
D_FancyStringNode *next;
D_FancyString v;
};
typedef struct D_FancyStringList D_FancyStringList;
struct D_FancyStringList
{
D_FancyStringNode *first;
D_FancyStringNode *last;
U64 node_count;
U64 total_size;
};
typedef struct D_FancyRun D_FancyRun;
struct D_FancyRun
{
F_Run run;
Vec4F32 color;
F32 underline_thickness;
F32 strikethrough_thickness;
};
typedef struct D_FancyRunNode D_FancyRunNode;
struct D_FancyRunNode
{
D_FancyRunNode *next;
D_FancyRun v;
};
typedef struct D_FancyRunList D_FancyRunList;
struct D_FancyRunList
{
D_FancyRunNode *first;
D_FancyRunNode *last;
U64 node_count;
Vec2F32 dim;
};
////////////////////////////////
//~ rjf: Generated Code
#include "generated/draw.meta.h"
////////////////////////////////
//~ rjf: Draw Bucket Types
typedef struct D_Bucket D_Bucket;
struct D_Bucket
{
R_PassList passes;
U64 stack_gen;
U64 last_cmd_stack_gen;
D_BucketStackDecls;
};
////////////////////////////////
//~ rjf: Thread Context
typedef struct D_BucketSelectionNode D_BucketSelectionNode;
struct D_BucketSelectionNode
{
D_BucketSelectionNode *next;
D_Bucket *bucket;
};
typedef struct D_ThreadCtx D_ThreadCtx;
struct D_ThreadCtx
{
Arena *arena;
U64 arena_frame_start_pos;
D_BucketSelectionNode *top_bucket;
D_BucketSelectionNode *free_bucket_selection;
};
////////////////////////////////
//~ rjf: Globals
thread_static D_ThreadCtx *d_thread_ctx = 0;
////////////////////////////////
//~ rjf: Basic Helpers
internal U64 d_hash_from_string(String8 string);
////////////////////////////////
//~ rjf: Fancy String Type Functions
internal void d_fancy_string_list_push(Arena *arena, D_FancyStringList *list, D_FancyString *str);
internal String8 d_string_from_fancy_string_list(Arena *arena, D_FancyStringList *list);
internal D_FancyRunList d_fancy_run_list_from_fancy_string_list(Arena *arena, D_FancyStringList *strs);
////////////////////////////////
//~ rjf: Top-Level API
//
// (Frame boundaries & bucket submission)
internal void d_begin_frame(void);
internal void d_submit_bucket(OS_Handle os_window, R_Handle r_window, D_Bucket *bucket);
////////////////////////////////
//~ rjf: Bucket Construction & Selection API
//
// (Bucket: Handle to sequence of many render passes, constructed by this layer)
internal D_Bucket *d_bucket_make(void);
internal void d_push_bucket(D_Bucket *bucket);
internal void d_pop_bucket(void);
internal D_Bucket *d_top_bucket(void);
#define D_BucketScope(b) DeferLoop(d_push_bucket(b), d_pop_bucket())
////////////////////////////////
//~ rjf: Bucket Stacks
//
// (Pushing/popping implicit draw parameters)
internal R_Tex2DSampleKind d_push_tex2d_sample_kind(R_Tex2DSampleKind v);
internal Mat3x3F32 d_push_xform2d(Mat3x3F32 v);
internal Rng2F32 d_push_clip(Rng2F32 v);
internal F32 d_push_transparency(F32 v);
internal R_Tex2DSampleKind d_pop_tex2d_sample_kind(void);
internal Mat3x3F32 d_pop_xform2d(void);
internal Rng2F32 d_pop_clip(void);
internal F32 d_pop_transparency(void);
internal R_Tex2DSampleKind d_top_tex2d_sample_kind(void);
internal Mat3x3F32 d_top_xform2d(void);
internal Rng2F32 d_top_clip(void);
internal F32 d_top_transparency(void);
#define D_Tex2DSampleKindScope(v) DeferLoop(d_push_tex2d_sample_kind(v), d_pop_tex2d_sample_kind())
#define D_XForm2DScope(v) DeferLoop(d_push_xform2d(v), d_pop_xform2d())
#define D_ClipScope(v) DeferLoop(d_push_clip(v), d_pop_clip())
#define D_TransparencyScope(v) DeferLoop(d_push_transparency(v), d_pop_transparency())
////////////////////////////////
//~ rjf: Core Draw Calls
//
// (Apply to the calling thread's currently selected bucket)
//- rjf: rectangles
internal inline R_Rect2DInst *d_rect(Rng2F32 dst, Vec4F32 color, F32 corner_radius, F32 border_thickness, F32 edge_softness);
//- rjf: images
internal inline R_Rect2DInst *d_img(Rng2F32 dst, Rng2F32 src, R_Handle texture, Vec4F32 color, F32 corner_radius, F32 border_thickness, F32 edge_softness);
//- rjf: blurs
internal R_PassParams_Blur *d_blur(Rng2F32 rect, F32 blur_size, F32 corner_radius);
//- rjf: 3d rendering pass params
internal R_PassParams_Geo3D *d_geo3d_begin(Rng2F32 viewport, Mat4x4F32 view, Mat4x4F32 projection);
//- rjf: meshes
internal R_Mesh3DInst *d_mesh(R_Handle mesh_vertices, R_Handle mesh_indices, R_GeoTopologyKind mesh_geo_topology, R_GeoVertexFlags mesh_geo_vertex_flags, R_Handle albedo_tex, Mat4x4F32 inst_xform);
//- rjf: collating one pre-prepped bucket into parent bucket
internal void d_sub_bucket(D_Bucket *bucket);
////////////////////////////////
//~ rjf: Draw Call Helpers
//- rjf: text
internal void d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run trailer_run);
internal void d_text_run(Vec2F32 p, Vec4F32 color, F_Run run);
internal void d_truncated_text_run(Vec2F32 p, Vec4F32 color, F32 max_x, F_Run text_run, F_Run trailer_run);
internal void d_text(F_Tag font, F32 size, Vec2F32 p, Vec4F32 color, String8 string);
internal void d_textf(F_Tag font, F32 size, Vec2F32 p, Vec4F32 color, char *fmt, ...);
internal void d_truncated_text(F_Tag font, F32 size, Vec2F32 p, Vec4F32 color, F32 max_x, String8 string);
internal void d_truncated_textf(F_Tag font, F32 size, Vec2F32 p, Vec4F32 color, F32 max_x, char *fmt, ...);
#endif // DRAW_H
+58
View File
@@ -0,0 +1,58 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
@table(name, name_lower, type, default_init)
D_StackTable:
{
{Tex2DSampleKind tex2d_sample_kind R_Tex2DSampleKind `R_Tex2DSampleKind_Nearest` }
{XForm2D xform2d Mat3x3F32 `{1, 0, 0, 0, 1, 0, 0, 0, 1}` }
{Clip clip Rng2F32 `{0}` }
{Transparency transparency F32 `0` }
}
@table_gen
{
@expand(D_StackTable a) `typedef struct D_$(a.name)Node D_$(a.name)Node; struct D_$(a.name)Node {D_$(a.name)Node *next; $(a.type) v;};`;
}
@table_gen
{
`#define D_BucketStackDecls struct{\\`;
@expand(D_StackTable a) `D_$(a.name)Node *top_$(a.name_lower);\\`;
`}`;
}
@table_gen
{
@expand(D_StackTable a) `read_only global D_$(a.name)Node d_nil_$(a.name_lower) = {0, $(a.default_init)};`;
}
@table_gen
{
`#define D_BucketStackInits(b) do{\\`;
@expand(D_StackTable a) `(b)->top_$(a.name_lower) = &d_nil_$(a.name_lower);\\`;
`}while(0)`;
}
@table_gen
{
`#if 0`;
@expand(D_StackTable a) `internal $(a.type) $(=>35) d_push_$(a.name_lower)($(a.type) v);`;
@expand(D_StackTable a) `internal $(a.type) $(=>35) d_pop_$(a.name_lower)(void);`;
@expand(D_StackTable a) `internal $(a.type) $(=>35) d_top_$(a.name_lower)(void);`;
`#endif`;
}
@table_gen @c_file
{
@expand(D_StackTable a) `internal $(a.type) $(=>35) d_push_$(a.name_lower)($(a.type) v) {D_StackPushImpl($(a.name), $(a.name_lower), $(a.type), v);}`;
@expand(D_StackTable a) `internal $(a.type) $(=>35) d_pop_$(a.name_lower)(void) {D_StackPopImpl($(a.name), $(a.name_lower), $(a.type));}`;
@expand(D_StackTable a) `internal $(a.type) $(=>35) d_top_$(a.name_lower)(void) {D_StackTopImpl($(a.name), $(a.name_lower), $(a.type));}`;
}
@table_gen
{
`#if 0`;
@expand(D_StackTable a) `#define D_$(a.name)Scope(v) $(=>35) DeferLoop(d_push_$(a.name_lower)(v), d_pop_$(a.name_lower)())`;
`#endif`;
}
+17
View File
@@ -0,0 +1,17 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
internal R_Tex2DSampleKind d_push_tex2d_sample_kind(R_Tex2DSampleKind v) {D_StackPushImpl(Tex2DSampleKind, tex2d_sample_kind, R_Tex2DSampleKind, v);}
internal Mat3x3F32 d_push_xform2d(Mat3x3F32 v) {D_StackPushImpl(XForm2D, xform2d, Mat3x3F32, v);}
internal Rng2F32 d_push_clip(Rng2F32 v) {D_StackPushImpl(Clip, clip, Rng2F32, v);}
internal F32 d_push_transparency(F32 v) {D_StackPushImpl(Transparency, transparency, F32, v);}
internal R_Tex2DSampleKind d_pop_tex2d_sample_kind(void) {D_StackPopImpl(Tex2DSampleKind, tex2d_sample_kind, R_Tex2DSampleKind);}
internal Mat3x3F32 d_pop_xform2d(void) {D_StackPopImpl(XForm2D, xform2d, Mat3x3F32);}
internal Rng2F32 d_pop_clip(void) {D_StackPopImpl(Clip, clip, Rng2F32);}
internal F32 d_pop_transparency(void) {D_StackPopImpl(Transparency, transparency, F32);}
internal R_Tex2DSampleKind d_top_tex2d_sample_kind(void) {D_StackTopImpl(Tex2DSampleKind, tex2d_sample_kind, R_Tex2DSampleKind);}
internal Mat3x3F32 d_top_xform2d(void) {D_StackTopImpl(XForm2D, xform2d, Mat3x3F32);}
internal Rng2F32 d_top_clip(void) {D_StackTopImpl(Clip, clip, Rng2F32);}
internal F32 d_top_transparency(void) {D_StackTopImpl(Transparency, transparency, F32);}
+50
View File
@@ -0,0 +1,50 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
#ifndef DRAW_META_H
#define DRAW_META_H
typedef struct D_Tex2DSampleKindNode D_Tex2DSampleKindNode; struct D_Tex2DSampleKindNode {D_Tex2DSampleKindNode *next; R_Tex2DSampleKind v;};
typedef struct D_XForm2DNode D_XForm2DNode; struct D_XForm2DNode {D_XForm2DNode *next; Mat3x3F32 v;};
typedef struct D_ClipNode D_ClipNode; struct D_ClipNode {D_ClipNode *next; Rng2F32 v;};
typedef struct D_TransparencyNode D_TransparencyNode; struct D_TransparencyNode {D_TransparencyNode *next; F32 v;};
#define D_BucketStackDecls struct{\
D_Tex2DSampleKindNode *top_tex2d_sample_kind;\
D_XForm2DNode *top_xform2d;\
D_ClipNode *top_clip;\
D_TransparencyNode *top_transparency;\
}
read_only global D_Tex2DSampleKindNode d_nil_tex2d_sample_kind = {0, R_Tex2DSampleKind_Nearest};
read_only global D_XForm2DNode d_nil_xform2d = {0, {1, 0, 0, 0, 1, 0, 0, 0, 1}};
read_only global D_ClipNode d_nil_clip = {0, {0}};
read_only global D_TransparencyNode d_nil_transparency = {0, 0};
#define D_BucketStackInits(b) do{\
(b)->top_tex2d_sample_kind = &d_nil_tex2d_sample_kind;\
(b)->top_xform2d = &d_nil_xform2d;\
(b)->top_clip = &d_nil_clip;\
(b)->top_transparency = &d_nil_transparency;\
}while(0)
#if 0
internal R_Tex2DSampleKind d_push_tex2d_sample_kind(R_Tex2DSampleKind v);
internal Mat3x3F32 d_push_xform2d(Mat3x3F32 v);
internal Rng2F32 d_push_clip(Rng2F32 v);
internal F32 d_push_transparency(F32 v);
internal R_Tex2DSampleKind d_pop_tex2d_sample_kind(void);
internal Mat3x3F32 d_pop_xform2d(void);
internal Rng2F32 d_pop_clip(void);
internal F32 d_pop_transparency(void);
internal R_Tex2DSampleKind d_top_tex2d_sample_kind(void);
internal Mat3x3F32 d_top_xform2d(void);
internal Rng2F32 d_top_clip(void);
internal F32 d_top_transparency(void);
#endif
#if 0
#define D_Tex2DSampleKindScope(v) DeferLoop(d_push_tex2d_sample_kind(v), d_pop_tex2d_sample_kind())
#define D_XForm2DScope(v) DeferLoop(d_push_xform2d(v), d_pop_xform2d())
#define D_ClipScope(v) DeferLoop(d_push_clip(v), d_pop_clip())
#define D_TransparencyScope(v) DeferLoop(d_push_transparency(v), d_pop_transparency())
#endif
#endif // DRAW_META_H
+81
View File
@@ -0,0 +1,81 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
@table(name num_children op_string)
// num_children - # of children packed after this node kind
// op_string - string for quick display of the operator
EVAL_ExprKindTable:
{
{ ArrayIndex 2 "[]" }
{ MemberAccess 2 "." }
{ Deref 1 "*" }
{ Address 1 "&" }
{ Cast 2 "cast" }
{ Sizeof 1 "sizeof" }
{ Neg 1 "-" }
{ LogNot 1 "!" }
{ BitNot 1 "~" }
{ Mul 2 "*" }
{ Div 2 "/" }
{ Mod 2 "%" }
{ Add 2 "+" }
{ Sub 2 "-" }
{ LShift 2 "<<" }
{ RShift 2 ">>" }
{ Less 2 "<" }
{ LsEq 2 "<=" }
{ Grtr 2 ">" }
{ GrEq 2 ">=" }
{ EqEq 2 "==" }
{ NtEq 2 "!=" }
{ BitAnd 2 "&" }
{ BitXor 2 "^" }
{ BitOr 2 "|" }
{ LogAnd 2 "&&" }
{ LogOr 2 "||" }
{ Ternary 3 "? " }
{ LeafBytecode 0 "bytecode" }
{ LeafMember 0 "member" }
{ LeafU64 0 "U64" }
{ LeafF64 0 "F64" }
{ LeafF32 0 "F32" }
{ TypeIdent 0 "type_ident" }
{ Ptr 1 "ptr" }
{ Array 2 "array" }
{ Func 1 "function" }
}
@table_gen
{
`typedef U32 EVAL_ExprKind;`;
`enum`;
`{`;
@expand(EVAL_ExprKindTable a) `EVAL_ExprKind_$(a.name),`;
`EVAL_ExprKind_COUNT`;
`};`;
``;
}
@table_gen_data(type:U8, fallback:0)
eval_expr_kind_child_counts:
{
@expand(EVAL_ExprKindTable a) `$(a.num_children),`;
}
@table_gen_data(type:String8, fallback:`{0}`)
eval_expr_kind_strings:
{
@expand(EVAL_ExprKindTable a) `str8_lit_comp("$(a.name)"),`;
}
@table_gen_data(type:String8, fallback:`{0}`)
eval_expr_op_strings:
{
@expand(EVAL_ExprKindTable a) `str8_lit_comp("$(a.op_string)"),`;
}
File diff suppressed because it is too large Load Diff
+204
View File
@@ -0,0 +1,204 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef EVAL_COMPILER_H
#define EVAL_COMPILER_H
////////////////////////////////
//~ allen: EVAL Error Types
typedef enum EVAL_ErrorKind
{
EVAL_ErrorKind_Null,
EVAL_ErrorKind_MalformedInput,
EVAL_ErrorKind_MissingInfo,
EVAL_ErrorKind_ResolutionFailure,
EVAL_ErrorKind_COUNT
}
EVAL_ErrorKind;
typedef struct EVAL_Error EVAL_Error;
struct EVAL_Error{
EVAL_Error *next;
EVAL_ErrorKind kind;
void *location;
String8 text;
};
typedef struct EVAL_ErrorList EVAL_ErrorList;
struct EVAL_ErrorList{
EVAL_Error *first;
EVAL_Error *last;
EVAL_ErrorKind max_kind;
U64 count;
};
////////////////////////////////
//~ allen: EVAL Op List Types
enum{
EVAL_IRExtKind_Bytecode = RADDBG_EvalOp_COUNT,
EVAL_IRExtKind_COUNT
};
typedef struct EVAL_Op EVAL_Op;
struct EVAL_Op{
EVAL_Op *next;
RADDBG_EvalOp opcode;
union{
U64 p;
String8 bytecode;
};
};
typedef struct EVAL_OpList EVAL_OpList;
struct EVAL_OpList{
EVAL_Op *first_op;
EVAL_Op *last_op;
U32 op_count;
U32 encoded_size;
};
////////////////////////////////
//- allen: EVAL Expression Types
#include "eval/generated/eval.meta.h"
typedef enum EVAL_EvalMode{
EVAL_EvalMode_NULL,
EVAL_EvalMode_Value,
EVAL_EvalMode_Addr,
EVAL_EvalMode_Reg
}
EVAL_EvalMode;
typedef struct EVAL_Expr EVAL_Expr;
struct EVAL_Expr{
EVAL_ExprKind kind;
void *location;
union{
EVAL_Expr *children[3];
U32 u32;
U64 u64;
F32 f32;
F64 f64;
struct{
EVAL_Expr *child;
U64 u64;
} child_and_constant;
String8 name;
struct{
TG_Key type_key;
String8 bytecode;
EVAL_EvalMode mode;
};
};
};
global read_only EVAL_Expr eval_expr_nil = {0};
////////////////////////////////
//~ allen: EVAL Compiler Types
typedef struct EVAL_IRTree EVAL_IRTree;
struct EVAL_IRTree{
RADDBG_EvalOp op;
EVAL_IRTree *children[3];
union{
U64 p;
String8 bytecode;
};
};
global read_only EVAL_IRTree eval_irtree_nil = {0};
typedef struct EVAL_IRTreeAndType EVAL_IRTreeAndType;
struct EVAL_IRTreeAndType{
EVAL_IRTree *tree;
TG_Key type_key;
EVAL_EvalMode mode;
};
////////////////////////////////
//~ allen: Eval Error Helpers
internal void eval_error(Arena *arena, EVAL_ErrorList *list, EVAL_ErrorKind kind, void *location, String8 text);
internal void eval_errorf(Arena *arena, EVAL_ErrorList *list, EVAL_ErrorKind kind, void *location, char *fmt, ...);
internal void eval_error_list_concat_in_place(EVAL_ErrorList *dst, EVAL_ErrorList *to_push);
////////////////////////////////
//~ allen: EVAL Bytecode Helpers
internal String8 eval_bytecode_from_oplist(Arena *arena, EVAL_OpList *list);
internal void eval_oplist_push_op(Arena *arena, EVAL_OpList *list, RADDBG_EvalOp op, U64 p);
internal void eval_oplist_push_uconst(Arena *arena, EVAL_OpList *list, U64 x);
internal void eval_oplist_push_sconst(Arena *arena, EVAL_OpList *list, S64 x);
internal void eval_oplist_push_bytecode(Arena *arena, EVAL_OpList *list, String8 bytecode);
internal void eval_oplist_concat_in_place(EVAL_OpList *left_dst, EVAL_OpList *right_destroyed);
////////////////////////////////
//~ allen: EVAL Expression Info Functions
internal RADDBG_EvalOp eval_opcode_from_expr_kind(EVAL_ExprKind kind);
internal B32 eval_expr_kind_is_comparison(EVAL_ExprKind kind);
////////////////////////////////
//~ allen: EVAL Expression Constructors
internal EVAL_Expr* eval_expr(Arena *arena, EVAL_ExprKind kind, void *location, EVAL_Expr *c0, EVAL_Expr *c1, EVAL_Expr *c2);
internal EVAL_Expr* eval_expr_u64(Arena *arena, void *location, U64 u64);
internal EVAL_Expr* eval_expr_f64(Arena *arena, void *location, F64 f64);
internal EVAL_Expr* eval_expr_f32(Arena *arena, void *location, F32 f32);
internal EVAL_Expr* eval_expr_child_and_u64(Arena *arena, EVAL_ExprKind kind, void *location, EVAL_Expr *child, U64 u64);
internal EVAL_Expr* eval_expr_leaf_member(Arena *arena, void *location, String8 name);
internal EVAL_Expr* eval_expr_leaf_bytecode(Arena *arena, void *location, TG_Key type_key, String8 bytecode, EVAL_EvalMode mode);
internal EVAL_Expr* eval_expr_leaf_op_list(Arena *arena, void *location, TG_Key type_key, EVAL_OpList *ops, EVAL_EvalMode mode);
internal EVAL_Expr* eval_expr_leaf_type(Arena *arena, void *location, TG_Key type_key);
////////////////////////////////
//~ allen: EVAL Type Information Transformers
internal RADDBG_EvalTypeGroup eval_type_group_from_kind(TG_Kind kind);
internal TG_Key eval_type_unwrap(TG_Graph *graph, RADDBG_Parsed *rdbg, TG_Key key);
internal TG_Key eval_type_unwrap_enum(TG_Graph *graph, RADDBG_Parsed *rdbg, TG_Key key);
internal TG_Key eval_type_promote(TG_Graph *graph, RADDBG_Parsed *rdbg, TG_Key key);
internal TG_Key eval_type_coerce(TG_Graph *graph, RADDBG_Parsed *rdbg, TG_Key l, TG_Key r);
internal B32 eval_type_match(TG_Graph *graph, RADDBG_Parsed *rdbg, TG_Key l, TG_Key r);
internal B32 eval_kind_is_integer(TG_Kind kind);
internal B32 eval_kind_is_signed(TG_Kind kind);
internal B32 eval_kind_is_basic_or_enum(TG_Kind kind);
////////////////////////////////
//~ allen: EVAL IR-Tree Constructors
internal EVAL_IRTree* eval_irtree_const_u(Arena *arena, U64 v);
internal EVAL_IRTree* eval_irtree_unary_op(Arena *arena, RADDBG_EvalOp op, RADDBG_EvalTypeGroup group, EVAL_IRTree *c);
internal EVAL_IRTree* eval_irtree_binary_op(Arena *arena, RADDBG_EvalOp op, RADDBG_EvalTypeGroup group, EVAL_IRTree *l, EVAL_IRTree *r);
internal EVAL_IRTree* eval_irtree_binary_op_u(Arena *arena, RADDBG_EvalOp op, EVAL_IRTree *l, EVAL_IRTree *r);
internal EVAL_IRTree* eval_irtree_conditional(Arena *arena, EVAL_IRTree *c, EVAL_IRTree *l, EVAL_IRTree *r);
internal EVAL_IRTree* eval_irtree_bytecode_no_copy(Arena *arena, String8 bytecode);
////////////////////////////////
//~ allen: EVAL IR-Tree High Level Helpers
internal EVAL_IRTree* eval_irtree_mem_read_type(Arena *arena, TG_Graph *graph, RADDBG_Parsed *rdbg, EVAL_IRTree *c, TG_Key type_key);
internal EVAL_IRTree* eval_irtree_convert_lo(Arena *arena, EVAL_IRTree *c, RADDBG_EvalTypeGroup out, RADDBG_EvalTypeGroup in);
internal EVAL_IRTree* eval_irtree_trunc(Arena *arena, TG_Graph *graph, RADDBG_Parsed *rdbg, EVAL_IRTree *c, TG_Key type_key);
internal EVAL_IRTree* eval_irtree_convert_hi(Arena *arena, TG_Graph *graph, RADDBG_Parsed *rdbg, EVAL_IRTree *c, TG_Key out, TG_Key in);
internal EVAL_IRTree* eval_irtree_resolve_to_value(Arena *arena, TG_Graph *graph, RADDBG_Parsed *rdbg, EVAL_EvalMode from_mode, EVAL_IRTree *tree, TG_Key type_key);
////////////////////////////////
//~ allen: EVAL Compiler Phases
internal TG_Key eval_type_from_type_expr(Arena *arena, TG_Graph *graph, RADDBG_Parsed *rdbg, EVAL_Expr *expr, EVAL_ErrorList *eout);
internal EVAL_IRTreeAndType eval_irtree_and_type_from_expr(Arena *arena, TG_Graph *graph, RADDBG_Parsed *rdbg, EVAL_Expr *expr, EVAL_ErrorList *eout);
internal void eval_oplist_from_irtree(Arena *arena, EVAL_IRTree *tree, EVAL_OpList *out);
#endif //EVAL_COMPILER_H
+50
View File
@@ -0,0 +1,50 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
// NOTE(allen): Eval Decode Function
internal void
eval_print_decode_from_bytecode(FILE *out, String8 bytecode){
U8 *ptr = bytecode.str;
U8 *opl = bytecode.str + bytecode.size;
for (;ptr < opl;){
// consume opcode
SYMS_EvalOp op = (SYMS_EvalOp)*ptr;
if (op >= SYMS_EvalOp_COUNT){
fprintf(out, "decode error: undefined op code\n");
goto done;
}
U8 ctrlbits = syms_eval_opcode_ctrlbits[op];
ptr += 1;
// decode
U64 imm = 0;
U32 decode_size = (ctrlbits >> SYMS_EvalOpCtrlBits_DecodeShft)&SYMS_EvalOpCtrlBits_DecodeMask;
{
U8 *next_ptr = ptr + decode_size;
if (next_ptr > opl){
fprintf(out, "decode error: expected constant goes past the end of bytecode\n");
goto done;
}
// TODO(allen): to improve this:
// gaurantee 8 bytes padding after the end of serialized bytecode
// read 8 bytes and mask
switch (decode_size){
case 1: imm = *ptr; break;
case 2: imm = *(U16*)ptr; break;
case 4: imm = *(U32*)ptr; break;
case 8: imm = *(U64*)ptr; break;
}
ptr = next_ptr;
}
// op string & control bits
SYMS_String8 op_string = syms_eval_opcode_strings[op];
// print
fprintf(out, "%.*s 0x%llx\n", str8_varg(op_string), imm);
}
done:;
}
+12
View File
@@ -0,0 +1,12 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef EVAL_DECODE_H
#define EVAL_DECODE_H
////////////////////////////////
// NOTE(allen): Eval Decode Function
internal void eval_print_decode_from_bytecode(FILE *out, String8 bytecode);
#endif //EVAL_DECODE_H
+630
View File
@@ -0,0 +1,630 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ allen: Eval Machine Functions
internal EVAL_Result
eval_interpret(EVAL_Machine *machine, String8 bytecode){
EVAL_Result result = {0};
// TODO(allen): We could scan the bytecode and figure out the
// maximum depth of the stack
Temp scratch = scratch_begin(0, 0);
U64 stack_cap = 128;
EVAL_Slot *stack = push_array_no_zero(scratch.arena, EVAL_Slot, stack_cap);
U64 stack_count = 0;
U8 *ptr = bytecode.str;
U8 *opl = bytecode.str + bytecode.size;
for (;ptr < opl;){
// consume opcode
RADDBG_EvalOp op = (RADDBG_EvalOp)*ptr;
if (op >= RADDBG_EvalOp_COUNT){
result.bad_eval = 1;
goto done;
}
U8 ctrlbits = raddbg_eval_opcode_ctrlbits[op];
ptr += 1;
// decode
U64 imm = 0;
{
U32 decode_size = RADDBG_DECODEN_FROM_CTRLBITS(ctrlbits);
U8 *next_ptr = ptr + decode_size;
if (next_ptr > opl){
result.bad_eval = 1;
goto done;
}
// TODO(allen): to improve this:
// gaurantee 8 bytes padding after the end of serialized bytecode
// read 8 bytes and mask
switch (decode_size){
case 1: imm = *ptr; break;
case 2: imm = *(U16*)ptr; break;
case 4: imm = *(U32*)ptr; break;
case 8: imm = *(U64*)ptr; break;
}
ptr = next_ptr;
}
// pop
EVAL_Slot *svals = 0;
{
U32 pop_count = RADDBG_POPN_FROM_CTRLBITS(ctrlbits);
if (pop_count > stack_count){
result.bad_eval = 1;
goto done;
}
if (pop_count <= stack_count){
stack_count -= pop_count;
svals = stack + stack_count;
}
}
// interpret
EVAL_Slot nval = {0};
switch (op){
case RADDBG_EvalOp_Stop:
{
goto done;
}break;
case RADDBG_EvalOp_Noop:
{
// do nothing
}break;
case RADDBG_EvalOp_Cond:
{
if (svals[0].u64){
ptr += imm;
}
}break;
case RADDBG_EvalOp_Skip:
{
ptr += imm;
}break;
case RADDBG_EvalOp_MemRead:
{
U64 addr = svals[0].u64;
U64 size = imm;
B32 good_read = 0;
if (machine->memory_read != 0 &&
machine->memory_read(machine->u, &nval, addr, size)){
good_read = 1;
}
if (!good_read){
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_RegRead:
{
U8 raddbg_reg_code = (imm&0x0000FF)>>0;
U8 byte_size = (imm&0x00FF00)>>8;
U8 byte_off = (imm&0xFF0000)>>16;
REGS_RegCode base_reg_code = regs_reg_code_from_arch_raddbg_code(machine->arch, raddbg_reg_code);
REGS_Rng rng = regs_reg_code_rng_table_from_architecture(machine->arch)[base_reg_code];
U64 off = (U64)rng.byte_off + byte_off;
U64 size = (U64)byte_size;
if (off + size <= machine->reg_size){
MemoryCopy(&nval, (U8*)machine->reg_data + off, size);
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_RegReadDyn:
{
U64 off = svals[0].u64;
U64 size = bit_size_from_arch(machine->arch)/8;
if (off + size <= machine->reg_size){
MemoryCopy(&nval, (U8*)machine->reg_data + off, size);
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_FrameOff:
{
if (machine->frame_base != 0){
nval.u64 = *machine->frame_base + imm;
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_ModuleOff:
{
if (machine->module_base != 0){
nval.u64 = *machine->module_base + imm;
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_TLSOff:
{
if (machine->tls_base != 0){
nval.u64 = *machine->tls_base + imm;
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_ConstU8:
case RADDBG_EvalOp_ConstU16:
case RADDBG_EvalOp_ConstU32:
case RADDBG_EvalOp_ConstU64:
{
nval.u64 = imm;
}break;
case RADDBG_EvalOp_Abs:
{
if (imm == RADDBG_EvalTypeGroup_F32){
nval.f32 = svals[0].f32;
if (svals[0].f32 < 0){
nval.f32 = -svals[0].f32;
}
}
else if (imm == RADDBG_EvalTypeGroup_F64){
nval.f64 = svals[0].f64;
if (svals[0].f64 < 0){
nval.f64 = -svals[0].f64;
}
}
else{
nval.s64 = svals[0].s64;
if (svals[0].s64 < 0){
nval.s64 = -svals[0].s64;
}
}
}break;
case RADDBG_EvalOp_Neg:
{
if (imm == RADDBG_EvalTypeGroup_F32){
nval.f32 = -svals[0].f32;
}
else if (imm == RADDBG_EvalTypeGroup_F64){
nval.f64 = -svals[0].f64;
}
else{
nval.u64 = (~svals[0].u64) + 1;
}
}break;
case RADDBG_EvalOp_Add:
{
if (imm == RADDBG_EvalTypeGroup_F32){
nval.f32 = svals[0].f32 + svals[1].f32;
}
else if (imm == RADDBG_EvalTypeGroup_F64){
nval.f64 = svals[0].f64 + svals[1].f64;
}
else{
nval.u64 = svals[0].u64 + svals[1].u64;
}
}break;
case RADDBG_EvalOp_Sub:
{
if (imm == RADDBG_EvalTypeGroup_F32){
nval.f32 = svals[0].f32 - svals[1].f32;
}
else if (imm == RADDBG_EvalTypeGroup_F64){
nval.f64 = svals[0].f64 - svals[1].f64;
}
else{
nval.u64 = svals[0].u64 - svals[1].u64;
}
}break;
case RADDBG_EvalOp_Mul:
{
if (imm == RADDBG_EvalTypeGroup_F32){
nval.f32 = svals[0].f32*svals[1].f32;
}
else if (imm == RADDBG_EvalTypeGroup_F64){
nval.f64 = svals[0].f64*svals[1].f64;
}
else{
nval.u64 = svals[0].u64*svals[1].u64;
}
}break;
case RADDBG_EvalOp_Div:
{
if (imm == RADDBG_EvalTypeGroup_F32){
if (svals[1].f32 != 0.f){
nval.f32 = svals[0].f32/svals[1].f32;
}
}
else if (imm == RADDBG_EvalTypeGroup_F64){
if (svals[1].f64 != 0.){
nval.f64 = svals[0].f64/svals[1].f64;
}
}
else if (imm == RADDBG_EvalTypeGroup_U ||
imm == RADDBG_EvalTypeGroup_S){
if (svals[1].u64 != 0){
nval.u64 = svals[0].u64/svals[1].u64;
}
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_Mod:
{
if (imm == RADDBG_EvalTypeGroup_U ||
imm == RADDBG_EvalTypeGroup_S){
if (svals[1].u64 != 0){
nval.u64 = svals[0].u64%svals[1].u64;
}
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_LShift:
{
if (imm == RADDBG_EvalTypeGroup_U ||
imm == RADDBG_EvalTypeGroup_S){
nval.u64 = svals[0].u64 << svals[1].u64;
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_RShift:
{
if (imm == RADDBG_EvalTypeGroup_U){
nval.u64 = svals[0].u64 >> svals[1].u64;
}
else if (imm == RADDBG_EvalTypeGroup_S){
nval.u64 = svals[0].s64 >> svals[1].u64;
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_BitAnd:
{
if (imm == RADDBG_EvalTypeGroup_U ||
imm == RADDBG_EvalTypeGroup_S){
nval.u64 = svals[0].u64&svals[1].u64;
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_BitOr:
{
if (imm == RADDBG_EvalTypeGroup_U ||
imm == RADDBG_EvalTypeGroup_S){
nval.u64 = svals[0].u64|svals[1].u64;
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_BitXor:
{
if (imm == RADDBG_EvalTypeGroup_U ||
imm == RADDBG_EvalTypeGroup_S){
nval.u64 = svals[0].u64^svals[1].u64;
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_BitNot:
{
if (imm == RADDBG_EvalTypeGroup_U ||
imm == RADDBG_EvalTypeGroup_S){
nval.u64 = ~svals[0].u64;
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_LogAnd:
{
if (imm == RADDBG_EvalTypeGroup_U ||
imm == RADDBG_EvalTypeGroup_S){
nval.u64 = (svals[0].u64 && svals[1].u64);
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_LogOr:
{
if (imm == RADDBG_EvalTypeGroup_U ||
imm == RADDBG_EvalTypeGroup_S){
nval.u64 = (svals[0].u64 || svals[1].u64);
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_LogNot:
{
if (imm == RADDBG_EvalTypeGroup_U ||
imm == RADDBG_EvalTypeGroup_S){
nval.u64 = (!svals[0].u64);
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_EqEq:
{
nval.u64 = (svals[0].u64 == svals[1].u64);
}break;
case RADDBG_EvalOp_NtEq:
{
nval.u64 = (svals[0].u64 != svals[1].u64);
}break;
case RADDBG_EvalOp_LsEq:
{
if (imm == RADDBG_EvalTypeGroup_F32){
nval.u64 = (svals[0].f32 <= svals[1].f32);
}
else if (imm == RADDBG_EvalTypeGroup_F64){
nval.u64 = (svals[0].f64 <= svals[1].f64);
}
else if (imm == RADDBG_EvalTypeGroup_U){
nval.u64 = (svals[0].u64 <= svals[1].u64);
}
else if (imm == RADDBG_EvalTypeGroup_S){
nval.u64 = (svals[0].s64 <= svals[1].s64);
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_GrEq:
{
if (imm == RADDBG_EvalTypeGroup_F32){
nval.u64 = (svals[0].f32 >= svals[1].f32);
}
else if (imm == RADDBG_EvalTypeGroup_F64){
nval.u64 = (svals[0].f64 >= svals[1].f64);
}
else if (imm == RADDBG_EvalTypeGroup_U){
nval.u64 = (svals[0].u64 >= svals[1].u64);
}
else if (imm == RADDBG_EvalTypeGroup_S){
nval.u64 = (svals[0].s64 >= svals[1].s64);
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_Less:
{
if (imm == RADDBG_EvalTypeGroup_F32){
nval.u64 = (svals[0].f32 < svals[1].f32);
}
else if (imm == RADDBG_EvalTypeGroup_F64){
nval.u64 = (svals[0].f64 < svals[1].f64);
}
else if (imm == RADDBG_EvalTypeGroup_U){
nval.u64 = (svals[0].u64 < svals[1].u64);
}
else if (imm == RADDBG_EvalTypeGroup_S){
nval.u64 = (svals[0].s64 < svals[1].s64);
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_Grtr:
{
if (imm == RADDBG_EvalTypeGroup_F32){
nval.u64 = (svals[0].f32 > svals[1].f32);
}
else if (imm == RADDBG_EvalTypeGroup_F64){
nval.u64 = (svals[0].f64 > svals[1].f64);
}
else if (imm == RADDBG_EvalTypeGroup_U){
nval.u64 = (svals[0].u64 > svals[1].u64);
}
else if (imm == RADDBG_EvalTypeGroup_S){
nval.u64 = (svals[0].s64 > svals[1].s64);
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_Trunc:
{
if (0 < imm){
U64 mask = 0;
if (imm < 64){
mask = max_U64 >> (64 - imm);
}
nval.u64 = svals[0].u64&mask;
}
}break;
case RADDBG_EvalOp_TruncSigned:
{
if (0 < imm){
U64 mask = 0;
if (imm < 64){
mask = max_U64 >> (64 - imm);
}
U64 high = 0;
if (svals[0].u64 & (1 << (imm - 1))){
high = ~mask;
}
nval.u64 = high|(svals[0].u64&mask);
}
}break;
case RADDBG_EvalOp_Convert:
{
U32 in = imm&0xFF;
U32 out = (imm >> 8)&0xFF;
if (in != out){
switch (in + out*RADDBG_EvalTypeGroup_COUNT){
case RADDBG_EvalTypeGroup_F32 + RADDBG_EvalTypeGroup_U*RADDBG_EvalTypeGroup_COUNT:
{
nval.u64 = (U64)svals[0].f32;
}break;
case RADDBG_EvalTypeGroup_F64 + RADDBG_EvalTypeGroup_U*RADDBG_EvalTypeGroup_COUNT:
{
nval.u64 = (U64)svals[0].f64;
}break;
case RADDBG_EvalTypeGroup_F32 + RADDBG_EvalTypeGroup_S*RADDBG_EvalTypeGroup_COUNT:
{
nval.s64 = (S64)svals[0].f32;
}break;
case RADDBG_EvalTypeGroup_F64 + RADDBG_EvalTypeGroup_S*RADDBG_EvalTypeGroup_COUNT:
{
nval.s64 = (S64)svals[0].f64;
}break;
case RADDBG_EvalTypeGroup_U + RADDBG_EvalTypeGroup_F32*RADDBG_EvalTypeGroup_COUNT:
{
nval.f32 = (F32)svals[0].u64;
}break;
case RADDBG_EvalTypeGroup_S + RADDBG_EvalTypeGroup_F32*RADDBG_EvalTypeGroup_COUNT:
{
nval.f32 = (F32)svals[0].s64;
}break;
case RADDBG_EvalTypeGroup_F64 + RADDBG_EvalTypeGroup_F32*RADDBG_EvalTypeGroup_COUNT:
{
nval.f32 = (F32)svals[0].f64;
}break;
case RADDBG_EvalTypeGroup_U + RADDBG_EvalTypeGroup_F64*RADDBG_EvalTypeGroup_COUNT:
{
nval.f64 = (F64)svals[0].u64;
}break;
case RADDBG_EvalTypeGroup_S + RADDBG_EvalTypeGroup_F64*RADDBG_EvalTypeGroup_COUNT:
{
nval.f64 = (F64)svals[0].s64;
}break;
case RADDBG_EvalTypeGroup_F32 + RADDBG_EvalTypeGroup_F64*RADDBG_EvalTypeGroup_COUNT:
{
nval.f64 = (F64)svals[0].f32;
}break;
}
}
}break;
case RADDBG_EvalOp_Pick:
{
if (stack_count > imm){
nval = stack[stack_count - imm - 1];
}
else{
result.bad_eval = 1;
goto done;
}
}break;
case RADDBG_EvalOp_Pop:
{
// do nothing - the pop is handled by the control bits
}break;
case RADDBG_EvalOp_Insert:
{
if (stack_count > imm){
if (imm > 0){
EVAL_Slot tval = stack[stack_count - 1];
EVAL_Slot *dst = stack + stack_count - 1 - imm;
EVAL_Slot *shift = dst + 1;
MemoryCopy(shift, dst, imm*sizeof(EVAL_Slot));
*dst = tval;
}
}
else{
result.bad_eval = 1;
goto done;
}
}break;
}
// push
{
U64 push_count = RADDBG_PUSHN_FROM_CTRLBITS(ctrlbits);
if (push_count == 1){
if (stack_count < stack_cap){
stack[stack_count] = nval;
stack_count += 1;
}
else{
result.bad_eval = 1;
goto done;
}
}
}
}
done:;
if (stack_count == 1){
result.value = stack[0];
}
else{
result.bad_eval = 1;
}
scratch_end(scratch);
return(result);
}
+45
View File
@@ -0,0 +1,45 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef EVAL2_MACHINE_H
#define EVAL2_MACHINE_H
////////////////////////////////
//~ allen: Eval Machine Types
typedef B32 EVAL_MemoryRead(void *u, void *out, U64 addr, U64 size);
typedef struct EVAL_Machine EVAL_Machine;
struct EVAL_Machine{
void *u;
Architecture arch;
EVAL_MemoryRead *memory_read;
void *reg_data;
U64 reg_size;
U64 *module_base;
U64 *frame_base;
U64 *tls_base;
};
typedef union EVAL_Slot EVAL_Slot;
union EVAL_Slot{
U64 u256[4];
U64 u128[2];
U64 u64;
S64 s64;
F64 f64;
F32 f32;
};
typedef struct EVAL_Result EVAL_Result;
struct EVAL_Result{
EVAL_Slot value;
B32 bad_eval;
};
////////////////////////////////
//~ allen: Eval Machine Functions
internal EVAL_Result eval_interpret(EVAL_Machine *machine, String8 bytecode);
#endif //EVAL2_MACHINE_H
File diff suppressed because it is too large Load Diff
+145
View File
@@ -0,0 +1,145 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef EVAL2_PARSER_H
#define EVAL2_PARSER_H
////////////////////////////////
//~ rjf: Maps
typedef struct EVAL_String2NumMapNode EVAL_String2NumMapNode;
struct EVAL_String2NumMapNode
{
EVAL_String2NumMapNode *next;
String8 string;
U64 num;
};
typedef struct EVAL_String2NumMapSlot EVAL_String2NumMapSlot;
struct EVAL_String2NumMapSlot
{
EVAL_String2NumMapNode *first;
EVAL_String2NumMapNode *last;
};
typedef struct EVAL_String2NumMap EVAL_String2NumMap;
struct EVAL_String2NumMap
{
U64 slots_count;
EVAL_String2NumMapSlot *slots;
};
////////////////////////////////
//~ rjf: Token Types
typedef enum EVAL_TokenKind
{
EVAL_TokenKind_Null,
EVAL_TokenKind_Identifier,
EVAL_TokenKind_Numeric,
EVAL_TokenKind_StringLiteral,
EVAL_TokenKind_CharLiteral,
EVAL_TokenKind_Symbol,
EVAL_TokenKind_COUNT
}
EVAL_TokenKind;
typedef struct EVAL_Token EVAL_Token;
struct EVAL_Token
{
EVAL_TokenKind kind;
Rng1U64 range;
};
typedef struct EVAL_TokenChunkNode EVAL_TokenChunkNode;
struct EVAL_TokenChunkNode
{
EVAL_TokenChunkNode *next;
EVAL_Token *v;
U64 count;
U64 cap;
};
typedef struct EVAL_TokenChunkList EVAL_TokenChunkList;
struct EVAL_TokenChunkList
{
EVAL_TokenChunkNode *first;
EVAL_TokenChunkNode *last;
U64 node_count;
U64 total_count;
};
typedef struct EVAL_TokenArray EVAL_TokenArray;
struct EVAL_TokenArray
{
EVAL_Token *v;
U64 count;
};
////////////////////////////////
//~ rjf: Parser Types
typedef struct EVAL_ParseResult EVAL_ParseResult;
struct EVAL_ParseResult
{
EVAL_Token *last_token;
EVAL_Expr *expr;
EVAL_ErrorList errors;
};
typedef struct EVAL_ParseCtx EVAL_ParseCtx;
struct EVAL_ParseCtx
{
Architecture arch;
U64 ip_voff;
RADDBG_Parsed *rdbg;
TG_Graph *type_graph;
EVAL_String2NumMap *regs_map;
EVAL_String2NumMap *reg_alias_map;
EVAL_String2NumMap *locals_map;
EVAL_String2NumMap *member_map;
};
////////////////////////////////
//~ rjf: Globals
read_only global EVAL_String2NumMap eval_string2num_map_nil = {0};
global read_only EVAL_ParseResult eval_parse_result_nil = {0, &eval_expr_nil};
////////////////////////////////
//~ rjf: Basic Functions
internal U64 eval_hash_from_string(String8 string);
////////////////////////////////
//~ rjf: Map Functions
internal EVAL_String2NumMap eval_string2num_map_make(Arena *arena, U64 slot_count);
internal void eval_string2num_map_insert(Arena *arena, EVAL_String2NumMap *map, String8 string, U64 num);
internal U64 eval_num_from_string(EVAL_String2NumMap *map, String8 string);
////////////////////////////////
//~ rjf: Debug-Info-Driven Map Building Fast Paths
internal EVAL_String2NumMap *eval_push_locals_map_from_raddbg_voff(Arena *arena, RADDBG_Parsed *rdbg, U64 voff);
internal EVAL_String2NumMap *eval_push_member_map_from_raddbg_voff(Arena *arena, RADDBG_Parsed *rdbg, U64 voff);
////////////////////////////////
//~ rjf: Tokenization Functions
#define eval_token_at_it(it, arr) (((it) < (arr)->v+(arr)->count) ? (*(it)) : eval_token_zero())
internal EVAL_Token eval_token_zero(void);
internal void eval_token_chunk_list_push(Arena *arena, EVAL_TokenChunkList *list, U64 chunk_size, EVAL_Token *token);
internal EVAL_TokenArray eval_token_array_from_chunk_list(Arena *arena, EVAL_TokenChunkList *list);
internal EVAL_TokenArray eval_token_array_from_text(Arena *arena, String8 text);
internal EVAL_TokenArray eval_token_array_make_first_opl(EVAL_Token *first, EVAL_Token *opl);
////////////////////////////////
//~ rjf: Parser Functions
internal TG_Key eval_leaf_type_from_name(RADDBG_Parsed *rdbg, String8 name);
internal EVAL_ParseResult eval_parse_type_from_text_tokens(Arena *arena, EVAL_ParseCtx *ctx, String8 text, EVAL_TokenArray *tokens);
internal EVAL_ParseResult eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 text, EVAL_TokenArray *tokens, S64 max_precedence);
internal EVAL_ParseResult eval_parse_expr_from_text_tokens(Arena *arena, EVAL_ParseCtx *ctx, String8 text, EVAL_TokenArray *tokens);
#endif // EVAL2_PARSER_H
+5
View File
@@ -0,0 +1,5 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
+176
View File
@@ -0,0 +1,176 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE
#ifndef EVAL_META_H
#define EVAL_META_H
typedef U32 EVAL_ExprKind;
enum
{
EVAL_ExprKind_ArrayIndex,
EVAL_ExprKind_MemberAccess,
EVAL_ExprKind_Deref,
EVAL_ExprKind_Address,
EVAL_ExprKind_Cast,
EVAL_ExprKind_Sizeof,
EVAL_ExprKind_Neg,
EVAL_ExprKind_LogNot,
EVAL_ExprKind_BitNot,
EVAL_ExprKind_Mul,
EVAL_ExprKind_Div,
EVAL_ExprKind_Mod,
EVAL_ExprKind_Add,
EVAL_ExprKind_Sub,
EVAL_ExprKind_LShift,
EVAL_ExprKind_RShift,
EVAL_ExprKind_Less,
EVAL_ExprKind_LsEq,
EVAL_ExprKind_Grtr,
EVAL_ExprKind_GrEq,
EVAL_ExprKind_EqEq,
EVAL_ExprKind_NtEq,
EVAL_ExprKind_BitAnd,
EVAL_ExprKind_BitXor,
EVAL_ExprKind_BitOr,
EVAL_ExprKind_LogAnd,
EVAL_ExprKind_LogOr,
EVAL_ExprKind_Ternary,
EVAL_ExprKind_LeafBytecode,
EVAL_ExprKind_LeafMember,
EVAL_ExprKind_LeafU64,
EVAL_ExprKind_LeafF64,
EVAL_ExprKind_LeafF32,
EVAL_ExprKind_TypeIdent,
EVAL_ExprKind_Ptr,
EVAL_ExprKind_Array,
EVAL_ExprKind_Func,
EVAL_ExprKind_COUNT
};
U8 eval_expr_kind_child_counts[] =
{
2,
2,
1,
1,
2,
1,
1,
1,
1,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
3,
0,
0,
0,
0,
0,
0,
1,
2,
1,
};
String8 eval_expr_kind_strings[] =
{
str8_lit_comp("ArrayIndex"),
str8_lit_comp("MemberAccess"),
str8_lit_comp("Deref"),
str8_lit_comp("Address"),
str8_lit_comp("Cast"),
str8_lit_comp("Sizeof"),
str8_lit_comp("Neg"),
str8_lit_comp("LogNot"),
str8_lit_comp("BitNot"),
str8_lit_comp("Mul"),
str8_lit_comp("Div"),
str8_lit_comp("Mod"),
str8_lit_comp("Add"),
str8_lit_comp("Sub"),
str8_lit_comp("LShift"),
str8_lit_comp("RShift"),
str8_lit_comp("Less"),
str8_lit_comp("LsEq"),
str8_lit_comp("Grtr"),
str8_lit_comp("GrEq"),
str8_lit_comp("EqEq"),
str8_lit_comp("NtEq"),
str8_lit_comp("BitAnd"),
str8_lit_comp("BitXor"),
str8_lit_comp("BitOr"),
str8_lit_comp("LogAnd"),
str8_lit_comp("LogOr"),
str8_lit_comp("Ternary"),
str8_lit_comp("LeafBytecode"),
str8_lit_comp("LeafMember"),
str8_lit_comp("LeafU64"),
str8_lit_comp("LeafF64"),
str8_lit_comp("LeafF32"),
str8_lit_comp("TypeIdent"),
str8_lit_comp("Ptr"),
str8_lit_comp("Array"),
str8_lit_comp("Func"),
};
String8 eval_expr_op_strings[] =
{
str8_lit_comp("[]"),
str8_lit_comp("."),
str8_lit_comp("*"),
str8_lit_comp("&"),
str8_lit_comp("cast"),
str8_lit_comp("sizeof"),
str8_lit_comp("-"),
str8_lit_comp("!"),
str8_lit_comp("~"),
str8_lit_comp("*"),
str8_lit_comp("/"),
str8_lit_comp("%"),
str8_lit_comp("+"),
str8_lit_comp("-"),
str8_lit_comp("<<"),
str8_lit_comp(">>"),
str8_lit_comp("<"),
str8_lit_comp("<="),
str8_lit_comp(">"),
str8_lit_comp(">="),
str8_lit_comp("=="),
str8_lit_comp("!="),
str8_lit_comp("&"),
str8_lit_comp("^"),
str8_lit_comp("|"),
str8_lit_comp("&&"),
str8_lit_comp("||"),
str8_lit_comp("? "),
str8_lit_comp("bytecode"),
str8_lit_comp("member"),
str8_lit_comp("U64"),
str8_lit_comp("F64"),
str8_lit_comp("F32"),
str8_lit_comp("type_ident"),
str8_lit_comp("ptr"),
str8_lit_comp("array"),
str8_lit_comp("function"),
};
#endif // EVAL_META_H
File diff suppressed because it is too large Load Diff
+265
View File
@@ -0,0 +1,265 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef FONT_CACHE_H
#define FONT_CACHE_H
////////////////////////////////
//~ rjf: Rasterization Flags
typedef U32 F_RunFlags;
enum
{
F_RunFlag_Smooth = (1<<0),
};
////////////////////////////////
//~ rjf: Handles & Tags
typedef struct F_Hash F_Hash;
struct F_Hash
{
U64 u64[2];
};
typedef struct F_Tag F_Tag;
struct F_Tag
{
U64 u64[2];
};
////////////////////////////////
//~ rjf: Draw Package Types (For Cache Queries)
typedef struct F_Piece F_Piece;
struct F_Piece
{
R_Handle texture;
Rng2S16 subrect;
Vec2S16 offset;
F32 advance;
U16 decode_size;
};
typedef struct F_PieceChunkNode F_PieceChunkNode;
struct F_PieceChunkNode
{
F_PieceChunkNode *next;
F_Piece *v;
U64 count;
U64 cap;
};
typedef struct F_PieceChunkList F_PieceChunkList;
struct F_PieceChunkList
{
F_PieceChunkNode *first;
F_PieceChunkNode *last;
U64 node_count;
U64 total_piece_count;
};
typedef struct F_PieceArray F_PieceArray;
struct F_PieceArray
{
F_Piece *v;
U64 count;
};
typedef struct F_Run F_Run;
struct F_Run
{
F_PieceArray pieces;
Vec2F32 dim;
F32 ascent;
F32 descent;
};
////////////////////////////////
//~ rjf: Font Path -> Handle * Metrics * Path Cache Types
typedef struct F_FontHashNode F_FontHashNode;
struct F_FontHashNode
{
F_FontHashNode *hash_next;
F_Tag tag;
FP_Handle handle;
FP_Metrics metrics;
String8 path;
};
typedef struct F_FontHashSlot F_FontHashSlot;
struct F_FontHashSlot
{
F_FontHashNode *first;
F_FontHashNode *last;
};
////////////////////////////////
//~ rjf: Rasterization Cache Types
typedef struct F_RasterCacheInfo F_RasterCacheInfo;
struct F_RasterCacheInfo
{
Rng2S16 subrect;
S16 atlas_num;
F32 advance;
};
typedef struct F_Hash2InfoRasterCacheNode F_Hash2InfoRasterCacheNode;
struct F_Hash2InfoRasterCacheNode
{
F_Hash2InfoRasterCacheNode *hash_next;
F_Hash2InfoRasterCacheNode *hash_prev;
U64 hash;
F_RasterCacheInfo info;
};
typedef struct F_Hash2InfoRasterCacheSlot F_Hash2InfoRasterCacheSlot;
struct F_Hash2InfoRasterCacheSlot
{
F_Hash2InfoRasterCacheNode *first;
F_Hash2InfoRasterCacheNode *last;
};
typedef struct F_Hash2StyleRasterCacheNode F_Hash2StyleRasterCacheNode;
struct F_Hash2StyleRasterCacheNode
{
F_Hash2StyleRasterCacheNode *hash_next;
F_Hash2StyleRasterCacheNode *hash_prev;
U64 style_hash;
F32 ascent;
F32 descent;
F_RasterCacheInfo *utf8_class1_direct_map;
U64 utf8_class1_direct_map_mask[4];
U64 hash2info_slots_count;
F_Hash2InfoRasterCacheSlot *hash2info_slots;
};
typedef struct F_Hash2StyleRasterCacheSlot F_Hash2StyleRasterCacheSlot;
struct F_Hash2StyleRasterCacheSlot
{
F_Hash2StyleRasterCacheNode *first;
F_Hash2StyleRasterCacheNode *last;
};
////////////////////////////////
//~ rjf: Atlas Types
typedef U32 F_AtlasRegionNodeFlags;
enum
{
F_AtlasRegionNodeFlag_Taken = (1<<0),
};
typedef struct F_AtlasRegionNode F_AtlasRegionNode;
struct F_AtlasRegionNode
{
F_AtlasRegionNode *parent;
F_AtlasRegionNode *children[Corner_COUNT];
Vec2S16 max_free_size[Corner_COUNT];
F_AtlasRegionNodeFlags flags;
U64 num_allocated_descendants;
};
typedef struct F_Atlas F_Atlas;
struct F_Atlas
{
F_Atlas *next;
F_Atlas *prev;
R_Handle texture;
Vec2S16 root_dim;
F_AtlasRegionNode *root;
};
////////////////////////////////
//~ rjf: Metrics
typedef struct F_Metrics F_Metrics;
struct F_Metrics
{
F32 ascent;
F32 descent;
F32 line_gap;
F32 capital_height;
};
////////////////////////////////
//~ rjf: Main State Type
typedef struct F_State F_State;
struct F_State
{
Arena *arena;
// rjf: font table
U64 font_hash_table_size;
F_FontHashSlot *font_hash_table;
// rjf: hash -> raster cache table
U64 hash2style_slots_count;
F_Hash2StyleRasterCacheSlot *hash2style_slots;
// rjf: atlas list
F_Atlas *first_atlas;
F_Atlas *last_atlas;
};
////////////////////////////////
//~ rjf: Globals
global F_State *f_state = 0;
////////////////////////////////
//~ rjf: Basic Functions
internal F_Hash f_hash_from_string(String8 string);
internal U64 f_little_hash_from_string(String8 string);
internal Vec2S32 f_vertex_from_corner(Corner corner);
////////////////////////////////
//~ rjf: Font Tags
internal F_Tag f_tag_zero(void);
internal B32 f_tag_match(F_Tag a, F_Tag b);
internal FP_Handle f_handle_from_tag(F_Tag tag);
internal FP_Metrics f_fp_metrics_from_tag(F_Tag tag);
internal F_Tag f_tag_from_path(String8 path);
internal F_Tag f_tag_from_static_data_string(String8 *data_ptr);
internal String8 f_path_from_tag(F_Tag tag);
////////////////////////////////
//~ rjf: Atlas
internal Rng2S16 f_atlas_region_alloc(Arena *arena, F_Atlas *atlas, Vec2S16 needed_size);
internal void f_atlas_region_release(F_Atlas *atlas, Rng2S16 region);
////////////////////////////////
//~ rjf: Piece Type Functions
internal F_Piece *f_piece_chunk_list_push_new(Arena *arena, F_PieceChunkList *list, U64 cap);
internal void f_piece_chunk_list_push(Arena *arena, F_PieceChunkList *list, U64 cap, F_Piece *piece);
internal F_PieceArray f_piece_array_from_chunk_list(Arena *arena, F_PieceChunkList *list);
////////////////////////////////
//~ rjf: Rasterization Cache
internal F_Hash2StyleRasterCacheNode *f_hash2style_from_tag_size(F_Tag tag, F32 size);
internal F_Run f_push_run_from_string(Arena *arena, F_Tag tag, F32 size, F_RunFlags flags, String8 string);
internal String8List f_wrapped_string_lines_from_font_size_string_max(Arena *arena, F_Tag font, F32 size, String8 string, F32 max);
internal Vec2F32 f_dim_from_tag_size_string(F_Tag tag, F32 size, String8 string);
internal Vec2F32 f_dim_from_tag_size_string_list(F_Tag tag, F32 size, String8List list);
internal U64 f_char_pos_from_tag_size_string_p(F_Tag tag, F32 size, String8 string, F32 p);
////////////////////////////////
//~ rjf: Metrics
internal F_Metrics f_metrics_from_tag_size(F_Tag tag, F32 size);
internal F32 f_line_height_from_metrics(F_Metrics *metrics);
////////////////////////////////
//~ rjf: Main Calls
internal void f_init(void);
#endif // FONT_CACHE_H
@@ -0,0 +1,449 @@
////////////////////////////////
//~ rjf: Globals
global FP_DWrite_State *fp_dwrite_state = 0;
global FP_DWrite_FontFileLoaderVTable fp_dwrite_static_data_font_file_loader__vtable =
{
fp_dwrite_iunknown_noop__query_interface,
fp_dwrite_iunknown_noop__add_ref,
fp_dwrite_iunknown_noop__release,
fp_dwrite_static_font_file_loader__stream_from_key,
};
global FP_DWrite_FontFileLoader fp_dwrite_static_data_font_file_loader = {&fp_dwrite_static_data_font_file_loader__vtable};
global FP_DWrite_FontFileStreamVTable fp_dwrite_static_data_font_file_stream__vtable =
{
fp_dwrite_iunknown_noop__query_interface,
fp_dwrite_iunknown_noop__add_ref,
fp_dwrite_iunknown_noop__release,
fp_dwrite_static_font_file_stream__read_file_fragment,
fp_dwrite_static_font_file_stream__release_file_fragment,
fp_dwrite_static_font_file_stream__get_file_size,
fp_dwrite_static_font_file_stream__get_last_write_time,
};
////////////////////////////////
//~ rjf: Helpers
//- rjf: handle conversion functions
internal FP_DWrite_Font
fp_dwrite_font_from_handle(FP_Handle handle)
{
FP_DWrite_Font result = {0};
result.file = (IDWriteFontFile *)handle.u64[0];
result.face = (IDWriteFontFace *)handle.u64[1];
return result;
}
internal FP_Handle
fp_dwrite_handle_from_font(FP_DWrite_Font font)
{
FP_Handle result = {0};
result.u64[0] = (U64)font.file;
result.u64[1] = (U64)font.face;
return result;
}
//- rjf: file stream allocator
internal FP_DWrite_FontFileStreamNode *
fp_dwrite_font_file_stream_node_alloc(String8 *data_ptr)
{
FP_DWrite_FontFileStreamNode *node = 0;
for(FP_DWrite_FontFileStreamNode *n = fp_dwrite_state->first_stream_node; n != 0; n = n->next)
{
if(n->stream.data == data_ptr)
{
node = n;
break;
}
}
if(node == 0)
{
node = fp_dwrite_state->free_stream_node;
if(node != 0)
{
SLLStackPop(fp_dwrite_state->free_stream_node);
}
else
{
node = push_array_no_zero(fp_dwrite_state->arena, FP_DWrite_FontFileStreamNode, 1);
}
MemoryZeroStruct(node);
node->stream.lpVtbl = &fp_dwrite_static_data_font_file_stream__vtable;
node->stream.data = data_ptr;
DLLPushBack(fp_dwrite_state->first_stream_node, fp_dwrite_state->last_stream_node, node);
}
return node;
}
internal void
fp_dwrite_font_file_stream_node_release(FP_DWrite_FontFileStreamNode *node)
{
DLLPushBack(fp_dwrite_state->first_stream_node, fp_dwrite_state->last_stream_node, node);
SLLStackPush(fp_dwrite_state->free_stream_node, node);
}
//- rjf: iunknown no-op helpers
internal HRESULT
fp_dwrite_iunknown_noop__query_interface(void *obj, REFIID riid, void *ptr_to_object)
{
return E_NOINTERFACE;
}
internal ULONG
fp_dwrite_iunknown_noop__add_ref(void *obj)
{
ULONG result = 1;
return result;
}
internal ULONG
fp_dwrite_iunknown_noop__release(void *obj)
{
ULONG result = 1;
return result;
}
//- rjf: font file loader interface function implementations
internal HRESULT
fp_dwrite_static_font_file_loader__stream_from_key(FP_DWrite_FontFileLoader *obj, void const *font_file_ref_key, UINT32 font_file_ref_key_size, IDWriteFontFileStream **stream_out)
{
HRESULT result = S_OK;
String8 *key = *(String8 **)font_file_ref_key;
FP_DWrite_FontFileStreamNode *node = fp_dwrite_font_file_stream_node_alloc(key);
*stream_out = (IDWriteFontFileStream *)&node->stream;
return result;
}
//- rjf: font file stream interface function implementations
internal HRESULT
fp_dwrite_static_font_file_stream__read_file_fragment(FP_DWrite_FontFileStream *obj, void const **fragment_start, UINT64 file_offset, UINT64 fragment_size, void **fragment_context)
{
HRESULT result = S_OK;
*fragment_start = obj->data->str + file_offset;
*fragment_context = 0;
return result;
}
internal HRESULT
fp_dwrite_static_font_file_stream__release_file_fragment(FP_DWrite_FontFileStream *obj, void *fragment_context)
{
HRESULT result = S_OK;
return result;
}
internal HRESULT
fp_dwrite_static_font_file_stream__get_file_size(FP_DWrite_FontFileStream *obj, UINT64 *size_out)
{
HRESULT result = S_OK;
*size_out = obj->data->size;
return result;
}
internal HRESULT
fp_dwrite_static_font_file_stream__get_last_write_time(FP_DWrite_FontFileStream *obj, UINT64 *time_out)
{
HRESULT result = S_OK;
*time_out = 0;
return result;
}
////////////////////////////////
//~ rjf: Backend Implementations
fp_hook void
fp_init(void)
{
ProfBeginFunction();
HRESULT error = 0;
//- rjf: initialize main state
{
Arena *arena = arena_alloc();
fp_dwrite_state = push_array(arena, FP_DWrite_State, 1);
fp_dwrite_state->arena = arena;
}
//- rjf: make dwrite factory
error = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), (IUnknown **)&fp_dwrite_state->factory);
//- rjf: register static data font "loader" interface
error = fp_dwrite_state->factory->RegisterFontFileLoader((IDWriteFontFileLoader *)&fp_dwrite_static_data_font_file_loader);
//- rjf: make base rendering params
error = fp_dwrite_state->factory->CreateRenderingParams(&fp_dwrite_state->base_rendering_params);
//- rjf: make sharp rendering params
{
FLOAT gamma = 1.f;
FLOAT enhanced_contrast = fp_dwrite_state->base_rendering_params->GetEnhancedContrast();
// FLOAT clear_type_level = fp_dwrite_state->base_rendering_params->GetClearTypeLevel();
error = fp_dwrite_state->factory->CreateCustomRenderingParams(gamma,
enhanced_contrast,
2.f,
DWRITE_PIXEL_GEOMETRY_FLAT,
DWRITE_RENDERING_MODE_GDI_NATURAL,
&fp_dwrite_state->rendering_params[FP_RasterMode_Sharp]);
}
//- rjf: make smooth rendering params
{
FLOAT gamma = 1.f;
FLOAT enhanced_contrast = fp_dwrite_state->base_rendering_params->GetEnhancedContrast();
// FLOAT clear_type_level = fp_dwrite_state->base_rendering_params->GetClearTypeLevel();
error = fp_dwrite_state->factory->CreateCustomRenderingParams(gamma,
enhanced_contrast,
2.f,
DWRITE_PIXEL_GEOMETRY_FLAT,
DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC,
&fp_dwrite_state->rendering_params[FP_RasterMode_Smooth]);
}
//- rjf: make dwrite gdi interop
error = fp_dwrite_state->factory->GetGdiInterop(&fp_dwrite_state->gdi_interop);
//- rjf: build render target for rasterization
fp_dwrite_state->bitmap_render_target_dim = v2s32(2048, 256);
error = fp_dwrite_state->gdi_interop->CreateBitmapRenderTarget(0, fp_dwrite_state->bitmap_render_target_dim.x, fp_dwrite_state->bitmap_render_target_dim.y, &fp_dwrite_state->bitmap_render_target);
fp_dwrite_state->bitmap_render_target->SetPixelsPerDip(1.0);
ProfEnd();
}
fp_hook FP_Handle
fp_font_open(String8 path)
{
ProfBeginFunction();
Temp scratch = scratch_begin(0, 0);
String16 path16 = str16_from_8(scratch.arena, path);
FP_DWrite_Font font = {0};
HRESULT error = 0;
//- rjf: open font file reference
error = fp_dwrite_state->factory->CreateFontFileReference((WCHAR *)path16.str, 0, &font.file);
//- rjf: open font face
error = fp_dwrite_state->factory->CreateFontFace(DWRITE_FONT_FACE_TYPE_TRUETYPE, 1, &font.file, 0, DWRITE_FONT_SIMULATIONS_NONE, &font.face);
//- rjf: handlify & return
FP_Handle handle = fp_dwrite_handle_from_font(font);
scratch_end(scratch);
ProfEnd();
return handle;
}
fp_hook FP_Handle
fp_font_open_from_static_data_string(String8 *data_ptr)
{
ProfBeginFunction();
Temp scratch = scratch_begin(0, 0);
FP_DWrite_Font font = {0};
HRESULT error = 0;
//- rjf: open font file reference
error = fp_dwrite_state->factory->CreateCustomFontFileReference(&data_ptr, sizeof(String8 *), (IDWriteFontFileLoader *)&fp_dwrite_static_data_font_file_loader, &font.file);
//- rjf: open font face
error = fp_dwrite_state->factory->CreateFontFace(DWRITE_FONT_FACE_TYPE_TRUETYPE, 1, &font.file, 0, DWRITE_FONT_SIMULATIONS_NONE, &font.face);
//- rjf: handlify & return
FP_Handle handle = fp_dwrite_handle_from_font(font);
scratch_end(scratch);
ProfEnd();
return handle;
}
fp_hook void
fp_font_close(FP_Handle handle)
{
ProfBeginFunction();
FP_DWrite_Font font = fp_dwrite_font_from_handle(handle);
if(font.face != 0)
{
font.face->Release();
}
if(font.file != 0)
{
font.file->Release();
}
ProfEnd();
}
fp_hook FP_Metrics
fp_metrics_from_font(FP_Handle handle)
{
ProfBeginFunction();
FP_DWrite_Font font = fp_dwrite_font_from_handle(handle);
DWRITE_FONT_METRICS metrics = {0};
if(font.face != 0)
{
font.face->GetMetrics(&metrics);
}
FP_Metrics result = {0};
{
result.design_units_per_em = (F32)metrics.designUnitsPerEm;
result.ascent = (F32)metrics.ascent;
result.descent = (F32)metrics.descent;
result.line_gap = (F32)metrics.lineGap;
result.capital_height = (F32)metrics.capHeight;
}
ProfEnd();
return result;
}
fp_hook NO_ASAN FP_RasterResult
fp_raster(Arena *arena, FP_Handle font_handle, F32 size, FP_RasterMode mode, String8 string)
{
ProfBeginFunction();
Temp scratch = scratch_begin(&arena, 1);
HRESULT error = 0;
String32 string32 = str32_from_8(scratch.arena, string);
FP_DWrite_Font font = fp_dwrite_font_from_handle(font_handle);
COLORREF bg_color = RGB(0, 0, 0);
COLORREF fg_color = RGB(255, 255, 255);
//- rjf: get font metrics
DWRITE_FONT_METRICS font_metrics = {0};
if(font.face != 0)
{
font.face->GetMetrics(&font_metrics);
}
F32 design_units_per_em = (F32)font_metrics.designUnitsPerEm;
//- rjf: get glyph indices
U16 *glyph_indices = push_array_no_zero(scratch.arena, U16, string32.size);
if(font.face != 0)
{
error = font.face->GetGlyphIndices(string32.str, string32.size, glyph_indices);
}
//- rjf: get metrics info
U64 glyphs_count = string32.size;
DWRITE_GLYPH_METRICS *glyphs_metrics = push_array_no_zero(scratch.arena, DWRITE_GLYPH_METRICS, glyphs_count);
if(font.face != 0)
{
error = font.face->GetGdiCompatibleGlyphMetrics((96.f/72.f)*size, 1.f, 0, 1, glyph_indices, glyphs_count, glyphs_metrics, 0);
}
//- rjf: derive info from metrics
F32 advance = 0;
Vec2S16 atlas_dim = {0};
if(font.face != 0)
{
atlas_dim.y = (S16)((96.f/72.f) * size * (font_metrics.ascent + font_metrics.descent) / design_units_per_em);
for(U64 idx = 0; idx < glyphs_count; idx += 1)
{
DWRITE_GLYPH_METRICS *glyph_metrics = glyphs_metrics + idx;
F32 glyph_advance_width = (96.f/72.f) * size * glyph_metrics->advanceWidth / design_units_per_em;
F32 glyph_advance_height = (96.f/72.f) * size * glyph_metrics->advanceHeight / design_units_per_em;
advance += glyph_advance_width;
atlas_dim.x = Max(atlas_dim.x, (S16)(advance+1));
}
atlas_dim.x += 7;
atlas_dim.x -= atlas_dim.x%8;
atlas_dim.x += 4;
atlas_dim.y += 4;
}
//- rjf: make dwrite bitmap for rendering
IDWriteBitmapRenderTarget *render_target = 0;
if(font.face != 0)
{
error = fp_dwrite_state->gdi_interop->CreateBitmapRenderTarget(0, atlas_dim.x, atlas_dim.y, &render_target);
render_target->SetPixelsPerDip(1.0);
}
//- rjf: get bitmap & clear
HDC dc = 0;
if(font.face != 0)
{
dc = render_target->GetMemoryDC();
HGDIOBJ original = SelectObject(dc, GetStockObject(DC_PEN));
SetDCPenColor(dc, bg_color);
SelectObject(dc, GetStockObject(DC_BRUSH));
SetDCBrushColor(dc, bg_color);
Rectangle(dc, 0, 0, atlas_dim.x, atlas_dim.y);
SelectObject(dc, original);
}
//- rjf: draw glyph run
Vec2F32 draw_p = {1, (F32)atlas_dim.y - 2.f};
if(font.face != 0)
{
F32 ascent = (96.f/72.f)*size * font_metrics.ascent / design_units_per_em;
F32 descent = (96.f/72.f)*size * font_metrics.descent / design_units_per_em;
draw_p.y -= descent;
}
DWRITE_GLYPH_RUN glyph_run = {0};
if(font.face != 0)
{
glyph_run.fontFace = font.face;
glyph_run.fontEmSize = size * 96.f/72.f;
glyph_run.glyphCount = string32.size;
glyph_run.glyphIndices = glyph_indices;
}
RECT bounding_box = {0};
if(font.face != 0)
{
error = render_target->DrawGlyphRun(draw_p.x, draw_p.y,
DWRITE_MEASURING_MODE_NATURAL,
&glyph_run,
fp_dwrite_state->rendering_params[mode],
fg_color,
&bounding_box);
}
//- rjf: get bitmap
DIBSECTION dib = {0};
if(font.face != 0)
{
HBITMAP bitmap = (HBITMAP)GetCurrentObject(dc, OBJ_BITMAP);
GetObject(bitmap, sizeof(dib), &dib);
}
//- rjf: fill & return
FP_RasterResult result = {0};
if(font.face != 0)
{
// rjf: fill basics
result.atlas_dim = atlas_dim;
result.atlas = push_array_no_zero(arena, U8, atlas_dim.x*atlas_dim.y*4);
result.advance = advance;
result.height = bounding_box.bottom + 1.f;
// rjf: fill atlas
{
U8 *in_data = (U8 *)dib.dsBm.bmBits;
U64 in_pitch = (U64)dib.dsBm.bmWidthBytes;
U8 *out_data = (U8 *)result.atlas;
U64 out_pitch = atlas_dim.x * 4;
U8 *in_line = (U8 *)in_data;
U8 *out_line = out_data;
for(U64 y = 0; y < atlas_dim.y; y += 1)
{
U8 *in_pixel = in_line;
U8 *out_pixel = out_line;
for(U64 x = 0; x < atlas_dim.x; x += 1)
{
U8 in_pixel_byte = in_pixel[0];
out_pixel[0] = 255;
out_pixel[1] = 255;
out_pixel[2] = 255;
out_pixel[3] = in_pixel_byte;
in_pixel += 4;
out_pixel += 4;
}
in_line += in_pitch;
out_line += out_pitch;
}
}
render_target->Release();
}
scratch_end(scratch);
ProfEnd();
return result;
}
@@ -0,0 +1,99 @@
/* date = November 2nd 2022 11:31 am */
#ifndef FONT_PROVIDER_DWRITE_H
#define FONT_PROVIDER_DWRITE_H
#include <dwrite.h>
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "dwrite.lib")
//- rjf: font file loader interface types
struct FP_DWrite_FontFileLoaderVTable
{
HRESULT (*QueryInterface)(void *obj, REFIID riid, void *ptr_to_object);
ULONG (*AddRef)(void *obj);
ULONG (*Release)(void *obj);
HRESULT (*CreateStreamFromKey)(struct FP_DWrite_FontFileLoader *loader, void const *font_file_ref_key, UINT32 font_file_ref_key_size, IDWriteFontFileStream **stream_out);
};
struct FP_DWrite_FontFileLoader
{
FP_DWrite_FontFileLoaderVTable *lpVtbl;
};
//- rjf: font file stream interface types
struct FP_DWrite_FontFileStreamVTable
{
HRESULT (*QueryInterface)(void *obj, REFIID riid, void *ptr_to_object);
ULONG (*AddRef)(void *obj);
ULONG (*Release)(void *obj);
HRESULT (*ReadFileFragment)(struct FP_DWrite_FontFileStream *obj, void const **fragment_start, UINT64 file_offset, UINT64 fragment_size, void **fragment_context);
HRESULT (*ReleaseFileFragment)(struct FP_DWrite_FontFileStream *obj, void *fragment_context);
HRESULT (*GetFileSize)(struct FP_DWrite_FontFileStream *obj, UINT64 *size_out);
HRESULT (*GetLastWriteTime)(struct FP_DWrite_FontFileStream *obj, UINT64 *time_out);
};
struct FP_DWrite_FontFileStream
{
FP_DWrite_FontFileStreamVTable *lpVtbl;
String8 *data;
};
struct FP_DWrite_FontFileStreamNode
{
FP_DWrite_FontFileStreamNode *next;
FP_DWrite_FontFileStreamNode *prev;
FP_DWrite_FontFileStream stream;
};
//- rjf: state & underlying handle types
struct FP_DWrite_State
{
Arena *arena;
IDWriteFactory *factory;
IDWriteRenderingParams *base_rendering_params;
IDWriteRenderingParams *rendering_params[FP_RasterMode_COUNT];
IDWriteGdiInterop *gdi_interop;
Vec2S32 bitmap_render_target_dim;
IDWriteBitmapRenderTarget *bitmap_render_target;
FP_DWrite_FontFileStreamNode *first_stream_node;
FP_DWrite_FontFileStreamNode *last_stream_node;
FP_DWrite_FontFileStreamNode *free_stream_node;
};
struct FP_DWrite_Font
{
IDWriteFontFile *file;
IDWriteFontFace *face;
};
////////////////////////////////
//~ rjf: Helpers
//- rjf: handle conversion functions
internal FP_DWrite_Font fp_dwrite_font_from_handle(FP_Handle handle);
internal FP_Handle fp_dwrite_handle_from_font(FP_DWrite_Font font);
//- rjf: file stream allocator
internal FP_DWrite_FontFileStreamNode *fp_dwrite_font_file_stream_node_alloc(String8 *data_ptr);
internal void fp_dwrite_font_file_stream_node_release(FP_DWrite_FontFileStreamNode *node);
//- rjf: iunknown no-op helpers
internal HRESULT fp_dwrite_iunknown_noop__query_interface(void *obj, REFIID riid, void *ptr_to_object);
internal ULONG fp_dwrite_iunknown_noop__add_ref(void *obj);
internal ULONG fp_dwrite_iunknown_noop__release(void *obj);
//- rjf: font file loader interface function implementations
internal HRESULT fp_dwrite_static_font_file_loader__stream_from_key(FP_DWrite_FontFileLoader *obj, void const *font_file_ref_key, UINT32 font_file_ref_key_size, IDWriteFontFileStream **stream_out);
//- rjf: font file stream interface function implementations
internal HRESULT fp_dwrite_static_font_file_stream__read_file_fragment(FP_DWrite_FontFileStream *obj, void const **fragment_start, UINT64 file_offset, UINT64 fragment_size, void **fragment_context);
internal HRESULT fp_dwrite_static_font_file_stream__release_file_fragment(FP_DWrite_FontFileStream *obj, void *fragment_context);
internal HRESULT fp_dwrite_static_font_file_stream__get_file_size(FP_DWrite_FontFileStream *obj, UINT64 *size_out);
internal HRESULT fp_dwrite_static_font_file_stream__get_last_write_time(FP_DWrite_FontFileStream *obj, UINT64 *time_out);
#endif // FONT_PROVIDER_DWRITE_H
@@ -0,0 +1,12 @@
#define SUPPLEMENT_UNIT 1
#include "base/base_inc.h"
#include "os/os_inc.h"
#include "font_provider/font_provider.h"
#include "font_provider_dwrite.h"
#include "font_provider_dwrite.cpp"
#include "base/base_inc.c"
#include "os/os_inc.c"
#include "font_provider/font_provider.c"

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