[CRT][MSVCRT] Implement _CrtDbgReport(W)V and redefine _CrtDbgReport(W) around those (#5678)

Also add the internal _VCrtDbgReportA and _VCrtDbgReportW functions listed in
https://learn.microsoft.com/en-us/cpp/c-runtime-library/internal-crt-globals-and-functions?view=msvc-170

CORE-11835, CORE-15517
This commit is contained in:
Hermès Bélusca-Maïto 2023-09-10 19:08:07 +02:00
parent 7901a4c8fe
commit f49e213943
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 89 additions and 23 deletions

View file

@ -200,9 +200,9 @@
@ stub -version=0x600+ _CrtCheckMemory @ stub -version=0x600+ _CrtCheckMemory
@ stub -version=0x600+ _CrtDbgBreak @ stub -version=0x600+ _CrtDbgBreak
@ cdecl -version=0x600+ _CrtDbgReport(long str long str str) @ cdecl -version=0x600+ _CrtDbgReport(long str long str str)
@ stub -version=0x600+ _CrtDbgReportV @ cdecl -version=0x600+ _CrtDbgReportV(long str long str str ptr)
@ cdecl -version=0x600+ _CrtDbgReportW(long wstr long wstr wstr) @ cdecl -version=0x600+ _CrtDbgReportW(long wstr long wstr wstr)
@ stub -version=0x600+ _CrtDbgReportWV @ cdecl -version=0x600+ _CrtDbgReportWV(long wstr long wstr wstr ptr)
@ stub -version=0x600+ _CrtDoForAllClientObjects @ stub -version=0x600+ _CrtDoForAllClientObjects
@ stub -version=0x600+ _CrtDumpMemoryLeaks @ stub -version=0x600+ _CrtDumpMemoryLeaks
@ stub -version=0x600+ _CrtIsMemoryBlock @ stub -version=0x600+ _CrtIsMemoryBlock

View file

@ -81,6 +81,7 @@ extern "C" {
size_t lTotalCount; size_t lTotalCount;
} _CrtMemState; } _CrtMemState;
// Debug reporting functions // Debug reporting functions
#ifdef _DEBUG #ifdef _DEBUG
@ -88,6 +89,9 @@ extern "C" {
int __cdecl _CrtDbgReport(int reportType, const char *filename, int linenumber, const char *moduleName, const char *format, ...); int __cdecl _CrtDbgReport(int reportType, const char *filename, int linenumber, const char *moduleName, const char *format, ...);
int __cdecl _CrtDbgReportW(int reportType, const wchar_t *filename, int linenumber, const wchar_t *moduleName, const wchar_t *format, ...); int __cdecl _CrtDbgReportW(int reportType, const wchar_t *filename, int linenumber, const wchar_t *moduleName, const wchar_t *format, ...);
int __cdecl _CrtDbgReportV(int reportType, const char *filename, int linenumber, const char *moduleName, const char *format, va_list arglist);
int __cdecl _CrtDbgReportWV(int reportType, const wchar_t *filename, int linenumber, const wchar_t *moduleName, const wchar_t *format, va_list arglist);
#endif #endif

View file

@ -9,18 +9,11 @@
#include "atldef.h" #include "atldef.h"
#if DBG // FIXME: We should use _DEBUG instead of DBG. CORE-17505 #ifdef _DEBUG
#include <stdio.h> #include <stdio.h>
#include <crtdbg.h> #include <crtdbg.h>
extern "C"
{
// FIXME: Enabling _DEBUG at top level causes assertion failures... CORE-17505
int __cdecl _CrtDbgReport(int reportType, const char *filename, int linenumber, const char *moduleName, const char *format, ...);
int __cdecl _CrtDbgReportW(int reportType, const wchar_t *filename, int linenumber, const wchar_t *moduleName, const wchar_t *format, ...);
}
namespace ATL namespace ATL
{ {
@ -267,10 +260,10 @@ AtlTrace(_In_z_ _Printf_format_string_ const X_CHAR *format, ...)
} // namespace ATL } // namespace ATL
#endif // DBG #endif // _DEBUG
#ifndef ATLTRACE #ifndef ATLTRACE
#if DBG // FIXME: We should use _DEBUG instead of DBG. CORE-17505 #ifdef _DEBUG
#define ATLTRACE(format, ...) ATL::AtlTraceEx(__FILE__, __LINE__, format, ##__VA_ARGS__) #define ATLTRACE(format, ...) ATL::AtlTraceEx(__FILE__, __LINE__, format, ##__VA_ARGS__)
#else #else
#define ATLTRACE(format, ...) ((void)0) #define ATLTRACE(format, ...) ((void)0)
@ -279,7 +272,7 @@ AtlTrace(_In_z_ _Printf_format_string_ const X_CHAR *format, ...)
#define ATLTRACE2 ATLTRACE #define ATLTRACE2 ATLTRACE
#if DBG // FIXME: We should use _DEBUG instead of DBG. CORE-17505 #ifdef _DEBUG
#define ATLTRACENOTIMPL(funcname) do { \ #define ATLTRACENOTIMPL(funcname) do { \
ATLTRACE(atlTraceNotImpl, 0, #funcname " is not implemented.\n"); \ ATLTRACE(atlTraceNotImpl, 0, #funcname " is not implemented.\n"); \
return E_NOTIMPL; \ return E_NOTIMPL; \

View file

@ -309,7 +309,14 @@ static int _CrtHandleDbgReport(int reportType, const char_t* szCompleteMessage,
EXTERN_C EXTERN_C
int __cdecl _CrtDbgReport(int reportType, const char *filename, int linenumber, const char *moduleName, const char *format, ...) int __cdecl
_VCrtDbgReportA(
int reportType,
const char *filename,
int linenumber,
const char *moduleName,
const char *format,
va_list arglist)
{ {
char szFormatted[DBGRPT_MAX_BUFFER_SIZE+1] = {0}; // The user provided message char szFormatted[DBGRPT_MAX_BUFFER_SIZE+1] = {0}; // The user provided message
char szCompleteMessage[(DBGRPT_MAX_BUFFER_SIZE+1)*2] = {0}; // The output for debug / file char szCompleteMessage[(DBGRPT_MAX_BUFFER_SIZE+1)*2] = {0}; // The output for debug / file
@ -325,11 +332,7 @@ int __cdecl _CrtDbgReport(int reportType, const char *filename, int linenumber,
if (format) if (format)
{ {
va_list arglist;
va_start(arglist, format);
int len = _vsnprintf(szFormatted, DBGRPT_MAX_BUFFER_SIZE - 2 - sizeof(DBGRPT_ASSERT_PREFIX_MESSAGE), format, arglist); int len = _vsnprintf(szFormatted, DBGRPT_MAX_BUFFER_SIZE - 2 - sizeof(DBGRPT_ASSERT_PREFIX_MESSAGE), format, arglist);
va_end(arglist);
if (len < 0) if (len < 0)
{ {
strcpy(szFormatted, DBGRPT_STRING_TOO_LONG); strcpy(szFormatted, DBGRPT_STRING_TOO_LONG);
@ -361,7 +364,14 @@ int __cdecl _CrtDbgReport(int reportType, const char *filename, int linenumber,
} }
EXTERN_C EXTERN_C
int __cdecl _CrtDbgReportW(int reportType, const wchar_t *filename, int linenumber, const wchar_t *moduleName, const wchar_t *format, ...) int __cdecl
_VCrtDbgReportW(
int reportType,
const wchar_t *filename,
int linenumber,
const wchar_t *moduleName,
const wchar_t *format,
va_list arglist)
{ {
wchar_t szFormatted[DBGRPT_MAX_BUFFER_SIZE+1] = {0}; // The user provided message wchar_t szFormatted[DBGRPT_MAX_BUFFER_SIZE+1] = {0}; // The user provided message
wchar_t szCompleteMessage[(DBGRPT_MAX_BUFFER_SIZE+1)*2] = {0}; // The output for debug / file wchar_t szCompleteMessage[(DBGRPT_MAX_BUFFER_SIZE+1)*2] = {0}; // The output for debug / file
@ -377,11 +387,7 @@ int __cdecl _CrtDbgReportW(int reportType, const wchar_t *filename, int linenumb
if (format) if (format)
{ {
va_list arglist;
va_start(arglist, format);
int len = _vsnwprintf(szFormatted, DBGRPT_MAX_BUFFER_SIZE - 2 - sizeof(DBGRPT_ASSERT_PREFIX_MESSAGE), format, arglist); int len = _vsnwprintf(szFormatted, DBGRPT_MAX_BUFFER_SIZE - 2 - sizeof(DBGRPT_ASSERT_PREFIX_MESSAGE), format, arglist);
va_end(arglist);
if (len < 0) if (len < 0)
{ {
wcscpy(szFormatted, _CRT_WIDE(DBGRPT_STRING_TOO_LONG)); wcscpy(szFormatted, _CRT_WIDE(DBGRPT_STRING_TOO_LONG));
@ -412,5 +418,68 @@ int __cdecl _CrtDbgReportW(int reportType, const wchar_t *filename, int linenumb
return nResult; return nResult;
} }
EXTERN_C
int __cdecl
_CrtDbgReportV(
int reportType,
const char *filename,
int linenumber,
const char *moduleName,
const char *format,
va_list arglist)
{
return _VCrtDbgReportA(reportType, filename, linenumber, moduleName, format, arglist);
}
EXTERN_C
int __cdecl
_CrtDbgReportWV(
int reportType,
const wchar_t *filename,
int linenumber,
const wchar_t *moduleName,
const wchar_t *format,
va_list arglist)
{
return _VCrtDbgReportW(reportType, filename, linenumber, moduleName, format, arglist);
}
EXTERN_C
int __cdecl
_CrtDbgReport(
int reportType,
const char *filename,
int linenumber,
const char *moduleName,
const char *format,
...)
{
va_list arglist;
int result;
va_start(arglist, format);
result = _VCrtDbgReportA(reportType, filename, linenumber, moduleName, format, arglist);
va_end(arglist);
return result;
}
EXTERN_C
int __cdecl
_CrtDbgReportW(
int reportType,
const wchar_t *filename,
int linenumber,
const wchar_t *moduleName,
const wchar_t *format,
...)
{
va_list arglist;
int result;
va_start(arglist, format);
result = _VCrtDbgReportW(reportType, filename, linenumber, moduleName, format, arglist);
va_end(arglist);
return result;
}
//#endif // _DEBUG //#endif // _DEBUG