1 /* Common definitions. 2 3 Copyright (C) 1986-2020 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20 #ifndef COMMON_COMMON_DEFS_H 21 #define COMMON_COMMON_DEFS_H 22 23 #include <gdbsupport/config.h> 24 25 #undef PACKAGE_NAME 26 #undef PACKAGE 27 #undef PACKAGE_VERSION 28 #undef PACKAGE_STRING 29 #undef PACKAGE_TARNAME 30 31 #include "gnulib/config.h" 32 33 /* From: 34 https://www.gnu.org/software/gnulib/manual/html_node/stdint_002eh.html 35 36 "On some hosts that predate C++11, when using C++ one must define 37 __STDC_CONSTANT_MACROS to make visible the definitions of constant 38 macros such as INTMAX_C, and one must define __STDC_LIMIT_MACROS to 39 make visible the definitions of limit macros such as INTMAX_MAX.". 40 41 And: 42 https://www.gnu.org/software/gnulib/manual/html_node/inttypes_002eh.html 43 44 "On some hosts that predate C++11, when using C++ one must define 45 __STDC_FORMAT_MACROS to make visible the declarations of format 46 macros such as PRIdMAX." 47 48 Must do this before including any system header, since other system 49 headers may include stdint.h/inttypes.h. */ 50 #define __STDC_CONSTANT_MACROS 1 51 #define __STDC_LIMIT_MACROS 1 52 #define __STDC_FORMAT_MACROS 1 53 54 /* Some distros enable _FORTIFY_SOURCE by default, which on occasion 55 has caused build failures with -Wunused-result when a patch is 56 developed on a distro that does not enable _FORTIFY_SOURCE. We 57 enable it here in order to try to catch these problems earlier; 58 plus this seems like a reasonable safety measure. The check for 59 optimization is required because _FORTIFY_SOURCE only works when 60 optimization is enabled. If _FORTIFY_SOURCE is already defined, 61 then we don't do anything. Also, on MinGW, fortify requires 62 linking to -lssp, and to avoid the hassle of checking for 63 that and linking to it statically, we just don't define 64 _FORTIFY_SOURCE there. */ 65 66 #if (!defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__ > 0 \ 67 && !defined(__MINGW32__)) 68 #define _FORTIFY_SOURCE 2 69 #endif 70 71 /* We don't support Windows versions before XP, so we define 72 _WIN32_WINNT correspondingly to ensure the Windows API headers 73 expose the required symbols. */ 74 #if defined (__MINGW32__) || defined (__CYGWIN__) 75 # ifdef _WIN32_WINNT 76 # if _WIN32_WINNT < 0x0501 77 # undef _WIN32_WINNT 78 # define _WIN32_WINNT 0x0501 79 # endif 80 # else 81 # define _WIN32_WINNT 0x0501 82 # endif 83 #endif /* __MINGW32__ || __CYGWIN__ */ 84 85 #include <stdarg.h> 86 #include <stdio.h> 87 88 /* Include both cstdlib and stdlib.h to ensure we have standard functions 89 defined both in the std:: namespace and in the global namespace. */ 90 #include <cstdlib> 91 #include <stdlib.h> 92 93 #include <stddef.h> 94 #include <stdint.h> 95 #include <string.h> 96 #ifdef HAVE_STRINGS_H 97 #include <strings.h> /* for strcasecmp and strncasecmp */ 98 #endif 99 #include <errno.h> 100 #if HAVE_ALLOCA_H 101 #include <alloca.h> 102 #endif 103 104 #include "ansidecl.h" 105 /* This is defined by ansidecl.h, but we prefer gnulib's version. On 106 MinGW, gnulib might enable __USE_MINGW_ANSI_STDIO, which may or not 107 require use of attribute gnu_printf instead of printf. gnulib 108 checks that at configure time. Since _GL_ATTRIBUTE_FORMAT_PRINTF 109 is compatible with ATTRIBUTE_PRINTF, simply use it. */ 110 #undef ATTRIBUTE_PRINTF 111 #define ATTRIBUTE_PRINTF _GL_ATTRIBUTE_FORMAT_PRINTF 112 113 #if GCC_VERSION >= 3004 114 #define ATTRIBUTE_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) 115 #else 116 #define ATTRIBUTE_UNUSED_RESULT 117 #endif 118 119 #include "libiberty.h" 120 #include "pathmax.h" 121 #include "gdb/signals.h" 122 #include "gdb_locale.h" 123 #include "ptid.h" 124 #include "common-types.h" 125 #include "common-utils.h" 126 #include "gdb_assert.h" 127 #include "errors.h" 128 #include "print-utils.h" 129 #include "common-debug.h" 130 #include "cleanups.h" 131 #include "common-exceptions.h" 132 #include "gdbsupport/poison.h" 133 134 #define EXTERN_C extern "C" 135 #define EXTERN_C_PUSH extern "C" { 136 #define EXTERN_C_POP } 137 138 /* Pull in gdb::unique_xmalloc_ptr. */ 139 #include "gdbsupport/gdb_unique_ptr.h" 140 141 /* String containing the current directory (what getwd would return). */ 142 extern char *current_directory; 143 144 /* sbrk on macOS is not useful for our purposes, since sbrk(0) always 145 returns the same value. brk/sbrk on macOS is just an emulation 146 that always returns a pointer to a 4MB section reserved for 147 that. */ 148 149 #if defined (HAVE_SBRK) && !__APPLE__ 150 #define HAVE_USEFUL_SBRK 1 151 #endif 152 153 #endif /* COMMON_COMMON_DEFS_H */ 154