forked from ValveSoftware/source-sdk-2013
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82bc30c
commit b63ab76
Showing
14 changed files
with
11,410 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//----------------------------------------------------------------------- | ||
// github.com/samisalreadytaken/sqdbg | ||
//----------------------------------------------------------------------- | ||
// | ||
// Squirrel Debugger | ||
// | ||
|
||
#ifndef SQDBG_SERVER_H | ||
#define SQDBG_SERVER_H | ||
|
||
#include <squirrel.h> | ||
|
||
#define SQDBG_SV_API_VER 1 | ||
|
||
struct SQDebugServer; | ||
typedef SQDebugServer* HSQDEBUGSERVER; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// Create and attach a new debugger | ||
// Memory is owned by the VM, it is freed when the VM dies or | ||
// the debugger is disconnected via sqdbg_destroy_debugger() | ||
extern HSQDEBUGSERVER sqdbg_attach_debugger( HSQUIRRELVM vm ); | ||
|
||
// Detach and destroy the debugger attached to this VM | ||
// Invalidates the handle returned from sqdbg_attach_debugger() | ||
extern void sqdbg_destroy_debugger( HSQUIRRELVM vm ); | ||
|
||
// Open specified port and allow client connections | ||
// Returns 0 on success | ||
extern int sqdbg_listen_socket( HSQDEBUGSERVER dbg, unsigned short port ); | ||
|
||
// Process client connections and incoming messages | ||
extern void sqdbg_frame( HSQDEBUGSERVER dbg ); | ||
|
||
// Redirects to sq_compilebuffer | ||
// If the VM has a debugger attached, copies every script to be able to source them to debugger clients | ||
extern SQRESULT sqdbg_compilebuffer( HSQUIRRELVM vm, const SQChar *script, SQInteger size, | ||
const SQChar *sourcename, SQBool raiseerror ); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // SQDBG_SERVER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
//----------------------------------------------------------------------- | ||
// github.com/samisalreadytaken/sqdbg | ||
//----------------------------------------------------------------------- | ||
// | ||
|
||
#ifndef SQDBG_DEBUG_H | ||
#define SQDBG_DEBUG_H | ||
|
||
#ifdef _DEBUG | ||
#ifdef _WIN32 | ||
#include <crtdbg.h> | ||
|
||
bool __IsDebuggerPresent(); | ||
|
||
static inline const char *GetModuleBaseName() | ||
{ | ||
static char module[MAX_PATH]; | ||
DWORD len = GetModuleFileNameA( NULL, module, sizeof(module) ); | ||
|
||
if ( len != 0 ) | ||
{ | ||
for ( char *pBase = module + len; pBase-- > module; ) | ||
{ | ||
if ( *pBase == '\\' ) | ||
return pBase + 1; | ||
} | ||
|
||
return module; | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
#define DebuggerBreak() do { if ( __IsDebuggerPresent() ) __debugbreak(); } while(0); | ||
|
||
#define Assert(x) \ | ||
do { \ | ||
__CAT( L, __LINE__ ): \ | ||
if ( !(x) && (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, GetModuleBaseName(), #x)) ) { \ | ||
if ( !__IsDebuggerPresent() ) \ | ||
goto __CAT( L, __LINE__ ); \ | ||
__debugbreak(); \ | ||
} \ | ||
} while(0) | ||
|
||
#define AssertMsg(x,msg) \ | ||
do { \ | ||
__CAT( L, __LINE__ ): \ | ||
if ( !(x) && (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, GetModuleBaseName(), msg)) ) { \ | ||
if ( !__IsDebuggerPresent() ) \ | ||
goto __CAT( L, __LINE__ ); \ | ||
__debugbreak(); \ | ||
} \ | ||
} while(0) | ||
|
||
#define AssertMsgF(x,msg,...) \ | ||
do { \ | ||
__CAT( L, __LINE__ ): \ | ||
if ( !(x) && (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, GetModuleBaseName(), msg, __VA_ARGS__)) ) { \ | ||
if ( !__IsDebuggerPresent() ) \ | ||
goto __CAT( L, __LINE__ ); \ | ||
__debugbreak(); \ | ||
} \ | ||
} while(0) | ||
#else | ||
extern "C" int printf(const char *, ...); | ||
|
||
#define DebuggerBreak() asm("int3") | ||
|
||
#define Assert(x) \ | ||
do { \ | ||
if ( !(x) ) \ | ||
{ \ | ||
::printf("Assertion failed %s:%d: %s\n", __FILE__, __LINE__, #x); \ | ||
DebuggerBreak(); \ | ||
} \ | ||
} while(0) | ||
|
||
#define AssertMsg(x,msg) \ | ||
do { \ | ||
if ( !(x) ) \ | ||
{ \ | ||
::printf("Assertion failed %s:%d: %s\n", __FILE__, __LINE__, msg); \ | ||
DebuggerBreak(); \ | ||
} \ | ||
} while(0) | ||
|
||
#define AssertMsgF(x,msg,...) \ | ||
do { \ | ||
if ( !(x) ) \ | ||
{ \ | ||
::printf("Assertion failed %s:%d: ", __FILE__, __LINE__); \ | ||
::printf(msg, __VA_ARGS__); \ | ||
::printf("\n"); \ | ||
DebuggerBreak(); \ | ||
} \ | ||
} while(0) | ||
#endif | ||
#define Verify(x) Assert(x) | ||
#else | ||
#define DebuggerBreak() | ||
#define Assert(x) | ||
#define AssertMsg(x,msg) | ||
#define AssertMsgF(x,msg,...) | ||
#define Verify(x) x | ||
#endif // _DEBUG | ||
|
||
#ifdef _WIN32 | ||
#define UNREACHABLE() do { Assert(!"UNREACHABLE"); __assume(0); } while(0); | ||
#else | ||
#define UNREACHABLE() do { Assert(!"UNREACHABLE"); __builtin_unreachable(); } while(0); | ||
#endif | ||
|
||
#define ___CAT(a, b) a##b | ||
#define __CAT(a, b) ___CAT(a,b) | ||
|
||
#ifndef assert | ||
#define assert(x) Assert(x) | ||
#endif | ||
|
||
#ifdef _DEBUG | ||
class CEntryCounter | ||
{ | ||
int *count; | ||
public: | ||
CEntryCounter( int *p ) : count(p) { (*count)++; } | ||
~CEntryCounter() { (*count)--; } | ||
}; | ||
|
||
#define TRACK_ENTRIES() \ | ||
static int s_EntryCount = 0; \ | ||
CEntryCounter entrycounter( &s_EntryCount ); | ||
#else | ||
#define TRACK_ENTRIES() | ||
#endif | ||
|
||
#endif // SQDBG_DEBUG_H |
Oops, something went wrong.