aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
AgeCommit message (Collapse)AuthorFilesLines
2024-11-25gdbsupport: add unordered_dense.h 4.4.0Simon Marchi3-0/+2105
Add a copy of unordered_dense.h from [1]. This file implements an efficient hash map and hash set with a nice C++ interface (a near drop-in for std::unordered_map and std::unordered_set). This is expected to be used to replace uses of `htab_t`, for improved code readability and type safety. Performance-wise, it is preferred to the std types (std::unordered_map and std::unordered_set) due to it using open addressing vs closed addressing for the std types. I chose this particular implementation because it is simple to use, it's a standalone header and it typically performs well in benchmarks I have seen (e.g. [2]). The license being MIT, my understanding is that it's not a problem to use it and re-distribute it. Add two additional files, gdbsupport/unordered_map.h and gdbsupport/unordered_set.h, which make the map and set offered by gdbsupport/unordered_dense.h available as gdb::unordered_map and gdb::unordered_set. [1] https://github.com/martinus/unordered_dense [2] https://jacksonallan.github.io/c_cpp_hash_tables_benchmark/#conclusion-which-hash-table-to-choose Change-Id: I0c7469ccf9a14540465479e58b2a5140a2440a7d Approved-By: Tom Tromey <tom@tromey.com>
2024-11-23[gdbsupport] Rerun autoreconf -fTom de Vries2-2/+2
Rerun autoreconf -f in gdbsupport, reverting "behaviour" -> "behavior" changes in generated files aclocal.m4 and configure.
2024-11-23[gdb/contrib] Add two rules in common-misspellings.txtTom de Vries3-3/+3
Eli mentioned [1] that given that we use US English spelling in our documentation, we should use "behavior" instead of "behaviour". In wikipedia-common-misspellings.txt there's a rule: ... behavour->behavior, behaviour ... which leaves this as a choice. Add an overriding rule to hardcode the choice to common-misspellings.txt: ... behavour->behavior ... and add a rule to rewrite behaviour into behavior: ... behaviour->behavior ... and re-run spellcheck.sh on gdb*. Tested on x86_64-linux. [1] https://sourceware.org/pipermail/gdb-patches/2024-November/213371.html
2024-11-22gdb: Introduce RAII signal handler setterGuinevere Larsen1-0/+73
This patch is motivated by the wait function for the record-full target, that would install a custom signal handler for SIGINT, but could throw an exception and never reset the SIGINT handler. This is clearly a bad idea, so this patch introduces the class scoped_signal_handler in a new .h file. The file is added to gdbsupport, even though only gdb code is using it, because it feels like an addition that would be useful for more than just directly gdb. The implementation of the RAII class is based on the implementation on gdb/utils.c. That is, it uses preprocessor ifdefs to probe for sigaction support, and uses it if possible, defaulting to a raw call to signal only if sigaction isn't supported. sigaction is preferred based on the "portability" section of the manual page for the signal function. There are 3 places where this class can just be dropped in, gdb/record-full.c, gdb/utils.c and gdb/extension.c. This third place already had a specialized RAII signal handler setter, but it is substituted for the new general purpose one. Approved-By: Tom Tromey <tom@tromey.com>
2024-11-22[gdbsupport] Handle EINTR in event-pipe.ccTom de Vries1-13/+8
Use gdb syscall wrappers to handle EINTR in event-pipe.cc. Tested on aarch64-linux.
2024-11-22[gdb] Handle EINTR in ser-event.cTom de Vries1-0/+11
Use gdb syscall wrappers to handle EINTR in ser-event.c. Tested on aarch64-linux.
2024-11-22[gdb] Add gdb::waitTom de Vries1-0/+6
Add gdb::wait, and use it in gdb/procfs.c, making sure that EINTR is handled. Tested on x86_64-linux.
2024-11-22[gdbsupport] Add gdb::{waitpid,read,write,close}Tom de Vries1-0/+29
We have gdb::handle_eintr, which allows us to rewrite: ... ssize_t ret; do { errno = 0; ret = ::write (pipe[1], "+", 1); } while (ret == -1 && errno == EINTR); ... into: ... ssize_t ret = gdb::handle_eintr (-1, ::write, pipe[1], "+", 1); ... However, the call to write got a bit mangled, requiring effort to decode it back to its original form. Instead, add a new function gdb::write that allows us to write: ... ssize_t ret = gdb::write (pipe[1], "+", 1); ... Likewise for waitpid, read and close. Tested on x86_64-linux.
2024-11-18[gdb] Fix some typosTom de Vries1-3/+3
Run gdb/contrib/spellcheck.sh on directories gdb*. Fix typo: ... unkown -> unknown ... Tested on x86_64-linux.
2024-11-12[gdb/tdep] Use raw_supply_part_zeroed for AArch64Tom de Vries1-0/+6
In gdb/aarch64-linux-tdep.c we find: ... gdb::byte_vector za_zeroed (za_bytes, 0); regcache->raw_supply (tdep->sme_za_regnum, za_zeroed); ... We can't use reg_buffer::raw_supply_zeroed here because only part of the register is written. Add raw_supply_part_zeroed, and use it instead. Likewise elsewhere in AArch64 tdep code. Tested on aarch64-linux. Approved-By: Luis Machado <luis.machado@arm.com>
2024-11-04Remove gdb::hash_enumTom Tromey1-45/+0
gdb::hash_enum is a workaround for a small oversight in C++11: std::hash was not defined for enumeration types. This was rectified in C++14 and so we can remove the local workaround. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-10-19Pass current directory to gdb_abspathTom Tromey2-12/+12
Currently, gdb_abspath uses the current_directory global. However, background threads need to capture this global to avoid races with the user using "cd". This patch changes this function to accept a cwd parameter, in prepration for this. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31716
2024-10-19[gdbsupport] Add gdb::array_view::{iterator,const_iterator}Tom de Vries1-4/+6
While trying to substitute some std::vector type A in the code with a gdb::array_view: ... - using A = std::vector<T> + using A = gdb::array_view<T> .... I ran into the problem that the code was using A::iterator while gdb::array_view doesn't define such a type. Fix this by: - adding types gdb::array_view::iterator and gdb::array_view::const_iterator, - using them in gdb::array_view::(c)begin and gdb::array_view::(c)end, as is usual, and - using them explicitly in a unit test. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-10-19[gdbsupport] Use std::span-style iterators for gdb::array_viewTom de Vries1-4/+4
There's a plan to replace gdb::array_view with std::span (PR31422), and making gdb::array_view more like std::span helps with that. One difference is that std::span has: ... constexpr iterator begin() const noexcept; constexpr const_iterator cbegin() const noexcept; ... while gdb::array_view has: ... constexpr T *begin () noexcept; constexpr const T *begin () const noexcept; ... Fix this by renaming the second variant to cbegin, and making the first variant const. Likewise for gdb::array_view::end. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-10-18[gdb/build] Use -fno-hoist-adjacent-loads for gcc <= 13Tom de Vries1-0/+7
When building gdb with gcc 12 and -fsanitize=threads while renabling background dwarf reading by setting dwarf_synchronous to false, I run into: ... (gdb) file amd64-watchpoint-downgrade Reading symbols from amd64-watchpoint-downgrade... (gdb) watch global_var ================== WARNING: ThreadSanitizer: data race (pid=20124) Read of size 8 at 0x7b80000500d8 by main thread: #0 cooked_index_entry::full_name(obstack*, bool) const cooked-index.c:220 #1 cooked_index::get_main_name(obstack*, language*) const cooked-index.c:735 #2 cooked_index_worker::wait(cooked_state, bool) cooked-index.c:559 #3 cooked_index::wait(cooked_state, bool) cooked-index.c:631 #4 cooked_index_functions::wait(objfile*, bool) cooked-index.h:729 #5 cooked_index_functions::compute_main_name(objfile*) cooked-index.h:806 #6 objfile::compute_main_name() symfile-debug.c:461 #7 find_main_name symtab.c:6503 #8 main_language() symtab.c:6608 #9 set_initial_language_callback symfile.c:1634 #10 get_current_language() language.c:96 ... Previous write of size 8 at 0x7b80000500d8 by thread T1: #0 cooked_index_shard::finalize(parent_map_map const*) \ dwarf2/cooked-index.c:409 #1 operator() cooked-index.c:663 ... ... SUMMARY: ThreadSanitizer: data race cooked-index.c:220 in \ cooked_index_entry::full_name(obstack*, bool) const ================== Hardware watchpoint 1: global_var (gdb) PASS: gdb.arch/amd64-watchpoint-downgrade.exp: watch global_var ... This was also reported in PR31715. This is due do gcc PR110799 [1], generating wrong code with -fhoist-adjacent-loads, and causing a false positive for -fsanitize=threads. Work around the gcc PR by forcing -fno-hoist-adjacent-loads for gcc <= 13 and -fsanitize=threads. Tested in that same configuration on x86_64-linux. Remaining ThreadSanitizer problems are the ones reported in PR31626 (gdb.rust/dwindex.exp) and PR32247 (gdb.trace/basic-libipa.exp). PR gdb/31715 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31715 Tested-By: Bernd Edlinger <bernd.edlinger@hotmail.de> Approved-By: Tom Tromey <tom@tromey.com> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110799
2024-10-10gdb/gdbserver: change shared set_tdesc_osabi to take gdb_osabiAndrew Burgess1-2/+4
There is a single declaration of set_tdesc_osabi that is shared between gdbserver/ and gdb/, this declaration takes a 'const char *' argument which is the string representing an osabi. Then in gdb/ we have an overload of set_tdesc_osabi which takes an 'enum gdb_osabi'. In this commit I change the shared set_tdesc_osabi to be the version which takes an 'enum gdb_osabi', and I remove the version which takes a 'const char *'. All users of set_tdesc_osabi are updated to pass an 'enum gdb_osabi'. The features/ code, which is generated from the xml files, requires a new function to be added to osabi.{c,h} which can return a string representation of an 'enum gdb_osabi'. With that new function in place the features/ code is regenerated. This change is being made to support the next commit. In the next commit gdbserver will be updated to call set_tdesc_osabi in more cases. The problem is that gdbserver stores the osabi as a string. The issue here is that a typo in the gdbserver/ code might go unnoticed and result in gdbserver sending back an invalid osabi string. To fix this we want gdbserver to pass an 'enum gdb_osabi' to the set_tdesc_osabi function. With that requirement in place it seems to make sense if all calls to set_tdesc_osabi pass an 'enum gdb_osabi'. There should be no user visible changes after this commit. Approved-By: Luis Machado <luis.machado@arm.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-10-10gdb: split osabi support between gdb/ and gdbsupport/ directoriesAndrew Burgess5-6/+219
In future commits I want to call set_tdesc_osabi from gdbserver/ code. Currently the only version of set_tdesc_osabi available to gdbserver takes a string representing the osabi. The problem with this is that, having lots of calls to set_tdesc_osabi which all take a string is an invite for a typo to slip in. This typo could potentially go unnoticed until someone tries to debug the wrong combination of GDB and gdbserver, at which point GDB will fail to find the correct gdbarch because it doesn't understand the osabi string. It would be better if the set_tdesc_osabi calls in gdbserver could take an 'enum gdb_osabi' value and then convert this to the "correct" string internally. In this way we are guaranteed to always have a valid, known, osabi string. This commit splits the osabi related code, which currently lives entirely on the GDB side, between gdb/ and gdbsupport/. I've moved the enum definition along with the array of osabi names into gdbsupport/. Then all the functions that access the names list, and which convert between names and enum values are also moved. I've taken the opportunity of this move to add a '.def' file which contains all the enum names along with the name strings. This '.def' file is then used to create 'enum gdb_osabi' as well as the array of osabi name strings. By using a '.def' file we know that the enum order will always match the name string array. This commit is just a refactor, there are no user visible changes after this commit. This commit doesn't change how gdbserver sets the target description osabi string, that will come in the next commit. Approved-By: Luis Machado <luis.machado@arm.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-10-06[gdb] Fix common misspellingsTom de Vries2-3/+3
Fix the following common misspellings: ... accidently -> accidentally additonal -> additional addresing -> addressing adress -> address agaisnt -> against albiet -> albeit arbitary -> arbitrary artifical -> artificial auxillary -> auxiliary auxilliary -> auxiliary bcak -> back begining -> beginning cannonical -> canonical compatiblity -> compatibility completetion -> completion diferent -> different emited -> emitted emiting -> emitting emmitted -> emitted everytime -> every time excercise -> exercise existance -> existence fucntion -> function funtion -> function guarentee -> guarantee htis -> this immediatly -> immediately layed -> laid noone -> no one occurances -> occurrences occured -> occurred originaly -> originally preceeded -> preceded preceeds -> precedes propogate -> propagate publically -> publicly refering -> referring substract -> subtract substracting -> subtracting substraction -> subtraction taht -> that targetting -> targeting teh -> the thier -> their thru -> through transfered -> transferred transfering -> transferring upto -> up to vincinity -> vicinity whcih -> which whereever -> wherever wierd -> weird withing -> within writen -> written wtih -> with doesnt -> doesn't ... Tested on x86_64-linux.
2024-09-25gdb, gdbserver, python, testsuite: Remove MPX.Schimpe, Christina1-15/+2
GDB deprecated the commands "show/set mpx bound" in GDB 15.1, as Intel listed Intel(R) Memory Protection Extensions (MPX) as removed in 2019. MPX is also deprecated in gcc (since v9.1), the linux kernel (since v5.6) and glibc (since v2.35). Let's now remove MPX support in GDB completely. This includes the removal of: - MPX functionality including register support - deprecated mpx commands - i386 and amd64 implementation of the hooks report_signal_info and get_siginfo_type - tests - and pretty printer. We keep MPX register numbers to not break compatibility with old gdbservers. Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
2024-09-24btrace: Enable event tracing on Linux for Intel PT.Felix Willgerodt1-0/+3
Event tracing allows GDB to show information about interesting asynchronous events when tracing with Intel PT. Subsequent patches will add support for displaying each type of event. Enabling event-tracing unconditionally would result in rather noisy output, as breakpoints themselves result in interrupt events. Which is why this patch adds a set/show command to allow the user to enable/disable event-tracing before starting a recording. The event-tracing setting has no effect on an already active recording. The default setting is off. As event tracing will use the auxiliary infrastructure added by ptwrite, the user can still disable printing events, even when event-tracing was enabled, by using the /a switch for the record instruction-history/function-call-history commands. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Markus Metzger <markus.t.metzger@intel.com>
2024-09-24[gdb] Make scope_exit constructor throwTom de Vries1-0/+3
While reviewing "catch (...)" uses I came across: ... scope_exit (EFP &&f) try : m_exit_function ((!std::is_lvalue_reference<EFP>::value && std::is_nothrow_constructible<EF, EFP>::value) ? std::move (f) : f) { } catch (...) { /* "If the initialization of exit_function throws an exception, calls f()." */ f (); } ... and while looking up the origin of the comment here [1] I saw right after: ... throws: Nothing, unless the initialization of exit_function throws ... I think that means that the exception should be rethrown, so fix this by doing so. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com> [1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0052r5.pdf
2024-09-13gdbsupport/intrusive-list: add owning_intrusive_listSimon Marchi2-4/+173
It occured to me that `intrusive_list<solib>`, as returned by `solib_ops::current_sos`, for instance, is not very safe. The current_sos method returns the ownership of the solib objects (heap-allocated) to its caller, but the `intrusive_list<solib>` type does not convey it. If a function is building an `intrusive_list<solib>` and something throws, the solibs won't automatically be deleted. Introduce owning_intrusive_list to fill this gap. Interface --------- The interface of owning_intrusive_list is mostly equivalent to intrusive_list, with the following differences: - When destroyed, owning_intrusive_list deletes all element objects. The clear method does so as well. - The erase method destroys the removed object. - The push_front, push_back and insert methods accept a `unique_ptr<T>` (compared to `T &` for intrusive_list), taking ownership of the object. - owning_intrusive_list has emplace_front, emplace_back and emplace methods, allowing to allocate and construct an object directly in the list. This is really just a shorthand over std::make_unique and insert (or push_back / push_front if you don't care about the return value), but I think it is nicer to read: list.emplace (pos, "hello", 2); rather than list.insert (pos, std::make_unique<Foo> ("hello", 2)); These methods are not `noexcept`, since the allocation or the constructor could throw. - owning_intrusive_list has a release method, allowing to remove an element without destroying it. The release method returns a pair-like struct with an iterator to the next element in the list (like the erase method) and a unique pointer transferring the ownership of the released element to the caller. - owning_intrusive_list does not have a clear_and_dispose method, since that is typically used to manually free items. Implementation -------------- owning_intrusive_list privately inherits from intrusive_list, in order to re-use the linked list machinery. It adds ownership semantics around it. Testing ------- Because of the subtle differences in the behavior in behavior and what we want to test for each type of intrusive list, I didn't see how to share the tests for the two implementations. I chose to copy the intrusive_list tests and adjust them for owning_intrusive_list. The verify_items function was made common though, and it tries to dereference the items in the list, to make sure they have not been deleted by mistake (which would be caught by Valgrind / ASan). Change-Id: Idbde09c1417b79992a0a9534d6907433e706f760 Co-Authored-By: Pedro Alves <pedro@palves.net> Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-09-13gdbsupport/intrusive-list: make insert return an iteratorSimon Marchi1-5/+15
Make the insert method return an iterator to the inserted element. This mimics what boost does [1] and what the standard library insert methods generally do [2]. [1] https://www.boost.org/doc/libs/1_79_0/doc/html/boost/intrusive/list.html#idm33771-bb [2] https://en.cppreference.com/w/cpp/container/vector/insert Change-Id: I59082883492c60ee95e8bb29a18c9376283dd660 Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-09-13gdbsupport/intrusive-list: sprinkle noexceptSimon Marchi1-43/+43
Some methods of intrusive_list are marked noexcept. But really, everything in that file could be noexcept. Add it everywhere. The only one I had a doubt about is clear_and_dispose: what if the disposer throws? The boost equivalent [1] is noexcept and requires the disposer not to throw. The rationale is probably the same as for destructors. What if the disposer throws for an element in the middle of the list? Do you skip the remaining elements? Do you swallow the exception and keep calling the disposer for the remaining elements? It's simpler to say no exceptions allowed. [1] https://www.boost.org/doc/libs/1_79_0/doc/html/boost/intrusive/list.html#idm33710-bb Change-Id: I402646cb12c6b7906f4bdc2ad85203d8c8cdf2cc Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-09-07gdb: add another overload of startswithAndrew Burgess1-0/+10
We already have one overload of the startswith function that takes a std::string_view for both arguments. A later patch in this series is going to be improved by having an overload that takes one argument as a std::string_view and the other argument as a plain 'char *'. This commit adds the new overload, but doesn't make use of it (yet). There should be no user visible changes after this commit.
2024-08-19gdb: avoid '//' in filenames when searching for debuginfoAndrew Burgess2-7/+15
I spotted that the gdb.base/sysroot-debug-lookup.exp test that I added recently actually had a KPASS when run with the native-extended-gdbserver board. This was an oversight when adding the test. The failures in this test, when using the 'unix' board, are logged as bug PR gdb/31804. The problem appears to be caused by the use of the child_path function in find_separate_debug_file. What happens on the 'unix' board is that the file is specified to GDB with a target: prefix, however GDB spots that the target filesystem is local to GDB and so opens the file without a target: prefix. When we call into find_separate_debug_file the DIR and CANON_DIR arguments, which are computed from the objfile_name() no longer have a target: prefix. However, in this test if the file was opened with a target: prefix, then the sysroot also has a target: prefix. When child_path is called it looks for a common prefix between CANON_DIR (from the objfile_name) and the sysroot. However, the sysroot still has the target: prefix, which means the child_path() call fails and returns nullptr. What happens in the native-extended-gdbserver case is that GDB doesn't see the target filesystem as local. Now the filename retains the target: prefix, which means that in the child_path() call both the sysroot and the CANON_DIR have a target: prefix, and so the child_path() call succeeds. This allows GDB to progress, try some additional paths, and then find the debug information. So, this commit changes gdb.base/sysroot-debug-lookup.exp to expect the test to succeed when using the native-extended-gdbserver protocol. This leaves one KFAIL when using the native-extended-gdbserver board, we find the debug information but (apparently) find it in the wrong file. What's happening is that when GDB builds the filename for the debug information we end up with a '//' string as a directory separator, the test regexp only expects a single separator. Instead of just fixing the test regexp, I've updated the path_join function in gdbsupport/pathstuff.{cc,h} to allow for absolute paths to appear in the argument list after the first argument. This means it's now possible to do this: auto result = path_join ("/a/b/c", "/d/e/f"); gdb_assert (result == "/a/b/c/d/e/f"); Additionally I've changed path_join so that it avoids adding unnecessary directory separators. In the above case when the two paths were joined GDB only added a single separator between 'c' and 'd'. But additionally, if we did this: auto result = path_join ("/a/b/c/", "/d/e/f"); gdb_assert (result == "/a/b/c/d/e/f"); We'd still only get a single separator. With these changes to path_join I can now make use of this function in find_separate_debug_file. With this done I now have no KFAIL when using the native-extended-gdbserver board. After this commit we still have 2 KFAIL when not using the native-gdbserver and unix boards, these will be addressed in the next commit. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31804 Reviewed-By: Keith Seitz <keiths@redhat.com>
2024-08-14btrace, python: Enable ptwrite filter registration.Felix Willgerodt3-0/+16
By default GDB will be printing the hex payload of the ptwrite package as auxiliary information. To customize this, the user can register a ptwrite filter function in python, that takes the payload and the PC as arguments and returns a string which will be printed instead. Registering the filter function is done using a factory pattern to make per-thread filtering easier. Approved-By: Markus Metzger <markus.t.metzger@intel.com>
2024-08-14btrace, gdbserver: Add ptwrite to btrace_config_pt.Felix Willgerodt1-0/+6
This enables gdb and gdbserver to communicate about ptwrite support. If ptwrite support would be enabled unconditionally, GDBs with older libipt versions would break. Approved-By: Markus Metzger <markus.t.metzger@intel.com> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-08-12gdb, gdbsupport: use `using` in enum flags codeSimon Marchi1-15/+15
I think that `using` is easier to read than `typedef`, and it's the modern C++ thing anyway. Change-Id: Iccb62dc3869cddfb6a684ef3023dcd5b799f3ab2
2024-08-12gdbsupport: remove C enum flags fallbackSimon Marchi1-11/+0
This might have been useful during the C -> C++ conversion (not sure), but it doesn't appear useful today. I don't see when enum-flags.h would be used in a C context. Change-Id: I6c7ed655757248a62a1bf6615995f42e8aa2b4bd
2024-08-12gdbsupport: remove #ifndef REALTIME_LO in signals.ccSimon Marchi1-8/+6
REALTIME_LO was only possibly previously defined in config/nm-nto.h, which is now removed. So we can remove the #ifndef protecting against a redefinition of REALTIME_LO in gdbsupport/signals.cc. Change-Id: I021b9518ceaa6223bd480ff1e07e9a978b0b241e Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-08-02gdb, gdbserver, gdbsupport: remove -Wno-vla-cxx-extensionSimon Marchi2-2/+2
Now that all known uses of VLAs within GDB are removed, remove the `-Wno-vla-cxx-extension` (which was used to silence clang warnings) and add `-Wvla`, such that any use of a VLA will trigger a warning. Change-Id: I69a8d7f93f973743165b0ba46f9c2ea8adb89025 Reviewed-By: Keith Seitz <keiths@redhat.com>
2024-07-16gdb, gdbserver, gdbsupport: use [[noreturn]] instead of ATTRIBUTE_NORETURNSimon Marchi3-30/+27
C++ 11 has a built-in attribute for this, no need to use a compat macro. Change-Id: I90e4220d26e8f3949d91761f8a13cd9c37da3875 Reviewed-by: Lancelot Six <lancelot.six@amd.com>
2024-06-27gdb: add overloads of gdb_tilde_expandAndrew Burgess1-2/+16
Like the previous commit, add two overloads of gdb_tilde_expand, one takes std::string and other takes gdb::unique_xmalloc_ptr<char>. Make use of these overloads throughout GDB and gdbserver. There should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com>
2024-06-27gdb: add overloads of gdb_abspathAndrew Burgess1-0/+16
Add two overloads of gdb_abspath, one which takes std::string and one which takes gdb::unique_xmalloc_ptr<char>, then make use of these overloads throughout GDB and gdbserver. There should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com>
2024-06-24Remove hashtab_obstack_allocateTom Tromey4-53/+1
I think that hashtabs should never be obstack-allocated. In the past this was convenient sometimes, because any new data structure needed a corresponding cleanup. However, with the switch to C++, resource management has become much simpler; for example, a local variable can simply be of type htab_up rather than hashtab_t, and the problem is solved. This patch removes hashtab_obstack_allocate to try to prevent this anti-pattern from being used again.
2024-06-20Revert "Remove LIBINTL_DEP"Alan Modra2-0/+3
This reverts commit e874cbd3879843a83e4bcc4b54cd7107387b1df6. The patch was wrong. LIBINTL_DEP is needed with an in-tree gettext.
2024-06-20Remove LIBINTL_DEPAlan Modra2-3/+0
The intl directory in the source no longer exists. LIBINTL_DEP is thus always empty. Remove references to it. config/ * gettext-sister.m4: Don't AC_SUBST LIBINTL_DEP. bfd/ * Makefile.in: Regenerate. * configure: Regenerate. binutils/ * Makefile.am (*_DEPENDENCIES): Remove LIBINTL_DEP. * Makefile.in: Regenerate. * configure: Regenerate. gas/ * Makefile.am (as_new_DEPENDENCIES): Remove LIBINTL_DEP. * Makefile.in: Regenerate. * configure: Regenerate. gdb/ * Makefile.in (INTL_DEPS): Don't set or reference. * configure: Regenerate. gdbserver/ * Makefile.in (INTL_DEPS): Don't set or reference. gdbsupport/ * Makefile.in: Regenerate. * configure: Regenerate. gold/ * Makefile.am (deps_var): Remove LIBINTL_DEP. (incremental_dump_DEPENDENCIES, dwp_DEPENDENCIES): Likewise. * Makefile.in: Regenerate. * configure: Regenerate. * testsuite/Makefile.am (DEPENDENCIES): Remove LIBINTL_DEP. * testsuite/Makefile.in: Regenerate. gprof/ * Makefile.am (gprof_DEPENDENCIES): Remove LIBINTL_DEP. * Makefile.in: Regenerate. * configure: Regenerate. ld/ * Makefile.am (ld_new_DEPENDENCIES): Remove LIBINTL_DEP. * Makefile.in: Regenerate. * configure: Regenerate. libctf/ * Makefile.in: Regenerate. * configure: Regenerate. opcodes/ * configure.ac (BUILD_LIBS): Remove LIBINTL. (BUILD_LIB_DEPS): Remove LIBINTL_DEP. * Makefile.in: Regenerate. * configure: Regenerate.
2024-06-14gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definitionAndrew Burgess1-0/+20
Share the definition of I386_LINUX_XSAVE_XCR0_OFFSET between GDB and gdbserver. This commit moves the definition into gdbsupport/x86-xstate.h, which allows the #define to be shared. There should be no user visible changes after this commit. Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
2024-06-10autoupdate: add square brackets around arguments of AC_INITMatthieu Longo1-1/+1
https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fINIT-2
2024-06-10autoupdate: replace obsolete macros AC_CONFIG_HEADERMatthieu Longo1-1/+1
- AC_CONFIG_HEADER by AC_CONFIG_HEADERS https://www.gnu.org/software/automake/manual/1.12.2/html_node/Obsolete-Macros.html#index-AM_005fCONFIG_005fHEADER
2024-06-07gdb: remove get_exec_fileSimon Marchi1-5/+0
I believe that the get_exec_file function is unnecessary, and the code can be simplified if we remove it. Consider for instance when you "run" a program on Linux with native debugging. 1. run_command_1 obtains the executable file from `current_program_space->exec_filename ()` 2. it passes it to `run_target->create_inferior()`, which is `inf_ptrace_target::create_inferior()` in this case, which then passes it to `fork_inferior()` 3. `fork_inferior()` then has a fallback, where if the passed exec file is nullptr, it gets its from `get_exec_file()`. 4. `get_exec_file()` returns `current_program_space->exec_filename ()` - just like the things we started with - or errors out if the current program space doesn't have a specified executable. If there's no exec filename passed in step 1, there's not going to be any in step 4, so it seems pointless to call `get_exec_file()`, we could just error out when `exec_file` is nullptr. But we can't error out directly in `fork_inferior()`, since the error is GDB-specific, and that function is shared with GDBserver. Speaking of GDBserver, all code paths that lead to `fork_inferior()` provide a non-nullptr exec file. Therefore, to simplify things: - Make `fork_inferior()` assume that the passed exec file is not nullptr, don't call `get_exec_file()` - Change some targets (darwin-nat, go32-nat, gnu-nat, inf-ptrace, nto-procfs, procfs) to error out when the exec file passed to their create_inferior method is nullptr. Some targets are fine with a nullptr exec file, so we can't check that in `run_command_1()`. - Add the `no_executable_specified_error()` function, which re-uses the error message that `get_exec_file()` had. - Change some targets (go32-nat, nto-procfs) to not call `get_exec_file()`, since it's pointless for the same reason as in the example above, if it returns, it's going the be the same value as the `exec_file` parameter. Just rely on `exec_file`. - Remove the final use of `get_exec_file()`, in `load_command()`. - Remove the `get_exec_file()` implementations in GDB and GDBserver and remove the shared declaration. Change-Id: I601c16498e455f7baa1f111a179da2f6c913baa3 Approved-By: Tom Tromey <tom@tromey.com>
2024-06-07gdb: replace `get_exec_file (0)` calls with ↵Simon Marchi1-3/+3
`current_program_space->exec_filename ()` Calls of `get_exec_file (0)` are equivalent to just getting the exec filename from the current program space. I'm looking to remove `get_exec_file`, so replace these uses with `current_program_space->exec_filename ()`. Remove the `err` parameter of `get_exec_wrapper` since all the calls that remain pass 1, meaning to error out if no executable is specified. Change-Id: I7729ea4c7f03dbb046211cc5aa3858ab3a551965 Approved-By: Tom Tromey <tom@tromey.com>
2024-05-16Stop 'configure --enable-threading' if std::thread doesn't workPedro Alves2-6/+21
Currently, if you configure gdb with explicit --enable-threading, but then configure detects std::thread does not work, configure silently disables threading support and continues configuring. This patch makes that scenario cause a configuration error, like so: $ /home/pedro/gdb/src/configure --enable-threading && make ... configure: error: std::thread does not work; disable threading make[1]: *** [Makefile:11225: configure-gdbsupport] Error 1 make[1]: Leaving directory '/home/pedro/gdb/build-windows-threads' make: *** [Makefile:1041: all] Error 2 $ Additionally, if you don't explicitly pass --enable-threading, and std::thread does not work, we will now get a warning (and the build continues): $ /home/pedro/gdb/src/configure && make ... configure: WARNING: std::thread does not work; disabling threading ... This is similar to how we handle --enable-tui and missing curses. The code and error/warning messages were borrowed from there. Change-Id: I73a8b580d1e2a796b23136920c0e181408ae1b22 Approved-By: Tom Tromey <tom@tromey.com>
2024-05-06Fix build issues with mingw toolchainBernd Edlinger2-0/+2
With a x86_64-pc-mingw32 toolchain there is a build issue whether or not the --disable-threading option is used. The problem happens because _WIN32_WINNT is defined to 0x501 before #include <mutex> which makes the compilation abort due to missing support for __gthread_cond_t in std_mutex.h, which is conditional on _WIN32_WINNT >= 0x600. Fix the case when --disable-threading is used, by only including <mutex> in gdb/complaints.c when STD_CXX_THREAD is defined. Additionally make the configure script try to #include <mutex> to automatically select --disable-threading when the header file is not able to compile. Approved-By: Tom Tromey <tom@tromey.com>
2024-04-22gdb: move RequireLongest to gdbsupport/traits.hSimon Marchi1-0/+4
Move it out of defs.h. Change-Id: Ie1743d41a57f81667650048563e66073c72230cf Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-04-21Use std::vector in event-loop.ccTom Tromey1-39/+18
In my occasional and continuing campaign against realloc, this patch changes event-loop.cc to use std::vector to keep track of pollfd objects. Regression tested on x86-64 Fedora 38. Approved-By: Simon Marchi <simon.marchi@efficios.com> Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-04-18gdbsupport: constify some return values in print-utils.{h,cc}Simon Marchi2-18/+18
There is no reason the callers of these functions need to change the returned string, so change the `char *` return types to `const char *`. Update a few callers to also use `const char *`. Change-Id: I94adff574d5e1b326e8cc688cf1817a15b408b96 Approved-By: Tom Tromey <tom@tromey.com>
2024-04-17gdbsupport, gdbserver, gdb: use -Wno-vla-cxx-extensionSimon Marchi2-0/+2
When building with clang 18, I see: CXX aarch64-linux-tdep.o /home/smarchi/src/binutils-gdb/gdb/aarch64-linux-tdep.c:1299:26: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension] 1299 | gdb_byte za_zeroed[za_bytes]; | ^~~~~~~~ /home/smarchi/src/binutils-gdb/gdb/aarch64-linux-tdep.c:1299:26: note: read of non-const variable 'za_bytes' is not allowed in a constant expression /home/smarchi/src/binutils-gdb/gdb/aarch64-linux-tdep.c:1282:10: note: declared here 1282 | size_t za_bytes = std::pow (sve_vl_from_vg (svg), 2); | ^ Since we are using VLAs right now, that warning doesn't make sense for us. add `-Wno-vla-cxx-extension` to the list of warning flags we try to enable. If we ever choose to disallow VLAs, we can remove that flag. Change-Id: Ie41feafc50c343f6e75333d4f836ce32fbeb6d8c
2024-03-26gdb, gdbserver, gdbsupport: remove includes of early headersSimon Marchi40-40/+0
Now that defs.h, server.h and common-defs.h are included via the `-include` option, it is no longer necessary for source files to include them. Remove all the inclusions of these files I could find. Update the generation scripts where relevant. Change-Id: Ia026cff269c1b7ae7386dd3619bc9bb6a5332837 Approved-By: Pedro Alves <pedro@palves.net>