Last active
January 29, 2024 18:14
-
-
Save tomrittervg/4c50058b464cee441d9fd6614743ecd7 to your computer and use it in GitHub Desktop.
A patch to help you break in Firefox when and where you want it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HG changeset patch | |
# User Tom Ritter <[email protected]> | |
# Date 1681485863 14400 | |
# Fri Apr 14 11:24:23 2023 -0400 | |
# Node ID 45c767e3ec49ef47dec62b0ad94481885c46b564 | |
# Parent fce9e73861891da48d1a0b85240491fa3e042f8b | |
MaybeDebugTrap | |
diff --git a/xpcom/base/nsDebug.h b/xpcom/base/nsDebug.h | |
--- a/xpcom/base/nsDebug.h | |
+++ b/xpcom/base/nsDebug.h | |
@@ -322,9 +322,23 @@ inline void MOZ_PretendNoReturn() MOZ_PR | |
#endif | |
#ifdef MOZILLA_INTERNAL_API | |
void NS_ABORT_OOM(size_t aSize); | |
#else | |
inline void NS_ABORT_OOM(size_t) { MOZ_CRASH(); } | |
#endif | |
+ | |
+ | |
+#ifdef __cplusplus | |
+extern "C" { | |
+#endif | |
+ | |
+#if defined(DEBUG) && defined(XP_LINUX) | |
+void MaybeDebugTrap(); | |
+#endif | |
+ | |
+#ifdef __cplusplus | |
+} | |
+#endif | |
+ | |
#endif /* nsDebug_h___ */ | |
diff --git a/xpcom/base/nsDebugImpl.cpp b/xpcom/base/nsDebugImpl.cpp | |
--- a/xpcom/base/nsDebugImpl.cpp | |
+++ b/xpcom/base/nsDebugImpl.cpp | |
@@ -668,8 +668,56 @@ nsresult NS_ErrorAccordingToNSPR() { | |
return NS_ERROR_FAILURE; | |
} | |
} | |
void NS_ABORT_OOM(size_t aSize) { | |
CrashReporter::AnnotateOOMAllocationSize(aSize); | |
MOZ_CRASH("OOM"); | |
} | |
+ | |
+#if defined(DEBUG) && defined(XP_LINUX) | |
+# include <stdio.h> | |
+# include <signal.h> | |
+# include <sys/mman.h> | |
+ | |
+static FILE* sDebughelper = nullptr; | |
+static char* sMyPid = nullptr; | |
+static char* sShouldBreak = nullptr; | |
+ | |
+# define TRAP() raise(SIGTRAP) | |
+// #define TRAP() __builtin_debugtrap() | |
+ | |
+void MaybeDebugTrap() { | |
+ if (sShouldBreak == nullptr) { | |
+ sDebughelper = fopen("/tmp/mozilla_debughelper", "r"); | |
+ if (!sDebughelper) { | |
+ fprintf(stderr, | |
+ "Could not open /tmp/mozilla_debughelper in pid %i, ensure it " | |
+ "exists with a single byte present.\n", | |
+ getpid()); | |
+ sShouldBreak = new char[1]; | |
+ sShouldBreak[0] = '\0'; | |
+ } else { | |
+ sShouldBreak = (char*)mmap(nullptr, 1, PROT_READ, MAP_SHARED, | |
+ fileno(sDebughelper), 0); | |
+ if (!sShouldBreak) { | |
+ fprintf(stderr, "Could not mmap /tmp/mozilla_debughelper in pid %i.\n", | |
+ getpid()); | |
+ TRAP(); | |
+ } else { | |
+ fprintf( | |
+ stderr, | |
+ "Mapped /tmp/mozilla_debughelper in pid %i, doing a test read.\n", | |
+ getpid()); | |
+ } | |
+ } | |
+ | |
+ int num_digits = (int)((ceil(log10(getpid())) + 1) * sizeof(char)); | |
+ sMyPid = new char[num_digits]; | |
+ snprintf(sMyPid, num_digits, "%d", getpid()); | |
+ } | |
+ | |
+ if (strncmp(sShouldBreak, sMyPid, strlen(sMyPid)) == 0) { | |
+ raise(SIGTRAP); | |
+ } | |
+} | |
+#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment