aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
AgeCommit message (Collapse)AuthorFilesLines
2022-07-19[AArch64] MTE corefile supportLuis Machado2-0/+327
Teach GDB how to dump memory tags for AArch64 when using the gcore command and how to read memory tag data back from a core file generated by GDB (via gcore) or by the Linux kernel. The format is documented in the Linux Kernel documentation [1]. Each tagged memory range (listed in /proc/<pid>/smaps) gets dumped to its own PT_AARCH64_MEMTAG_MTE segment. A section named ".memtag" is created for each of those segments when reading the core file back. To save a little bit of space, given MTE tags only take 4 bits, the memory tags are stored packed as 2 tags per byte. When reading the data back, the tags are unpacked. I've added a new testcase to exercise the feature. Build-tested with --enable-targets=all and regression tested on aarch64-linux Ubuntu 20.04. [1] Documentation/arm64/memory-tagging-extension.rst (Core Dump Support)
2022-07-19[AArch64] Fix testcase compilation failureLuis Machado1-5/+10
Newer distros carry newer headers that contains MTE definitions. Account for that fact in the MTE testcases (gdb.arch/aarch64-mte.exp) and define constants conditionally to prevent compilation failures.
2022-07-18Add gdb.free_objfile event registryTom Tromey3-0/+139
Currently, Python code can use event registries to detect when gdb loads a new objfile, and when gdb clears the objfile list. However, there's no way to detect the removal of an objfile, say when the inferior calls dlclose. This patch adds a gdb.free_objfile event registry and arranges for an event to be emitted in this case.
2022-07-18Put gdb.base/bt-on-fatal-signal.exp GDB cores in output dirPedro Alves1-0/+5
I noticed that gdb.base/bt-on-fatal-signal.exp was contributing four core files to the count of unexpected core files: $ make check TESTS="gdb.base/bt-on-fatal-signal.exp" === gdb Summary === # of unexpected core files 4 # of expected passes 21 These are GDB core dumps. They are expected, however, because the whole point of the testcase is to crash GDB with a signal. Make GDB change its current directory to the output dir just before crashing, so that the core files end up there. The result is now: === gdb Summary === # of expected passes 25 and: $ find . -name "core.*" ./testsuite/outputs/gdb.base/bt-on-fatal-signal/core.gdb.1676506.nelson.1657727692 ./testsuite/outputs/gdb.base/bt-on-fatal-signal/core.gdb.1672585.nelson.1657727671 ./testsuite/outputs/gdb.base/bt-on-fatal-signal/core.gdb.1674833.nelson.1657727683 ./testsuite/outputs/gdb.base/bt-on-fatal-signal/core.gdb.1673709.nelson.1657727676 (Note the test is skipped at the top if on a remote host.) Change-Id: I79e4fb2e91330279c7a509930b1952194a72e85a
2022-07-18Remove array typedef assumption for AdaTom Tromey3-0/+128
Currently the Ada code assumes that it can distinguish between a multi-dimensional array and an array of arrays by looking for an intervening typedef -- that is, for an array of arrays, there will be a typedef wrapping the innermost array type. A recent compiler change removes this typedef, which causes a gdb failure in the internal AdaCore test suite. This patch handles this case by checking whether the array type in question has a name.
2022-07-18[gdb/testsuite] Remove duplicate of supports_gnucTom de Vries1-11/+0
In commit 9d9dd861e98 ("[gdb/testsuite] Fix regression in step-indirect-call-thunk.exp with gcc 7") I accidentally committed a duplicate of supports_gnuc, which caused: ... DUPLICATE: gdb.base/gdb-caching-proc.exp: supports_gnuc: consistency ... Fix this by removing the duplicate. Tested on x86_64-linux.
2022-07-18[gdb/testsuite] Allow override of ASAN_OPTIONS in lib/gdb.expTom de Vries1-7/+7
Use set_sanitizer_default for ASAN_OPTIONS in lib/gdb.exp. This allows us to override the default detect_leaks=0 setting, by manually doing: ... $ export ASAN_OPTIONS=detect_leaks=1 $ make check ... Tested on x86_64-linux, by building with -fsanitize=address and running test-case gdb.dwarf2/gdb-add-index.exp with and without "export ASAN_OPTIONS=detect_leaks=1".
2022-07-18[gdb/testsuite] Fix regression in step-indirect-call-thunk.exp with gcc 7Tom de Vries2-1/+16
Since commit 43127ae5714 ("Fix gdb.base/step-indirect-call-thunk.exp") I run into: ... gdb compile failed, gcc: error: unrecognized command line option \ '-fcf-protection=none'; did you mean '-flto-partition=none'? UNTESTED: gdb.base/step-indirect-call-thunk.exp: failed to prepare ... The problem is that -fcf-protection is supported starting gcc 8, but I'm using system gcc 7.5.0. Fix this by only adding -fcf-protection=none for gcc 8 and later. Tested on x86_64-linux, with gcc 7.5.0, 8.2.1 and 12.1.1.
2022-07-18[gdb/testsuite] Fix gdb.arch/i386-mpx.expTom de Vries1-1/+1
Since commit c4a3dbaf113 ("Expose current 'print' settings to Python") we have: ... (gdb) print /x $bnd0 = {0x10, 0x20}^M $22 = {lbound = 0x10, ubound = 0x20} : size 0x11^M (gdb) FAIL: gdb.arch/i386-mpx.exp: verify size for bnd0 ... The regexp in the test-case expects "size 17". Fix this by updating the regexp. Tested on x86_64-linux.
2022-07-15gdb/testsuite: modernize gdb.base/maint.expBruno Larsen1-101/+45
gdb.base/maint.exp was using several gdb_expect statements, probably because this test case predates the existance of gdb_test_multiple. This commit updates the test case to use gdb_test_multiple, making it more resilient to internal errors and such. The only gdb_expect left in the testcase is one that specifically looks for an internal error being triggered as a PASS.
2022-07-15Add 'nibbles' to gdb.print_optionsTom Tromey1-2/+4
When I rebased and updated the print_options patch, I forgot to update print_options to add the new 'nibbles' feature to the result. This patch fixes the oversight. I'm checking this in.
2022-07-15Add 'summary' mode to Value.format_stringTom Tromey2-0/+8
This adds a 'summary' mode to Value.format_string and to gdb.print_options. For the former, it lets Python code format values using this mode. For the latter, it lets a printer potentially detect if it is being called in a backtrace with 'set print frame-arguments' set to 'scalars'. I considered adding a new mode here to let a pretty-printer see whether it was being called in a 'backtrace' context at all, but I'm not sure if this is really desirable.
2022-07-15Expose current 'print' settings to PythonTom Tromey2-11/+42
PR python/17291 asks for access to the current print options. While I think this need is largely satisfied by the existence of Value.format_string, it seemed to me that a bit more could be done. First, while Value.format_string uses the user's settings, it does not react to temporary settings such as "print/x". This patch changes this. Second, there is no good way to examine the current settings (in particular the temporary ones in effect for just a single "print"). This patch adds this as well. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17291
2022-07-15PowerPC: fix for gdb.base/eh_return.expCarl Love1-1/+35
Disable the Traceback Table generation on PowerPC for this test. The Traceback Table consists of a series of bit fields to indicate things like the Traceback Table version, language, and specific information about the function. The Traceback Table is generated following the end of the code for every function by default. The Traceback Table is defined in the PowerPC ELF ABI and is intended to support debuggers and exception handlers. The Traceback Table is displayed in the disassembly of functions by default and is part of the function length. The table is typically interpreted by the disassembler as data represented by .long xxx entries. Generation of the Traceback Table is disabled in this test using the PowerPC specific gcc compiler option -mtraceback=no, the xlc option additional_flags-qtable=none and the clang optons -mllvm -xcoff-traceback-table=false. Disabling the Traceback Table generation in this test results in the gdb_test_multiple statement correctly locating the address of the bclr instruction before the statement "End of assembler dump." in the disassembly output.
2022-07-15Run 'black' on gdbTom Tromey1-2/+4
Running 'black' on gdb fixed a couple of small issues. This patch is the result.
2022-07-13Tighten gdb.threads/no-unwaited-for-left.exp regexpsPedro Alves1-2/+2
A WIP version of a patch (https://sourceware.org/pipermail/gdb-patches/2022-June/190202.html) resulted in a bug that went unnoticed by the testuite, like so: (gdb) PASS: gdb.threads/no-unwaited-for-left.exp: enable scheduler-locking, for main thread continue Continuing. [New Thread 1251861.1251861] No unwaited-for children left. (gdb) PASS: gdb.threads/no-unwaited-for-left.exp: continue stops when the main thread exits info threads Id Target Id Frame 3 Thread 1251861.1251863 "no-unwaited-for" __pthread_clockjoin_ex (threadid=140737351558976, thread_return=0x0, clockid=<optimized out>, abstime=<optimized out>, block=<optimized out>) at pthread_join_common.c:145 4 Thread 1251861.1251861 "no-unwaited-for" <unavailable> in ?? () The current thread <Thread ID 1> has terminated. See `help thread'. (gdb) PASS: gdb.threads/no-unwaited-for-left.exp: only thread 3 left, main thread terminated Somehow, above, GDB re-added the zombie leader back before printing "No unwaited-for children left.". The "only thread 3 left, main thread terminated" test should have caught this, but didn't. That is because the test's regexp has a ".*" after the part that matches thread 3. This commit tightens that regexp to catch such a bug. It also tightens the "only main thread left, thread 2 terminated" test's regexp in the same way. Change-Id: I8744f327a0aa0e2669d1ddda88247e99b91cefff
2022-07-13Fix for gdb.base/stap-probe.cCarl Love1-0/+2
On PowePC, the test fails on a compile error: /../binutils-gdb-current/gdb/testsuite/gdb.base/stap-probe.c:107:1: error: expected '=', ',', ';', 'asm' or 'attribute' before 'use_xmm_reg' 107 | use_xmm_reg (int val) | ^~~~~~~~~~~ Where the source code for stap-probe.c is: static const char * __attribute__((noinline)) ATTRIBUTE_NOCLONE use_xmm_reg (int val) <-- line 107 { ... The issue is the ATTRIBUTE_NOCLONE is not defined as an attribute as expected. The #define for ATTRIBUTE_NOCLONE can be found in ../lib/attributes.h. This patch adds the missing include statement for the definition of ATTRIBUTE_NOCLONE. The patch has been tested and verified on a Power10 system.
2022-07-13Add PowerPC support to gdb.cp/call-method-register.ccCarl Love1-0/+2
This patch adds the needed define ASM_REG for PowerPC. The patch was run on a Power 10 system. The gdb Summary for the run lists 2 expected passes, no unexpected failures or untested testcases. Please let me know if this patch is acceptable for mainline. Carl Love
2022-07-13Fix gdb.base/step-indirect-call-thunk.expCarl Love1-1/+5
Due to recent changes in the default value of -fcf-protection for gcc, the test gdb.base/step-indirect-call-thunk.exp fails on Intel X86-64 with the error: Executing on host: gcc -fno-stack-protector -fdiagnostics-color=never -mindirect-branch=thunk -mfunction-return=thunk -c -g -o /.../gdb/testsuite/outputs/gdb.base/step-indirect-call-thunk/step-indirect-call-thunk0.o /.../gdb/testsuite/gdb.base/step-indirect-call-thunk.c (timeout = 300) builtin_spawn -ignore SIGHUP gcc -fno-stack-protector -fdiagnostics-color=never -mindirect-branch=thunk -mfunction-return=thunk -c -g -o /.../gdb/testsuite/outputs/gdb.base/step-indirect-call-thunk/step-indirect-call-thunk0.o /.../binutils-gdb-current/gdb/testsuite/gdb.base/step-indirect-call-thunk.c /.../gdb/testsuite/gdb.base/step-indirect-call-thunk.c: In function 'inc': /.../gdb/testsuite/gdb.base/step-indirect-call-thunk.c: 22:1: error: '-mindirect-branch' and '-fcf-protection' are not compatible 22 | { /* inc.1 */ As stated in the error message the default "-fcf-protection" and "-mindirect-branch' are in compatible. The fcf-protection argument needs to be "-fcf-protection=none" for the test to compile on Intel. The gcc command line "-mindirect-branch' is an Intel specific and will give an error on other platforms. A check for X86 is added so the test will only run on X86 platforms. The patch has been tested and verified on Power 10 and Intel X86-64 systems with no regressions.
2022-07-13Fix "until LINE" in main, when "until" runs into longjmpPedro Alves2-0/+78
With a test like this: 1 #include <dlfcn.h> 2 int 3 main () 4 { 5 dlsym (RTLD_DEFAULT, "FOO"); 6 return 0; 7 } and then "start" followed by "until 6", GDB currently incorrectly stops inside the runtime loader, instead of line 6. Vis: ... Temporary breakpoint 1, main () at until.c:5 4 { (gdb) until 6 0x00007ffff7f0a90d in __GI__dl_catch_exception (exception=exception@entry=0x7fffffffdb00, operate=<optimized out>, args=0x7ffff7f0a90d <__GI__dl_catch_exception+109>) at dl-error-skeleton.c:206 206 dl-error-skeleton.c: No such file or directory. (gdb) The problem is related to longjmp handling -- dlsym internally longjmps on error. The testcase can be reduced to this: 1 #include <setjmp.h> 2 void func () { 3 jmp_buf buf; 4 if (setjmp (buf) == 0) 5 longjmp (buf, 1); 6 } 7 8 int main () { 9 func (); 10 return 0; /* until to here */ 11 } and then with "start" followed by "until 10", GDB currently incorrectly stops at line 4 (returning from setjmp), instead of line 10. The problem is that the BPSTAT_WHAT_CLEAR_LONGJMP_RESUME code in infrun.c fails to find the initiating frame, and so infrun thinks that the longjmp jumped somewhere outer to "until"'s originating frame. Here: case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: { struct frame_info *init_frame; /* There are several cases to consider. 1. The initiating frame no longer exists. In this case we must stop, because the exception or longjmp has gone too far. ... init_frame = frame_find_by_id (ecs->event_thread->initiating_frame); if (init_frame) // this is NULL! { ... } /* For Cases 1 and 2, remove the step-resume breakpoint, if it exists. */ delete_step_resume_breakpoint (ecs->event_thread); end_stepping_range (ecs); // case 1., so we stop. } The initiating frame is set by until_break_command -> set_longjmp_breakpoint. The initiating frame is supposed to be the frame that is selected when the command was issued, but until_break_command instead passes the frame id of the _caller_ frame by mistake. When the "until LINE" command is issued from main, the caller frame is the caller of main. When later infrun tries to find that frame by id, it fails to find it, because frame_find_by_id doesn't unwind past main. The bug is that we passed the caller frame's id to set_longjmp_breakpoint. We should have passed the selected frame's id instead. Change-Id: Iaae1af7cdddf296b7c5af82c3b5b7d9b66755b1c
2022-07-13[gdb/symtab] Make per_cu->set_lang more strictTom de Vries1-2/+2
We have in per_cu->set_lang this comment: ... void set_lang (enum language lang) { /* We'd like to be more strict here, similar to what is done in set_unit_type, but currently a partial unit can go from unknown to minimal to ada to c. */ ... Fix this by not setting m_lang for partial units. This requires us to move the m_unit_type initialization to ensure that m_unit_type is initialized before per_cu->m_lang. Tested on x86_64-linux, with native and target board cc-with-dwz-m.
2022-07-12[gdb/record] Support recording of getrandomTom de Vries2-0/+97
Add missing support for recording of linux syscall getrandom. Tested on x86_64-linux with native and target board unix/-m32. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22081
2022-07-12[gdb/testsuite] Run two test-cases with ASAN_OPTIONS=verify_asan_link_order=0Tom de Vries2-2/+14
When building gdb with -fsanitize=address we run into: ... builtin_spawn gdb -nw -nx -iex set height 0 -iex set width 0 -data-directory \ build/gdb/data-directory^M ==10637==ASan runtime does not come first in initial library list; you \ should either link runtime to your application or manually preload it with \ LD_PRELOAD.^M ERROR: GDB process no longer exists ... Prevent the ASan runtime error by using ASAN_OPTIONS=verify_asan_link_order=0. This makes both test-cases pass. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29358
2022-07-12[gdb/testsuite] Add tsan-suppressions.txtTom de Vries1-0/+26
Add a new file tsan-suppressions.txt, to suppress the "unlock unlocked mutex" problem in ncurses, filed in PR29328. The file is added to the TSAN_OPTIONS in lib/gdb.exp. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29328
2022-07-11Always emit =thread-exited notifications, even if silentPedro Alves2-0/+96
[Note: the testcased added by this commit depends on https://sourceware.org/pipermail/gdb-patches/2022-June/190259.html, otherwise GDB just crashes when detaching the core] Currently, in MI, =thread-created are always emitted, like: =thread-group-started,id="i1",pid="195680" =thread-created,id="1",group-id="i1" ... but on teardown, if the target uses exit_inferior_silent, then you'll only see the inferior exit notification (thread-group-exited), no notification for threads. The core target is one of the few targets that use exit_inferior_silent. Here's an example session: -target-select core $corefile =thread-group-started,id="i1",pid="195680" =thread-created,id="1",group-id="i1" ... ^connected,frame=.... (gdb) -target-detach =thread-group-exited,id="i1" ^done (gdb) This imbalance of emitting =thread-created but then not =thread-exited seems off to me. (And, it complicates changes I want to do to centralize emitting thread exit notifications for the CLI, which is why I'm looking at this.) And then, since most other targets use exit_inferior instead of exit_inferior_silent, MI is already emitting =thread-exited notifications when tearing down an inferior, for most targets. This commit makes MI always emit the =thread-exited notifications, even for exit_inferior_silent. Afterwards, when debugging a core, MI outputs: (gdb) -target-detach =thread-exited,id="1",group-id="i1" << new line =thread-group-exited,id="i1" ^done (gdb) Surprisingly, there's no MI testcase debugging a core file. This commit adds the first. Change-Id: I5100501a46f07b6bbad3e04d120c2562a51c93a4
2022-07-11Fix core-file -> detach -> crash (corefiles/29275)Pedro Alves1-0/+12
After loading a core file, you're supposed to be able to use "detach" to unload the core file. That unfortunately regressed starting with GDB 11, with these commits: 1192f124a308 - gdb: generalize commit_resume, avoid commit-resuming when threads have pending statuses 408f66864a1a - detach in all-stop with threads running resulting in a GDB crash: ... Thread 1 "gdb" received signal SIGSEGV, Segmentation fault. 0x0000555555e842bf in maybe_set_commit_resumed_all_targets () at ../../src/gdb/infrun.c:2899 2899 if (proc_target->commit_resumed_state) (top-gdb) bt #0 0x0000555555e842bf in maybe_set_commit_resumed_all_targets () at ../../src/gdb/infrun.c:2899 #1 0x0000555555e848bf in scoped_disable_commit_resumed::reset (this=0x7fffffffd440) at ../../src/gdb/infrun.c:3023 #2 0x0000555555e84a0c in scoped_disable_commit_resumed::reset_and_commit (this=0x7fffffffd440) at ../../src/gdb/infrun.c:3049 #3 0x0000555555e739cd in detach_command (args=0x0, from_tty=1) at ../../src/gdb/infcmd.c:2791 #4 0x0000555555c0ba46 in do_simple_func (args=0x0, from_tty=1, c=0x55555662a600) at ../../src/gdb/cli/cli-decode.c:95 #5 0x0000555555c112b0 in cmd_func (cmd=0x55555662a600, args=0x0, from_tty=1) at ../../src/gdb/cli/cli-decode.c:2514 #6 0x0000555556173b1f in execute_command (p=0x5555565c5916 "", from_tty=1) at ../../src/gdb/top.c:699 The code that crashes looks like: static void maybe_set_commit_resumed_all_targets () { scoped_restore_current_thread restore_thread; for (inferior *inf : all_non_exited_inferiors ()) { process_stratum_target *proc_target = inf->process_target (); if (proc_target->commit_resumed_state) ^^^^^^^^^^^ With 'proc_target' above being null. all_non_exited_inferiors filters out inferiors that have pid==0. We get here at the end of detach_command, after core_target::detach has already run, at which point the inferior _should_ have pid==0 and no process target. It is clear it no longer has a process target, but, it still has a pid!=0 somehow. The reason the inferior still has pid!=0, is that core_target::detach just unpushes, and relies on core_target::close to actually do the getting rid of the core and exiting the inferior. The problem with that is that detach_command grabs an extra strong reference to the process stratum target, so the unpush_target inside core_target::detach doesn't actually result in a call to core_target::close. Fix this my moving the cleaning up the core inferior to a shared routine called by both core_target::close and core_target::detach. We still need to cleanup the inferior from within core_file::close because there are paths to it that want to get rid of the core without going through detach. E.g., "core-file" -> "run". This commit includes a new test added to gdb.base/corefile.exp to cover the "core-file core" -> "detach" scenario. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29275 Change-Id: Ic42bdd03182166b19f598428b0dbc2ce6f67c893
2022-07-11Try a couple PAuth compilation flags for gdb.arch/aarch64-pauth.expLuis Machado1-2/+17
The -msign-return-address switch has been dropped from GCC, but some older compiler may still support it. Make sure we try both -msign-return-address and -mbranch-protection before bailing out when running gdb.arch/aarch64-pauth.exp.
2022-07-08Accept gdb.Value in more Python APIsTom Tromey4-2/+11
PR python/27000 points out that gdb.block_for_pc will accept a Python integer, but not a gdb.Value. This patch corrects this oversight. I looked at all uses of GDB_PY_LLU_ARG and fixed these up to use get_addr_from_python instead. I also looked at uses of GDB_PY_LL_ARG, but those seemed relatively unlikely to be useful with a gdb.Value, so I didn't change them. My thinking here is that a Value will typically come from inferior memory, and something like a line number is not too likely to be found this way. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27000
2022-07-08Handle bool specially in gdb.set_parameterTom Tromey1-0/+4
PR python/29217 points out that gdb.parameter will return bool values, but gdb.set_parameter will not properly accept them. This patch fixes the problem by adding a special case to set_parameter. I looked at a fix involving rewriting set_parameter in C++. However, this one is simpler. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29217
2022-07-07Fix pedantically invalid DWARF in gdb.trace/unavailable-dwarf-piece.expPedro Alves1-2/+2
The DWARF spec says: Any debugging information entry representing the declaration of an object, module, subprogram or type may have DW_AT_decl_file, DW_AT_decl_line and DW_AT_decl_column attributes, each of whose value is an unsigned integer ^^^^^^^^ constant. Grepping around the DWARF-assembler-based testcases, I noticed that gdb.trace/unavailable-dwarf-piece.exp emits decl_line with DW_FORM_sdata, a signed integer form. This commit tweaks it to use DW_FORM_udata instead. Unsurprisingly, this: $ make check \ TESTS="gdb.trace/unavailable-dwarf-piece.exp" \ RUNTESTFLAGS="--target_board=native-gdbserver" ... still passes cleanly for me after this change. I've noticed this because current llvm-dwarfdump crashed on an ROCm-internal DWARF-assembler-based testcase that incorrectly used signed forms for DW_AT_decl_file/DW_AT_decl_line. The older llvm-dwarfdump found on Ubuntu 20.04 (LLVM 10) reads the line numbers with signed forms as "0" instead of crashing. Here's the before/after fix for gdb.trace/unavailable-dwarf-piece.exp with that llvm-dwarfdump version: $ diff -up before.txt after.txt --- before.txt 2022-07-07 13:21:28.387690334 +0100 +++ after.txt 2022-07-07 13:21:39.379801092 +0100 @@ -18,7 +18,7 @@ DW_AT_name ("s") DW_AT_byte_size (3) DW_AT_decl_file (0) - DW_AT_decl_line (0) + DW_AT_decl_line (1) 0x0000002f: DW_TAG_member DW_AT_name ("a") @@ -41,7 +41,7 @@ DW_AT_name ("t") DW_AT_byte_size (3) DW_AT_decl_file (0) - DW_AT_decl_line (0) + DW_AT_decl_line (1) 0x00000054: DW_TAG_member DW_AT_name ("a") Change-Id: I5c866946356da421ff944019d0eca2607b2b738f
2022-07-07GDB/testsuite: Add coverage for `print -elements' commandMaciej W. Rozycki1-0/+9
We currently have no coverage for the `print -elements ...' command (or `p -elements ...' in the shortened form), so add a couple of test cases mimicking ones using corresponding `set print elements ...' values.
2022-07-05[gdb/exp] Fix internal error when printing C++ pointer-to-memberTom de Vries2-0/+62
When running the test-case included with this patch, we run into: ... (gdb) print ptm^M $1 = gdb/gdbtypes.h:695: internal-error: loc_bitpos: \ Assertion `m_loc_kind == FIELD_LOC_KIND_BITPOS' failed.^M ... while printing a c++ pointer-to-member. Fix this by skipping static fields in cp_find_class_member, such that we have: ... (gdb) print ptm^M $1 = &A::i^M ... Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29294
2022-07-05Add gdb.Objfile.is_file attributeTom Tromey1-0/+12
Sometimes an objfile comes from memory and not from a file. It can be useful to be able to check this from Python, so this patch adds a new "is_file" attribute.
2022-07-05Make 'import gdb.events' workTom Tromey1-0/+2
Pierre-Marie noticed that, while gdb.events is a Python module, it can't be imported. This patch changes how this module is created, so that it can be imported, while also ensuring that the module is always visible, just as it was in the past. This new approach required one non-obvious change -- when running gdb.base/warning.exp, where --data-directory is intentionally not found, the event registries can now be nullptr. Consequently, this patch probably also requires https://sourceware.org/pipermail/gdb-patches/2022-June/189796.html Note that this patch obsoletes https://sourceware.org/pipermail/gdb-patches/2022-June/189797.html
2022-07-02[gdb/testsuite] Fix gdb.base/early-init-file.exp with -fsanitize=threadTom de Vries1-2/+17
When building gdb with -fsanitize=thread, I run into: ... FAIL: gdb.base/early-init-file.exp: check startup version string has style \ version ... due to this: ... warning: Found custom handler for signal 7 (Bus error) preinstalled.^M warning: Found custom handler for signal 8 (Floating point exception) \ preinstalled.^M warning: Found custom handler for signal 11 (Segmentation fault) \ preinstalled.^M Some signal dispositions inherited from the environment (SIG_DFL/SIG_IGN)^M won't be propagated to spawned programs.^M ... appearing before the "GNU gdb (GDB) $version" line. This is similar to the problem fixed by commit f0bbba7886f ("gdb.debuginfod/fetch_src_and_symbols.exp: fix when GDB is built with AddressSanitizer"). In that commit, the problem was fixed by starting gdb with -quiet, but using that would mean the "GNU gdb (GDB) $version" line that we're trying to check would disappear. Fix this instead by updating the regexp to allow the message. Tested on x86_64-linux.
2022-06-30GDB: Add `NUMBER' completion to `set' integer commandsMaciej W. Rozycki1-1/+7
Fix a completion consistency issue with `set' commands accepting integer values and the special `unlimited' keyword: (gdb) complete print -elements print -elements NUMBER print -elements unlimited (gdb) vs: (gdb) complete set print elements set print elements unlimited (gdb) (there is a space entered at the end of both commands, not shown here) which also means if you strike <Tab> with `set print elements ' input, it will, annoyingly, complete to `set print elements unlimited' right away rather than showing a choice between `NUMBER' and `unlimited'. Add `NUMBER' then as an available completion for such `set' commands: (gdb) complete set print elements set print elements NUMBER set print elements unlimited (gdb) Adjust the testsuite accordingly. Also document the feature in the Completion section of the manual in addition to the Command Options section already there.
2022-06-30gdb/testsuite: Expand gdb.cp/mb-ctor.exp to test dynamic allocationBruno Larsen2-0/+24
When testing GDB's ability to stop in constructors, gdb.cp/mb-ctor.exp only tested objects allocated on the stack. This commit adds a couple of dynamic allocations and tests if GDB can stop in it as well.
2022-06-29GDB/testsuite: Tighten `set print elements' error checkMaciej W. Rozycki1-1/+2
Match the whole error message expected to be given rather than omitting the part about the "unlimited" keyword. There's no point in omitting the missing part first, and second with an upcoming change the part in parentheses will no longer be a fixed string, so doing a full match will ensure the algorithm correctly builds the message expected here. Also avoid any wildcard matches.
2022-06-29GDB: Remove extraneous full stops from `set' command error messagesMaciej W. Rozycki1-4/+4
With errors given for bad commands such as `set annotate' or `set width' we produce an extraneous full stop within parentheses: (gdb) set annotate Argument required (integer to set it to.). (gdb) set width Argument required (integer to set it to, or "unlimited".). (gdb) This is grammatically incorrect, so remove the full stop and adjust the testsuite accordingly.
2022-06-29gdb/testsuite: fix gdb.base/break-idempotent.exp on ppcCarl Love1-1/+7
When running the gdb.base/break-idempotent.exp test on ppc, I was seeing some test failures (or rather errors), that looked like this: (gdb) watch local Hardware watchpoint 2: local has_hw_wp_support: Hardware watchpoint detected ERROR: no fileid for gcc2-power8 ERROR: Couldn't send delete breakpoints to GDB. ERROR OCCURED: can't read "gdb_spawn_id": no such variable while executing "expect { -i 1000 -timeout 100 -re ".*A problem internal to GDB has been detected" { fail "$message (GDB internal error)" gdb_internal_erro..." ("uplevel" body line 1) invoked from within What happens is that in break-idempotent.exp we basically do this: if {[prepare_for_testing "failed to prepare" $binfile $srcfile $opts]} { continue } # .... if {![skip_hw_watchpoint_tests]} { test_break $always_inserted "watch" } The problem with this is that skip_hw_watchpoint_tests, includes this: if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] || [istarget "ia64-*-*"] || [istarget "arm*-*-*"] || [istarget "aarch64*-*-*"] || ([istarget "powerpc*-*-linux*"] && [has_hw_wp_support]) || [istarget "s390*-*-*"] } { return 0 } For powerpc only we call has_hw_wp_support. This is a caching proc that runs a test within GDB to detect if we have hardware watchpoint support or not. Unfortunately, to run this test we restart GDB, and when the test has completed, we exit GDB. This means that in break-idempotent.exp, when we call skip_hw_watchpoint_tests for the first time on powerpc, GDB will unexpectedly be exited. When we later call delete_breakpoints we see the errors I reported above. The fix is to call skip_hw_watchpoint_tests early, before we start GDB as part of the break-idempotent.exp script, and store the result in a variable, we can then check this variable in the script as needed. After this change break-idempotent.exp runs fine on powerpc. Co-authored-by: Andrew Burgess <aburgess@redhat.com>
2022-06-27gdb/testsuite: update bug numbers from Gnats to bugzillaBruno Larsen2-11/+11
Some tests link to outdated bug numbers when an XFAIL or a KFAIL happen. gdb.base/macscp.exp was referencing bug number 555, and the bug 7660 mentions that it used to be 555 on the Gnats system and seems to relate to the issue at hand. gdb.base/annota1.exp was referencing bug number 1270, and bug 8375 mentions being number 1270 on Gnats, and mentions annota1 specifically, so it seemed pretty obvious.
2022-06-27[gdb/testsuite] Handle older python in gdb.python/py-send-packet.pyTom de Vries1-2/+6
With python 3.4, I run into: ... Traceback (most recent call last):^M File "<string>", line 1, in <module>^M File "outputs/gdb.python/py-send-packet/py-send-packet.py", line 128, in \ run_set_global_var_test^M res = conn.send_packet(b"X%x,4:\x02\x02\x02\x02" % addr)^M TypeError: Could not convert Python object: b'X%x,4:\x02\x02\x02\x02'.^M Error while executing Python code.^M ... while with python 3.6 this works fine. The type of addr is <class 'gdb.Value'>, so the first thing to try is whether changing it into a string works: ... addr_str = "%x" % addr res = conn.send_packet(b"X%s,4:\x02\x02\x02\x02" % addr_str) ... which gets us the more detailed: ... TypeError: unsupported operand type(s) for %: 'bytes' and 'str' ... Fix this by avoiding the '%' operator in the byte literal, and use instead: ... def xpacket_header (addr): return ("X%x,4:" % addr).encode('ascii') ... res = conn.send_packet(xpacket_header(addr) + b"\x02\x02\x02\x02") ... Tested on x86_64-linux, with python 3.4 and 3.6, and a backported version was tested on the gdb-12-branch in combination with python 2.7.
2022-06-27[gdb/testsuite] Fix gdb.reverse/i387-env-reverse.exp for -pieTom de Vries1-1/+1
When running test-case gdb.reverse/i387-env-reverse.exp for x86_64-linux with target board unix/-m32/-fPIE/-pie, we run into: ... (gdb) PASS: gdb.reverse/i387-env-reverse.exp: push st0 info register eax^M eax 0x56550000 1448411136^M (gdb) FAIL: gdb.reverse/i387-env-reverse.exp: verify eax == 0x8040000 ... The problem is that the tested instruction (fstsw) only sets $ax, not $eax. Fix this by verifying $ax instead of $eax. Tested on x86_64-linux with target boards unix/-m32 and unix/-m32/-fPIE/-pie.
2022-06-27[gdb/testsuite] Enable some test-cases for x86_64 -m32Tom de Vries4-173/+166
When trying to run test-case gdb.reverse/i387-env-reverse.exp for x86_64-linux with target board unix/-m32, it's skipped. Fix this by using is_x86_like_target instead of istarget "i?86-*linux*". This exposes a number of duplicates, fix those by making the test names unique. Likewise in a couple of other test-cases. Tested on x86_64-linux with target boards unix/-m32.
2022-06-27[gdb/testsuite] Workaround unnecessary .s file with gfortran 4.8Tom de Vries1-0/+6
After running test-case gdb.fortran/namelist.exp with gfortran 4.8.5, I'm left with: ... $ git sti On branch master Your branch is up to date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) gdb/testsuite/lib/compiler.s nothing added to commit but untracked files present (use "git add" to track) ... We're running into PR gcc/60447, which was fixed in gcc 4.9.0. Workaround this by first copying the source file to the temp dir, such that the .s file is left there instead: ... $ ls build/gdb/testsuite/temp/<runtest pid>/ compiler.c compiler.F90 compiler.s ... Tested on x86_64-linux.
2022-06-27[gdb/testsuite] Skip gdb.fortran/namelist.exp for gfortran 4.8Tom de Vries2-4/+12
The test-case gdb.fortran/namelist.exp uses a gfortran feature (emitting DW_TAG_namelist in the debug info) that has been supported since gfortran 4.9, see PR gcc/37132. Skip the test for gfortran 4.8 and earlier. Do this using gcc_major_version, and update it to be able to handle "gcc_major_version {gfortran-*} f90". Tested on x86_64-linux, with gfortran 4.8.5, 7.5.0, and 12.1.1.
2022-06-25Fix corrupt DWARF in dw2-double-set-die-typeTom Tromey1-31/+0
The dw2-double-set-die-type.exp test case caused an AddressSanitizer failure in the new DWARF scanner. The immediate cause was bad DWARF in the test -- in particular, the the sibling attribute here: <2><181>: Abbrev Number: 33 (DW_TAG_subprogram) <182> DW_AT_external : 1 <183> DW_AT_name : address <18b> DW_AT_type : <0x171> <18f> DW_AT_declaration : 1 <190> DW_AT_sibling : <0x1a1> ... <1><1a1>: Abbrev Number: 23 (DW_TAG_pointer_type) <1a2> DW_AT_byte_size : 4 <1a3> DW_AT_type : <0x1a7> ...points to a "sibling" DIE that is at a different child depth. Because this test case doesn't really require sibling attributes, this patch fixes the problem by removing them from the test. Note that gdb is not generally robust against malformed DWARF. Detecting and compensating for this problem would probably be expensive and, IMO, is better left to some (still hypothetical) DWARF linter.
2022-06-24gdb/testsuite: remove unneeded calls to get_compiler_infoAndrew Burgess174-714/+10
It is not necessary to call get_compiler_info before calling test_compiler_info, and, after recent commits that removed setting up the gcc_compiled, true, and false globals from get_compiler_info, there is now no longer any need for any test script to call get_compiler_info directly. As a result every call to get_compiler_info outside of lib/gdb.exp is redundant, and this commit removes them all. There should be no change in what is tested after this commit.
2022-06-24gdb/testsuite: remove global gcc_compiled from gdb.expAndrew Burgess37-177/+54
After this commit the gcc_compiled global is no longer exported from lib/gdb.exp. In theory we could switch over all uses of gcc_compiled to instead call test_compiler_info directly, however, I have instead added a new proc to gdb.exp: 'is_c_compiler_gcc'. I've then updated the testsuite to call this proc instead of using the global. Having a new proc specifically for this task means that we have a single consistent pattern for detecting gcc. By wrapping this logic within a proc that calls test_compiler_info, rather than using the global, means that test scripts don't need to call get_compiler_info before they read the global, simply calling the new proc does everything in one go. As a result I've been able to remove the get_compiler_info calls from all the test scripts that I've touched in this commit. In some of the tests e.g. gdb.dwarf2/*.exp, the $gcc_compiled flag was being checked at the top of the script to decide if the whole script should be skipped or not. In these cases I've called the new proc directly and removed all uses of gcc_compiled. In other cases, e.g. most of the gdb.base scripts, there were many uses of gcc_compiled. In these cases I set a new global gcc_compiled near the top of the script, and leave the rest of the script unchanged. There should be no changes in what is tested after this commit.
2022-06-24Include count of unexpected core files in gdb.sum summaryPedro Alves2-1/+49
If GDB, GDBserver, a testcase program, Valgrind, etc. unexpectedly crash while running the GDB testsuite, and you've setup your machine such that core files are dumped in the current directory instead of being shoved somewhere by abrt, apport, or similar (as you should for proper GDB testing), you'll end up with an unexpected core file in the $build/gdb/testsuite/ directory. It can happen that GDB, GDBserver, etc. even crashes _after_ gdb_exit, during teardown, and thus such a crash won't be noticed by looking at the gdb.sum file at all. This commit aims at improving that, by including a new "unexpected core files" line in the testrun summary. For example, here's what I get on x86-64 Ubuntu 20.04, with this patch: === gdb Summary === # of unexpected core files 12 << new info # of expected passes 107557 # of unexpected failures 35 # of expected failures 77 # of unknown successes 2 # of known failures 114 # of untested testcases 31 # of unsupported tests 139 I have my core pattern setup like this: $ cat /proc/sys/kernel/core_pattern core.%e.%p.%h.%t That's: %e: executable filename %p: pid %h: hostname %t: UNIX time of dump and so I get these core files: $ ls -1 testsuite/core.* testsuite/core.connect-with-no.216191.nelson.1656002431 testsuite/core.connect-with-no.217729.nelson.1656002431 testsuite/core.gdb.194247.nelson.1656002423 testsuite/core.gdb.226014.nelson.1656002435 testsuite/core.gdb.232078.nelson.1656002438 testsuite/core.gdb.352268.nelson.1656002441 testsuite/core.gdb.4152093.nelson.1656002337 testsuite/core.gdb.4154515.nelson.1656002338 testsuite/core.gdb.4156668.nelson.1656002339 testsuite/core.gdb.4158871.nelson.1656002341 testsuite/core.gdb.468495.nelson.1656002444 testsuite/core.vgdb.4192247.nelson.1656002366 where we can see that GDB crashed a number of times, but also Valgrind's vgdb, and a couple testcase programs. Neither of which is good. If your core_pattern is just "core" (but why??), then I guess that you may end up with just a single core file in testsuite/. Still, that is one core file too many. Above, we see a couple cores for "connect-with-no", which are the result of gdb.server/connect-with-no-symbol-file.exp. This is a case mentioned above -- while the program crashed, that happens during testcase teardown, and it goes unnoticed (without this commit) by gdb.sum results. Vis: $ make check TESTS="gdb.server/connect-with-no-symbol-file.exp" ... === gdb Summary === # of unexpected core files 2 # of expected passes 8 ... $ The tests fully passed, but still the testcase program crashed somehow: $ ls -1 testsuite/core.* testsuite/core.connect-with-no.941561.nelson.1656003317 testsuite/core.connect-with-no.941682.nelson.1656003317 Against --target_board=native-extended-gdbserver it's even worse. I get: # of unexpected core files 26 and note that when GDBserver hits an assertion failure, it exits with error, instead of crashing with SIGABRT. I think that should be changed, at least on development builds, but that would be for another patch. After such patch, I suspect the number of unexpected cores will be higher, as there are likely teardown GDBserver assertions that we're not noticing. I decided to put this new info in the "gdb Summary" section, as that's a place people already are used to looking at, either when looking at the tail of gdb.sum, or when diffing gdb.sum files, and we've already extended this section before, to include the count of DUPLICATE and PATH problems, so there's precedent. Implementation-wise, the new line is appended after DejaGnu is finished, with a shell script that is invoked by the Makefile. It is done this way so that serial and parallel testing work the same way. My initial cut at an implementation was in TCL, straight in testsuite/lib/check-test-names.exp, where DUPLICATES and PATH are handled, like so: @@ -148,6 +159,10 @@ namespace eval ::CheckTestNames { $counts(paths,$which) maybe_show_count "# of duplicate test names\t" \ $counts(duplicates,$which) + + set cores [glob -nocomplain -directory $::objdir core*] + maybe_show_count "# of unexpected core files\t" \ + [llength $cores] } But that would only work for serial testing, as in parallel testing, the final gdb.sum is generated by aggregating the results of all the individual gdb.sum files, and dg-extract-results.sh doesn't know about our new summary line. And I don't think that dg-extract-results.sh should be taught about it, since the count of core files is not something that we want to count many times, once per testcase, and then add up the subcounts at the end. Every time we count the core files, we're already counting the final count. I considered using the Tcl implementation in serial mode, and the script approach for parallel testing, but that has the obvious downside of implementing and maintaining the same thing twice. In the end, I settled on the script approach for serial mode too, which requires making the "check-single" rule print the tail end of the gdb.sum file, with a side effect being that if you look at the terminal after a run (instead of at the gdb.sum file), you'll see the "gdb Summary" section twice, once without the unexpected core lines printed, and then another with. IMO, this isn't an issue; when testing in parallel mode, if you look at the terminal after "make -jN check", you'll also see multiple "gdb Summary" sections printed. Change-Id: I190b8d41856d49ad143854b6e3e6ccd7caa04491