Skip to content

Commit

Permalink
[CRT][MSVCRT] Implement _CrtDbgReport(W)V and redefine _CrtDbgReport(…
Browse files Browse the repository at this point in the history
…W) around those (reactos#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
  • Loading branch information
HBelusca committed Nov 11, 2023
1 parent 83e1193 commit a445c6b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 23 deletions.
4 changes: 2 additions & 2 deletions dll/win32/msvcrt/msvcrt.spec
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@
@ stub -version=0x600+ _CrtCheckMemory
@ stub -version=0x600+ _CrtDbgBreak
@ 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)
@ stub -version=0x600+ _CrtDbgReportWV
@ cdecl -version=0x600+ _CrtDbgReportWV(long wstr long wstr wstr ptr)
@ stub -version=0x600+ _CrtDoForAllClientObjects
@ stub -version=0x600+ _CrtDumpMemoryLeaks
@ stub -version=0x600+ _CrtIsMemoryBlock
Expand Down
4 changes: 4 additions & 0 deletions sdk/include/crt/crtdbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ extern "C" {
size_t lTotalCount;
} _CrtMemState;


// Debug reporting functions

#ifdef _DEBUG

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 _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


Expand Down
15 changes: 4 additions & 11 deletions sdk/lib/atl/atltrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@

#include "atldef.h"

#if DBG // FIXME: We should use _DEBUG instead of DBG. CORE-17505
#ifdef _DEBUG

#include <stdio.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
{

Expand Down Expand Up @@ -267,10 +260,10 @@ AtlTrace(_In_z_ _Printf_format_string_ const X_CHAR *format, ...)

} // namespace ATL

#endif // DBG
#endif // _DEBUG

#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__)
#else
#define ATLTRACE(format, ...) ((void)0)
Expand All @@ -279,7 +272,7 @@ AtlTrace(_In_z_ _Printf_format_string_ const X_CHAR *format, ...)

#define ATLTRACE2 ATLTRACE

#if DBG // FIXME: We should use _DEBUG instead of DBG. CORE-17505
#ifdef _DEBUG
#define ATLTRACENOTIMPL(funcname) do { \
ATLTRACE(atlTraceNotImpl, 0, #funcname " is not implemented.\n"); \
return E_NOTIMPL; \
Expand Down
89 changes: 79 additions & 10 deletions sdk/lib/crt/misc/dbgrpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,14 @@ static int _CrtHandleDbgReport(int reportType, const char_t* szCompleteMessage,


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 szCompleteMessage[(DBGRPT_MAX_BUFFER_SIZE+1)*2] = {0}; // The output for debug / file
Expand All @@ -325,11 +332,7 @@ int __cdecl _CrtDbgReport(int reportType, const char *filename, int linenumber,

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);
va_end(arglist);

if (len < 0)
{
strcpy(szFormatted, DBGRPT_STRING_TOO_LONG);
Expand Down Expand Up @@ -361,7 +364,14 @@ int __cdecl _CrtDbgReport(int reportType, const char *filename, int linenumber,
}

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 szCompleteMessage[(DBGRPT_MAX_BUFFER_SIZE+1)*2] = {0}; // The output for debug / file
Expand All @@ -377,11 +387,7 @@ int __cdecl _CrtDbgReportW(int reportType, const wchar_t *filename, int linenumb

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);
va_end(arglist);

if (len < 0)
{
wcscpy(szFormatted, _CRT_WIDE(DBGRPT_STRING_TOO_LONG));
Expand Down Expand Up @@ -412,5 +418,68 @@ int __cdecl _CrtDbgReportW(int reportType, const wchar_t *filename, int linenumb
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

0 comments on commit a445c6b

Please sign in to comment.