binutils-gdb/gdbsupport
Simon Marchi ff8885c3be gdbsupport: include cstdlib in common-defs.h
In PR 25731 [1], the following build failure was reported:

    ../../binutils-gdb/gdb/gdbtypes.c:1254:10: error: no member named 'abs' in namespace 'std'; did you mean simply 'abs'?
                = ((std::abs (stride) * element_count) + 7) / 8;
                    ^~~~~~~~
                    abs
    /usr/include/stdlib.h:129:6: note: 'abs' declared here
    int      abs(int) __pure2;
             ^
The original report was using:

    $ gcc -v
    Apple LLVM version 8.0.0 (clang-800.0.42.1)
    Target: x86_64-apple-darwin15.6.0

Note that I was _not_ able to reproduce using:

    $ g++ --version
    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
    Apple clang version 11.0.0 (clang-1100.0.33.17)
    Target: x86_64-apple-darwin19.3.0

The proposed fix is to include <cstdlib> in addition to <stdlib.h>.

Here's an excerpt of [2] relevant to this problem:

    These headers [speaking of the .h form] are allowed to also declare
    the same names in the std namespace, and the corresponding cxxx
    headers are allowed to also declare the same names in the global
    namespace: including <cstdlib> definitely provides std::malloc and
    may also provide ::malloc.  Including <stdlib.h> definitely provides
    ::malloc and may also provide std::malloc

Since we use std::abs, we should not assume that our include of stdlib.h
declares an `abs` function in the `std` namespace.

If we replace the include of stdlib.h with cstdlib, then we fall in the
opposite situation.  A standard C++ library may decide to only put the
declarations in the std namespace, requiring us to prefix all standard
functions with `std::`.  I'm not against that, but for the moment I think the
safest way forward is to just include both.

Note that I don't know what effect this patch can have on any stdlib.h fix
provided by gnulib.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=25731
[2] https://en.cppreference.com/w/cpp/header#C_compatibility_headers

gdbsupport/ChangeLog:

	* common-defs.h: Include cstdlib.h.
2020-04-27 09:28:03 -04:00
..
.dir-locals.el gdbserver/gdbsupport: Add .dir-locals.el file 2020-03-06 11:29:46 +00:00
.gitattributes gdb, gdbserver, gdbsupport: add .gitattributes files 2020-03-05 15:59:22 +01:00
ChangeLog gdbsupport: include cstdlib in common-defs.h 2020-04-27 09:28:03 -04:00
Makefile.am Move event-loop.[ch] to gdbsupport/ 2020-04-13 14:10:04 -06:00
Makefile.in Move event-loop.[ch] to gdbsupport/ 2020-04-13 14:10:04 -06:00
README Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
acinclude.m4 Move gdb/selftest.m4 to gdbsupport/selftest.m4 2020-03-12 14:19:38 -04:00
aclocal.m4 Move many configure checks to common.m4 2020-01-14 16:25:03 -07:00
agent.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
agent.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
alt-stack.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
array-view.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
ax.def Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
block-signals.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
break-common.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
btrace-common.cc Don't pass NULL to memcpy in gdb 2020-03-31 07:29:53 -06:00
btrace-common.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
buffer.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
buffer.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
byte-vector.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
check-defines.el Add gdbsupport check-defines script 2020-01-14 16:25:04 -07:00
cleanups.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
cleanups.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
common-debug.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
common-debug.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
common-defs.h gdbsupport: include cstdlib in common-defs.h 2020-04-27 09:28:03 -04:00
common-exceptions.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
common-exceptions.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
common-gdbthread.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
common-inferior.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
common-inferior.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
common-regcache.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
common-regcache.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
common-types.h Change gdbsupport not to rely on BFD 2020-03-12 13:32:16 -06:00
common-utils.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
common-utils.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
common.m4 Move event-loop configury to common.m4 2020-04-13 14:10:03 -06:00
config.in Move event-loop configury to common.m4 2020-04-13 14:10:03 -06:00
configure Move event-loop configury to common.m4 2020-04-13 14:10:03 -06:00
configure.ac Move sourcing of development.sh to GDB_AC_COMMON 2020-03-12 14:18:00 -04:00
create-version.sh gdbsupport: Resolve shellcheck issues in create-version.sh script 2020-03-27 13:52:00 +00:00
def-vector.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
default-init-alloc.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
enum-flags.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
environ.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
environ.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
errors.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
errors.h Introduce and use flush_streams 2020-04-13 14:10:04 -06:00
event-loop.cc Move gdb_notifier comment 2020-04-13 14:10:04 -06:00
event-loop.h Move event-loop.[ch] to gdbsupport/ 2020-04-13 14:10:04 -06:00
fileio.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
fileio.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
filestuff.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
filestuff.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
filtered-iterator.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
format.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
format.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
forward-scope-exit.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
function-view.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb-dlfcn.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
gdb-dlfcn.h Fix comment for 'gdb_dlopen' 2020-02-28 11:04:28 -05:00
gdb-sigmask.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_assert.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_binary_search.h Fix two typos in gdb_binary_search.h 2020-03-08 11:05:43 -06:00
gdb_locale.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_optional.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_proc_service.h Ensure proc-service symbols have default visibility (PR build/24805) 2020-01-16 19:14:14 +00:00
gdb_ref_ptr.h Mark move constructors as "noexcept" 2020-04-20 11:45:06 -06:00
gdb_select.h Move gdb_select.h to gdbsupport/ 2020-04-13 14:10:03 -06:00
gdb_setjmp.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_signals.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_splay_tree.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_string_view.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_string_view.tcc Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_sys_time.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_tilde_expand.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
gdb_tilde_expand.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_unique_ptr.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_unlinker.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_vecs.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
gdb_vecs.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
gdb_wait.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
gdb_wait.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
hash_enum.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
host-defs.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
job-control.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
job-control.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
netstuff.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
netstuff.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
new-op.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
next-iterator.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
observable.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
offset-type.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
parallel-for.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
pathstuff.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
pathstuff.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
poison.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
preprocessor.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
print-utils.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
print-utils.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
ptid.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
ptid.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
refcounted-object.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
rsp-low.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
rsp-low.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
run-time-clock.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
run-time-clock.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
safe-iterator.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
safe-strerror.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
scope-exit.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
scoped_fd.h Mark move constructors as "noexcept" 2020-04-20 11:45:06 -06:00
scoped_mmap.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
scoped_mmap.h Mark move constructors as "noexcept" 2020-04-20 11:45:06 -06:00
scoped_restore.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
selftest.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
selftest.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
selftest.m4 Move gdb/selftest.m4 to gdbsupport/selftest.m4 2020-03-12 14:19:38 -04:00
signals-state-save-restore.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
signals-state-save-restore.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
signals.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
symbol.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
tdesc.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
tdesc.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
thread-pool.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
thread-pool.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
traits.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
underlying.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
valid-expr.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
version.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
warning.m4 gdb: enable -Wmissing-prototypes warning 2020-03-11 15:15:12 -04:00
x86-xstate.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00
xml-utils.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
xml-utils.h Move gdbsupport to the top level 2020-01-14 16:25:02 -07:00

README

This is a helper library that is used by gdb and gdbserver.

To send patches, follow the gdb patch submission instructions in
../gdb/CONTRIBUTE.  For maintainers, see ../gdb/MAINTAINERS.