#include "util/test_utils.h"
#include "common/FixedVector.h"
#include "common/angleutils.h"
#include "common/string_utils.h"
#include "common/system_utils.h"
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <iostream>
#if !defined(ANGLE_PLATFORM_ANDROID) && !defined(ANGLE_PLATFORM_FUCHSIA)
# if defined(ANGLE_PLATFORM_APPLE)
#define UNW_LOCAL_ONLY
# include <cxxabi.h>
# include <libunwind.h>
# include <signal.h>
# elif defined(ANGLE_PLATFORM_POSIX)
# include <cxxabi.h>
# include <dlfcn.h>
# include <execinfo.h>
# include <libgen.h>
# include <link.h>
# include <signal.h>
# include <string.h>
# endif
#endif
#if defined(NDEBUG)
#define HANDLE_EINTR …
#else
#define HANDLE_EINTR(x) …
#endif
namespace angle
{
#if defined(ANGLE_PLATFORM_ANDROID) || defined(ANGLE_PLATFORM_FUCHSIA)
void PrintStackBacktrace()
{
}
void InitCrashHandler(CrashCallback *callback)
{
}
void TerminateCrashHandler()
{
}
#else
namespace
{
CrashCallback *gCrashHandlerCallback;
}
# if defined(ANGLE_PLATFORM_APPLE)
void PrintStackBacktrace()
{
printf("Backtrace:\n");
unw_context_t context;
unw_getcontext(&context);
unw_cursor_t cursor;
unw_init_local(&cursor, &context);
while (unw_step(&cursor) > 0)
{
static const size_t kMax = 256;
char mangled[kMax];
unw_word_t offset;
unw_get_proc_name(&cursor, mangled, kMax, &offset);
int ok = -1;
char *demangled = abi::__cxa_demangle(mangled, nullptr, nullptr, &ok);
printf(" %s (+0x%zx)\n", ok == 0 ? demangled : mangled, (size_t)offset);
if (ok)
{
free(demangled);
}
}
printf("\n");
}
static void Handler(int sig)
{
printf("\nSignal %d:\n", sig);
if (gCrashHandlerCallback)
{
(*gCrashHandlerCallback)();
}
PrintStackBacktrace();
_Exit(sig);
}
# elif defined(ANGLE_PLATFORM_POSIX)
#define ANGLE_HAS_ADDR2LINE
# if defined(ANGLE_HAS_ADDR2LINE)
namespace
{
struct MappedMemoryRegion
{ … };
MemoryRegionArray;
bool ReadProcMaps(std::string *proc_maps)
{ … }
bool ParseProcMaps(const std::string &input, MemoryRegionArray *regions_out)
{ … }
void SetBaseAddressesForMemoryRegions(MemoryRegionArray ®ions)
{ … }
bool CacheMemoryRegions(MemoryRegionArray ®ions)
{ … }
constexpr size_t kAddr2LineMaxParameters = …;
Addr2LineCommandLine;
void CallAddr2Line(const Addr2LineCommandLine &commandLine)
{ … }
constexpr size_t kMaxAddressLen = …;
AddressBuffer;
const char *ResolveAddress(const MemoryRegionArray ®ions,
const std::string &resolvedModule,
const char *address,
AddressBuffer &buffer)
{ … }
std::string RemoveOverlappingPath(const std::string &resolvedModule)
{ … }
}
# endif
void PrintStackBacktrace()
{ … }
static void Handler(int sig)
{ … }
# endif
static constexpr int kSignals[] = …;
void InitCrashHandler(CrashCallback *callback)
{ … }
void TerminateCrashHandler()
{ … }
#endif
}