Path: blob/main/contrib/llvm-project/compiler-rt/lib/memprof/memprof_stack.h
35236 views
//===-- memprof_stack.h ----------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of MemProfiler, a memory profiler.9//10// MemProf-private header for memprof_stack.cpp.11//===----------------------------------------------------------------------===//1213#ifndef MEMPROF_STACK_H14#define MEMPROF_STACK_H1516#include "memprof_flags.h"17#include "memprof_thread.h"18#include "sanitizer_common/sanitizer_flags.h"19#include "sanitizer_common/sanitizer_stacktrace.h"2021namespace __memprof {2223static const u32 kDefaultMallocContextSize = 30;2425void SetMallocContextSize(u32 size);26u32 GetMallocContextSize();2728} // namespace __memprof2930// NOTE: A Rule of thumb is to retrieve stack trace in the interceptors31// as early as possible (in functions exposed to the user), as we generally32// don't want stack trace to contain functions from MemProf internals.3334#define GET_STACK_TRACE(max_size, fast) \35BufferedStackTrace stack; \36if (max_size <= 2) { \37stack.size = max_size; \38if (max_size > 0) { \39stack.top_frame_bp = GET_CURRENT_FRAME(); \40stack.trace_buffer[0] = StackTrace::GetCurrentPc(); \41if (max_size > 1) \42stack.trace_buffer[1] = GET_CALLER_PC(); \43} \44} else { \45stack.Unwind(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), nullptr, \46fast, max_size); \47}4849#define GET_STACK_TRACE_FATAL_HERE \50GET_STACK_TRACE(kStackTraceMax, common_flags()->fast_unwind_on_fatal)5152#define GET_STACK_TRACE_THREAD GET_STACK_TRACE(kStackTraceMax, true)5354#define GET_STACK_TRACE_MALLOC \55GET_STACK_TRACE(GetMallocContextSize(), common_flags()->fast_unwind_on_malloc)5657#define GET_STACK_TRACE_FREE GET_STACK_TRACE_MALLOC5859#define PRINT_CURRENT_STACK() \60{ \61GET_STACK_TRACE_FATAL_HERE; \62stack.Print(); \63}6465#endif // MEMPROF_STACK_H666768