MySQL 8.0.30
Source Code Documentation
my_stacktrace.h
Go to the documentation of this file.
1/* Copyright (c) 2001, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MY_STACKTRACE_INCLUDED
24#define MY_STACKTRACE_INCLUDED
25
26/**
27 @file include/my_stacktrace.h
28*/
29
30#include <stddef.h>
31#include <sys/types.h>
32
33#ifdef _WIN32
34#include <windows.h>
35#endif
36
37#include "my_compiler.h"
38#include "my_config.h"
39#include "my_inttypes.h"
40#include "my_macros.h"
41
42/*
43 HAVE_BACKTRACE - Linux, FreeBSD, OSX, Solaris
44 _WIN32 - Windows
45*/
46#if defined(HAVE_BACKTRACE) || defined(_WIN32)
47#define HAVE_STACKTRACE 1
49void my_print_stacktrace(const uchar *stack_bottom, ulong thread_stack);
50void my_safe_puts_stderr(const char *val, size_t max_len);
51
52#ifdef _WIN32
53void my_set_exception_pointers(EXCEPTION_POINTERS *ep);
54void my_create_minidump(const char *name, HANDLE process, DWORD pid);
55#endif
56#endif /* HAVE_BACKTRACE || _WIN32 */
57
58void my_write_core(int sig);
59
60/**
61 Async-signal-safe utility functions used by signal handler routines.
62 Declared here in order to unit-test them.
63 These are not general-purpose, but tailored to the signal handling routines.
64*/
65/**
66 Converts a longlong value to string.
67 @param base 10 for decimal, 16 for hex values (0..9a..f)
68 @param val The value to convert
69 @param buf Assumed to point to the *end* of the buffer.
70 @returns Pointer to the first character of the converted string.
71 Negative values:
72 for base-10 the return string will be prepended with '-'
73 for base-16 the return string will contain 16 characters
74 Implemented with simplicity, and async-signal-safety in mind.
75*/
76char *my_safe_itoa(int base, longlong val, char *buf);
77
78/**
79 Converts a ulonglong value to string.
80 @param base 10 for decimal, 16 for hex values (0..9a..f)
81 @param val The value to convert
82 @param buf Assumed to point to the *end* of the buffer.
83 @returns Pointer to the first character of the converted string.
84 Implemented with simplicity, and async-signal-safety in mind.
85*/
86char *my_safe_utoa(int base, ulonglong val, char *buf);
87
88/**
89 A (very) limited version of snprintf.
90 @param to Destination buffer.
91 @param n Size of destination buffer.
92 @param fmt printf() style format string.
93 @returns Number of bytes written, including terminating '\0'
94 Supports 'd' 'i' 'u' 'x' 'p' 's' conversion.
95 Supports 'l' and 'll' modifiers for integral types.
96 Does not support any width/precision.
97 Implemented with simplicity, and async-signal-safety in mind.
98*/
99size_t my_safe_snprintf(char *to, size_t n, const char *fmt, ...)
100 MY_ATTRIBUTE((format(printf, 3, 4)));
101
102/**
103 A (very) limited version of snprintf, which writes the result to STDERR.
104 @sa my_safe_snprintf
105 Implemented with simplicity, and async-signal-safety in mind.
106 @note Has an internal buffer capacity of 512 bytes,
107 which should suffice for our signal handling routines.
108*/
109size_t my_safe_printf_stderr(const char *fmt, ...)
110 MY_ATTRIBUTE((format(printf, 1, 2)));
111
112/**
113 Writes up to count bytes from buffer to STDERR.
114 Implemented with simplicity, and async-signal-safety in mind.
115 @param buf Buffer containing data to be written.
116 @param count Number of bytes to write.
117 @returns Number of bytes written.
118*/
119size_t my_write_stderr(const void *buf, size_t count);
120
121/**
122 Writes system time to STDERR without allocating new memory.
123*/
125
126#endif // MY_STACKTRACE_INCLUDED
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
long long int longlong
Definition: my_inttypes.h:54
Some common macros.
size_t my_safe_snprintf(char *to, size_t n, const char *fmt,...)
A (very) limited version of snprintf.
Definition: stacktrace.cc:760
void my_safe_puts_stderr(const char *val, size_t max_len)
Definition: stacktrace.cc:173
size_t my_safe_printf_stderr(const char *fmt,...)
A (very) limited version of snprintf, which writes the result to STDERR.
Definition: stacktrace.cc:769
void my_print_stacktrace(const uchar *stack_bottom, ulong thread_stack)
Definition: stacktrace.cc:252
size_t my_write_stderr(const void *buf, size_t count)
Writes up to count bytes from buffer to STDERR.
Definition: stacktrace.cc:586
void my_safe_print_system_time()
Writes system time to STDERR without allocating new memory.
Definition: stacktrace.cc:780
char * my_safe_utoa(int base, ulonglong val, char *buf)
Converts a ulonglong value to string.
Definition: stacktrace.cc:593
char * my_safe_itoa(int base, longlong val, char *buf)
Async-signal-safe utility functions used by signal handler routines.
Definition: stacktrace.cc:601
void my_init_stacktrace()
Definition: stacktrace.cc:92
void my_write_core(int sig)
Definition: stacktrace.cc:293
static int count
Definition: myisam_ftdump.cc:42
Definition: buf0block_hint.cc:29
case opt name
Definition: sslopt-case.h:32
#define HANDLE
Definition: violite.h:157
int n
Definition: xcom_base.cc:505