aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
AgeCommit message (Collapse)AuthorFilesLines
2022-03-30Consolidate definition of current_directoryTom Tromey3-3/+7
I noticed that both gdbserver and gdb define current_directory. However, as it is referenced by gdbsupport, it seemed better to define it there as well. This patch also moves the declaration to pathstuff.h. Tested by rebuilding.
2022-03-07Let phex and phex_nz handle sizeof_l==1Tom Tromey1-0/+8
Currently, neither phex nor phex_nz handle sizeof_l==1 -- they let this case fall through to the default case. However, a subsequent patch in this series needs this case to work correctly. I looked at all calls to these functions that pass a 1 for the sizeof_l parameter. The only such case seems to be correct with this change.
2022-03-03Fix typo in last change.Roland McGrath1-1/+1
2022-03-03Avoid conflict with gnulib open/close macros.Roland McGrath2-5/+5
On some systems, the gnulib configuration will decide to define open and/or close as macros to replace the POSIX C functions. This interferes with using those names in C++ class or namespace scopes. gdbsupport/ * event-pipe.cc (event_pipe::open): Renamed to ... (event_pipe::open_pipe): ... this. (event_pipe::close): Renamed to ... (event_pipe::close_pipe): ... this. * event-pipe.h (class event_pipe): Updated. gdb/ * inf-ptrace.h (async_file_open, async_file_close): Updated. gdbserver/ * gdbserver/linux-low.cc (linux_process_target::async): Likewise.
2022-02-25gdb: add operator+= and operator+ overload for std::stringAndrew Burgess1-0/+19
This commit adds operator+= and operator+ overloads for adding gdb::unique_xmalloc_ptr<char> to a std::string. I could only find 3 places in GDB where this was useful right now, and these all make use of operator+=. I've also added a self test for gdb::unique_xmalloc_ptr<char>, which makes use of both operator+= and operator+, so they are both getting used/tested. There should be no user visible changes after this commit, except when running 'maint selftest', where the new self test is visible.
2022-02-22gdbsupport: Add an event-pipe class.John Baldwin6-3/+190
This pulls out the implementation of an event pipe used to implement target async support in both linux-low.cc (gdbserver) and linux-nat.c (gdb). This will be used to replace the existing event pipe in linux-low.cc and linux-nat.c in future commits. Co-Authored-By: Lancelot SIX <lsix@lancelotsix.com>
2022-01-20gdbsupport/gdb_regex.cc: replace defs.h include with common-defs.hSimon Marchi1-1/+1
This was forgotten when gdb_regex was moved from gdb to gdbsupport. Change-Id: I73b446f71861cabbf7afdb7408ef9d59fa64b804
2022-01-18Move gdb_regex to gdbsupportTom Tromey4-8/+126
This moves the gdb_regex convenience class to gdbsupport.
2022-01-18Introduce gdb-hashtab module in gdbsupportTom Tromey4-9/+106
gdb has some extensions and helpers for working with the libiberty hash table. This patch consolidates these and moves them to gdbsupport.
2022-01-18Move gdb obstack code to gdbsupportTom Tromey4-8/+216
This moves the gdb-specific obstack code -- both extensions like obconcat and obstack_strdup, and things like auto_obstack -- to gdbsupport.
2022-01-18Move gdb_argv to gdbsupportTom Tromey1-0/+204
This moves the gdb_argv class to a new header in gdbsupport.
2022-01-13gdb: don't use -Wmissing-prototypes with g++Andrew Burgess6-4/+137
This commit aims to not make use of -Wmissing-prototypes when compiling with g++. Use of -Wmissing-prototypes was added with this commit: commit a0761e34f054767de6d6389929d27e9015fb299b Date: Wed Mar 11 15:15:12 2020 -0400 gdb: enable -Wmissing-prototypes warning Because clang can provide helpful warnings with this flag. Unfortunately, g++ doesn't accept this flag, and will give this warning: cc1plus: warning: command line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++ In theory the fact that this flag is not supported should be detected by the configure check in gdbsupport/warning.m4, but for users of ccache, this check doesn't work due to a long standing ccache issue: https://github.com/ccache/ccache/issues/738 The ccache problem is that -W... options are reordered on the command line, and so -Wmissing-prototypes is seen before -Werror. Usually this doesn't matter, but the above warning (about the flag not being valid) is issued before the -Werror flag is processed, and so is not fatal. There have been two previous attempts to fix this that I'm aware of. The first is: https://sourceware.org/pipermail/gdb-patches/2021-September/182148.html In this attempt, instead of just relying on a compile to check if a flag is valid, the proposal was to both compile and link. As linking doesn't go through ccache, we don't suffer from the argument reordering problem, and the link phase will correctly fail when using -Wmissing-prototypes with g++. The configure script will then disable the use of this flag. This approach was rejected, and the suggestion was to only add the -Wmissing-prototypes flag if we are compiling with gcc. The second attempt, attempts this approach, and can be found here: https://sourceware.org/pipermail/gdb-patches/2021-November/183076.html This attempt only adds the -Wmissing-prototypes flag is the value of GCC is not 'yes'. This feels like it is doing the right thing, unfortunately, the GCC flag is really a 'is gcc like' flag, not a strict, is gcc check. As such, GCC is set to 'yes' for clang, which would mean the flag was not included for clang or gcc. The entire point of the original commit was to add this flag for clang, so clearly the second attempt is not sufficient either. In this new attempt I have added gdbsupport/compiler-type.m4, this file defines AM_GDB_COMPILER_TYPE. This macro sets the variable GDB_COMPILER_TYPE to either 'gcc', 'clang', or 'unknown'. In future the list of values might be extended to cover other compilers, if this is ever useful. I've then modified gdbsupport/warning.m4 to only add the problematic -Wmissing-prototypes flag if GDB_COMPILER_TYPE is not 'gcc'. I've tested this with both gcc and clang and see the expected results, gcc no longer attempts to use the -Wmissing-prototypes flag, while clang continues to use it. When compiling using ccache, I am no longer seeing the warning.
2022-01-11gdbsupport: regenerate Makefile.inAndrew Burgess1-2/+2
I had cause to regenerate gdbsupport/Makefile.in, and noticed some unexpected changes in the copyright header dates. I suspect that this was caused by the end of year date range update process. The Makefile.in contains two date ranges. The first range appears to be the date range for the version of automake being used, that is the range runs up to 2017 only, when automake 1.15.1 was released. The second date range in Makefile.in represents the date range for the generated file, and so, now runs up to 2022. Anyway, this is the result of running autoreconf (using automake 1.15.1) in the gdbsupport directory.
2022-01-04gdb: don't pass nullptr to sigwaitAndrew Burgess1-1/+6
I tried building GDB on GNU/Hurd, and ran into this warning: gdbsupport/scoped_ignore_signal.h:78:16: error: null argument where non-null required (argument 2) [-Werror=nonnull] This is because in this commit: commit 99624310dd82542c389c89c2e55d8cae36bb74e1 Date: Sun Jun 27 15:13:14 2021 -0400 gdb: fall back on sigpending + sigwait if sigtimedwait is not available A call to sigwait was introduced that passes nullptr as the second argument, this call is only reached if sigtimedwait is not supported. The original patch was written for macOS, I assume on that target passing nullptr as the second argument is fine. On my GNU/Linux box, the man-page for sigwait doesn't mention that nullptr is allowed for the second argument, so my assumption would be that nullptr is not OK, and, if I change the '#ifdef HAVE_SIGTIMEDWAIT' introduced by the above patch to '#if 0', and rebuild on GNU/Linux, I see the same warning that I see on GNU/Hurd. I propose that we stop passing nullptr as the second argument to sigwait, and instead pass a valid int pointer. The value returned in the int can then be used in an assert. For testing, I (locally) made the change to the #ifdef I mentioned above, compiled GDB, and ran the usual tests, this meant I was using sigwait instead on sigtimedwait on GNU/Linux, I saw no regressions.
2022-01-01Automatic Copyright Year update after running gdb/copyright.pyJoel Brobecker138-138/+138
This commit brings all the changes made by running gdb/copyright.py as per GDB's Start of New Year Procedure. For the avoidance of doubt, all changes in this commits were performed by the script.
2021-12-15New --enable-threading configure option to control use of threads in ↵Luis Machado2-4/+42
GDB/GDBserver Add the --enable-threading configure option so multithreading can be disabled at configure time. This is useful for statically-linked builds of GDB/GDBserver, since the thread library doesn't play well with that setup. If you try to run a statically-linked GDB built with threading, it will crash when setting up the number of worker threads. This new option is also convenient when debugging GDB in a system with lots of threads, where the thread discovery code in GDB will emit too many messages, like so: [New Thread 0xfffff74d3a50 (LWP 2625599)] If you have X threads, that message will be repeated X times. The default for --enable-threading is "yes".
2021-12-09Revert "gdbsupport: remove unnecessary `#ifndef IN_PROCESS_AGENT`"Simon Marchi1-0/+2
This reverts commit fe72c32765e1190c8a17d309fc3a7e1882d6a430. It turns out it was wrong, libinproctrace.so does build its own gdbsupport/tdesc.cc. This broke the build: make[1]: Entering directory '/home/simark/build/binutils-gdb-one-target/gdbserver' CXXLD libinproctrace.so /usr/bin/ld: gdbsupport/tdesc-ipa.o: in function `print_xml_feature::visit_pre(target_desc const*)': /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/tdesc.cc:407: undefined reference to `tdesc_architecture_name(target_desc const*)' /usr/bin/ld: /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/tdesc.cc:408: undefined reference to `tdesc_architecture_name(target_desc const*)' /usr/bin/ld: /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/tdesc.cc:411: undefined reference to `tdesc_osabi_name(target_desc const*)' /usr/bin/ld: /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/tdesc.cc:416: undefined reference to `tdesc_compatible_info_list(target_desc const*)' /usr/bin/ld: /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/tdesc.cc:418: undefined reference to `tdesc_compatible_info_arch_name(std::unique_ptr<tdesc_compatible_info, std::default_delete<tdesc_compatible_info> > const&)'
2021-12-09gdbsupport: remove unnecessary `#ifndef IN_PROCESS_AGENT`Simon Marchi1-2/+0
I suppose this code was copied from GDBserver and this ifndef was left there. As far as I know, IN_PROCESS_AGENT will never be defined when building this file, so we can remove this. Change-Id: I84fc408e330b3a29106df830a09342861cadbaf6
2021-12-04gdbsupport: fix memory leak in create_file_handler when re-using file handlerSimon Marchi1-7/+6
ASan made me notice a memory leak, where the memory tied to the file handle name string wasn't freed. When register a file handler with an fd that is already registered, we re-use the file_handler object, so we ended up creating a new std::string object and overwriting the file_handler::name pointer, without free-ing the old std::string. Fix this by allocating file_handler with new, deleting it with delete, and making file_handler::name not a pointer. Change-Id: Ie304cc78ab5ae5dfad9a1366e9890c09de651f43
2021-12-03gdbsupport: add array_view copy functionSimon Marchi1-0/+15
An assertion was recently added to array_view::operator[] to ensure we don't do out of bounds accesses. However, when the array_view is copied to or from using memcpy, it bypasses that safety. To address this, add a `copy` free function that copies data from an array view to another, ensuring that the destination and source array views have the same size. When copying to or from parts of an array_view, we are expected to use gdb::array_view::slice, which does its own bounds check. With all that, any copy operation that goes out of bounds should be caught by an assertion at runtime. copy is implemented using std::copy and std::copy_backward, which, at least on libstdc++, appears to pick memmove when copying trivial data. So in the end there shouldn't be much difference vs using a bare memcpy, as we do right now. When copying non-trivial data, std::copy and std::copy_backward assigns each element in a loop. To properly support overlapping ranges, we must use std::copy or std::copy_backward, depending on whether the destination is before the source or vice-versa. std::copy and std::copy_backward don't support copying exactly overlapping ranges (where the source range is equal to the destination range). But in this case, no copy is needed anyway, so we do nothing. The order of parameters of the new copy function is based on std::copy and std::copy_backward, where the source comes before the destination. Change a few randomly selected spots to use the new function, to show how it can be used. Add a test for the new function, testing both with arrays of a trivial type (int) and of a non-trivial type (foo). Test non-overlapping ranges as well as three kinds of overlapping ranges: source before dest, dest before source, and dest == source. Change-Id: Ibeaca04e0028410fd44ce82f72e60058d6230a03
2021-11-22gdb: introduce target_waitkind_str, use it in target_waitstatus::to_stringSimon Marchi2-4/+8
I would like to print target_waitkind values in debug messages, so I think that a target_waitkind-to-string function would be useful. While at it, use it in target_waitstatus::to_string. This changes the output of target_waitstatus::to_string a bit, but I think it is for the better. The debug messages will show a string matching exactly the target_waitkind enumerator (minus the TARGET_WAITKIND prefix). As a convenience, make string_appendf return the same reference to string it got as a parameter. This allows doing this: return string_appendf (str, "foo"); ... keeping the code concise. Change-Id: I383dffc9c78614e7d0668b1516073905e798eef7
2021-11-20gdbsupport: fix array-view compilation with c++11 && _GLIBCXX_DEBUGSimon Marchi1-3/+3
When building with -std=c++11 and -D_GLIBCXX_DEBUG=1, we get some errors like: CXX unittests/array-view-selftests.o In file included from /home/smarchi/src/binutils-gdb/gdb/utils.h:25, from /home/smarchi/src/binutils-gdb/gdb/defs.h:630, from /home/smarchi/src/binutils-gdb/gdb/unittests/array-view-selftests.c:20: /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/array-view.h: In instantiation of constexpr gdb::array_view<T> gdb::array_view<T>::slice(gdb::array_view<T>::size_type, gdb::array_view<T>::size_type) const [with T = unsigned char; gdb::array_view<T>::size_type = long unsigned int: /home/smarchi/src/binutils-gdb/gdb/unittests/array-view-selftests.c:532:29: required from here /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/array-view.h:192:3: error: body of constexpr function constexpr gdb::array_view<T> gdb::array_view<T>::slice(gdb::array_view<T>::size_type, gdb::array_view<T>::size_type) const [with T = unsigned char; gdb::array_view<T>::size_type = long unsigned int not a return-statement 192 | } | ^ This is because constexpr functions in c++11 can only consist of a single return statement, so we can't have the gdb_assert in there. Make the gdb_assert presence conditional to the __cplusplus version, to enable it only for c++14 and later. Change-Id: I2ac33f7b4bd1765ddc3ac8d07445b16ac1f340f0
2021-11-18gdbsupport: make gdb_assert_not_reached accept a format stringSimon Marchi2-5/+6
Change gdb_assert_not_reached to accept a format string plus corresponding arguments. This allows giving more precise messages. Because the format string passed by the caller is prepended with a "%s:" to add the function name, the callers can no longer pass a translated string (`_(...)`). Make the gdb_assert_not_reached include the _(), just like the gdb_assert_fail macro just above. Change-Id: Id0cfda5a57979df6cdaacaba0d55dd91ae9efee7
2021-11-16gdbsupport: remove FUNCTION_NAMESimon Marchi2-33/+2
__func__ is standard C++11: https://en.cppreference.com/w/cpp/language/function Also, in C++11, __func__ expands to the demangled function name, so the mention in the comment above FUNCTION_NAME doesn't apply anymore. Finally, in places where FUNCTION_NAME is used, I think it's enough to print the function name, no need to print the whole signature. Therefore, I propose to just remove FUNCTION_NAME and update users to use the standard __func__. Change-Id: I778f28155422b044402442dc18d42d0cded1017d
2021-11-16gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptrAndrew Burgess2-7/+8
The motivation is to reduce the number of places where unmanaged pointers are returned from allocation type routines. All of the callers are updated. There should be no user visible changes after this commit.
2021-11-16gdbsupport: move xfree into its own fileAndrew Burgess4-16/+43
In the next commit I'd like to reference gdb_unique_ptr within the common-utils.h file. However, this requires that I include gdb_unique_ptr.h, which requires that xfree be defined. Interestingly, gdb_unique_ptr.h doesn't actually include anything that defines xfree, but I was finding that when I added a gdb_unique_ptr.h include to common-utils.h I was getting a dependency cycle; before my change xfree was defined when gdb_unique_ptr.h was processed, while after my change it was not, and this made g++ unhappy. To break this cycle, I propose to move xfree into its own header file, gdb-xfree.h, which I'll then include into gdb_unique_ptr.h and common-utils.cc.
2021-11-11[gdb/build] Fix Wimplicit-exception-spec-mismatch in clang buildTom de Vries1-2/+2
When building with clang 13 (and -std=gnu++17 to work around an issue in string_view-selftests.c), we run into a few Wimplicit-exception-spec-mismatch warnings: ... src/gdbsupport/new-op.cc:102:1: error: function previously declared with an \ explicit exception specification redeclared with an implicit exception \ specification [-Werror,-Wimplicit-exception-spec-mismatch] operator delete (void *p) ^ /usr/include/c++/11/new:130:6: note: previous declaration is here void operator delete(void*) _GLIBCXX_USE_NOEXCEPT ^ ... These are due to recent commit 5fff6115fea "Fix LD_PRELOAD=/usr/lib64/libasan.so.6 gdb". Fix this by adding the missing noexcept. Build on x86_64-linux, using gcc 7.5.0 and clang 13.0.0.
2021-11-11[gdb/build] Fix build with -std=c++11Tom de Vries1-0/+5
When building with -std=c++11, we run into two Werror=missing-declarations: ... new-op.cc: In function 'void operator delete(void*, std::size_t)': new-op.cc:114:1: error: no previous declaration for \ 'void operator delete(void*, std::size_t)' [-Werror=missing-declarations] operator delete (void *p, std::size_t) noexcept ^~~~~~~~ new-op.cc: In function 'void operator delete [](void*, std::size_t)': new-op.cc:132:1: error: no previous declaration for \ 'void operator delete [](void*, std::size_t)' [-Werror=missing-declarations] operator delete[] (void *p, std::size_t) noexcept ^~~~~~~~ ... These are due to recent commit 5fff6115fea "Fix LD_PRELOAD=/usr/lib64/libasan.so.6 gdb". The declarations are provided by <new> (which is included) for c++14 onwards, but they are missing for c++11. Fix this by adding the missing declarations. Tested on x86_64-linux, with gcc 7.5.0, both without (implying -std=gnu++14) and with -std=c++11.
2021-11-09Fix build on rhES5Tom Tromey3-0/+25
The rhES5 build failed due to an upstream import a while back. The bug here is that, while the 'personality' function exists, ADDR_NO_RANDOMIZE is only defined in <linux/personality.h>, not <sys/personality.h>. However, <linux/personality.h> does not declare the 'personality' function, and <sys/personality.h> and <linux/personality.h> cannot both be included. This patch restores one of the removed configure checks and updates the code to check it. We had this as a local patch at AdaCore, because it seemed like there was no interest upstream. However, now it turns out that this fixes PR build/28555, so I'm sending it now.
2021-11-08Improve gdb::array_view ctor from contiguous containersLancelot SIX1-3/+4
While reading the interface of gdb::array_view, I realized that the constructor that builds an array_view on top of a contiguous container (such as std::vector, std::array or even gdb::array_view) can be missused. Lets consider the following code sample: struct Parent { Parent (int a): a { a } {} int a; }; std::ostream &operator<< (std::ostream& os, const Parent & p) { os << "Parent {a=" << p.a << "}"; return os; } struct Child : public Parent { Child (int a, int b): Parent { a }, b { b } {} int b; }; std::ostream &operator<< (std::ostream& os, const Child & p) { os << "Child {a=" << p.a << ", b=" << p.b << "}"; return os; } template <typename T> void print (const gdb::array_view<const T> &p) { std::for_each (p.begin (), p.end (), [](const T &p) { std::cout << p << '\n'; }); } Then with the current interface nothinng prevents this usage of array_view to be done: const std::array<Child, 3> elts = { Child {1, 2}, Child {3, 4}, Child {5, 6} }; print_all<Parent> (elts); This compiles fine and produces the following output: Parent {a=1} Parent {a=2} Parent {a=3} which is obviously wrong. There is nowhere in memory a Parent-like object for which the A member is 2 and this call to print_all<Parent> shold not compile at all (calling print_all<Child> is however fine). This comes down to the fact that a Child* is convertible into a Parent*, and that an array view is constructed to a pointer to the first element and a size. The valid type pointed to that can be used with this constructor are restricted using SFINAE, which requires that a pointer to a member into the underlying container can be converted into a pointer the array_view's data type. This patch proposes to change the constraints on the gdb::array_view ctor which accepts a container now requires that the (decayed) type of the elements in the container match the (decayed) type of the array_view being constructed. Applying this change required minimum adjustment in GDB codebase, which are also included in this patch. Tested by rebuilding.
2021-11-05Introduce make_unique_xstrndupTom Tromey1-0/+9
This adds a new make_unique_xstrndup function, which is the "n" analogue of make_unique_xstrdup. It also updates a couple existing places to use this function.
2021-11-03Fix LD_PRELOAD=/usr/lib64/libasan.so.6 gdbJan Kratochvil1-0/+42
Currently for a binary compiled normally (without -fsanitize=address) but with LD_PRELOAD of ASAN one gets: $ ASAN_OPTIONS=detect_leaks=0:alloc_dealloc_mismatch=1:abort_on_error=1:fast_unwind_on_malloc=0 LD_PRELOAD=/usr/lib64/libasan.so.6 gdb ================================================================= ==1909567==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete []) on 0x602000001570 #0 0x7f1c98e5efa7 in operator delete[](void*) (/usr/lib64/libasan.so.6+0xb0fa7) ... 0x602000001570 is located 0 bytes inside of 2-byte region [0x602000001570,0x602000001572) allocated by thread T0 here: #0 0x7f1c98e5cd1f in __interceptor_malloc (/usr/lib64/libasan.so.6+0xaed1f) #1 0x557ee4a42e81 in operator new(unsigned long) (/usr/libexec/gdb+0x74ce81) SUMMARY: AddressSanitizer: alloc-dealloc-mismatch (/usr/lib64/libasan.so.6+0xb0fa7) in operator delete[](void*) ==1909567==HINT: if you don't care about these errors you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0 ==1909567==ABORTING Despite the code called properly operator new[] and operator delete[]. But GDB's new-op.cc provides its own operator new[] which gets translated into malloc() (which gets recogized as operatore new(size_t)) but as it does not translate also operators delete[] Address Sanitizer gets confused. The question is how many variants of the delete operator need to be provided. There could be 14 operators new but there are only 4, GDB uses 3 of them. There could be 16 operators delete but there are only 6, GDB uses 2 of them. It depends on libraries and compiler which of the operators will get used. Currently being used: U operator new[](unsigned long) U operator new(unsigned long) U operator new(unsigned long, std::nothrow_t const&) U operator delete[](void*) U operator delete(void*, unsigned long) Tested on x86_64-linux.
2021-10-28gdb: add selftest name completionSimon Marchi1-1/+3
After the previous commit, it is easy to add completion for selftest names. Again, this is not particularly high value, but I rarely touched completion, so it served as a simple example to get some practice. Change the for_each_selftest_ftype parameter to gdb::function_view, so that we can pass a lambda that captures things. Change-Id: I87cac299ddca9ca7eb0ffab78342e850a98d954c
2021-10-25gdbsupport: add assertions in array_viewSimon Marchi1-4/+24
Add assertions to ensure we don't access an array_view out of bounds. Enable these assertions only when _GLIBCXX_DEBUG is set, as we did for gdb::optional. Change-Id: Iffaee38252405073735ed123c8e57fde6b2c6be3
2021-10-19Fix format_pieces selftest on WindowsTom Tromey3-0/+70
The format_pieces selftest currently fails on Windows hosts. The selftest doesn't handle the "%ll" -> "%I64" rewrite that the formatter may perform, but also gdbsupport was missing a configure check for PRINTF_HAS_LONG_LONG. This patch fixes both issues.
2021-10-19Always use std::function for self-testsTom Tromey2-45/+6
Now that there is a register_test variant that accepts std::function, it seems to me that the 'selftest' struct and accompanying code is obsolete -- simply always using std::function is simpler. This patch implements this idea.
2021-10-04[gdb/build] Add CXX_DIALECT to CXXTom de Vries1-0/+8
Say we use a gcc version that (while supporting c++11) does not support c++11 by default, and needs an -std setting to enable it. If gdb would use the default AX_CXX_COMPILE_STDCXX from autoconf-archive, then we'd have: ... CXX="g++ -std=gnu++11" ... That mechanism however has the following problem (quoting from commit 0bcda685399): ... the top level Makefile passes CXX down to subdirs, and that overrides whatever gdb/Makefile may set CXX to. The result would be that a make invocation from the build/gdb/ directory would use "g++ -std=gnu++11" as expected, while a make invocation at the top level would not. ... Commit 0bcda685399 fixes this by using a custom AX_CXX_COMPILE_STDCXX which does: ... CXX=g++ CXX_DIALECT=-std=gnu++11 ... The problem reported in PR28318 is that using the custom instead of the default AX_CXX_COMPILE_STDCXX makes the configure test for std::thread support fail. We could simply add $CXX_DIALECT to the test for std::thread support, but that would have to be repeated for each added c++ support test. Instead, fix this by doing: ... CXX="g++ -std=gnu++11" CXX_DIALECT=-std=gnu++11 ... This is somewhat awkward, since it results in -std=gnu++11 occuring twice in some situations: ... $ touch src/gdb/dwarf2/read.c $ ( cd build/gdb; make V=1 dwarf2/read.o ) g++-4.8 -std=gnu++11 -x c++ -std=gnu++11 ... ... However, both settings are needed: - the switch in CXX for the std::thread tests (and other tests) - the switch in CXX_DIALECT so it can be appended in Makefiles, to counteract the fact that the top-level Makefile overrides CXX The code added in gdb/ax_cxx_compile_stdcxx.m4 is copied from the default AX_CXX_COMPILE_STDCXX from autoconf-archive. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28318
2021-10-04gdbsupport: remove attempt to define TARGET_WORD_SIZEAndrew Burgess3-14/+0
In the gdbsupport configure.ac file, there is an attempt to define TARGET_WORD_SIZE. This is done by running grep on the file ../bfd/bfd-in3.h. The problem with this is, the file bfd-in3.h is generated into the bfd build directory when bfd is configured, and there is no dependency between the gdbsupport module and the bfd module, so, for example, if I do: $ ../src/configure $ make all-gdbsupport Then bfd will neither be configured, or built. In this case TARGET_WORD_SIZE ends up being defined, but with no value because the grep on bfd-in3.h fails. However, it turns out that this doesn't matter; we don't actually use TARGET_WORD_SIZE anywhere. My proposal in this commit is to just remove the definition of TARGET_WORD_SIZE, the alternative would be to add a dependency between configure-gdbsupport and configure-bfd into Makefile.def, but adding a dependency for something we don't need seems pretty pointless.
2021-09-30gdbsupport: make gdb_mkostemp_cloexec return a scoped_fdSimon Marchi1-2/+2
This encourages the callers to use automatic file descriptor management. Change-Id: I137a81df6f3607b457e28c35aafde8ed6f3a3344
2021-09-30gdbsupport: make gdb_open_cloexec return scoped_fdSimon Marchi3-8/+9
Make gdb_open_cloexec return a scoped_fd, to encourage using automatic management of the file descriptor closing. Except in the most trivial cases, I changed the callers to just release the fd, which retains their existing behavior. That will allow the transition to using scoped_fd more to go gradually, one caller at a time. Change-Id: Ife022b403f96e71d5ebb4f1056ef6251b30fe554
2021-09-30gdbsupport: move gdb_file_up to its own fileSimon Marchi3-13/+39
The following patches wants to change gdb_fopen_cloexec and gdb_mkostemp_cloexec to return a scoped_fd. Doing this causes a cyclic include between scoped_fd.h and filestuff.h, that both want to include each other. scoped_fd.h includes filestuff.h because of the scoped_fd::to_file method's return value. filestuff.h would then include scoped_fd.h for gdb_fopen_cloexec's and gdb_mkostemp_cloexec's return values. To fix that, move gdb_file_up to its own file, gdb_file.h. Change-Id: Ic82a48914b2aacee8f14af535b7469245f88b93d
2021-09-23Change ptid_t::tid to ULONGESTTom Tromey2-4/+6
The ptid_t 'tid' member is normally used as an address in gdb -- both bsd-uthread and ravenscar-thread use it this way. However, because the type is 'long', this can cause problems with sign extension. This patch changes the type to ULONGEST to ensure that sign extension does not occur.
2021-09-23Remove defaulted 'tid' parameter to ptid_t constructorTom Tromey1-1/+1
I wanted to find, and potentially modify, all the spots where the 'tid' parameter to the ptid_t constructor was used. So, I temporarily removed this parameter and then rebuilt. In order to make it simpler to search through the "real" (nonzero) uses of this parameter, something I knew I'd have to do multiple times, I removed any ", 0" from constructor calls. Co-Authored-By: John Baldwin <jhb@FreeBSD.org>
2021-09-22[gdb] Add maint selftest -verbose optionTom de Vries2-2/+20
The print_one_insn selftest in gdb/disasm-selftests.c contains: ... /* If you want to see the disassembled instruction printed to gdb_stdout, set verbose to true. */ static const bool verbose = false; ... Make this parameter available in the maint selftest command using a new option -verbose, such that we can do: ... (gdb) maint selftest -verbose print_one_insn ... Tested on x86_64-linux.
2021-09-21[gdb] Change register_test to use std::function argTom de Vries2-19/+22
Change register_test to use std::function arg, such that we can do: ... register_test (test_name, [=] () { SELF_CHECK (...); }); ... Tested on x86_64-linux.
2021-09-20gdbsupport/gdb_proc_service.h: use decltype instead of typeofSimon Marchi1-1/+1
Bug 28341 shows that GDB fails to compile when built with -std=c++11. I don't know much about the use case, but according to the author of the bug: I encountered the scenario where CXX is set to "g++ -std=c++11" when I try to compile binutils under GCC as part of the GCC 3-stage compilation, which is common for building a cross-compiler. The author of the bug suggests using __typeof__ instead of typeof. But since we're using C++, we might as well use decltype, which is standard. This is what this patch does. The failure (and fix) can be observed by configuring GDB with CXX="g++ -std=c++11": CXX linux-low.o In file included from /home/simark/src/binutils-gdb/gdbserver/gdb_proc_service.h:22, from /home/simark/src/binutils-gdb/gdbserver/linux-low.h:27, from /home/simark/src/binutils-gdb/gdbserver/linux-low.cc:20: /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/gdb_proc_service.h:177:50: error: expected constructor, destructor, or type conversion before (token 177 | __attribute__((visibility ("default"))) typeof (SYM) SYM | ^ /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/gdb_proc_service.h:179:1: note: in expansion of macro PS_EXPORT 179 | PS_EXPORT (ps_get_thread_area); | ^~~~~~~~~ Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28341 Change-Id: I84fbaae938209d8d935ca08dec9b7e6a0dd1bda0
2021-08-03gdbsupport: add debug assertions in gdb::optional::getSimon Marchi1-2/+14
The libstdc++ version of optional contains some runtime checks enabled when _GLIBCXX_DEBUG is defined. I think it would be useful if our version contained similar checks. Add checks in the two `get` methods, also conditional on _GLIBCXX_DEBUG. I think it's simpler to use that macro rather than introducing a new GDB-specific one, as I think that if somebody is interested in enabling these runtime checks, they'll also be interested in enabling the libstdc++ runtime checks (and vice-versa). I implemented these checks using gdb_assert. Note that gdb_assert throws (after querying the user), and we are in noexcept methods. That means that std::terminate / abort will immediately be called. I think this is ok, since if those were "real" _GLIBCXX_DEBUG checks, abort would be called straight away. If I add a dummy failure, it looks like so: $ ./gdb -q -nx --data-directory=data-directory /home/simark/src/binutils-gdb/gdb/../gdbsupport/gdb_optional.h:206: internal-error: T& gdb::optional<T>::get() [with T = int]: Assertion `this->has_value ()' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) n [1] 658767 abort (core dumped) ./gdb -q -nx --data-directory=data-directory Change-Id: Iadfdcd131425bd2ca6a2de30d7b22e9b3cc67793
2021-07-30Replace exception_print_same with operator!=Tom Tromey1-0/+17
I noticed that exception_print_same is only used in a single spot, and it seemed to be better as an operator!= method attached to gdb_exception. Regression tested on x86-64 Fedora 34.
2021-07-30[gdb/build] Disable attribute nonnullTom de Vries1-0/+75
With trunk gcc (12.0) we're running into a -Werror=nonnull-compare build breaker in gdb, which caused a broader review of the usage of the nonnull attribute. The current conclusion is that it's best to disable this. This is explained at length in the gdbsupport/common-defs.h comment. Tested by building with trunk gcc. gdb/ChangeLog: 2021-07-29 Tom de Vries <tdevries@suse.de> * gdbsupport/common-defs.h (ATTRIBUTE_NONNULL): Disable.
2021-07-26gdb: move remaining ChangeLogs to legacy filesAndrew Burgess1-0/+0
In commit: commit f069ea46a03ae868581d1c852da28e979ea1245a Date: Sat Jul 3 16:29:08 2021 -0700 Rename gdb/ChangeLog to gdb/ChangeLog-2021 The gdb/ChangeLog file was renamed, but all of the other ChangeLog files relating to gdb were left in place. As I understand things, the no ChangeLogs policy applies to all the GDB related directories, so this commit renames all of the remaining GDB related ChangeLog files. As with the original commit, the intention behind this commit is to hopefully stop people merging ChangeLog entries by mistake. The renames carried out in this commit are: gdb/doc/ChangeLog -> gdb/doc/ChangeLog-1991-2021 gdb/stubs/ChangeLog -> gdb/stubs/ChangeLog-2012-2020 gdb/testsuite/ChangeLog -> gdb/testsuite/ChangeLog-2014-2021 gdbserver/ChangeLog -> gdbserver/ChangeLog-2002-2021 gdbsupport/ChangeLog -> gdbsupport/ChangeLog-2020-2021