Reactos
1/*
2 * PROJECT: ReactOS Command Shell
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Dynamic trace (generates debugging output to console output)
5 * COPYRIGHT: Copyright 2011 Hans Harder <hans@atbas.org>
6 * Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7 */
8
9#include "precomp.h"
10
11#ifdef FEATURE_DYNAMIC_TRACE
12
13BOOL g_bDynamicTrace = FALSE;
14
15VOID CmdTrace(INT type, LPCSTR file, INT line, LPCSTR func, LPCSTR fmt, ...)
16{
17 va_list va;
18 int cch;
19 char szTextA[800];
20#ifdef _UNICODE
21 wchar_t szTextW[800];
22#endif
23 static struct __wine_debug_functions s_Debug;
24
25 va_start(va, fmt);
26
27 /* Console output */
28 if (g_bDynamicTrace)
29 {
30 StringCchPrintfA(szTextA, _countof(szTextA), "%s (%d): ", file, line);
31 cch = lstrlenA(szTextA);
32 StringCchVPrintfA(&szTextA[cch], _countof(szTextA) - cch, fmt, va);
33
34#ifdef _UNICODE
35 MultiByteToWideChar(OutputCodePage, 0, szTextA, -1, szTextW, _countof(szTextW));
36 szTextW[_countof(szTextW) - 1] = UNICODE_NULL; /* Avoid buffer overrun */
37 ConOutPuts(szTextW);
38#else
39 ConOutPuts(szTextA);
40#endif
41 }
42
43 if (!s_Debug.dbg_vlog)
44 __wine_dbg_set_functions(NULL, &s_Debug, sizeof(s_Debug));
45
46 /* Debug logging */
47 switch (type)
48 {
49 case __WINE_DBCL_FIXME:
50 if (__WINE_IS_DEBUG_ON(_FIXME, __wine_dbch___default))
51 s_Debug.dbg_vlog(__WINE_DBCL_FIXME, __wine_dbch___default, file, func, line, fmt, va);
52 break;
53 case __WINE_DBCL_ERR:
54 if (__WINE_IS_DEBUG_ON(_ERR, __wine_dbch___default))
55 s_Debug.dbg_vlog(__WINE_DBCL_ERR, __wine_dbch___default, file, func, line, fmt, va);
56 break;
57 case __WINE_DBCL_WARN:
58 if (__WINE_IS_DEBUG_ON(_WARN, __wine_dbch___default))
59 s_Debug.dbg_vlog(__WINE_DBCL_WARN, __wine_dbch___default, file, func, line, fmt, va);
60 break;
61 case __WINE_DBCL_TRACE:
62 if (__WINE_IS_DEBUG_ON(_TRACE, __wine_dbch___default))
63 s_Debug.dbg_vlog(__WINE_DBCL_TRACE, __wine_dbch___default, file, func, line, fmt, va);
64 break;
65 default:
66 break;
67 }
68
69 va_end(va);
70}
71
72#endif /* def FEATURE_DYNAMIC_TRACE */