Add backtrace symbolizer/line number getter
This commit is contained in:
parent
f58ac24769
commit
33170f252a
@ -85,11 +85,9 @@ endif()
|
|||||||
configure_file(include/config.h.in ${CMAKE_SOURCE_DIR}/include/config.h @ONLY)
|
configure_file(include/config.h.in ${CMAKE_SOURCE_DIR}/include/config.h @ONLY)
|
||||||
configure_file(include/version.h.in ${CMAKE_SOURCE_DIR}/include/version.h @ONLY)
|
configure_file(include/version.h.in ${CMAKE_SOURCE_DIR}/include/version.h @ONLY)
|
||||||
|
|
||||||
#set_target_properties(cathook PROPERTIES COMPILE_FLAGS "-m32 -msse -msse2 -msse3 -fexceptions" LINK_FLAGS "-m32 -fno-gnu-unique -fexceptions -DNDEBUG")
|
set(CMAKE_CXX_FLAGS "-m32 -msse -msse2 -msse3 -fexceptions -fno-gnu-unique -DNDEBUG -Og -rdynamic -ggdb")
|
||||||
set(CMAKE_CXX_FLAGS "-m32 -msse -msse2 -msse3 -fexceptions -fno-gnu-unique -DNDEBUG")
|
set(CMAKE_CXX_FLAGS_DEBUG "")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-Og -rdynamic -ggdb")
|
set(CMAKE_CXX_FLAGS_RELEASE "")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
|
||||||
|
|
||||||
|
|
||||||
target_compile_definitions(cathook PRIVATE
|
target_compile_definitions(cathook PRIVATE
|
||||||
_GLIBCXX_USE_CXX11_ABI=0
|
_GLIBCXX_USE_CXX11_ABI=0
|
||||||
@ -136,3 +134,10 @@ add_subdirectory(external)
|
|||||||
|
|
||||||
add_custom_command(TARGET cathook POST_BUILD
|
add_custom_command(TARGET cathook POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cathook> "${CMAKE_SOURCE_DIR}/bin/$<TARGET_FILE_NAME:cathook>")
|
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cathook> "${CMAKE_SOURCE_DIR}/bin/$<TARGET_FILE_NAME:cathook>")
|
||||||
|
|
||||||
|
# Strip
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
|
message("Stripping info from library")
|
||||||
|
add_custom_command(TARGET cathook POST_BUILD
|
||||||
|
COMMAND strip --strip-all "${CMAKE_SOURCE_DIR}/bin/$<TARGET_FILE_NAME:cathook>")
|
||||||
|
endif()
|
||||||
|
10
src/hack.cpp
10
src/hack.cpp
@ -98,7 +98,7 @@ void hack::ExecuteCommand(const std::string command)
|
|||||||
hack::command_stack().push(command);
|
hack::command_stack().push(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void my_signal_handler(int signum)
|
void critical_error_handler(int signum)
|
||||||
{
|
{
|
||||||
namespace st = boost::stacktrace;
|
namespace st = boost::stacktrace;
|
||||||
::signal(signum, SIG_DFL);
|
::signal(signum, SIG_DFL);
|
||||||
@ -110,7 +110,7 @@ void my_signal_handler(int signum)
|
|||||||
Dl_info info;
|
Dl_info info;
|
||||||
if (!dladdr(reinterpret_cast<void *>(SetCanshootStatus), &info))
|
if (!dladdr(reinterpret_cast<void *>(SetCanshootStatus), &info))
|
||||||
return;
|
return;
|
||||||
unsigned int baseaddr = (unsigned int) info.dli_fbase;
|
unsigned int baseaddr = (unsigned int) info.dli_fbase - 1;
|
||||||
|
|
||||||
for (auto i : st::stacktrace())
|
for (auto i : st::stacktrace())
|
||||||
{
|
{
|
||||||
@ -127,7 +127,7 @@ void my_signal_handler(int signum)
|
|||||||
{
|
{
|
||||||
int status = -4;
|
int status = -4;
|
||||||
char *realname =
|
char *realname =
|
||||||
abi::__cxa_demangle(info2.dli_sname, 0, 0, &status);
|
abi::__cxa_demangle(info2.dli_sname, nullptr, nullptr, &status);
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
{
|
{
|
||||||
out << realname << std::endl;
|
out << realname << std::endl;
|
||||||
@ -137,7 +137,7 @@ void my_signal_handler(int signum)
|
|||||||
out << info2.dli_sname << std::endl;
|
out << info2.dli_sname << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
out << "Not found!" << std ::endl;
|
out << "No Symbol" << std ::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
out.close();
|
out.close();
|
||||||
@ -146,7 +146,7 @@ void my_signal_handler(int signum)
|
|||||||
|
|
||||||
void hack::Initialize()
|
void hack::Initialize()
|
||||||
{
|
{
|
||||||
::signal(SIGSEGV, &my_signal_handler);
|
::signal(SIGSEGV, &critical_error_handler);
|
||||||
//::signal(SIGABRT, &my_signal_handler);
|
//::signal(SIGABRT, &my_signal_handler);
|
||||||
time_injected = time(nullptr);
|
time_injected = time(nullptr);
|
||||||
/*passwd *pwd = getpwuid(getuid());
|
/*passwd *pwd = getpwuid(getuid());
|
||||||
|
22
symbolize-crash-log
Executable file
22
symbolize-crash-log
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
BACKTRACEFILE=$(ls -t1 /tmp | grep "cathook-$USER-.*-segfault.log" | head -n 1)
|
||||||
|
echo "$BACKTRACEFILE"
|
||||||
|
|
||||||
|
unknown=0
|
||||||
|
|
||||||
|
while read p; do
|
||||||
|
out=$(addr2line $(echo $p | cut -f 1 -d " ") -pCe ./build/bin/libcathook.so)
|
||||||
|
if [ $out != "??:0" ] && [ $out != "??:?" ]; then
|
||||||
|
if [ $unknown -gt 0 ]; then
|
||||||
|
echo "${unknown}x Unknown"
|
||||||
|
unknown=0
|
||||||
|
fi
|
||||||
|
echo "$out"
|
||||||
|
else
|
||||||
|
unknown=$(($unknown + 1))
|
||||||
|
fi
|
||||||
|
done <"/tmp/$BACKTRACEFILE"
|
||||||
|
|
||||||
|
if [ $unknown -gt 0 ]; then
|
||||||
|
echo "${unknown}x Unknown"
|
||||||
|
fi
|
Reference in New Issue
Block a user