added: `MEMDEBUG` configuration option
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 6 Nov 2023 04:18:52 +0000 (22:18 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 6 Nov 2023 04:18:52 +0000 (22:18 -0600)
core/alloc/memdebug.onyx
core/runtime/platform/onyx/platform.onyx

index c700d5f36f163527b52c042dcce768a975891024..fa64e9679fb690532f3e2b891f5254382b0c183e 100644 (file)
@@ -23,6 +23,7 @@ MemDebugState :: struct {
 MemDebugMsg :: union {
     Start: struct {
         version: u32;
+        heap_base_address: u32;
     };
 
     Action: struct {
@@ -67,7 +68,7 @@ wait_for_connection :: (m: &MemDebugState) -> Result(void, io.Error) {
     m.socket = .{ Some = result.socket };
     m.writer = .{ Some = io.writer_make(m.socket->unwrap_ptr(), 0) };
 
-    memdebug_send_message(m, .{ Start = .{ version = VERSION } });
+    memdebug_send_message(m, .{ Start = .{ version = VERSION, heap_base_address = cast(u32) __heap_start } });
 }
 
 enable_in_scope :: macro (a: Allocator, port := DEFAULT_PORT) {
index 4c50afa8bf0f943415918caaf1c32aa68bc435d3..09d187eb5c020521b937d6fdb6238f386929c28d 100644 (file)
@@ -127,6 +127,10 @@ __start :: () {
     __runtime_initialize();
     context.thread_id = 0;
 
+    #if #defined(runtime.vars.MEMDEBUG) {
+        use core.alloc.memdebug
+        memdebug.enable_in_scope(context.allocator);
+    }
 
     #if (typeof MAIN_FUNCTION) == #type () -> void { // An error on this line means no 'main.main' was found in your program.
         MAIN_FUNCTION();