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