MySQL 8.0.39
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*/
47#if defined(HAVE_BACKTRACE) || defined(_WIN32)
48#define HAVE_STACKTRACE 1
50void my_print_stacktrace(const uchar *stack_bottom, ulong thread_stack);
51void my_safe_puts_stderr(const char *val, size_t max_len);
52
53#ifdef _WIN32
54void my_set_exception_pointers(EXCEPTION_POINTERS *ep);
55void my_create_minidump(const char *name, HANDLE process, DWORD pid);
56#endif
57#endif /* HAVE_BACKTRACE || _WIN32 */
58
59void my_write_core(int sig);
60
61/**
62 Async-signal-safe utility functions used by signal handler routines.
63 Declared here in order to unit-test them.
64 These are not general-purpose, but tailored to the signal handling routines.
65*/
66/**
67 Converts a longlong value to string.
68 @param base 10 for decimal, 16 for hex values (0..9a..f)
69 @param val The value to convert
70 @param buf Assumed to point to the *end* of the buffer.
71 @returns Pointer to the first character of the converted string.
72 Negative values:
73 for base-10 the return string will be prepended with '-'
74 for base-16 the return string will contain 16 characters
75 Implemented with simplicity, and async-signal-safety in mind.
76*/
77char *my_safe_itoa(int base, longlong val, char *buf);
78
79/**
80 Converts a ulonglong value to string.
81 @param base 10 for decimal, 16 for hex values (0..9a..f)
82 @param val The value to convert
83 @param buf Assumed to point to the *end* of the buffer.
84 @returns Pointer to the first character of the converted string.
85 Implemented with simplicity, and async-signal-safety in mind.
86*/
87char *my_safe_utoa(int base, ulonglong val, char *buf);
88
89/**
90 A (very) limited version of snprintf.
91 @param to Destination buffer.
92 @param n Size of destination buffer.
93 @param fmt printf() style format string.
94 @returns Number of bytes written, including terminating '\0'
95 Supports 'd' 'i' 'u' 'x' 'p' 's' conversion.
96 Supports 'l' and 'll' modifiers for integral types.
97 Does not support any width/precision.
98 Implemented with simplicity, and async-signal-safety in mind.
99*/
100size_t my_safe_snprintf(char *to, size_t n, const char *fmt, ...)
101 MY_ATTRIBUTE((format(printf, 3, 4)));
102
103/**
104 A (very) limited version of snprintf, which writes the result to STDERR.
105 @sa my_safe_snprintf
106 Implemented with simplicity, and async-signal-safety in mind.
107 @note Has an internal buffer capacity of 512 bytes,
108 which should suffice for our signal handling routines.
109*/
110size_t my_safe_printf_stderr(const char *fmt, ...)
111 MY_ATTRIBUTE((format(printf, 1, 2)));
112
113/**
114 Writes up to count bytes from buffer to STDERR.
115 Implemented with simplicity, and async-signal-safety in mind.
116 @param buf Buffer containing data to be written.
117 @param count Number of bytes to write.
118 @returns Number of bytes written.
119*/
120size_t my_write_stderr(const void *buf, size_t count);
121
122/**
123 Writes system time to STDERR without allocating new memory.
124*/
126
127#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:767
void my_safe_puts_stderr(const char *val, size_t max_len)
Definition: stacktrace.cc:174
size_t my_safe_printf_stderr(const char *fmt,...)
A (very) limited version of snprintf, which writes the result to STDERR.
Definition: stacktrace.cc:776
void my_print_stacktrace(const uchar *stack_bottom, ulong thread_stack)
Definition: stacktrace.cc:253
size_t my_write_stderr(const void *buf, size_t count)
Writes up to count bytes from buffer to STDERR.
Definition: stacktrace.cc:593
void my_safe_print_system_time()
Writes system time to STDERR without allocating new memory.
Definition: stacktrace.cc:787
char * my_safe_utoa(int base, ulonglong val, char *buf)
Converts a ulonglong value to string.
Definition: stacktrace.cc:600
char * my_safe_itoa(int base, longlong val, char *buf)
Async-signal-safe utility functions used by signal handler routines.
Definition: stacktrace.cc:608
void my_init_stacktrace()
Definition: stacktrace.cc:93
void my_write_core(int sig)
Definition: stacktrace.cc:294
static int count
Definition: myisam_ftdump.cc:43
Definition: buf0block_hint.cc:30
case opt name
Definition: sslopt-case.h:33
#define HANDLE
Definition: violite.h:159
int n
Definition: xcom_base.cc:509