[MOAB-dev] commit/MOAB: danwu: Normalize source file paths in stack traces such that they are all relative to MOAB source directory. This is done by trimming __FILE__ to a short form __FILENAME__ and stringifying LOCDIR to __SDIR__.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Feb 5 10:56:11 CST 2014
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/8c4eeeac7e91/
Changeset: 8c4eeeac7e91
Branch: error_handling_enhancement
User: danwu
Date: 2014-02-05 17:55:56
Summary: Normalize source file paths in stack traces such that they are all relative to MOAB source directory. This is done by trimming __FILE__ to a short form __FILENAME__ and stringifying LOCDIR to __SDIR__.
Affected #: 2 files
diff --git a/src/ErrorHandler.cpp b/src/ErrorHandler.cpp
index 1f67c52..45a8cea 100644
--- a/src/ErrorHandler.cpp
+++ b/src/ErrorHandler.cpp
@@ -26,7 +26,7 @@ bool MBErrorHandler_Initialized()
return (NULL != errorOutput);
}
-void MBTraceBackErrorHandler(int line, const char* func, const char* file, const char* err_msg, ErrorType err_type)
+void MBTraceBackErrorHandler(int line, const char* func, const char* file, const char* dir, const char* err_msg, ErrorType err_type)
{
// Print the error message
if (MB_ERROR_TYPE_NEW == err_type) {
@@ -40,12 +40,12 @@ void MBTraceBackErrorHandler(int line, const char* func, const char* file, const
// Print a line of stack trace
if (NULL != errorOutput)
- errorOutput->printf("%s at line %d, in file %s\n", func, line, file);
+ errorOutput->printf("%s() line %d in file %s%s\n", func, line, dir, file);
}
-ErrorInfo MBError(int line, const char* func, const char* file, const ErrorInfo& err_info, ErrorType err_type)
+ErrorInfo MBError(int line, const char* func, const char* file, const char* dir, const ErrorInfo& err_info, ErrorType err_type)
{
- MBTraceBackErrorHandler(line, func, file, err_info.get_error_msg(), err_type);
+ MBTraceBackErrorHandler(line, func, file, dir, err_info.get_error_msg(), err_type);
return err_info;
}
diff --git a/src/moab/ErrorHandler.hpp b/src/moab/ErrorHandler.hpp
index 6323335..efb117f 100644
--- a/src/moab/ErrorHandler.hpp
+++ b/src/moab/ErrorHandler.hpp
@@ -4,6 +4,7 @@
#include "moab/Types.hpp"
#include <sstream>
+#include <string.h>
namespace moab {
@@ -86,20 +87,31 @@ void MBErrorHandler_Finalize();
bool MBErrorHandler_Initialized();
//! Routine that is called when an error has been detected
-ErrorInfo MBError(int line, const char* func, const char* file, const ErrorInfo& err_info, ErrorType err_type);
+ErrorInfo MBError(int line, const char* func, const char* file, const char* dir, const ErrorInfo& err_info, ErrorType err_type);
#define ERROR_INFO_SUCCESS ErrorInfo(MB_SUCCESS)
+#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
+
+#define MBSTRINGIFY_(X) #X
+#define MBSTRINGIFY(X) MBSTRINGIFY_(X)
+
+#ifdef LOCDIR
+#define __SDIR__ MBSTRINGIFY(LOCDIR)
+#else
+#define __SDIR__ ""
+#endif
+
#define SET_ERR(err_info) \
- return MBError(__LINE__, __func__, __FILE__, err_info, MB_ERROR_TYPE_NEW)
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_info, MB_ERROR_TYPE_NEW)
#define SET_ERR1(err_code, err_msg) \
- return MBError(__LINE__, __func__, __FILE__, ErrorInfo(err_code, err_msg), MB_ERROR_TYPE_NEW)
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, ErrorInfo(err_code, err_msg), MB_ERROR_TYPE_NEW)
#define CHK_ERR(err_info) \
do { \
if (MB_SUCCESS != err_info) \
- return MBError(__LINE__, __func__, __FILE__, err_info, MB_ERROR_TYPE_EXISTING); \
+ return MBError(__LINE__, __func__, __FILENAME__, __SDIR__, err_info, MB_ERROR_TYPE_EXISTING); \
} while (false)
#define CHK_ERR1(err_info, err_msg_to_set) \
Repository URL: https://bitbucket.org/fathomteam/moab/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the moab-dev
mailing list