aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2022-06-09gdb/arm: Document and fix exception stack offsetsYvan Roux1-4/+61
Add a description of exception entry context stacking and fix next frame offset (at 0xA8 relative to R0 location) as well as FPU registers ones (starting at 0x68 relative to R0). Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com> Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-09gdb/arm: Simplify logic for updating addressesYvan Roux1-4/+5
Small performance improvement by fetching previous SP value only once before the loop and reuse it to avoid fetching at every iteration. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com> Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-09Fix ARM_CC_FOR_TARGET handlingPedro Alves1-2/+2
The previous patch that introduced the arm_cc_for_target procedure moved the ARM_CC_FOR_TARGET global check to that procedure, but forgot to tell tcl that ARM_CC_FOR_TARGET is a global. As a result, specifying ARM_CC_FOR_TARGET on the command line actually does nothing. This fixes it. Change-Id: I4e33b7633fa665e2f7b8f8c9592a949d74a19153
2022-06-09gdb/arm: Terminate unwinding when LR is 0xffffffffYvan Roux1-0/+11
ARMv7-M Architecture Reference "A2.3.1 Arm core registers" states that LR is set to 0xffffffff on reset. ARMv8-M Architecture Reference "B3.3 Registers" states that LR is set to 0xffffffff on warm reset if Main Extension is implemented, otherwise the value is unknown. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com> Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-09gdb/testsuite: solve problems with compiler_info cachingAndrew Burgess1-11/+17
After this commit: commit 44d469c5f85a4243462b8966722dafa62b602bf5 Date: Tue May 31 16:43:44 2022 +0200 gdb/testsuite: add Fortran compiler identification to GDB Some regressions were noticed: https://sourceware.org/pipermail/gdb-patches/2022-May/189673.html The problem is associated with how compiler_info variable is cached between calls to get_compiler_info. Even before the above commit, get_compiler_info supported two language, C and C++. Calling get_compiler_info would set the global compiler_info based on the language passed as an argument to get_compiler_info, and, in theory, compiler_info would not be updated for the rest of the dejagnu run. This obviously is slightly broken behaviour. If the first call to get_compiler_info was for the C++ language then compiler_info would be set based on the C++ compiler in use, while if the first call to get_compiler_info was for the C language then compiler_info would be set based on the C compiler. This probably wasn't very noticable, assuming a GCC based test environment then in most cases the C and C++ compiler would be the same version. However, if the user starting playing with CC_FOR_TARGET or CXX_FOR_TARGET, then they might not get the behaviour they expect. Except, to make matters worse, most of the time, the user probably would get the behaviour they expected .... except when they didn't! I'll explain: In gdb.exp we try to avoid global variables leaking between test scripts, this is done with the help of the two procs gdb_setup_known_globals and gdb_cleanup_globals. All known globals are recorded before a test script starts, and then, when the test script ends, any new globals are deleted. Normally, compiler_info is only set as a result of a test script calling get_compiler_info or test_compiler_info. This means that the compiler_info global will not exist when the test script starts, but will exist when the test script end, and so, the compiler_info variable is deleted at the end of each test. This means that, in reality, the compiler_info is recalculated once for each test script, hence, if a test script just checks on the C compiler, or just checks on the C++ compiler, then compiler_info will be correct and the user will get the behaviour they expect. However, if a single test script tries to check both the C and C++ compiler versions then this will not work (even before the above commit). The situation is made worse be the behaviour or the load_lib proc. This proc (provided by dejagnu) will only load each library once. This means that if a library defines a global, then this global would normally be deleted at the end of the first test script that includes the library. As future attempts to load the library will not actually reload it, then the global will not be redefined and would be missing for later test scripts that also tried to load that library. To work around this issue we override load_lib in gdb.exp, this new version adds all globals from the newly loaded library to the list of globals that should be preserved (not deleted). And this is where things get interesting for us. The library trace-support.exp includes calls, at the file scope, to things like is_amd64_regs_target, which cause get_compiler_info to be called. This means that after loading the library the compiler_info global is defined. Our override of load_lib then decides that this new global has to be preserved, and adds it to the gdb_persistent_globals array. From that point on compiler_info will never be recomputed! This commit addresses all the caching problems by doing the following: Change the compiler_info global into compiler_info_cache global. This new global is an array, the keys of this array will be each of the supported languages, and the values will be the compiler version for that language. Now, when we call get_compiler_info, if the compiler information for the specific language has not been computed, then we do that, and add it to the cache. Next, compiler_info_cache is defined by calling gdb_persistent_global. This automatically adds the global to the list of persistent globals. Now the cache will not be deleted at the end of each test script. This means that, for a single test run, we will compute the compiler version just once for each language, this result will then be cached between test scripts. Finally, the legacy 'gcc_compiled' flag is now only set when we call get_compiler_info with the language 'c'. Without making this change the value of 'gcc_compiled' would change each time a new language is passed to get_compiler_info. If the last language was e.g. Fortran, then gcc_compiled might be left false.
2022-06-09gdb/testsuite: handle errors better in test_compiler_infoAndrew Burgess1-1/+11
Now that get_compiler_info might actually fail (if the language is not handled), then we should try to handle this failure better in test_compiler_info. After this commit, if get_compiler_info fails then we will return a suitable result depending on how the user called test_compiler_info. If the user does something like: set version [test_compiler_info "" "unknown-language"] Then test_compiler_info will return an empty string. My assumption is that the user will be trying to match 'version' against something, and the empty string hopefully will not match. If the user does something like: if { [test_compiler_info "some_pattern" "unknown-language"] } { .... } Then test_compiler_info will return false which seems the obvious choice. There should be no change in the test results after this commit.
2022-06-09gdb/testsuite: make 'c' default language for get/test compiler infoAndrew Burgess1-8/+13
This commit is a minor cleanup for the two functions (in gdb.exp) get_compiler_info and test_compiler_info. Instead of using the empty string as the default language, and just "knowing" that this means the C language. Make this explicit. The language argument now defaults to "c" if not specified, and the if chain in get_compiler_info that checks the language not explicitly handles "c" and gives an error for unknown languages. This is a good thing, now that the API appears to take a language, if somebody does: test_compiler_info "xxxx" "rust" to check the version of the rust compiler then we will now give an error rather than just using the C compiler and leaving the user having to figure out why they are not getting the results they expect. After a little grepping, I think the only place we were explicitly passing the empty string to either get_compiler_info or test_compiler_info was in gdb_compile_shlib_1, this is now changed to pass "c" as the default language. There should be no changes to the test results after this commit.
2022-06-09gdb/testsuite: remove get_compiler_info calls from gdb.exp and dwarf.expAndrew Burgess2-30/+1
We don't need to call get_compiler_info before calling test_compiler_info; test_compiler_info includes a call to get_compiler_info. This commit cleans up lib/gdb.exp and lib/dwarf.exp a little by removing some unneeded calls to get_compiler_info. We could do the same cleanup throughout the testsuite, but I'm leaving that for another day. There should be no change in the test results after this commit.
2022-06-09gdb/testsuite: use test_compiler_info in gcc_major_versionNils-Christian Kempke1-2/+1
The procedure gcc_major_version was earlier using the global variable compiler_info to retrieve gcc's major version. This is discouraged and (as can be read in a comment in compiler.c) compiler_info should be local to get_compiler_info and test_compiler_info. The preferred way of getting the compiler string is via calling test_compiler_info without arguments. Gcc_major_version was changed to do that.
2022-06-09gdb: add Yvan Roux to gdb/MAINTAINERSYvan Roux1-0/+1
2022-06-09gdb/testsuite: resolve duplicate test names in gdb.threads/tls.expAndrew Burgess1-1/+4
While running the gdb.threads/tls.exp test with a GDB configured without Python, I noticed some duplicate test names. This is caused by a call to skip_python_tests that is within a proc that is called multiple times by the test script. Each call to skip_python_tests results in a call to 'unsupported', and this causes the duplicate test names. After this commit we now call skip_python_tests just once and place the result into a variable. Now, instead of calling skip_python_tests multiple times, we just check the variable. There should be no change in what is tested after this commit.
2022-06-09gdb/testsuite: resolve duplicate test name in gnu_vector.expAndrew Burgess1-9/+11
While testing on AArch64 I spotted a duplicate test name in the gdb.base/gnu_vector.exp test. This commit adds a 'with_test_prefix' to resolve the duplicate. While I was in the area I updated a 'gdb_test_multiple' call to make use of $gdb_test_name. There should be no change in what is tested after this commit.
2022-06-08gdb: make throw_perror_with_name staticAndrew Burgess2-4/+1
The throw_perror_with_name function is not used outside of utils.c right now. And as perror_with_name is just a wrapper around throw_perror_with_name, then any future calls would be to perror_with_name. Lets make throw_perror_with_name static. There should be no user visible changes after this commit.
2022-06-08gdb: remove trailing '.' from perror_with_name callsAndrew Burgess6-36/+36
I ran into this error while working on AArch64 GDB: Unable to fetch VFP registers.: Invalid argument. Notice the '.:' in the middle of this error message. This is because of this call in aarch64-linux-nat.c: perror_with_name (_("Unable to fetch VFP registers.")); The perror_with_name function take a string, and adds ': <message>' to the end the string, so I don't think the string that we pass to perror_with_name should end in '.'. This commit removes all of the trailing '.' characters from perror_with_name calls, which give more readable error messages. I don't believe that any of these errors are tested in the testsuite (after a little grepping).
2022-06-08Move CU queue to dwarf2_per_objfileTom Tromey2-14/+14
The CU queue is a member of dwarf2_per_bfd, but it is only used when expanding CUs. Also, the dwarf2_per_objfile destructor checks the queue -- however, if the per-BFD object is destroyed first, this will not work. This was pointed out Lancelot as fallout from the patch to rewrite the registry system. This patch avoids this problem by moving the queue to the per-objfile object.
2022-06-08Change allocation of m_dwarf2_cusTom Tromey2-16/+13
m_dwarf2_cus manually manages the 'dwarf2_cu' pointers it owns. This patch simplifies the code by changing it to use unique_ptr.
2022-06-08Fix gdb.arch/powerpc-power7.exp isel disassembly output.Carl Love1-1/+1
The following commit changes the output format for the isel instruction on PowerPC. commit dd4832bf3efc1bd1797a6b9188260692b8b0db52 Introduces error in test Author: Dmitry Selyutin <ghostmansd@gmail.com> Date: Tue May 24 13:46:35 2022 +0000 opcodes: introduce BC field; fix isel Per Power ISA Version 3.1B 3.3.12, isel uses BC field rather than CRB field present in binutils sources. Also, per 1.6.2, BC has the same semantics as BA and BB fields, so this should keep the same flags and mask, only with the different offset. opcodes/ * ppc-opc.c (BC): Define new field, with the same definition as CRB field, but with the PPC_OPERAND_CR_BIT flag present. gas/ * testsuite/gas/ppc/476.d: Update. * testsuite/gas/ppc/a2.d: Update. * testsuite/gas/ppc/e500.d: Update. * testsuite/gas/ppc/power7.d: Update. <snip> --- a/gas/testsuite/gas/ppc/476.d +++ b/gas/testsuite/gas/ppc/476.d @@ -209,7 +209,7 @@ Disassembly of section \.text: .*: (7c 20 07 8c|8c 07 20 7c) ici 1 .*: (7c 03 27 cc|cc 27 03 7c) icread r3,r4 .*: (50 83 65 36|36 65 83 50) rlwimi r3,r4,12,20,27 -.*: (7c 43 27 1e|1e 27 43 7c) isel r2,r3,r4,28 +.*: (7c 43 27 1e|1e 27 43 7c) isel r2,r3,r4,4\*cr7\+lt The above change breaks the gdb regression test gdb.arch/powerpc-power7.exp on Power 7, Power 8, Power 9 and Power 10. This patch updates the regression test gdb.arch/powerpc-power7.exp with the new expected output for the isel instruction. The patch has been tested on Power 7 and Power 10 to verify the patch fixes the test.
2022-06-08aarch64: Add fallback if ARM_CC_FOR_TARGET not setPedro Alves3-4/+59
On Aarch64, you can set ARM_CC_FOR_TARGET to point to the 32-bit compiler to use when testing gdb.multi/multi-arch.exp and gdb.multi/multi-arch-exec.exp. If you don't set it, then those testcases don't run. I guess that approximately nobody remembers to set ARM_CC_FOR_TARGET. This commit adds a fallback. If ARM_CC_FOR_TARGET is not set, and testing for Linux, try arm-linux-gnueabi-gcc, arm-none-linux-gnueabi-gcc, arm-linux-gnueabihf-gcc as 32-bit compilers, making sure that the produced executable runs on the target machine before claiming that the compiler produces useful executables. Change-Id: Iefe5865d5fc84b4032eaff7f4c5c61582bf75c39
2022-06-07Use subclasses of windows_process_infoTom Tromey2-180/+180
This changes windows_process_info to use virtual methods for its callbacks, and then changes the two clients of this code to subclass this class to implement the methods. I considered using CRTP here, but that would require making the new structures visible to the compilation of of nat/windows-nat.c. This seemed like a bit of a pain, so I didn't do it. This change then lets us change all the per-inferior globals to be members of the new subclass. Note that there can still only be a single inferior -- currently there's a single global of the new type. This is just another step toward possibly implementing multi-inferior for Windows. It's possible this could be cleaned up further... ideally I'd like to move more of the data into the base class. However, because gdb supports Cygwin and gdbserver does not, and because I don't have a way to build or test Cygwin, larger refactorings are difficult.
2022-06-07Turn some windows-nat.c static functions into methodsTom Tromey1-19/+28
This patch turns some windows-nat.c static functions into methods on windows_nat_target. This avoids having to reference the windows_nat_target singleton in some more spots -- a minor code cleanup.
2022-06-07Allow ASLR to be disabled on WindowsTom Tromey4-4/+158
On Windows, it is possible to disable ASLR when creating a process. This patch adds code to do this, and hooks it up to gdb's existing disable-randomization feature. Because the Windows documentation cautions that this isn't available on all versions of Windows, the CreateProcess wrapper function is updated to make the attempt, and then fall back to the current approach if it fails.
2022-06-07Introduce wrapper for CreateProcessTom Tromey3-18/+70
This is a small refactoring that introduces a wrapper for the Windows CreateProcess function. This is done to make the next patch a bit simpler.
2022-06-07Update my email address in gdb/MAINTAINERSEnze Li1-1/+1
2022-06-07Constify solib_name_from_addressTom Tromey4-6/+6
I noticed that solib_name_from_address returned a non-const string, but it's more appropriate to return const. This patch implements this. Tested by rebuilding.
2022-06-07[gdb/rust] Add missing _() for error callTom de Vries1-1/+1
In commit 1390b65a1b9 ("[gdb/rust] Fix literal truncation") I forgot to add _() around a string using in an error call. Fix this by adding the missing _(). Tested on x86_64-linux.
2022-06-07[gdb] Allow frv::fr300 in selftestsTom de Vries1-6/+0
In skip_arch in gdb/selftest-arch.c we skip architecture fr300 because of PR20946, but the PR has been fixed by commit 0ae60c3ef45 ("Prevent an abort in the FRV disassembler if the target bfd name is unknown.") in Januari 2017. Remove the skipping of frv::fr300. Tested on x86_64-linux.
2022-06-06Consolidate "Python API" sections in NEWSTom Tromey1-7/+5
I noticed that the gdb NEWS file had two "Python API" sections in "Changes since GDB 12". This patch consolidates the two. I chose to preserve the second one, first because it is longer, and second because I felt that user command changes should come before API changes.
2022-06-06Simplify varobj "change" logicTom Tromey1-5/+2
varobj used to store 'print_value' as a C string, where NULL was a valid value, and so it had logic to handle this situation. However, at some point this was changed to be a std::string, and so the code can be simplified in this spot.
2022-06-06Remove "-break-insert -r" testsTom Tromey2-76/+0
PR mi/14270 points out that mi-break.exp has some tests for an unimplemented "-r" switch for "-break-insert". This switch was never implemented, and is not documented -- though it is mentioned in a comment in the documentation. This patch removes the test and the doc comment. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=14270
2022-06-06[gdb] Name arch selftests more clearlyTom de Vries1-5/+22
When running some all archs selftest I get: ... $ gdb -q -batch -ex "maint selftest unpack_field_as_long" Running selftest unpack_field_as_long::A6. ... By now I know that A6 is an arc architecture, but for others that's less clear. Fix this by using unpack_field_as_long::arc::A6 instead. This then introduces redundant names like arm::arm, so try to avoid those, though I'm not entirely convinced that that's worth the trouble. This introduces the following new names: ... +Running selftest unpack_field_as_long::am33_2::am33-2. +Running selftest unpack_field_as_long::arc::A6. +Running selftest unpack_field_as_long::arc::A7. +Running selftest unpack_field_as_long::arc::EM. +Running selftest unpack_field_as_long::arc::HS. +Running selftest unpack_field_as_long::arm::ep9312. +Running selftest unpack_field_as_long::arm::iwmmxt. +Running selftest unpack_field_as_long::arm::iwmmxt2. +Running selftest unpack_field_as_long::arm::xscale. +Running selftest unpack_field_as_long::bpf::xbpf. +Running selftest unpack_field_as_long::frv::fr400. +Running selftest unpack_field_as_long::frv::fr450. +Running selftest unpack_field_as_long::frv::fr500. +Running selftest unpack_field_as_long::frv::fr550. +Running selftest unpack_field_as_long::frv::simple. +Running selftest unpack_field_as_long::frv::tomcat. +Running selftest unpack_field_as_long::iq2000::iq10. +Running selftest unpack_field_as_long::m32c::m16c. +Running selftest unpack_field_as_long::mep::c5. +Running selftest unpack_field_as_long::mep::h1. +Running selftest unpack_field_as_long::nds32::n1. +Running selftest unpack_field_as_long::nds32::n1h. +Running selftest unpack_field_as_long::nds32::n1h_v2. +Running selftest unpack_field_as_long::nds32::n1h_v3. +Running selftest unpack_field_as_long::nds32::n1h_v3m. +Running selftest unpack_field_as_long::z80::ez80-adl. +Running selftest unpack_field_as_long::z80::ez80-z80. +Running selftest unpack_field_as_long::z80::gbz80. +Running selftest unpack_field_as_long::z80::r800. +Running selftest unpack_field_as_long::z80::z180. ... Tested on x86_64-linux.
2022-06-06[gdb] Enable some more print_one_insn selftestsTom de Vries1-0/+18
In print_one_insn_test we have this cluster of skipped tests: ... case bfd_arch_ia64: case bfd_arch_mep: case bfd_arch_mips: case bfd_arch_tic6x: case bfd_arch_xtensa: return; ... Enable some of these, and document in more detail why they're enabled or skipped. Likewise, document bfd_arch_or1k because it's an odd case. Tested on x86_64-linux.
2022-06-06[gdb] Fix maint selftest -v print_one_insnTom de Vries1-8/+2
When running the print_one_insn selftests with -v, I get: ... $ gdb -q -batch -ex "maint selftest -v print_one_insn" Running selftest print_one_insn::A6. .shor 0x783eRunning selftest print_one_insn::A7. trap_s 0x1Running selftest print_one_insn::ARC600. .shor 0x783eRunning selftest print_one_insn::ARC601. Running selftest print_one_insn::ARC700. trap_s 0x1Running selftest print_one_insn::ARCv2. trap_s 0x1Running selftest print_one_insn::EM. trap_s 0x1Running selftest print_one_insn::HS. trap_s 0x1Running selftest print_one_insn::Loongarch32. ... The insn is written to gdb_stdout, and there is code in the selftest to add a newline after the insn, which writes to stream(). The stream() ui_file points into a string buffer, which the disassembler uses before writing to gdb_stdout, so writing into it after the disassembler has finished has no effect. Fix this by using gdb_stdlog and debug_printf (which is what the unit test infrastructure itself uses) instead, such that we have: ... Running selftest print_one_insn::A6. .shor 0x783e Running selftest print_one_insn::A7. trap_s 0x1 Running selftest print_one_insn::ARC600. .shor 0x783e Running selftest print_one_insn::ARC601. Running selftest print_one_insn::ARC700. trap_s 0x1 Running selftest print_one_insn::ARCv2. trap_s 0x1 Running selftest print_one_insn::Loongarch32. ... Note: I've also removed the printing of arch_name, which would give us otherwise the redundant: ... Running selftest print_one_insn::A6. arc .shor 0x783e Running selftest print_one_insn::A7. arc trap_s 0x1 ... Tested on x86_64-linux.
2022-06-06gdb/testsuite: add missing skip_python_tests call in py-doc-reformat.expAndrew Burgess1-0/+4
In commit: commit 51e8dbe1fbe7d8955589703140ca5eba7b4f1bd7 Date: Mon May 16 19:26:54 2022 +0100 gdb/python: improve formatting of help text for user defined commands the test that was added (gdb.python/py-doc-reformat.exp) was missing a call to skip_python_tests. As a result, this test would fail for any GDB built within Python support. This commit adds a call to skip_python_tests.
2022-06-05Remove obsolete Python 2 commentTom Tromey1-7/+0
I found a comment that referred to Python 2, but that is now obsolete -- the code it refers to is gone. I'm checking in this patch to remove the comment. There's a similar comment elsewhere, but I plan to remove that one in another patch I'm going to submit shortly.
2022-06-04[gdb/ada] Fix literal truncationTom de Vries2-7/+24
Make sure we error out on overflow instead of truncating in all cases. Tested on x86_64-linux, with a build with --enable-targets=all.
2022-06-04[gdb/m2] Fix UB and literal truncationTom de Vries2-26/+24
Rewrite parse_number to use ULONGEST instead of LONGEST, to fix UB errors as mentioned in PR29163. Furthermore, make sure we error out on overflow instead of truncating in all cases. Tested on x86_64-linux, with a build with --enable-targets=all. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29163
2022-06-04[gdb/rust] Fix literal truncationTom de Vries2-3/+7
Make sure we error out on overflow instead of truncating in all cases. I've used as overflow string: "Integer literal is too large", based on what I found at <rust-lang/rust>/src/test/ui/parser/int-literal-too-large-span.rs but perhaps someone has a better idea. Tested on x86_64-linux, with a build with --enable-targets=all.
2022-06-04[gdb/pascal] Fix literal truncationTom de Vries2-73/+30
Make sure we error out on overflow instead of truncating in all cases. The current implementation of parse_number contains a comment about PR16377, but that's related to C-like languages. In absence of information of whether the same fix is needed for pascal, take the conservative approach and keep behaviour for decimals unchanged. Tested on x86_64-linux, with a build with --enable-targets=all.
2022-06-04[gdb/go] Fix literal truncationTom de Vries2-67/+30
Make sure we error out on overflow instead of truncating in all cases. The current implementation of parse_number contains a comment about PR16377, but that's related to C-like languages. In absence of information of whether the same fix is needed for go, take the conservative approach and keep behaviour for decimals unchanged. Tested on x86_64-linux, with a build with --enable-targets=all.
2022-06-04[gdb/fortran] Fix literal truncationTom de Vries2-19/+16
As mentioned in commit 5b758627a18 ("Make gdb.base/parse_number.exp test all architectures"): ... There might be a bug that 32-bit fortran truncates 64-bit values to 32-bit, given "p/x 0xffffffffffffffff" returns "0xffffffff". ... More concretely, we have: ... $ for arch in i386:x86-64 i386; do \ gdb -q -batch -ex "set arch $arch" -ex "set lang fortran" \ -ex "p /x 0xffffffffffffffff"; \ done The target architecture is set to "i386:x86-64". $1 = 0xffffffffffffffff The target architecture is set to "i386". $1 = 0xffffffff ... Fix this by adding a range check in parse_number in gdb/f-exp.y. Furthermore, make sure we error out on overflow instead of truncating in all other cases. Tested on x86_64-linux.
2022-06-04[gdb/c] Fix type of 2147483648 and literal truncationTom de Vries4-76/+130
[ Assuming arch i386:x86-64, sizeof (int) == 4, sizeof (long) == sizeof (long long) == 8. ] Currently we have (decimal for 0x80000000): ... (gdb) ptype 2147483648 type = unsigned int ... According to C language rules, unsigned types cannot be used for decimal constants, so the type should be long instead (reported in PR16377). Fix this by making sure the type of 2147483648 is long. The next interesting case is (decimal for 0x8000000000000000): ... (gdb) ptype 9223372036854775808 type = unsigned long ... According to the same rules, unsigned long is incorrect. Current gcc uses __int128 as type, which is allowed, but we don't have that available in gdb, so the strict response here would be erroring out with overflow. Older gcc without __int128 support, as well as clang use an unsigned type, but with a warning. Interestingly, clang uses "unsigned long long" while gcc uses "unsigned long", which seems the better choice. Given that the compilers allow this as a convience, do the same in gdb and keep type "unsigned long", and make this explicit in parser and test-case. Furthermore, make sure we error out on overflow instead of truncating in all cases. Tested on x86_64-linux with --enable-targets=all. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16377
2022-06-04[gdb/testsuite] Test more values in gdb.base/parse_numbers.expTom de Vries1-42/+260
Currently we only test value 0xffffffffffffffff in test-case gdb.base/parse_numbers.exp. Test more interesting values, both in decimal and hex format, as well as negative decimals for language modula-2. This results in an increase in total tests from 15572 to 847448 (55 times more tests). Balance out the increase in runtime by reducing the number of architectures tested: only test one architecture per sizeof longlong/long/int/short combination, while keeping the possibility intact to run with all architectures (through setting a variable in the test-case) Results in slight reduction of total tests: 15572 -> 13853. Document interesting cases in the expected results: - wrapping from unsigned to signed - truncation - PR16377: using unsigned types to represent decimal constants in C Running the test-case with a gdb build with -fsanitize=undefined, we trigger two UB errors in the modula-2 parser, filed as PR29163. Tested on x86_64-linux with --enable-targets=all.
2022-06-04[gdb/testsuite] Fix ERROR in gdb.ctf/funcreturn.expTom de Vries1-14/+12
On openSUSE Tumbleweed (with gcc-12, enabling ctf tests) I run into: ... ERROR: tcl error sourcing src/gdb/testsuite/gdb.ctf/funcreturn.exp. ERROR: tcl error code NONE ERROR: Unexpected arguments: \ {print v_double_func} \ {[0-9]+ = {double \(\)} 0x[0-9a-z]+.*} \ {print double function} \ } ... The problem is a curly brace as fourth argument to gdb_test, which errors out due to recently introduced more strict argument checking in gdb_test. Fix the error by removing the brace. Though this fixes the error for me, due to PR29160 I get only FAILs, so I can't claim proper testing on x86_64-linux.
2022-06-04[gdb/testsuite] Fix gdb.threads/manythreads.exp with check-read1Tom de Vries1-15/+19
When running test-case gdb.threads/manythreads.exp with check-read1, I ran into this hard-to-reproduce FAIL: ... [New Thread 0x7ffff7318700 (LWP 31125)]^M [Thread 0x7ffff7321700 (LWP 31124) exited]^M [New T^C^M ^M Thread 769 "manythreads" received signal SIGINT, Interrupt.^M [Switching to Thread 0x7ffff6d66700 (LWP 31287)]^M 0x00007ffff7586a81 in clone () from /lib64/libc.so.6^M (gdb) FAIL: gdb.threads/manythreads.exp: stop threads 1 ... The matching in the failing gdb_test_multiple is done in an intricate way, trying to pass on some order and fail on another order. Fix this by rewriting the regexps to match one line at most, and detecting invalid order by setting and checking state variables. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29177
2022-06-04[gdb] Fix warning in print_one_insn::ez80-adlTom de Vries1-0/+7
When running selftest print_one_insn::ez80-adl we run into this warning: ... Running selftest print_one_insn::ez80-adl. warning: Unable to determine inferior's software breakpoint type: couldn't find `_break_handler' function in inferior. Will be used default software \ breakpoint instruction RST 0x08. ... Fix this by explicitly handling bfd_arch_z80 in print_one_insn_test. Tested on x86_64-linux.
2022-06-03Use bool for evregpy_no_listeners_pTom Tromey2-2/+2
I noticed that evregpy_no_listeners_p should return a bool. This patch makes this change. I'm checking it in.
2022-06-03[gdb] Fix warning in foreach_arch selftestsTom de Vries4-9/+76
When running the selftests, I run into: ... $ gdb -q -batch -ex "maint selftest" ... Running selftest execute_cfa_program::aarch64:ilp32. warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default aarch64:ilp32 settings. ... and likewise for execute_cfa_program::i8086 and execute_cfa_program::ia64-elf32. The warning can easily be reproduced outside the selftests by doing: ... $ gdb -q -batch -ex "set arch aarch64:ilp32" ... and can be prevented by first doing "set osabi none". Fix the warning by setting osabi to none while doing selftests that iterate over all architectures. This causes a regression in the print_one_insn selftests for the ARC architecture. The problem is pre-existing, and can be demonstrated (already without this patch) using: ... $ gdb -q -batch -ex "set osabi none" -ex "maint selftest print_one_insn::A6" Running selftest print_one_insn::A6. Self test failed: Cannot access memory at address 0x0 Ran 1 unit tests, 1 failed $ ... For ARC, we use the generic case in print_one_insn_test, containing this code: ... int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, &pc); ... insn = gdbarch_sw_breakpoint_from_kind (gdbarch, kind, &bplen); ... The problem is that with osabi linux we trigger: ... static int arc_linux_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) { return trap_size; } ... but with osabi none: ... arc_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) { size_t length_with_limm = gdb_insn_length (gdbarch, *pcptr); ... which needs access to memory, and will consequently fail. Fix this in print_one_insn_test, in the default case, by iterating over supported osabi's to makes sure we trigger arc_linux_breakpoint_kind_from_pc which will give us a usable instruction to disassemble. Tested on x86_64-linux.
2022-06-03Revert "[gdb] Fix warning in foreach_arch selftests"Tom de Vries3-68/+13
This reverts commit fc18b1c5afd ("[gdb] Fix warning in foreach_arch selftests"). The commit introduced regressions for an --enable-targets=all build: ... Running selftest print_one_insn::A6.^M Self test failed: Cannot access memory at address 0x0^M ... and while investigating those I realized that the commit fc18b1c5afd complicates things by trying to set the current osabi. So, revert the patch in preparation for a simpler solution. Tested on x86_64-linux.
2022-06-02gdb: LoongArch: Remove nonportable #includeRoland McGrath1-1/+0
Don't use gregset.h in *-tdep.c since it's not usable on hosts that don't have <sys/procfs.h>. It's not needed by this file, and should only be needed by *-nat.c files.
2022-06-02[gdb/testsuite] Detect change instead of init in gdb.mi/mi-var-block.expTom de Vries2-1/+7
On openSUSE Tumbleweed with target board unix/-m32, I run into: ... PASS: gdb.mi/mi-var-block.exp: step at do_block_test 2 Expecting: ^(-var-update \*[^M ]+)?(\^done,changelist=\[{name="foo",in_scope="true",type_changed="false",has_more="0"}, {name="cb",in_scope="true",type_changed="false",has_more="0"}\][^M ]+[(]gdb[)] ^M [ ]*) -var-update *^M ^done,changelist=[{name="foo",in_scope="true",type_changed="false",has_more="0"}]^M (gdb) ^M FAIL: gdb.mi/mi-var-block.exp: update all vars: cb foo changed (unexpected output) ... The problem is that the test-case attempts to detect a change in the cb variable caused by this initialization: ... void do_block_tests () { int cb = 12; ... but that only works if the stack location happens to be unequal to 12 before the initialization. Fix this by first initializing to 0, and then changing the value to 12: ... - int cb = 12; + int cb = 0; + cb = 12; ... and detecting that change. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29195