2014-07-24 22:35:45 +08:00
|
|
|
/* Common definitions.
|
|
|
|
|
2015-01-01 17:32:14 +08:00
|
|
|
Copyright (C) 1986-2015 Free Software Foundation, Inc.
|
2014-07-24 22:35:45 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H
|
|
|
|
#define COMMON_DEFS_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#ifdef GDBSERVER
|
|
|
|
#include "build-gnulib-gdbserver/config.h"
|
|
|
|
#else
|
|
|
|
#include "build-gnulib/config.h"
|
|
|
|
#endif
|
|
|
|
|
common-defs.h: include <stdarg.h> before <stdio.h>
When trying to build gdbserver on ppc-lynx178, the compiler reports
while trying to compile gdbserver/ax.c that vsprintf is not declared.
Looking at my C99 reference manual (a draft), I see the following
synopsis:
#include <stdarg.h>
#include <stdio.h>
int vsprintf(char * restrict s, [etc]);
Looking at stdio.h on LynxOS-178, if found where vsprintf gets
declared:
#if defined(__varargs_h) || defined(__stdarg_h) \
|| defined(_VARARGS_H) || defined(_STDARG_H)
extern int vsprintf _AP((char *, const char *, va_list));
#endif
Digging further, I noticed that common-defs.h, which is included
via server.h, includes stdarg.h after including stdio, explaining
why vsprintf does not get declared in this case.
This patch fixes the problem by including stdarg.h before stdio.h.
gdb/ChangeLog:
* common/common-defs.h: Move <stdarg.h> #include ahead of
<stdio.h> #include.
Tested on x86_64-linux.
2014-10-07 02:50:46 +08:00
|
|
|
#include <stdarg.h>
|
2014-07-25 23:29:40 +08:00
|
|
|
#include <stdio.h>
|
2014-07-26 00:35:30 +08:00
|
|
|
#include <stdlib.h>
|
2014-07-28 20:15:41 +08:00
|
|
|
#include <stddef.h>
|
[C++] Define __STDC_CONSTANT_MACROS / __STDC_LIMIT_MACROS for stdint.h
With some toolchains, building in C++ mode stumbles on many instances
of:
In file included from ../../src/gdb/../include/splay-tree.h:43:0,
from ../../src/gdb/dcache.c:26:
build-gnulib/import/inttypes.h:61:3: error: #error "This file assumes that 'int' has exactly 32 bits. Please report your platform and compiler to <bug-gnulib@gnu.org>."
# error "This file assumes that 'int' has exactly 32 bits. Please report your platform and compiler to <bug-gnulib@gnu.org>."
^
make: *** [dcache.o] Error 1
That's:
#if !(INT_MIN == INT32_MIN && INT_MAX == INT32_MAX)
# error "This file assumes that 'int' has exactly 32 bits. Please report your platform and compiler to <bug-gnulib@gnu.org>."
#endif
I see it when cross building for --host=x86_64-w64-mingw32 using
Fedora 20's g++ (gcc version 4.8.4 20141219 (Fedora MinGW
4.8.4-1.fc20)), Simon reports seeing this on several cross compilers
too.
The issue is that on some hosts that predate C++11, when using C++ one
must define __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS to make visible
the definitions of INTMAX_C / INTMAX_MAX etc.
This was a C99 requirement that later C++11 -- the first to define
stdint.h -- removed, and then C11 removed it as well.
https://www.gnu.org/software/gnulib/manual/html_node/stdint_002eh.html
says that gnulib's stdint.h fixes this, but because we run gnulib's
configure tests with a C compiler, gnulib determines that mingw's
stdint.h is C99-compliant, and doesn't actually replace it. Actually,
even though configuring gnulib with a C++ compiler does result in
gnulib replacing stdint.h, the resulting replacement is broken for
mingw, because it defines uintptr_t incorrectly. I sent a gnulib
patch upstream to fix that, here:
https://lists.gnu.org/archive/html/bug-gnulib/2015-11/msg00004.html
but then even with that, gnulib still stumbles on other
configured-with-C++-compiler problems.
So for now, until gnulib + C++ is fixed upstream and then gdb's copy
is updated, which may take a while, I think it's best to keep
configuring gnulib in C, and define
__STDC_LIMIT_MACROS/__STDC_CONSTANT_MACROS ourselves, just like C99
intended.
gdb/ChangeLog:
2015-11-17 Pedro Alves <palves@redhat.com>
* common/common-defs.h (__STDC_CONSTANT_MACROS)
(__STDC_LIMIT_MACROS): Define before including stdint.h.
2015-11-17 23:17:45 +08:00
|
|
|
|
|
|
|
/* From:
|
|
|
|
https://www.gnu.org/software/gnulib/manual/html_node/stdint_002eh.html
|
|
|
|
|
|
|
|
"On some hosts that predate C++11, when using C++ one must define
|
|
|
|
__STDC_CONSTANT_MACROS to make visible the definitions of constant
|
|
|
|
macros such as INTMAX_C, and one must define __STDC_LIMIT_MACROS to
|
|
|
|
make visible the definitions of limit macros such as INTMAX_MAX."
|
|
|
|
|
|
|
|
gnulib doesn't fix this for us correctly yet. See:
|
|
|
|
https://lists.gnu.org/archive/html/bug-gnulib/2015-11/msg00004.html
|
|
|
|
|
|
|
|
Meanwhile, explicitly define these ourselves, as C99 intended. */
|
|
|
|
#define __STDC_CONSTANT_MACROS 1
|
|
|
|
#define __STDC_LIMIT_MACROS 1
|
2015-01-16 04:10:49 +08:00
|
|
|
#include <stdint.h>
|
[C++] Define __STDC_CONSTANT_MACROS / __STDC_LIMIT_MACROS for stdint.h
With some toolchains, building in C++ mode stumbles on many instances
of:
In file included from ../../src/gdb/../include/splay-tree.h:43:0,
from ../../src/gdb/dcache.c:26:
build-gnulib/import/inttypes.h:61:3: error: #error "This file assumes that 'int' has exactly 32 bits. Please report your platform and compiler to <bug-gnulib@gnu.org>."
# error "This file assumes that 'int' has exactly 32 bits. Please report your platform and compiler to <bug-gnulib@gnu.org>."
^
make: *** [dcache.o] Error 1
That's:
#if !(INT_MIN == INT32_MIN && INT_MAX == INT32_MAX)
# error "This file assumes that 'int' has exactly 32 bits. Please report your platform and compiler to <bug-gnulib@gnu.org>."
#endif
I see it when cross building for --host=x86_64-w64-mingw32 using
Fedora 20's g++ (gcc version 4.8.4 20141219 (Fedora MinGW
4.8.4-1.fc20)), Simon reports seeing this on several cross compilers
too.
The issue is that on some hosts that predate C++11, when using C++ one
must define __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS to make visible
the definitions of INTMAX_C / INTMAX_MAX etc.
This was a C99 requirement that later C++11 -- the first to define
stdint.h -- removed, and then C11 removed it as well.
https://www.gnu.org/software/gnulib/manual/html_node/stdint_002eh.html
says that gnulib's stdint.h fixes this, but because we run gnulib's
configure tests with a C compiler, gnulib determines that mingw's
stdint.h is C99-compliant, and doesn't actually replace it. Actually,
even though configuring gnulib with a C++ compiler does result in
gnulib replacing stdint.h, the resulting replacement is broken for
mingw, because it defines uintptr_t incorrectly. I sent a gnulib
patch upstream to fix that, here:
https://lists.gnu.org/archive/html/bug-gnulib/2015-11/msg00004.html
but then even with that, gnulib still stumbles on other
configured-with-C++-compiler problems.
So for now, until gnulib + C++ is fixed upstream and then gdb's copy
is updated, which may take a while, I think it's best to keep
configuring gnulib in C, and define
__STDC_LIMIT_MACROS/__STDC_CONSTANT_MACROS ourselves, just like C99
intended.
gdb/ChangeLog:
2015-11-17 Pedro Alves <palves@redhat.com>
* common/common-defs.h (__STDC_CONSTANT_MACROS)
(__STDC_LIMIT_MACROS): Define before including stdint.h.
2015-11-17 23:17:45 +08:00
|
|
|
|
2014-07-29 22:06:51 +08:00
|
|
|
#include <string.h>
|
2014-07-30 20:21:40 +08:00
|
|
|
#include <errno.h>
|
2014-11-21 22:05:41 +08:00
|
|
|
#include <alloca.h>
|
2014-07-28 19:03:31 +08:00
|
|
|
#include "ansidecl.h"
|
2014-07-28 20:52:38 +08:00
|
|
|
#include "libiberty.h"
|
2014-07-28 21:04:00 +08:00
|
|
|
#include "pathmax.h"
|
2014-07-28 21:09:12 +08:00
|
|
|
#include "gdb/signals.h"
|
2014-07-28 21:21:31 +08:00
|
|
|
#include "gdb_locale.h"
|
2014-07-28 21:28:06 +08:00
|
|
|
#include "ptid.h"
|
Move utility functions to common/
gdb/ChangeLog
2015-06-15 Aleksandar Ristovski <aristovski@qnx.com
Jan Kratochvil <jan.kratochvil@redhat.com>
Move utility functions to common/.
* cli/cli-utils.c (skip_spaces, skip_spaces_const, skip_to_space_const):
Move defs to common/common-utils.c.
* cli/cli-utils.h (skip_spaces, skip_spaces_const, skip_to_space)
(skip_to_space_const): Move decls to common/common-utils.h.
* common/common-defs.h: Move include of common-types.h before
common-utils.h.
* common/common-utils.c: Include host-defs.h and ctype.h.
(HIGH_BYTE_POSN, is_digit_in_base, digit_to_int, strtoulst): Move
from utils.c.
(skip_spaces, skip_spaces_const, skip_to_space_const): Move from
cli/cli-utils.c.
* common/common-utils.h (strtoulst): Move decl from utils.h.
(skip_spaces, skip_spaces_const, skip_to_space, skip_to_space_const):
Move from cli/cli-utils.h.
* common/host-defs.h: Include limits.h.
(TARGET_CHAR_BIT, HOST_CHAR_BIT): Moved from defs.h.
(skip_spaces, skip_spaces_const): Move decls from cli/cli-utils.h.
* defs.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Move to
common/common-utils.h.
* utils.c (HIGH_BYTE_POSN, is_digit_in_base, digit_to_int)
(strtoulst): Move to common/common-utils.c.
* utils.h (strtoulst): Moved decl to common/common-utils.h.
2015-06-15 23:04:56 +08:00
|
|
|
#include "common-types.h"
|
2014-07-28 21:35:17 +08:00
|
|
|
#include "common-utils.h"
|
2014-07-29 21:47:21 +08:00
|
|
|
#include "gdb_assert.h"
|
2014-07-30 21:09:07 +08:00
|
|
|
#include "errors.h"
|
2014-07-30 23:14:21 +08:00
|
|
|
#include "print-utils.h"
|
2014-07-30 23:21:55 +08:00
|
|
|
#include "common-debug.h"
|
2014-10-08 16:33:22 +08:00
|
|
|
#include "cleanups.h"
|
2014-10-08 16:33:22 +08:00
|
|
|
#include "common-exceptions.h"
|
2014-07-25 23:29:40 +08:00
|
|
|
|
2015-02-09 22:59:08 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
# define EXTERN_C extern "C"
|
Make functions and variables exported by the IPA be extern "C"
Functions and variables that are exported by the IPA DSO (that
GDBserver needs to look up) should have "C" mangling, thus be declared
with extern "C".
Function and variable declarations need the extern "C" marker, but
variable definitions can't be marked extern, so the patch splits
IP_AGENT_EXPORT into three.
Building in C++ mode revealed that a few variables were missing
IP_AGENT_EXPORT, thus the IPA has been broken when stripped, even in C
mode... So this ends being a bug fix as well.
gdb/ChangeLog:
2015-02-27 Pedro Alves <palves@redhat.com>
* common/agent.h (IPA_SYM_EXPORTED_NAME): New.
(IPA_SYM): Use it.
* common/common-defs.h (EXTERN_C_PUSH, EXTERN_C_POP): New macros.
gdb/gdbserver/ChangeLog:
2015-02-27 Pedro Alves <palves@redhat.com>
* linux-amd64-ipa.c (gdb_agent_get_raw_reg): Use
IP_AGENT_EXPORT_FUNC.
* linux-i386-ipa.c (gdb_agent_get_raw_reg): Use
IP_AGENT_EXPORT_FUNC.
* tracepoint.c (ATTR_USED, ATTR_NOINLINE, ATTR_CONSTRUCTOR)
(IP_AGENT_EXPORT): Delete.
(gdb_tp_heap_buffer, gdb_jump_pad_buffer, gdb_jump_pad_buffer_end)
(gdb_trampoline_buffer, gdb_trampoline_buffer_end)
(gdb_trampoline_buffer_error, collecting, gdb_collect)
(stop_tracing, flush_trace_buffer, about_to_request_buffer_space)
(trace_buffer_is_full, stopping_tracepoint, expr_eval_result)
(error_tracepoint, tracepoints, tracing, trace_buffer_ctrl)
(trace_buffer_ctrl_curr, trace_buffer_lo, trace_buffer_hi)
(traceframe_read_count, traceframe_write_count)
(traceframes_created, trace_state_variables, get_raw_reg)
(get_trace_state_variable_value, set_trace_state_variable_value)
(ust_loaded, helper_thread_id, cmd_buf): Use
IPA_SYM_EXPORTED_NAME.
(stop_tracing, flush_trace_buffer): Use IP_AGENT_EXPORT_FUNC.
(tracepoints) Use IP_AGENT_EXPORT_VAR.
(stopping_tracepoint, trace_buffer_is_full, expr_eval_result): Use
IP_AGENT_EXPORT_VAR and wrap in EXTERN_C_PUSH/EXTERN_C_POP.
(last_tracepoint): Move into !IN_PROCESS_AGENT block.
(error_tracepoint): Use IP_AGENT_EXPORT_VAR and wrap in
EXTERN_C_PUSH/EXTERN_C_POP.
(trace_state_variables): Use IP_AGENT_EXPORT_VAR.
(trace_buffer_lo, trace_buffer_hi): Use IP_AGENT_EXPORT_VAR and
wrap in EXTERN_C_PUSH/EXTERN_C_POP.
(trace_buffer_ctrl, trace_buffer_ctrl_curr)
(traceframe_write_count, traceframe_read_count)
(traceframes_created, tracing): Use IP_AGENT_EXPORT_VAR.
(about_to_request_buffer_space, get_trace_state_variable_value)
(set_trace_state_variable_value): Use IP_AGENT_EXPORT_FUNC.
(collecting): Use IP_AGENT_EXPORT_VAR and wrap in
EXTERN_C_PUSH/EXTERN_C_POP.
(gdb_collect): Use IP_AGENT_EXPORT_FUNC.
(ust_loaded, cmd_buf): Use IP_AGENT_EXPORT_VAR.
(helper_thread_id, gdb_agent_capability): Use IP_AGENT_EXPORT_VAR
and wrap in EXTERN_C_PUSH/EXTERN_C_POP.
(gdb_tp_heap_buffer, gdb_jump_pad_buffer, gdb_jump_pad_buffer_end)
(gdb_trampoline_buffer, gdb_trampoline_buffer_end)
(gdb_trampoline_buffer_error): Use IP_AGENT_EXPORT_VAR.
* tracepoint.h (ATTR_USED, ATTR_NOINLINE, EXPORTED_SYMBOL):
Define.
(IP_AGENT_EXPORT_FUNC, IP_AGENT_EXPORT_VAR)
(IP_AGENT_EXPORT_VAR_DECL): Define.
(tracing): Declare.
(gdb_agent_get_raw_reg): Declare.
2015-02-09 22:59:08 +08:00
|
|
|
# define EXTERN_C_PUSH extern "C" {
|
|
|
|
# define EXTERN_C_POP }
|
2015-02-09 22:59:08 +08:00
|
|
|
#else
|
|
|
|
# define EXTERN_C extern
|
Make functions and variables exported by the IPA be extern "C"
Functions and variables that are exported by the IPA DSO (that
GDBserver needs to look up) should have "C" mangling, thus be declared
with extern "C".
Function and variable declarations need the extern "C" marker, but
variable definitions can't be marked extern, so the patch splits
IP_AGENT_EXPORT into three.
Building in C++ mode revealed that a few variables were missing
IP_AGENT_EXPORT, thus the IPA has been broken when stripped, even in C
mode... So this ends being a bug fix as well.
gdb/ChangeLog:
2015-02-27 Pedro Alves <palves@redhat.com>
* common/agent.h (IPA_SYM_EXPORTED_NAME): New.
(IPA_SYM): Use it.
* common/common-defs.h (EXTERN_C_PUSH, EXTERN_C_POP): New macros.
gdb/gdbserver/ChangeLog:
2015-02-27 Pedro Alves <palves@redhat.com>
* linux-amd64-ipa.c (gdb_agent_get_raw_reg): Use
IP_AGENT_EXPORT_FUNC.
* linux-i386-ipa.c (gdb_agent_get_raw_reg): Use
IP_AGENT_EXPORT_FUNC.
* tracepoint.c (ATTR_USED, ATTR_NOINLINE, ATTR_CONSTRUCTOR)
(IP_AGENT_EXPORT): Delete.
(gdb_tp_heap_buffer, gdb_jump_pad_buffer, gdb_jump_pad_buffer_end)
(gdb_trampoline_buffer, gdb_trampoline_buffer_end)
(gdb_trampoline_buffer_error, collecting, gdb_collect)
(stop_tracing, flush_trace_buffer, about_to_request_buffer_space)
(trace_buffer_is_full, stopping_tracepoint, expr_eval_result)
(error_tracepoint, tracepoints, tracing, trace_buffer_ctrl)
(trace_buffer_ctrl_curr, trace_buffer_lo, trace_buffer_hi)
(traceframe_read_count, traceframe_write_count)
(traceframes_created, trace_state_variables, get_raw_reg)
(get_trace_state_variable_value, set_trace_state_variable_value)
(ust_loaded, helper_thread_id, cmd_buf): Use
IPA_SYM_EXPORTED_NAME.
(stop_tracing, flush_trace_buffer): Use IP_AGENT_EXPORT_FUNC.
(tracepoints) Use IP_AGENT_EXPORT_VAR.
(stopping_tracepoint, trace_buffer_is_full, expr_eval_result): Use
IP_AGENT_EXPORT_VAR and wrap in EXTERN_C_PUSH/EXTERN_C_POP.
(last_tracepoint): Move into !IN_PROCESS_AGENT block.
(error_tracepoint): Use IP_AGENT_EXPORT_VAR and wrap in
EXTERN_C_PUSH/EXTERN_C_POP.
(trace_state_variables): Use IP_AGENT_EXPORT_VAR.
(trace_buffer_lo, trace_buffer_hi): Use IP_AGENT_EXPORT_VAR and
wrap in EXTERN_C_PUSH/EXTERN_C_POP.
(trace_buffer_ctrl, trace_buffer_ctrl_curr)
(traceframe_write_count, traceframe_read_count)
(traceframes_created, tracing): Use IP_AGENT_EXPORT_VAR.
(about_to_request_buffer_space, get_trace_state_variable_value)
(set_trace_state_variable_value): Use IP_AGENT_EXPORT_FUNC.
(collecting): Use IP_AGENT_EXPORT_VAR and wrap in
EXTERN_C_PUSH/EXTERN_C_POP.
(gdb_collect): Use IP_AGENT_EXPORT_FUNC.
(ust_loaded, cmd_buf): Use IP_AGENT_EXPORT_VAR.
(helper_thread_id, gdb_agent_capability): Use IP_AGENT_EXPORT_VAR
and wrap in EXTERN_C_PUSH/EXTERN_C_POP.
(gdb_tp_heap_buffer, gdb_jump_pad_buffer, gdb_jump_pad_buffer_end)
(gdb_trampoline_buffer, gdb_trampoline_buffer_end)
(gdb_trampoline_buffer_error): Use IP_AGENT_EXPORT_VAR.
* tracepoint.h (ATTR_USED, ATTR_NOINLINE, EXPORTED_SYMBOL):
Define.
(IP_AGENT_EXPORT_FUNC, IP_AGENT_EXPORT_VAR)
(IP_AGENT_EXPORT_VAR_DECL): Define.
(tracing): Declare.
(gdb_agent_get_raw_reg): Declare.
2015-02-09 22:59:08 +08:00
|
|
|
# define EXTERN_C_PUSH
|
|
|
|
# define EXTERN_C_POP
|
2015-02-09 22:59:08 +08:00
|
|
|
#endif
|
|
|
|
|
2014-07-24 22:35:45 +08:00
|
|
|
#endif /* COMMON_DEFS_H */
|