MySQL 8.4.2
Source Code Documentation
stacktrace.cc File Reference
#include "my_config.h"
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <cstdint>
#include <string_view>
#include <time.h>
#include <algorithm>
#include <cinttypes>
#include "my_inttypes.h"
#include "my_macros.h"
#include "my_stacktrace.h"
#include "template_utils.h"
#include <signal.h>
#include "my_thread.h"
#include <unistd.h>
#include <execinfo.h>
#include <cxxabi.h>

Functions

static bool ptr_sane (const char *p, const char *heap_end)
 
void my_init_stacktrace ()
 
void my_safe_puts_stderr (const char *val, size_t max_len)
 
static char * my_demangle (const char *mangled_name, int *status)
 
static bool my_demangle_symbol (char *line)
 
static void my_demangle_symbols (char **addrs, int n)
 
void my_print_stacktrace (const uchar *stack_bottom, ulong thread_stack)
 
void my_write_core (int sig)
 
size_t my_write_stderr (const void *buf, size_t count)
 Writes up to count bytes from buffer to STDERR. More...
 
char * my_safe_utoa (int base, ulonglong val, char *buf)
 Converts a ulonglong value to string. More...
 
char * my_safe_itoa (int base, longlong val, char *buf)
 Async-signal-safe utility functions used by signal handler routines. More...
 
static const char * check_longlong (const char *fmt, bool *have_longlong)
 
static size_t my_safe_vsnprintf (char *to, size_t size, const char *format, va_list ap)
 
size_t my_safe_snprintf (char *to, size_t n, const char *fmt,...)
 A (very) limited version of snprintf. More...
 
size_t my_safe_printf_stderr (const char *fmt,...)
 A (very) limited version of snprintf, which writes the result to STDERR. More...
 
void my_safe_print_system_time ()
 Writes system time to STDERR without allocating new memory. More...
 

Variables

static const char digits [] = "0123456789abcdef"
 

Function Documentation

◆ check_longlong()

static const char * check_longlong ( const char *  fmt,
bool *  have_longlong 
)
static

◆ my_demangle()

static char * my_demangle ( const char *  mangled_name,
int *  status 
)
static

◆ my_demangle_symbol()

static bool my_demangle_symbol ( char *  line)
static

◆ my_demangle_symbols()

static void my_demangle_symbols ( char **  addrs,
int  n 
)
static

◆ my_init_stacktrace()

void my_init_stacktrace ( )

◆ my_print_stacktrace()

void my_print_stacktrace ( const uchar stack_bottom,
ulong  thread_stack 
)

◆ my_safe_itoa()

char * my_safe_itoa ( int  base,
longlong  val,
char *  buf 
)

Async-signal-safe utility functions used by signal handler routines.

Declared here in order to unit-test them. These are not general-purpose, but tailored to the signal handling routines. Converts a longlong value to string.

Parameters
base10 for decimal, 16 for hex values (0..9a..f)
valThe value to convert
bufAssumed to point to the end of the buffer.
Returns
Pointer to the first character of the converted string. Negative values: for base-10 the return string will be prepended with '-' for base-16 the return string will contain 16 characters Implemented with simplicity, and async-signal-safety in mind.

◆ my_safe_print_system_time()

void my_safe_print_system_time ( )

Writes system time to STDERR without allocating new memory.

◆ my_safe_printf_stderr()

size_t my_safe_printf_stderr ( const char *  fmt,
  ... 
)

A (very) limited version of snprintf, which writes the result to STDERR.

See also
my_safe_snprintf Implemented with simplicity, and async-signal-safety in mind.
Note
Has an internal buffer capacity of 512 bytes, which should suffice for our signal handling routines.

◆ my_safe_puts_stderr()

void my_safe_puts_stderr ( const char *  val,
size_t  max_len 
)

◆ my_safe_snprintf()

size_t my_safe_snprintf ( char *  to,
size_t  n,
const char *  fmt,
  ... 
)

A (very) limited version of snprintf.

Parameters
toDestination buffer.
nSize of destination buffer.
fmtprintf() style format string.
Returns
Number of bytes written, including terminating '\0' Supports 'd' 'i' 'u' 'x' 'p' 's' conversion. Supports 'l' and 'll' modifiers for integral types. Does not support any width/precision. Implemented with simplicity, and async-signal-safety in mind.

◆ my_safe_utoa()

char * my_safe_utoa ( int  base,
ulonglong  val,
char *  buf 
)

Converts a ulonglong value to string.

Parameters
base10 for decimal, 16 for hex values (0..9a..f)
valThe value to convert
bufAssumed to point to the end of the buffer.
Returns
Pointer to the first character of the converted string. Implemented with simplicity, and async-signal-safety in mind.

◆ my_safe_vsnprintf()

static size_t my_safe_vsnprintf ( char *  to,
size_t  size,
const char *  format,
va_list  ap 
)
static

◆ my_write_core()

void my_write_core ( int  sig)

◆ my_write_stderr()

size_t my_write_stderr ( const void *  buf,
size_t  count 
)

Writes up to count bytes from buffer to STDERR.

Implemented with simplicity, and async-signal-safety in mind.

Parameters
bufBuffer containing data to be written.
countNumber of bytes to write.
Returns
Number of bytes written.

◆ ptr_sane()

static bool ptr_sane ( const char *  p,
const char *  heap_end 
)
inlinestatic

Variable Documentation

◆ digits

const char digits[] = "0123456789abcdef"
static