aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
AgeCommit message (Collapse)AuthorFilesLines
2023-01-26gdb/testsuite/dap: make dap_request_and_response not catch / issue test resultSimon Marchi2-20/+7
Following some of my changes, dap_request_and_response was failing and I didn't know why. I think it's better to make it not catch any exception, and just make it do a simple "send request, read response". If an exception is thrown while sending a request or reading a response, things are going really badly, it's not like we'll want to recover from that and continue the test. Change-Id: I27568d3547f753c3a74e3e5a730d38a8caef9356
2023-01-26gdb/testsuite/dap: write requests to gdb.logSimon Marchi1-1/+1
This helps following what happens when reading gdb.log. The downside is that it becomes harder to tell what text is from GDB and what text is going to GDB, but I think that seeing responses without seeing requests is even more confusing. At least, the lines are prefix with >>>, so when you see this, you know that until the end of the line, it's something that was sent to GDB, and not GDB output. Change-Id: I1ba1acd8b16f4e64686c5ad268cc41082951c874
2023-01-26gdb/testsuite/dap: prefix some procs with _Simon Marchi1-12/+12
Prefix some procs that are only used internally with an underscore, to make it clear they are internal. If they need to be used by some test later, we can always un-prefix them. Change-Id: Iacb8e77363b5d1f8b98d9ba5a6d115aee5c8925d
2023-01-26gdb/testsuite/dap: use gdb_assert in gdb.dap/basic-dap.expSimon Marchi1-16/+3
Use gdb_assert instead of manual pass/fail. Change-Id: I71fbc4e37a0a1ef4783056c7424e932651fa397f
2023-01-26[gdb/testsuite] Add gdb.base/unwind-on-each-insn-{amd64,i386}.expTom de Vries6-153/+792
The gcc 4.4.x (and earlier) compilers had the problem that the unwind info in the epilogue was inaccurate. In order to work around this in gdb, epilogue unwinders were added with a higher priority than the dwarf unwinders in the amd64 and i386 targets: - amd64_epilogue_frame_unwind, and - i386_epilogue_frame_unwind. Subsequently, the epilogue unwind info problem got fixed in gcc 4.5.0. However, the epilogue unwinders prevented gdb from taking advantage of the fixed epilogue unwind info, so the scope of the epilogue unwinders was limited, bailing out for gcc >= 4.5.0. There was no regression test added for this preference scheme, so if we now declare epilogue unwind info from all gcc versions as trusted, no test will start failing. Fix this by adding an amd64 and i386 regression test for this. I have no gcc 4.4.x lying around, so I fabricated the assembly files by: - commenting out some .cfi directives to break the epilogue unwind info, and - hand-editing the producer info to 4.4.7 to activate the fix. Tested on x86_64-linux, target boards unix/{-m64,-m32}.
2023-01-26[gdb/testsuite] Add and use is_x86_64_m64_targetTom de Vries54-114/+68
Add new proc is_x86_64_m64_target and use it where appropriate. Tested on x86_64-linux.
2023-01-25Move target check into allow_altivec_testsTom Tromey4-3/+6
Pedro pointed out that only PPC can possibly have altivec, so we can move the target check into allow_altivec_tests.
2023-01-25Use require with is_remoteTom Tromey43-156/+64
This changes some tests to use require with 'is_remote', rather than an explicit test. This adds uniformity helps clean up more spots where a test might exit early without any notification.
2023-01-25Add unsupported calls where neededTom Tromey8-2/+9
A number of tests will exit early without saying why. This patch adds "unsupported" at spots like this that I could readily find. There are definitely more of these; for example dw2-ranges.exp fails silently because a compilation fails. I didn't attempt to address these as that is a much larger task.
2023-01-25Introduce and use is_any_targetTom Tromey28-110/+39
A few tests work on two different targets that can't be detected with a single call to istarget -- that proc only accepts globs, not regular expressions. This patch introduces a new is_any_target proc and then converts these tests to use it in a 'require'.
2023-01-25Use require with istargetTom Tromey125-549/+139
This changes many tests to use require when checking 'istarget'. A few of these conversions were already done in earlier patches. No change was needed to 'require' to make this work, due to the way it is written. I think the result looks pretty clear, and it has the bonus of helping to ensure that the reason that a test is skipped is always logged.
2023-01-25Rename skip_vsx_tests to allow formTom Tromey4-18/+20
This renames skip_vsx_tests to allow_vsx_tests and updates it users to use require.
2023-01-25Rename skip_power_isa_3_1_tests to allow formTom Tromey3-11/+13
This renames skip_power_isa_3_1_tests to allow_power_isa_3_1_tests and updates its users to use require.
2023-01-25Rename skip_float_test to allow formTom Tromey15-57/+51
This renames skip_float_test to allow_float_test and updates its users to use require.
2023-01-25Convert skip_altivec_tests to allow formTom Tromey4-18/+20
This renames skip_altivec_tests to allow_altivec_tests and updates its users to use require.
2023-01-25[gdb/testsuite] Fix gdb.base/unwind-on-each-insn.exp for -m32Tom de Vries1-1/+1
With test-case gdb.base/unwind-on-each-insn.exp and target board unix/-m32, I now get: ... # of expected passes 25 ... instead of: ... # of expected passes 133 ... as I used to get before commit d25a8dbc7c3 ("[gdb/testsuite] Allow debug srcfile2 in gdb.base/unwind-on-each-insn.exp"), due to the test-case trying to match "rip = " and info frame printing "eip = " instead. Fix this by dropping "rip" from the regexp. Tested on x86_64-linux, target boards unix/{-m64,-m32}.
2023-01-25[gdb/testsuite] Allow debug srcfile2 in gdb.base/unwind-on-each-insn.expTom de Vries1-2/+4
Test-case gdb.base/unwind-on-each-insn.exp compiles $srcfile with debug info, and $srcfile2 without. Occasionally, I try both files with debug info: ... - $srcfile $debug_flags $srcfile2 $nodebug_flags]]} { + $srcfile $debug_flags $srcfile2 $debug_flags]]} { ... This shortcuts the test due to no longer recognizing that stepi still lands in foo. Fix this by determining whether still in foo by checking the info frame output. Tested on x86_64-linux.
2023-01-25[gdb/testsuite] Allow nodebug srcfile in gdb.base/unwind-on-each-insn.expTom de Vries1-2/+2
Test-case gdb.base/unwind-on-each-insn.exp compiles $srcfile with debug info, and $srcfile2 without. Occasionally, I try both files with debug info: ... - $srcfile $debug_flags $srcfile2 $nodebug_flags]]} { + $srcfile $debug_flags $srcfile2 $debug_flags]]} { ... and both files without: ... - $srcfile $debug_flags $srcfile2 $nodebug_flags]]} { + $srcfile $nodebug_flags $srcfile2 $nodebug_flags]]} { ... In the latter case, I run into: ... FAIL: gdb.base/unwind-on-each-insn.exp: foo: instruction 1: bt 2 FAIL: gdb.base/unwind-on-each-insn.exp: foo: instruction 1: up ... due to a mismatch between the regexp and the different output due to using nodebug. Fix this by making the regexp less strict. Tested on x86_64-linux.
2023-01-25[gdb/testsuite] Analyze non-leaf fn in gdb.base/unwind-on-each-insn.expTom de Vries3-59/+86
In test-case gdb.base/unwind-on-each-insn.exp, we stepi through function foo to check various invariants at each insn, in particular hoping to excercise insns that modify stack and frame pointers. Function foo is a leaf function, so add a non-leaf function bar, and step through it as well (using nexti instead of stepi). With the updated test-case, on powerpc64le-linux, I run into PR tdep/30049: ... FAIL: bar: instruction 5: bt 2 FAIL: bar: instruction 5: up FAIL: bar: instruction 5: [string equal $fid $::main_fid] FAIL: bar: instruction 6: bt 2 FAIL: bar: instruction 6: up FAIL: bar: instruction 6: [string equal $fid $::main_fid] ... Tested on: - x86_64-linux (-m64 and -m32) - s390x-linux (-m64 and -m31) - aarch64-linux - powerpc64le-linux
2023-01-25[gdb/testsuite] Improve leaf fn in gdb.base/unwind-on-each-insn.expTom de Vries3-4/+9
In test-case gdb.base/unwind-on-each-insn.exp, we stepi through function foo to check various invariants at each insn, in particular hoping to excercise insns that modify stack and frame pointers. For x86_64-linux, we have a reasonably complex foo (and similar for -m32): ... 4004bc: 55 push %rbp 4004bd: 48 89 e5 mov %rsp,%rbp 4004c0: 90 nop 4004c1: 5d pop %rbp 4004c2: c3 ret ... Both stack pointer (%rsp) and frame pointer (%rbp) are modified. Also for s390x-linux (and similar for -m31): ... 0000000001000668 <foo>: 1000668: e3 b0 f0 58 00 24 stg %r11,88(%r15) 100066e: b9 04 00 bf lgr %r11,%r15 1000672: e3 b0 b0 58 00 04 lg %r11,88(%r11) 1000678: 07 fe br %r14 ... Frame pointer (%r11) is modified. Likewise for powerpc64le-linux: ... 00000000100006c8 <foo>: 100006c8: f8 ff e1 fb std r31,-8(r1) 100006cc: d1 ff 21 f8 stdu r1,-48(r1) 100006d0: 78 0b 3f 7c mr r31,r1 100006d4: 00 00 00 60 nop 100006d8: 30 00 3f 38 addi r1,r31,48 100006dc: f8 ff e1 eb ld r31,-8(r1) 100006e0: 20 00 80 4e blr ... Both stack pointer (r1) and frame pointer (r31) are modified. But for aarch64-linux, we have: ... 00000000004005fc <foo>: 4005fc: d503201f nop 400600: d65f03c0 ret ... There's no insn that modifies stack or frame pointer. Fix this by making foo more complex, adding an (unused) argument: ... 0000000000400604 <foo>: 400604: d10043ff sub sp, sp, #0x10 400608: f90007e0 str x0, [sp, #8] 40060c: d503201f nop 400610: 910043ff add sp, sp, #0x10 400614: d65f03c0 ret ... such that the stack pointer (sp) is modified. [ Note btw that we're seeing the effects of -momit-leaf-frame-pointer, with -mno-omit-leaf-frame-pointer we have instead: ... 0000000000400604 <foo>: 400604: a9be7bfd stp x29, x30, [sp, #-32]! 400608: 910003fd mov x29, sp 40060c: f9000fa0 str x0, [x29, #24] 400610: d503201f nop 400614: a8c27bfd ldp x29, x30, [sp], #32 400618: d65f03c0 ret ... such that also the frame pointer (x29) is modified. ] Having made foo more complex, we now run into the following fail on x86_64/-m32: ... FAIL: gdb.base/unwind-on-each-insn.exp: instruction 1: $sp_value == $main_sp .... The problem is that the stack pointer has changed inbetween the sampling of main_sp and *foo, in particular by the push insn: ... 804841a: 68 c0 84 04 08 push $0x80484c0 804841f: e8 10 00 00 00 call 8048434 <foo> ... Fix this by updating main_sp. On powerpc64le-linux, with gcc 7.5.0 I now run into PR tdep/30021: ... FAIL: gdb.base/unwind-on-each-insn.exp: insn 7: $fba_value == $main_fba FAIL: gdb.base/unwind-on-each-insn.exp: insn 7: [string equal $fid $main_fid] ... but I saw the same failure before this commit with gcc 4.8.5. Tested on: - x86_64-linux (-m64 and -m32) - s390x-linux (-m64 and -m31) - powerpc64le-linux - aarch64-linux Also I've checked that the test-case still functions as regression test for PR record/16678 on x86_64.
2023-01-25gdb/tui: better filtering of tab completion results for focus commandAndrew Burgess1-2/+16
While working on the previous couple of commits, I noticed that the 'focus' command would happily suggest 'status' as a possible focus completion, even though the 'status' window is non-focusable, and, after the previous couple of commits, trying to focus the status window will result in an error. This commit improves the tab-completion results for the focus command so that the status window is not included.
2023-01-25gdb/testsuite/tui: more testing of the 'focus' commandAndrew Burgess2-0/+90
I noticed that we didn't have many tests of the tui 'focus' command, so I started adding some. This exposed a bug in GDB; we are able to focus windows that should not be focusable, e.g. the 'status' window. This is harmless until we then do 'focus next' or 'focus prev', along this code path we assert that the currently focused window is focusable, which obviously, is not always true, so GDB fails with an assertion error. The fix is simple; add a check to the tui_set_focus_command function to ensure that the selected window is focusable. If it is not then an error is thrown. The new tests I've added cover this case.
2023-01-25gdb/testsuite: update gdb.tui/tui-nl-filtered-output.expAndrew Burgess1-21/+16
Following on from the previous commit, in this commit I am updating the test script gdb.tui/tui-nl-filtered-output.exp to take account of the changes in commit: commit 9162a27c5f5828240b53379d735679e2a69a9f41 Date: Tue Nov 13 11:59:03 2018 -0700 Change gdb test suite's TERM setting In the above commit the TERM environment variable was changed to be 'dumb' by default, which means that tests, that previously activated tui mode, no longer do unless TERM is set to 'ansi'. As the gdb.tui/tui-nl-filtered-output.exp script didn't do this, the test stopped working. As the expect patterns in this script were pretty generic no tests actually started failing, and we never noticed. In this commit I update the test script to correctly activate our terminal emulator, the test continues to pass after this update, but now we are testing in tui mode.
2023-01-25gdb/testsuite: update gdb.tui/tui-disasm-long-lines.expAndrew Burgess1-7/+14
Following on from the previous commit, in this commit I am updating the test script gdb.tui/tui-disasm-long-lines.exp to take account of the changes in commit: commit 9162a27c5f5828240b53379d735679e2a69a9f41 Date: Tue Nov 13 11:59:03 2018 -0700 Change gdb test suite's TERM setting In the above commit the TERM environment variable was changed to be 'dumb' by default, which means that tests, that previously activated tui mode, no longer do unless TERM is set to 'ansi'. As the gdb.tui/tui-disasm-long-lines.exp script didn't do this, the test stopped working. As the expect patterns in this script were pretty generic no tests actually started failing, and we never noticed. In this commit I update the script to use Term::clean_restart, which correctly sets TERM to 'ansi'. I've also added a check that the asm box does appear on the screen, which should indicate that tui mode has correctly activated. However, I also notice that GDB doesn't appear to fully work correctly. The test should display the disassembly for the test program, but it doesn't. The test is trying to disassemble some code that (deliberately) uses a very long symbol name, this eventually results in GDB entering tui_source_window_base::show_source_content and trying to allocate an ncurses pad in order to hold the current page of disassembler output. Unfortunately, due to the very long line, the call to newpad fails, meaning that tui_source_window_base::m_pad is nullptr. Luckily non of the following calls appear to crash when passed a nullptr, however, all the output that is written to the pad is lost, which is why we don't see any assembly code written to the screen. As the test history indicates that the script was originally checking for a crash in GDB when the long identifier was encountered, I think there is value in just leaving the test as it is for now, I have a fix for the issue of the newpad call failing, which I'll post in a follow up commit later.
2023-01-25gdb/testsuite: extend gdb.tui/tui-layout.exp test scriptAndrew Burgess1-11/+46
In passing I noticed that the gdb.tui/tui-layout.exp test script was a little strange, it tests the layout command multiple times, but never sets up our ANSI terminal emulator, so every layout command fails with a message about the terminal lacking the required abilities. It turns out that this was caused by this commit: commit 9162a27c5f5828240b53379d735679e2a69a9f41 Date: Tue Nov 13 11:59:03 2018 -0700 Change gdb test suite's TERM setting This was when we changed the testsuite to set the TERM environment variable to "dumb" by default. After this, any tui test that didn't set the terminal mode back to 'ansi' would fail to activate tui mode. For the tui-layout.exp test it just so happens that the test patterns are generic enough that the test continued to pass, even after this change. In this commit I have updated the test so we now check the layout command both with a 'dumb' terminal and with the 'ansi' terminal. When testing with the 'ansi' terminal, I have some limited validation that GDB correctly entered tui mode. I figured that it is probably worth having at least one test in the test suite that deliberately tries to enter tui mode in a dumb terminal, it would be sad if we one day managed to break GDB such that this caused a crash, and never noticed.
2023-01-25gdb/testsuite: rename test source file to match test scriptAndrew Burgess2-1/+1
The previous commit touched the source file for the test script gdb.cp/cpcompletion.exp. This source file is called pr9594.cc. The source file is only used by the one test script. This commit renames the source file to cpcompletion.cc to match the test script, this is more inline with how we name source files these days.
2023-01-25gdb/testsuite: use test_gdb_complete_unique more in C++ testsAndrew Burgess1-4/+4
Spotted in gdb.cp/cpcompletion.exp that we could replace some uses of gdb_test with test_gdb_complete_unique, this will extend the completion testing to check tab-completion as well as completion using the 'complete' command in some additional cases.
2023-01-23[gdb/testsuite] Avoid using .eh_frame in gdb.base/unwind-on-each-insn.expTom de Vries1-2/+12
One purpose of the gdb.base/unwind-on-each-insn.exp test-case is to test the architecture-specific unwinders on foo, so unwind-on-each-insn-foo.c is compiled with nodebug, to prevent the dwarf unwinders from taking effect. For for instance gcc x86_64 though, -fasynchronous-unwind-tables is enabled by default, generating an .eh_frame section contribution which might enable the dwarf unwinders and bypass the architecture-specific unwinders. Currently, that happens to be not the case due to the current implementation of epilogue_unwind_valid, which assumes that in absence of debug info proving that the compiler is gcc >= 4.5.0, the .eh_frame contribution is invalid. That may change though, see PR30028, in which case gdb.base/unwind-on-each-insn.exp stops being a regression test for commit 49d7cd733a7 ("Change calculation of frame_id by amd64 epilogue unwinder"). Fix this by making sure that we don't use .eh_frame info regardless of epilogue_unwind_valid, simply by not generating it using -fno-asynchronous-unwind-tables. Tested on x86_64-linux, target boards unix/{-m64,-m32}, using compilers gcc 7.5.0 and clang 13.0.1.
2023-01-23[gdb/testsuite] Simplify gdb.base/unwind-on-each-insn.expTom de Vries1-51/+11
In test-case gdb.base/unwind-on-each-insn.exp, we try to determine the last disassembled insn in function foo. This in it self is fragile, as demonstrated by commit 91836f41e20 ("Powerpc fix for gdb.base/unwind-on-each-insn.exp"). The use of the last disassembled insn in the test-case is to stop stepping in foo once reaching it. However, the intent is to stop stepping just before returning to main. There is no guarantee that the last disassembled insn: - is actually executed - is executed just before returning to main - is executed only once. Fix this by simplying the test-case to continue stepping till stepping out of foo. Tested on x86_64-linux.
2023-01-23[gdb/testsuite] Fix untested in gdb.base/frame-view.expTom de Vries1-1/+1
When running test-case gdb.base/frame-view.exp, I see: ... gdb compile failed, ld: frame-view0.o: in function `main': frame-view.c:73: undefined reference to `pthread_create' ld: frame-view.c:76: undefined reference to `pthread_join' collect2: error: ld returned 1 exit status UNTESTED: gdb.base/frame-view.exp: failed to prepare ... Fix this by adding pthreads to the compilation flags. Tested on x86_64-linux.
2023-01-22Remove path name from testTom Tromey1-1/+2
The test suite reports several path names in tests. I couldn't find most of these, and I suspect they are false reports, but I did manage to locate one. This one is probably harmless, as I think the path does not vary; but it's also easy to fix and suppress one warning.
2023-01-22Minor cleanup in gdb.btrace/enable.expTom Tromey1-1/+1
I noticed a weird-looking bit of code in gdb.btrace/enable.exp that is left over from an earlier change. This patch moves the "!" inside the braces, where it belongs.
2023-01-22Minor fixup in allow_aarch64_sve_testsTom Tromey1-1/+1
An earlier patch failed to update a string in allow_aarch64_sve_tests.
2023-01-20gdb: make user-created frames reinflatableSimon Marchi3-4/+89
This patch teaches frame_info_ptr to reinflate user-created frames (frames created through create_new_frame, with the "select-frame view" command). Before this patch, frame_info_ptr doesn't support reinflating user-created frames, because it currently reinflates by getting the current target frame (for frame 0) or frame_find_by_id (for other frames). To reinflate a user-created frame, we need to call create_new_frame, to make it lookup an existing user-created frame, or otherwise create one. So, in prepare_reinflate, get the frame id even if the frame has level 0, if it is user-created. In reinflate, if the saved frame id is user create it, call create_new_frame. In order to test this, I initially enhanced the gdb.base/frame-view.exp test added by the previous patch by setting a pretty-printer for the type of the function parameters, in which we do an inferior call. This causes print_frame_args to not reinflate its frame (which is a user-created one) properly. On one machine (my Arch Linux one), it properly catches the bug, as the frame is not correctly restored after printing the first parameter, so it messes up the second parameter: frame #0 baz (z1=hahaha, z2=<error reading variable: frame address is not available.>) at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/frame-view.c:40 40 return z1.m + z2.n; (gdb) FAIL: gdb.base/frame-view.exp: with_pretty_printer=true: frame frame #0 baz (z1=hahaha, z2=<error reading variable: frame address is not available.>) at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/frame-view.c:40 40 return z1.m + z2.n; (gdb) FAIL: gdb.base/frame-view.exp: with_pretty_printer=true: frame again However, on another machine (my Ubuntu 22.04 one), it just passes fine, without the appropriate fix. I then thought about writing a selftest for that, it's more reliable. I left the gdb.base/frame-view.exp pretty printer test there, it's already written, and we never know, it might catch some unrelated issue some day. Change-Id: I5849baf77991fc67a15bfce4b5e865a97265b386 Reviewed-By: Bruno Larsen <blarsen@redhat.com>
2023-01-20gdb: make it possible to restore selected user-created framesSimon Marchi2-0/+144
I would like to improve frame_info_ptr to automatically grab the information needed to reinflate a frame, and automatically reinflate it as needed. One thing that is in the way is the fact that some frames can be created out of thin air by the create_new_frame function. These frames are not the fruit of unwinding from the target's current frame. These frames are created by the "select-frame view" command. These frames are not correctly handled by the frame save/restore functions, save_selected_frame, restore_selected_frame and lookup_selected_frame. This can be observed here, using the test included in this patch: $ ./gdb --data-directory=data-directory -nx -q testsuite/outputs/gdb.base/frame-view/frame-view Reading symbols from testsuite/outputs/gdb.base/frame-view/frame-view... (gdb) break thread_func Breakpoint 1 at 0x11a2: file /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/frame-view.c, line 42. (gdb) run Starting program: /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/frame-view/frame-view [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib/../lib/libthread_db.so.1". [New Thread 0x7ffff7cc46c0 (LWP 4171134)] [Switching to Thread 0x7ffff7cc46c0 (LWP 4171134)] Thread 2 "frame-view" hit Breakpoint 1, thread_func (p=0x0) at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/frame-view.c:42 42 foo (11); (gdb) info frame Stack level 0, frame at 0x7ffff7cc3ee0: rip = 0x5555555551a2 in thread_func (/home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/frame-view.c:42); saved rip = 0x7ffff7d4e8fd called by frame at 0x7ffff7cc3f80 source language c. Arglist at 0x7ffff7cc3ed0, args: p=0x0 Locals at 0x7ffff7cc3ed0, Previous frame's sp is 0x7ffff7cc3ee0 Saved registers: rbp at 0x7ffff7cc3ed0, rip at 0x7ffff7cc3ed8 (gdb) thread 1 [Switching to thread 1 (Thread 0x7ffff7cc5740 (LWP 4171122))] #0 0x00007ffff7d4b4b6 in ?? () from /usr/lib/libc.so.6 Here, we create a custom frame for thread 1 (using the stack from thread 2, for convenience): (gdb) select-frame view 0x7ffff7cc3f80 0x5555555551a2 The first calls to "frame" looks good: (gdb) frame #0 thread_func (p=0x7ffff7d4e630) at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/frame-view.c:42 42 foo (11); But not the second one: (gdb) frame #0 0x00007ffff7d4b4b6 in ?? () from /usr/lib/libc.so.6 This second "frame" command shows the current target frame instead of the user-created frame. It's not totally clear how the "select-frame view" feature is expected to behave, especially since it's not tested. I heard accounts that it used to be possible to select a frame like this and do "up" and "down" to navigate the backtrace starting from that frame. The fact that create_new_frame calls frame_unwind_find_by_frame to install the right unwinder suggest that it used to be possible. But that doesn't work today: (gdb) select-frame view 0x7ffff7cc3f80 0x5555555551a2 (gdb) up Initial frame selected; you cannot go up. (gdb) down Bottom (innermost) frame selected; you cannot go down. and "backtrace" always shows the actual thread's backtrace, it ignores the user-created frame: (gdb) bt #0 0x00007ffff7d4b4b6 in ?? () from /usr/lib/libc.so.6 #1 0x00007ffff7d50403 in ?? () from /usr/lib/libc.so.6 #2 0x000055555555521a in main () at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/frame-view.c:56 I don't want to address all the `select-frame view` issues , but I think we can agree that the "frame" command changing the selected frame, as shown above, is a bug. I would expect that command to show the currently selected frame and not change it. This happens because of the scoped_restore_selected_frame object in print_frame_args. The frame information is saved in the constructor (the backtrace below), and restored in the destructor. #0 save_selected_frame (frame_id=0x7ffdc0020ad0, frame_level=0x7ffdc0020af0) at /home/simark/src/binutils-gdb/gdb/frame.c:1682 #1 0x00005631390242f0 in scoped_restore_selected_frame::scoped_restore_selected_frame (this=0x7ffdc0020ad0) at /home/simark/src/binutils-gdb/gdb/frame.c:324 #2 0x000056313993581e in print_frame_args (fp_opts=..., func=0x62100023bde0, frame=..., num=-1, stream=0x60b000000300) at /home/simark/src/binutils-gdb/gdb/stack.c:755 #3 0x000056313993ad49 in print_frame (fp_opts=..., frame=..., print_level=1, print_what=SRC_AND_LOC, print_args=1, sal=...) at /home/simark/src/binutils-gdb/gdb/stack.c:1401 #4 0x000056313993835d in print_frame_info (fp_opts=..., frame=..., print_level=1, print_what=SRC_AND_LOC, print_args=1, set_current_sal=1) at /home/simark/src/binutils-gdb/gdb/stack.c:1126 #5 0x0000563139932e0b in print_stack_frame (frame=..., print_level=1, print_what=SRC_AND_LOC, set_current_sal=1) at /home/simark/src/binutils-gdb/gdb/stack.c:368 #6 0x0000563139932bbe in print_stack_frame_to_uiout (uiout=0x611000016840, frame=..., print_level=1, print_what=SRC_AND_LOC, set_current_sal=1) at /home/simark/src/binutils-gdb/gdb/stack.c:346 #7 0x0000563139b0641e in print_selected_thread_frame (uiout=0x611000016840, selection=...) at /home/simark/src/binutils-gdb/gdb/thread.c:1993 #8 0x0000563139940b7f in frame_command_core (fi=..., ignored=true) at /home/simark/src/binutils-gdb/gdb/stack.c:1871 #9 0x000056313994db9e in frame_command_helper<frame_command_core>::base_command (arg=0x0, from_tty=1) at /home/simark/src/binutils-gdb/gdb/stack.c:1976 Since the user-created frame has level 0 (identified by the saved level -1), lookup_selected_frame just reselects the target's current frame, and the user-created frame is lost. My goal here is to fix this particular problem. Currently, select_frame does not set selected_frame_id and selected_frame_level for frames with level 0. It leaves them at null_frame_id / -1, indicating to restore_selected_frame to use the target's current frame. User-created frames also have level 0, so add a special case them such that select_frame saves their selected id and level. save_selected_frame does not need any change. Change the assertion in restore_selected_frame that checks `frame_level != 0` to account for the fact that we can restore user-created frames, which have level 0. Finally, change lookup_selected_frame to make it able to re-create user-created frame_info objects from selected_frame_level and selected_frame_id. Add a minimal test case for the case described above, that is the "select-frame view" command followed by the "frame" command twice. In order to have a known stack frame to switch to, the test spawns a second thread, and tells the first thread to use the other thread's top frame. Change-Id: Ifc77848dc465fbd21324b9d44670833e09fe98c7 Reviewed-By: Bruno Larsen <blarsen@redhat.com>
2023-01-20Make gdb.ada/ptype_tagged_param.exp passTom Tromey1-19/+23
gdb.ada/ptype_tagged_param.exp is failing for me on x86-64 Fedora 36. However, it's actually generating the correct output -- it is just that the test thinks that the "ptype" will not work because I do not have the GNAT debuginfo installed. This patch changes the code to accept either result, and then to issue a kfail as appropriate.
2023-01-20gdb/dwarf: fix UBsan crash in read_subrange_typeSimon Marchi1-0/+22
When running gdb.ada/arrayptr.exp (and others) on Ubuntu 22.04, with the `gnat-11` package installed (not `gnat`), with UBSan activated, I get: (gdb) break foo.adb:40 /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:17689:20: runtime error: shift exponent 127 is too large for 64-bit type 'long unsigned int' The problematic DIEs are: 0x00001460: DW_TAG_subrange_type DW_AT_lower_bound [DW_FORM_data1] (0x00) DW_AT_upper_bound [DW_FORM_data16] (ffffffffffffffff3f00000000000000) DW_AT_name [DW_FORM_strp] ("foo__packed_array___XP7___XDLU_0__1180591620717411303423") DW_AT_type [DW_FORM_ref4] (0x0000153f "long_long_long_unsigned") DW_AT_GNAT_descriptive_type [DW_FORM_ref4] (0x0000147e) DW_AT_artificial [DW_FORM_flag_present] (true) 0x0000153f: DW_TAG_base_type DW_AT_byte_size [DW_FORM_data1] (0x10) DW_AT_encoding [DW_FORM_data1] (DW_ATE_unsigned) DW_AT_name [DW_FORM_strp] ("long_long_long_unsigned") DW_AT_artificial [DW_FORM_flag_present] (true) When processed by this code: negative_mask = -((ULONGEST) 1 << (base_type->length () * TARGET_CHAR_BIT - 1)); if (low.kind () == PROP_CONST && !base_type->is_unsigned () && (low.const_val () & negative_mask)) low.set_const_val (low.const_val () | negative_mask); When the base type's length (16 bytes in this case) is larger than a ULONGEST (typically 8 bytes), the bit shift is too large. My obvious fix is just to skip the fixup for base types larger than a ULONGEST (8 bytes). I don't think we really handle constant attribute values larger than 8 bytes anyway, so this is part of a much larger problem. Add a test that replicates this situation, but uses bounds that fit in a signed 64 bit, so we get a sensible result. Change-Id: I8d0a24f3edd83b44e0761a0ce38922d3e2e112fb Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29386
2023-01-20gdb/testsuite: add test for negative subrange bounds with unsigned formSimon Marchi1-0/+25
I am looking at this code [1]: /* Normally, the DWARF producers are expected to use a signed constant form (Eg. DW_FORM_sdata) to express negative bounds. But this is unfortunately not always the case, as witnessed with GCC, for instance, where the ambiguous DW_FORM_dataN form is used instead. To work around that ambiguity, we treat the bounds as signed, and thus sign-extend their values, when the base type is signed. */ negative_mask = -((ULONGEST) 1 << (base_type->length () * TARGET_CHAR_BIT - 1)); if (low.kind () == PROP_CONST && !base_type->is_unsigned () && (low.const_val () & negative_mask)) low.set_const_val (low.const_val () | negative_mask); if (high.kind () == PROP_CONST && !base_type->is_unsigned () && (high.const_val () & negative_mask)) high.set_const_val (high.const_val () | negative_mask); Nothing in the testsuite seems to exercise it, as when I remove it, all of gdb.dwarf2 still passes. And tests in other directories would be compiler-dependent, so would rely on having a buggy compiler. Update gdb.dwarf2/subrange.exp to have a test for it. When removing the code above, the new test fails with: ptype array_with_buggy_negative_bounds_type^M type = array [240..244] of signed_byte^M (gdb) FAIL: gdb.dwarf2/subrange.exp: ptype array_with_buggy_negative_bounds_type instead of the expected: ptype array_with_buggy_negative_bounds_type^M type = array [-16..-12] of signed_byte^M (gdb) PASS: gdb.dwarf2/subrange.exp: ptype array_with_buggy_negative_bounds_type [1] https://gitlab.com/gnutools/binutils-gdb/-/blob/5ea14aa4e53fa37f4ba4517497ed2c1e4c60dee2/gdb/dwarf2/read.c#L17681-17695 Change-Id: I1992a3ff0cb1e90fa8a9114dae6c591792f059c2
2023-01-19Use "maint ignore-probes" in no-libstdcxx-probe.expTom Tromey1-5/+4
While looking at some test output, I saw that no-libstdcxx-probe.exp was not being run. However, it occurred to me that Tom de Vries' new "maint ignore-probes" command could be used to enable this test unconditionally. Reviewed-by: Tom de Vries <tdevries@suse.de>
2023-01-19GDB/testsuite: Expand for character string limiting optionsAndrew Burgess9-38/+306
Modify test cases that verify the operation of the array element limit with character strings such that they are executed twice, once with the `set print characters' option set to `elements' and the limit controlled with the `set print elements' option, and then again with the limit controlled with the `set print characters' option instead. Similarly with the `-elements' and `-characters' options for the `print' command. Additionally verify that said `print' command options combined yield the expected result. Verify correct $_gdb_setting and $_gdb_setting_str values for the `print characters' setting, in particular the `void' value for the `elements' default, which has no corresponding integer value exposed. Add Guile and Python coverage for the `print characters' GDB setting. There are new tests for Ada and Pascal, as the string printing code for these languages is different than the generic string printing code used by other languages. Modula2 also has different string printing code, but (a) this is similar to Pascal, and (b) there are no existing modula2 tests written in Modula2, so I'm not sure how I'd even test the Modula2 string printing. Co-Authored-By: Maciej W. Rozycki <macro@embecosm.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-01-19GDB: Add a character string limiting optionAndrew Burgess2-0/+8
This commit splits the `set/show print elements' option into two. We retain `set/show print elements' for controlling how many elements of an array we print, but a new `set/show print characters' setting is added which is used for controlling how many characters of a string are printed. The motivation behind this change is to allow users a finer level of control over how data is printed, reflecting that, although strings can be thought of as arrays of characters, users often want to treat these two things differently. For compatibility reasons by default the `set/show print characters' option is set to `elements', which makes the limit for character strings follow the setting of the `set/show print elements' option, as it used to. Using `set print characters' with any other value makes the limit independent from the `set/show print elements' setting, however it can be restored to the default with the `set print characters elements' command at any time. A corresponding `-characters' option for the `print' command is added, with the same semantics, i.e. one can use `elements' to make a given `print' invocation follow the limit of elements, be it set with the `-elements' option also given with the same invocation or taken from the `set/show print elements' setting, for characters as well regardless of the current setting of the `set/show print characters' option. The GDB changes are all pretty straightforward, just changing references to the old 'print_max' to use a new `get_print_max_chars' helper which figures out which of the two of `print_max' and `print_max_chars' values to use. Likewise, the documentation is just updated to reference the new setting where appropriate. To make people's life easier the message shown by `show print elements' now indicates if the setting also applies to character strings: (gdb) set print characters elements (gdb) show print elements Limit on string chars or array elements to print is 200. (gdb) set print characters unlimited (gdb) show print elements Limit on array elements to print is 200. (gdb) and the help text shows the dependency as well: (gdb) help set print elements Set limit on array elements to print. "unlimited" causes there to be no limit. This setting also applies to string chars when "print characters" is set to "elements". (gdb) In the testsuite there are two minor updates, one to add `-characters' to the list of completions now shown for the `print' command, and a bare minimum pair of checks for the right handling of `set print characters' and `show print characters', copied from the corresponding checks for `set print elements' and `show print elements' respectively. Co-Authored-By: Maciej W. Rozycki <macro@embecosm.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-01-19GDB: Allow arbitrary keywords in integer set commandsMaciej W. Rozycki6-38/+53
Rather than just `unlimited' allow the integer set commands (or command options) to define arbitrary keywords for the user to use, removing hardcoded arrangements for the `unlimited' keyword. Remove the confusingly named `var_zinteger', `var_zuinteger' and `var_zuinteger_unlimited' `set'/`show' command variable types redefining them in terms of `var_uinteger', `var_integer' and `var_pinteger', which have the range of [0;UINT_MAX], [INT_MIN;INT_MAX], and [0;INT_MAX] each. Following existing practice `var_pinteger' allows extra negative values to be used, however unlike `var_zuinteger_unlimited' any number of such values can be defined rather than just `-1'. The "p" in `var_pinteger' stands for "positive", for the lack of a more appropriate unambiguous letter, even though 0 obviously is not positive; "n" would be confusing as to whether it stands for "non-negative" or "negative". Add a new structure, `literal_def', the entries of which define extra keywords allowed for a command and numerical values they correspond to. Those values are not verified against the basic range supported by the underlying variable type, allowing extra values to be allowed outside that range, which may or may not be individually made visible to the user. An optional value translation is possible with the structure to follow the existing practice for some commands where user-entered 0 is internally translated to UINT_MAX or INT_MAX. Such translation can now be arbitrary. Literals defined by this structure are automatically used for completion as necessary. So for example: const literal_def integer_unlimited_literals[] = { { "unlimited", INT_MAX, 0 }, { nullptr } }; defines an extra `unlimited' keyword and a user-visible 0 value, both of which get translated to INT_MAX for the setting to be used with. Similarly: const literal_def zuinteger_unlimited_literals[] = { { "unlimited", -1, -1 }, { nullptr } }; defines the same keyword and a corresponding user-visible -1 value that is used for the requested setting. If the last member were omitted (or set to `{}') here, then only the keyword would be allowed for the user to enter and while -1 would still be used internally trying to enter it as a part of a command would result in an "integer -1 out of range" error. Use said error message in all cases (citing the invalid value requested) replacing "only -1 is allowed to set as unlimited" previously used for `var_zuinteger_unlimited' settings only rather than propagating it to `var_pinteger' type. It could only be used for the specific case where a single extra `unlimited' keyword was defined standing for -1 and the use of numeric equivalents is discouraged anyway as it is for historical reasons only that they expose GDB internals, confusingly different across variable types. Similarly update the "must be >= -1" Guile error message. Redefine Guile and Python parameter types in terms of the new variable types and interpret extra keywords as Scheme keywords and Python strings used to communicate corresponding parameter values. Do not add a new PARAM_INTEGER Guile parameter type, however do handle the `var_integer' variable type now, permitting existing parameters defined by GDB proper, such as `listsize', to be accessed from Scheme code. With these changes in place it should be trivial for a Scheme or Python programmer to expand the syntax of the `make-parameter' command and the `gdb.Parameter' class initializer to have arbitrary extra literals along with their internal representation supplied. Update the testsuite accordingly. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-01-19[gdb/testsuite] Fix gdb.python/py-value-cc.exp for big endianTom de Vries2-2/+3
On s390x-linux, I run into: ... (gdb) python print(u[u_fields[0]])^M 99^M (gdb) PASS: gdb.python/py-value-cc.exp: u's first field via field python print(u[u_fields[1]])^M 0 '\000'^M (gdb) FAIL: gdb.python/py-value-cc.exp: u's second field via field ... There's a var u of this type: ... union U { int a; char c; }; ... and after assigning 99 to u.a, the test-case expects u.c to contain 99 (which it does on x86_64), but instead it contains 0. Fix this by instead assigning 0x63636363, to ensure that u.c == 99 for both little and big endian. Tested on x86_64-linux and s390x-linux.
2023-01-18Revert "X86: reverse-finish fix"Carl Love9-200/+57
This reverts commit b22548ddb30bfb167708e82d3bb932461c1b703a. This patch is being reverted since the patch series is causing regressions.
2023-01-18Revert "PowerPC: fix for gdb.reverse/finish-precsave.exp and ↵Carl Love2-120/+15
gdb.reverse/finish-reverse.exp" This reverts commit 92e07580db6a5572573d5177ca23933064158f89. Reverting patch as the patch series is causing regressions.
2023-01-18gdb: care for dynamic objfiles in build_id_bfd_get ()Jan Vrany1-0/+4
Accessing gdb.Objfile.build_id caused GDB to crash when objfile is dynamic, that is created by JIT reader API. The issue was NULL-pointer dereferencing in build_id_bfd_get () because dynamic objfiles have no underlaying BFD structure. This commit fixes the problem by a NULL-check in build_id_bfd_get ().
2023-01-17Use require in paramless.expTom Tromey1-1/+1
The new paramless.exp test was not converted to the new "require" approach. This patch fixes the problem.
2023-01-17PowerPC: fix for gdb.reverse/finish-precsave.exp and ↵Carl Love2-15/+120
gdb.reverse/finish-reverse.exp PR record/29927 - reverse-finish requires two reverse next instructions to reach previous source line PowerPC uses two entry points called the local entry point (LEP) and the global entry point (GEP). Normally the LEP is used when calling a function. However, if the table of contents (TOC) value in register 2 is not valid the GEP is called to setup the TOC before execution continues at the LEP. When executing in reverse, the function finish_backward sets the break point at the alternate entry point (GEP). However if the forward execution enters via the normal entry point (LEP), the reverse execution never sees the break point at the GEP of the function. Reverse execution continues until the next break point is encountered or the end of the recorded log is reached causing gdb to stop at the wrong place. This patch adds a new address to struct execution_control_state to hold the address of the alternate function start address, known as the GEP on PowerPC. The finish_backwards function is updated. If the stopping point is between the two entry points (the LEP and GEP on PowerPC), the stepping range is set to execute back to the alternate entry point (GEP on PowerPC). Otherwise, a breakpoint is inserted at the normal entry point (LEP on PowerPC). Function process_event_stop_test checks uses a stepping range to stop execution in the caller at the first instruction of the source code line. Note, on systems that only support one entry point, the address of the two entry points are the same. Test finish-reverse-next.exp is updated to include tests for the reverse-finish command when the function is entered via the normal entry point (i.e. the LEP) and the alternate entry point (i.e. the GEP). The patch has been tested on X86 and PowerPC with no regressions.
2023-01-17X86: reverse-finish fixCarl Love9-57/+200
PR record/29927 - reverse-finish requires two reverse next instructions to reach previous source line Currently on X86, when executing the finish command in reverse, gdb does a single step from the first instruction in the callee to get back to the caller. GDB stops on the last instruction in the source code line where the call was made. When stopped at the last instruction of the source code line, a reverse next or step command will stop at the first instruction of the same source code line thus requiring two step/next commands to reach the previous source code line. It should only require one step/next command to reach the previous source code line. By contrast, a reverse next or step command from the first line in a function stops at the first instruction in the source code line where the call was made. This patch fixes the reverse finish command so it will stop at the first instruction of the source line where the function call was made. The behavior on X86 for the reverse-finish command now matches doing a reverse-next from the beginning of the function. The proceed_to_finish flag in struct thread_control_state is no longer used. This patch removes the declaration, initialization and setting of the flag. This patch requires a number of regression tests to be updated. Test gdb.mi/mi-reverse.exp no longer needs to execute two steps to get to the previous line. The gdb output for tests gdb.reverse/until-precsave.exp and gdb.reverse/until-reverse.exp changed slightly. The expected result in tests gdb.reverse/amd64-failcall-reverse.exp and gdb.reverse/singlejmp-reverse.exp are updated to the correct expected result. This patch adds a new test gdb.reverse/finish-reverse-next.exp to test the reverse-finish command when returning from the entry point and from the body of the function. The step_until proceedure in test gdb.reverse/step-indirect-call-thunk.exp was moved to lib/gdb.exp and renamed cmd_until. The patch has been tested on X86 and PowerPC to verify no additional regression failures occured. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29927
2023-01-17gdb/testsuite: expect SIGSEGV from top GDB spawn idSimon Marchi2-2/+2
When testing with the native-extended-gdbserver, I get: Thread 1 "xgdb" received signal SIGSEGV, Segmentation fault. 0x00007ffff6d828f2 in GC_find_limit_with_bound () from /usr/lib/x86_64-linux-gnu/libgc.so.1 (gdb) FAIL: gdb.gdb/selftest.exp: xgdb is at prompt This is because the -re that is supposed to match this SIGSEGV is after `-i $inferior_spawn_id`. On native, the top and bottom GDB are on the same spawn id, so it ends up working. But with a gdbserver board, that's not the case. Move the SIGSEGV -re before the `-i $inferior_spawn_id` line, such that it matches what the top GDB outputs. Do the same fix in gdb.gdb/python-helper.exp. Change-Id: I3291630e218a5a3a6a47805b999ddbc9b968c927 Approved-By: Tom Tromey <tom@tromey.com>