forked from lsdev/LiteStep
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.cpp
More file actions
executable file
·149 lines (128 loc) · 4.04 KB
/
debug.cpp
File metadata and controls
executable file
·149 lines (128 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// This is a part of the Litestep Shell source code.
//
// Copyright (C) 1997-2015 LiteStep Development Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "debug.hpp"
#include "core.hpp"
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// DbgTraceMessage
//
void DbgTraceMessage(const char* pszFormat, ...)
{
ASSERT(NULL != pszFormat);
va_list args;
va_start(args, pszFormat);
char szBuffer[512];
StringCchVPrintfExA(szBuffer, 512,
NULL, NULL, STRSAFE_NULL_ON_FAILURE,
pszFormat, args);
va_end(args);
OutputDebugStringA(szBuffer);
#if !defined(__GNUC__)
// This just outputs a blank line in gdb
OutputDebugStringA("\n");
#endif
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// DbgTraceWindowMessage
//
#if defined(TRACE_ENABLED)
void DbgTraceWindowMessage(const char* pszPrefix, unsigned int uMsg,
uintptr_t wParam, uintptr_t lParam)
{
if (uMsg < WM_USER)
{
TRACE("[%s] WM_%.4X(%p, %p)",
pszPrefix, uMsg, wParam, lParam);
}
else if (uMsg >= WM_USER && uMsg <= (WM_APP-1))
{
TRACE("[%s] WM_USER+%u(%p, %p)",
pszPrefix, uMsg-WM_USER, wParam, lParam);
}
else if (uMsg >= WM_APP && uMsg <= (MAXINTATOM-1))
{
TRACE("[%s] WM_APP+%u(%p, %p)",
pszPrefix, uMsg-WM_APP, wParam, lParam);
}
else if (uMsg >= MAXINTATOM)
{
TCHAR szMsgName[MAX_PATH] = { 0 };
// GetClipboardFormatName retrieves the name of
// registered window messages too!
if (GetClipboardFormatName(
uMsg, szMsgName, COUNTOF(szMsgName)) > 0)
{
TRACE("[%s] WM_'%ls'(%p, %p)",
pszPrefix, szMsgName, wParam, lParam);
}
else
{
TRACE("[%s] WM_%.8X(%p, %p)",
pszPrefix, uMsg, wParam, lParam);
}
}
}
#endif // #TRACE_ENABLED
#if defined(MSVC_DEBUG)
#define MS_VC_EXCEPTION 0x406D1388
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// THREADNAME_INFO
// Helper struct for SetCurrentThreadName
//
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
48E0
-=-=-=
//
// DbgSetCurrentThreadName
//
void DbgSetCurrentThreadName(const char* pszThreadName)
{
//
// While you can put any thread's ID in the info struct, the thread
// apparently needs to be up and running for this to work, ie. there's a
// race condition. Thus we only support naming the current thread.
//
THREADNAME_INFO info = { 0 };
info.dwType = 0x1000;
info.szName = pszThreadName;
info.dwThreadID = (DWORD)-1;
info.dwFlags = 0;
__try
{
RaiseException(MS_VC_EXCEPTION, 0,
sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
// do nothing
}
}
#endif // MSVC_DEBUG