diff --git a/xpcom/base/ErrorNames.cpp b/xpcom/base/ErrorNames.cpp index 322163e6ff9b..c1540d4bd333 100644 --- a/xpcom/base/ErrorNames.cpp +++ b/xpcom/base/ErrorNames.cpp @@ -14,6 +14,8 @@ namespace mozilla { +const char* GetStaticErrorName(nsresult rv) { return GetErrorNameInternal(rv); } + void GetErrorName(nsresult rv, nsACString& name) { if (const char* errorName = GetErrorNameInternal(rv)) { name.AssignASCII(errorName); diff --git a/xpcom/base/ErrorNames.h b/xpcom/base/ErrorNames.h index 1648bb37339b..d209cc492baf 100644 --- a/xpcom/base/ErrorNames.h +++ b/xpcom/base/ErrorNames.h @@ -19,6 +19,11 @@ namespace mozilla { // "NS_ERROR_GENERATE_FAILURE(, )". void GetErrorName(nsresult rv, nsACString& name); +// Same as GetErrorName, except that only nsresult values with statically +// known symbolic names are handled. For all other values, nullptr is +// returned. +const char* GetStaticErrorName(nsresult rv); + } // namespace mozilla #endif // mozilla_ErrorNames_h diff --git a/xpcom/base/nsDebug.h b/xpcom/base/nsDebug.h index 5950dea5fe27..61913e9bb4a2 100644 --- a/xpcom/base/nsDebug.h +++ b/xpcom/base/nsDebug.h @@ -17,6 +17,7 @@ #include #ifdef DEBUG +# include "mozilla/ErrorNames.h" # include "mozilla/IntegerPrintfMacros.h" # include "mozilla/Printf.h" #endif @@ -247,18 +248,22 @@ inline void MOZ_PretendNoReturn() MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS {} #if defined(DEBUG) && !defined(XPCOM_GLUE_AVOID_NSPR) -# define NS_ENSURE_SUCCESS_BODY(res, ret) \ - mozilla::SmprintfPointer msg = mozilla::Smprintf( \ - "NS_ENSURE_SUCCESS(%s, %s) failed with " \ - "result 0x%" PRIX32, \ - #res, #ret, static_cast(__rv)); \ +# define NS_ENSURE_SUCCESS_BODY(res, ret) \ + const char* name = mozilla::GetStaticErrorName(__rv); \ + mozilla::SmprintfPointer msg = mozilla::Smprintf( \ + "NS_ENSURE_SUCCESS(%s, %s) failed with " \ + "result 0x%" PRIX32 "%s%s%s", \ + #res, #ret, static_cast(__rv), name ? " (" : "", \ + name ? name : "", name ? ")" : ""); \ NS_WARNING(msg.get()); -# define NS_ENSURE_SUCCESS_BODY_VOID(res) \ - mozilla::SmprintfPointer msg = mozilla::Smprintf( \ - "NS_ENSURE_SUCCESS_VOID(%s) failed with " \ - "result 0x%" PRIX32, \ - #res, static_cast(__rv)); \ +# define NS_ENSURE_SUCCESS_BODY_VOID(res) \ + const char* name = mozilla::GetStaticErrorName(__rv); \ + mozilla::SmprintfPointer msg = mozilla::Smprintf( \ + "NS_ENSURE_SUCCESS_VOID(%s) failed with " \ + "result 0x%" PRIX32 "%s%s%s", \ + #res, static_cast(__rv), name ? " (" : "", name ? name : "", \ + name ? ")" : ""); \ NS_WARNING(msg.get()); #else