MySQL  8.0.16
Source Code Documentation
my_stacktrace.h
Go to the documentation of this file.
1 /* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
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_h_
24 #define _my_stacktrace_h_
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
44  HAVE_PRINTSTACK - Solaris
45  _WIN32 - Windows
46 */
47 #if defined(HAVE_BACKTRACE) || defined(HAVE_PRINTSTACK) || defined(_WIN32)
48 #define HAVE_STACKTRACE 1
49 void my_init_stacktrace();
50 void my_print_stacktrace(uchar *stack_bottom, ulong thread_stack);
51 void my_safe_puts_stderr(const char *val, size_t max_len);
52 
53 #ifdef _WIN32
54 void my_set_exception_pointers(EXCEPTION_POINTERS *ep);
55 void my_create_minidump(const char *name, HANDLE process, DWORD pid);
56 #endif
57 #endif /* HAVE_BACKTRACE || HAVE_PRINTSTACK || _WIN32 */
58 
59 void 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 */
77 char *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 */
87 char *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 */
100 size_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 */
110 size_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 */
120 size_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_h_ */
Some common macros.
unsigned long long int ulonglong
Definition: my_inttypes.h:69
unsigned char uchar
Definition: my_inttypes.h:49
size_t my_safe_printf_stderr(const char *fmt,...)
A (very) limited version of snprintf, which writes the result to STDERR.
Definition: stacktrace.cc:746
char * my_safe_utoa(int base, ulonglong val, char *buf)
Converts a ulonglong value to string.
Definition: stacktrace.cc:570
ssize_t count
Definition: memcached.c:386
const string name("\ame\)
Some integer typedefs for easier portability.
printf("== done ==\)
void process(inf) FILE *inf
#define HANDLE
Definition: violite.h:156
size_t my_safe_snprintf(char *to, size_t n, const char *fmt,...)
A (very) limited version of snprintf.
Definition: stacktrace.cc:737
Header for compiler-dependent features.
long long int longlong
Definition: my_inttypes.h:70
void my_safe_print_system_time()
Writes system time to STDERR without allocating new memory.
Definition: stacktrace.cc:757
size_t my_write_stderr(const void *buf, size_t count)
Writes up to count bytes from buffer to STDERR.
Definition: stacktrace.cc:563
char * my_safe_itoa(int base, longlong val, char *buf)
Async-signal-safe utility functions used by signal handler routines.
Definition: stacktrace.cc:578
void my_write_core(int sig)
Definition: stacktrace.cc:282
unsigned long ulong
Definition: my_inttypes.h:46