stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farid Zaripov" <Farid_Zari...@epam.com>
Subject Convert MSVC CRT debug reports to rwtest driver debug reports
Date Mon, 25 Jun 2007 16:45:37 GMT
  In some tests in debug mode GUI popups appear.
  We can disable this popups by using _CrtSetReportMode(,
_CRTDBG_MODE_DEBUG), but I think
it would be useful to convert them into the rwtest debug reports
(rw_warn(), rw_error(), rw_assert()).
This conversion can be made by installing custom hook function.
 
  And also MSVC8 CRT performs parameter checking with invoking Dr.Watson
tool (the result is GUI
popup) in case the invalid parameter was passed to the CRT function. I
suggest to convert this popups
to the rw_note() reports (or maybe rw_error()).
 
  The proposed patch below:
 
Index: driver.cpp
===================================================================
--- driver.cpp (revision 550382)
+++ driver.cpp (working copy)
@@ -69,6 +69,10 @@
 #  define _RWSTD_NO_ISATTY
 #endif   // _WIN{32,64}
 
+#ifdef _MSC_VER
+#include <crtdbg.h>   // for _CrtSetReportHook()
+#endif   // _MSC_VER
+
 // expand _TEST_EXPORT macros
 #define _RWSTD_TEST_SRC
 #include <driver.h>
@@ -1118,6 +1122,47 @@
 
 
/***********************************************************************
*/
 
+#ifdef _MSC_VER
+
+#if _MSC_VER >= 1400
+static void
+_rw_invalid_parameter(const wchar_t * expression,
+                      const wchar_t * function, 
+                      const wchar_t * file, 
+                      unsigned int line,
+                      uintptr_t pReserved)
+{
+#ifdef _DEBUG
+    rw_note (0, __FILE__, __LINE__,
+             "Invalid parameter in function %ls.\nFile: %ls Line: %u\n"
+             "Expression: %ls", function, file, line, expression);
+#endif
+}
+#endif  // _MSC_VER >= 1400
+
+
+static int
+_rw_report_hook (int type, char *msg, int *ret)
+{
+    typedef int (* rw_report) (int, const char *, int, const char *,
...);
+    rw_report rw_reports [] = { rw_warn, rw_error, rw_assert };
+
+    RW_ASSERT (0 <= type && sizeof (rw_reports) / sizeof (*rw_reports)
> type);
+
+    // remove trailing new line
+    const size_t len = strlen (msg);
+    if (len && '\n' == msg [len - 1])
+        msg [len - 1] = '\0';
+
+    *ret = rw_reports [type] (0, __FILE__, __LINE__, "%s", msg);
+
+    return 1;  // 1 == TRUE
+}
+
+#endif   // _MSC_VER
+
+/**********************************************************************
**/
+
 _TEST_EXPORT int
 rw_test (int argc, char **argv,
          const char *fname,
@@ -1127,6 +1172,13 @@
          const char *optstr,
          ...)
 {
+#ifdef _MSC_VER
+#  if _MSC_VER >= 1400
+    _set_invalid_parameter_handler (_rw_invalid_parameter);
+#  endif   // _MSC_VER >= 1400
+    _CrtSetReportHook (_rw_report_hook);
+#endif   // _MSC_VER
+
     CHECK_INIT (false, "rw_test()");
 
     va_list va;

 
Farid.
 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message