Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion sp/src/game/client/vscript_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
extern IScriptManager *scriptmanager;
extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );

#ifdef MAPBASE_VSCRIPT
extern int vscript_debugger_port;
#endif

// #define VMPROFILE 1

#ifdef VMPROFILE
Expand Down Expand Up @@ -682,6 +686,14 @@ bool VScriptClientInit()
//g_pScriptVM->RegisterInstance( &g_ScriptEntityIterator, "Entities" );
#endif

#ifdef MAPBASE_VSCRIPT
if ( vscript_debugger_port )
{
g_pScriptVM->ConnectDebugger( vscript_debugger_port );
vscript_debugger_port = 0;
}
#endif

if (scriptLanguage == SL_SQUIRREL)
{
g_pScriptVM->Run( g_Script_vscript_client );
Expand Down Expand Up @@ -768,11 +780,19 @@ class CVScriptGameSystem : public CAutoGameSystemPerFrame
VScriptClientTerm();
}

virtual void FrameUpdatePostEntityThink()
#ifdef MAPBASE_VSCRIPT
virtual void Update( float frametime )
{
if ( g_pScriptVM )
g_pScriptVM->Frame( frametime );
}
#else
virtual void FrameUpdatePostEntityThink()
{
if ( g_pScriptVM )
g_pScriptVM->Frame( gpGlobals->frametime );
}
#endif

bool m_bAllowEntityCreationInScripts;
};
Expand Down
12 changes: 12 additions & 0 deletions sp/src/game/server/vscript_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );

#ifdef MAPBASE_VSCRIPT
extern int vscript_debugger_port;
#endif

// #define VMPROFILE 1

#ifdef VMPROFILE
Expand Down Expand Up @@ -663,6 +667,14 @@ bool VScriptServerInit()
RegisterSharedScriptFunctions();
#endif

#ifdef MAPBASE_VSCRIPT
if ( vscript_debugger_port )
{
g_pScriptVM->ConnectDebugger( vscript_debugger_port );
vscript_debugger_port = 0;
}
#endif

if (scriptLanguage == SL_SQUIRREL)
{
g_pScriptVM->Run( g_Script_vscript_server );
Expand Down
19 changes: 19 additions & 0 deletions sp/src/game/shared/vscript_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );
#ifdef MAPBASE_VSCRIPT
// This is to ensure a dependency exists between the vscript library and the game DLLs
extern int vscript_token;
extern int vscript_debugger_port;
int vscript_token_hack = vscript_token;
#endif

Expand Down Expand Up @@ -390,12 +391,30 @@ CON_COMMAND_F( script_debug, "Connect the vscript VM to the script debugger", FC
if ( !IsCommandIssuedByServerAdmin() )
return;

#ifdef MAPBASE_VSCRIPT
#ifdef GAME_DLL
int port = 1212;
#else
int port = 1213;
#endif
#endif

if ( !g_pScriptVM )
{
#ifdef MAPBASE_VSCRIPT
vscript_debugger_port = port;
CGMsg( 0, CON_GROUP_VSCRIPT, "VScript VM is not running, waiting for it to attach the debugger to port %d...\n", port );
#else
CGWarning( 0, CON_GROUP_VSCRIPT, "Scripting disabled or no server running\n" );
#endif
return;
}

#ifdef MAPBASE_VSCRIPT
g_pScriptVM->ConnectDebugger( port );
#else
g_pScriptVM->ConnectDebugger();
#endif
}

#ifdef CLIENT_DLL
Expand Down
4 changes: 4 additions & 0 deletions sp/src/public/vscript/ivscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,11 @@ class IScriptVM
virtual bool Init() = 0;
virtual void Shutdown() = 0;

#ifdef MAPBASE_VSCRIPT
virtual bool ConnectDebugger( int port = 0 ) = 0;
#else
virtual bool ConnectDebugger() = 0;
#endif
virtual void DisconnectDebugger() = 0;

virtual ScriptLanguage_t GetLanguage() = 0;
Expand Down
70 changes: 70 additions & 0 deletions sp/src/vscript/sqdbg/include/sqdbg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//-----------------------------------------------------------------------
// github.com/samisalreadytaken/sqdbg
//-----------------------------------------------------------------------
//
// Squirrel Debugger
//

#ifndef SQDBG_H
#define SQDBG_H

#include <squirrel.h>

#define SQDBG_SV_API_VER 1

#ifndef SQDBG_API
#ifdef SQDBG_DLL
#if defined(_WIN32)
#ifdef SQDBG_DLL_EXPORT
#define SQDBG_API __declspec(dllexport)
#else
#define SQDBG_API __declspec(dllimport)
#endif
#elif defined(__GNUC__)
#ifdef SQDBG_DLL_EXPORT
#define SQDBG_API __attribute__((visibility("default")))
#else
#define SQDBG_API extern
#endif
#else
#define SQDBG_API extern
#endif
#else
#define SQDBG_API extern
#endif
#endif

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()
SQDBG_API HSQDEBUGSERVER sqdbg_attach_debugger( HSQUIRRELVM vm );

// Detach and destroy the debugger attached to this VM
// Invalidates the handle returned from sqdbg_attach_debugger()
SQDBG_API void sqdbg_destroy_debugger( HSQUIRRELVM vm );

// Open specified port and allow client connections
// If port is 0, the system will choose a unique available port
// Returns 0 on success
SQDBG_API int sqdbg_listen_socket( HSQDEBUGSERVER dbg, unsigned short port );

// Process client connections and incoming messages
// Blocks on script breakpoints while a client is connected
SQDBG_API void sqdbg_frame( HSQDEBUGSERVER dbg );

// Copies the script to be able to source it to debugger clients
SQDBG_API void sqdbg_on_script_compile( HSQDEBUGSERVER dbg, const SQChar *script, SQInteger size,
const SQChar *sourcename, SQInteger sourcenamelen );

#ifdef __cplusplus
}
#endif

#endif // SQDBG_H
131 changes: 131 additions & 0 deletions sp/src/vscript/sqdbg/sqdbg/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//-----------------------------------------------------------------------
// github.com/samisalreadytaken/sqdbg
//-----------------------------------------------------------------------
//

#ifndef SQDBG_DEBUG_H
#define SQDBG_DEBUG_H

#if 0

#ifdef _DEBUG
#ifdef _WIN32
#include <crtdbg.h>

bool __IsDebuggerPresent();
const char *GetModuleBaseName();

#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 AssertMsg1( x, msg, a1 ) \
do { \
__CAT( L, __LINE__ ): \
if ( !(x) && (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, GetModuleBaseName(), msg, a1)) ) \
{ \
if ( !__IsDebuggerPresent() ) \
goto __CAT( L, __LINE__ ); \
__debugbreak(); \
} \
} while(0)

#define AssertMsg2( x, msg, a1, a2 ) \
do { \
__CAT( L, __LINE__ ): \
if ( !(x) && (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, GetModuleBaseName(), msg, a1, a2)) ) \
{ \
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 AssertMsg1( x, msg, a1 ) \
do { \
if ( !(x) ) \
{ \
::printf("Assertion failed %s:%d: ", __FILE__, __LINE__); \
::printf(msg, a1); \
::printf("\n"); \
DebuggerBreak(); \
} \
} while(0)

#define AssertMsg2( x, msg, a1, a2 ) \
do { \
if ( !(x) ) \
{ \
::printf("Assertion failed %s:%d: ", __FILE__, __LINE__); \
::printf(msg, a1, a2); \
::printf("\n"); \
DebuggerBreak(); \
} \
} while(0)
#endif
#define Verify( x ) Assert(x)
#else
#define DebuggerBreak() ((void)0)
#define Assert( x ) ((void)0)
#define AssertMsg( x, msg ) ((void)0)
#define AssertMsg1( x, msg, a1 ) ((void)0)
#define AssertMsg2( x, msg, a1, a2 ) ((void)0)
#define Verify( x ) x
#endif // _DEBUG

#endif

#include <tier0/dbg.h>

// Misdefined for GCC in platform.h
#undef UNREACHABLE

#ifdef _WIN32
#define UNREACHABLE() do { Assert(!"UNREACHABLE"); __assume(0); } while(0)
#else
#define UNREACHABLE() do { Assert(!"UNREACHABLE"); __builtin_unreachable(); } while(0)
#endif

#endif // SQDBG_DEBUG_H
Loading