aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
AgeCommit message (Collapse)AuthorFilesLines
28 hours[gdb/contrib] Drop two words from codespell-ignore-words.txtTom de Vries2-2/+2
Tom Tromey mentioned [1] that the words "invokable" and "useable" present in codespell-ignore-words.txt should be dropped. Do so and fix the following typos: ... $ codespell --config gdbsupport/setup.cfg gdbsupport gdbsupport/common-debug.h:218: invokable ==> invocable gdbsupport/event-loop.cc:84: useable ==> usable ... Approved-By: Tom Tromey <tom@tromey.com> [1] https://sourceware.org/pipermail/gdb-patches/2025-March/216584.html
32 hours[gdbsupport] Ignore pathc in codespell check in gdb_tilde_expand.ccTom de Vries1-2/+2
Ignore the following codespell detections: ... $ codespell --config gdbsupport/setup.cfg gdbsupport gdbsupport/gdb_tilde_expand.cc:54: pathc ==> patch gdbsupport/gdb_tilde_expand.cc:99: pathc ==> patch ... by adding codespell:ignore comments.
32 hours[gdbsupport] Fix a typo in common-debug.hTom de Vries1-1/+1
Fix a typo: ... $ codespell --config gdbsupport/setup.cfg gdbsupport/common-debug.h gdbsupport/common-debug.h:109: re-used ==> reused ...
8 days[gdbsupport] Fix typo in common-inferior.hTom de Vries1-1/+1
Fix the following typo: ... $ codespell --config gdbsupport/setup.cfg gdbsupport/ gdbsupport/common-inferior.h:57: elemets ==> elements ...
10 daysgdb: split up construct_inferior_argumentsAndrew Burgess2-46/+107
The function construct_inferior_arguments (gdbsupport/common-inferior.cc) currently escapes all special shell characters. After this commit there will be two "levels" of quoting: 1. The current "full" quoting, where all posix shell special characters are quoted, and 2. a new "reduced" quoting, where only the characters that GDB sees as special (quotes and whitespace) are quoted. After this, almost all construct_inferior_arguments calls will use the "full" quoting, which is the current quoting. The "reduced" quoting will be used in this commit to restore the behaviour that was lost in the previous commit (more details below). In the future, the reduced quoting will be useful for some additional inferior argument that I have planned. I already posted my full inferior argument work here: https://inbox.sourceware.org/gdb-patches/cover.1730731085.git.aburgess@redhat.com But that series is pretty long, and wasn't getting reviewed, so I'm posted the series in parts now. Before the previous commit, GDB behaved like this: $ gdb -eiex 'set startup-with-shell off' --args /tmp/exec '$FOO' (gdb) show args Argument list to give program being debugged when it is started is "$FOO". Notice that with 'startup-with-shell' off, the argument was left as just '$FOO'. But after the previous commit, this changed to: $ gdb -eiex 'set startup-with-shell off' --args /tmp/exec '$FOO' (gdb) show args Argument list to give program being debugged when it is started is "\$FOO". Now the '$' is escaped with a backslash. This commit restores the original behaviour, as this is (currently) the only way to unquoted shell special characters into arguments from the GDB command line. The series that I listed above includes a new command line option for GDB which provides a better approach for controlling the quoting of special shell characters, but that work requires these patches to be merged first. I've split out the core of construct_inferior_arguments into the new function escape_characters, which takes a set of characters to escape. Then the two functions escape_shell_characters and escape_gdb_characters call escape_characters with the appropriate character sets. Finally, construct_inferior_arguments, now takes a boolean which indicates if we should perform full shell escaping, or just perform the reduced escaping. I've updated all uses of construct_inferior_arguments to pass a suitable value to indicate what escaping to perform (mostly just 'true', but one case in main.c is different), also I've updated inferior::set_args to take the same boolean flag, and pass it through to construct_inferior_arguments. Tested-By: Guinevere Larsen <guinevere@redhat.com>
10 daysgdb: remove the !startup_with_shell path from construct_inferior_argumentsAndrew Burgess1-67/+41
In the commit: commit 0df62bf09ecf242e3a932255d24ee54407b3c593 Date: Fri Oct 22 07:19:33 2021 +0000 gdb: Support some escaping of args with startup-with-shell being off nat/fork-inferior.c was updated such that when we are starting an inferior without a shell we now remove escape characters. The benefits of this are explained in that commit, but having made this change we can now make an additional change. Currently, in construct_inferior_arguments, when startup_with_shell is false we construct the inferior argument string differently than when startup_with_shell is true; when true we apply some escaping to special shell character, when false we don't. This commit simplifies construct_inferior_arguments by removing the !startup_with_shell case, and instead we now apply escaping in all cases. This is fine because, thanks to the above commit the escaping will be correctly removed again when we call into nat/fork-inferior.c. We should think of construct_inferior_arguments and nat/fork-inferior.c as needing to cooperate in order for argument handling to work correctly. construct_inferior_arguments converts a list of separate arguments into a single string, and nat/fork-inferior.c splits that single string back into a list of arguments. It is critical that, if nat/fork-inferior.c is expecting to remove a "layer" of escapes, then construct_inferior_arguments must add that expected "layer", otherwise, we end up stripping more escapes than expected. The great thing (I think) about the new configuration, is that GDB no longer cares about startup_with_shell at the point the arguments are being setup. We only care about startup_with_shell at the point that the inferior is started. This means that a user can set the inferior arguments, and then change the startup-with-shell setting, and GDB will do what they expect. Under the previous system, where construct_inferior_arguments changed its behaviour based on startup_with_shell, the user had to change the setting, and then set the arguments, otherwise, GDB might not do what they expect. There is one slight issue with this commit though, which will be addressed by the next commit. For GDB's native targets construct_inferior_arguments is reached via two code paths; first when GDB starts and we combine arguments from the command line, and second when the Python API is used to set the arguments from a sequence. It's the command line argument handling which we are interested in. Consider this: $ gdb --args /tmp/exec '$FOO' (gdb) show args Argument list to give program being debugged when it is started is "\$FOO". Notice that the argument has become \$FOO, the '$' is now quoted. This is because, by quoting the argument in the shell command that started GDB, GDB was passed a literal $FOO with no quotes. In order to ensure that the inferior sees this same value, GDB added the extra escape character. When GDB starts with a shell we pass \$FOO, which results in the inferior seeing a literal $FOO. But what if the user _actually_ wanted to have the shell GDB uses to start the inferior expand $FOO? Well, it appears this can't be done from the command line, but from the GDB prompt we can just do: (gdb) set args $FOO (gdb) show args Argument list to give program being debugged when it is started is "$FOO". And now the inferior will see the shell expanded version of $FOO. It might seem like we cannot achieve the same result from the GDB command line, however, it is possible with this trick: $ gdb -eiex 'set startup-with-shell off' --args /tmp/exec '$FOO' (gdb) show args Argument list to give program being debugged when it is started is "$FOO". (gdb) show startup-with-shell Use of shell to start subprocesses is off. And now the $FOO is not escaped, but GDB is no longer using a shell to start the inferior, however, we can extend our command line like this: $ gdb -eiex 'set startup-with-shell off' \ -ex 'set startup-with-shell on' \ --args /tmp/exec '$FOO' (gdb) show args Argument list to give program being debugged when it is started is "$FOO". (gdb) show startup-with-shell Use of shell to start subprocesses is on. Use an early-initialisation option to disable startup-with-shell, this is done before command line argument processing, then a normal initialisation option turns startup-with-shell back on after GDB has processed the command line arguments! Is this useful? Yes, absolutely. Is this a good user experience? Absolutely not. And I plan to add a new command line option to GDB (and gdbserver) that will allow users to achieve the same result (this trick doesn't work in gdbserver as there's no early-initialisation there) without having to toggle the startup-with-shell option. The new option can be found in the series here: https://inbox.sourceware.org/gdb-patches/cover.1730731085.git.aburgess@redhat.com The problem is that, that series is pretty long, and getting it reviewed is just not possible. So instead I'm posting the individual patches in smaller blocks, to make reviews easier. So, what's the problem? Well, by removing the !startup_with_shell code path from GDB, there is no longer a construct_inferior_arguments code path that doesn't quote inferior arguments, and so there's no longer a way, from the command line, to set an unquoted '$FOO' as an inferior argument. Obviously, this can still be done from GDB's CLI prompt. The trick above is completely untested, so this regression isn't going to show up in the testsuite. And the breakage is only temporary. In the next commit I'll add a fix which restores the above trick. Of course, I hope that this fix will itself, only be temporary. Once the new command line options that I mentioned above are added, then the fix I add in the next commit can be removed, and user should start using the new command line option. After this commit a whole set of tests that were added as xfail in the above commit are now passing. A change similar to this one can be found in this series: https://inbox.sourceware.org/gdb-patches/20211022071933.3478427-1-m.weghorn@posteo.de/ which I reviewed before writing this patch. I don't think there's any one patch in that series that exactly corresponds with this patch though, so I've listed the author of the original series as co-author on this patch. Co-Authored-By: Michael Weghorn <m.weghorn@posteo.de> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28392 Tested-By: Guinevere Larsen <guinevere@redhat.com>
11 daysgdbsupport: add some -Wunused-* warning flagsSimon Marchi2-0/+12
Add a few -Wunused-* diagnostic flags that look useful. Some are known to gcc, some to clang, some to both. Fix the fallouts. -Wunused-const-variable=1 is understood by gcc, but not clang. -Wunused-const-variable would be undertsood by both, but for gcc at least it would flag the unused const variables in headers. This doesn't make sense to me, because as soon as one source file includes a header but doesn't use a const variable defined in that header, it's an error. With `=1`, gcc only warns about unused const variable in the main source file. It's not a big deal that clang doesn't understand it though: any instance of that problem will be flagged by any gcc build. Change-Id: Ie20d99524b3054693f1ac5b53115bb46c89a5156 Approved-By: Tom Tromey <tom@tromey.com>
11 daysgdbsupport: re-format and sort warning flagsSimon Marchi2-24/+40
Put them one per line and sort alphabetically. Change-Id: Idb6947d444dc6e556a75645b04f97a915bba7a59 Approved-By: Tom Tromey <tom@tromey.com>
2025-03-12Use correct types in string-set.hTom Tromey1-2/+2
My earlier patch to introduce string-set.h used the wrong type in the hash functions. This patch fixes the error.
2025-03-10Add string cache and use it in cooked indexTom Tromey1-0/+129
The cooked index needs to allocate names in some cases -- when canonicalizing or when synthesizing Ada package names. This process currently uses a vector of unique_ptrs to manage the memory. Another series I'm writing adds another spot where this allocation must be done, and examining the result showed that certain names were allocated multiple times. To clean this up, this patch introduces a string cache object and changes the cooked indexer to use it. I considered using bcache here, but bcache doesn't work as nicely with string_view -- because bcache is fundamentally memory-based, a temporary copy of the contents must be made to ensure that bcache can see the trailing \0. Furthermore, writing a custom class lets us avoid another copy when canonicalizing C++ names. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-03-10Fix check-include-guards.pyTom Tromey1-3/+3
I noticed that check-include-guards.py doesn't error in certain situations -- but in situations where the --update flag would cause a file to be changed. This patch changes the script to issue an error for any discrepancy. It also fixes the headers that weren't correct. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-03-06[gdbsupport] Add codespell section in setup.cfgTom de Vries1-0/+4
When running codespell on gdbsupport, we get: ... $ codespell gdbsupport gdbsupport/common-debug.h:218: invokable ==> invocable gdbsupport/osabi.h:51: configury ==> configurable gdbsupport/ChangeLog-2020-2021:344: ro ==> to, row, rob, rod, roe, rot gdbsupport/ChangeLog-2020-2021:356: contaning ==> containing gdbsupport/common.m4:19: configury ==> configurable gdbsupport/Makefile.am:97: configury ==> configurable gdbsupport/Makefile.in:811: configury ==> configurable gdbsupport/event-loop.cc:84: useable ==> usable gdbsupport/configure:15904: assigment ==> assignment ... Some of these files we want to skip in a spell check, because they're generated. We also want to skip ChangeLogs, we don't actively maintain those. Add a file gdbsupport/setup.cfg with a codespell section, that skips those files. The choice for setup.cfg (rather than say .codespellrc) comes from the presence of gdb/setup.cfg. That leaves invokable, configury and useable. I think configury is a common expression in our context, and for invokable and useable I don't manage to find out whether they really need rewriting, so I'd rather leave them alone for now. Add these to a file gdb/contrib/codespell-ignore-words.txt, and use the file in gdbsupport/setup.cfg. This makes the directory codespell clean: ... $ codespell --config gdbsupport/setup.cfg gdbsupport $ ... Because codespell seems to interpret filenames relative to the working directory rather than relative to the config file, and the filename used in gdbsupport/setup.cfg is gdb/contrib/codespell-ignore-words.txt, this simple invocation doesn't work: ... $ cd gdbsupport $ codespell ... because codespell can't find gdbsupport/gdb/contrib/codespell-ignore-words.txt. We could fix this by using ../gdb/contrib/codespell-ignore-words.txt instead, but likewise that breaks this invocation: ... $ codespell --config gdbsupport/setup.cfg gdbsupport ... I can't decide which one is worse, so I'm sticking with gdb/contrib/codespell-ignore-words.txt for now. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-03-06[gdbsupport] Fix some typosTom de Vries3-4/+4
Fix typos: ... mentionning -> mentioning suppported -> supported aligment -> alignment ...
2025-02-27gdb, gdbserver, gdbsupport: fix some namespace comment formattingSimon Marchi2-9/+9
I noticed a // namespace selftests comment, which doesn't follow our comment formatting convention. I did a find & replace to fix all the offenders. Change-Id: Idf8fe9833caf1c3d99e15330db000e4bab4ec66c
2025-02-25Fix mkdir_recursive on windows when CWD is rootCiaran Woodward1-0/+7
On windows, when creating a directory with an absolute path, mkdir_recursive would start by trying to make 'C:'. On windows, this has a special meaning, which is "the current directory on the C drive". So the first thing it tries to do is create the current directory. Most of the time, this fails with EEXIST, so the function continues as expected. However if the current directory is C:/, trying to create that causes EPERM, which causes the function to prematurely terminate. (The same applies for any drive letter.) This patch resolves this issue, by skipping the drive letter so that it is never sent to the mkdir call. Approved-By: Tom Tromey <tom@tromey.com>
2025-02-10gdbsupport: add gdb::make_array_view overload to create from an arraySimon Marchi1-0/+9
I think this overload will be useful for the following reasons. Consider a templated function like this: template <typename T> void func(gdb::array_view<T> view) {} Trying to pass an array to this function doesn't work, as template argument deduction fails: test.c:698:8: error: no matching function for call to ‘func(int [12])’ 698 | func (array); | ~~~~~^~~~~~~ test.c:686:6: note: candidate: ‘template<class T> void func(gdb::array_view<U>)’ 686 | void func(gdb::array_view<T> view) {} | ^~~~ test.c:686:6: note: template argument deduction/substitution failed: test.c:698:8: note: mismatched types ‘gdb::array_view<U>’ and ‘int*’ 698 | func (array); | ~~~~~^~~~~~~ Similarly, trying to compare a view with an array doesn't work. This: int array[12]; gdb::array_view<int> view; if (view == array) {} ... fails with: test.c:698:8: error: no matching function for call to ‘func(int [12])’ 698 | func (array); | ~~~~~^~~~~~~ test.c:686:6: note: candidate: ‘template<class T> void func(gdb::array_view<U>)’ 686 | void func(gdb::array_view<T> view) {} | ^~~~ test.c:686:6: note: template argument deduction/substitution failed: test.c:698:8: note: mismatched types ‘gdb::array_view<U>’ and ‘int*’ 698 | func (array); | ~~~~~^~~~~~~ With this new overload, we can do: func (gdb::make_array_view (array)); and if (view == gdb::make_array_view (array)) {} This is not ideal, I wish that omitting `gdb::make_array_view` would just work, but at least it allows creating an array view and have the element type automatically deduced from the array type. If someone knows how to make these cases "just work", I would be happy to know how. Change-Id: I6a71919d2d5a385e6826801d53f5071b470fef5f Approved-By: Tom Tromey <tom@tromey.com>
2025-01-29gdbserver: introduce and use new gdb::argv_vec classAndrew Burgess1-0/+139
In gdbserver there are a couple of places where we perform manual memory management using a 'std::vector<char *>' with the vector owning the strings within it. We need to take care to call free_vector_argv() before leaving the scope to cleanup the strings within the vector. This commit introduces a new class gdb::argv_vec which wraps around a 'std::vector<char *>' and owns the strings within the vector, taking care to xfree() them when the gdb::argv_vec is destroyed. Right now I plan to use this class in gdbserver. But this class will also be used to address review feedback on this commit: https://inbox.sourceware.org/gdb-patches/72227f1c5a2e350ca70b2151d1b91306a0261bdc.1736860317.git.aburgess@redhat.com where I tried to introduce another 'std::vector<char *>' which owns the strings. That patch will be updated to use gdb::argv_vec instead. The obvious question is, instead of introducing this new class, could we change the APIs to avoid having a std::vector<char *> that owns the strings? Could we use 'std::vector<std::string>' or 'std::vector<gdb::unique_xmalloc_ptr<char>>' instead? The answer is yes we could. I originally posted this larger patch set: https://inbox.sourceware.org/gdb-patches/cover.1730731085.git.aburgess@redhat.com however, getting a 14 patch series reviewed is just not possible, so instead, I'm posting the patches one at a time. The earlier patch I mentioned is pulled from the larger series. The larger series already includes changes to gdbserver which removes the need for the 'std::vector<char *>', however, getting those changes in depends (I think) on the patch I mention above. Hence we have a bit of a circular dependency. My proposal is to merge this patch (adding gdb::argv_vec) and make use of it in gdbserver. Then I'll update the patch above to also use gdb::argv_vec, which will allow the above patch to get reviewed and merged. Then I'll post, and hopefully merge additional patches from my larger inferior argument series, which will remove the need for gdb::argv_vec from gdbserver. At this point, the only use of gdb::argv_vec will be in the above patch, where I think it will remain, as I don't think that location can avoid using 'std::vector<char *>'. Approved-By: Tom Tromey <tom@tromey.com>
2025-01-10[gdb/build, c++20] Fix build with gcc 10Tom de Vries1-2/+2
With gcc 10 and -std=c++20, we run into the same problem as reported in commit 6feae66da1d ("[gdb/build, c++20] Handle deprecated std::allocator::construct"). The problem was fixed using: ... -template<typename T, typename A = std::allocator<T>> +template<typename T, + typename A +#if __cplusplus >= 202002L + = std::pmr::polymorphic_allocator<T> +#else + = std::allocator<T> +#endif + > ... but that doesn't work for gcc 10, because it defines __cplusplus differently: ... $ echo | g++-10 -E -dD -x c++ - -std=c++20 2>&1 | grep __cplusplus #define __cplusplus 201709L $ echo | g++-11 -E -dD -x c++ - -std=c++20 2>&1 | grep __cplusplus #define __cplusplus 202002L ... Fix this by using the library feature test macro __cpp_lib_polymorphic_allocator [1], which is undefined for c++17 and defined for c++20: ... $ echo | g++-10 -E -dD -x c++ - -include memory_resource -std=c++17 2>&1 \ | grep __cpp_lib_polymorphic_allocator $ echo | g++-10 -E -dD -x c++ - -include memory_resource -std=c++20 2>&1 \ | grep __cpp_lib_polymorphic_allocator #define __cpp_lib_polymorphic_allocator 201902L $ ... A similar problem exists for commit 3173529d7de ("[gdb/guile, c++20] Work around Werror=volatile in libguile.h"). Fix this by testing for 201709L instead. Tested on x86_64-linux, by building gdb with {gcc 10, clang 17.0.6} x {-std=c++17, -std=c++20}. PR build/32503 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32503 Approved-By: Tom Tromey <tom@tromey.com> [1] https://en.cppreference.com/w/cpp/feature_test#cpp_lib_polymorphic_allocator
2025-01-08GDB, gdbserver: Convert regcache_register_size function to methodThiago Jung Bauermann1-15/+5
The regcache_register_size function has one implementation in GDB, and one in gdbserver. Both of them have a gdb::checked_static_cast to their corresponding regcache class. This can be avoided by defining a pure virtual register_size method in the reg_buffer_common class, which is then implemented by the reg_buffer class in GDB, and by the regcache class in gdbserver. Calls to the register_size () function from methods of classes in the reg_buffer_common hierarchy need to be changed to calls to the newly defined method, otherwise the compiler complains that a matching method cannot be found. Co-Authored-By: Simon Marchi <simon.marchi@efficios.com> Approved-By: Simon Marchi <simon.marchi@efficios.com> Reviewed-By: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> Change-Id: I7f4f74a51e96c42604374e87321ca0e569bc07a3
2025-01-06Simplify traits.h using C++17Tom Tromey1-46/+9
This patch simplifies gdbsupport/traits.h by reusing some C++17 type traits. I kept the local names, since they are generally better. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31423 Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-12-22Fix -Wenum-constexpr-conversion in enum-flags.hCarlos Galvez1-34/+69
This fixes PR 31331: https://sourceware.org/bugzilla/show_bug.cgi?id=31331 Currently, enum-flags.h is suppressing the warning -Wenum-constexpr-conversion coming from recent versions of Clang. This warning is intended to be made a compiler error (non-downgradeable) in future versions of Clang: https://github.com/llvm/llvm-project/issues/59036 The rationale is that casting a value of an integral type into an enumeration is Undefined Behavior if the value does not fit in the range of values of the enum: https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1766 Undefined Behavior is not allowed in constant expressions, leading to an ill-formed program. In this case, in enum-flags.h, we are casting the value -1 to an enum of a positive range only, which is UB as per the Standard and thus not allowed in a constexpr context. The purpose of doing this instead of using std::underlying_type is because, for C-style enums, std::underlying_type typically returns "unsigned int". However, when operating with it arithmetically, the enum is promoted to *signed* int, which is what we want to avoid. This patch solves this issue as follows: * Use std::underlying_type and remove the custom enum_underlying_type. * Ensure that operator~ is called always on an unsigned integer. We do this by casting the input enum into std::size_t, which can fit any unsigned integer. We have the guarantee that the cast is safe, because we have checked that the underlying type is unsigned. If the enum had negative values, the underlying type would be signed. This solves the issue with C-style enums, but also solves a hidden issue: enums with underlying type of std::uint8_t or std::uint16_t are *also* promoted to signed int. Now they are all explicitly casted to the largest unsigned int type and operator~ is safe to use. * There is one more thing that needs fix. Currently, operator~ is implemented as follows: return (enum_type) ~underlying(e); After applying ~underlying(e), the result is a very large value, which we then cast to "enum_type". This cast is Undefined Behavior if the large value does not fit in the range of the enum. For C++ enums (scoped and/or with explicit underlying type), the range of the enum is the entire range of the underlying type, so the cast is safe. However, for C-style enums, the range is the smallest bit-field that can hold all the values of the enumeration. So the range is a lot smaller and casting a large value to the enum would invoke Undefined Behavior. To solve this problem, we create a new trait EnumHasFixedUnderlyingType, to ensure operator~ may only be called on C++-style enums. This behavior is roughly the same as what we had on trunk, but relying on different properties of the enums. * Once this is implemented, the following tests fail to compile: CHECK_VALID (true, int, true ? EF () : EF2 ()) This is because it expects the enums to be promoted to signed int, instead of unsigned int (which is the true underlying type). I propose to remove these tests altogether, because: - The comment nearby say they are not very important. - Comparing 2 enums of different type like that is strange, relies on integer promotions and thus hurts readability. As per comments in the related PR, we likely don't want this type of code in gdb code anyway, so there's no point in testing it. - Most importantly, this type of comparison will be ill-formed in C++26 for regular enums, so enum_flags does not need to emulate that. Since this is the only place where the warning was suppressed, remove also the corresponding macro in include/diagnostics.h. The change has been tested by running the entire gdb test suite (make check) and comparing the results (testsuite/gdb.sum) against trunk. No noticeable differences have been observed. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31331 Tested-by: Keith Seitz <keiths@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
2024-12-18Run check-include-guards.pyTom Tromey81-243/+243
This patch is the result of running check-include-guards.py on the current tree. Running it a second time causes no changes. Reviewed-By: Tom de Vries <tdevries@suse.de>
2024-12-17gdbsupport: fix a typo in a comment in common-regcache.hTankut Baris Aktemur1-4/+4
Fix a typo. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-12-09gdb: allow core file containing special characters on the command lineAndrew Burgess2-0/+26
After the commit: commit 03ad29c86c232484f9090582bbe6f221bc87c323 Date: Wed Jun 19 11:14:08 2024 +0100 gdb: 'target ...' commands now expect quoted/escaped filenames it was no longer possible to pass GDB the name of a core file containing any special characters (white space or quote characters) on the command line. For example: $ gdb -c /tmp/core\ file.core Junk after filename "/tmp/core": file.core (gdb) The problem is that the above commit changed the 'target core' command to expect quoted filenames, so before the above commit a user could write: (gdb) target core /tmp/core file.core [New LWP 2345783] Core was generated by `./mkcore'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x0000000000401111 in ?? () (gdb) But after the above commit the user must write: (gdb) target core /tmp/core\ file.core or (gdb) target core "/tmp/core file.core" This is part of a move to make GDB's filename argument handling consistent. Anyway, the problem with the '-c' command line flag is that it forwards the filename unmodified through to the 'core-file' command, which in turn forwards to the 'target core' command. So when the user, at a shell writes: $ gdb -c "core file.core" this arrives in GDB as the unquoted string 'core file.core' (without the single quotes). GDB then forwards this to the 'core-file' command as if the user had written this at a GDB prompt: (gdb) core-file core file.core Which then fails to parse due to the unquoted white space between 'core' and 'file.core'. The solution I propose is to escape any special characters in the core file name passed from the command line before calling 'core-file' command from main.c. I've updated the corefile.exp test to include a test for passing a core file containing a white space character. While I was at it I've modernised the part of corefile.exp that I was touching.
2024-12-06gdb, gdbserver, gdbsupport: remove some unused gdb_vecs.h includesSimon Marchi1-1/+0
Remove some includes reported as unused by clangd. Add some to files that actually need it. Change-Id: I01c61c174858c1ade5cb54fd7ee1f582b17c3363
2024-12-04[gdb/build] Fix build breaker on mingw-w64Simon Marchi4-0/+31
The mingw-w64 build breaks currently: ... In file included from gdb/cli/cli-cmds.c:58: gdbsupport/eintr.h: In function ‘pid_t gdb::waitpid(pid_t, int*, int)’: gdbsupport/eintr.h:77:35: error: ‘::waitpid’ has not been declared; \ did you mean ‘gdb::waitpid’? 77 | return gdb::handle_eintr (-1, ::waitpid, pid, wstatus, options); | ^~~~~~~ | gdb::waitpid gdbsupport/eintr.h:75:1: note: ‘gdb::waitpid’ declared here 75 | waitpid (pid_t pid, int *wstatus, int options) | ^~~~~~~ ... This is a regression since commit 658a03e9e85 ("[gdbsupport] Add gdb::{waitpid,read,write,close}"), which moved the use of ::waitpid from run_under_shell, where it was used conditionally: ... #if defined(CANT_FORK) || \ (!defined(HAVE_WORKING_VFORK) && !defined(HAVE_WORKING_FORK)) ... #else ... int ret = gdb::handle_eintr (-1, ::waitpid, pid, &status, 0); ... to gdb::waitpid, where it's used unconditionally: ... inline pid_t waitpid (pid_t pid, int *wstatus, int options) { return gdb::handle_eintr (-1, ::waitpid, pid, wstatus, options); } ... Likewise for ::wait. Guard these uses with HAVE_WAITPID and HAVE_WAIT. Reproduced and tested by doing a mingw-w64 cross-build on x86_64-linux. Reported-By: Simon Marchi <simark@simark.ca> Co-Authored-By: Tom de Vries <tdevries@suse.de>
2024-12-02gdb, gdbserver, gdbsupport: flatten and sort some list in configure filesSimon Marchi2-15/+76
This makes the lists easier sort read and modify. There are no changes in the generated config.h files, so I'm confident this brings no functional changes. Change-Id: Ib6b7fc532bcd662af7dbb230070fb1f4fc75f86b
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>