adding stream value tracing macros draft
authorISHIKAWA, Chiaki <ishikawa@yk.rim.or.jp>
Mon, 23 May 2022 03:03:51 +0900
changeset 116823 237536d6a09f43d39831c4ef54cc9004185f509e
parent 116822 8fb8d1160e506d631182439d29c8f0a87db4db29
child 116824 988c393b0dc1405ea1fd3416b2423dd8821cdfd3
push id15955
push userishikawa@yk.rim.or.jp
push dateSun, 22 May 2022 18:04:18 +0000
treeherdertry-comm-central@beaacca97fbd [default view] [failures only]
adding stream value tracing macros
mailnews/base/src/nsMsgUtils.h
--- a/mailnews/base/src/nsMsgUtils.h
+++ b/mailnews/base/src/nsMsgUtils.h
@@ -438,9 +438,118 @@ void MsgLogToConsole4(const nsAString& a
   } while (0)
 
 /**
  * Perform C-style string escaping. E.g. "foo\r\n" => "foo\\r\\n"
  * This is primarily intended for debuggin purposes.
  */
 nsCString CEscapeString(nsACString const& s);
 
+/*
+ *
+ * PSTREAM(p)         value:  p=0x%08x in func at line of filename
+ * PSTREAM2(p,msg)    value:  p=0x%08x 'msg' at in func at line of filename
+ * ASSIGNSTREAM(p, q) assigning: p=0x%08x <- q=%08x in function at line of
+ * filename
+ * ASSIGNSREAM2(p, q, msg) assign: p=0x%08x <- q=%08x 'msg' in function
+ * at line of filename
+ * CLOSESTREAM(p)     closing:  p (0x%08x)->Close() in
+ * function at line of filename
+ * CLOSESTREAM2(p, msg)   closing:  p * (0x%08x)->Close()
+ * 'msg' in function at line of filename
+ */
+
+#ifdef DEBUG
+#  define PSTREAM(p)                                                           \
+    do {                                                                       \
+      fflush(stdout);                                                          \
+      fprintf(stderr, "{streamdebug} value: %s = %p in %s at line %d of %s\n", \
+              #p, (void *)p, __func__, __LINE__, __FILE__);                    \
+    } while (0)
+
+#  define PSTREAM2(p, msg)                                                   \
+    do {                                                                     \
+      fflush(stdout);                                                        \
+      fprintf(stderr,                                                        \
+              "{streamdebug} value: %s = %p '%s' in %s  at line %d of %s\n", \
+              #p, (void *)p, msg, __func__, __LINE__, __FILE__);             \
+    } while (0)
+
+#  define ASSIGNSTREAM(p, q)                                                 \
+    do {                                                                     \
+      fflush(stdout);                                                        \
+      fprintf(stderr,                                                        \
+              "{streamdebug} assigning: %s (= %p ) <- %s (= %p ) in %s  at " \
+              "line %d "                                                     \
+              "of %s\n",                                                     \
+              #p, (void *)p, #q, (void *)q, __func__, __LINE__, __FILE__);   \
+    } while (0)
+
+#  define ASSIGNSTREAM2(p, q, msg)                                            \
+    do {                                                                      \
+      fflush(stdout);                                                         \
+      fprintf(                                                                \
+          stderr,                                                             \
+          "{streamdebug} assigning: %s (= %p ) <- %s (= %p ) '%s' in %s  at " \
+          "line %d of %s\n",                                                  \
+          #p, (void *)p, #q, (void *)q, msg, __func__, __LINE__, __FILE__);   \
+    } while (0)
+
+#  define CLOSESTREAM(p)                                                      \
+    do {                                                                      \
+      fflush(stdout);                                                         \
+      fprintf(stderr,                                                         \
+              "{streamdebug} closing: %s (= %p )->Close() in %s  at line %d " \
+              "of %s\n",                                                      \
+              #p, (void *)p, __func__, __LINE__, __FILE__);                   \
+    } while (0)
+
+#  define CLOSESTREAM2(p, msg)                                                 \
+    do {                                                                       \
+      fflush(stdout);                                                          \
+      fprintf(                                                                 \
+          stderr,                                                              \
+          "{streamdebug} closing: %s (= %p )->Close() '%s' in %s  at line %d " \
+          "of %s\n",                                                           \
+          #p, (void *)p, msg, __func__, __LINE__, __FILE__);                   \
+    } while (0)
+#else
+#  define PSTREAM(p)
+#  define PSTREAM2(p, msg)
+#  define ASSIGNSTREAM(p, q)
+#  define ASSIGNSTREAM2(p, q, msg)
+#  define CLOSESTREAM(p)
+#  define CLOSESTREAM2(p, msg)
 #endif
+
+#ifdef DEBUG
+#  ifdef DEBUG_TEST_PSTREAM
+#    include <stdio.h>
+#    include <unistd.h>
+struct A {
+  int a;
+  int b;
+  char c;
+} sa;
+
+struct B {
+  int a;
+  int b;
+  char c;
+} sb;
+
+int main(int argc, char *argv[]) {
+  struct A *p, *q;
+  p = &sa;
+  q = NULL;
+  PSTREAM(p);
+  PSTREAM2(p, "with message");
+  ASSIGNSTREAM(p, q);
+  ASSIGNSTREAM2(p, NULL, "with message");
+  CLOSESTREAM(p);
+  CLOSESTREAM2(p, "with message");
+  exit(0);
+}
+#  endif
+#endif
+
+#endif
+