ReactOS 0.4.16-dev-1067-ge98bba2
dbgrpt.cpp File Reference
#include <corecrt_internal.h>
#include <corecrt_internal_traits.h>
#include <intrin.h>
#include <malloc.h>
#include <minmax.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for dbgrpt.cpp:

Go to the source code of this file.

Macros

#define MAXLINELEN   64
 

Functions

static __crt_report_hook_node< char > *&__cdecl get_report_hook_list (char) throw ()
 
static __crt_report_hook_node< wchar_t > *&__cdecl get_report_hook_list (wchar_t) throw ()
 
static wchar_t const *__cdecl get_output_message_format (char) throw ()
 
static wchar_t const *__cdecl get_output_message_format (wchar_t) throw ()
 
template<typename Character , typename Hook >
static int __cdecl common_set_report_hook (int const mode, Hook const new_hook) throw ()
 
int __cdecl _CrtSetReportHook2 (int const mode, _CRT_REPORT_HOOK const new_hook)
 
int __cdecl _CrtSetReportHookW2 (int const mode, _CRT_REPORT_HOOKW const new_hook)
 
int __cdecl _CrtDbgReport (int const report_type, char const *const file_name, int const line_number, char const *const module_name, char const *const format,...)
 
int __cdecl _CrtDbgReportW (int const report_type, wchar_t const *const file_name, int const line_number, wchar_t const *const module_name, wchar_t const *const format,...)
 
template<typename Character >
static int __cdecl common_message_window (int const report_type, void *const return_address, Character const *const file_name, Character const *const line_number, Character const *const module_name, Character const *const user_message) throw ()
 
int __cdecl __acrt_MessageWindowA (int const report_type, void *const return_address, char const *const file_name, char const *const line_number, char const *const module_name, char const *const user_message)
 
int __cdecl __acrt_MessageWindowW (int const report_type, void *const return_address, wchar_t const *const file_name, wchar_t const *const line_number, wchar_t const *const module_name, wchar_t const *const user_message)
 

Variables

_CRT_REPORT_HOOK _pfnReportHook
 
__crt_report_hook_node< char > * _pReportHookList
 
__crt_report_hook_node< wchar_t > * _pReportHookListW
 
static wchar_t const *const report_type_messages [_CRT_ERRCNT]
 
static wchar_t const *const more_info_string
 

Macro Definition Documentation

◆ MAXLINELEN

#define MAXLINELEN   64

Definition at line 204 of file dbgrpt.cpp.

Function Documentation

◆ __acrt_MessageWindowA()

int __cdecl __acrt_MessageWindowA ( int const  report_type,
void *const  return_address,
char const *const  file_name,
char const *const  line_number,
char const *const  module_name,
char const *const  user_message 
)

Definition at line 443 of file dbgrpt.cpp.

451{
452 return common_message_window(report_type, return_address, file_name, line_number, module_name, user_message);
453}
static LPCWSTR LPCWSTR module_name
Definition: db.cpp:170
int const char const *const int const line_number
Definition: debug_heap.cpp:499
static LPCWSTR file_name
Definition: protocol.c:147
static int __cdecl common_message_window(int const report_type, void *const return_address, Character const *const file_name, Character const *const line_number, Character const *const module_name, Character const *const user_message)
Definition: dbgrpt.cpp:316
report_type
Definition: winetest.h:46

Referenced by _VCrtDbgReportA().

◆ __acrt_MessageWindowW()

int __cdecl __acrt_MessageWindowW ( int const  report_type,
void *const  return_address,
wchar_t const *const  file_name,
wchar_t const *const  line_number,
wchar_t const *const  module_name,
wchar_t const *const  user_message 
)

Definition at line 455 of file dbgrpt.cpp.

463{
464 return common_message_window(report_type, return_address, file_name, line_number, module_name, user_message);
465}

Referenced by _VCrtDbgReportW().

◆ _CrtDbgReport()

int __cdecl _CrtDbgReport ( int const  report_type,
char const *const  file_name,
int const  line_number,
char const *const  module_name,
char const *const  format,
  ... 
)

Definition at line 253 of file dbgrpt.cpp.

260{
265 return result;
266}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
EXTERN_C int __cdecl _VCrtDbgReportA(int reportType, const char *filename, int linenumber, const char *moduleName, const char *format, va_list arglist)
Definition: dbgrpt.cpp:314
GLuint64EXT * result
Definition: glext.h:11304
#define _ReturnAddress()
Definition: intrin_arm.h:35
va_lists_t arglist[FMT_ARGMAX+1]
Definition: format.c:284
Definition: format.c:58

◆ _CrtDbgReportW()

int __cdecl _CrtDbgReportW ( int const  report_type,
wchar_t const *const  file_name,
int const  line_number,
wchar_t const *const  module_name,
wchar_t const *const  format,
  ... 
)

Definition at line 268 of file dbgrpt.cpp.

275{
280 return result;
281}
EXTERN_C int __cdecl _VCrtDbgReportW(int reportType, const wchar_t *filename, int linenumber, const wchar_t *moduleName, const wchar_t *format, va_list arglist)
Definition: dbgrpt.cpp:376

◆ _CrtSetReportHook2()

int __cdecl _CrtSetReportHook2 ( int const  mode,
_CRT_REPORT_HOOK const  new_hook 
)

Definition at line 188 of file dbgrpt.cpp.

192{
193 return common_set_report_hook<char>(mode, new_hook);
194}
GLenum mode
Definition: glext.h:6217

◆ _CrtSetReportHookW2()

int __cdecl _CrtSetReportHookW2 ( int const  mode,
_CRT_REPORT_HOOKW const  new_hook 
)

Definition at line 196 of file dbgrpt.cpp.

200{
201 return common_set_report_hook<wchar_t>(mode, new_hook);
202}

◆ common_message_window()

template<typename Character >
static int __cdecl common_message_window ( int const  report_type,
void *const  return_address,
Character const *const  file_name,
Character const *const  line_number,
Character const *const  module_name,
Character const *const  user_message 
)
throw (
)
static

Definition at line 316 of file dbgrpt.cpp.

324{
325 using traits = __crt_char_traits<Character>;
326
327 if (user_message == nullptr)
328 {
329 return 1;
330 }
331
332 HMODULE module = nullptr;
334 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
335 static_cast<LPCWSTR>(return_address),
336 &module))
337 {
338 module = nullptr;
339 }
340 #ifdef CRTDLL
341 else if (module == reinterpret_cast<HMODULE>(&__ImageBase))
342 {
343 // If the message was reported from within the CRT DLL, report it as
344 // having come from the EXE instead:
345 module = nullptr;
346 }
347 #endif
348
349 Character program_name[MAX_PATH + 1]{};
350 if (!traits::get_module_file_name(module, program_name, static_cast<DWORD>(_countof(program_name))))
351 {
352 _ERRCHECK(traits::tcscpy_s(program_name, _countof(program_name), get_program_name_unknown_text(Character())));
353 }
354
355 // Shorten the program name:
356 size_t const program_name_length = traits::tcslen(program_name);
357 Character* short_program_name = program_name;
358 if (program_name_length > MAXLINELEN)
359 {
360 short_program_name += program_name_length - MAXLINELEN;
361 static_assert(MAXLINELEN > 3, "");
362#pragma warning(push)
363#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_HIGH_PRIORITY) // 26015
364 short_program_name[0] = '.';
365 short_program_name[1] = '.';
366 short_program_name[2] = '.';
367#pragma warning(pop)
368 }
369
370 // Shorten the module name:
371 size_t const module_name_length = module_name ? traits::tcslen(module_name) : 0;
372 Character const* short_module_name = nullptr;
373 if (module_name && module_name_length > MAXLINELEN)
374 {
375 short_module_name = module_name + module_name_length - MAXLINELEN + 3;
376 }
377
378 static Character const empty_string[] = { '\0' };
379
380 wchar_t message_buffer[DBGRPT_MAX_MSG];
381 int const sprintf_result = _snwprintf_s(
382 message_buffer,
383 _countof(message_buffer),
384 _countof(message_buffer) - 1,
385
386 get_output_message_format(Character()),
387
389 short_program_name,
390 module_name ? L"\nModule: " : L"",
391 short_module_name ? L"..." : L"",
392 short_module_name ? short_module_name : (module_name ? module_name : empty_string),
393 file_name ? L"\nFile: " : L"",
394 file_name ? file_name : empty_string,
395 line_number ? L"\nLine: " : L"",
396 line_number ? line_number : empty_string,
397 user_message[0] ? L"\n\n" : L"",
398 user_message[0] && _CRT_ASSERT == report_type ? L"Expression: " : L"",
399 user_message[0] ? user_message : empty_string,
401
402 _ERRCHECK_SPRINTF(sprintf_result);
403
404 if (sprintf_result < 0)
405 {
407 }
408
409 int const message_box_result = __acrt_show_wide_message_box(
410 message_buffer,
411 L"Microsoft Visual C++ Runtime Library",
413
414 switch (message_box_result)
415 {
416 case IDABORT: // Abort: Terminate execution
417 {
418 // Note that even though we are "aborting," we do not call abort()
419 // because we do not want to invoke Watson (the user has already had an
420 // opportunity to debug the error and chose not to).
421 __crt_signal_handler_t const sigabrt_action = __acrt_get_sigabrt_handler();
422 if (sigabrt_action != SIG_DFL)
423 {
424 raise(SIGABRT);
425 }
426
428 }
429
430 case IDRETRY:
431 {
432 return 1; // Retry: Debug break
433 }
434
435 case IDIGNORE:
436 default:
437 {
438 return 0; // Ignore: Continue execution
439 }
440 }
441}
#define DBGRPT_MAX_MSG
void(__cdecl * __crt_signal_handler_t)(int)
__crt_signal_handler_t __cdecl __acrt_get_sigabrt_handler(void)
Definition: signal.cpp:564
int __cdecl __acrt_show_wide_message_box(_In_opt_z_ wchar_t const *text, _In_opt_z_ wchar_t const *caption, _In_ unsigned type)
#define _ERRCHECK(e)
#define _ERRCHECK_SPRINTF(_PrintfCall)
#define DBGRPT_TOOLONGMSG
#define _CRT_ASSERT
Definition: crtdbg.h:22
int __cdecl raise(int _SigNum)
Definition: signal.c:71
#define SIG_DFL
Definition: signal.h:47
#define SIGABRT
Definition: signal.h:28
#define __ImageBase
Definition: crt_handler.c:22
#define GetCurrentProcess()
Definition: compat.h:759
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI GetModuleHandleExW(IN DWORD dwFlags, IN LPCWSTR lpwModuleName OPTIONAL, OUT HMODULE *phModule)
Definition: loader.c:866
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
unsigned long DWORD
Definition: ntddk_ex.h:95
static char * program_name
Definition: mkdosfs.c:519
#define wcscpy_s(d, l, s)
Definition: utility.h:201
#define L(x)
Definition: ntvdm.h:50
#define _countof(array)
Definition: sndvol32.h:70
#define MAXLINELEN
Definition: dbgrpt.cpp:204
static wchar_t const *const report_type_messages[_CRT_ERRCNT]
Definition: dbgrpt.cpp:37
static wchar_t const *__cdecl get_output_message_format(char)
Definition: dbgrpt.cpp:47
static wchar_t const *const more_info_string
Definition: dbgrpt.cpp:57
#define _CRT_WIDE(_String)
Definition: vcruntime.h:20
#define MB_SETFOREGROUND
Definition: winuser.h:825
#define MB_ICONHAND
Definition: winuser.h:799
#define MB_TASKMODAL
Definition: winuser.h:827
#define IDIGNORE
Definition: winuser.h:845
#define MB_ABORTRETRYIGNORE
Definition: winuser.h:802
#define IDABORT
Definition: winuser.h:843
#define IDRETRY
Definition: winuser.h:844
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by __acrt_MessageWindowA(), and __acrt_MessageWindowW().

◆ common_set_report_hook()

template<typename Character , typename Hook >
static int __cdecl common_set_report_hook ( int const  mode,
Hook const  new_hook 
)
throw (
)
static

Definition at line 88 of file dbgrpt.cpp.

92{
93 using node_type = __crt_report_hook_node<Character>;
94
96 _VALIDATE_RETURN(new_hook != nullptr, EINVAL, -1);
97
98 return __acrt_lock_and_call(__acrt_debug_lock, [&]
99 {
100 node_type*& hook_list = get_report_hook_list(Character());
101
102 node_type* p;
103 int ret = 0;
104
105 // Search for new hook function to see if it's already installed
106 for (p = hook_list; p != nullptr; p = p->next)
107 if (p->hook == new_hook)
108 break;
109
111 {
112 // Remove request - free list node if refcount goes to zero
113 if (p != nullptr)
114 {
115 if ((ret = --p->refcount) == 0)
116 {
117 if (p->next)
118 {
119 p->next->prev = p->prev;
120 }
121 if (p->prev)
122 {
123 p->prev->next = p->next;
124 }
125 else
126 {
127 hook_list = p->next;
128 }
129
130 _free_crt(p);
131 }
132 }
133 else
134 {
135 _ASSERTE(("The hook function is not in the list!", 0));
136 errno = EINVAL;
137 return -1;
138 }
139 }
140 else
141 {
142 // Insert request
143 if (p != nullptr)
144 {
145 // Hook function already registered, move to head of list
146 ret = ++p->refcount;
147 if (p != hook_list)
148 {
149 if (p->next)
150 p->next->prev = p->prev;
151 p->prev->next = p->next;
152 p->prev = nullptr;
153 p->next = hook_list;
154 hook_list->prev = p;
155 hook_list = p;
156 }
157 }
158 else
159 {
160 // Hook function not already registered, insert new node
161 __crt_unique_heap_ptr<node_type> new_node(_calloc_crt_t(node_type, 1));
162 if (!new_node)
163 {
164 ret = -1;
165 errno = ENOMEM;
166 }
167 else
168 {
169 new_node.get()->prev = nullptr;
170 new_node.get()->next = hook_list;
171
172 if (hook_list)
173 {
174 hook_list->prev = new_node.get();
175 }
176
177 ret = new_node.get()->refcount = 1;
178 new_node.get()->hook = new_hook;
179 hook_list = new_node.detach();
180 }
181 }
182 }
183
184 return ret;
185 });
186}
#define EINVAL
Definition: acclib.h:90
#define ENOMEM
Definition: acclib.h:84
@ __acrt_debug_lock
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
#define _ASSERTE(expr)
Definition: crtdbg.h:114
#define _CRT_RPTHOOK_INSTALL
Definition: crtdbg.h:39
#define _CRT_RPTHOOK_REMOVE
Definition: crtdbg.h:40
static OleMenuHookItem * hook_list
Definition: ole2.c:95
GLfloat GLfloat p
Definition: glext.h:8902
#define _free_crt
#define errno
Definition: errno.h:18
struct define * next
Definition: compiler.c:65
struct tagOleMenuHookItem * next
Definition: ole2.c:92
static __crt_report_hook_node< char > *&__cdecl get_report_hook_list(char)
Definition: dbgrpt.cpp:34
int ret

◆ get_output_message_format() [1/2]

static wchar_t const *__cdecl get_output_message_format ( char  )
throw (
)
static

Definition at line 47 of file dbgrpt.cpp.

48{
49 return L"Debug %ls!\n\nProgram: %hs%ls%ls%hs%ls%hs%ls%hs%ls%ls%hs%ls\n\n(Press Retry to debug the application)\n";
50}

Referenced by common_message_window().

◆ get_output_message_format() [2/2]

static wchar_t const *__cdecl get_output_message_format ( wchar_t  )
throw (
)
static

Definition at line 52 of file dbgrpt.cpp.

53{
54 return L"Debug %ls!\n\nProgram: %ls%ls%ls%ls%ls%ls%ls%ls%ls%ls%ls%ls\n\n(Press Retry to debug the application)\n";
55}

◆ get_report_hook_list() [1/2]

static __crt_report_hook_node< char > *&__cdecl get_report_hook_list ( char  )
throw (
)
static

Definition at line 34 of file dbgrpt.cpp.

34{ return _pReportHookList; }
__crt_report_hook_node< char > * _pReportHookList
Definition: dbgrpt.cpp:31

Referenced by common_set_report_hook().

◆ get_report_hook_list() [2/2]

static __crt_report_hook_node< wchar_t > *&__cdecl get_report_hook_list ( wchar_t  )
throw (
)
static

Definition at line 35 of file dbgrpt.cpp.

35{ return _pReportHookListW; }
__crt_report_hook_node< wchar_t > * _pReportHookListW
Definition: dbgrpt.cpp:32

Variable Documentation

◆ _pfnReportHook

_CRT_REPORT_HOOK _pfnReportHook

Definition at line 30 of file dbgrpt.cpp.

◆ _pReportHookList

__crt_report_hook_node<char>* _pReportHookList

Definition at line 31 of file dbgrpt.cpp.

Referenced by get_report_hook_list().

◆ _pReportHookListW

__crt_report_hook_node<wchar_t>* _pReportHookListW

Definition at line 32 of file dbgrpt.cpp.

Referenced by get_report_hook_list().

◆ more_info_string

wchar_t const* const more_info_string
static
Initial value:
=
L"\n\nFor information on how your program can cause an assertion"
L"\nfailure, see the Visual C++ documentation on asserts."

Definition at line 57 of file dbgrpt.cpp.

Referenced by common_message_window().

◆ report_type_messages

wchar_t const* const report_type_messages[_CRT_ERRCNT]
static
Initial value:
=
{
L"Warning",
L"Error",
L"Assertion Failed"
}

Definition at line 37 of file dbgrpt.cpp.

Referenced by common_message_window().