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