summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/lib/osdlib_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/lib/osdlib_unix.cpp')
-rw-r--r--src/osd/modules/lib/osdlib_unix.cpp77
1 files changed, 72 insertions, 5 deletions
diff --git a/src/osd/modules/lib/osdlib_unix.cpp b/src/osd/modules/lib/osdlib_unix.cpp
index 20f6a9ab40c..1cfa9b1f183 100644
--- a/src/osd/modules/lib/osdlib_unix.cpp
+++ b/src/osd/modules/lib/osdlib_unix.cpp
@@ -17,8 +17,10 @@
#include <csignal>
#include <cstdio>
#include <cstdlib>
+#include <cstring>
#include <iomanip>
#include <memory>
+#include <string_view>
#include <dlfcn.h>
#include <sys/mman.h>
@@ -53,21 +55,86 @@ void osd_process_kill()
kill(getpid(), SIGKILL);
}
+
//============================================================
// osd_break_into_debugger
//============================================================
void osd_break_into_debugger(const char *message)
{
-#ifdef MAME_DEBUG
- printf("MAME exception: %s\n", message);
- printf("Attempting to fall into debugger\n");
- kill(getpid(), SIGTRAP);
+#if defined(__linux__)
+ bool do_break = false;
+ FILE *const f = std::fopen("/proc/self/status", "r");
+ if (f)
+ {
+ using namespace std::literals;
+
+ std::string_view const tag = "TracerPid:\t"sv;
+ char buf[128];
+ bool ignore = false;
+ while (std::fgets(buf, std::size(buf), f))
+ {
+ // ignore excessively long lines
+ auto const len = strnlen(buf, std::size(buf));
+ bool const noeol = !len || ('\n' != buf[len - 1]);
+ if (ignore || noeol)
+ {
+ ignore = noeol;
+ continue;
+ }
+
+ if (!std::strncmp(buf, tag.data(), tag.length()))
+ {
+ long tpid;
+ if ((std::sscanf(buf + tag.length(), "%ld", &tpid) == 1) && (0 != tpid))
+ do_break = true;
+ break;
+ }
+ }
+ std::fclose(f);
+ }
+#elif defined(MAME_DEBUG)
+ bool const do_break = true;
#else
- printf("Ignoring MAME exception: %s\n", message);
+ bool const do_break = false;
+#endif
+ if (do_break)
+ {
+ printf("MAME exception: %s\n", message);
+ printf("Attempting to fall into debugger\n");
+ kill(getpid(), SIGTRAP);
+ }
+ else
+ {
+ printf("Ignoring MAME exception: %s\n", message);
+ }
+}
+
+
+//============================================================
+// osd_get_cache_line_size
+//============================================================
+
+std::pair<std::error_condition, unsigned> osd_get_cache_line_size() noexcept
+{
+#if defined(__linux__)
+ FILE *const f = std::fopen("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", "r");
+ if (!f)
+ return std::make_pair(std::error_condition(errno, std::generic_category()), 0U);
+
+ unsigned result = 0;
+ auto const cnt = std::fscanf(f, "%u", &result);
+ std::fclose(f);
+ if (1 == cnt)
+ return std::make_pair(std::error_condition(), result);
+ else
+ return std::make_pair(std::errc::io_error, 0U);
+#else // defined(__linux__)
+ return std::make_pair(std::errc::not_supported, 0U);
#endif
}
+
#ifdef SDLMAME_ANDROID
std::string osd_get_clipboard_text() noexcept
{