MySQL 8.3.0
Source Code Documentation
my_stacktrace.h
Go to the documentation of this file.
1/* Copyright (c) 2001, 2023, 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 HAVE_EXT_BACKTRACE - Unixes without backtrace(3)
46*/
47#if defined(HAVE_BACKTRACE) || defined(_WIN32) || defined(HAVE_EXT_BACKTRACE)
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 || HAVE_EXT_BACKTRACE */
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: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:812
void my_safe_puts_stderr(const char *val, size_t max_len)
Definition: stacktrace.cc:178
size_t my_safe_printf_stderr(const char *fmt,...)
A (very) limited version of snprintf, which writes the result to STDERR.
Definition: stacktrace.cc:821
void my_print_stacktrace(const uchar *stack_bottom, ulong thread_stack)
Definition: stacktrace.cc:298
size_t my_write_stderr(const void *buf, size_t count)
Writes up to count bytes from buffer to STDERR.
Definition: stacktrace.cc:638
void my_safe_print_system_time()
Writes system time to STDERR without allocating new memory.
Definition: stacktrace.cc:832
char * my_safe_utoa(int base, ulonglong val, char *buf)
Converts a ulonglong value to string.
Definition: stacktrace.cc:645
char * my_safe_itoa(int base, longlong val, char *buf)
Async-signal-safe utility functions used by signal handler routines.
Definition: stacktrace.cc:653
void my_init_stacktrace()
Definition: stacktrace.cc:97
void my_write_core(int sig)
Definition: stacktrace.cc:337
static int count
Definition: myisam_ftdump.cc:44
Definition: buf0block_hint.cc:29
case opt name
Definition: sslopt-case.h:32
#define HANDLE
Definition: violite.h:158
int n
Definition: xcom_base.cc:508