From ec9c68f55ee102e5d2c2d1cd8dbd844f907c941f Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Tue, 16 Jul 2024 17:23:08 -0700 Subject: [PATCH] start work on raddbg building --- build.sh | 5 +- src/base/base_core.h | 9 + src/base/base_log.h | 130 ++++++------- src/demon/demon_inc.h | 30 +-- src/font_provider/font_provider_inc.h | 66 +++---- src/os/gfx/linux/os_gfx_linux.c | 251 ++++++++++++++++++++++++++ src/os/gfx/linux/os_gfx_linux.h | 14 ++ src/os/gfx/os_gfx.h | 6 +- src/os/gfx/stub/os_gfx_stub.c | 10 + 9 files changed, 403 insertions(+), 118 deletions(-) create mode 100644 src/os/gfx/linux/os_gfx_linux.c create mode 100644 src/os/gfx/linux/os_gfx_linux.h diff --git a/build.sh b/build.sh index a63c1c95..3a8bc784 100644 --- a/build.sh +++ b/build.sh @@ -14,7 +14,7 @@ if [ "$gcc" = "1" ]; then clang=0 && echo "[gcc compile]"; fi auto_compile_flags='' # --- Compile/Link Line Definitions ------------------------------------------- -clang_common='-I../src/ -I../local/ -gcodeview -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf' +clang_common='-I../src/ -I../local/ -gcodeview -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Wno-for-loop-analysis -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf' clang_debug="clang -g -O0 -DBUILD_DEBUG=1 ${clang_common} ${auto_compile_flags}" clang_release="clang -g -O2 -DBUILD_DEBUG=0 ${clang_common} ${auto_compile_flags}" clang_link="-lpthread" @@ -22,6 +22,7 @@ clang_out="-o" # --- Per-Build Settings ------------------------------------------------------ link_dll="-fPIC" +link_os_gfx="-lX11 -lXext" # --- Choose Compile/Link Lines ----------------------------------------------- if [ "$clang" = "1" ]; then compile_debug="$clang_debug"; fi @@ -47,7 +48,7 @@ fi # --- Build Everything (@build_targets) --------------------------------------- cd build -if [ "$raddbg" = "1" ]; then didbuild=1 && $compile ../src/raddbg/raddbg_main.c $compile_link $out raddbg || exit 1; fi +if [ "$raddbg" = "1" ]; then didbuild=1 && $compile ../src/raddbg/raddbg_main.c $compile_link $link_os_gfx $out raddbg || exit 1; fi if [ "$rdi_from_pdb" = "1" ]; then didbuild=1 && $compile ../src/rdi_from_pdb/rdi_from_pdb_main.c $compile_link $out rdi_from_pdb || exit 1; fi if [ "$rdi_from_dwarf" = "1" ]; then didbuild=1 && $compile ../src/rdi_from_dwarf/rdi_from_dwarf.c $compile_link $out rdi_from_dwarf || exit 1; fi if [ "$rdi_dump" = "1" ]; then didbuild=1 && $compile ../src/rdi_dump/rdi_dump_main.c $compile_link $out rdi_dump || exit 1; fi diff --git a/src/base/base_core.h b/src/base/base_core.h index 565b05bd..31f4e774 100644 --- a/src/base/base_core.h +++ b/src/base/base_core.h @@ -191,7 +191,16 @@ # endif #elif OS_LINUX # if ARCH_X64 +# define ins_atomic_u64_eval(x) __sync_fetch_and_add((volatile U64 *)(x), 0) # define ins_atomic_u64_inc_eval(x) __sync_fetch_and_add((volatile U64 *)(x), 1) +# define ins_atomic_u64_dec_eval(x) __sync_fetch_and_sub((volatile U64 *)(x), 1) +# define ins_atomic_u64_eval_assign(x,c) __sync_lock_test_and_set((volatile U64 *)(x),(c)) +# define ins_atomic_u64_add_eval(x,c) __sync_fetch_and_add((volatile U64 *)(x), c) +# define ins_atomic_u64_eval_cond_assign(x,k,c) __sync_val_compare_and_swap((volatile U64 *)(x),(c),(k)) +# define ins_atomic_u32_eval(x,c) __sync_fetch_and_add((volatile U32 *)(x), 0) +# define ins_atomic_u32_eval_assign(x,c) __sync_lock_test_and_set((volatile U32 *)(x),(c)) +# define ins_atomic_u32_eval_cond_assign(x,k,c) __sync_val_compare_and_swap((volatile U32 *)(x),(c),(k)) +# define ins_atomic_ptr_eval_assign(x,c) (void*)ins_atomic_u64_eval_assign((volatile U64 *)(x), (U64)(c)) # else # error Atomic intrinsics not defined for this operating system / architecture combination. # endif diff --git a/src/base/base_log.h b/src/base/base_log.h index 52a297d8..3687390e 100644 --- a/src/base/base_log.h +++ b/src/base/base_log.h @@ -1,65 +1,65 @@ -// Copyright (c) 2024 Epic Games Tools -// Licensed under the MIT license (https://opensource.org/license/mit/) - -#ifndef BASE_LOG_H -#define BASE_LOG_H - -//////////////////////////////// -//~ rjf: Log Types - -typedef enum LogMsgKind -{ - LogMsgKind_Info, - LogMsgKind_UserError, - LogMsgKind_COUNT -} -LogMsgKind; - -typedef struct LogScope LogScope; -struct LogScope -{ - LogScope *next; - U64 pos; - String8List strings[LogMsgKind_COUNT]; -}; - -typedef struct LogScopeResult LogScopeResult; -struct LogScopeResult -{ - String8 strings[LogMsgKind_COUNT]; -}; - -typedef struct Log Log; -struct Log -{ - Arena *arena; - LogScope *top_scope; -}; - -//////////////////////////////// -//~ rjf: Log Creation/Selection - -internal Log *log_alloc(void); -internal void log_release(Log *log); -internal void log_select(Log *log); - -//////////////////////////////// -//~ rjf: Log Building - -internal void log_msg(LogMsgKind kind, String8 string); -internal void log_msgf(LogMsgKind kind, char *fmt, ...); -#define log_info(s) log_msg(LogMsgKind_Info, (s)) -#define log_infof(fmt, ...) log_msgf(LogMsgKind_Info, (fmt), __VA_ARGS__) -#define log_user_error(s) log_msg(LogMsgKind_UserError, (s)) -#define log_user_errorf(fmt, ...) log_msgf(LogMsgKind_UserError, (fmt), __VA_ARGS__) - -#define LogInfoNamedBlock(s) DeferLoop(log_infof("%S:\n{\n", (s)), log_infof("}\n")) -#define LogInfoNamedBlockF(fmt, ...) DeferLoop((log_infof(fmt, __VA_ARGS__), log_infof(":\n{\n")), log_infof("}\n")) - -//////////////////////////////// -//~ rjf: Log Scopes - -internal void log_scope_begin(void); -internal LogScopeResult log_scope_end(Arena *arena); - -#endif // BASE_LOG_H +// Copyright (c) 2024 Epic Games Tools +// Licensed under the MIT license (https://opensource.org/license/mit/) + +#ifndef BASE_LOG_H +#define BASE_LOG_H + +//////////////////////////////// +//~ rjf: Log Types + +typedef enum LogMsgKind +{ + LogMsgKind_Info, + LogMsgKind_UserError, + LogMsgKind_COUNT +} +LogMsgKind; + +typedef struct LogScope LogScope; +struct LogScope +{ + LogScope *next; + U64 pos; + String8List strings[LogMsgKind_COUNT]; +}; + +typedef struct LogScopeResult LogScopeResult; +struct LogScopeResult +{ + String8 strings[LogMsgKind_COUNT]; +}; + +typedef struct Log Log; +struct Log +{ + Arena *arena; + LogScope *top_scope; +}; + +//////////////////////////////// +//~ rjf: Log Creation/Selection + +internal Log *log_alloc(void); +internal void log_release(Log *log); +internal void log_select(Log *log); + +//////////////////////////////// +//~ rjf: Log Building + +internal void log_msg(LogMsgKind kind, String8 string); +internal void log_msgf(LogMsgKind kind, char *fmt, ...); +#define log_info(s) log_msg(LogMsgKind_Info, (s)) +#define log_infof(fmt, ...) log_msgf(LogMsgKind_Info, (fmt), __VA_ARGS__) +#define log_user_error(s) log_msg(LogMsgKind_UserError, (s)) +#define log_user_errorf(fmt, ...) log_msgf(LogMsgKind_UserError, (fmt), __VA_ARGS__) + +#define LogInfoNamedBlock(s) DeferLoop(log_infof("%S:\n{\n", (s)), log_infof("}\n")) +#define LogInfoNamedBlockF(fmt, ...) DeferLoop((log_infof(fmt, __VA_ARGS__), log_infof(":\n{\n")), log_infof("}\n")) + +//////////////////////////////// +//~ rjf: Log Scopes + +internal void log_scope_begin(void); +internal LogScopeResult log_scope_end(Arena *arena); + +#endif // BASE_LOG_H diff --git a/src/demon/demon_inc.h b/src/demon/demon_inc.h index 3328f9b6..b7266cca 100644 --- a/src/demon/demon_inc.h +++ b/src/demon/demon_inc.h @@ -1,15 +1,15 @@ -// 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" - -#if OS_WINDOWS -# include "win32/demon_core_win32.h" -#else -# error Demon layer backend not defined for this operating system. -#endif - -#endif // DEMON_INC_H +// 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" + +#if OS_WINDOWS +# include "win32/demon_core_win32.h" +#else +# error Demon layer backend not defined for this operating system. +#endif + +#endif // DEMON_INC_H diff --git a/src/font_provider/font_provider_inc.h b/src/font_provider/font_provider_inc.h index a79c66fc..6fcf5d03 100644 --- a/src/font_provider/font_provider_inc.h +++ b/src/font_provider/font_provider_inc.h @@ -1,33 +1,33 @@ -// Copyright (c) 2024 Epic Games Tools -// Licensed under the MIT license (https://opensource.org/license/mit/) - -#ifndef FONT_PROVIDER_INC_H -#define FONT_PROVIDER_INC_H - -//////////////////////////////// -//~ rjf: Backend Constants - -#define FP_BACKEND_DWRITE 1 - -//////////////////////////////// -//~ rjf: Decide On Backend - -#if !defined(FP_BACKEND) && OS_WINDOWS -# define FP_BACKEND FP_BACKEND_DWRITE -#endif - -//////////////////////////////// -//~ rjf: Main Includes - -#include "font_provider.h" - -//////////////////////////////// -//~ rjf: Backend Includes - -#if FP_BACKEND == FP_BACKEND_DWRITE -# include "dwrite/font_provider_dwrite.h" -#else -# error Font provider backend not specified. -#endif - -#endif // FONT_PROVIDER_INC_H +// Copyright (c) 2024 Epic Games Tools +// Licensed under the MIT license (https://opensource.org/license/mit/) + +#ifndef FONT_PROVIDER_INC_H +#define FONT_PROVIDER_INC_H + +//////////////////////////////// +//~ rjf: Backend Constants + +#define FP_BACKEND_DWRITE 1 + +//////////////////////////////// +//~ rjf: Decide On Backend + +#if !defined(FP_BACKEND) && OS_WINDOWS +# define FP_BACKEND FP_BACKEND_DWRITE +#endif + +//////////////////////////////// +//~ rjf: Main Includes + +#include "font_provider.h" + +//////////////////////////////// +//~ rjf: Backend Includes + +#if FP_BACKEND == FP_BACKEND_DWRITE +# include "dwrite/font_provider_dwrite.h" +#else +# error Font provider backend not specified. +#endif + +#endif // FONT_PROVIDER_INC_H diff --git a/src/os/gfx/linux/os_gfx_linux.c b/src/os/gfx/linux/os_gfx_linux.c new file mode 100644 index 00000000..1982f794 --- /dev/null +++ b/src/os/gfx/linux/os_gfx_linux.c @@ -0,0 +1,251 @@ +// Copyright (c) 2024 Epic Games Tools +// Licensed under the MIT license (https://opensource.org/license/mit/) + +//////////////////////////////// +//~ rjf: @os_hooks Main Initialization API (Implemented Per-OS) + +internal void +os_gfx_init(void) +{ + +} + +//////////////////////////////// +//~ rjf: @os_hooks Graphics System Info (Implemented Per-OS) + +internal OS_GfxInfo * +os_get_gfx_info(void) +{ + return 0; +} + +//////////////////////////////// +//~ rjf: @os_hooks Clipboards (Implemented Per-OS) + +internal void +os_set_clipboard_text(String8 string) +{ + +} + +internal String8 +os_get_clipboard_text(Arena *arena) +{ + +} + +//////////////////////////////// +//~ rjf: @os_hooks Windows (Implemented Per-OS) + +internal OS_Handle +os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title) +{ + +} + +internal void +os_window_close(OS_Handle handle) +{ + +} + +internal void +os_window_first_paint(OS_Handle window_handle) +{ + +} + +internal void +os_window_equip_repaint(OS_Handle handle, OS_WindowRepaintFunctionType *repaint, void *user_data) +{ + +} + +internal void +os_window_focus(OS_Handle handle) +{ + +} + +internal B32 +os_window_is_focused(OS_Handle handle) +{ + +} + +internal B32 +os_window_is_fullscreen(OS_Handle handle) +{ + +} + +internal void +os_window_set_fullscreen(OS_Handle handle, B32 fullscreen) +{ + +} + +internal B32 +os_window_is_maximized(OS_Handle handle) +{ + +} + +internal void +os_window_set_maximized(OS_Handle handle, B32 maximized) +{ + +} + +internal void +os_window_minimize(OS_Handle handle) +{ + +} + +internal void +os_window_bring_to_front(OS_Handle handle) +{ + +} + +internal void +os_window_set_monitor(OS_Handle window_handle, OS_Handle monitor) +{ + +} + +internal void +os_window_clear_custom_border_data(OS_Handle handle) +{ + +} + +internal void +os_window_push_custom_title_bar(OS_Handle handle, F32 thickness) +{ + +} + +internal void +os_window_push_custom_edges(OS_Handle handle, F32 thickness) +{ + +} + +internal void +os_window_push_custom_title_bar_client_area(OS_Handle handle, Rng2F32 rect) +{ + +} + +internal Rng2F32 +os_rect_from_window(OS_Handle handle) +{ + +} + +internal Rng2F32 +os_client_rect_from_window(OS_Handle handle) +{ + +} + +internal F32 +os_dpi_from_window(OS_Handle handle) +{ + +} + +//////////////////////////////// +//~ rjf: @os_hooks Monitors (Implemented Per-OS) + +internal OS_HandleArray +os_push_monitors_array(Arena *arena) +{ + +} + +internal OS_Handle +os_primary_monitor(void) +{ + +} + +internal OS_Handle +os_monitor_from_window(OS_Handle window) +{ + +} + +internal String8 +os_name_from_monitor(Arena *arena, OS_Handle monitor) +{ + +} + +internal Vec2F32 +os_dim_from_monitor(OS_Handle monitor) +{ + +} + +//////////////////////////////// +//~ rjf: @os_hooks Events (Implemented Per-OS) + +internal void +os_send_wakeup_event(void) +{ + +} + +internal OS_EventList +os_get_events(Arena *arena, B32 wait) +{ + +} + +internal OS_EventFlags +os_get_event_flags(void) +{ + +} + +internal B32 +os_key_is_down(OS_Key key) +{ + +} + +internal Vec2F32 +os_mouse_from_window(OS_Handle handle) +{ + +} + +//////////////////////////////// +//~ rjf: @os_hooks Cursors (Implemented Per-OS) + +internal void +os_set_cursor(OS_Cursor cursor) +{ + +} + +//////////////////////////////// +//~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS) + +internal void +os_graphical_message(B32 error, String8 title, String8 message) +{ + +} + +//////////////////////////////// +//~ rjf: @os_hooks Shell Operations + +internal void +os_show_in_filesystem_ui(String8 path) +{ + +} diff --git a/src/os/gfx/linux/os_gfx_linux.h b/src/os/gfx/linux/os_gfx_linux.h new file mode 100644 index 00000000..5c2193b3 --- /dev/null +++ b/src/os/gfx/linux/os_gfx_linux.h @@ -0,0 +1,14 @@ +// Copyright (c) 2024 Epic Games Tools +// Licensed under the MIT license (https://opensource.org/license/mit/) + +#ifndef OS_GFX_LINUX_H +#define OS_GFX_LINUX_H + +//////////////////////////////// +//~ rjf: Includes + +#include +#include +#include + +#endif // OS_GFX_LINUX_H diff --git a/src/os/gfx/os_gfx.h b/src/os/gfx/os_gfx.h index 92cc4816..436657ec 100644 --- a/src/os/gfx/os_gfx.h +++ b/src/os/gfx/os_gfx.h @@ -1,8 +1,8 @@ // Copyright (c) 2024 Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -#ifndef OS_GRAPHICAL_H -#define OS_GRAPHICAL_H +#ifndef OS_GFX_H +#define OS_GFX_H //////////////////////////////// //~ rjf: Graphics System Info @@ -188,4 +188,4 @@ internal void os_graphical_message(B32 error, String8 title, String8 m internal void os_show_in_filesystem_ui(String8 path); -#endif // OS_GRAPHICAL_H +#endif // OS_GFX_H diff --git a/src/os/gfx/stub/os_gfx_stub.c b/src/os/gfx/stub/os_gfx_stub.c index 8adb429e..134e6b7d 100644 --- a/src/os/gfx/stub/os_gfx_stub.c +++ b/src/os/gfx/stub/os_gfx_stub.c @@ -6,6 +6,16 @@ os_gfx_init(void) { } +//////////////////////////////// +//~ rjf: @os_hooks Graphics System Info (Implemented Per-OS) + +internal OS_GfxInfo * +os_get_gfx_info(void) +{ + local_persist OS_GfxInfo g = {0}; + return &g; +} + //////////////////////////////// //~ rjf: @os_hooks Clipboards (Implemented Per-OS)