Skip to content
Open
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ Read `lua/gcrash.lua` for information on function behavior.

The dump format is a simple text file containing a stack trace and any extra data generated by the crash handler. Dump files are saved under `garrysmod/gcrash/` with a name containing the date and time of the crash.

### UPDATE ~ x64 - 2025

Update on x64 Builds for GCrash
Testing the x64 builds on Linux proved to be unstable and resulted in random crashes. As a result, I've decided to simplify the x64 version of GCrash to focus solely on the Watchdog feature (freeze/hang detection and auto-restart).

As of 2025, Garry's Mod now supports dumping its state to text files. While this feature isn't as comprehensive as GCrash's stack dumps, it helps retain useful information. Additionally, Garry's Mod offers a console buffer for error logs, which can provide further insights in case of crashes.

With this in mind, I've removed the full GCrash functionality from the x64 build and kept only the infinite loop and server freeze detection, with automatic restart. This change is aimed at improving stability for x64 servers.

-----------------------------

Please note that if you're re-compiling, you’ll need to adjust the source files accordingly. The x86 version will remain unchanged and retain all previous features.

## Installing

Get the released (or build from source) `gmsv_gcrash_linux.dll` and put it in
Expand Down
Binary file added libs/bin/linux64/lua_shared.so
Binary file not shown.
Binary file removed libs/garrysmod/bin/lua_shared.so
Binary file not shown.
Binary file added libs/garrysmod/bin/lua_shared_srv.so
Binary file not shown.
Binary file modified libs/lua_shared.dll
Binary file not shown.
27 changes: 14 additions & 13 deletions lua/gcrash.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if CLIENT then return end
require "gcrash"

local enable_watchdog = true
Expand All @@ -24,32 +25,32 @@ local enable_watchdog = true
Destroy the watchdog, this is done automatically on server stop.
]]

gcrash.sethandler( function( write )
local function printline( s, ... ) write( string.format( tostring( s or "" ) .. "\n", ... ) ) end
gcrash.sethandler(function(write)
local function printline(s, ...) write(string.format(tostring(s or "") .. "\n", ...)) end

local i = 2 -- Only start at frame 2, we don't need the locals of this function
local dbg = debug.getinfo( i )
local dbg = debug.getinfo(i)
while dbg do
printline( "Frame #%d:", i - 2 )
printline("Frame #%d:", i - 2)

for j = 1, 255 do
local n, v = debug.getlocal( i, j )
local n, v = debug.getlocal(i, j)
if not n then break end
printline( " %s = %s", tostring( n ), tostring( v ) )
printline(" %s = %s", tostring(n), tostring(v))
end

printline( "" )
printline("")
i = i + 1
dbg = debug.getinfo( i )
dbg = debug.getinfo(i)
end

end )
end)

gcrash.crash = nil -- You can comment this out if you want to use it (to crash your server?)

if enable_watchdog then
timer.Simple(30, function()
gcrash.startwatchdog()
print( "Starting gcrash watchdog..." )
RunConsoleCommand("sv_hibernate_think", 1) -- We need it to run the watchdog updater while the server is empty
timer.Simple(120, function() -- We let the watchdog wait before launching for long time loading servers
gcrash.startwatchdog(45)
end)
end
end
30 changes: 14 additions & 16 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project "gmsv_gcrash"
libdirs "libs/"
targetdir "build"

if _ACTION == "gmake2" then
if _ACTION == "gmake" then
postbuildcommands "{MOVE} %{cfg.targetdir}/lib%{prj.name}%{cfg.targetsuffix}.so %{cfg.targetdir}/%{prj.name}%{cfg.targetsuffix}.dll"
else
links "lua_shared"
Expand All @@ -21,46 +21,44 @@ project "gmsv_gcrash"
"include/**.*"
}

configuration "Debug"
filter "configurations:Debug"
architecture "x86"
optimize "Debug"
if _ACTION == "gmake2" then
linkoptions "-l:garrysmod/bin/lua_shared.so"
if _ACTION == "gmake" then
linkoptions "-l:garrysmod/bin/lua_shared_srv.so"
end
if os.istarget( "windows" ) then targetsuffix "_win32" end
if os.istarget( "macosx" ) then targetsuffix "_osx" end
if os.istarget( "linux" ) then targetsuffix "_linux" end

configuration "Debug64"
filter "configurations:Debug64"
architecture "x86_64"
optimize "Debug"
if _ACTION == "gmake2" then
if _ACTION == "gmake" then
linkoptions "-l:bin/linux64/lua_shared.so"
end
if os.istarget( "windows" ) then targetsuffix "_win64" end
if os.istarget( "macosx" ) then targetsuffix "_osx64" end
if os.istarget( "linux" ) then targetsuffix "_linux64" end

configuration "Release"
filter "configurations:Release"
architecture "x86"
optimize "Speed"
if staticruntime then staticruntime "On"
else flags "StaticRuntime" end
if _ACTION == "gmake2" then
linkoptions "-l:garrysmod/bin/lua_shared.so"
staticruntime "On"
if _ACTION == "gmake" then
linkoptions "-l:garrysmod/bin/lua_shared_srv.so"
end
if os.istarget( "windows" ) then targetsuffix "_win32" end
if os.istarget( "macosx" ) then targetsuffix "_osx" end
if os.istarget( "linux" ) then targetsuffix "_linux" end

configuration "Release64"
filter "configurations:Release64"
architecture "x86_64"
optimize "Speed"
if staticruntime then staticruntime "On"
else flags "StaticRuntime" end
if _ACTION == "gmake2" then
staticruntime "On"
if _ACTION == "gmake" then
linkoptions "-l:bin/linux64/lua_shared.so"
end
if os.istarget( "windows" ) then targetsuffix "_win64" end
if os.istarget( "macosx" ) then targetsuffix "_osx64" end
if os.istarget( "linux" ) then targetsuffix "_linux64" end
if os.istarget( "linux" ) then targetsuffix "_linux64" end
Loading