3ds Max C++ API Reference
MaxSDK::Util::DebugHelpers Namespace Reference

Classes

struct  THREADNAME_INFO
 

Functions

void SetThreadName (DWORD dwThreadID, LPCSTR pcszThreadName)
 Sets the name of the given thread. More...
 
void SetThreadName (LPCSTR pcszThreadName)
 Sets the name of the current thread. More...
 
void SetThreadNameDebug (DWORD dwThreadID, LPCSTR pcszThreadName)
 Sets the name of the given thread. More...
 
void SetThreadNameDebug (LPCSTR pcszThreadName)
 Sets the name of the current thread, but only if building for debug. More...
 
void Trace (LPCMSTR lpctszMsg,...)
 Send a string to the debugger's output window, but only in debug builds. More...
 
void Trace0 (LPCMSTR lpctszMsg)
 Identical to Trace(), but without the variable argument list. More...
 

Function Documentation

◆ SetThreadName() [1/2]

void SetThreadName ( DWORD  dwThreadID,
LPCSTR  pcszThreadName 
)
inline

Sets the name of the given thread.

The given name will appear in the thread view of the debugger, enabling easier debugging.

Parameters
dwThreadIDThe ID of the thread for which to set the name.
pcszThreadNameThe string to use as the name of the thread.
62 {
63  THREADNAME_INFO info(pcszThreadName, dwThreadID);
64 
65  enum { MS_VC_EXCEPTION_ID = 0x406D1388 };
66 #ifdef _MSC_VER
67  __try
68 #endif
69  {
70  RaiseException( MS_VC_EXCEPTION_ID, 0,
71  sizeof(info)/ sizeof(ULONG_PTR),
72  reinterpret_cast<const ULONG_PTR*>(&info) );
73  }
74 #ifdef _MSC_VER
75  __except (EXCEPTION_CONTINUE_EXECUTION)
76  {
77  // empty
78  }
79 #endif
80 }

◆ SetThreadName() [2/2]

void SetThreadName ( LPCSTR  pcszThreadName)
inline

Sets the name of the current thread.

The given name will appear in the thread view of the debugger, enabling easier debugging.

Parameters
pcszThreadNameThe string to use as the name of the thread.
83 {
84 #if (_MANAGED == 1) || (_M_CEE == 1)
85  DebugHelpersCLR::SetThreadName(pcszThreadName);
86 #else
87  SetThreadName((DWORD)-1, pcszThreadName);
88 #endif
89 }
void SetThreadName(DWORD dwThreadID, LPCSTR pcszThreadName)
Sets the name of the given thread.
Definition: DebugHelpers.inline.h:61

◆ SetThreadNameDebug() [1/2]

void SetThreadNameDebug ( DWORD  dwThreadID,
LPCSTR  pcszThreadName 
)
inline

Sets the name of the given thread.

The given name will appear in the thread view of the debugger, enabling easier debugging. If the thread name shouldn't appear in release builds (e.g. because of security risks), then use this method instead of SetThreadName().

Parameters
dwThreadIDThe ID of the thread for which to set the name.
pcszThreadNameThe string to use as the name of the thread.
95 {
96 #ifdef _DEBUG
97  SetThreadName(dwThreadID, pcszThreadName);
98 #else
99  UNUSED_PARAM(dwThreadID);
100  UNUSED_PARAM(pcszThreadName);
101 #endif
102 }
#define UNUSED_PARAM(x)
Definition: BuildWarnings.h:18

◆ SetThreadNameDebug() [2/2]

void SetThreadNameDebug ( LPCSTR  pcszThreadName)
inline

Sets the name of the current thread, but only if building for debug.

The given name will appear in the thread view of the debugger, enabling easier debugging. If the thread name shouldn't appear in release builds (e.g. because of security risks), then use this method instead of SetThreadName().

Parameters
pcszThreadNameThe string to use as the name of the thread.
105 {
106 #ifdef _DEBUG
107 
108 #if (_MANAGED == 1) || (_M_CEE == 1)
110 #else
111  SetThreadName((DWORD)-1, pcszThreadName);
112 #endif
113 
114 #else
115  UNUSED_PARAM(pcszThreadName);
116 #endif
117 }

◆ Trace()

void Trace ( LPCMSTR  lpctszMsg,
  ... 
)
inline

Send a string to the debugger's output window, but only in debug builds.

More convenient than having to #ifndef NDEBUG all over the place. It also supports a variable number of arguments, as you can see.

Parameters
lpctszMsgThe string to send to the debugger's output window.
123 {
124 #ifndef NDEBUG
125  MCHAR tszBuffer[4096];
126 
127  va_list args;
128  va_start(args, lpctszMsg);
129 
130  _vsntprintf_s(tszBuffer, 4096, lpctszMsg, args);
131  DebugOutputString(tszBuffer);
132 
133  va_end(args);
134 #else
135  UNUSED_PARAM(lpctszMsg);
136 #endif
137 }
UtilExport void DebugOutputString(const MCHAR *string)
#define MCHAR
MBCS/Unicode helper defines std::wofstream doesn't mix well with Unicode.
Definition: strbasic.h:42

◆ Trace0()

void Trace0 ( LPCMSTR  lpctszMsg)
inline

Identical to Trace(), but without the variable argument list.

140 {
141 #ifndef NDEBUG
142  DebugOutputString(lpctszMsg);
143 #else
144  UNUSED_PARAM(lpctszMsg);
145 #endif
146 }