Title: [278474] trunk/Source/WTF
Revision
278474
Author
[email protected]
Date
2021-06-04 10:58:37 -0700 (Fri, 04 Jun 2021)

Log Message

Add a way to prefix output of `WTFReportBacktrace` to make log filtering easier
https://bugs.webkit.org/show_bug.cgi?id=226390

Reviewed by Megan Gardner.

Often times while debugging I add `WTFLogAlways("<DR> ...")` to various places as indicators
that "logic has reached here". This is especially useful when debugging iOS as unlike macOS
there's no console output from `run-safari`, meaning that I have to use system logging,
which is often a deluge of unrelated information. Having "<DR>" as a prefix makes filtering
through the system logging trivial as I can ignore logs that don't have it. Unfortunately,
`WTFReportBacktrace` does not have a way to add this prefix, so it becomes much harder to
find in the logs. This patch enables adding a prefix to each line of `WTFReportBacktrace`
via a new function `WTFReportBactraceWithPrefix`.

* wtf/Assertions.h:
* wtf/Assertions.cpp:
(WTFReportBacktraceWithPrefix): Added.
(WTFPrintBacktraceWithPrefix): Added.

* wtf/StackTrace.h:
(WTF::StackTrace::StackTrace):
* wtf/StackTrace.cpp:
(WTF::StackTrace::dump const):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (278473 => 278474)


--- trunk/Source/WTF/ChangeLog	2021-06-04 17:46:09 UTC (rev 278473)
+++ trunk/Source/WTF/ChangeLog	2021-06-04 17:58:37 UTC (rev 278474)
@@ -1,3 +1,29 @@
+2021-06-04  Devin Rousso  <[email protected]>
+
+        Add a way to prefix output of `WTFReportBacktrace` to make log filtering easier
+        https://bugs.webkit.org/show_bug.cgi?id=226390
+
+        Reviewed by Megan Gardner.
+
+        Often times while debugging I add `WTFLogAlways("<DR> ...")` to various places as indicators
+        that "logic has reached here". This is especially useful when debugging iOS as unlike macOS
+        there's no console output from `run-safari`, meaning that I have to use system logging,
+        which is often a deluge of unrelated information. Having "<DR>" as a prefix makes filtering
+        through the system logging trivial as I can ignore logs that don't have it. Unfortunately,
+        `WTFReportBacktrace` does not have a way to add this prefix, so it becomes much harder to
+        find in the logs. This patch enables adding a prefix to each line of `WTFReportBacktrace`
+        via a new function `WTFReportBactraceWithPrefix`.
+
+        * wtf/Assertions.h:
+        * wtf/Assertions.cpp:
+        (WTFReportBacktraceWithPrefix): Added.
+        (WTFPrintBacktraceWithPrefix): Added.
+
+        * wtf/StackTrace.h:
+        (WTF::StackTrace::StackTrace):
+        * wtf/StackTrace.cpp:
+        (WTF::StackTrace::dump const):
+
 2021-06-04  Michael Catanzaro  <[email protected]>
 
         Fix more GCC warnings

Modified: trunk/Source/WTF/wtf/Assertions.cpp (278473 => 278474)


--- trunk/Source/WTF/wtf/Assertions.cpp	2021-06-04 17:46:09 UTC (rev 278473)
+++ trunk/Source/WTF/wtf/Assertions.cpp	2021-06-04 17:58:37 UTC (rev 278474)
@@ -277,6 +277,17 @@
     }
 };
 
+void WTFReportBacktraceWithPrefix(const char* prefix)
+{
+    static constexpr int framesToShow = 31;
+    static constexpr int framesToSkip = 2;
+    void* samples[framesToShow + framesToSkip];
+    int frames = framesToShow + framesToSkip;
+
+    WTFGetBacktrace(samples, &frames);
+    WTFPrintBacktraceWithPrefix(samples + framesToSkip, frames - framesToSkip, prefix);
+}
+
 void WTFReportBacktrace()
 {
     static constexpr int framesToShow = 31;
@@ -288,13 +299,18 @@
     WTFPrintBacktrace(samples + framesToSkip, frames - framesToSkip);
 }
 
-void WTFPrintBacktrace(void** stack, int size)
+void WTFPrintBacktraceWithPrefix(void** stack, int size, const char* prefix)
 {
     CrashLogPrintStream out;
-    StackTrace stackTrace(stack, size);
+    StackTrace stackTrace(stack, size, prefix);
     out.print(stackTrace);
 }
 
+void WTFPrintBacktrace(void** stack, int size)
+{
+    WTFPrintBacktraceWithPrefix(stack, size, "");
+}
+
 #if !defined(NDEBUG) || !(OS(DARWIN) || PLATFORM(PLAYSTATION))
 void WTFCrash()
 {

Modified: trunk/Source/WTF/wtf/Assertions.h (278473 => 278474)


--- trunk/Source/WTF/wtf/Assertions.h	2021-06-04 17:46:09 UTC (rev 278473)
+++ trunk/Source/WTF/wtf/Assertions.h	2021-06-04 17:58:37 UTC (rev 278474)
@@ -218,7 +218,9 @@
 WTF_EXPORT_PRIVATE bool WTFWillLogWithLevel(WTFLogChannel*, WTFLogLevel);
 
 WTF_EXPORT_PRIVATE void WTFGetBacktrace(void** stack, int* size);
+WTF_EXPORT_PRIVATE void WTFReportBacktraceWithPrefix(const char*);
 WTF_EXPORT_PRIVATE void WTFReportBacktrace(void);
+WTF_EXPORT_PRIVATE void WTFPrintBacktraceWithPrefix(void** stack, int size, const char* prefix);
 WTF_EXPORT_PRIVATE void WTFPrintBacktrace(void** stack, int size);
 #if !RELEASE_LOG_DISABLED
 WTF_EXPORT_PRIVATE void WTFReleaseLogStackTrace(WTFLogChannel*);

Modified: trunk/Source/WTF/wtf/StackTrace.cpp (278473 => 278474)


--- trunk/Source/WTF/wtf/StackTrace.cpp	2021-06-04 17:46:09 UTC (rev 278473)
+++ trunk/Source/WTF/wtf/StackTrace.cpp	2021-06-04 17:58:37 UTC (rev 278474)
@@ -141,9 +141,9 @@
         }
         const int frameNumber = i + 1;
         if (mangledName || cxaDemangled)
-            out.printf("%s%-3d %p %s\n", indentString, frameNumber, stack[i], cxaDemangled ? cxaDemangled : mangledName);
+            out.printf("%s%s%-3d %p %s\n", m_prefix ? m_prefix : "", indentString, frameNumber, stack[i], cxaDemangled ? cxaDemangled : mangledName);
         else
-            out.printf("%s%-3d %p\n", indentString, frameNumber, stack[i]);
+            out.printf("%s%s%-3d %p\n", m_prefix ? m_prefix : "", indentString, frameNumber, stack[i]);
     }
 
 #if HAVE(BACKTRACE_SYMBOLS)

Modified: trunk/Source/WTF/wtf/StackTrace.h (278473 => 278474)


--- trunk/Source/WTF/wtf/StackTrace.h	2021-06-04 17:46:09 UTC (rev 278473)
+++ trunk/Source/WTF/wtf/StackTrace.h	2021-06-04 17:58:37 UTC (rev 278474)
@@ -39,10 +39,11 @@
     WTF_EXPORT_PRIVATE static std::unique_ptr<StackTrace> captureStackTrace(int maxFrames, int framesToSkip = 0);
 
     // Borrowed stack trace.
-    StackTrace(void** stack, int size)
+    StackTrace(void** stack, int size, const char* prefix = "")
         : m_size(size)
         , m_capacity(0)
         , m_borrowedStack(stack)
+        , m_prefix(prefix)
     { }
 
     int size() const { return m_size; }
@@ -99,6 +100,8 @@
         void** m_borrowedStack;
         void* m_stack[1];
     };
+
+    const char* m_prefix;
 };
 
 } // namespace WTF
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to