Add LLDB self debug to OSX
This commit is contained in:
21
config.lib
21
config.lib
@@ -97,6 +97,7 @@ set_default() {
|
|||||||
with_libbfd="1"
|
with_libbfd="1"
|
||||||
with_bfd_extra_debug="1"
|
with_bfd_extra_debug="1"
|
||||||
with_self_gdb_debug="1"
|
with_self_gdb_debug="1"
|
||||||
|
with_self_lldb_debug="1"
|
||||||
|
|
||||||
save_params_array="
|
save_params_array="
|
||||||
build
|
build
|
||||||
@@ -176,6 +177,7 @@ set_default() {
|
|||||||
with_libbfd
|
with_libbfd
|
||||||
with_bfd_extra_debug
|
with_bfd_extra_debug
|
||||||
with_self_gdb_debug
|
with_self_gdb_debug
|
||||||
|
with_self_lldb_debug
|
||||||
CC CXX CFLAGS CXXFLAGS LDFLAGS CFLAGS_BUILD CXXFLAGS_BUILD LDFLAGS_BUILD PKG_CONFIG_PATH PKG_CONFIG_LIBDIR"
|
CC CXX CFLAGS CXXFLAGS LDFLAGS CFLAGS_BUILD CXXFLAGS_BUILD LDFLAGS_BUILD PKG_CONFIG_PATH PKG_CONFIG_LIBDIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,6 +481,10 @@ detect_params() {
|
|||||||
--with-self-gdb-debug) with_self_gdb_debug="1";;
|
--with-self-gdb-debug) with_self_gdb_debug="1";;
|
||||||
--with-self-gdb-debug=*) with_self_gdb_debug="$optarg";;
|
--with-self-gdb-debug=*) with_self_gdb_debug="$optarg";;
|
||||||
|
|
||||||
|
--without-self-lldb-debug) with_self_lldb_debug="0";;
|
||||||
|
--with-self-lldb-debug) with_self_lldb_debug="1";;
|
||||||
|
--with-self-lldb-debug=*) with_self_lldb_debug="$optarg";;
|
||||||
|
|
||||||
CC=* | --CC=*) CC="$optarg";;
|
CC=* | --CC=*) CC="$optarg";;
|
||||||
CXX=* | --CXX=*) CXX="$optarg";;
|
CXX=* | --CXX=*) CXX="$optarg";;
|
||||||
CFLAGS=* | --CFLAGS=*) CFLAGS="$optarg";;
|
CFLAGS=* | --CFLAGS=*) CFLAGS="$optarg";;
|
||||||
@@ -1888,6 +1894,20 @@ EOL
|
|||||||
CFLAGS="$OSX_SYSROOT $CFLAGS"
|
CFLAGS="$OSX_SYSROOT $CFLAGS"
|
||||||
LDFLAGS="$OSX_LD_SYSROOT $LDFLAGS"
|
LDFLAGS="$OSX_LD_SYSROOT $LDFLAGS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$with_self_lldb_debug" = "0" ]; then
|
||||||
|
log 1 "using dbg lldb... no"
|
||||||
|
CFLAGS="$CFLAGS -DWITHOUT_DBG_LLDB"
|
||||||
|
else
|
||||||
|
log 1 "using dbg lldb... yes"
|
||||||
|
if [ $enable_debug -lt 1 ]; then
|
||||||
|
if [ -n "`"$cc_host" --version | head -n1 | grep "clang" 2>/dev/null`" ]; then
|
||||||
|
CFLAGS="$CFLAGS -gline-tables-only"
|
||||||
|
else
|
||||||
|
CFLAGS="$CFLAGS -g1"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$os" = "HAIKU" ]; then
|
if [ "$os" = "HAIKU" ]; then
|
||||||
@@ -3826,6 +3846,7 @@ showhelp() {
|
|||||||
echo " --without-libbfd disable libbfd support, used for improved crash logs (MinGW and Unix/glibc only)"
|
echo " --without-libbfd disable libbfd support, used for improved crash logs (MinGW and Unix/glibc only)"
|
||||||
echo " --without-bfd-extra-debug disable extra debugging information when using libbfd (MinGW and Unix/glibc only)"
|
echo " --without-bfd-extra-debug disable extra debugging information when using libbfd (MinGW and Unix/glibc only)"
|
||||||
echo " --without-self-gdb-debug disable improved crash logs using gdb (Linux only)"
|
echo " --without-self-gdb-debug disable improved crash logs using gdb (Linux only)"
|
||||||
|
echo " --without-self-lldb-debug disable improved crash logs using lldb (OSX only)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Some influential environment variables:"
|
echo "Some influential environment variables:"
|
||||||
echo " CC C compiler command"
|
echo " CC C compiler command"
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
#include "../../string_func.h"
|
#include "../../string_func.h"
|
||||||
#include "../../gamelog.h"
|
#include "../../gamelog.h"
|
||||||
#include "../../saveload/saveload.h"
|
#include "../../saveload/saveload.h"
|
||||||
|
#include "../../thread.h"
|
||||||
#include "macos.h"
|
#include "macos.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -41,6 +42,62 @@
|
|||||||
|
|
||||||
#define MAX_STACK_FRAMES 64
|
#define MAX_STACK_FRAMES 64
|
||||||
|
|
||||||
|
#if !defined(WITHOUT_DBG_LLDB)
|
||||||
|
static bool ExecReadStdout(const char *file, char *const *args, char *&buffer, const char *last)
|
||||||
|
{
|
||||||
|
int pipefd[2];
|
||||||
|
if (pipe(pipefd) == -1) return false;
|
||||||
|
|
||||||
|
int pid = fork();
|
||||||
|
if (pid < 0) return false;
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
/* child */
|
||||||
|
|
||||||
|
close(pipefd[0]); /* Close unused read end */
|
||||||
|
dup2(pipefd[1], STDOUT_FILENO);
|
||||||
|
close(pipefd[1]);
|
||||||
|
int null_fd = open("/dev/null", O_RDWR);
|
||||||
|
if (null_fd != -1) {
|
||||||
|
dup2(null_fd, STDERR_FILENO);
|
||||||
|
dup2(null_fd, STDIN_FILENO);
|
||||||
|
}
|
||||||
|
|
||||||
|
execvp(file, args);
|
||||||
|
exit(42);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* parent */
|
||||||
|
|
||||||
|
close(pipefd[1]); /* Close unused write end */
|
||||||
|
|
||||||
|
while (buffer < last) {
|
||||||
|
ssize_t res = read(pipefd[0], buffer, last - buffer);
|
||||||
|
if (res < 0) {
|
||||||
|
if (errno == EINTR) continue;
|
||||||
|
break;
|
||||||
|
} else if (res == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
buffer += res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffer += seprintf(buffer, last, "\n");
|
||||||
|
|
||||||
|
close(pipefd[0]); /* close read end */
|
||||||
|
|
||||||
|
int status;
|
||||||
|
int wait_ret = waitpid(pid, &status, 0);
|
||||||
|
if (wait_ret == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
|
||||||
|
/* command did not appear to run successfully */
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
/* command executed successfully */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* !WITHOUT_DBG_LLDB */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OSX implementation for the crash logger.
|
* OSX implementation for the crash logger.
|
||||||
*/
|
*/
|
||||||
@@ -150,6 +207,57 @@ class CrashLogOSX : public CrashLog {
|
|||||||
return buffer + seprintf(buffer, last, "\n");
|
return buffer + seprintf(buffer, last, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a stack backtrace of the current thread's stack and other info using the gdb debugger, if available.
|
||||||
|
*
|
||||||
|
* Using LLDB is useful as it knows about inlined functions and locals, and generally can
|
||||||
|
* do a more thorough job than in LogStacktrace.
|
||||||
|
* This is done in addition to LogStacktrace as lldb cannot be assumed to be present
|
||||||
|
* and there is some potentially useful information in the output from LogStacktrace
|
||||||
|
* which is not in lldb's output.
|
||||||
|
*/
|
||||||
|
char *LogLldbInfo(char *buffer, const char *last) const
|
||||||
|
{
|
||||||
|
|
||||||
|
#if !defined(WITHOUT_DBG_LLDB)
|
||||||
|
pid_t pid = getpid();
|
||||||
|
|
||||||
|
char *buffer_orig = buffer;
|
||||||
|
buffer += seprintf(buffer, last, "LLDB info:\n");
|
||||||
|
|
||||||
|
char pid_buffer[16];
|
||||||
|
|
||||||
|
seprintf(pid_buffer, lastof(pid_buffer), "%d", pid);
|
||||||
|
|
||||||
|
std::vector<const char *> args;
|
||||||
|
args.push_back("lldb");
|
||||||
|
args.push_back("-x");
|
||||||
|
args.push_back("-p");
|
||||||
|
args.push_back(pid_buffer);
|
||||||
|
args.push_back("--batch");
|
||||||
|
|
||||||
|
args.push_back("-o");
|
||||||
|
args.push_back(IsNonMainThread() ? "bt all" : "bt");
|
||||||
|
|
||||||
|
args.push_back(nullptr);
|
||||||
|
if (!ExecReadStdout("lldb", const_cast<char* const*>(&(args[0])), buffer, last)) {
|
||||||
|
buffer = buffer_orig;
|
||||||
|
}
|
||||||
|
#endif /* !WITHOUT_DBG_LLDB */
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log LLDB information if available
|
||||||
|
*/
|
||||||
|
char *LogRegisters(char *buffer, const char *last) const override
|
||||||
|
{
|
||||||
|
buffer = LogLldbInfo(buffer, last);
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* A crash log is always generated by signal.
|
* A crash log is always generated by signal.
|
||||||
|
Reference in New Issue
Block a user