#include "base/debug/stack_trace.h"
#include <stddef.h>
#include <limits>
#include <sstream>
#include <string>
#include "base/allocator/buildflags.h"
#include "base/containers/span.h"
#include "base/debug/debugging_buildflags.h"
#include "base/immediate_crash.h"
#include "base/logging.h"
#include "base/process/kill.h"
#include "base/process/process_handle.h"
#include "base/profiler/stack_buffer.h"
#include "base/profiler/stack_copier.h"
#include "base/strings/cstring_view.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "partition_alloc/partition_alloc.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
#include "partition_alloc/shim/allocator_shim.h"
#endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
#include "base/test/multiprocess_test.h"
#endif
namespace base {
namespace debug {
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
StackTraceTest;
#else
typedef testing::Test StackTraceTest;
#endif
StackTraceDeathTest;
#if !defined(__UCLIBC__) && !defined(_AIX)
TEST_F(StackTraceTest, OutputToStream) { … }
#if !defined(OFFICIAL_BUILD) && !defined(NO_UNWIND_TABLES)
TEST_F(StackTraceTest, TruncatedTrace) { … }
#endif
TEST_F(StackTraceTest, DebugOutputToStream) { … }
TEST_F(StackTraceTest, DebugPrintBacktrace) { … }
TEST_F(StackTraceTest, DebugPrintWithPrefixBacktrace) { … }
TEST_F(StackTraceTest, DebugPrintWithNullPrefixBacktrace) { … }
TEST_F(StackTraceTest, DebugOutputToStreamWithPrefix) { … }
TEST_F(StackTraceTest, DebugOutputToStreamWithNullPrefix) { … }
#endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM) && !BUILDFLAG(IS_MAC)
namespace {
void* BadMalloc(size_t, void*) { … }
void* BadCalloc(size_t, size_t, void* context) { … }
void* BadAlignedAlloc(size_t, size_t, void*) { … }
void* BadAlignedRealloc(void*, size_t, size_t, void*) { … }
void* BadRealloc(void*, size_t, void*) { … }
void BadFree(void*, void*) { … }
allocator_shim::AllocatorDispatch g_bad_malloc_dispatch = …;
}
TEST_F(StackTraceDeathTest, StackDumpSignalHandlerIsMallocFree) { … }
#endif
namespace {
std::string itoa_r_wrapper(intptr_t i, size_t sz, int base, size_t padding) { … }
}
TEST_F(StackTraceTest, itoa_r) { … }
#endif
#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
class CopyFunction : public StackCopier { … };
template <size_t Depth>
NOINLINE NOOPT void ExpectStackFramePointers(span<const void*> frames) { … }
template <>
NOINLINE NOOPT void ExpectStackFramePointers<1>(span<const void*> frames) { … }
#if defined(MEMORY_SANITIZER)
#define MAYBE_TraceStackFramePointers …
#else
#define MAYBE_TraceStackFramePointers …
#endif
TEST_F(StackTraceTest, MAYBE_TraceStackFramePointers) { … }
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_APPLE)
#define MAYBE_StackEnd …
#else
#define MAYBE_StackEnd …
#endif
TEST_F(StackTraceTest, MAYBE_StackEnd) { … }
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
#if !defined(ADDRESS_SANITIZER) && !defined(UNDEFINED_SANITIZER)
#if !defined(ARCH_CPU_ARM_FAMILY)
TEST(CheckExitCodeAfterSignalHandlerDeathTest, CheckSIGFPE) { … }
#endif
TEST(CheckExitCodeAfterSignalHandlerDeathTest, CheckSIGSEGV) { … }
#if defined(ARCH_CPU_X86_64)
TEST(CheckExitCodeAfterSignalHandlerDeathTest,
CheckSIGSEGVNonCanonicalAddress) { … }
#endif
#endif
TEST(CheckExitCodeAfterSignalHandlerDeathTest, CheckSIGILL) { … }
#endif
}
}