foxygit / fake-08-xbox360 Log in
commit 2b7636dd450da7b2c0b17ea8055ab61c4eab5214
Author:     mrfox <jens.se@icloud.com>
AuthorDate: Wed Nov 25 16:49:17 2026 +0100
Commit:     mrfox <jens.se@icloud.com>
CommitDate: Wed Nov 25 16:49:17 2026 +0100

    xex host: log the cart listing and uncaught exceptions

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
 platform/xex/source/XexHost.cpp | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/platform/xex/source/XexHost.cpp b/platform/xex/source/XexHost.cpp
index fdf0fc7..704143e 100644
--- a/platform/xex/source/XexHost.cpp
+++ b/platform/xex/source/XexHost.cpp
@@ -16,9 +16,14 @@
 #include <string.h>
 #include <dirent.h>
 #include <sys/stat.h>
+#include <errno.h>
+#include <stdlib.h>

 #include <string>
 #include <vector>
+#include <exception>
+#include <typeinfo>
+#include <cxxabi.h>

 #include "../../../source/host.h"
 #include "../../../source/hostVmShared.h"
@@ -247,7 +252,28 @@ static void perfFrameDone(uint64_t emuTb, uint64_t waitTb, uint64_t blitTb, uint
 // Host
 // ---------------------------------------------------------------------------

+// An uncaught C++ exception ends up here: log it before the title dies.
+static void logTerminate() {
+    const char *what = "unknown";
+    std::string type = "?";
+    if (std::exception_ptr e = std::current_exception()) {
+        if (std::type_info *t = abi::__cxa_current_exception_type()) type = t->name();
+        try {
+            std::rethrow_exception(e);
+        } catch (const std::exception &ex) {
+            Logger_Write("terminate: uncaught %s: %s\n", type.c_str(), ex.what());
+            what = nullptr;
+        } catch (...) {
+        }
+    }
+    if (what) Logger_Write("terminate: uncaught exception of type %s\n", type.c_str());
+    xex_notify("FAKE-08 crashed (see fake08/pico.log)");
+    xex_sleep_ms(3000);
+    abort();
+}
+
 Host::Host(int windowWidth, int windowHeight) {
+    std::set_terminate(logTerminate);
     std::string base = "game:/fake08";
     mkdir(base.c_str(), 0777);
     mkdir((base + "/cdata").c_str(), 0777);
@@ -511,15 +537,23 @@ bool Host::shouldRunMainLoop() {
 vector<string> Host::listcarts() {
     vector<string> carts;

+    Logger_Write("listing carts in %s\n", _cartDirectory.c_str());
     DIR *dir = opendir(_cartDirectory.c_str());
     if (dir != NULL) {
         struct dirent *ent;
+        int entries = 0;
         while ((ent = readdir(dir)) != NULL) {
-            if (isCartFile(ent->d_name)) {
+            entries++;
+            bool cart = isCartFile(ent->d_name);
+            Logger_Write("  %s%s\n", ent->d_name, cart ? "" : " (skipped)");
+            if (cart) {
                 carts.push_back(_cartDirectory + "/" + ent->d_name);
             }
         }
         closedir(dir);
+        Logger_Write("%d entries, %d carts\n", entries, (int)carts.size());
+    } else {
+        Logger_Write("opendir failed (errno %d)\n", errno);
     }

     return carts;