@@ -23,60 +23,62 @@ bool BeginCrashListener() { return true; }
2323#include " ../files/Files.h"
2424#include " ../common.h"
2525#include " ../entrypoint.h"
26+ #include " ../plugins/PluginManager.h"
27+ #include " CallStack.h"
2628
2729std::string startup_cmd = " None" ;
2830
29- const char * ws = " \t\n\r\f\v " ;
31+ const char * ws = " \t\n\r\f\v " ;
3032
3133// trim from end of string (right)
32- inline std::string & rtrim (std::string & s, const char * t = ws)
34+ inline std::string& rtrim (std::string& s, const char * t = ws)
3335{
3436 s.erase (s.find_last_not_of (t) + 1 );
3537 return s;
3638}
3739
3840// trim from beginning of string (left)
39- inline std::string & ltrim (std::string & s, const char * t = ws)
41+ inline std::string& ltrim (std::string& s, const char * t = ws)
4042{
4143 s.erase (0 , s.find_first_not_of (t));
4244 return s;
4345}
4446
4547// trim from both ends of string (right then left)
46- inline std::string & trim (std::string & s, const char * t = ws)
48+ inline std::string& trim (std::string& s, const char * t = ws)
4749{
4850 return ltrim (rtrim (s, t), t);
4951}
5052
5153std::string BacktraceRaw (int skip = 1 )
5254{
53- void * callstack[128 ];
55+ void * callstack[128 ];
5456 const int nMaxFrames = sizeof (callstack) / sizeof (callstack[0 ]);
5557 char buf[1024 ];
5658 int nFrames = backtrace (callstack, nMaxFrames);
57- char ** symbols = backtrace_symbols (callstack, nFrames);
59+ char ** symbols = backtrace_symbols (callstack, nFrames);
5860
5961 std::ostringstream trace_buf;
6062 for (int i = skip; i < nFrames; i++)
6163 {
6264 Dl_info info;
6365 if (dladdr (callstack[i], &info) && info.dli_sname )
6466 {
65- char * demangled = NULL ;
67+ char * demangled = NULL ;
6668 int status = -1 ;
6769 if (info.dli_sname [0 ] == ' _' )
6870 demangled = abi::__cxa_demangle (info.dli_sname , NULL , 0 , &status);
6971 snprintf (buf, sizeof (buf), " %02d. %p %s + %zd\n " ,
70- i - 1 , callstack[i],
71- status == 0 ? demangled : info.dli_sname == 0 ? symbols[i]
72- : info.dli_sname ,
73- (char *)callstack[i] - (char *)info.dli_saddr );
72+ i - 1 , callstack[i],
73+ status == 0 ? demangled : info.dli_sname == 0 ? symbols[i]
74+ : info.dli_sname ,
75+ (char *)callstack[i] - (char *)info.dli_saddr );
7476 free (demangled);
7577 }
7678 else
7779 {
7880 snprintf (buf, sizeof (buf), " %02d. %p %s\n " ,
79- i - 1 , callstack[i], symbols[i]);
81+ i - 1 , callstack[i], symbols[i]);
8082 }
8183 trace_buf << buf;
8284 }
@@ -97,11 +99,11 @@ TextTable GetBacktrace()
9799 backtraceTable.add (" Address " );
98100 backtraceTable.endOfRow ();
99101
100- void * callstack[128 ];
102+ void * callstack[128 ];
101103 const int nMaxFrames = sizeof (callstack) / sizeof (callstack[0 ]);
102104 char buf[1024 ];
103105 int nFrames = backtrace (callstack, nMaxFrames);
104- char ** symbols = backtrace_symbols (callstack, nFrames);
106+ char ** symbols = backtrace_symbols (callstack, nFrames);
105107
106108 for (int i = 2 ; i < nFrames; i++)
107109 {
@@ -113,13 +115,13 @@ TextTable GetBacktrace()
113115 Dl_info info;
114116 if (dladdr (callstack[i], &info) && info.dli_sname )
115117 {
116- char * demangled = NULL ;
118+ char * demangled = NULL ;
117119 int status = -1 ;
118120 if (info.dli_sname [0 ] == ' _' )
119121 demangled = abi::__cxa_demangle (info.dli_sname , NULL , 0 , &status);
120122
121123 std::string funcName = (status == 0 ? demangled : info.dli_sname == 0 ? " -"
122- : info.dli_sname );
124+ : info.dli_sname );
123125
124126 backtraceTable.add (string_format (" %s " , (funcName.size () > 36 ? (funcName.substr (0 , 33 ) + " ..." ) : funcName).c_str ()));
125127 free (demangled);
@@ -136,11 +138,27 @@ TextTable GetBacktrace()
136138 return backtraceTable;
137139}
138140
141+ std::string WritePluginsCallStack ()
142+ {
143+ std::string callstacks = " " ;
144+ for (Plugin* plugin : g_pluginManager->GetPluginsList ()) {
145+ auto callstack = g_callStack->GetPluginCallstack (plugin->GetName ());
146+ if (callstack.size () > 0 ) {
147+ callstacks += string_format (" Plugin %s:\n " , plugin->GetName ().c_str ());
148+ for (auto it = callstack.begin (); it != callstack.end (); ++it)
149+ callstacks += string_format (" - %s\n " , it->second .c_str ());
150+
151+ callstacks += " \n " ;
152+ }
153+ }
154+ return callstacks;
155+ }
156+
139157void signal_handler (int signumber)
140158{
141159 try
142160 {
143- void * tracePointers[20 ];
161+ void * tracePointers[20 ];
144162 size_t count = backtrace (tracePointers, 20 );
145163
146164 PLUGIN_PRINTF (" Crash Reporter" , " A crash has occured and a dump has been created:\n " );
@@ -153,10 +171,10 @@ void signal_handler(int signumber)
153171 if (Files::ExistsPath (file_path))
154172 Files::Delete (file_path);
155173
156- Files::Append (file_path, string_format (" ================================\n Command: %s\n Map: %s\n ================================\n\n %s" , startup_cmd.c_str (), engine->GetServerGlobals () ? engine->GetServerGlobals ()->mapname .ToCStr () : " None" , backtraceData.c_str ()), false );
174+ Files::Append (file_path, string_format (" ================================\n Command: %s\n Map: %s\n ================================\n\n %s\n %s " , startup_cmd.c_str (), engine->GetServerGlobals () ? engine->GetServerGlobals ()->mapname .ToCStr () : " None" , backtraceData. c_str (), WritePluginsCallStack () .c_str ()), false );
157175 PLUGIN_PRINTF (" Crash Reporter" , " A dump log file has been created at: %s\n " , file_path.c_str ());
158176 }
159- catch (const std::runtime_error & e)
177+ catch (const std::runtime_error& e)
160178 {
161179 PLUGIN_PRINTF (" Crash Reporter" , " Error crash handling: %s\n " , e.what ());
162180 }
0 commit comments