aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/Makefile.in12
-rw-r--r--gdb/testsuite/gdb.ada/dyn-bit-offset.exp43
-rw-r--r--gdb/testsuite/gdb.ada/dyn-bit-offset/exam.adb2
-rw-r--r--gdb/testsuite/gdb.ada/finish-var-size.exp8
-rw-r--r--gdb/testsuite/gdb.ada/negative-bit-offset.exp36
-rw-r--r--gdb/testsuite/gdb.ada/negative-bit-offset/prog.adb36
-rw-r--r--gdb/testsuite/gdb.ada/operator_call.exp6
-rw-r--r--gdb/testsuite/gdb.ada/return-small-char-array.exp40
-rw-r--r--gdb/testsuite/gdb.ada/return-small-char-array/proc.adb22
-rw-r--r--gdb/testsuite/gdb.ada/return-small-char-array/value.adb21
-rw-r--r--gdb/testsuite/gdb.ada/return-small-char-array/value.ads20
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs-core.c123
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs-core.exp113
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs-disp-step.c140
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs-disp-step.exp86
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs-return.c105
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs-return.exp129
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs-tdesc-without-linux.xml65
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs-wrong-tdesc.c26
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs-wrong-tdesc.exp48
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs.c180
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-gcs.exp98
-rw-r--r--gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp1
-rw-r--r--gdb/testsuite/gdb.arch/amd64-disp-step-self-call-alarm.c18
-rw-r--r--gdb/testsuite/gdb.arch/amd64-disp-step-self-call.S23
-rw-r--r--gdb/testsuite/gdb.arch/amd64-shadow-stack-cmds.exp143
-rw-r--r--gdb/testsuite/gdb.arch/amd64-shadow-stack-corefile.c46
-rw-r--r--gdb/testsuite/gdb.arch/amd64-shadow-stack-corefile.exp119
-rw-r--r--gdb/testsuite/gdb.arch/amd64-shadow-stack-disp-step.exp84
-rw-r--r--gdb/testsuite/gdb.arch/amd64-shadow-stack.c40
-rw-r--r--gdb/testsuite/gdb.arch/amd64-shadow-stack.exp71
-rw-r--r--gdb/testsuite/gdb.arch/amd64-watchpoint-downgrade.exp2
-rw-r--r--gdb/testsuite/gdb.arch/i386-disp-step-self-call-alarm.c18
-rw-r--r--gdb/testsuite/gdb.arch/i386-disp-step-self-call.S23
-rw-r--r--gdb/testsuite/gdb.arch/i386-prologue-skip-cf-protection-stackalign.c27
-rw-r--r--gdb/testsuite/gdb.arch/i386-prologue-skip-cf-protection.exp70
-rw-r--r--gdb/testsuite/gdb.base/a2-run.exp7
-rw-r--r--gdb/testsuite/gdb.base/annotate-symlink.exp2
-rw-r--r--gdb/testsuite/gdb.base/args.exp1
-rw-r--r--gdb/testsuite/gdb.base/attach-deleted-exec.exp44
-rw-r--r--gdb/testsuite/gdb.base/attach.c4
-rw-r--r--gdb/testsuite/gdb.base/backtrace-through-cu-nodebug.exp69
-rw-r--r--gdb/testsuite/gdb.base/backtrace.exp6
-rw-r--r--gdb/testsuite/gdb.base/bp-cond-failure.exp4
-rw-r--r--gdb/testsuite/gdb.base/bp-permanent.c2
-rw-r--r--gdb/testsuite/gdb.base/bp-permanent.exp4
-rw-r--r--gdb/testsuite/gdb.base/break-dbg.cc31
-rw-r--r--gdb/testsuite/gdb.base/break-dbg.exp80
-rw-r--r--gdb/testsuite/gdb.base/break-interp.exp1
-rw-r--r--gdb/testsuite/gdb.base/catch-fork-kill.exp2
-rw-r--r--gdb/testsuite/gdb.base/catch-fork-static.exp4
-rw-r--r--gdb/testsuite/gdb.base/catch-signal-fork.exp1
-rw-r--r--gdb/testsuite/gdb.base/color-prompt.exp29
-rw-r--r--gdb/testsuite/gdb.base/command-line-input.exp60
-rw-r--r--gdb/testsuite/gdb.base/corefile-shmem-zero-id-lib.c522
-rw-r--r--gdb/testsuite/gdb.base/corefile-shmem-zero-id.c63
-rw-r--r--gdb/testsuite/gdb.base/corefile-shmem-zero-id.exp228
-rw-r--r--gdb/testsuite/gdb.base/corefile.exp1
-rw-r--r--gdb/testsuite/gdb.base/corefile2.exp1
-rw-r--r--gdb/testsuite/gdb.base/corefile3.exp1
-rw-r--r--gdb/testsuite/gdb.base/default.exp264
-rw-r--r--gdb/testsuite/gdb.base/dlmopen-ns-ids.exp181
-rw-r--r--gdb/testsuite/gdb.base/dlmopen.exp38
-rw-r--r--gdb/testsuite/gdb.base/dump.c2
-rw-r--r--gdb/testsuite/gdb.base/dump.exp9
-rw-r--r--gdb/testsuite/gdb.base/exprs.exp5
-rw-r--r--gdb/testsuite/gdb.base/filename-completion.exp27
-rw-r--r--gdb/testsuite/gdb.base/foll-exec-c++.exp24
-rw-r--r--gdb/testsuite/gdb.base/foll-exec-c.exp23
-rw-r--r--gdb/testsuite/gdb.base/foll-exec.c33
-rw-r--r--gdb/testsuite/gdb.base/foll-exec.exp.tcl (renamed from gdb/testsuite/gdb.base/foll-exec.exp)90
-rw-r--r--gdb/testsuite/gdb.base/foll-fork-syscall.c35
-rw-r--r--gdb/testsuite/gdb.base/foll-fork-syscall.exp143
-rw-r--r--gdb/testsuite/gdb.base/foll-fork.exp2
-rw-r--r--gdb/testsuite/gdb.base/foll-vfork.exp7
-rw-r--r--gdb/testsuite/gdb.base/fork-no-detach-follow-child-dlopen.exp1
-rw-r--r--gdb/testsuite/gdb.base/fork-print-inferior-events.exp2
-rw-r--r--gdb/testsuite/gdb.base/fork-running-state.exp2
-rw-r--r--gdb/testsuite/gdb.base/fullname.exp2
-rw-r--r--gdb/testsuite/gdb.base/infcall-failure-2.exp37
-rw-r--r--gdb/testsuite/gdb.base/infcall-failure.exp16
-rw-r--r--gdb/testsuite/gdb.base/inferior-args.exp1
-rw-r--r--gdb/testsuite/gdb.base/inferior-died.exp5
-rw-r--r--gdb/testsuite/gdb.base/info-shared.exp3
-rw-r--r--gdb/testsuite/gdb.base/info_sources_2.exp35
-rw-r--r--gdb/testsuite/gdb.base/inline-frame-cycle-unwind.py4
-rw-r--r--gdb/testsuite/gdb.base/interrupt-daemon.exp2
-rw-r--r--gdb/testsuite/gdb.base/jit-elf-fork.exp1
-rw-r--r--gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp1
-rw-r--r--gdb/testsuite/gdb.base/macro-source-path.exp4
-rw-r--r--gdb/testsuite/gdb.base/maint.exp38
-rw-r--r--gdb/testsuite/gdb.base/many-headers.exp1
-rw-r--r--gdb/testsuite/gdb.base/multi-forks.exp6
-rw-r--r--gdb/testsuite/gdb.base/options.exp16
-rw-r--r--gdb/testsuite/gdb.base/pie-fork.exp2
-rw-r--r--gdb/testsuite/gdb.base/readline-ask.exp2
-rw-r--r--gdb/testsuite/gdb.base/readline.exp2
-rw-r--r--gdb/testsuite/gdb.base/run-control-while-bg-execution.exp5
-rw-r--r--gdb/testsuite/gdb.base/sigall.exp9
-rw-r--r--gdb/testsuite/gdb.base/source-dir.exp52
-rw-r--r--gdb/testsuite/gdb.base/source-search.c127
-rw-r--r--gdb/testsuite/gdb.base/source-search.exp106
-rw-r--r--gdb/testsuite/gdb.base/startup-with-shell.exp2
-rw-r--r--gdb/testsuite/gdb.base/step-over-exit.exp7
-rw-r--r--gdb/testsuite/gdb.base/style.exp289
-rw-r--r--gdb/testsuite/gdb.base/tls-common.exp.tcl2
-rw-r--r--gdb/testsuite/gdb.base/tls-dlobj-lib.c2
-rw-r--r--gdb/testsuite/gdb.base/tls-dlobj.c2
-rw-r--r--gdb/testsuite/gdb.base/tls-dlobj.exp2
-rw-r--r--gdb/testsuite/gdb.base/tls-multiobj.c2
-rw-r--r--gdb/testsuite/gdb.base/tls-multiobj.exp2
-rw-r--r--gdb/testsuite/gdb.base/tls-multiobj1.c2
-rw-r--r--gdb/testsuite/gdb.base/tls-multiobj2.c2
-rw-r--r--gdb/testsuite/gdb.base/tls-multiobj3.c2
-rw-r--r--gdb/testsuite/gdb.base/tls-nothreads.c2
-rw-r--r--gdb/testsuite/gdb.base/tls-nothreads.exp2
-rw-r--r--gdb/testsuite/gdb.base/user-namespace-attach.c35
-rw-r--r--gdb/testsuite/gdb.base/user-namespace-attach.exp148
-rw-r--r--gdb/testsuite/gdb.base/vfork-follow-parent.exp2
-rw-r--r--gdb/testsuite/gdb.base/watch-before-fork.exp2
-rw-r--r--gdb/testsuite/gdb.base/watch-vfork.exp2
-rw-r--r--gdb/testsuite/gdb.base/watchpoint-hw-attach.exp21
-rw-r--r--gdb/testsuite/gdb.base/watchpoint-unaligned.c37
-rw-r--r--gdb/testsuite/gdb.base/watchpoint-unaligned.exp111
-rw-r--r--gdb/testsuite/gdb.base/wchar.exp4
-rw-r--r--gdb/testsuite/gdb.btrace/multi-inferior.exp2
-rw-r--r--gdb/testsuite/gdb.cp/chained-calls.cc17
-rw-r--r--gdb/testsuite/gdb.cp/chained-calls.exp3
-rw-r--r--gdb/testsuite/gdb.cp/cpexprs.exp.tcl36
-rw-r--r--gdb/testsuite/gdb.cp/method-ref-return.cc42
-rw-r--r--gdb/testsuite/gdb.cp/method-ref-return.exp70
-rw-r--r--gdb/testsuite/gdb.cp/static-print-quit.exp23
-rw-r--r--gdb/testsuite/gdb.dap/attach.exp4
-rw-r--r--gdb/testsuite/gdb.dap/log-message.exp9
-rw-r--r--gdb/testsuite/gdb.dap/scopes.c2
-rw-r--r--gdb/testsuite/gdb.dap/scopes.exp247
-rw-r--r--gdb/testsuite/gdb.dap/threads.c67
-rw-r--r--gdb/testsuite/gdb.dap/threads.exp81
-rw-r--r--gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp2
-rw-r--r--gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp4
-rw-r--r--gdb/testsuite/gdb.debuginfod/solib-with-soname.exp2
-rw-r--r--gdb/testsuite/gdb.dwarf2/ada-array-bound.c29
-rw-r--r--gdb/testsuite/gdb.dwarf2/ada-array-bound.exp89
-rw-r--r--gdb/testsuite/gdb.dwarf2/backward-spec-inter-cu.exp6
-rw-r--r--gdb/testsuite/gdb.dwarf2/debug-names-non-ascending-cu.exp81
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw-form-ref-addr-with-type-units.exp109
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw-form-strx-out-of-bounds.exp6
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw-form-strx.exp2
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw-form-strx.exp.tcl12
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-entry-points.c17
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp7
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-linkage-name-trust.exp2
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-modula2-self-type.S6
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-ranges-psym-warning.exp2
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-simple-locdesc.S6
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-strp.S6
-rw-r--r--gdb/testsuite/gdb.dwarf2/dynamic-bit-offset.exp95
-rw-r--r--gdb/testsuite/gdb.dwarf2/fission-dw-form-strx.exp88
-rw-r--r--gdb/testsuite/gdb.dwarf2/forward-spec-inter-cu.exp6
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw4.exp4
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw5.exp4
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld234-dw5.exp4
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw4.exp4
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw5.exp4
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path.exp.tcl4
-rw-r--r--gdb/testsuite/gdb.dwarf2/pr11465.S6
-rw-r--r--gdb/testsuite/gdb.dwarf2/varval.exp2
-rw-r--r--gdb/testsuite/gdb.gdb/index-file.exp7
-rw-r--r--gdb/testsuite/gdb.gdb/python-helper.exp22
-rw-r--r--gdb/testsuite/gdb.gdb/selftest.exp2
-rw-r--r--gdb/testsuite/gdb.guile/scm-cmd.exp59
-rw-r--r--gdb/testsuite/gdb.guile/scm-color.exp1
-rw-r--r--gdb/testsuite/gdb.guile/scm-frame.exp2
-rw-r--r--gdb/testsuite/gdb.guile/scm-parameter.exp275
-rw-r--r--gdb/testsuite/gdb.linespec/linespec.exp6
-rw-r--r--gdb/testsuite/gdb.linespec/lspec.cc2
-rw-r--r--gdb/testsuite/gdb.mi/interrupt-thread-group.exp2
-rw-r--r--gdb/testsuite/gdb.mi/mi-condbreak-throw.exp2
-rw-r--r--gdb/testsuite/gdb.mi/mi-corefile.exp1
-rw-r--r--gdb/testsuite/gdb.mi/mi-dlmopen.exp14
-rw-r--r--gdb/testsuite/gdb.mi/mi-exec-run.exp5
-rw-r--r--gdb/testsuite/gdb.mi/mi-multi-commands.exp2
-rw-r--r--gdb/testsuite/gdb.mi/mi-var-display.exp4
-rw-r--r--gdb/testsuite/gdb.mi/user-selected-context-sync.exp4
-rw-r--r--gdb/testsuite/gdb.multi/attach-no-multi-process.exp5
-rw-r--r--gdb/testsuite/gdb.multi/attach-while-running.exp3
-rw-r--r--gdb/testsuite/gdb.multi/bp-thread-specific.exp2
-rw-r--r--gdb/testsuite/gdb.multi/dummy-frame-restore.exp2
-rw-r--r--gdb/testsuite/gdb.multi/multi-arch.exp2
-rw-r--r--gdb/testsuite/gdb.multi/multi-attach.exp2
-rw-r--r--gdb/testsuite/gdb.multi/multi-exit.exp2
-rw-r--r--gdb/testsuite/gdb.multi/multi-kill.exp2
-rw-r--r--gdb/testsuite/gdb.multi/multi-re-run.exp2
-rw-r--r--gdb/testsuite/gdb.multi/multi-target.exp.tcl4
-rw-r--r--gdb/testsuite/gdb.multi/multi-term-settings.exp2
-rw-r--r--gdb/testsuite/gdb.multi/pending-bp.exp6
-rw-r--r--gdb/testsuite/gdb.multi/start-inferior-specific.exp2
-rw-r--r--gdb/testsuite/gdb.multi/stop-all-on-exit.exp2
-rw-r--r--gdb/testsuite/gdb.multi/tids-gid-reset.exp2
-rw-r--r--gdb/testsuite/gdb.multi/tids.exp7
-rw-r--r--gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp2
-rw-r--r--gdb/testsuite/gdb.multi/watchpoint-multi.exp2
-rw-r--r--gdb/testsuite/gdb.opt/break-on-_exit.exp2
-rw-r--r--gdb/testsuite/gdb.pascal/integers.exp2
-rw-r--r--gdb/testsuite/gdb.python/py-cmd.exp93
-rw-r--r--gdb/testsuite/gdb.python/py-color-pagination.exp137
-rw-r--r--gdb/testsuite/gdb.python/py-color-pagination.py46
-rw-r--r--gdb/testsuite/gdb.python/py-color.exp1
-rw-r--r--gdb/testsuite/gdb.python/py-format-string.exp4
-rw-r--r--gdb/testsuite/gdb.python/py-parameter-prefix.exp382
-rw-r--r--gdb/testsuite/gdb.python/py-parameter.exp195
-rw-r--r--gdb/testsuite/gdb.python/py-source-styling-2.exp24
-rw-r--r--gdb/testsuite/gdb.python/py-startup-opt.exp1
-rw-r--r--gdb/testsuite/gdb.python/py-styled-execute.exp1
-rw-r--r--gdb/testsuite/gdb.python/py-symbol.exp1
-rw-r--r--gdb/testsuite/gdb.python/py-warning.exp63
-rw-r--r--gdb/testsuite/gdb.python/python.exp16
-rw-r--r--gdb/testsuite/gdb.replay/connect.exp2
-rw-r--r--gdb/testsuite/gdb.reverse/i386-avx-reverse.c359
-rw-r--r--gdb/testsuite/gdb.reverse/i386-avx-reverse.exp571
-rw-r--r--gdb/testsuite/gdb.reverse/solib-precsave.exp2
-rw-r--r--gdb/testsuite/gdb.reverse/solib-reverse.exp2
-rw-r--r--gdb/testsuite/gdb.rocm/code-object-load-while-breakpoint-hit.cpp86
-rw-r--r--gdb/testsuite/gdb.rocm/code-object-load-while-breakpoint-hit.exp68
-rw-r--r--gdb/testsuite/gdb.rocm/fork-exec-gpu-to-non-gpu.exp1
-rw-r--r--gdb/testsuite/gdb.rocm/fork-exec-non-gpu-to-gpu.exp1
-rw-r--r--gdb/testsuite/gdb.rocm/mi-attach.cpp4
-rw-r--r--gdb/testsuite/gdb.rocm/precise-memory-fork.exp1
-rw-r--r--gdb/testsuite/gdb.rocm/precise-memory.exp2
-rw-r--r--gdb/testsuite/gdb.server/build-id-seqno.exp6
-rw-r--r--gdb/testsuite/gdb.server/fileio-packets.exp66
-rw-r--r--gdb/testsuite/gdb.server/fileio-packets.py208
-rw-r--r--gdb/testsuite/gdb.server/non-existing-program.exp4
-rw-r--r--gdb/testsuite/gdb.server/pread-offset-size.S29
-rw-r--r--gdb/testsuite/gdb.server/pread-offset-size.exp49
-rw-r--r--gdb/testsuite/gdb.stabs/weird.def2
-rw-r--r--gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.exp84
-rwxr-xr-xgdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.gdb25
-rw-r--r--gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp89
-rw-r--r--gdb/testsuite/gdb.threads/corethreads.exp1
-rw-r--r--gdb/testsuite/gdb.threads/current-lwp-dead.exp2
-rw-r--r--gdb/testsuite/gdb.threads/detach-step-over.exp2
-rw-r--r--gdb/testsuite/gdb.threads/foll-fork-other-thread.exp2
-rw-r--r--gdb/testsuite/gdb.threads/fork-child-threads.exp5
-rw-r--r--gdb/testsuite/gdb.threads/fork-plus-threads.exp2
-rw-r--r--gdb/testsuite/gdb.threads/fork-thread-pending.exp6
-rw-r--r--gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp2
-rw-r--r--gdb/testsuite/gdb.threads/info-threads-options.c77
-rw-r--r--gdb/testsuite/gdb.threads/info-threads-options.exp131
-rw-r--r--gdb/testsuite/gdb.threads/next-fork-exec-other-thread.exp2
-rw-r--r--gdb/testsuite/gdb.threads/next-fork-other-thread.exp2
-rw-r--r--gdb/testsuite/gdb.threads/pending-fork-event-detach-ns.exp2
-rw-r--r--gdb/testsuite/gdb.threads/pending-fork-event-detach.exp2
-rw-r--r--gdb/testsuite/gdb.threads/thread-bp-deleted.exp2
-rw-r--r--gdb/testsuite/gdb.threads/thread-execl.c10
-rw-r--r--gdb/testsuite/gdb.threads/threadapply.exp6
-rw-r--r--gdb/testsuite/gdb.threads/vfork-follow-child-exec.exp2
-rw-r--r--gdb/testsuite/gdb.threads/vfork-follow-child-exit.exp2
-rw-r--r--gdb/testsuite/gdb.threads/vfork-multi-inferior.exp4
-rw-r--r--gdb/testsuite/gdb.threads/vfork-multi-thread.exp2
-rw-r--r--gdb/testsuite/gdb.threads/watchpoint-fork.exp2
-rw-r--r--gdb/testsuite/gdb.trace/tspeed.exp2
-rw-r--r--gdb/testsuite/gdb.tui/basic.exp6
-rw-r--r--gdb/testsuite/gdb.tui/color-prompt.exp10
-rw-r--r--gdb/testsuite/gdb.tui/color-prompt.exp.tcl80
-rw-r--r--gdb/testsuite/gdb.tui/esc-match.exp48
-rw-r--r--gdb/testsuite/gdb.tui/esc-match.py26
-rwxr-xr-xgdb/testsuite/gdb.tui/gdb.tcl20
-rw-r--r--gdb/testsuite/gdb.tui/main-2.exp4
-rw-r--r--gdb/testsuite/gdb.tui/main.exp5
-rw-r--r--gdb/testsuite/gdb.tui/new-layout.exp3
-rw-r--r--gdb/testsuite/gdb.tui/pr30056.exp9
-rw-r--r--gdb/testsuite/gdb.tui/source-search.c127
-rw-r--r--gdb/testsuite/gdb.tui/source-search.exp72
-rw-r--r--gdb/testsuite/gdb.tui/tui-disasm-styling.exp3
-rw-r--r--gdb/testsuite/gdb.tui/tui-focus.exp2
-rw-r--r--gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp10
-rw-r--r--gdb/testsuite/gdb.tui/tui-missing-src.exp6
-rw-r--r--gdb/testsuite/gdb.tui/tui-mode-switch.exp57
-rw-r--r--gdb/testsuite/gdb.tui/tuiterm-2.exp70
-rw-r--r--gdb/testsuite/gdb.tui/tuiterm.exp62
-rw-r--r--gdb/testsuite/gdb.xml/bad-include.xml2
-rw-r--r--gdb/testsuite/gdb.xml/tdesc-xinclude.exp2
-rw-r--r--gdb/testsuite/lib/dwarf.exp36
-rw-r--r--gdb/testsuite/lib/gdb-utils.exp4
-rw-r--r--gdb/testsuite/lib/gdb.exp575
-rw-r--r--gdb/testsuite/lib/gdb_watchdog.h75
-rw-r--r--gdb/testsuite/lib/gdbserver-support.exp2
-rw-r--r--gdb/testsuite/lib/selftest-support.exp216
-rw-r--r--gdb/testsuite/lib/tuiterm.exp2366
-rwxr-xr-xgdb/testsuite/make-check-all.sh4
291 files changed, 11786 insertions, 1946 deletions
diff --git a/gdb/testsuite/Makefile.in b/gdb/testsuite/Makefile.in
index 4a6665d..fa2d9eb 100644
--- a/gdb/testsuite/Makefile.in
+++ b/gdb/testsuite/Makefile.in
@@ -386,7 +386,17 @@ check-all-boards: all $(abs_builddir)/site.exp
${abs_srcdir}/make-check-all.sh --keep-results \
--host-user "$(GDB_HOST_USERNAME)" \
--target-user "$(GDB_TARGET_USERNAME)" \
- "$(TESTS)"
+ "$(TESTS)" \
+ result=$$?; \
+ if test -d check-all; then \
+ $(SHELL) $(srcdir)/../../contrib/dg-extract-results.sh \
+ `find check-all -name gdb.sum -print` > check-all/gdb.sum; \
+ $(SHELL) $(srcdir)/../../contrib/dg-extract-results.sh -L \
+ `find check-all -name gdb.log -print` > check-all/gdb.log; \
+ sed -n '/=== gdb Summary ===/,$$ p' check-all/gdb.sum; \
+ fi; \
+ exit $$result
+
force:;
diff --git a/gdb/testsuite/gdb.ada/dyn-bit-offset.exp b/gdb/testsuite/gdb.ada/dyn-bit-offset.exp
index 19d16b1..f8a4363 100644
--- a/gdb/testsuite/gdb.ada/dyn-bit-offset.exp
+++ b/gdb/testsuite/gdb.ada/dyn-bit-offset.exp
@@ -28,19 +28,52 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable $flags] != ""} {
return -1
}
+# GCC needs to have fixes:
+# - 809b46d2ccc ("Partially lift restriction from loc_list_from_tree_1")
+# - d7f24e37d4b ("Fix oversight about big-endian targets in latest change")
+set have_xfail [gnat_version_compare <= {16 1}]
+
clean_restart ${testfile}
set bp_location [gdb_get_line_number "STOP" ${testdir}/exam.adb]
runto "exam.adb:$bp_location"
+set re_pass \
+ [string_to_regexp \
+ " = (discr => 3, array_field => (-5, -6, -7), field => -5, another_field => -6)"]
+set re_xfail_le \
+ [string_to_regexp \
+ " = (discr => 3, array_field => (-5, -6, -7), field => -4, another_field => -4)"]
+set re_xfail_be \
+ [string_to_regexp \
+ " = (discr => 3, array_field => (-5, -6, -7), field => -6, another_field => -6)"]
+
gdb_test_multiple "print spr" "" {
- -re -wrap " = \\(discr => 3, array_field => \\(-5, -6, -7\\), field => -4, another_field => -6\\)" {
+ -re -wrap $re_pass {
pass $gdb_test_name
}
- -re -wrap " = \\(discr => 3, array_field => \\(-5, -6, -7\\), field => -4, another_field => -4\\)" {
- # A known GCC bug.
- xfail $gdb_test_name
+ -re -wrap $re_xfail_le|$re_xfail_be {
+ if { $have_xfail } {
+ xfail $gdb_test_name
+ } else {
+ fail $gdb_test_name
+ }
}
}
-gdb_test "print spr.field" " = -4"
+set re_pass " = -5"
+set re_xfail_le " = -4"
+set re_xfail_be " = -6"
+
+gdb_test_multiple "print spr.field" "" {
+ -re -wrap $re_pass {
+ pass $gdb_test_name
+ }
+ -re -wrap $re_xfail_le|$re_xfail_be {
+ if { $have_xfail } {
+ xfail $gdb_test_name
+ } else {
+ fail $gdb_test_name
+ }
+ }
+}
diff --git a/gdb/testsuite/gdb.ada/dyn-bit-offset/exam.adb b/gdb/testsuite/gdb.ada/dyn-bit-offset/exam.adb
index a882afd..5c7f70b 100644
--- a/gdb/testsuite/gdb.ada/dyn-bit-offset/exam.adb
+++ b/gdb/testsuite/gdb.ada/dyn-bit-offset/exam.adb
@@ -36,7 +36,7 @@ procedure Exam is
pragma No_Component_Reordering (Some_Packed_Record);
SPR : Some_Packed_Record := (Discr => 3,
- Field => -4,
+ Field => -5,
Another_Field => -6,
Array_Field => (-5, -6, -7));
diff --git a/gdb/testsuite/gdb.ada/finish-var-size.exp b/gdb/testsuite/gdb.ada/finish-var-size.exp
index e038ed4..ae30086 100644
--- a/gdb/testsuite/gdb.ada/finish-var-size.exp
+++ b/gdb/testsuite/gdb.ada/finish-var-size.exp
@@ -22,7 +22,13 @@ require {expr [gcc_major_version] >= 12}
standard_ada_testfile p
-if {[gdb_compile_ada "${srcfile}" "${binfile}" executable debug] != ""} {
+set opts {}
+lappend opts debug
+if { [have_fvar_tracking] } {
+ lappend opts additional_flags=-fvar-tracking
+}
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable $opts] != ""} {
return -1
}
diff --git a/gdb/testsuite/gdb.ada/negative-bit-offset.exp b/gdb/testsuite/gdb.ada/negative-bit-offset.exp
new file mode 100644
index 0000000..c5fcae1
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/negative-bit-offset.exp
@@ -0,0 +1,36 @@
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test negative DW_AT_bit_offset.
+
+load_lib "ada.exp"
+
+require allow_ada_tests
+
+standard_ada_testfile prog
+
+# This particular output is only generated with -gdwarf-4.
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable \
+ {debug additional_flags=-gdwarf-4}] != ""} {
+ return
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "STOP" ${testdir}/prog.adb]
+runto "prog.adb:$bp_location"
+
+gdb_test "print xp" \
+ [string_to_regexp "(x => 21, y => (-1, -2, -3, -4, -5, -6, -7, -8, -9, -10))"]
diff --git a/gdb/testsuite/gdb.ada/negative-bit-offset/prog.adb b/gdb/testsuite/gdb.ada/negative-bit-offset/prog.adb
new file mode 100644
index 0000000..e3c1775
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/negative-bit-offset/prog.adb
@@ -0,0 +1,36 @@
+-- Copyright 2025 Free Software Foundation, Inc.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+procedure Prog is
+
+ type Small is range -32 .. 31;
+ for Small'Size use 6;
+
+ type SomeArray is array (POSITIVE range <>) of Small;
+
+ type SomePackedArray is array (POSITIVE range <>) of Small;
+ pragma Pack (SomePackedArray);
+
+ type SomePackedRecord is record
+ X: Small;
+ Y: SomePackedArray (1 .. 10);
+ end record;
+ pragma Pack (SomePackedRecord);
+
+ XP: SomePackedRecord := (21, (-1, -2, -3, -4, -5, -6, -7, -8, -9, -10));
+
+begin
+ null; -- STOP
+end;
diff --git a/gdb/testsuite/gdb.ada/operator_call.exp b/gdb/testsuite/gdb.ada/operator_call.exp
index e96107b..dc7f679 100644
--- a/gdb/testsuite/gdb.ada/operator_call.exp
+++ b/gdb/testsuite/gdb.ada/operator_call.exp
@@ -71,6 +71,12 @@ proc test_with_menu {command result} {
fail $command
}
}
+ "Argument to arithmetic operation not a number or boolean." {
+ fail $command
+ }
+ -re "No definition of \".*\" in current context." {
+ fail $command
+ }
timeout {
fail "$command (timeout)"
}
diff --git a/gdb/testsuite/gdb.ada/return-small-char-array.exp b/gdb/testsuite/gdb.ada/return-small-char-array.exp
new file mode 100644
index 0000000..75c781e
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/return-small-char-array.exp
@@ -0,0 +1,40 @@
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+load_lib "ada.exp"
+
+require allow_ada_tests
+
+standard_ada_testfile proc
+
+if { [gdb_compile_ada $srcfile $binfile executable debug] != "" } {
+ return -1
+}
+
+clean_restart $testfile
+
+set bp_location [gdb_get_line_number "STOP" $testdir/proc.adb]
+runto "proc.adb:$bp_location"
+
+gdb_test "print Value.Name(My_Value)" \
+ { = "abcd"}
+
+# Step into the function.
+gdb_test "step 2" \
+ "return Of_Value;"
+
+# and finish.
+gdb_test "finish" \
+ { = "abcd"}
diff --git a/gdb/testsuite/gdb.ada/return-small-char-array/proc.adb b/gdb/testsuite/gdb.ada/return-small-char-array/proc.adb
new file mode 100644
index 0000000..b18d9fe
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/return-small-char-array/proc.adb
@@ -0,0 +1,22 @@
+-- Copyright 2025 Free Software Foundation, Inc.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+with Value;
+procedure Proc is
+ My_Value : Value.T := "abcd";
+begin
+ null; -- STOP
+ My_Value := Value.Name(My_Value);
+end;
diff --git a/gdb/testsuite/gdb.ada/return-small-char-array/value.adb b/gdb/testsuite/gdb.ada/return-small-char-array/value.adb
new file mode 100644
index 0000000..2dd9faa
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/return-small-char-array/value.adb
@@ -0,0 +1,21 @@
+-- Copyright 2025 Free Software Foundation, Inc.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package body Value is
+ function Name (Of_Value : T) return T is
+ begin
+ return Of_Value;
+ end Name;
+end Value;
diff --git a/gdb/testsuite/gdb.ada/return-small-char-array/value.ads b/gdb/testsuite/gdb.ada/return-small-char-array/value.ads
new file mode 100644
index 0000000..16b171e
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/return-small-char-array/value.ads
@@ -0,0 +1,20 @@
+-- Copyright 2025 Free Software Foundation, Inc.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package Value is
+ type T is new String (1 .. 4);
+
+ function Name (Of_Value : T) return T;
+end;
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs-core.c b/gdb/testsuite/gdb.arch/aarch64-gcs-core.c
new file mode 100644
index 0000000..7767204
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs-core.c
@@ -0,0 +1,123 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/auxv.h>
+#include <linux/prctl.h>
+#include <sys/syscall.h>
+
+/* Feature check for Guarded Control Stack. */
+#ifndef HWCAP_GCS
+#define HWCAP_GCS (1UL << 32)
+#endif
+
+#ifndef PR_GET_SHADOW_STACK_STATUS
+#define PR_GET_SHADOW_STACK_STATUS 74
+#define PR_SET_SHADOW_STACK_STATUS 75
+#define PR_SHADOW_STACK_ENABLE (1UL << 0)
+#endif
+
+/* We need to use a macro to call prctl because after GCS is enabled, it's not
+ possible to return from the function which enabled it. This is because the
+ return address of the calling function isn't on the GCS. */
+#define my_syscall2(num, arg1, arg2) \
+ ({ \
+ register long _num __asm__("x8") = (num); \
+ register long _arg1 __asm__("x0") = (long)(arg1); \
+ register long _arg2 __asm__("x1") = (long)(arg2); \
+ register long _arg3 __asm__("x2") = 0; \
+ register long _arg4 __asm__("x3") = 0; \
+ register long _arg5 __asm__("x4") = 0; \
+ \
+ __asm__ volatile ("svc #0\n" \
+ : "=r"(_arg1) \
+ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \
+ "r"(_arg5), "r"(_num) \
+ : "memory", "cc"); \
+ _arg1; \
+ })
+
+#define get_gcspr(void) \
+ ({ \
+ unsigned long *gcspr; \
+ \
+ /* Get GCSPR_EL0. */ \
+ asm volatile ("mrs %0, S3_3_C2_C5_1" : "=r"(gcspr) : : "cc"); \
+ \
+ gcspr; \
+ })
+
+/* Corrupt the return address to see if GDB will report a SIGSEGV with the
+ expected $_siginfo.si_code. */
+static void __attribute__ ((noinline))
+function (unsigned long *gcspr)
+{
+ /* x30 holds the return address. */
+ register long x30 __asm__("x30") __attribute__ ((unused));
+
+ /* Print GCSPR to stdout so that the testcase can capture it. */
+ printf ("%p\n", get_gcspr ());
+ fflush (stdout);
+
+ /* Cause a GCS exception. */
+ x30 = 0xbadc0ffee;
+ __asm__ volatile ("ret\n");
+}
+
+int
+main (void)
+{
+ if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
+ {
+ fprintf (stderr, "GCS support not found in AT_HWCAP\n");
+ return EXIT_FAILURE;
+ }
+
+ /* Force shadow stacks on, our tests *should* be fine with or
+ without libc support and with or without this having ended
+ up tagged for GCS and enabled by the dynamic linker. We
+ can't use the libc prctl() function since we can't return
+ from enabling the stack. Also lock GCS if not already
+ locked so we can test behaviour when it's locked. */
+ unsigned long gcs_mode;
+ int ret = my_syscall2 (__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &gcs_mode);
+ if (ret)
+ {
+ fprintf (stderr, "Failed to read GCS state: %d\n", ret);
+ return EXIT_FAILURE;
+ }
+
+ if (!(gcs_mode & PR_SHADOW_STACK_ENABLE))
+ {
+ gcs_mode = PR_SHADOW_STACK_ENABLE;
+ ret = my_syscall2 (__NR_prctl, PR_SET_SHADOW_STACK_STATUS, gcs_mode);
+ if (ret)
+ {
+ fprintf (stderr, "Failed to configure GCS: %d\n", ret);
+ return EXIT_FAILURE;
+ }
+ }
+
+ unsigned long *gcspr = get_gcspr ();
+
+ /* Pass gscpr to function just so it's used for something. */
+ function (gcspr); /* Break here. */
+
+ /* Avoid returning, in case libc doesn't understand GCS. */
+ exit (EXIT_SUCCESS);
+}
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs-core.exp b/gdb/testsuite/gdb.arch/aarch64-gcs-core.exp
new file mode 100644
index 0000000..2261ac8
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs-core.exp
@@ -0,0 +1,113 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test reading and writing the core dump of a binary that uses a Guarded
+# Control Stack.
+
+require allow_aarch64_gcs_tests
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+ return
+}
+
+set linespec ${srcfile}:[gdb_get_line_number "Break here"]
+
+if ![runto $linespec] {
+ return
+}
+
+# Obtain an OS-generated core file. Save test program output to
+# ${binfile}.out.
+set core_filename [core_find $binfile {} {} "${binfile}.out"]
+set core_generated [expr {$core_filename != ""}]
+
+# Make sure GDB can read the given core file correctly.
+proc check_core_file {core_filename saved_gcspr} {
+ global decimal hex
+
+ # Load the core file.
+ if [gdb_test "core $core_filename" \
+ [multi_line \
+ "Core was generated by .*\\." \
+ "Program terminated with signal SIGSEGV, Segmentation fault" \
+ "Guarded Control Stack error\\." \
+ "#0 function \\(gcspr=$hex\\) at .*aarch64-gcs-core.c:$decimal" \
+ "$decimal.*__asm__ volatile \\(\"ret\\\\n\"\\);"] \
+ "load core file"] {
+ return -1
+ }
+
+ # Check the value of GCSPR in the core file.
+ gdb_test "print/x \$gcspr" "\\$\[0-9\]+ = $saved_gcspr" \
+ "gcspr contents from core file"
+}
+
+if {!$core_generated} {
+ untested "unable to create or find corefile"
+}
+
+if {$core_generated} {
+ clean_restart $binfile
+
+ with_test_prefix "OS corefile" {
+ # Read GCSPR value from saved output of the test program.
+ set out_id [open ${binfile}.out "r"]
+ set gcspr_in_core [gets $out_id]
+ close $out_id
+
+ check_core_file $core_filename $gcspr_in_core
+ }
+}
+
+if ![gcore_cmd_available] {
+ unsupported "target does not support gcore command."
+ return
+}
+
+clean_restart $binfile
+
+if ![runto $linespec] {
+ return
+}
+
+# Continue until a crash. The line with the hex number is optional because
+# it's printed by the test program, and doesn't appear in the Expect buffer
+# when testing a remote target.
+gdb_test "continue" \
+ [multi_line \
+ "Continuing\\." \
+ "($hex\r\n)?" \
+ "Program received signal SIGSEGV, Segmentation fault" \
+ "Guarded Control Stack error\\." \
+ "function \\(gcspr=$hex\\) at .*aarch64-gcs-core.c:$decimal" \
+ {.*__asm__ volatile \("ret\\n"\);}] \
+ "continue to SIGSEGV"
+
+set gcspr_in_gcore [get_valueof "/x" "\$gcspr" "*unknown*"]
+
+# Generate the gcore core file.
+set gcore_filename [standard_output_file "${testfile}.gcore"]
+set gcore_generated [gdb_gcore_cmd "$gcore_filename" "generate gcore file"]
+
+gdb_assert { $gcore_generated } "gcore corefile created"
+if {$gcore_generated} {
+ clean_restart $binfile
+
+ with_test_prefix "gcore corefile" {
+ check_core_file $gcore_filename $gcspr_in_gcore
+ }
+}
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs-disp-step.c b/gdb/testsuite/gdb.arch/aarch64-gcs-disp-step.c
new file mode 100644
index 0000000..3d89535
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs-disp-step.c
@@ -0,0 +1,140 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/auxv.h>
+#include <sys/syscall.h>
+#include <linux/prctl.h>
+
+/* Feature check for Guarded Control Stack. */
+#ifndef HWCAP_GCS
+#define HWCAP_GCS (1UL << 32)
+#endif
+
+#ifndef PR_GET_SHADOW_STACK_STATUS
+#define PR_GET_SHADOW_STACK_STATUS 74
+#define PR_SET_SHADOW_STACK_STATUS 75
+#define PR_SHADOW_STACK_ENABLE (1UL << 0)
+#endif
+
+/* We need to use a macro to call prctl because after GCS is enabled, it's not
+ possible to return from the function which enabled it. This is because the
+ return address of the calling function isn't on the GCS. */
+#define my_syscall2(num, arg1, arg2) \
+ ({ \
+ register long _num __asm__("x8") = (num); \
+ register long _arg1 __asm__("x0") = (long)(arg1); \
+ register long _arg2 __asm__("x1") = (long)(arg2); \
+ register long _arg3 __asm__("x2") = 0; \
+ register long _arg4 __asm__("x3") = 0; \
+ register long _arg5 __asm__("x4") = 0; \
+ \
+ __asm__ volatile("svc #0\n" \
+ : "=r"(_arg1) \
+ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \
+ "r"(_arg5), "r"(_num) \
+ : "memory", "cc"); \
+ _arg1; \
+ })
+
+#define get_gcspr(void) \
+ ({ \
+ unsigned long *gcspr; \
+ \
+ /* Get GCSPR_EL0. */ \
+ asm volatile("mrs %0, S3_3_C2_C5_1" : "=r"(gcspr) : : "cc"); \
+ \
+ gcspr; \
+ })
+
+static int __attribute__ ((noinline))
+function2 (void)
+{
+ return EXIT_SUCCESS;
+}
+
+/* Put branch and link instructions being tested into their own functions so
+ that the program returns one level up in the stack after the displaced
+ stepped instruction. This tests that GDB doesn't leave the GCS out of sync
+ with the regular stack. */
+
+static int __attribute__ ((noinline))
+function_bl (void)
+{
+ register int x0 __asm__("x0");
+
+ __asm__ ("bl function2\n"
+ : "=r"(x0)
+ :
+ : "x30");
+
+ return x0;
+}
+
+static int __attribute__ ((noinline))
+function_blr (void)
+{
+ register int x0 __asm__("x0");
+
+ __asm__ ("blr %1\n"
+ : "=r"(x0)
+ : "r"(&function2)
+ : "x30");
+
+ return x0;
+}
+
+int
+main (void)
+{
+ if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
+ {
+ fprintf (stderr, "GCS support not found in AT_HWCAP\n");
+ return EXIT_FAILURE;
+ }
+
+ /* Force shadow stacks on, our tests *should* be fine with or
+ without libc support and with or without this having ended
+ up tagged for GCS and enabled by the dynamic linker. We
+ can't use the libc prctl() function since we can't return
+ from enabling the stack. */
+ unsigned long gcs_mode;
+ int ret = my_syscall2 (__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &gcs_mode);
+ if (ret)
+ {
+ fprintf (stderr, "Failed to read GCS state: %d\n", ret);
+ return EXIT_FAILURE;
+ }
+
+ if (!(gcs_mode & PR_SHADOW_STACK_ENABLE))
+ {
+ gcs_mode = PR_SHADOW_STACK_ENABLE;
+ ret = my_syscall2 (__NR_prctl, PR_SET_SHADOW_STACK_STATUS, gcs_mode);
+ if (ret)
+ {
+ fprintf (stderr, "Failed to configure GCS: %d\n", ret);
+ return EXIT_FAILURE;
+ }
+ }
+
+ int ret1 = function_bl ();
+ int ret2 = function_blr ();
+
+ /* Avoid returning, in case libc doesn't understand GCS. */
+ exit (ret1 + ret2);
+}
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs-disp-step.exp b/gdb/testsuite/gdb.arch/aarch64-gcs-disp-step.exp
new file mode 100644
index 0000000..2359d96
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs-disp-step.exp
@@ -0,0 +1,86 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test displaced stepping in a program that uses a Guarded Control Stack.
+
+require allow_aarch64_gcs_tests
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+ return
+}
+
+if ![runto_main] {
+ return
+}
+
+gdb_test_no_output "set breakpoint auto-hw off"
+gdb_test_no_output "set displaced-stepping on"
+
+# Get address of the branch and link instructions of interest.
+set addr_bl 0
+set test "get address of bl instruction"
+gdb_test_multiple "disassemble function_bl" $test -lbl {
+ -re "\r\n\\s+($hex) <\\+${decimal}>:\\s+bl\\s+${hex} <function2>(?=\r\n)" {
+ set addr_bl $expect_out(1,string)
+ exp_continue
+ }
+ -re -wrap "" {
+ gdb_assert { $addr_bl != 0 } $test
+ }
+}
+
+set addr_blr 0
+set test "get address of blr instruction"
+gdb_test_multiple "disassemble function_blr" $test -lbl {
+ -re "\r\n\\s+($hex) <\\+${decimal}>:\\s+blr\\s+x${decimal}(?=\r\n)" {
+ set addr_blr $expect_out(1,string)
+ exp_continue
+ }
+ -re -wrap "" {
+ gdb_assert { $addr_blr != 0 } $test
+ }
+}
+
+if { $addr_bl == 0 || $addr_blr == 0 } {
+ return
+}
+
+gdb_test "break *$addr_bl" \
+ "Breakpoint $decimal at $hex: file .*aarch64-gcs-disp-step.c, line ${decimal}." \
+ "set breakpoint at bl instruction"
+
+gdb_test "break *$addr_blr" \
+ "Breakpoint $decimal at $hex: file .*aarch64-gcs-disp-step.c, line ${decimal}." \
+ "set breakpoint at blr instruction"
+
+gdb_test "continue" \
+ [multi_line \
+ {Continuing\.} \
+ "" \
+ "Breakpoint $decimal, function_bl \\(\\) at .*aarch64-gcs-disp-step.c:${decimal}(?: \\\[GCS error\\\])?" \
+ {[^\r\n]+"bl function2\\n"}] \
+ "continue to breakpoint at bl"
+
+gdb_test "continue" \
+ [multi_line \
+ {Continuing\.} \
+ "" \
+ "Breakpoint $decimal, $hex in function_blr \\(\\) at .*aarch64-gcs-disp-step.c:${decimal}(?: \\\[GCS error\\\])?" \
+ {[^\r\n]+"blr %1\\n"}] \
+ "continue to breakpoint at blr"
+
+gdb_continue_to_end
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs-return.c b/gdb/testsuite/gdb.arch/aarch64-gcs-return.c
new file mode 100644
index 0000000..95518b6
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs-return.c
@@ -0,0 +1,105 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/auxv.h>
+#include <sys/syscall.h>
+#include <linux/prctl.h>
+
+/* Feature check for Guarded Control Stack. */
+#ifndef HWCAP_GCS
+#define HWCAP_GCS (1UL << 32)
+#endif
+
+#ifndef PR_GET_SHADOW_STACK_STATUS
+#define PR_GET_SHADOW_STACK_STATUS 74
+#define PR_SET_SHADOW_STACK_STATUS 75
+#define PR_SHADOW_STACK_ENABLE (1UL << 0)
+#endif
+
+/* We need to use a macro to call prctl because after GCS is enabled, it's not
+ possible to return from the function which enabled it. This is because the
+ return address of the calling function isn't on the GCS. */
+#define my_syscall2(num, arg1, arg2) \
+ ({ \
+ register long _num __asm__("x8") = (num); \
+ register long _arg1 __asm__("x0") = (long)(arg1); \
+ register long _arg2 __asm__("x1") = (long)(arg2); \
+ register long _arg3 __asm__("x2") = 0; \
+ register long _arg4 __asm__("x3") = 0; \
+ register long _arg5 __asm__("x4") = 0; \
+ \
+ __asm__ volatile("svc #0\n" \
+ : "=r"(_arg1) \
+ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \
+ "r"(_arg5), "r"(_num) \
+ : "memory", "cc"); \
+ _arg1; \
+ })
+
+static int __attribute__ ((noinline))
+call2 ()
+{
+ return 42; /* Break call2. */
+}
+
+static int __attribute__ ((noinline))
+call1 ()
+{
+ return call2 (); /* Break call1. */
+}
+
+int
+main ()
+{
+ if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
+ {
+ fprintf (stderr, "GCS support not found in AT_HWCAP\n");
+ return EXIT_FAILURE;
+ }
+
+ /* Force shadow stacks on, our tests *should* be fine with or
+ without libc support and with or without this having ended
+ up tagged for GCS and enabled by the dynamic linker. We
+ can't use the libc prctl() function since we can't return
+ from enabling the stack. Also lock GCS if not already
+ locked so we can test behaviour when it's locked. */
+ unsigned long gcs_mode;
+ int ret = my_syscall2 (__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &gcs_mode);
+ if (ret)
+ {
+ fprintf (stderr, "Failed to read GCS state: %d\n", ret);
+ return EXIT_FAILURE;
+ }
+
+ if (!(gcs_mode & PR_SHADOW_STACK_ENABLE))
+ {
+ gcs_mode = PR_SHADOW_STACK_ENABLE;
+ ret = my_syscall2 (__NR_prctl, PR_SET_SHADOW_STACK_STATUS, gcs_mode);
+ if (ret)
+ {
+ fprintf (stderr, "Failed to configure GCS: %d\n", ret);
+ return EXIT_FAILURE;
+ }
+ }
+
+ call1 (); /* Break begin. */
+
+ /* Avoid returning, in case libc doesn't understand GCS. */
+ exit (EXIT_SUCCESS);
+}
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs-return.exp b/gdb/testsuite/gdb.arch/aarch64-gcs-return.exp
new file mode 100644
index 0000000..1d1c237
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs-return.exp
@@ -0,0 +1,129 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test the GDB return command in a program that uses a Guarded Control Stack.
+# Based on the return tests in gdb.arch/amd64-shadow-stack-cmds.exp.
+# Note that potential GCS violations often only occur after resuming normal
+# execution. Therefore, it is important to test normal program
+# completion after testing the return command.
+
+require allow_aarch64_gcs_tests
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+ return
+}
+
+set begin_line [gdb_get_line_number "Break begin"]
+set call1_line [gdb_get_line_number "Break call1"]
+set call2_line [gdb_get_line_number "Break call2"]
+
+if ![runto ${begin_line}] {
+ return
+}
+
+proc restart_and_run_infcall_call2 {} {
+ global binfile call2_line
+ clean_restart ${binfile}
+ if ![runto_main] {
+ return
+ }
+ set inside_infcall_str "The program being debugged stopped while in a function called from GDB"
+ gdb_breakpoint ${call2_line}
+ gdb_continue_to_breakpoint "Break call2" ".*Break call2.*"
+ gdb_test "call (int) call2()" \
+ "Breakpoint \[0-9\]*, call2.*$inside_infcall_str.*"
+}
+
+with_test_prefix "test inferior call and continue" {
+ gdb_breakpoint ${call1_line}
+ gdb_continue_to_breakpoint "Break call1" ".*Break call1.*"
+
+ gdb_test "call (int) call2()" "= 42"
+
+ gdb_continue_to_end
+}
+
+with_test_prefix "test return inside an inferior call" {
+ restart_and_run_infcall_call2
+
+ gdb_test "return" "\#0.*call2.*" \
+ "Test GCS return inside an inferior call" \
+ "Make.*return now\\? \\(y or n\\) " "y"
+
+ gdb_continue_to_end
+}
+
+with_test_prefix "test return 'above' an inferior call" {
+ restart_and_run_infcall_call2
+
+ gdb_test "frame 2" "call2 ().*" "move to frame 'above' inferior call"
+
+ gdb_test "return" "\#0.*call1.*" \
+ "Test GCS return 'above' an inferior call" \
+ "Make.*return now\\? \\(y or n\\) " "y"
+
+ gdb_continue_to_end
+}
+
+clean_restart ${binfile}
+if ![runto ${begin_line}] {
+ return
+}
+
+# Extract GCS pointer inside main, call1 and call2 function.
+gdb_breakpoint ${call1_line}
+gdb_breakpoint ${call2_line}
+set gcspr_main [get_valueof /x "\$gcspr" 0 "get value of gcspr in main"]
+gdb_continue_to_breakpoint "Break call1" ".*Break call1.*"
+set gcspr_call1 [get_valueof /x "\$gcspr" 0 "get value of gcspr in call1"]
+gdb_continue_to_breakpoint "Break call2" ".*Break call2.*"
+set gcspr_call2 [get_valueof /x "\$gcspr" 0 "get value of gcspr in call2"]
+
+with_test_prefix "test frame level update" {
+ gdb_test "up" "call1.*" "move to frame 1"
+ gdb_test "print /x \$gcspr" "= $gcspr_call1" "check gcspr of frame 1"
+ gdb_test "up" "main.*" "move to frame 2"
+ gdb_test "print /x \$gcspr" "= $gcspr_main" "check gcspr of frame 2"
+ gdb_test "frame 0" "call2.*" "move to frame 0"
+ gdb_test "print /x \$gcspr" "= $gcspr_call2" "check gcspr of frame 0"
+}
+
+with_test_prefix "test return from current frame" {
+ gdb_test "return (int) 1" "#0.*call1.*" \
+ "Test GCS return from current frame" \
+ "Make.*return now\\? \\(y or n\\) " "y"
+
+ gdb_continue_to_end
+}
+
+clean_restart ${binfile}
+if ![runto_main] {
+ return
+}
+
+with_test_prefix "test return from past frame" {
+ gdb_breakpoint ${call2_line}
+ gdb_continue_to_breakpoint "Break call2" ".*Break call2.*"
+
+ gdb_test "frame 1" ".*in call1.*"
+
+ gdb_test "return (int) 1" "#0.*main.*" \
+ "Test GCS return from past frame" \
+ "Make.*return now\\? \\(y or n\\) " "y"
+
+ gdb_continue_to_end
+}
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs-tdesc-without-linux.xml b/gdb/testsuite/gdb.arch/aarch64-gcs-tdesc-without-linux.xml
new file mode 100644
index 0000000..056ab58
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs-tdesc-without-linux.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<target>
+ <architecture>aarch64</architecture>
+ <feature name="org.gnu.gdb.aarch64.core">
+ <flags id="cpsr_flags" size="4">
+ <field name="SP" start="0" end="0" type="bool"/>
+ <field name="EL" start="2" end="3" type="uint32"/>
+ <field name="nRW" start="4" end="4" type="bool"/>
+ <field name="F" start="6" end="6" type="bool"/>
+ <field name="I" start="7" end="7" type="bool"/>
+ <field name="A" start="8" end="8" type="bool"/>
+ <field name="D" start="9" end="9" type="bool"/>
+ <field name="BTYPE" start="10" end="11" type="uint32"/>
+ <field name="SSBS" start="12" end="12" type="bool"/>
+ <field name="IL" start="20" end="20" type="bool"/>
+ <field name="SS" start="21" end="21" type="bool"/>
+ <field name="PAN" start="22" end="22" type="bool"/>
+ <field name="UAO" start="23" end="23" type="bool"/>
+ <field name="DIT" start="24" end="24" type="bool"/>
+ <field name="TCO" start="25" end="25" type="bool"/>
+ <field name="V" start="28" end="28" type="bool"/>
+ <field name="C" start="29" end="29" type="bool"/>
+ <field name="Z" start="30" end="30" type="bool"/>
+ <field name="N" start="31" end="31" type="bool"/>
+ </flags>
+ <reg name="x0" bitsize="64" type="int" regnum="0"/>
+ <reg name="x1" bitsize="64" type="int" regnum="1"/>
+ <reg name="x2" bitsize="64" type="int" regnum="2"/>
+ <reg name="x3" bitsize="64" type="int" regnum="3"/>
+ <reg name="x4" bitsize="64" type="int" regnum="4"/>
+ <reg name="x5" bitsize="64" type="int" regnum="5"/>
+ <reg name="x6" bitsize="64" type="int" regnum="6"/>
+ <reg name="x7" bitsize="64" type="int" regnum="7"/>
+ <reg name="x8" bitsize="64" type="int" regnum="8"/>
+ <reg name="x9" bitsize="64" type="int" regnum="9"/>
+ <reg name="x10" bitsize="64" type="int" regnum="10"/>
+ <reg name="x11" bitsize="64" type="int" regnum="11"/>
+ <reg name="x12" bitsize="64" type="int" regnum="12"/>
+ <reg name="x13" bitsize="64" type="int" regnum="13"/>
+ <reg name="x14" bitsize="64" type="int" regnum="14"/>
+ <reg name="x15" bitsize="64" type="int" regnum="15"/>
+ <reg name="x16" bitsize="64" type="int" regnum="16"/>
+ <reg name="x17" bitsize="64" type="int" regnum="17"/>
+ <reg name="x18" bitsize="64" type="int" regnum="18"/>
+ <reg name="x19" bitsize="64" type="int" regnum="19"/>
+ <reg name="x20" bitsize="64" type="int" regnum="20"/>
+ <reg name="x21" bitsize="64" type="int" regnum="21"/>
+ <reg name="x22" bitsize="64" type="int" regnum="22"/>
+ <reg name="x23" bitsize="64" type="int" regnum="23"/>
+ <reg name="x24" bitsize="64" type="int" regnum="24"/>
+ <reg name="x25" bitsize="64" type="int" regnum="25"/>
+ <reg name="x26" bitsize="64" type="int" regnum="26"/>
+ <reg name="x27" bitsize="64" type="int" regnum="27"/>
+ <reg name="x28" bitsize="64" type="int" regnum="28"/>
+ <reg name="x29" bitsize="64" type="int" regnum="29"/>
+ <reg name="x30" bitsize="64" type="int" regnum="30"/>
+ <reg name="sp" bitsize="64" type="data_ptr" regnum="31"/>
+ <reg name="pc" bitsize="64" type="code_ptr" regnum="32"/>
+ <reg name="cpsr" bitsize="32" type="cpsr_flags" regnum="33"/>
+ </feature>
+ <feature name="org.gnu.gdb.aarch64.gcs">
+ <reg name="gcspr" bitsize="64" type="data_ptr" regnum="90" group="system"/>
+ </feature>
+</target>
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs-wrong-tdesc.c b/gdb/testsuite/gdb.arch/aarch64-gcs-wrong-tdesc.c
new file mode 100644
index 0000000..10cf749
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs-wrong-tdesc.c
@@ -0,0 +1,26 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+
+int
+main (void)
+{
+ printf ("Hello, world!\n");
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs-wrong-tdesc.exp b/gdb/testsuite/gdb.arch/aarch64-gcs-wrong-tdesc.exp
new file mode 100644
index 0000000..f0508cd
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs-wrong-tdesc.exp
@@ -0,0 +1,48 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test that GDB complains when given a target description with the GCS feature
+# but not the GCS Linux feature.
+
+require allow_aarch64_gcs_tests
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+ return
+}
+
+set xml_path "${srcdir}/${subdir}/aarch64-gcs-tdesc-without-linux.xml"
+
+gdb_test "set tdesc filename ${xml_path}" \
+ "warning: Incomplete GCS support in the target: missing Linux part. GCS feature disabled." \
+ "warn about incomplete GCS support"
+
+# We can't test a debugging session on a remote target because with the
+# wrong tdesc, GDB expects a g packet reply with the wrong size.
+if {[gdb_protocol_is_remote]} {
+ return
+}
+
+if ![runto_main] {
+ return
+}
+
+gdb_test "print \$gcspr" " = <unavailable>" "GCSPR is unavailable"
+
+# Now check that we can continue the debugging session normally.
+gdb_test "next"
+
+gdb_continue_to_end
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs.c b/gdb/testsuite/gdb.arch/aarch64-gcs.c
new file mode 100644
index 0000000..39519e4
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs.c
@@ -0,0 +1,180 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/auxv.h>
+#include <sys/syscall.h>
+#include <linux/prctl.h>
+
+/* Feature check for Guarded Control Stack. */
+#ifndef HWCAP_GCS
+#define HWCAP_GCS (1UL << 32)
+#endif
+
+#ifndef PR_GET_SHADOW_STACK_STATUS
+#define PR_GET_SHADOW_STACK_STATUS 74
+#define PR_SET_SHADOW_STACK_STATUS 75
+#define PR_SHADOW_STACK_ENABLE (1UL << 0)
+#endif
+
+/* We need to use a macro to call prctl because after GCS is enabled, it's not
+ possible to return from the function which enabled it. This is because the
+ return address of the calling function isn't on the GCS. */
+#define my_syscall2(num, arg1, arg2) \
+ ({ \
+ register long _num __asm__("x8") = (num); \
+ register long _arg1 __asm__("x0") = (long)(arg1); \
+ register long _arg2 __asm__("x1") = (long)(arg2); \
+ register long _arg3 __asm__("x2") = 0; \
+ register long _arg4 __asm__("x3") = 0; \
+ register long _arg5 __asm__("x4") = 0; \
+ \
+ __asm__ volatile ("svc #0\n" \
+ : "=r"(_arg1) \
+ : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \
+ "r"(_arg5), "r"(_num) \
+ : "memory", "cc"); \
+ _arg1; \
+ })
+
+#define get_gcspr(void) \
+ ({ \
+ unsigned long *gcspr; \
+ \
+ /* Get GCSPR_EL0. */ \
+ asm volatile ("mrs %0, S3_3_C2_C5_1" : "=r"(gcspr) : : "cc"); \
+ \
+ gcspr; \
+ })
+
+static unsigned long *handler_gcspr = 0;
+
+static void
+handler (int sig)
+{
+ handler_gcspr = get_gcspr ();
+}
+
+static int __attribute__ ((unused))
+called_from_gdb (int val)
+{
+ return val + 1;
+}
+
+/* Corrupt the return address to see if GDB will report a SIGSEGV with the
+ expected $_siginfo.si_code. */
+static void __attribute__ ((noinline))
+normal_function2 (void)
+{
+ /* x30 holds the return address. */
+ register unsigned long x30 __asm__("x30") __attribute__ ((unused));
+
+ /* Cause a GCS exception. */
+ x30 = 0xbadc0ffee;
+ /* Use explicit ret so that we can verify that a SIGSEGV was generated
+ exactly on the return instruction. */
+ __asm__ volatile ("ret\n");
+}
+
+static inline void __attribute__ ((__always_inline__))
+inline_function2 (void)
+{
+ normal_function2 ();
+}
+
+static void __attribute__ ((noinline))
+normal_function1 (void)
+{
+ inline_function2 ();
+}
+
+/* First in a sequence of inline and normal functions, to test GDB
+ backtrace. */
+static inline void __attribute__ ((__always_inline__))
+inline_function1 (void)
+{
+ normal_function1 ();
+}
+
+/* Trivial function, just so that GDB can test return with wrong GCSPR. */
+static void __attribute__ ((noinline))
+normal_function0 (void)
+{
+ /* Use explicit ret so that we can verify that a SIGSEGV was generated
+ exactly on the return instruction. */
+ __asm__ volatile ("ret\n");
+}
+
+int
+main (void)
+{
+ if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
+ {
+ fprintf (stderr, "GCS support not found in AT_HWCAP\n");
+ return EXIT_FAILURE;
+ }
+
+ /* Force shadow stacks on, our tests *should* be fine with or
+ without libc support and with or without this having ended
+ up tagged for GCS and enabled by the dynamic linker. We
+ can't use the libc prctl() function since we can't return
+ from enabling the stack. Also lock GCS if not already
+ locked so we can test behaviour when it's locked. */
+ unsigned long gcs_mode;
+ int ret = my_syscall2 (__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &gcs_mode);
+ if (ret)
+ {
+ fprintf (stderr, "Failed to read GCS state: %d\n", ret);
+ return EXIT_FAILURE;
+ }
+
+ if (!(gcs_mode & PR_SHADOW_STACK_ENABLE))
+ {
+ gcs_mode = PR_SHADOW_STACK_ENABLE;
+ ret = my_syscall2 (__NR_prctl, PR_SET_SHADOW_STACK_STATUS, gcs_mode);
+ if (ret)
+ {
+ fprintf (stderr, "Failed to configure GCS: %d\n", ret);
+ return EXIT_FAILURE;
+ }
+ }
+
+ /* Regular function call. */
+ normal_function0 ();
+
+ /* This is used by GDB. */
+ __attribute__((unused)) unsigned long *gcspr = get_gcspr ();
+
+ struct sigaction act = { 0 };
+
+ act.sa_handler = &handler; /* Break here. */
+ if (sigaction (SIGUSR1, &act, NULL) == -1)
+ {
+ perror ("sigaction");
+ exit (EXIT_FAILURE);
+ }
+
+ raise (SIGUSR1);
+
+/* Call sequence of inline and normal functions, to test GDB backtrace. */
+ inline_function1 ();
+
+ /* Avoid returning, in case libc doesn't understand GCS. */
+ exit (EXIT_SUCCESS);
+}
diff --git a/gdb/testsuite/gdb.arch/aarch64-gcs.exp b/gdb/testsuite/gdb.arch/aarch64-gcs.exp
new file mode 100644
index 0000000..ad73b41
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-gcs.exp
@@ -0,0 +1,98 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test a binary that uses a Guarded Control Stack.
+
+require allow_aarch64_gcs_tests
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+ return
+}
+
+set linespec ${srcfile}:[gdb_get_line_number "Break here"]
+
+if ![runto ${linespec}] {
+ return
+}
+
+gdb_test "print \$gcs_features_enabled" \
+ [string_to_regexp { = [ PR_SHADOW_STACK_ENABLE ]}] \
+ "GCS is enabled"
+
+gdb_test "print \$gcspr" ". = \\(void \\*\\) $hex" "GDB knows about gcspr"
+gdb_test "print \$gcspr == gcspr" ". = 1" "GDB has the correct gcspr value"
+gdb_test_no_output "set \$gcspr_in_main = \$gcspr" \
+ "save gcspr value in main for later"
+
+# If the inferior function call fails, we don't want the tests following it
+# to be affected.
+gdb_test_no_output "set unwindonsignal on"
+gdb_test "print called_from_gdb (41)" ". = 42" "call inferior function"
+
+gdb_test "break handler" "Breakpoint \[0-9\]+ .*aarch64-gcs.c, line \[0-9\]+\\."
+gdb_test "handle SIGUSR1 nostop" \
+ ".*\r\nSIGUSR1\\s+No\\s+Yes\\s+Yes\\s+User defined signal 1" \
+ "let the inferior receive SIGUSR1 uninterrupted"
+gdb_test "continue" \
+ ".*\r\nBreakpoint \[0-9\]+, handler \\(sig=10\\) at .*aarch64-gcs.c.*handler_gcspr = get_gcspr \\(\\);" \
+ "continue to signal handler"
+
+gdb_test_no_output "set \$gcspr_in_handler = \$gcspr" \
+ "save gcspr value in handler for later"
+# Select the frame above the <signal handler called> frame, which makes GDB
+# unwind the gcspr from the signal frame GCS context.
+gdb_test "frame 2" "#2 ($hex in )?\\S+ \\(.*\\) (at|from) \\S+.*" \
+ "reached frame 2"
+gdb_test "print \$gcspr" ". = \\(void \\*\\) $hex" "gcspr in frame level 2"
+gdb_test "print \$gcspr == \$gcspr_in_handler + 8" ". = 1" \
+ "gcspr unwound from signal context is correct"
+
+gdb_test "continue" \
+ [multi_line \
+ "Continuing\\." \
+ "" \
+ "Program received signal SIGSEGV, Segmentation fault" \
+ "Guarded Control Stack error\\." \
+ "normal_function2 \\(\\) at .*aarch64-gcs.c:$decimal" \
+ "${decimal}\\s+__asm__ volatile \\(\"ret\\\\n\"\\);"] \
+ "continue to SIGSEGV"
+
+gdb_test "print \$_siginfo.si_code" ". = 10" \
+ "test value of si_code when GCS SIGSEGV happens"
+# The GCS grows down, and there are two real frames until main.
+gdb_test "print \$gcspr == \$gcspr_in_main - 16" ". = 1" \
+ "test value of gcspr when GCS SIGSEGV happens"
+
+# Test writing to GCSPR.
+clean_restart ${binfile}
+if ![runto normal_function0] {
+ return
+}
+
+gdb_test_no_output "set \$gcspr = 0xbadc0ffee" "set bogus gcspr value"
+# Continue to make sure that the value was actually written to the register.
+# The SIGSEGV isn't a GCS error because the problem isn't that the GCS entry
+# doesn't match the return address, but rather that that GCSPR is pointing
+# to an invalid address.
+gdb_test "continue" \
+ [multi_line \
+ "Continuing\\." \
+ "" \
+ "Program received signal SIGSEGV, Segmentation fault\\." \
+ "normal_function0 \\(\\) at .*aarch64-gcs.c:$decimal" \
+ "${decimal}\\s+__asm__ volatile \\(\"ret\\\\n\"\\);"] \
+ "continue after bad gcspr"
diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp b/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp
index 08d73d8..b11efa7 100644
--- a/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp
@@ -19,6 +19,7 @@
# instructions.
require is_x86_64_m64_target have_avx
+require support_displaced_stepping
standard_testfile .S
diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step-self-call-alarm.c b/gdb/testsuite/gdb.arch/amd64-disp-step-self-call-alarm.c
index 03b868c..0fb2904 100644
--- a/gdb/testsuite/gdb.arch/amd64-disp-step-self-call-alarm.c
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step-self-call-alarm.c
@@ -16,9 +16,27 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <unistd.h>
+#include <stdlib.h>
+
+extern void test_call (void);
+
+void
+unreachable (void)
+{
+ abort ();
+}
void
setup_alarm (void)
{
alarm (300);
}
+
+int
+main ()
+{
+ setup_alarm ();
+ test_call ();
+ unreachable ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step-self-call.S b/gdb/testsuite/gdb.arch/amd64-disp-step-self-call.S
index 78a6859..20a8eb7 100644
--- a/gdb/testsuite/gdb.arch/amd64-disp-step-self-call.S
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step-self-call.S
@@ -18,33 +18,12 @@
handling. */
.text
-
- .global main
-main:
- nop
-
- callq setup_alarm
-
- nop
-
-/***********************************************/
-
-/* test call/ret */
-
.global test_call
test_call:
call test_call
- nop
+ call unreachable
.global test_ret_end
test_ret_end:
nop
-/***********************************************/
-
-/* all done */
-
-done:
- mov $0,%rdi
- call exit
- hlt
.section .note.GNU-stack,"",@progbits
diff --git a/gdb/testsuite/gdb.arch/amd64-shadow-stack-cmds.exp b/gdb/testsuite/gdb.arch/amd64-shadow-stack-cmds.exp
new file mode 100644
index 0000000..c819cbc
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-shadow-stack-cmds.exp
@@ -0,0 +1,143 @@
+# Copyright 2024-2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test shadow stack enabling for frame level update, the return and the
+# call commands.
+# As potential CET violations often only occur after resuming normal
+# execution, test normal program continuation after each return or call
+# commands.
+
+require allow_ssp_tests
+
+standard_testfile amd64-shadow-stack.c
+
+# Restart GDB an run until breakpoint in call2.
+
+proc restart_and_run_infcall_call2 {} {
+ global binfile
+ clean_restart ${binfile}
+ if { ![runto_main] } {
+ return -1
+ }
+ set inside_infcall_str "The program being debugged stopped while in a function called from GDB"
+ gdb_breakpoint [ gdb_get_line_number "break call2" ]
+ gdb_continue_to_breakpoint "break call2" ".*break call2.*"
+ gdb_test "call (int) call2()" \
+ "Breakpoint \[0-9\]*, call2.*$inside_infcall_str.*"
+}
+
+save_vars { ::env(GLIBC_TUNABLES) } {
+
+ append_environment GLIBC_TUNABLES "glibc.cpu.hwcaps" "SHSTK"
+
+ if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
+ {debug additional_flags="-fcf-protection=return"}] } {
+ return -1
+ }
+
+ clean_restart ${binfile}
+ if { ![runto_main] } {
+ return -1
+ }
+
+ with_test_prefix "test inferior call and continue" {
+ gdb_breakpoint [ gdb_get_line_number "break call1" ]
+ gdb_continue_to_breakpoint "break call1" ".*break call1.*"
+
+ gdb_test "call (int) call2()" "= 42"
+
+ gdb_continue_to_end
+ }
+
+ with_test_prefix "test return inside an inferior call" {
+ restart_and_run_infcall_call2
+
+ gdb_test "return" "\#0.*call2.*" \
+ "Test shadow stack return inside an inferior call" \
+ "Make.*return now\\? \\(y or n\\) " "y"
+
+ gdb_continue_to_end
+ }
+
+ with_test_prefix "test return 'above' an inferior call" {
+ restart_and_run_infcall_call2
+
+ gdb_test "frame 2" "call2 ().*" "move to frame 'above' inferior call"
+
+ gdb_test "return" "\#0.*call1.*" \
+ "Test shadow stack return 'above' an inferior call" \
+ "Make.*return now\\? \\(y or n\\) " "y"
+
+ gdb_continue_to_end
+ }
+
+ clean_restart ${binfile}
+ if { ![runto_main] } {
+ return -1
+ }
+
+ set call1_line [ gdb_get_line_number "break call1" ]
+ set call2_line [ gdb_get_line_number "break call2" ]
+
+ # Extract shadow stack pointer inside main, call1 and call2 function.
+ gdb_breakpoint $call1_line
+ gdb_breakpoint $call2_line
+ set ssp_main [get_valueof /x "\$pl3_ssp" 0 "get value of ssp in main"]
+ gdb_continue_to_breakpoint "break call1" ".*break call1.*"
+ set ssp_call1 [get_valueof /x "\$pl3_ssp" 0 "get value of ssp in call1"]
+ gdb_continue_to_breakpoint "break call2" ".*break call2.*"
+ set ssp_call2 [get_valueof /x "\$pl3_ssp" 0 "get value of ssp in call2"]
+
+ with_test_prefix "test frame level update" {
+ gdb_test "up" "call1.*" "move to frame 1"
+ gdb_test "print /x \$pl3_ssp" "= $ssp_call1" "check pl3_ssp of frame 1"
+ gdb_test "up" "main.*" "move to frame 2"
+ gdb_test "print /x \$pl3_ssp" "= $ssp_main" "check pl3_ssp of frame 2"
+ gdb_test "frame 0" "call2.*" "move to frame 0"
+ gdb_test "print /x \$pl3_ssp" "= $ssp_call2" "check pl3_ssp of frame 0"
+ }
+
+ with_test_prefix "test return from current frame" {
+ gdb_test "return (int) 1" "#0.*call1.*" \
+ "Test shadow stack return from current frame" \
+ "Make.*return now\\? \\(y or n\\) " "y"
+
+ # Potential CET violations often only occur after resuming normal execution.
+ # Therefore, it is important to test normal program continuation after
+ # testing the return command.
+ gdb_continue_to_end
+ }
+
+ clean_restart ${binfile}
+ if { ![runto_main] } {
+ return -1
+ }
+
+ with_test_prefix "test return from past frame" {
+ gdb_breakpoint $call2_line
+ gdb_continue_to_breakpoint "break call2" ".*break call2.*"
+
+ gdb_test "frame 1" ".*in call1.*"
+
+ gdb_test "return (int) 1" "#0.*main.*" \
+ "Test shadow stack return from past frame" \
+ "Make.*return now\\? \\(y or n\\) " "y"
+
+ # Potential CET violations often only occur after resuming normal execution.
+ # Therefore, it is important to test normal program continuation after
+ # testing the return command.
+ gdb_continue_to_end
+ }
+}
diff --git a/gdb/testsuite/gdb.arch/amd64-shadow-stack-corefile.c b/gdb/testsuite/gdb.arch/amd64-shadow-stack-corefile.c
new file mode 100644
index 0000000..5e84793
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-shadow-stack-corefile.c
@@ -0,0 +1,46 @@
+/* This test program is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+
+/* Call the return instruction before function epilogue to trigger a
+ control-flow exception. */
+void
+function ()
+{
+ unsigned long ssp;
+ #ifndef __ILP32__
+ asm volatile ("xor %0, %0; rdsspq %0" : "=r" (ssp));
+ #else
+ asm volatile ("xor %0, %0; rdsspd %0" : "=r" (ssp));
+ #endif
+
+ /* Print ssp to stdout so that the testcase can capture it. */
+ printf ("%p\n", (void *) ssp);
+ fflush (stdout);
+
+ /* Manually cause a control-flow exception by executing a return
+ instruction before function epilogue, so the address atop the stack
+ is not the return instruction. */
+ __asm__ volatile ("ret\n");
+}
+
+int
+main (void)
+{
+ function (); /* Break here. */
+}
diff --git a/gdb/testsuite/gdb.arch/amd64-shadow-stack-corefile.exp b/gdb/testsuite/gdb.arch/amd64-shadow-stack-corefile.exp
new file mode 100644
index 0000000..a45cd06
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-shadow-stack-corefile.exp
@@ -0,0 +1,119 @@
+# Copyright 2024-2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test the shadow stack pointer note in core dumps.
+# Based on the corefile tests in gdb.arch/aarch64-gcs-core.exp.
+
+require allow_ssp_tests
+
+standard_testfile
+
+# Make sure GDB can read the given core file correctly.
+
+proc check_core_file {core_filename saved_pl3_ssp} {
+ global decimal
+
+ # Load the core file.
+ if [gdb_test "core $core_filename" \
+ [multi_line \
+ "Core was generated by .*\\." \
+ "Program terminated with signal SIGSEGV, Segmentation fault.*" \
+ "#0 function \\(\\) at .*amd64-shadow-stack-corefile.c:$decimal" \
+ "$decimal.*__asm__ volatile \\(\"ret\\\\n\"\\);"] \
+ "load core file"] {
+ return
+ }
+
+ # Check the value of ssp in the core file.
+ gdb_test "print/x \$pl3_ssp" "\\$\[0-9\]+ = $saved_pl3_ssp" \
+ "pl3_ssp contents from core file $saved_pl3_ssp"
+}
+
+save_vars { ::env(GLIBC_TUNABLES) } {
+
+ append_environment GLIBC_TUNABLES "glibc.cpu.hwcaps" "SHSTK"
+
+ if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
+ {debug additional_flags="-fcf-protection=return"}] } {
+ return
+ }
+
+ set linespec ${srcfile}:[gdb_get_line_number "Break here"]
+
+ if ![runto $linespec] {
+ return
+ }
+
+ # Obtain an OS-generated core file. Save test program output to
+ # ${binfile}.out.
+ set core_filename [core_find $binfile {} {} "${binfile}.out"]
+ set core_generated [expr {$core_filename != ""}]
+
+ if {!$core_generated} {
+ untested "unable to create or find corefile"
+ }
+
+ # Load the core file and check the value of the shadow stack pointer.
+ if {$core_generated} {
+ clean_restart $binfile
+
+ with_test_prefix "OS corefile" {
+ # Read ssp value from saved output of the test program.
+ set out_id [open ${binfile}.out "r"]
+ set ssp_in_gcore [gets $out_id]
+ close $out_id
+ check_core_file $core_filename $ssp_in_gcore
+ }
+ }
+
+ if ![gcore_cmd_available] {
+ unsupported "target does not support gcore command."
+ return
+ }
+
+ clean_restart $binfile
+
+ if ![runto $linespec] {
+ return
+ }
+
+ # Continue until a crash. The line with the hex number is optional because
+ # it's printed by the test program, and doesn't appear in the Expect buffer
+ # when testing a remote target.
+
+ gdb_test "continue" \
+ [multi_line \
+ "Continuing\\." \
+ "($hex\r\n)?" \
+ "Program received signal SIGSEGV, Segmentation fault.*" \
+ "function \\(\\) at .*amd64-shadow-stack-corefile.c:$decimal" \
+ {.*__asm__ volatile \("ret\\n"\);}] \
+ "continue to SIGSEGV"
+
+ set ssp_in_gcore [get_valueof "/x" "\$pl3_ssp" "*unknown*"]
+
+ # Generate the gcore core file.
+ set gcore_filename [standard_output_file "${testfile}.gcore"]
+ set gcore_generated [gdb_gcore_cmd "$gcore_filename" "generate gcore file"]
+
+ gdb_assert { $gcore_generated } "gcore corefile created"
+ if { $gcore_generated } {
+ clean_restart $binfile
+
+ with_test_prefix "gcore corefile" {
+ check_core_file $gcore_filename $ssp_in_gcore
+ }
+ }
+}
diff --git a/gdb/testsuite/gdb.arch/amd64-shadow-stack-disp-step.exp b/gdb/testsuite/gdb.arch/amd64-shadow-stack-disp-step.exp
new file mode 100644
index 0000000..e4efa00
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-shadow-stack-disp-step.exp
@@ -0,0 +1,84 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test continue from call instructions with shadow stack and displaced
+# stepping being enabled.
+
+require allow_ssp_tests support_displaced_stepping
+
+standard_testfile amd64-shadow-stack.c
+
+save_vars { ::env(GLIBC_TUNABLES) } {
+
+ append_environment GLIBC_TUNABLES "glibc.cpu.hwcaps" "SHSTK"
+
+ if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
+ additional_flags="-fcf-protection=return"] } {
+ return
+ }
+
+ # Enable displaced stepping.
+ gdb_test_no_output "set displaced-stepping on"
+ gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
+
+ if { ![runto_main] } {
+ return
+ }
+
+ # Get the address of the call to the call1 function.
+ set call1_addr -1
+ gdb_test_multiple "disassemble main" "" {
+ -re -wrap "($hex) <\\+($decimal)>:\\s*call\\s*0x.*<call1>.*" {
+ set call1_addr $expect_out(1,string)
+ pass $gdb_test_name
+ }
+ }
+
+ if { $call1_addr == -1 } {
+ return
+ }
+
+ # Get the address of the call to the call2 function.
+ set call2_addr -1
+ gdb_test_multiple "disassemble call1" "" {
+ -re -wrap "($hex) <\\+($decimal)>:\\s*call\\s*0x.*<call2>.*" {
+ set call2_addr $expect_out(1,string)
+ pass $gdb_test_name
+ }
+ }
+
+ if { $call2_addr == -1 } {
+ return
+ }
+
+ gdb_test "break *$call1_addr" \
+ "Breakpoint $decimal at $hex.*" \
+ "break at the address of the call1 instruction"
+
+ gdb_test "break *$call2_addr" \
+ "Breakpoint $decimal at $hex.*" \
+ "break at the address of the call2 instruction"
+
+ gdb_test "continue" \
+ "Breakpoint $decimal, $call1_addr in main ().*" \
+ "continue until call1 instruction"
+
+ # Test continue from breakpoint at call1 and call2 instructions.
+ gdb_test "continue" \
+ "Breakpoint $decimal, $call2_addr in call1 ().*" \
+ "continue from call1 instruction"
+
+ gdb_continue_to_end "continue from call2 instruction"
+}
diff --git a/gdb/testsuite/gdb.arch/amd64-shadow-stack.c b/gdb/testsuite/gdb.arch/amd64-shadow-stack.c
new file mode 100644
index 0000000..4a1ca1e
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-shadow-stack.c
@@ -0,0 +1,40 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2024-2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+static int
+call2 ()
+{
+ return 42; /* break call2. */
+}
+
+static int
+call1 ()
+{
+ return call2 (); /* break call1. */
+}
+
+int
+main ()
+{
+ /* Depending on instruction generation we might end up in the call
+ instruction of call1 function after "runto_main". Avoid this by
+ adding a nop instruction, to simplify the testing in
+ amd64-shadow-stack-disp-step.exp. */
+ asm ("nop");
+ call1 (); /* break main. */
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.arch/amd64-shadow-stack.exp b/gdb/testsuite/gdb.arch/amd64-shadow-stack.exp
new file mode 100644
index 0000000..a72334a
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-shadow-stack.exp
@@ -0,0 +1,71 @@
+# Copyright 2024-2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test accessing the shadow stack pointer register.
+
+require allow_ssp_tests
+
+standard_testfile
+
+# Write PL3_SSP register with invalid shadow stack pointer value.
+proc write_invalid_ssp {} {
+ gdb_test "print /x \$pl3_ssp = 0x12345678" "= 0x12345678" "set pl3_ssp value"
+ gdb_test "print /x \$pl3_ssp" "= 0x12345678" "read pl3_ssp value after setting"
+}
+
+save_vars { ::env(GLIBC_TUNABLES) } {
+
+ append_environment GLIBC_TUNABLES "glibc.cpu.hwcaps" "SHSTK"
+
+ if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
+ additional_flags="-fcf-protection=return"] } {
+ return
+ }
+
+ if {![runto_main]} {
+ return
+ }
+
+ with_test_prefix "invalid ssp" {
+ write_invalid_ssp
+
+ # Continue until SIGSEV to test that the value is written back to HW.
+ gdb_test "continue" \
+ [multi_line \
+ "Continuing\\." \
+ "" \
+ "Program received signal SIGSEGV, Segmentation fault\\." \
+ "$hex in main \\(\\)"] \
+ "continue to SIGSEGV"
+ }
+
+ clean_restart ${binfile}
+ if { ![runto_main] } {
+ return
+ }
+
+ with_test_prefix "restore original ssp" {
+ # Read PL3_SSP register.
+ set ssp_main [get_hexadecimal_valueof "\$pl3_ssp" "read pl3_ssp value"]
+
+ write_invalid_ssp
+
+ # Restore original value.
+ gdb_test "print /x \$pl3_ssp = $ssp_main" "= $ssp_main" "restore original value"
+
+ # Now we should not see a SIGSEV, since the original value is restored.
+ gdb_continue_to_end
+ }
+}
diff --git a/gdb/testsuite/gdb.arch/amd64-watchpoint-downgrade.exp b/gdb/testsuite/gdb.arch/amd64-watchpoint-downgrade.exp
index dcee040..5663b0d 100644
--- a/gdb/testsuite/gdb.arch/amd64-watchpoint-downgrade.exp
+++ b/gdb/testsuite/gdb.arch/amd64-watchpoint-downgrade.exp
@@ -58,7 +58,7 @@ gdb_test "starti" \
[multi_line \
"warning: watchpoint $num downgraded to software watchpoint" \
"" \
- "Program stopped\\." \
+ "(Program|Thread \[^\r\n\]) stopped\\." \
".*"]
# Watchpoint should now have downgraded to a s/w watchpoint.
diff --git a/gdb/testsuite/gdb.arch/i386-disp-step-self-call-alarm.c b/gdb/testsuite/gdb.arch/i386-disp-step-self-call-alarm.c
index 03b868c..0fb2904 100644
--- a/gdb/testsuite/gdb.arch/i386-disp-step-self-call-alarm.c
+++ b/gdb/testsuite/gdb.arch/i386-disp-step-self-call-alarm.c
@@ -16,9 +16,27 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <unistd.h>
+#include <stdlib.h>
+
+extern void test_call (void);
+
+void
+unreachable (void)
+{
+ abort ();
+}
void
setup_alarm (void)
{
alarm (300);
}
+
+int
+main ()
+{
+ setup_alarm ();
+ test_call ();
+ unreachable ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.arch/i386-disp-step-self-call.S b/gdb/testsuite/gdb.arch/i386-disp-step-self-call.S
index 466e50c..20a8eb7 100644
--- a/gdb/testsuite/gdb.arch/i386-disp-step-self-call.S
+++ b/gdb/testsuite/gdb.arch/i386-disp-step-self-call.S
@@ -18,33 +18,12 @@
handling. */
.text
-
- .global main
-main:
- nop
-
- call setup_alarm
-
- nop
-
-/***********************************************/
-
-/* test call/ret */
-
.global test_call
test_call:
call test_call
- nop
+ call unreachable
.global test_ret_end
test_ret_end:
nop
-/***********************************************/
-
-/* all done */
-
-done:
- pushl $0
- call exit
- hlt
.section .note.GNU-stack,"",@progbits
diff --git a/gdb/testsuite/gdb.arch/i386-prologue-skip-cf-protection-stackalign.c b/gdb/testsuite/gdb.arch/i386-prologue-skip-cf-protection-stackalign.c
new file mode 100644
index 0000000..f55cee5
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/i386-prologue-skip-cf-protection-stackalign.c
@@ -0,0 +1,27 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <alloca.h>
+
+int
+main (int argc, char **argv)
+{
+ volatile __attribute__ ((__aligned__ (64))) int a;
+ volatile char *p = (char *) alloca (argc * 12);
+ p[2] = 'b';
+ return 1;
+}
diff --git a/gdb/testsuite/gdb.arch/i386-prologue-skip-cf-protection.exp b/gdb/testsuite/gdb.arch/i386-prologue-skip-cf-protection.exp
index eb93127..06285ce 100644
--- a/gdb/testsuite/gdb.arch/i386-prologue-skip-cf-protection.exp
+++ b/gdb/testsuite/gdb.arch/i386-prologue-skip-cf-protection.exp
@@ -19,41 +19,65 @@
# This option places an `endbr32`/`endbr64` instruction at the start of
# all functions, which can interfere with prologue analysis.
-standard_testfile .c
-set binfile ${binfile}
+standard_testfile .c -stackalign.c
require {is_any_target x86_64-*-* i?86-*-*}
-
require supports_fcf_protection
-set opts {debug additional_flags=-fcf-protection=full}
+# Tests if breakpoint set on main is placed past main's entry.
+proc test_run {} {
+ # Get start address of function main.
+ set main_addr [get_integer_valueof &main -1]
+ gdb_assert {$main_addr != -1}
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } {
- untested "failed to compile"
- return
-}
+ set bp_addr -1
-clean_restart ${binfile}
+ # Put breakpoint on main, get the address where the breakpoint was installed.
+ gdb_test_multiple "break -q main" "break on main, get address" {
+ -re -wrap "Breakpoint $::decimal at ($::hex).*" {
+ set bp_addr $expect_out(1,string)
-# Get start address of function main.
-set main_addr [get_integer_valueof &main -1]
-gdb_assert {$main_addr != -1}
+ # Convert to decimal.
+ set bp_addr [expr $bp_addr]
-set bp_addr -1
+ pass $gdb_test_name
+ }
+ }
-# Put breakpoint on main, get the address where the breakpoint was installed.
-gdb_test_multiple "break -q main" "break on main, get address" {
- -re -wrap "Breakpoint $decimal at ($hex).*" {
- set bp_addr $expect_out(1,string)
+ # Make sure some prologue was skipped.
+ gdb_assert {$bp_addr != -1 && $bp_addr > $main_addr} \
+ "breakpoint placed past main's entry"
+}
- # Convert to decimal.
- set bp_addr [expr $bp_addr]
+with_test_prefix "skip-cf-protection" {
+ set opts {debug additional_flags=-fcf-protection=full}
- pass $gdb_test_name
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
+ $opts] != "" } {
+ untested "failed to compile"
+ return
}
+
+ clean_restart ${binfile}
+
+ test_run
}
-if { $bp_addr != -1 } {
- # Make sure some prologue was skipped.
- gdb_assert {$bp_addr > $main_addr}
+# Now, make sure that the prologue analysis does not end up at function's entry
+# when stack alignment sequence is generated right after 'endbr64'/'endbr32'.
+# That could happen if GDB handled those incorrectly - there was a bug that
+# checked for those two in incorrect order, which caused such issue.
+with_test_prefix "skip-cf-protection-stackalign" {
+ # gcc is easier to make it produce the sequence of interest.
+ if { ![is_c_compiler_gcc] } {
+ unsupported "stackalign test part requires gcc compiler"
+ return
+ }
+
+ if { [prepare_for_testing "failed to prepare" "${testfile}-stackalign" \
+ $srcfile2 [list optimize=-O0 additional_flags=-fcf-protection=full]] } {
+ return
+ }
+
+ test_run
}
diff --git a/gdb/testsuite/gdb.base/a2-run.exp b/gdb/testsuite/gdb.base/a2-run.exp
index 4e95e56..966e12a 100644
--- a/gdb/testsuite/gdb.base/a2-run.exp
+++ b/gdb/testsuite/gdb.base/a2-run.exp
@@ -18,6 +18,8 @@
# Can't do this test without stdio support.
require {!gdb_skip_stdio_test "a2run.exp"}
+set have_startup_shell [have_startup_shell]
+
#
# test running programs
#
@@ -166,9 +168,8 @@ gdb_run_cmd
setup_xfail "arm-*-coff"
gdb_test_stdio "" "720" "" "run \"$testfile\" again after setting args"
-# GOAL: Test that shell is being used with "run". For remote debugging
-# targets, there is no guarantee that a "shell" (whatever that is) is used.
-if {![is_remote target]} {
+# GOAL: Test that shell is being used with "run".
+if { $have_startup_shell == 1 } {
gdb_test_stdio "run `echo 8`" \
"40320" "" "run \"$testfile\" with shell"
}
diff --git a/gdb/testsuite/gdb.base/annotate-symlink.exp b/gdb/testsuite/gdb.base/annotate-symlink.exp
index f7f6f18..a5d431e 100644
--- a/gdb/testsuite/gdb.base/annotate-symlink.exp
+++ b/gdb/testsuite/gdb.base/annotate-symlink.exp
@@ -20,7 +20,7 @@ standard_testfile realname-expand.c realname-expand-real.c
require {!is_remote host}
set srcdirabs [file join [pwd] $srcdir]
-set srcfilelink [standard_output_file realname-expand-link.c]
+set srcfilelink [build_standard_output_file realname-expand-link.c]
remote_exec build "ln -sf ${srcdirabs}/${subdir}/${srcfile2} $srcfilelink"
diff --git a/gdb/testsuite/gdb.base/args.exp b/gdb/testsuite/gdb.base/args.exp
index 33952e4..7b62a75 100644
--- a/gdb/testsuite/gdb.base/args.exp
+++ b/gdb/testsuite/gdb.base/args.exp
@@ -21,6 +21,7 @@ require {!target_info exists noargs}
# This test requires starting new inferior processes, skip it if the target
# board is a stub.
require !use_gdb_stub
+require {expr [have_startup_shell] != -1}
standard_testfile
diff --git a/gdb/testsuite/gdb.base/attach-deleted-exec.exp b/gdb/testsuite/gdb.base/attach-deleted-exec.exp
index 82a7bb4..45fac0d 100644
--- a/gdb/testsuite/gdb.base/attach-deleted-exec.exp
+++ b/gdb/testsuite/gdb.base/attach-deleted-exec.exp
@@ -67,5 +67,49 @@ if { [regexp $re_nfs $filename] } {
gdb_assert { [string equal $filename /proc/${testpid}/exe] } $test
}
+# Restart GDB.
+clean_restart
+
+# Setup an empty sysroot. GDB will fail to find the executable within
+# the sysroot. Additionally, the presence of a sysroot should prevent
+# GDB from trying to load the executable from /proc/PID/exe.
+set sysroot [standard_output_file "sysroot"]
+gdb_test_no_output "set sysroot $sysroot" \
+ "setup sysroot"
+
+# Attach to the inferior. GDB should complain about failing to find
+# the executable. It is the name of the executable that GDB doesn't
+# find that we're interesting in here. For native targets GDB should
+# be looking for BINFILE, not /proc/PID/exe.
+#
+# For extended-remote targets things are unfortunately harder. Native
+# GDB looks for BINFILE because it understands that GDB will be
+# looking in the sysroot. But remote GDB doesn't know if GDB is using
+# a sysroot or not. As such, gdbserver will return /proc/PID/exe if
+# it knows that the file has been deleted locally. This isn't great
+# if GDB then plans to look in a sysroot, but equally, if the remote
+# file has been deleted, then the name GDB will return, will have had
+# " (deleted" appended, so we're unlikely to get a hit in the sysroot
+# either way.
+if { [target_info gdb_protocol] == "extended-remote" } {
+ set filename_re "/proc/$testpid/exe"
+} else {
+ set filename_re "\[^\r\n\]+/${testfile} \\(deleted\\)"
+}
+
+verbose -log "APB: warning: No executable has been specified, and target executable $filename_re could not be found\\. Try using the \"file\" command\\."
+
+gdb_test "attach $testpid" \
+ [multi_line \
+ "Attaching to process $decimal" \
+ "warning: No executable has been specified, and target executable $filename_re could not be found\\. Try using the \"file\" command\\." \
+ ".*"] \
+ "attach to inferior"
+
+# Check GDB hasn't managed to load an executable.
+gdb_test "info inferior" \
+ "\\*\[^)\]+\\)\\s*" \
+ "confirm no executable is loaded."
+
# Cleanup.
kill_wait_spawned_process $test_spawn_id
diff --git a/gdb/testsuite/gdb.base/attach.c b/gdb/testsuite/gdb.base/attach.c
index b3c5498..5133dd0 100644
--- a/gdb/testsuite/gdb.base/attach.c
+++ b/gdb/testsuite/gdb.base/attach.c
@@ -5,7 +5,7 @@
exit unless/until gdb sets the variable to non-zero.)
*/
#include <stdio.h>
-#include <unistd.h>
+#include "gdb_watchdog.h"
int bidule = 0;
volatile int should_exit = 0;
@@ -14,7 +14,7 @@ int main ()
{
int local_i = 0;
- alarm (60);
+ gdb_watchdog (60);
while (! should_exit)
{
diff --git a/gdb/testsuite/gdb.base/backtrace-through-cu-nodebug.exp b/gdb/testsuite/gdb.base/backtrace-through-cu-nodebug.exp
index 53bf642..fce6d67 100644
--- a/gdb/testsuite/gdb.base/backtrace-through-cu-nodebug.exp
+++ b/gdb/testsuite/gdb.base/backtrace-through-cu-nodebug.exp
@@ -31,7 +31,7 @@ proc prepare_test {has_cfi} {
"${objcallerfile}" \
object [list {additional_flags=-fomit-frame-pointer \
-funwind-tables -fasynchronous-unwind-tables}]] != "" } {
- untested "couldn't compile with cfi"
+ untested "couldn't compile"
return false
}
} else {
@@ -41,7 +41,7 @@ proc prepare_test {has_cfi} {
object [list {additional_flags=-fomit-frame-pointer \
-fno-unwind-tables \
-fno-asynchronous-unwind-tables}]] != "" } {
- untested "couldn't compile without cfi"
+ untested "couldn't compile"
return false
}
}
@@ -54,15 +54,12 @@ proc prepare_test {has_cfi} {
clean_restart "$binfile-${extension}"
- with_test_prefix "${extension}" {
-
- if ![runto callback] then {
- fail "has_cfi=$has_cfi: Can't run to callback"
- return false
- }
- gdb_test_no_output "maint frame-unwinder disable ARCH"
- return true
+ if ![runto callback] then {
+ fail "has_cfi=$has_cfi: Can't run to callback"
+ return false
}
+ gdb_test_no_output "maint frame-unwinder disable ARCH"
+ return true
}
if {[gdb_compile "${srcdir}/${subdir}/${srcfile2}" \
@@ -72,15 +69,45 @@ if {[gdb_compile "${srcdir}/${subdir}/${srcfile2}" \
return
}
-if { [prepare_test false] } {
- gdb_test "bt" \
+proc_with_prefix no-cfi {} {
+ if { ![prepare_test false] } {
+ return
+ }
+
+ set re_msg \
+ [string_list_to_regexp \
+ "Required frame unwinder may have been disabled," \
+ " see 'maint info frame-unwinders'"]
+ set hs {[^\r\n]}
+ set re_bt_line "#0\\s+[string_to_regexp {callback ()}] $hs+"
+ set re_bt_no_filters \
[multi_line \
- "\[^\r\n\]+Required frame unwinder may have been disabled, \[^\r\n\]+" \
- "#0\\s+callback \\(\\) \[^\r\n\]+"] \
- "verify unwind fail without CFI"
+ $re_bt_line \
+ $re_msg]
+ gdb_test "bt -no-filters" \
+ $re_bt_no_filters \
+ "verify no-filters unwind fail"
+
+ # Flush frame cache to retrigger the message.
+ gdb_test "maint flush register-cache" \
+ [string_to_regexp "Register cache flushed."]
+
+ # This output may occur when we run into the message while applying the
+ # frame filters.
+ set re_bt \
+ [multi_line \
+ $hs+$re_msg \
+ $re_bt_line]
+ gdb_test "bt" \
+ "($re_bt|$re_bt_no_filters)" \
+ "verify unwind fail"
}
-if { [prepare_test true] } {
+proc_with_prefix cfi {} {
+ if { ![prepare_test true] } {
+ return
+ }
+
if { [istarget "arm*-*-*"] } {
setup_kfail backtrace/31950 *-*-*
}
@@ -89,6 +116,12 @@ if { [prepare_test true] } {
# #1 0x00000000004004e9 in caller ()
# #2 0x00000000004004cd in main () at ...
gdb_test "bt" \
- "#0 +callback $text\r\n#1 $text in caller $text\r\n#2 $text in main $text" \
- "Verify unwinding works based only on CFI information"
+ [multi_line \
+ "#0 +callback $text" \
+ "#1 $text in caller $text" \
+ "#2 $text in main $text"] \
+ "Verify unwinding works"
}
+
+no-cfi
+cfi
diff --git a/gdb/testsuite/gdb.base/backtrace.exp b/gdb/testsuite/gdb.base/backtrace.exp
index 35784b4..3020666 100644
--- a/gdb/testsuite/gdb.base/backtrace.exp
+++ b/gdb/testsuite/gdb.base/backtrace.exp
@@ -17,11 +17,7 @@
standard_testfile
-set flags {}
-lappend flags debug
-lappend_include_file flags $srcdir/lib/attributes.h
-
-if { [prepare_for_testing "failed to prepare" $testfile $srcfile $flags] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
return -1
}
diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.exp b/gdb/testsuite/gdb.base/bp-cond-failure.exp
index d645454..4d03e7b 100644
--- a/gdb/testsuite/gdb.base/bp-cond-failure.exp
+++ b/gdb/testsuite/gdb.base/bp-cond-failure.exp
@@ -75,7 +75,7 @@ proc run_test { cond_eval access_type bpexpr nloc } {
"Error in testing condition for breakpoint ${bp_num}.2:" \
"Cannot access memory at address 0x0" \
"" \
- "Breakpoint ${bp_num}.2, foo \\(c=49 ...\\) at \[^\r\n\]+:\[0-9\]+" \
+ "(Thread \[^\r\n\]+ hit )?Breakpoint ${bp_num}.2, foo \\(c=49 ...\\) at \[^\r\n\]+:\[0-9\]+" \
"${::decimal}\\s+\[^\r\n\]+ breakpoint here\\. \[^\r\n\]+"]
} else {
gdb_test "continue" \
@@ -84,7 +84,7 @@ proc run_test { cond_eval access_type bpexpr nloc } {
"Error in testing condition for breakpoint ${bp_num}:" \
"Cannot access memory at address 0x0" \
"" \
- "Breakpoint ${bp_num}, bar \\(\\) at \[^\r\n\]+:\[0-9\]+" \
+ "(Thread \[^\r\n\]+ hit )?Breakpoint ${bp_num}, bar \\(\\) at \[^\r\n\]+:\[0-9\]+" \
"${::decimal}\\s+\[^\r\n\]+ breakpoint here\\. \[^\r\n\]+"]
}
}
diff --git a/gdb/testsuite/gdb.base/bp-permanent.c b/gdb/testsuite/gdb.base/bp-permanent.c
index d586acc..72e5e8a 100644
--- a/gdb/testsuite/gdb.base/bp-permanent.c
+++ b/gdb/testsuite/gdb.base/bp-permanent.c
@@ -101,7 +101,7 @@ test_signal_no_handler (void)
}
static void
-test_signal_nested_handler ()
+test_signal_nested_handler (int sig)
{
test ();
}
diff --git a/gdb/testsuite/gdb.base/bp-permanent.exp b/gdb/testsuite/gdb.base/bp-permanent.exp
index 62ce3f6..c6c6269 100644
--- a/gdb/testsuite/gdb.base/bp-permanent.exp
+++ b/gdb/testsuite/gdb.base/bp-permanent.exp
@@ -134,7 +134,7 @@ proc test {always_inserted sw_watchpoint} {
unsupported "failed to stop at permanent breakpoint"
return
}
- -re "Program received signal SIGTRAP.*$gdb_prompt $" {
+ -re "received signal SIGTRAP.*$gdb_prompt $" {
pass $test
}
}
@@ -174,7 +174,7 @@ proc test {always_inserted sw_watchpoint} {
# disabled, it should act as if we hadn't created it in the first
# place. IOW, we should get a random signal, and, the breakpoint's
# command should not run.
- gdb_test "continue" "Program received signal SIGTRAP.*" \
+ gdb_test "continue" "received signal SIGTRAP.*" \
"disabled permanent breakpoint doesn't explain stop"
gdb_test "info breakpoints" \
diff --git a/gdb/testsuite/gdb.base/break-dbg.cc b/gdb/testsuite/gdb.base/break-dbg.cc
new file mode 100644
index 0000000..642ded0
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-dbg.cc
@@ -0,0 +1,31 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+volatile int global_var = 0;
+
+int
+foo ()
+{
+ return global_var;
+}
+
+int
+main ()
+{
+ int res = foo ();
+ return res;
+}
diff --git a/gdb/testsuite/gdb.base/break-dbg.exp b/gdb/testsuite/gdb.base/break-dbg.exp
new file mode 100644
index 0000000..a7c7d92
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-dbg.exp
@@ -0,0 +1,80 @@
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+# Some basic testing of 'set debug breakpoint on'. At one point a bug
+# meant that some breakpoints would immediately trigger a segfault if
+# GDB tried to run with breakpoint debugging turned on.
+#
+# Test is compiled as C++ only so 'catch catch/throw/rethrow' have a
+# something to do. The original bug would trigger for any 'catch'
+# style breakpoint, so C++ isn't really a hard requirement.
+
+standard_testfile .cc
+
+require allow_cplus_tests
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
+ {debug c++}] } {
+ return
+}
+
+if {![runto_main]} {
+ return
+}
+
+gdb_test "catch catch" "^Catchpoint $decimal \\(catch\\)"
+gdb_test "catch throw" "^Catchpoint $decimal \\(throw\\)"
+gdb_test "catch rethrow" "^Catchpoint $decimal \\(rethrow\\)"
+
+gdb_test "catch exec" "^Catchpoint $decimal \\(exec\\)"
+gdb_test "catch fork" "^Catchpoint $decimal \\(fork\\)"
+gdb_test "catch vfork" "^Catchpoint $decimal \\(vfork\\)"
+
+gdb_test "catch load" "^Catchpoint $decimal \\(load\\)"
+gdb_test "catch unload" "^Catchpoint $decimal \\(unload\\)"
+
+gdb_test "catch signal" "^Catchpoint $decimal \\(standard signals\\)"
+
+set re_warning_xml_disabled \
+ [string_to_regexp \
+ [join \
+ [list \
+ "warning: Can not parse XML syscalls information;" \
+ "XML support was disabled at compile time."]]]
+gdb_test "catch syscall" \
+ [multi_line \
+ "^($re_warning_xml_disabled" \
+ ")?Catchpoint $decimal [string_to_regexp {(any syscall)}]"]
+
+gdb_test "watch -l global_var" "\[Ww]atchpoint $decimal: -location global_var"
+
+gdb_test_no_output "set debug breakpoint on"
+
+set saw_bp_debug_line false
+gdb_test_multiple "step" "" {
+ -re "^step\r\n" {
+ exp_continue
+ }
+ -re "^\\\[breakpoint\\\] \[^\r\n\]+\r\n" {
+ set saw_bp_debug_line true
+ exp_continue
+ }
+ -re "^$gdb_prompt $" {
+ gdb_assert { $saw_bp_debug_line } $gdb_test_name
+ }
+ -re "^\[^\r\n\]*\r\n" {
+ exp_continue
+ }
+}
diff --git a/gdb/testsuite/gdb.base/break-interp.exp b/gdb/testsuite/gdb.base/break-interp.exp
index 649cc86..04d8c55 100644
--- a/gdb/testsuite/gdb.base/break-interp.exp
+++ b/gdb/testsuite/gdb.base/break-interp.exp
@@ -218,6 +218,7 @@ proc test_core {file displacement} {
set corefile [core_find $file {} "segv"]
if {$corefile == ""} {
+ untested "unable to create or find corefile"
return
}
diff --git a/gdb/testsuite/gdb.base/catch-fork-kill.exp b/gdb/testsuite/gdb.base/catch-fork-kill.exp
index 0fd853b..224a8df 100644
--- a/gdb/testsuite/gdb.base/catch-fork-kill.exp
+++ b/gdb/testsuite/gdb.base/catch-fork-kill.exp
@@ -32,6 +32,8 @@
standard_testfile
+require allow_fork_tests
+
# Build two programs -- one for fork, and another for vfork.
set testfile_fork "${testfile}-fork"
set testfile_vfork "${testfile}-vfork"
diff --git a/gdb/testsuite/gdb.base/catch-fork-static.exp b/gdb/testsuite/gdb.base/catch-fork-static.exp
index b171a6d..9d50d5d 100644
--- a/gdb/testsuite/gdb.base/catch-fork-static.exp
+++ b/gdb/testsuite/gdb.base/catch-fork-static.exp
@@ -21,9 +21,7 @@
# ld.so probes before reaching main, and ptrace flags were set then. But a
# static executable would just keep running and never catch the fork.
-# Until "catch fork" is implemented on other targets...
-#
-require {is_any_target "*-*-linux*" "*-*-openbsd*"}
+require allow_fork_tests
# Reusing foll-fork.c since it's a simple forking program.
standard_testfile foll-fork.c
diff --git a/gdb/testsuite/gdb.base/catch-signal-fork.exp b/gdb/testsuite/gdb.base/catch-signal-fork.exp
index dea0cc4..2a33ee1 100644
--- a/gdb/testsuite/gdb.base/catch-signal-fork.exp
+++ b/gdb/testsuite/gdb.base/catch-signal-fork.exp
@@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require {!target_info exists gdb,nosignals}
+require allow_fork_tests
standard_testfile
diff --git a/gdb/testsuite/gdb.base/color-prompt.exp b/gdb/testsuite/gdb.base/color-prompt.exp
new file mode 100644
index 0000000..c037185
--- /dev/null
+++ b/gdb/testsuite/gdb.base/color-prompt.exp
@@ -0,0 +1,29 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check using a prompt with color in CLI.
+
+# Using tuiterm requires setting TERM on host.
+require {!is_remote host}
+
+# We use a tuiterm, which allows us to determine cursor position.
+tuiterm_env
+Term::clean_restart 8 80
+
+# We start with an empty screen, to generate a visible prompt.
+Term::gen_prompt
+
+set tui 0
+source $srcdir/$subdir/../gdb.tui/color-prompt.exp.tcl
diff --git a/gdb/testsuite/gdb.base/command-line-input.exp b/gdb/testsuite/gdb.base/command-line-input.exp
index af228dc..9760f1a 100644
--- a/gdb/testsuite/gdb.base/command-line-input.exp
+++ b/gdb/testsuite/gdb.base/command-line-input.exp
@@ -18,19 +18,59 @@
# Test issuing a command split in multiple lines with continuation
# characters.
-gdb_exit
-gdb_start
+clean_restart
-set test "print 1\\\\n + 2"
-gdb_test_multiple "print 1\\\n + 2" $test {
- -re "^print 1\\\\\r\n \\+ 2\r\n\\\$$decimal = 3\r\n$gdb_prompt $" {
- pass $test
+set bs "\\"
+set re_bs [string_to_regexp $bs]
+set re_dollar [string_to_regexp $]
+
+set re \
+ [multi_line \
+ ^[string_to_regexp "print 1$bs"] \
+ [string_to_regexp " + 2"] \
+ "$re_dollar$decimal = 3" \
+ "$gdb_prompt $"]
+gdb_test_multiple "print 1$bs\n + 2" "print 1$bs${bs}n + 2" {
+ -re $re {
+ pass $gdb_test_name
+ }
+}
+
+set re \
+ [multi_line \
+ ^[string_to_regexp "print 1$bs"] \
+ "2" \
+ "$re_dollar$decimal = 12" \
+ "$gdb_prompt $"]
+gdb_test_multiple "print 1$bs\n2" "print 1$bs${bs}n2" {
+ -re $re {
+ pass $gdb_test_name
}
}
-set test "print 1\\\\n2"
-gdb_test_multiple "print 1\\\n2" $test {
- -re "^print 1\\\\\r\n2\r\n\\\$$decimal = 12\r\n$gdb_prompt $" {
- pass $test
+with_test_prefix "cancel multiline" {
+ send_gdb "print$bs\n 1"
+ gdb_test_multiple "" "setup" {
+ -re "print$re_bs\r\n 1" {
+ pass $gdb_test_name
+ }
+ }
+
+ send_gdb "\003"
+ gdb_test_multiple "" "cancel" {
+ -re -wrap "" {
+ pass $gdb_test_name
+ }
+ }
+
+ # Regression test for PR cli/33063.
+ gdb_test_multiple "print 2" "command after cancel" {
+ -re -wrap " = 2" {
+ pass $gdb_test_name
+ }
+ -re -wrap "" {
+ # Avoid undefined command error.
+ fail $gdb_test_name
+ }
}
}
diff --git a/gdb/testsuite/gdb.base/corefile-shmem-zero-id-lib.c b/gdb/testsuite/gdb.base/corefile-shmem-zero-id-lib.c
new file mode 100644
index 0000000..58fdec6
--- /dev/null
+++ b/gdb/testsuite/gdb.base/corefile-shmem-zero-id-lib.c
@@ -0,0 +1,522 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* This file contains a library that can be preloaded into GDB on Linux
+ using the LD_PRELOAD technique.
+
+ The library intercepts calls to OPEN, CLOSE, READ, and PREAD in order to
+ fake the inode number of a shared memory mapping.
+
+ When GDB creates a core file (e.g. with the 'gcore' command), then
+ shared memory mappings should be included in the generated core file.
+
+ The 'id' for the shared memory mapping shares the inode slot in the
+ /proc/PID/smaps file, which is what GDB consults to decide which
+ mappings should be included in the core file.
+
+ It is possible for a shared memory mapping to have an 'id' of zero.
+
+ At one point there was a bug in GDB where mappings with an inode of zero
+ would not be included in the generated core file. This meant that most
+ shared memory mappings would be included in the generated core file,
+ but, if a shared memory mapping happened to get an 'id' of zero, then,
+ because this would appear as a zero inode in the smaps file, this shared
+ memory mapping would be excluded from the generated core file.
+
+ This preload library spots when GDB opens a /proc/PID/smaps file and
+ immediately copies the contents of this file into an internal buffer.
+ The buffer is then scanned looking for a shared memory mapping, and, if
+ a shared memory mapping is found, its 'id' (in the inode position) is
+ changed to zero.
+
+ Calls to read/pread are intercepted, and attempts to read from the smaps
+ file are then served from the modified buffer contents.
+
+ The close calls are monitored and, when the smaps file is closed, the
+ internal buffer is released.
+
+ This works with GDB (currently) because the requirements for access to
+ the smaps file are pretty simple. GDB opens the file and grabs the
+ entire contents with a single pread call and a large buffer. There's no
+ seeking within the file or anything like that.
+
+ The intention is that this library is preloaded into a GDB session which
+ is then used to start an inferior and generate a core file. GDB will
+ then see the zero inode for the shared memory mapping and should, if the
+ bug is correctly fixed, still add the shared memory mapping to the
+ generated core file. */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdbool.h>
+#include <assert.h>
+
+/* Logging. */
+
+static void
+log_msg (const char *fmt, ...)
+{
+#ifdef LOGGING
+ va_list ap;
+
+ va_start (ap, fmt);
+ vfprintf (stderr, fmt, ap);
+ va_end (ap);
+#endif /* LOGGING */
+}
+
+/* Error handling, message and exit. */
+
+static void
+error (const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start (ap, fmt);
+ vfprintf (stderr, fmt, ap);
+ va_end (ap);
+
+ exit (EXIT_FAILURE);
+}
+
+/* The type of the open() function. */
+typedef int (*open_func_type)(const char *pathname, int flags, ...);
+
+/* The type of the close() function. */
+typedef int (*close_func_type)(int fd);
+
+/* The type of the read() function. */
+typedef ssize_t (*read_func_type)(int fd, void *buf, size_t count);
+
+/* The type of the pread() function. */
+typedef ssize_t (*pread_func_type) (int fd, void *buf, size_t count, off_t offset);
+
+/* Structure that holds information about a /proc/PID/smaps file that has
+ been opened. */
+struct interesting_file
+{
+ /* The file descriptor for the opened file. */
+ int fd;
+
+ /* The read offset within the file. Set to zero when the file is
+ opened. Any 'read' calls will update this offset. */
+ size_t offset;
+
+ /* The size of the contents within the buffer. This is not the total
+ buffer size (which might be larger). Attempts to read beyond SIZE
+ indicate an attempt to read beyond the end of the file. */
+ size_t size;
+
+ /* The (possibly modified) contents of the file. */
+ char *content;
+};
+
+/* We only track a single interesting file. Currently, for the use case
+ we imagine, GDB will only ever open one /proc/PID/smaps file at once. */
+struct interesting_file the_file = { -1, 0, 0, NULL };
+
+/* Update the contents of the global THE_FILE buffer. It is assumed that
+ the file contents have already been loaded into THE_FILE's content
+ buffer.
+
+ Look for any lines that represent a shared memory mapping and modify
+ the inode field (which holds the shared memory id) to be zero. */
+static void
+update_file_content_buffer (void)
+{
+ assert (the_file.content != NULL);
+
+ char *start = the_file.content;
+ do
+ {
+ /* Every line, even the last one, ends with a newline. */
+ char *end = strchrnul (start, '\n');
+ assert (end != NULL);
+ assert (*end != '\0');
+
+ /* Attribute lines start with an uppercase letter. The lines we want
+ to modify should start with a lower case hex character,
+ i.e. [0-9a-f]. Also, every line that we want to consider should
+ be long enough, but just in case, check the longest possible
+ filename that we care about. */
+ if (isxdigit (*start) && (isdigit (*start) || islower (*start))
+ && (end - start) > 23)
+ {
+ /* There are two possible filenames that we look for:
+ /SYSV%08x
+ /SYSV%08x (deleted)
+ The END pointer is pointing to the first character after the
+ filename.
+
+ Setup OFFSET to be the offset from END to the start of the
+ filename. As we check the filename we set OFFSET to 0 if the
+ filename doesn't match one of the expected patterns. */
+ size_t offset;
+ if (strncmp ((end - 13), "/SYSV", 5) == 0)
+ offset = 13;
+ else if (strncmp ((end - 23), "/SYSV", 5) == 0)
+ {
+ if (strncmp ((end - 10), " (deleted)", 10) == 0)
+ offset = 23;
+ else
+ offset = 0;
+ }
+ else
+ offset = 0;
+
+ for (int i = 0; i < 8 && offset != 0; ++i)
+ {
+ if (!isdigit (*(end - offset + 5 + i)))
+ offset = 0;
+ }
+
+ /* If OFFSET is non-zero then the filename on this line looks
+ like a shared memory mapping, and OFFSET is the offset from
+ END to the first character of the filename. */
+ if (offset != 0)
+ {
+ log_msg ("[LD_PRELOAD] shared memory entry: %.*s\n",
+ offset, (end - offset));
+
+ /* Set PTR to the first character before the filename. This
+ should be a white space character. */
+ char *ptr = end - offset - 1;
+ assert (isspace (*ptr));
+
+ /* Walk backwards until we find the inode field. */
+ while (isspace (*ptr))
+ --ptr;
+
+ /* Now replace every character in the inode field, except the
+ first one, with a space character. */
+ while (!isspace (*(ptr - 1)))
+ {
+ assert (isdigit (*ptr));
+ *ptr = ' ';
+ --ptr;
+ }
+
+ /* Replace the first character with '0'. */
+ assert (isdigit (*ptr));
+ *ptr = '0';
+
+ /* This print is checked for from GDB. */
+ printf ("[LD_PRELOAD] updated a shared memory mapping\n");
+ }
+ }
+
+ /* Update START to point to the next line. The last line of the
+ file will be empty. */
+ assert (*end == '\n');
+ start = end;
+ while (*start == '\n')
+ ++start;
+ }
+ while (*start != '\0');
+}
+
+/* Return true if PATHNAME has for form "/proc/PID/smaps" (without the
+ quotes). Otherwise, return false. */
+
+static bool
+is_smaps_file (const char *pathname)
+{
+ if (strncmp (pathname, "/proc/", 6) == 0)
+ {
+ int idx = 6;
+ while (isdigit (pathname[idx]))
+ idx++;
+ if (idx > 6 && strcmp (&pathname[idx], "/smaps") == 0)
+ return true;
+ }
+
+ return false;
+}
+
+/* Return true if PATHNAME should be considered interesting. PATHNAME is
+ interesting if it has the form /proc/PID/smaps, and there is no
+ interesting file already opened. */
+
+static bool
+is_interesting_pathname (const char *pathname)
+{
+ return the_file.fd == -1 && is_smaps_file (pathname);
+}
+
+/* Read the contents of an interesting file from FD (and open file
+ descriptor) into the global THE_FILE variable, making the file FD the
+ current interesting file. There should be no already open interesting
+ file when this function is called.
+
+ The contents of the file FD are read into a memory buffer and updated so
+ that any shared memory mappings listed within FD (which will be an smaps
+ file) will have the id zero. */
+
+static void
+read_interesting_file_contents (int fd)
+{
+#define BLOCK_SIZE 1024
+ /* Slurp contents into a local buffer. */
+ size_t buffer_size = 1024;
+ size_t offset = 0;
+
+ assert (the_file.size == 0);
+ assert (the_file.content == NULL);
+ assert (the_file.fd == -1);
+ assert (the_file.offset == 0);
+
+ do
+ {
+ the_file.content = (char *) realloc (the_file.content, buffer_size);
+ if (the_file.content == NULL)
+ error ("[LD_PRELOAD] Failed allocating memory: %s\n", strerror (errno));
+
+ ssize_t bytes_read = read (fd, the_file.content + offset, BLOCK_SIZE);
+ if (bytes_read == -1)
+ error ("[LD_PRELOAD] Failed reading file: %s\n", strerror (errno));
+
+ the_file.size += bytes_read;
+
+ if (bytes_read < BLOCK_SIZE)
+ break;
+
+ offset += BLOCK_SIZE;
+ buffer_size += BLOCK_SIZE;
+ }
+ while (true);
+
+ /* Add a null terminator. This makes the update easier. We know
+ there will be space because we only break out of the loop above
+ when the last read returns less than BLOCK_SIZE bytes. This means
+ we allocated an extra BLOCK_SIZE bytes, but didn't fill them all.
+ This means there must be at least 1 byte available for the null. */
+ the_file.content[the_file.size] = '\0';
+
+ /* Reset the seek pointer. */
+ if (lseek (fd, 0, SEEK_SET) == (off_t) -1)
+ error ("[LD_PRELOAD] Failed to lseek in file: %s\n", strerror (errno));
+
+ /* Record the file descriptor, this is used in read, pread, and close
+ in order to spot when we need to intercept the call. */
+ the_file.fd = fd;
+
+ update_file_content_buffer ();
+#undef BLOCK_SIZE
+}
+
+/* Intercept calls to 'open'. If this is an attempt to open a
+ /proc/PID/smaps file then intercept it, load the file contents into a
+ buffer and update the file contents. For all other open requests, just
+ forward to the real open function. */
+int
+open (const char *pathname, int flags, ...)
+{
+ /* Pointer to the real open function. */
+ static open_func_type real_open = NULL;
+
+ /* Mode is only used if the O_CREAT flag is set in FLAGS. */
+ mode_t mode = 0;
+
+ /* Set true if this is a /proc/PID/smaps file. */
+ bool is_interesting = is_interesting_pathname (pathname);
+
+ /* Check if O_CREAT is in flags. If it is, get the mode. */
+ if (flags & O_CREAT)
+ {
+ va_list args;
+ va_start (args, flags);
+ mode = va_arg (args, mode_t);
+ va_end (args);
+ }
+
+ /* Debug. */
+ if (is_interesting)
+ log_msg ("[LD_PRELOAD] Opening file: %s\n", pathname);
+
+ /* Make sure we have a pointer to the real open() function. */
+ if (real_open == NULL)
+ {
+ /* Get the address of the real open() function. */
+ real_open = (open_func_type) dlsym (RTLD_NEXT, "open");
+ if (real_open == NULL)
+ error ("[LD_PRELOAD] dlsym() error for 'open': %s\n", dlerror ());
+ }
+
+ /* Call the original open() function with the provided arguments. */
+ int res = -1;
+ if (flags & O_CREAT)
+ res = real_open (pathname, flags, mode);
+ else
+ res = real_open (pathname, flags);
+
+ if (res != -1 && is_interesting)
+ read_interesting_file_contents (res);
+
+ return res;
+}
+
+/* Like above, but for open64. */
+
+int
+open64 (const char *pathname, int flags, ...)
+{
+ /* Pointer to the real open64 function. */
+ static open_func_type real_open64 = NULL;
+
+ /* Mode is only used if the O_CREAT flag is set in FLAGS. */
+ mode_t mode = 0;
+
+ /* Set true if this is a /proc/PID/smaps file. */
+ bool is_interesting = is_interesting_pathname (pathname);
+
+ /* Check if O_CREAT is in flags. If it is, get the mode. */
+ if (flags & O_CREAT)
+ {
+ va_list args;
+ va_start (args, flags);
+ mode = va_arg (args, mode_t);
+ va_end (args);
+ }
+
+ /* Debug. */
+ if (is_interesting)
+ log_msg ("[LD_PRELOAD] Opening file: %s\n", pathname);
+
+ /* Make sure we have a pointer to the real open64() function. */
+ if (real_open64 == NULL)
+ {
+ /* Get the address of the real open64() function. */
+ real_open64 = (open_func_type) dlsym (RTLD_NEXT, "open64");
+ if (real_open64 == NULL)
+ error ("[LD_PRELOAD] dlsym() error for 'open64': %s\n", dlerror ());
+ }
+
+ /* Call the original open64() function with the provided arguments. */
+ int res = -1;
+ if (flags & O_CREAT)
+ res = real_open64 (pathname, flags, mode);
+ else
+ res = real_open64 (pathname, flags);
+
+ if (res != -1 && is_interesting)
+ read_interesting_file_contents (res);
+
+ return res;
+}
+
+/* Intercept the 'close' function. If this is a previously opened
+ interesting file then clean up. Otherwise, forward to the normal close
+ function. */
+int
+close (int fd)
+{
+ static close_func_type real_close = NULL;
+
+ if (fd == the_file.fd)
+ {
+ the_file.fd = -1;
+ free (the_file.content);
+ the_file.content = NULL;
+ the_file.offset = 0;
+ the_file.size = 0;
+ log_msg ("[LD_PRELOAD] Closing file.\n");
+ }
+
+ /* Make sure we have a pointer to the real open() function. */
+ if (real_close == NULL)
+ {
+ /* Get the address of the real open() function. */
+ real_close = (close_func_type) dlsym (RTLD_NEXT, "close");
+ if (real_close == NULL)
+ error ("[LD_PRELOAD] dlsym() error for 'close': %s\n", dlerror ());
+ }
+
+ return real_close (fd);
+}
+
+/* Intercept 'pread' calls. If this is a pread from a previously opened
+ interesting file, then read from the in memory buffer. Otherwise,
+ forward to the real pread function. */
+ssize_t
+pread (int fd, void *buf, size_t count, off_t offset)
+{
+ static pread_func_type real_pread = NULL;
+
+ if (fd == the_file.fd)
+ {
+ size_t max;
+
+ if (offset > the_file.size)
+ max = 0;
+ else
+ max = the_file.size - offset;
+ if (count > max)
+ count = max;
+
+ memcpy (buf, the_file.content + offset, count);
+ log_msg ("[LD_PRELOAD] Read from file.\n");
+ return count;
+ }
+
+ if (real_pread == NULL)
+ {
+ /* Get the address of the real read() function. */
+ real_pread = (pread_func_type) dlsym (RTLD_NEXT, "pread");
+ if (real_pread == NULL)
+ error ("[LD_PRELOAD] dlsym() error for 'pread': %s\n", dlerror ());
+ }
+
+ return real_pread (fd, buf, count, offset);
+}
+
+/* Intercept 'read' calls. If this is a read from a previously opened
+ interesting file, then read from the in memory buffer. Otherwise,
+ forward to the real read function. */
+ssize_t
+read (int fd, void *buf, size_t count)
+{
+ static read_func_type real_read = NULL;
+
+ if (fd == the_file.fd)
+ {
+ ssize_t bytes_read = pread (fd, buf, count, the_file.offset);
+ if (bytes_read > 0)
+ the_file.offset += bytes_read;
+ return bytes_read;
+ }
+
+ if (real_read == NULL)
+ {
+ /* Get the address of the real read() function. */
+ real_read = (read_func_type) dlsym (RTLD_NEXT, "read");
+ if (real_read == NULL)
+ error ("[LD_PRELOAD] dlsym() error for 'read': %s\n", dlerror ());
+ }
+
+ return real_read (fd, buf, count);
+}
diff --git a/gdb/testsuite/gdb.base/corefile-shmem-zero-id.c b/gdb/testsuite/gdb.base/corefile-shmem-zero-id.c
new file mode 100644
index 0000000..92d2edf
--- /dev/null
+++ b/gdb/testsuite/gdb.base/corefile-shmem-zero-id.c
@@ -0,0 +1,63 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <assert.h>
+#include <time.h>
+
+void
+breakpt (void)
+{
+ /* Nothing. */
+}
+
+int
+main (void)
+{
+ /* Create a shared memory mapping. */
+ int sid = shmget (IPC_PRIVATE, 0x1000, IPC_CREAT | IPC_EXCL | 0777);
+ if (sid == -1)
+ {
+ perror ("shmget");
+ exit (1);
+ }
+
+ /* Attach the shared memory mapping. */
+ void *addr = shmat (sid, NULL, SHM_RND);
+ if (addr == (void *) -1L)
+ {
+ perror ("shmat");
+ exit (1);
+ }
+
+ breakpt ();
+
+ /* Mark the shared memory mapping as deleted -- once the last user
+ has finished with it. */
+ if (shmctl (sid, IPC_RMID, NULL) != 0)
+ {
+ perror ("shmctl");
+ exit (1);
+ }
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/corefile-shmem-zero-id.exp b/gdb/testsuite/gdb.base/corefile-shmem-zero-id.exp
new file mode 100644
index 0000000..57c665e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/corefile-shmem-zero-id.exp
@@ -0,0 +1,228 @@
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This test script tries to check GDB's ability to create a core file
+# (e.g. with 'gcore' command) when there's a shared memory mapping
+# with the id zero.
+#
+# Testing this case is hard. Older kernels don't even seem to give
+# out the shared memory id zero. And on new kernels you still cannot
+# guarantee to grab the zero id for testing; the id might be in use by
+# some other process, or the kernel might just not give out that id
+# for some other reason.
+#
+# To figure out which mappings to include in the core file, GDB reads
+# the /proc/PID/smaps file. There is a field in this file which for
+# file backed mappings, holds the inode of the file. But for shared
+# memory mappings this field holds the shared memory id. The problem
+# was that GDB would ignore any entry in /proc/PID/smaps with an inode
+# entry of zero, which would catch the shared memory mapping with a
+# zero id.
+#
+# There was an attempt to write a test which spammed out requests for
+# shared memory mappings and tried to find the one with id zero, but
+# this was still really unreliable.
+#
+# This test takes a different approach. We compile a library which we
+# preload into the GDB process. This library intercepts calls to
+# open, close, read, and pread, and watches for an attempt to open the
+# /proc/PID/smaps file.
+#
+# When we see that file being opened, we copy the file contents into a
+# memory buffer and modify the buffer so that the inode field for any
+# shared memory mappings is set to zero. We then intercept calls to
+# read and pread and return results from that in memory buffer.
+#
+# The test executable itself create a shared memory mapping (which
+# might have any id).
+#
+# GDB, with the pre-load library in place, start the inferior and then
+# uses the 'gcore' command to dump a core file. When GDB opens the
+# smaps file and reads from it, the preload library ensures that GDB
+# sees an inode of zero.
+#
+
+# This test only works on Linux
+require isnative
+require {!is_remote host}
+require {!is_remote target}
+require {istarget *-linux*}
+require gcore_cmd_available
+
+standard_testfile .c -lib.c
+
+set libfile ${testfile}-lib
+set libobj [standard_output_file ${libfile}.so]
+
+# Compile the preload library. We only get away with this as we
+# limit this test to running when ISNATIVE is true.
+if { [build_executable "build preload lib" $libobj $srcfile2 \
+ {debug shlib libs=-ldl}] == -1 } {
+ return
+}
+
+# Now compile the inferior executable.
+if {[build_executable "build executable" $testfile $srcfile] == -1} {
+ return
+}
+
+# Spawn GDB with LIBOBJ preloaded using LD_PRELOAD.
+save_vars { env(LD_PRELOAD) env(ASAN_OPTIONS) } {
+ if { ![info exists env(LD_PRELOAD) ]
+ || $env(LD_PRELOAD) == "" } {
+ set env(LD_PRELOAD) "$libobj"
+ } else {
+ append env(LD_PRELOAD) ":$libobj"
+ }
+
+ # Prevent address sanitizer error:
+ # 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.
+ append_environment_default ASAN_OPTIONS verify_asan_link_order 0
+
+ clean_restart $binfile
+
+ # Start GDB with the modified environment, this means that, when
+ # using remote targets, gdbserver will also use the preload
+ # library.
+ if {![runto_main]} {
+ return
+ }
+}
+
+gdb_breakpoint breakpt
+gdb_continue_to_breakpoint "run to breakpt"
+
+# Check the /proc/PID/smaps file itself. The call to 'cat' should
+# inherit the preload library, so should see the modified file
+# contents. Check that the shared memory mapping line has an id of
+# zero. This confirms that the preload library is working. If the
+# preload library breaks then we'll start seeing non-zero shared
+# memory ids, which always worked, so we'd never know that this test
+# is broken!
+#
+# This check ensures the test is working as expected.
+set shmem_line_count 0
+set fixup_line_count 0
+set inf_pid [get_inferior_pid]
+gdb_test_multiple "shell cat /proc/${inf_pid}/smaps" "check smaps" {
+ -re "^\\\[LD_PRELOAD\\\] updated a shared memory mapping\r\n" {
+ incr fixup_line_count
+ exp_continue
+ }
+ -re "^\[^\r\n\]+($decimal)\\s+/SYSV\[0-9\]{8}(?: \\(deleted\\))?\r\n" {
+ set id $expect_out(1,string)
+ if { $id == 0 } {
+ incr shmem_line_count
+ }
+ exp_continue
+ }
+ -re "^$gdb_prompt $" {
+ with_test_prefix $gdb_test_name {
+ gdb_assert { $shmem_line_count == 1 } \
+ "single shared memory mapping found"
+ gdb_assert { $fixup_line_count == 1 } \
+ "single fixup line found"
+ }
+ }
+ -re "^\[^\r\n\]+\r\n" {
+ exp_continue
+ }
+}
+
+# Now generate a core file. This will use the preload library to read
+# the smaps file. The code below is copied from 'proc gdb_gcore_cmd',
+# but we don't use that as we also look for a message that is printed
+# by the LD_PRELOAD library. This is an extra level of check that the
+# preload library is triggering when needed.
+set corefile [standard_output_file ${testfile}.core]
+set saw_ld_preload_msg false
+set saw_saved_msg false
+with_timeout_factor 3 {
+ gdb_test_multiple "gcore $corefile" "save core file" {
+ -re "^\\\[LD_PRELOAD\\\] updated a shared memory mapping\r\n" {
+ # GDB actually reads the smaps file multiple times when
+ # creating a core file, so we'll see multiple of these
+ # fixup lines.
+ set saw_ld_preload_msg true
+ exp_continue
+ }
+ -re "^Saved corefile \[^\r\n\]+\r\n" {
+ set saw_saved_msg true
+ exp_continue
+ }
+ -re "^$gdb_prompt $" {
+ with_test_prefix $gdb_test_name {
+ gdb_assert { $saw_saved_msg } \
+ "saw 'Saved corefile' message"
+
+ # If we're using a remote target then the message from
+ # the preload library will go to gdbservers stdout,
+ # not GDB's, so don't check for it.
+ if { [gdb_protocol_is_native] } {
+ gdb_assert { $saw_ld_preload_msg } \
+ "saw LD_PRELOAD message from library"
+ }
+ }
+ }
+ -re "^\[^\r\n\]*\r\n" {
+ exp_continue
+ }
+ }
+}
+
+# Restart GDB. This time we are _not_ using the preload library. We
+# no longer need it as we are only analysing the core file now.
+clean_restart $binfile
+
+# Load the core file.
+gdb_test "core-file $corefile" \
+ "Program terminated with signal SIGTRAP, Trace/breakpoint trap\\..*" \
+ "load core file"
+
+# Look through the mappings. We _should_ see the shared memory
+# mapping. We _should_not_ see any of the special '[blah]' style
+# mappings, e.g. [vdso], [vstack], [vsyscalls], etc.
+set saw_special_mapping false
+set saw_shmem_mapping false
+gdb_test_multiple "info proc mappings" "" {
+ -re "\r\nStart Addr\[^\r\n\]+File\\s*\r\n" {
+ exp_continue
+ }
+
+ -re "^$hex\\s+$hex\\s+$hex\\s+$hex\\s+\\\[\\S+\\\]\\s*\r\n" {
+ set saw_special_mapping true
+ exp_continue
+ }
+
+ -re "^$hex\\s+$hex\\s+$hex\\s+$hex\\s+/SYSV\[0-9\]+ \\(deleted\\)\\s*\r\n" {
+ set saw_shmem_mapping true
+ exp_continue
+ }
+
+ -re "^$hex\\s+$hex\\s+$hex\\s+$hex\[^\r\n\]*\r\n" {
+ exp_continue
+ }
+
+ -re "^$gdb_prompt $" {
+ with_test_prefix $gdb_test_name {
+ gdb_assert { $saw_shmem_mapping } \
+ "check shared memory mapping exists"
+ gdb_assert { !$saw_special_mapping } \
+ "check no special mappings added"
+ }
+ }
+}
diff --git a/gdb/testsuite/gdb.base/corefile.exp b/gdb/testsuite/gdb.base/corefile.exp
index da1fdf3..fd8d1d1 100644
--- a/gdb/testsuite/gdb.base/corefile.exp
+++ b/gdb/testsuite/gdb.base/corefile.exp
@@ -31,6 +31,7 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
# mmapped data in core file" test.
set corefile [core_find $binfile {}]
if {$corefile == ""} {
+ untested "unable to create or find corefile"
return 0
}
diff --git a/gdb/testsuite/gdb.base/corefile2.exp b/gdb/testsuite/gdb.base/corefile2.exp
index 392705b..d35ba1a 100644
--- a/gdb/testsuite/gdb.base/corefile2.exp
+++ b/gdb/testsuite/gdb.base/corefile2.exp
@@ -40,6 +40,7 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
set corefile [core_find $binfile {}]
if {$corefile == ""} {
+ untested "unable to create or find corefile"
return 0
}
diff --git a/gdb/testsuite/gdb.base/corefile3.exp b/gdb/testsuite/gdb.base/corefile3.exp
index 57b2300..ef391d1 100644
--- a/gdb/testsuite/gdb.base/corefile3.exp
+++ b/gdb/testsuite/gdb.base/corefile3.exp
@@ -34,6 +34,7 @@ if {[build_executable $testfile.exp $testfile $srcfile] == -1} {
set corefile [core_find $binfile {}]
if {$corefile == ""} {
+ untested "unable to create or find corefile"
return
}
diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
index 3abd049..b5e64c2 100644
--- a/gdb/testsuite/gdb.base/default.exp
+++ b/gdb/testsuite/gdb.base/default.exp
@@ -253,10 +253,39 @@ gdb_test "h" "List of classes of commands:(\[^\r\n\]*\[\r\n\])+aliases -- User-d
gdb_test "help" "List of classes of commands:(\[^\r\n\]*\[\r\n\])+aliases -- User-defined aliases of other commands(\[^\r\n\]*\[\r\n\])+breakpoints -- Making program stop at certain points(\[^\r\n\]*\[\r\n\])+data -- Examining data(\[^\r\n\]*\[\r\n\])+files -- Specifying and examining files(\[^\r\n\]*\[\r\n\])+obscure -- Obscure features(\[^\r\n\]*\[\r\n\])+running -- Running the program(\[^\r\n\]*\[\r\n\])+stack -- Examining the stack(\[^\r\n\]*\[\r\n\])+status -- Status inquiries(\[^\r\n\]*\[\r\n\])+support -- Support facilities(\[^\r\n\]*\[\r\n\])+user-defined -- User-defined commands(\[^\r\n\]*\[\r\n\])+Type \"help\" followed by a class name for a list of commands in that class.(\[^\r\n\]*\[\r\n\])+Type \"help\" followed by command name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous."
#test handle
gdb_test "handle" "Argument required .signal to handle.*"
-#test info "i" abbreviation
-gdb_test "i" "List of \"info\" subcommands:(\[^\r\n\]*\[\r\n\])+Type \"help info\" followed by subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous." "info \"i\" abbreviation"
+
+proc test_info_command { command message } {
+ set saw_info_header 0
+ set saw_help_info 0
+ set saw_command_abbrev 0
+ gdb_test_multiple $command $message -lbl {
+ -re "\r\nList of \"info\" subcommands:" {
+ verbose "Info header displayed"
+ set saw_info_header 1
+ exp_continue
+ }
+ -re "Type \"help info\" followed by subcommand name for full documentation\\." {
+ verbose "Help info displayed"
+ set saw_help_info 1
+ exp_continue
+ }
+ -re "\r\nCommand name abbreviations are allowed if unambiguous\\." {
+ verbose "Command name abbreviations displayed"
+ set saw_command_abbrev 1
+ exp_continue
+ }
+ -re -wrap "" {
+ gdb_assert { $saw_info_header && $saw_help_info
+ && $saw_command_abbrev } $gdb_test_name
+ }
+ }
+}
+
+#test info "i" abbreviation
+test_info_command "i" "info \"i\" abbreviation"
#test info
-gdb_test "info" "List of \"info\" subcommands:(\[^\r\n\]*\[\r\n\])+Type \"help info\" followed by subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous."
+test_info_command "info" "info"
+
#test ignore
gdb_test "ignore" "Argument required .a breakpoint number.*"
#test info address
@@ -379,38 +408,52 @@ gdb_test "info registers" "The program has no registers now."
gdb_test "info s" "No stack." "info stack \"s\" abbreviation"
#test info stack
gdb_test "info stack" "No stack."
-#test info set
-# Test improved to check three parts:
-# 1) confirm
-# 2) prompt
-# 3) write
-# And only succeed if all three are matched.
-# This should fix an old problem on native solaris 2.8,
-# where this test fails due to this line:
+
+#test "info set" and "show" commands
+# The test needs to match the "prompt: ..." part to fix an old problem on native
+# Solaris 2.8, where this test fails due to this line:
# prompt: Gdb's prompt is "(gdb) ".^M
-set set_confirm_seen 0
-set set_prompt_seen 0
-gdb_test_multiple "info set" "info set" {
- -re "confirm: Whether to confirm potentially dangerous operations is o\[a-z\]*.(\[^\r\n\]*\[\r\n\])+history filename: The filename in which to record the command history is (\[^\r\n\]*\[\r\n\])+listsize: Number of source lines gdb will list by default is 10" {
- verbose "Confirm dislayed"
- set set_confirm_seen 1
- exp_continue
- }
- -re "Gdb's prompt is \"$gdb_prompt \"" {
- verbose "GDB prompt displayed"
- set set_prompt_seen 1
- exp_continue
- }
- -re "Writing into executable.*$gdb_prompt $" {
- verbose "write displayed"
- if { $set_prompt_seen && $set_confirm_seen } {
- pass "info set"
- } else {
- verbose "prompt $set_prompt_seen confirm $set_confirm_seen"
- fail "info set (incomplete output)"
+proc test_info_set_show { command } {
+ set set_confirm_seen 0
+ set set_history_filename_seen 0
+ set set_listsize_seen 0
+ set set_prompt_seen 0
+ set set_write_seen 0
+ gdb_test_multiple $command $command -lbl {
+ -re "\r\nconfirm: Whether to confirm potentially dangerous operations is o\[a-z\]+\\." {
+ verbose "Confirm displayed"
+ set set_confirm_seen 1
+ exp_continue
+ }
+ -re "\r\nhistory filename: The filename in which to record the command history is \[^\r\n\]+\\." {
+ verbose "History filename displayed"
+ set set_history_filename_seen 1
+ exp_continue
+ }
+ -re "\r\nlistsize: Number of source lines gdb will list by default is 10\\." {
+ verbose "Listsize displayed"
+ set set_listsize_seen 1
+ exp_continue
+ }
+ -re "\r\nprompt: Gdb's prompt is \"$::gdb_prompt \"" {
+ verbose "GDB prompt displayed"
+ set set_prompt_seen 1
+ exp_continue
+ }
+ -re "write: Writing into executable and core files is o\[a-z\]+\\." {
+ verbose "Write displayed"
+ set set_write_seen 1
+ exp_continue
+ }
+ -re -wrap "" {
+ gdb_assert { $set_confirm_seen && $set_history_filename_seen
+ && $set_listsize_seen && $set_prompt_seen
+ && $set_write_seen } $gdb_test_name
}
}
}
+test_info_set_show "info set"
+
gdb_test "info symbol" "Argument required .address.."
#test info source
gdb_test "info source" "No current source file..*"
@@ -591,12 +634,41 @@ gdb_test "set history" "List of \"set history\" subcommands:(\[^\r\n\]*\[\r\n\])
gdb_test "set language" "Requires an argument. Valid arguments are auto, local, unknown, ada, asm, c, c.., d, fortran, go, minimal, modula-2, objective-c, opencl, pascal, rust."
#test set listsize
gdb_test "set listsize" "Argument required .integer to set it to.*"
+
+proc test_set_print { command message } {
+ set saw_info_header 0
+ set saw_help_info 0
+ set saw_command_abbrev 0
+ gdb_test_multiple $command $message -lbl {
+ -re "\r\nList of \"set print\" subcommands:" {
+ verbose "Info header displayed"
+ set saw_info_header 1
+ exp_continue
+ }
+ -re "Type \"help set print\" followed by subcommand name for full documentation\\." {
+ verbose "Help info displayed"
+ set saw_help_info 1
+ exp_continue
+ }
+ -re "\r\nCommand name abbreviations are allowed if unambiguous\\." {
+ verbose "Command name abbreviations displayed"
+ set saw_command_abbrev 1
+ exp_continue
+ }
+ -re -wrap "" {
+ gdb_assert { $saw_info_header && $saw_help_info
+ && $saw_command_abbrev } $gdb_test_name
+ }
+ }
+}
+
#test set print "p" abbreviation
-gdb_test "set p" "List of \"set print\" subcommands:(\[^\r\n\]*\[\r\n\])+Type \"help set print\" followed by subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous." "set print \"p\" abbreviation"
+test_set_print "set p" "set print \"p\" abbreviation"
#test set print "pr" abbreviation
-gdb_test "set pr" "List of \"set print\" subcommands:(\[^\r\n\]*\[\r\n\])+Type \"help set print\" followed by subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous." "set print \"pr\" abbreviation"
+test_set_print "set pr" "set print \"pr\" abbreviation"
#test set print
-gdb_test "set print" "List of \"set print\" subcommands:(\[^\r\n\]*\[\r\n\])+Type \"help set print\" followed by subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous."
+test_set_print "set print" "set print"
+
#test set print address
gdb_test_no_output "set print address" "set print address"
#test set print array
@@ -687,7 +759,6 @@ set show_conv_list \
{$_probe_arg10 = <error: No frame selected>} \
{$_probe_arg11 = <error: No frame selected>} \
{$_cimag = <internal function _cimag>} \
- {$_colorsupport = "monochrome"} \
{$_creal = <internal function _creal>} \
{$_isvoid = <internal function _isvoid>} \
{$_shell = <internal function _shell>} \
@@ -695,12 +766,10 @@ set show_conv_list \
{$_gdb_maint_setting = <internal function _gdb_maint_setting>} \
{$_gdb_setting_str = <internal function _gdb_setting_str>} \
{$_gdb_setting = <internal function _gdb_setting>} \
- {$_gdb_major = 17} \
- {$_gdb_minor = 1} \
{$_shell_exitsignal = void} \
{$_shell_exitcode = 0} \
- {$_active_linker_namespaces = 1} \
- {$_current_linker_namespace = <error: No registers.>}\
+ {$_linker_namespace_count = 0} \
+ {$_linker_namespace = <error: No registers.>}\
}
if [allow_python_tests] {
append show_conv_list \
@@ -716,10 +785,52 @@ if [allow_python_tests] {
{$_any_caller_matches = <internal function _any_caller_matches>} \
}
}
-gdb_test_list_exact "show convenience" "show convenience" \
- "\[^\r\n\]+\[\r\n\]+" \
- "\[^\r\n\]+" \
- $show_conv_list
+
+set lines [gdb_get_lines_no_pass "show convenience"]
+set matches 0
+set all_found 1
+foreach s $show_conv_list {
+ if { ![regexp (^|\r\n)[string_to_regexp $s](\r\n|$) $lines] } {
+ verbose -log "didn't match: '$s'"
+ set all_found 0
+ break
+ }
+ incr matches
+}
+
+set re_var [string_to_regexp {$_colorsupport}]
+if { [is_remote host] } {
+ set re_val {[^\r\n]+}
+} else {
+ set re_val [string_to_regexp {"monochrome"}]
+}
+if { [regexp "$re_var = $re_val" $lines] } {
+ incr matches
+} else {
+ set all_found 0
+}
+
+set re_vars \
+ [list \
+ [string_to_regexp {$_gdb_major}] \
+ [string_to_regexp {$_gdb_minor}]]
+foreach re_var $re_vars {
+ if { [regexp "$re_var = $decimal" $lines] } {
+ incr matches
+ } else {
+ set all_found 0
+ }
+}
+
+if { [regexp [string_to_regexp {$_tlb = void}] $lines] } {
+ incr matches
+} else {
+ # Convenience variable _tlb is added only if support for windows targets
+ # is enabled. Don't complain if it's missing.
+}
+
+gdb_assert { $all_found && $matches == [count_newlines $lines] } \
+ "show convenience"
#test show directories
gdb_test "show directories" "Source directories searched: .cdir\[:;\].cwd"
@@ -741,12 +852,47 @@ gdb_test "show history" "history expansion: *History expansion on command input
gdb_test "show language" "The current source language is \"auto; currently c\"."
#test show listsize
gdb_test "show listsize" "Number of source lines gdb will list by default is 10."
+
+proc test_show_print { command } {
+ set saw_print_address 0
+ set saw_print_frame_args 0
+ set saw_print_symbol 0
+ set saw_print_vtbl 0
+ gdb_test_multiple $command $command -lbl {
+ -re "\r\nprint address: Printing of addresses is o\[a-z\]+\\." {
+ verbose "Print address displayed"
+ set saw_print_address 1
+ exp_continue
+ }
+ -re "\r\nprint frame-arguments: Printing of non-scalar frame arguments is \[^\r\n\]+\\." {
+ verbose "Print frame-arguments displayed"
+ set saw_print_frame_args 1
+ exp_continue
+ }
+ -re "\r\nprint symbol: Printing of symbols when printing pointers is o\[a-z\]+\\." {
+ verbose "Print symbol displayed"
+ set saw_print_symbol 1
+ exp_continue
+ }
+ -re "\r\nprint vtbl: Printing of C\\+\\+ virtual function tables is o\[a-z\]+\\." {
+ verbose "Print vtbl displayed"
+ set saw_print_vtbl 1
+ exp_continue
+ }
+ -re -wrap "" {
+ gdb_assert { $saw_print_address && $saw_print_frame_args
+ && $saw_print_symbol && $saw_print_vtbl } $gdb_test_name
+ }
+ }
+}
+
#test show print "p" abbreviation
-gdb_test "show p" ".*"
+test_show_print "show p"
#test show print "pr" abbreviation
-gdb_test "show pr" ".*"
+test_show_print "show pr"
#test show print
-gdb_test "show print" ".*"
+test_show_print "show print"
+
#test show paths
gdb_test "show paths" "Executable and object file path:.*"
#test show print address
@@ -792,30 +938,10 @@ gdb_test "show width" "Number of characters gdb thinks are in a line is.*"
#test show write
# This is only supported on targets which use exec.o.
gdb_test "show write" "Writing into executable and core files is o.*"
+
#test show
-set show_confirm_seen 0
-set show_prompt_seen 0
-gdb_test_multiple "show" "show" {
- -re "confirm: *Whether to confirm potentially dangerous operations is on.(\[^\r\n\]*\[\r\n\])+history filename: *The filename in which to record the command history is (\[^\r\n\]*\[\r\n\])+history save: *Saving of the history record on exit is on.(\[^\r\n\]*\[\r\n\])+history size: *The size of the command history is(\[^\r\n\]*\[\r\n\])+listsize: *Number of source lines gdb will list by default is 10(\[^\r\n]*\[\r\n\])+print elements: *Limit on string chars or array elements to print is 200." {
- verbose "Confirm displayed"
- set show_confirm_seen 1
- exp_continue
- }
- -re "Gdb's prompt is \"$gdb_prompt \"" {
- verbose "GDB prompt displayed"
- set show_prompt_seen 1
- exp_continue
- }
- -re "Writing into executable.*$gdb_prompt $" {
- verbose "write displayed"
- if { $show_prompt_seen && $show_confirm_seen } {
- pass "show"
- } else {
- verbose "prompt $show_prompt_seen confirm $show_confirm_seen"
- fail "show (incomplete output)"
- }
- }
-}
+test_info_set_show "show"
+
#history saving should stay disabled
gdb_test_no_output "set history save off" "set history save off"
#test stepi "si" abbreviation
diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
index 8f52199..bfce900 100644
--- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
+++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
@@ -38,16 +38,80 @@ if { [build_executable "failed to build" $testfile $srcfile \
return
}
+# Return a list of shared libraries extract from the "info sharedlibrary"
+# command. Each item in the list is itself a list with the following items:
+#
+# - "from" address
+# - "to" address
+# - namespace ID
+# - name (file path)
+
+proc get_info_shared {} {
+ set from_re "($::hex)\\s+"
+ set to_re "($::hex)\\s+"
+ set ns_re "(?:($::decimal)\\s+)?"
+ set syms_read_re "(Yes( \\(\\*\\))?|No)\\s+"
+ set name_re "(\[^\r\n\]+)"
+ set libs {}
+
+ gdb_test_multiple "info sharedlibrary" "" {
+ -re {From\s+To\s+(Linker NS\s+)?Syms Read\s+Shared Object Library\r\n} {
+ exp_continue
+ }
+
+ -re "^${from_re}${to_re}${ns_re}${syms_read_re}${name_re}\r\n" {
+ set from $expect_out(1,string)
+ set to $expect_out(2,string)
+ set ns $expect_out(3,string)
+ set name $expect_out(4,string)
+
+ lappend libs [list $from $to $ns $name]
+ exp_continue
+ }
+
+ -re {^\(\*\): Shared library is missing debugging information\.\r\n} {
+ exp_continue
+ }
+
+ -re "^$::gdb_prompt " {
+ pass $gdb_test_name
+ }
+ }
+
+ return $libs
+}
+
+# Verify that "info sharedlibrary" does not contain duplicate entries.
+
+proc check_no_duplicates {} {
+ with_test_prefix "check no duplicates" {
+ set libs [get_info_shared]
+ array set seen {}
+ set seen_duplicate 0
+
+ foreach lib $libs {
+ if {[info exists seen($lib)]} {
+ verbose -log "already seen: $lib"
+ set seen_duplicate 1
+ }
+
+ set seen($lib) 1
+ }
+
+ gdb_assert {!$seen_duplicate} "no duplicates"
+ }
+}
+
# Run the command "info sharedlibrary" and get the first namespace
# for the so
proc get_first_so_ns {} {
set ns -1
set lib_regexp [string_to_regexp ${::binfile_lib}]
gdb_test_multiple "info sharedlibrary $::so_name" "get SO namespace" -lbl {
- -re "\r\nFrom\\s+To\\s+\(NS\\s+\)?Syms\\s+Read\\s+Shared Object Library(?=\r\n)" {
+ -re "\r\nFrom\\s+To\\s+\(Linker NS\\s+\)?Syms\\s+Read\\s+Shared Object Library(?=\r\n)" {
exp_continue
}
- -re "\r\n$::hex\\s+$::hex\\s+\\\[\\\[($::decimal)\\\]\\\]\\s+\[^\r\n]+${lib_regexp}(?=\r\n)" {
+ -re "\r\n$::hex\\s+$::hex\\s+($::decimal)\\s+\[^\r\n]+${lib_regexp}(?=\r\n)" {
if {$ns == -1} {
set ns $expect_out(1,string)
}
@@ -78,9 +142,11 @@ proc test_info_shared {} {
# Next, test that we *do* print a namespace column after loading SOs.
gdb_test "info sharedlibrary" \
- "From\\s+To\\s+NS\\s+Syms\\s+Read\\s+Shared Object Library.*" \
+ "From\\s+To\\s+Linker NS\\s+Syms\\s+Read\\s+Shared Object Library.*" \
"after loading everything"
+ check_no_duplicates
+
gdb_assert {[get_first_so_ns] == 1} "before closing any library"
gdb_test "next" ".*second dlclose.*" "close first library"
@@ -107,21 +173,23 @@ proc test_info_shared {} {
# Run all tests related to the linkage namespaces convenience
# variables, _active_namespaces and _current_namespaces.
+# Also tests that the namespace ID is only printed at the correct
+# times.
proc_with_prefix test_conv_vars {} {
clean_restart $::binfile
- gdb_test "print \$_active_linker_namespaces" "1" \
- "1 namespace before starting inferior"
- gdb_test "print \$_current_linker_namespace" "No registers." \
+ gdb_test "print \$_linker_namespace_count" "0" \
+ "0 namespace before starting inferior"
+ gdb_test "print \$_linker_namespace" "No registers." \
"No current namespace before starting inferior"
if { ![runto_main] } {
return
}
- gdb_test "print \$_active_linker_namespaces" "1" \
+ gdb_test "print \$_linker_namespace_count" "1" \
"Before activating namespaces"
- gdb_test "print \$_current_linker_namespace" ".*\"\\\[\\\[0\\\]\\\]\"" \
+ gdb_test "print \$_linker_namespace" ".* = 0" \
"Still in the default namespace"
gdb_breakpoint "inc" allow-pending
@@ -130,17 +198,23 @@ proc_with_prefix test_conv_vars {} {
foreach_with_prefix dl {3 2 1} {
gdb_continue_to_breakpoint "inc"
- gdb_test "print \$_current_linker_namespace" ".*\"\\\[\\\[$dl\\\]\\\]\"" \
+ gdb_test "print \$_linker_namespace" ".* = $dl" \
"Verify we're in namespace $dl"
}
+ # Check that we display the namespace of the selected
+ # frame, not the lowermost one.
+ gdb_test "up" "\#1.*in main.*"
+ gdb_test "print \$_linker_namespace" ".* = 0" \
+ "print namespace of selected frame"
+
gdb_continue_to_breakpoint "first dlclose"
- gdb_test "print \$_active_linker_namespaces" "4" "all SOs loaded"
+ gdb_test "print \$_linker_namespace_count" "4" "all SOs loaded"
gdb_test "next" ".*second dlclose.*" "close one SO"
- gdb_test "print \$_active_linker_namespaces" "3" "one SOs unloaded"
+ gdb_test "print \$_linker_namespace_count" "3" "one SOs unloaded"
gdb_test "next" ".*third dlclose.*" "close another SO"
- gdb_test "print \$_active_linker_namespaces" "2" "two SOs unloaded"
+ gdb_test "print \$_linker_namespace_count" "2" "two SOs unloaded"
# Restarting GDB so that we can test setting a breakpoint
# using the convenience variable, while a proper bp syntax
@@ -154,7 +228,7 @@ proc_with_prefix test_conv_vars {} {
# breakpoints and pending breakpoints at the same time with
# gdb_breakpoint.
gdb_test "next" ".*assert.*" "load the first SO"
- gdb_breakpoint "inc if \$_streq(\$_current_linker_namespace, \"\[\[2\]\]\")"
+ gdb_breakpoint "inc if \$_linker_namespace == 2"
gdb_continue_to_breakpoint "inc"
gdb_continue_to_end "" continue 1
}
@@ -163,6 +237,12 @@ proc_with_prefix test_conv_vars {} {
proc test_info_linker_namespaces {} {
clean_restart $::binfile
+ # Check that "info linker-namespaces" while the inferior is not running
+ # doesn't crash.
+ gdb_test "info linker-namespaces" \
+ "Current inferior does not support linker namespaces\\. Use \"info sharedlibrary\" instead\\." \
+ "info linker-namespaces before running"
+
if { ![runto_main] } {
return
}
@@ -174,50 +254,44 @@ proc test_info_linker_namespaces {} {
# First, test printing a single namespace, and ensure all of
# them are correct, using both syntaxes.
- set found_all_libs false
- gdb_test_multiple "info linker-namespaces \[\[0\]\]" "print namespace 0" -lbl {
- -re "^\r\nThere are ($::decimal) libraries loaded in linker namespace \\\[\\\[0\\\]\\\]" {
- # Some systems may add libc and libm to every loaded namespace,
- # others may load only one or neither, because the SO doesn't
- # actually use either library. The best we can do is check if
- # we found the dynamic linker, and up to 2 more libraries.
- set libs $expect_out(1,string)
- set found_all_libs [expr $libs - 1 <= 2]
- exp_continue
- }
- -re "^\r\n$::gdb_prompt $" {
- gdb_assert $found_all_libs "the correct number of libraries was reported"
- }
- -re "(^\r\n)?\[^\r\n\]+(?=\r\n)" {
- exp_continue
+ set n_libraries 999
+
+ gdb_test_multiple "info linker-namespaces \[\[0\]\]" "print namespace 0" {
+ -re -wrap "($::decimal) librar(?:y|ies) loaded in linker namespace 0:.*" {
+ set n_libraries $expect_out(1,string)
}
}
+
+ # Some systems may add libc and libm to every loaded namespace,
+ # others may load only one or neither, because the SO doesn't
+ # actually use either library. The best we can do is check if
+ # we found the dynamic linker, and up to 2 more libraries.
+ gdb_assert {$n_libraries <= 3} "the correct number of libraries was reported"
+
+ set binfile_lib_re [string_to_regexp $::binfile_lib]
+
foreach_with_prefix ns {1 2 3} {
set found_test_so false
- set found_all_libs false
- gdb_test_multiple "info linker-namespaces $ns" "print namespace $ns" -lbl {
- -re "^\r\nThere are ($::decimal) libraries loaded in linker namespace \\\[\\\[$ns\\\]\\\]" {
- set libs $expect_out(1,string)
- # Some systems may add libc and libm to every loaded namespace,
- # others may load only one or neither, because the SO doesn't
- # actually use either library. The best we can do is check if
- # we found the dynamic linker, the test SO, and maybe up to 2
- # more libraries.
- set found_all_libs [expr $libs - 2 <= 2]
+ set n_libraries 999
+
+ gdb_test_multiple "info linker-namespaces $ns" "print namespace $ns" {
+ -re ".*($::decimal) librar(?:y|ies) loaded in linker namespace $ns:\r\n" {
+ set n_libraries $expect_out(1,string)
exp_continue
}
- -re "^\r\n\[^\r\n\]+${::binfile_lib}\[^\r\n\]*(?=\r\n)" {
+
+ -re -wrap "${binfile_lib_re}.*" {
set found_test_so true
- exp_continue
- }
- -re "^\r\n$::gdb_prompt $" {
- gdb_assert $found_test_so "this testfle's SO was reported"
- gdb_assert $found_all_libs "the correct number of libraries was reported"
- }
- -re "(^\r\n)?\[^\r\n\]+(?=\r\n)" {
- exp_continue
}
}
+
+ # Some systems may add libc and libm to every loaded namespace,
+ # others may load only one or neither, because the SO doesn't
+ # actually use either library. The best we can do is check if
+ # we found the dynamic linker, the test SO, and maybe up to 2
+ # more libraries.
+ gdb_assert {$n_libraries <= 4} "the correct number of libraries was reported"
+ gdb_assert {$found_test_so} "this testfile's SO was reported"
}
# These patterns are simpler, and purposefully glob multiple lines.
@@ -225,14 +299,15 @@ proc test_info_linker_namespaces {} {
# without worrying about the libraries printed, since that was tested
# above.
gdb_test "info linker-namespaces" \
- [multi_line "There are 4 linker namespaces loaded" \
- "There are $::decimal libraries loaded in linker namespace ..0.." \
+ [multi_line "There are 4 linker namespaces loaded\\." \
+ "" \
+ "$::decimal librar(y|ies) loaded in linker namespace 0:" \
".*" \
- "There are $::decimal libraries loaded in linker namespace ..1.." \
+ "$::decimal librar(y|ies) loaded in linker namespace 1:" \
".*" \
- "There are $::decimal libraries loaded in linker namespace ..2.." \
+ "$::decimal librar(y|ies) loaded in linker namespace 2:" \
".*" \
- "There are $::decimal libraries loaded in linker namespace ..3.." \
+ "$::decimal librar(y|ies) loaded in linker namespace 3:" \
".*" ] "print namespaces with no argument"
}
diff --git a/gdb/testsuite/gdb.base/dlmopen.exp b/gdb/testsuite/gdb.base/dlmopen.exp
index da17002..54fb4c4 100644
--- a/gdb/testsuite/gdb.base/dlmopen.exp
+++ b/gdb/testsuite/gdb.base/dlmopen.exp
@@ -95,9 +95,19 @@ if { $dyln_name eq "" } {
return
}
+# If the dynamic linker path contains a symlink, some instances show the real
+# path instead of the original path. Accept both.
+lassign [remote_exec target realpath "$dyln_name"] realpath_ret dyln_realpath_name
+
+if { $realpath_ret == 0 } {
+ set dyln_realpath_name [string trim $dyln_realpath_name]
+} else {
+ set dyln_realpath_name "not-a-valid-path"
+}
+
# Return true if FILENAME is the dynamic linker. Otherwise return false.
proc is_dyln { filename } {
- return [expr {$filename eq $::dyln_name}]
+ return [expr {$filename eq $::dyln_name || $filename eq $::dyln_realpath_name}]
}
# Check that 'info shared' show NUM occurrences of DSO.
@@ -106,7 +116,7 @@ proc check_dso_count { dso num } {
set count 0
gdb_test_multiple "info shared" "info shared" {
- -re "$hex $hex \(\[\[$::decimal\]\]\\s+\)\?Yes \[^\r\n\]*$dso\r\n" {
+ -re "$hex $hex \($::decimal\\s+\)\?Yes \[^\r\n\]*$dso\r\n" {
# use longer form so debug remote does not interfere
set count [expr $count + 1]
exp_continue
@@ -233,7 +243,7 @@ proc get_dyld_info {} {
set dyld_count 0
set dyld_start_addr ""
gdb_test_multiple "info sharedlibrary" "" {
- -re "From\\s+To\\s+\(NS\\s+\)?Syms\\s+Read\\s+Shared Object Library\r\n" {
+ -re "From\\s+To\\s+\(Linker NS\\s+\)?Syms\\s+Read\\s+Shared Object Library\r\n" {
exp_continue
}
-re "^($::hex)\\s+$::hex\\s+\(\#$::decimal\\s+\)?\[^/\]+(/\[^\r\n\]+)\r\n" {
@@ -358,15 +368,19 @@ proc_with_prefix test_solib_unmap_events { } {
# dynamic linker as pending when some instances of the library were
# unloaded, despite there really only being one copy of the dynamic
# linker actually loaded into the inferior's address space.
- gdb_test_multiple "info breakpoints $bpnum" "check b/p status" {
- -re -wrap "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+\\*$::hex\\s*\r\n\\s+stop only if \\(0\\)" {
- fail $gdb_test_name
- }
-
- -re -wrap "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+$::hex\\s*\[^\r\n\]+\r\n\\s+stop only if \\(0\\)" {
- pass $gdb_test_name
- }
- }
+ set hs {[^\r\n]}
+ set re_pass \
+ [multi_line \
+ "" \
+ [join \
+ [list \
+ "$bpnum" "breakpoint" "keep" "y" "$::hex$hs+"] \
+ {\s+}] \
+ [string cat \
+ {\s+} \
+ [string_to_regexp "stop only if (0)"] \
+ ([string_to_regexp " (target evals)"])?]]
+ gdb_test "info breakpoints $bpnum" $re_pass "check b/p status"
# With all the dlclose calls now complete, we should be back to a
# single copy of the dynamic linker.
diff --git a/gdb/testsuite/gdb.base/dump.c b/gdb/testsuite/gdb.base/dump.c
index bdcafbf..14b66b1 100644
--- a/gdb/testsuite/gdb.base/dump.c
+++ b/gdb/testsuite/gdb.base/dump.c
@@ -35,7 +35,7 @@ main()
for (i = 0; i < ARRSIZE; i++)
intarray[i] = i+1;
- intstruct.a = 12 * 1;
+ intstruct.a = (12 * 1) << 16;
intstruct.b = 12 * 2;
intstruct.c = 12 * 3;
intstruct.d = 12 * 4;
diff --git a/gdb/testsuite/gdb.base/dump.exp b/gdb/testsuite/gdb.base/dump.exp
index a55e5b0..7c84056 100644
--- a/gdb/testsuite/gdb.base/dump.exp
+++ b/gdb/testsuite/gdb.base/dump.exp
@@ -107,14 +107,7 @@ set endian [get_endianness]
# Now generate some dump files.
proc make_dump_file { command msg } {
- global gdb_prompt
-
- gdb_test_multiple "${command}" "$msg" {
- -re ".*\[Ee\]rror.*$gdb_prompt $" { fail $msg }
- -re ".*\[Ww\]arning.*$gdb_prompt $" { fail $msg }
- -re ".*\[Uu\]ndefined .*$gdb_prompt $" { fail $msg }
- -re ".*$gdb_prompt $" { pass $msg }
- }
+ gdb_test_no_output "${command}" "$msg"
}
make_dump_file "dump val [set intarr1.bin] intarray" \
diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp
index f703c18..81f6f19 100644
--- a/gdb/testsuite/gdb.base/exprs.exp
+++ b/gdb/testsuite/gdb.base/exprs.exp
@@ -285,11 +285,14 @@ gdb_test "print v_short + " \
gdb_test "print v_short =}{= 3" \
"A syntax error in expression, near `\\}\\{= 3'\\."
+set hs {[^\r\n]}
+set re_debug [string cat $hs* {[Ss]hift} $hs*]
+
gdb_test_no_output "set debug parse 1"
set saw_start 0
set saw_val 0
gdb_test_multiple "print 23" "print with debugging" -lbl {
- -re "\r\nStarting parse(?=\r\n)" {
+ -re "\r\n${re_debug}(?=\r\n)" {
set saw_start 1
exp_continue
}
diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp
index cb3fc90..c10941c 100644
--- a/gdb/testsuite/gdb.base/filename-completion.exp
+++ b/gdb/testsuite/gdb.base/filename-completion.exp
@@ -385,7 +385,7 @@ proc run_quoting_and_escaping_tests { root } {
remove-symbol-file \
"target core" "target exec" "target tfile" \
"maint print c-tdesc" "save gdb-index"
- "save gdb-index -dwarf-5" }
+ "save gdb-index -dwarf-5" "shell ls"}
if { [allow_compile_tests] } {
lappend all_cmds "compile file"
}
@@ -408,6 +408,31 @@ proc run_quoting_and_escaping_tests { root } {
run_quoting_and_escaping_tests_1 $root $cmd
}
}
+
+ # Some additional testing of shell command. Test 'shell' and '!'
+ # when there are multiple filenames on the command line. This
+ # focuses on completion of the final filename. There is also some
+ # testing of the shell command above, this tests completion within
+ # the line.
+ foreach_with_prefix shell_cmd { "shell " "!" "pipe print 1 | " } {
+ foreach suffix { "aaa/aa bb" "bb2/dir 1/unique file" } {
+ set dir $root/$suffix
+
+ regsub -all " " "$dir" "\\ " dir_with_backslash
+
+ with_test_prefix "suffix='$suffix'" {
+ with_test_prefix "with_backslash" {
+ run_quoting_and_escaping_tests_1 $root "${shell_cmd}ls $dir_with_backslash"
+ }
+ with_test_prefix "with double quotes" {
+ run_quoting_and_escaping_tests_1 $root "${shell_cmd}ls \"$dir\""
+ }
+ with_test_prefix "with single quotes" {
+ run_quoting_and_escaping_tests_1 $root "${shell_cmd}ls '$dir'"
+ }
+ }
+ }
+ }
}
# Helper for run_unquoted_tests. ROOT is the root directory as setup
diff --git a/gdb/testsuite/gdb.base/foll-exec-c++.exp b/gdb/testsuite/gdb.base/foll-exec-c++.exp
new file mode 100644
index 0000000..d96310b
--- /dev/null
+++ b/gdb/testsuite/gdb.base/foll-exec-c++.exp
@@ -0,0 +1,24 @@
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the gdb testsuite
+
+# See foll-exec.exp.tcl for test details. This file runs the test
+# using the C++ compiler.
+
+require allow_cplus_tests
+set lang c++
+
+source $srcdir/$subdir/foll-exec.exp.tcl
diff --git a/gdb/testsuite/gdb.base/foll-exec-c.exp b/gdb/testsuite/gdb.base/foll-exec-c.exp
new file mode 100644
index 0000000..67f62cc
--- /dev/null
+++ b/gdb/testsuite/gdb.base/foll-exec-c.exp
@@ -0,0 +1,23 @@
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the gdb testsuite
+
+# See foll-exec.exp.tcl for test details. This file runs the test
+# using the C compiler.
+
+set lang c
+
+source $srcdir/$subdir/foll-exec.exp.tcl
diff --git a/gdb/testsuite/gdb.base/foll-exec.c b/gdb/testsuite/gdb.base/foll-exec.c
index a1c9b70..291f803 100644
--- a/gdb/testsuite/gdb.base/foll-exec.c
+++ b/gdb/testsuite/gdb.base/foll-exec.c
@@ -19,25 +19,38 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-
+#include <libgen.h>
+#include <assert.h>
#include <limits.h>
int global_i = 100;
+#ifndef EXECD_PROG
+#define EXECD_PROG "execd-prog"
+#endif
+
int main (int argc, char ** argv)
{
int local_j = global_i + 1;
int local_k = local_j + 1;
char prog[PATH_MAX];
- int len;
+ size_t len = PATH_MAX - 1;
+
+ printf ("foll-exec is about to execlp(%s)...\n", EXECD_PROG);
+
+ prog [len] = '\0';
+
+ strncpy (prog, dirname (argv[0]), len);
+ len -= strlen (prog);
+ assert (len > 0);
- printf ("foll-exec is about to execlp(execd-prog)...\n");
+ strncat (prog, "/", len);
+ len -= 1;
+ assert (len > 0);
- strcpy (prog, argv[0]);
- len = strlen (prog);
- /* Replace "foll-exec" with "execd-prog". */
- memcpy (prog + len - 9, "execd-prog", 10);
- prog[len + 1] = 0;
+ strncat (prog, EXECD_PROG, len);
+ len -= strlen (EXECD_PROG);
+ assert (len > 0);
/* In the following function call, maximum line length exceed the limit 80.
This is intentional and required for clang compiler such that complete
@@ -45,7 +58,7 @@ int main (int argc, char ** argv)
multi-line. */
execlp (prog, /* tbreak-execlp */ prog, "execlp arg1 from foll-exec", (char *) 0);
- printf ("foll-exec is about to execl(execd-prog)...\n");
+ printf ("foll-exec is about to execl(%s)...\n", EXECD_PROG);
/* In the following function call, maximum line length exceed the limit 80.
This is intentional and required for clang compiler such that complete
@@ -61,7 +74,7 @@ int main (int argc, char ** argv)
argv[0] = prog;
- printf ("foll-exec is about to execv(execd-prog)...\n");
+ printf ("foll-exec is about to execv(%s)...\n", EXECD_PROG);
execv (prog, argv); /* tbreak-execv */
}
diff --git a/gdb/testsuite/gdb.base/foll-exec.exp b/gdb/testsuite/gdb.base/foll-exec.exp.tcl
index ad4c3516..8f96a55 100644
--- a/gdb/testsuite/gdb.base/foll-exec.exp
+++ b/gdb/testsuite/gdb.base/foll-exec.exp.tcl
@@ -22,33 +22,55 @@ require {istarget "*-linux*"}
standard_testfile foll-exec.c
-set testfile2 "execd-prog"
-set srcfile2 ${testfile2}.c
-set binfile2 [standard_output_file ${testfile2}]
+# Compile a program that performs an exec as EXECER_LANG, and a
+# program that will be exec'd as EXECEE_LANG. Either language can be
+# 'c' or 'c++'. Then run various test associated with 'catch exec'
+# using the compiled programs.
+proc do_exec_tests { execer_lang execee_lang } {
+ global srcfile testfile
+ global gdb_prompt
-set compile_options debug
+ # First compile the program to be exec'd, the execee.
+ set execee_base_filename "execd-prog"
+ set srcfile2 ${execee_base_filename}.c
+ set execee_testfile "execd-prog-${execee_lang}"
+ set execee_testfile_re [string_to_regexp $execee_testfile]
+ set execee_binfile [standard_output_file $execee_testfile]
-# build the first test case
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $compile_options] != "" } {
- untested "failed to compile"
- return -1
-}
+ set execee_flags debug
+ if { $execee_lang == "c++" } {
+ lappend execee_flags "c++"
+ }
-if { [is_remote target] } {
- gdb_remote_download target $binfile2
-}
+ if { [build_executable "failed to build $execee_testfile" $execee_testfile \
+ $srcfile2 $execee_flags] == -1 } {
+ return
+ }
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $compile_options] != "" } {
- untested "failed to compile"
- return -1
-}
+ if { [is_remote target] } {
+ gdb_remote_download target $execee_binfile
+ }
-proc do_exec_tests {} {
- global binfile srcfile srcfile2 testfile testfile2
- global gdb_prompt
+
+ # Now compile the program to do the exec, the execer.
+ set execer_testfile "$testfile-${execee_lang}"
+ set execer_binfile [standard_output_file $execer_testfile]
+
+ set execer_flags debug
+ if { $execer_lang == "c++" } {
+ lappend execer_flags "c++"
+ }
+ lappend execer_flags "additional_flags=-DEXECD_PROG=\"${execee_testfile}\""
+
+ if { [build_executable "failed to build $execer_testfile" $execer_testfile \
+ $srcfile $execer_flags] == -1 } {
+ return
+ }
+
+ # Now we can start running the tests.
+ clean_restart $execer_binfile
# Start the program running, and stop at main.
- #
if {![runto_main]} {
return
}
@@ -71,7 +93,7 @@ proc do_exec_tests {} {
return
}
- clean_restart $binfile
+ clean_restart $execer_binfile
# Start the program running, and stop at main.
#
@@ -120,7 +142,7 @@ proc do_exec_tests {} {
set execd_line [gdb_get_line_number "after-exec" $srcfile2]
send_gdb "next\n"
gdb_expect {
- -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
+ -re ".*xecuting new program: .*${execee_testfile_re}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
{pass "step through execlp call"}
-re "$gdb_prompt $" {fail "step through execlp call"}
timeout {fail "(timeout) step through execlp call"}
@@ -160,7 +182,7 @@ proc do_exec_tests {} {
# Explicitly kill this program, or a subsequent rerun actually runs
# the exec'd program, not the original program...
- clean_restart $binfile
+ clean_restart $execer_binfile
# Start the program running, and stop at main.
#
@@ -193,7 +215,7 @@ proc do_exec_tests {} {
send_gdb "continue\n"
gdb_expect {
- -re ".*xecuting new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*$gdb_prompt $"\
+ -re ".*xecuting new program:.*${execee_testfile_re}.*Catchpoint .*(exec\'d .*${execee_testfile_re}).*$gdb_prompt $"\
{pass "hit catch exec"}
-re "$gdb_prompt $" {fail "hit catch exec"}
timeout {fail "(timeout) hit catch exec"}
@@ -210,7 +232,7 @@ proc do_exec_tests {} {
#
set msg "info shows catchpoint exec pathname"
gdb_test_multiple "info breakpoints" $msg {
- -re ".*catchpoint.*keep y.*exec, program \".*${testfile2}\".*$gdb_prompt $" {
+ -re ".*catchpoint.*keep y.*exec, program \".*${execee_testfile_re}\".*$gdb_prompt $" {
pass $msg
}
}
@@ -228,7 +250,7 @@ proc do_exec_tests {} {
# Explicitly kill this program, or a subsequent rerun actually runs
# the exec'd program, not the original program...
- clean_restart $binfile
+ clean_restart $execer_binfile
# Start the program running, and stop at main.
#
@@ -269,7 +291,7 @@ proc do_exec_tests {} {
#
send_gdb "next 2\n"
gdb_expect {
- -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
+ -re ".*xecuting new program: .*${execee_testfile_re}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
{pass "step through execl call"}
-re "$gdb_prompt $" {fail "step through execl call"}
timeout {fail "(timeout) step through execl call"}
@@ -295,7 +317,7 @@ proc do_exec_tests {} {
# Explicitly kill this program, or a subsequent rerun actually runs
# the exec'd program, not the original program...
- clean_restart $binfile
+ clean_restart $execer_binfile
# Start the program running, and stop at main.
#
@@ -330,7 +352,7 @@ proc do_exec_tests {} {
}
send_gdb "next\n"
gdb_expect {
- -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
+ -re ".*xecuting new program: .*${execee_testfile_re}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
{pass "step through execv call"}
-re "$gdb_prompt $" {fail "step through execv call"}
timeout {fail "(timeout) step through execv call"}
@@ -356,7 +378,7 @@ proc do_exec_tests {} {
# Explicitly kill this program, or a subsequent rerun actually runs
# the exec'd program, not the original program...
- clean_restart $binfile
+ clean_restart $execer_binfile
# Start the program running, and stop at main.
#
@@ -370,13 +392,13 @@ proc do_exec_tests {} {
#
send_gdb "continue\n"
gdb_expect {
- -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
+ -re ".*xecuting new program: .*${execee_testfile_re}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
{pass "continue through exec"}
-re "$gdb_prompt $" {fail "continue through exec"}
timeout {fail "(timeout) continue through exec"}
}
}
-clean_restart $binfile
-
-do_exec_tests
+foreach_with_prefix execee_lang { c c++ } {
+ do_exec_tests $lang $execee_lang
+}
diff --git a/gdb/testsuite/gdb.base/foll-fork-syscall.c b/gdb/testsuite/gdb.base/foll-fork-syscall.c
new file mode 100644
index 0000000..ef695f5
--- /dev/null
+++ b/gdb/testsuite/gdb.base/foll-fork-syscall.c
@@ -0,0 +1,35 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <unistd.h>
+#include <stdio.h>
+
+int
+main (int argc, char **argv)
+{
+ int pid, x = 0;
+
+ pid = fork ();
+ if (pid == 0) /* set breakpoint here */
+ printf ("I am the child\n");
+ else
+ printf ("I am the parent\n");
+
+ chdir (".");
+ ++x; /* set exit breakpoint here */
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/foll-fork-syscall.exp b/gdb/testsuite/gdb.base/foll-fork-syscall.exp
new file mode 100644
index 0000000..21ef334
--- /dev/null
+++ b/gdb/testsuite/gdb.base/foll-fork-syscall.exp
@@ -0,0 +1,143 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test catching syscalls with all permutations of follow-fork parent/child
+# and detach-on-fork on/off.
+
+# Test relies on checking follow-fork output. Do not run if gdb debug is
+# enabled because it will be redirected to the log.
+require !gdb_debug_enabled
+require {is_any_target "i?86-*-*" "x86_64-*-*"}
+require allow_fork_tests
+
+standard_testfile
+
+if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
+ return -1
+}
+
+proc setup_gdb {} {
+ global testfile
+
+ clean_restart $testfile
+
+ if {![runto_main]} {
+ return false
+ }
+
+ # Set a breakpoint after the fork is "complete."
+ if {![gdb_breakpoint [gdb_get_line_number "set breakpoint here"]]} {
+ return false
+ }
+
+ # Set exit breakpoint (to prevent inferior from exiting).
+ if {![gdb_breakpoint [gdb_get_line_number "set exit breakpoint here"]]} {
+ return false
+ }
+ return true
+}
+
+# Check that fork catchpoints are supported, as an indicator for whether
+# fork-following is supported. Return 1 if they are, else 0.
+
+proc_with_prefix check_fork_catchpoints {} {
+ global gdb_prompt
+
+ if { ![setup_gdb] } {
+ return false
+ }
+
+ # Verify that the system supports "catch fork".
+ gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "insert first fork catchpoint"
+ set has_fork_catchpoints false
+ gdb_test_multiple "continue" "continue to first fork catchpoint" {
+ -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
+ unsupported "continue to first fork catchpoint"
+ }
+ -re ".*Catchpoint.*$gdb_prompt $" {
+ set has_fork_catchpoints true
+ pass "continue to first fork catchpoint"
+ }
+ }
+
+ return $has_fork_catchpoints
+}
+
+proc_with_prefix test_catch_syscall {follow-fork-mode detach-on-fork} {
+ # Start with shiny new gdb instance.
+ if {![setup_gdb]} {
+ return
+ }
+
+ # The "Detaching..." and "Attaching..." messages may be hidden by
+ # default.
+ gdb_test_no_output "set verbose"
+
+ # Setup modes to test.
+ gdb_test_no_output "set follow-fork-mode ${follow-fork-mode}"
+ gdb_test_no_output "set detach-on-fork ${detach-on-fork}"
+
+ gdb_test "catch fork" "Catchpoint . \\(fork\\)"
+ gdb_test "catch syscall chdir" "Catchpoint . \\(syscall 'chdir'.*\\)"
+
+ # Which inferior we're expecting to follow. Assuming the parent
+ # will be inferior #1, and the child will be inferior #2.
+ if {${follow-fork-mode} == "parent"} {
+ set following_inf 1
+ } else {
+ set followin_inf 2
+ }
+ # Next stop should be the fork catchpoint.
+ set expected_re ""
+ append expected_re "Catchpoint . \\(forked process.*"
+ gdb_test "continue" $expected_re "continue to fork catchpoint"
+
+ # Next stop should be the breakpoint after the fork.
+ set expected_re ".*"
+ if {${follow-fork-mode} == "child" || ${detach-on-fork} == "off"} {
+ append expected_re "\\\[New inferior.*"
+ }
+ if {${detach-on-fork} == "on"} {
+ append expected_re "\\\[Detaching after fork from "
+ if {${follow-fork-mode} == "parent"} {
+ append expected_re "child"
+ } else {
+ append expected_re "parent"
+ }
+ append expected_re " process.*"
+ }
+ append expected_re "Breakpoint .*set breakpoint here.*"
+ gdb_test "continue" $expected_re "continue to breakpoint after fork"
+
+ # Next stop should be the syscall catchpoint.
+ set expected_re ".*Catchpoint . \\(call to syscall chdir\\).*"
+ gdb_test continue $expected_re "continue to chdir syscall"
+}
+
+# Check for follow-fork support.
+if {![check_fork_catchpoints]} {
+ untested "follow-fork not supported"
+ return
+}
+
+# Test all permutations.
+foreach_with_prefix follow-fork-mode {"parent" "child"} {
+
+ # Do not run tests when not detaching from the parent.
+ # See breakpoints/13457 for discussion.
+ foreach_with_prefix detach-on-fork {"on"} {
+ test_catch_syscall ${follow-fork-mode} ${detach-on-fork}
+ }
+}
diff --git a/gdb/testsuite/gdb.base/foll-fork.exp b/gdb/testsuite/gdb.base/foll-fork.exp
index 94755c6..12db516 100644
--- a/gdb/testsuite/gdb.base/foll-fork.exp
+++ b/gdb/testsuite/gdb.base/foll-fork.exp
@@ -17,6 +17,8 @@
# enabled as it will be redirected to the log.
require !gdb_debug_enabled
+require allow_fork_tests
+
standard_testfile
if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
diff --git a/gdb/testsuite/gdb.base/foll-vfork.exp b/gdb/testsuite/gdb.base/foll-vfork.exp
index 266df46..6ca7711 100644
--- a/gdb/testsuite/gdb.base/foll-vfork.exp
+++ b/gdb/testsuite/gdb.base/foll-vfork.exp
@@ -18,12 +18,7 @@
# either execs or exits --- since those events take somewhat different
# code paths in GDB, both variants are exercised.
-# Until "set follow-fork-mode" and "catch vfork" are implemented on
-# other targets...
-#
-if {![istarget "*-linux*"]} {
- continue
-}
+require allow_fork_tests
standard_testfile .c -exit.c vforked-prog.c
diff --git a/gdb/testsuite/gdb.base/fork-no-detach-follow-child-dlopen.exp b/gdb/testsuite/gdb.base/fork-no-detach-follow-child-dlopen.exp
index 311d7ba..2d47d5d 100644
--- a/gdb/testsuite/gdb.base/fork-no-detach-follow-child-dlopen.exp
+++ b/gdb/testsuite/gdb.base/fork-no-detach-follow-child-dlopen.exp
@@ -23,6 +23,7 @@
# in the source of the shlib, and "list" should display the source where
# the program stopped.
+require allow_fork_tests
require allow_shlib_tests
standard_testfile .c -shlib.c
diff --git a/gdb/testsuite/gdb.base/fork-print-inferior-events.exp b/gdb/testsuite/gdb.base/fork-print-inferior-events.exp
index 26ed2f9..19ace00 100644
--- a/gdb/testsuite/gdb.base/fork-print-inferior-events.exp
+++ b/gdb/testsuite/gdb.base/fork-print-inferior-events.exp
@@ -19,6 +19,8 @@
# inferior-events [on,off]', 'set follow-fork-mode [child,parent]' and
# 'set detach-on-fork [on,off]' are the correct ones.
+require allow_fork_tests
+
# This test relies on "run", so it cannot run on target remote stubs.
require !use_gdb_stub
diff --git a/gdb/testsuite/gdb.base/fork-running-state.exp b/gdb/testsuite/gdb.base/fork-running-state.exp
index 4b810a6..c446800 100644
--- a/gdb/testsuite/gdb.base/fork-running-state.exp
+++ b/gdb/testsuite/gdb.base/fork-running-state.exp
@@ -17,6 +17,8 @@
# in non-stop). GDB used to miss updating the parent/child running
# states after a fork.
+require allow_fork_tests
+
standard_testfile
# The test proper.
diff --git a/gdb/testsuite/gdb.base/fullname.exp b/gdb/testsuite/gdb.base/fullname.exp
index 430d0c4..ce617d5 100644
--- a/gdb/testsuite/gdb.base/fullname.exp
+++ b/gdb/testsuite/gdb.base/fullname.exp
@@ -65,7 +65,7 @@ if { [gdb_breakpoint [standard_output_file tmp-${srcfile}]:${line} {no-message}]
}
# Build the test executable using a relative path.
-if { [gdb_compile [relative_filename [pwd] [standard_output_file tmp-${srcfile}]] \
+if { [gdb_compile [relative_filename [pwd] [build_standard_output_file tmp-${srcfile}]] \
"${binfile}" executable {debug}] != "" } {
return -1
}
diff --git a/gdb/testsuite/gdb.base/infcall-failure-2.exp b/gdb/testsuite/gdb.base/infcall-failure-2.exp
new file mode 100644
index 0000000..2a7d784
--- /dev/null
+++ b/gdb/testsuite/gdb.base/infcall-failure-2.exp
@@ -0,0 +1,37 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile infcall-failure.c
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile] == -1 } {
+ return
+}
+
+if { ![runto_main] } {
+ return
+}
+
+if { ![gdb_breakpoint "*0x1" message] } {
+ return
+}
+
+gdb_test "p foo ()" \
+ [multi_line \
+ [string_to_regexp "Command aborted."] \
+ ".*" ]
+
+# Check that gdb is still responsive. Regression test for PR gdb/33068.
+gdb_test "p 1 + 1" \
+ " = 2"
diff --git a/gdb/testsuite/gdb.base/infcall-failure.exp b/gdb/testsuite/gdb.base/infcall-failure.exp
index 66bccd1..e7aeac1 100644
--- a/gdb/testsuite/gdb.base/infcall-failure.exp
+++ b/gdb/testsuite/gdb.base/infcall-failure.exp
@@ -131,7 +131,13 @@ proc_with_prefix run_cond_hits_segfault_test { async_p non_stop_p } {
[multi_line \
"Continuing\\." \
"" \
- "Program received signal SIGSEGV, Segmentation fault\\." \
+ [string cat \
+ [string_to_regexp \
+ "Program received signal SIGSEGV, Segmentation fault."] \
+ "("] \
+ [string cat \
+ [string_to_regexp "Address not mapped to object."] \
+ ")?"] \
"${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \
"${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \
"Error in testing condition for breakpoint ${bp_1_num}:" \
@@ -161,7 +167,13 @@ proc_with_prefix run_call_hits_segfault_test { async_p non_stop_p } {
gdb_test "call func_segfault ()" \
[multi_line \
"" \
- "Program received signal SIGSEGV, Segmentation fault\\." \
+ [string cat \
+ [string_to_regexp \
+ "Program received signal SIGSEGV, Segmentation fault."] \
+ "("] \
+ [string cat \
+ [string_to_regexp "Address not mapped to object."] \
+ ")?"] \
"${::hex} in func_segfault \\(\\) at \[^\r\n\]+:${::segv_line}" \
"${::decimal}\\s+\[^\r\n\]+Segfault here\[^\r\n\]+" \
"The program being debugged was signaled while in a function called from GDB\\." \
diff --git a/gdb/testsuite/gdb.base/inferior-args.exp b/gdb/testsuite/gdb.base/inferior-args.exp
index 9406c78..dfa1215 100644
--- a/gdb/testsuite/gdb.base/inferior-args.exp
+++ b/gdb/testsuite/gdb.base/inferior-args.exp
@@ -17,6 +17,7 @@
# This does not work on boards that don't support inferior arguments.
require {!target_info exists noargs}
+require {expr [have_startup_shell] != -1}
standard_testfile .c
diff --git a/gdb/testsuite/gdb.base/inferior-died.exp b/gdb/testsuite/gdb.base/inferior-died.exp
index 3992561..764a88d 100644
--- a/gdb/testsuite/gdb.base/inferior-died.exp
+++ b/gdb/testsuite/gdb.base/inferior-died.exp
@@ -13,10 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# Until "set follow-fork-mode" and "catch fork" are implemented on
-# other targets...
-#
-require {istarget "*-*-linux*"}
+require allow_fork_tests
require support_displaced_stepping
diff --git a/gdb/testsuite/gdb.base/info-shared.exp b/gdb/testsuite/gdb.base/info-shared.exp
index 6f1b2d6..e81b28e 100644
--- a/gdb/testsuite/gdb.base/info-shared.exp
+++ b/gdb/testsuite/gdb.base/info-shared.exp
@@ -79,6 +79,9 @@ proc check_info_shared { test expect1 expect2 } {
}
}
+# Check that "info shared" before running doesn't crash.
+check_info_shared "info sharedlibrary before running" 0 0
+
# Start the inferior, and check neither of the libraries are loaded at
# the start.
if ![runto_main] {
diff --git a/gdb/testsuite/gdb.base/info_sources_2.exp b/gdb/testsuite/gdb.base/info_sources_2.exp
index c469049..39b594b 100644
--- a/gdb/testsuite/gdb.base/info_sources_2.exp
+++ b/gdb/testsuite/gdb.base/info_sources_2.exp
@@ -72,13 +72,18 @@ proc run_info_sources { extra_args args } {
set objfile_name ""
set source_files {}
set files {}
+ # Note below we sanitize paths so we can compare against the
+ # host_file_normalize'd paths later. Note we sanitize, but
+ # don't normalize here, as the latter would turn a relative
+ # path into an absolute path, and this testcase wants to make
+ # sure that GDB prints the absolute path.
gdb_test_multiple $cmd "" {
-re "${command_regex}\r\n" {
exp_continue
}
-re "^(\[^\r\n\]+):\r\n" {
- set objfile_name $expect_out(1,string)
+ set objfile_name [host_file_sanitize $expect_out(1,string)]
if { $is_remote_target } {
set objfile_name [file tail $objfile_name]
}
@@ -101,7 +106,7 @@ proc run_info_sources { extra_args args } {
}
-re "^(\[^,\r\n\]+), " {
- set f $expect_out(1,string)
+ set f [host_file_sanitize $expect_out(1,string)]
lappend files $f
exp_continue
}
@@ -111,7 +116,7 @@ proc run_info_sources { extra_args args } {
return
}
- set f $expect_out(1,string)
+ set f [host_file_sanitize $expect_out(1,string)]
lappend files $f
set info_sources($objfile_name) $files
set $objfile_name ""
@@ -133,7 +138,7 @@ proc run_info_sources { extra_args args } {
}
# Figure out the path for SOURCEFILE that we're looking for.
- set sourcepath [file normalize ${srcdir}/${subdir}/${sourcefile}]
+ set sourcepath [host_file_normalize ${srcdir}/${subdir}/${sourcefile}]
if { $is_remote_target } {
set objfile [file tail $objfile]
@@ -156,32 +161,34 @@ proc run_info_sources { extra_args args } {
# The actual tests.
+set host_binfile [host_file_normalize $binfile$EXEEXT]
+
run_info_sources "" \
- ${binfile} ${srcfile} \
- ${binfile} ${testfile}-header.h \
+ ${host_binfile} ${srcfile} \
+ ${host_binfile} ${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} ${testfile}-header.h
run_info_sources "-basename info_sources_2" \
- ${binfile} ${srcfile} \
- ${binfile} ${testfile}-header.h \
+ ${host_binfile} ${srcfile} \
+ ${host_binfile} ${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} ${testfile}-header.h
run_info_sources "-basename \\.c" \
- ${binfile} ${srcfile} \
- ${binfile} !${testfile}-header.h \
+ ${host_binfile} ${srcfile} \
+ ${host_binfile} !${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} !${testfile}-header.h
run_info_sources "-basename -- -test\\.c" \
- ${binfile} ${srcfile} \
- ${binfile} !${testfile}-header.h \
+ ${host_binfile} ${srcfile} \
+ ${host_binfile} !${testfile}-header.h \
${solib_name} !${srcfile2} \
${solib_name} !${testfile}-header.h
run_info_sources "-basename -- -lib\\.c" \
- ${binfile} !${srcfile} \
- ${binfile} !${testfile}-header.h \
+ ${host_binfile} !${srcfile} \
+ ${host_binfile} !${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} !${testfile}-header.h
diff --git a/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.py b/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.py
index bc4a673..4ab7257 100644
--- a/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.py
+++ b/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.py
@@ -65,6 +65,10 @@ class TestUnwinder(Unwinder):
for reg in pending_frame.architecture().registers("general"):
val = pending_frame.read_register(reg)
+ # Having unavailable registers leads to a fall back to the standard
+ # unwinders. Don't add unavailable registers to avoid this.
+ if str(val) == "<unavailable>":
+ continue
unwinder.add_saved_register(reg, val)
return unwinder
diff --git a/gdb/testsuite/gdb.base/interrupt-daemon.exp b/gdb/testsuite/gdb.base/interrupt-daemon.exp
index 161f854..8b8c61d 100644
--- a/gdb/testsuite/gdb.base/interrupt-daemon.exp
+++ b/gdb/testsuite/gdb.base/interrupt-daemon.exp
@@ -16,6 +16,8 @@
# Make sure that we can interrupt an inferior that forks and moves to
# its own session.
+require allow_fork_tests
+
standard_testfile
if {[build_executable "failed to build" $testfile $srcfile {debug}]} {
diff --git a/gdb/testsuite/gdb.base/jit-elf-fork.exp b/gdb/testsuite/gdb.base/jit-elf-fork.exp
index 81d3350..c1fa428 100644
--- a/gdb/testsuite/gdb.base/jit-elf-fork.exp
+++ b/gdb/testsuite/gdb.base/jit-elf-fork.exp
@@ -15,6 +15,7 @@
# Test fork handling of an inferior that has JIT-ed objfiles.
+require allow_fork_tests
require allow_shlib_tests
load_lib jit-elf-helpers.exp
diff --git a/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp b/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp
index ef4bb88..57ec330 100644
--- a/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp
+++ b/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp
@@ -19,6 +19,7 @@
# commands.
require can_spawn_for_attach
+require allow_multi_inferior_tests
standard_testfile
set executable $testfile
diff --git a/gdb/testsuite/gdb.base/macro-source-path.exp b/gdb/testsuite/gdb.base/macro-source-path.exp
index 47ad789..47d99aa 100644
--- a/gdb/testsuite/gdb.base/macro-source-path.exp
+++ b/gdb/testsuite/gdb.base/macro-source-path.exp
@@ -33,7 +33,7 @@ require {!is_remote host}
# Set the current working directory to $out/cwd, so that we can test compiling
# using relative paths.
-set out_dir [standard_output_file ""]
+set out_dir [build_standard_output_file ""]
file mkdir $out_dir/cwd
file mkdir $out_dir/other
file copy -force $srcdir/$subdir/$srcfile $out_dir/cwd
@@ -53,7 +53,7 @@ proc test { src name } {
return
}
- clean_restart $binfile
+ clean_restart [host_file_normalize $binfile]
if { ![runto_main] } {
return
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index 52282bc..7936e53 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -52,6 +52,40 @@ if {[prepare_for_testing "failed to prepare" $testfile \
return -1
}
+# Check "maint set per-command" warnings. We do this early so that
+# the following tests don't need to expect them, as GDB only warns
+# once.
+
+with_test_prefix "warnings" {
+ # Potential warning given by "maint set per-command time".
+ set maybe_per_command_warning \
+ "(?:warning: per-thread run time information not available on this platform)?"
+
+ # This one should not issue the "per-command time" warning.
+ with_test_prefix "per-command space" {
+ gdb_test_no_output "mt set per-command space on"
+ gdb_test_no_output "mt set per-command space off"
+ }
+
+ # These might warn. "per-command on" enables all sub commands, so
+ # might trigger the "per-command time" warning.
+ foreach cmd {"per-command" "per-command time"} {
+ with_test_prefix $cmd {
+ # GDB only warns once, so restart between commands.
+ clean_restart $binfile
+ gdb_test "mt set $cmd on" "$maybe_per_command_warning"
+ gdb_test "mt set $cmd off" "command started"
+ gdb_test_no_output "mt set $cmd on" \
+ "mt set $cmd on, again"
+ gdb_test "mt set $cmd off" "command started" \
+ "mt set $cmd off, again"
+ }
+ }
+
+ # We've already warned once above, so the following tests don't
+ # need to expect the warning.
+}
+
set readnow_p [readnow]
# The commands we test here produce many lines of output; disable "press
@@ -205,8 +239,8 @@ set re \
"( Number of \"partial\" symbols read: $decimal" \
")?( Number of psym tables \\(not yet expanded\\): $decimal" \
")?( Total memory used for psymbol cache: $decimal" \
- ")?( Number of read CUs: $decimal" \
- " Number of unread CUs: $decimal" \
+ ")?( Number of read units: $decimal" \
+ " Number of unread units: $decimal" \
")? Total memory used for objfile obstack: $decimal" \
" Total memory used for BFD obstack: $decimal" \
" Total memory used for string cache: $decimal" \
diff --git a/gdb/testsuite/gdb.base/many-headers.exp b/gdb/testsuite/gdb.base/many-headers.exp
index f46b980..5e022da 100644
--- a/gdb/testsuite/gdb.base/many-headers.exp
+++ b/gdb/testsuite/gdb.base/many-headers.exp
@@ -33,6 +33,7 @@ if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
# Generate core file.
set corefile [core_find $binfile]
if {$corefile == ""} {
+ untested "unable to create or find corefile"
return 0
}
diff --git a/gdb/testsuite/gdb.base/multi-forks.exp b/gdb/testsuite/gdb.base/multi-forks.exp
index 61a240f..3facccb 100644
--- a/gdb/testsuite/gdb.base/multi-forks.exp
+++ b/gdb/testsuite/gdb.base/multi-forks.exp
@@ -13,11 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# Until "set follow-fork-mode" and "catch fork" are implemented on
-# other targets...
-#
-require {istarget "*-*-linux*"}
-
+require allow_fork_tests
standard_testfile .c
diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp
index 7822e4a..a0947e2 100644
--- a/gdb/testsuite/gdb.base/options.exp
+++ b/gdb/testsuite/gdb.base/options.exp
@@ -508,12 +508,26 @@ proc_with_prefix test-thread-apply {} {
proc_with_prefix test-info-threads {} {
test_gdb_complete_multiple "info threads " "" "" {
"-gid"
+ "-running"
+ "-stopped"
"ID"
}
+ test_gdb_complete_multiple "info threads " "-" "" {
+ "-gid"
+ "-running"
+ "-stopped"
+ }
+
test_gdb_complete_unique \
- "info threads -" \
+ "info threads -g" \
"info threads -gid"
+ test_gdb_complete_unique \
+ "info threads -r" \
+ "info threads -running"
+ test_gdb_complete_unique \
+ "info threads -s" \
+ "info threads -stopped"
# "ID" isn't really something the user can type.
test_gdb_complete_none "info threads I"
diff --git a/gdb/testsuite/gdb.base/pie-fork.exp b/gdb/testsuite/gdb.base/pie-fork.exp
index 48c01d9..86407b4 100644
--- a/gdb/testsuite/gdb.base/pie-fork.exp
+++ b/gdb/testsuite/gdb.base/pie-fork.exp
@@ -16,6 +16,8 @@
# Test that we can follow forks properly when the executable is
# position-independent.
+require allow_fork_tests
+
standard_testfile
set opts [list debug pie]
diff --git a/gdb/testsuite/gdb.base/readline-ask.exp b/gdb/testsuite/gdb.base/readline-ask.exp
index 3f98e13..2948970 100644
--- a/gdb/testsuite/gdb.base/readline-ask.exp
+++ b/gdb/testsuite/gdb.base/readline-ask.exp
@@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+require {!is_remote host}
+
standard_testfile .c
set inputrc ${srcdir}/${subdir}/${testfile}.inputrc
diff --git a/gdb/testsuite/gdb.base/readline.exp b/gdb/testsuite/gdb.base/readline.exp
index 198d686..9b87790 100644
--- a/gdb/testsuite/gdb.base/readline.exp
+++ b/gdb/testsuite/gdb.base/readline.exp
@@ -21,6 +21,8 @@
# Tests for readline operations.
#
+require {!is_remote host}
+
# This function is used to test operate-and-get-next.
# NAME is the name of the test.
# ARGS is a list of alternating commands and expected results.
diff --git a/gdb/testsuite/gdb.base/run-control-while-bg-execution.exp b/gdb/testsuite/gdb.base/run-control-while-bg-execution.exp
index 22913ca..eaee010 100644
--- a/gdb/testsuite/gdb.base/run-control-while-bg-execution.exp
+++ b/gdb/testsuite/gdb.base/run-control-while-bg-execution.exp
@@ -49,6 +49,11 @@ if {[build_executable "failed to prepare" $testfile $srcfile]} {
# - run: use the run command
# - attach: start a process outside of GDB and attach it
proc do_test { action1 action2 } {
+
+ if {$action1 == "add" && ![allow_multi_inferior_tests]} {
+ return
+ }
+
save_vars { ::GDBFLAGS } {
append ::GDBFLAGS " -ex \"maintenance set target-non-stop on\""
clean_restart $::binfile
diff --git a/gdb/testsuite/gdb.base/sigall.exp b/gdb/testsuite/gdb.base/sigall.exp
index b23e3c5..461a92b 100644
--- a/gdb/testsuite/gdb.base/sigall.exp
+++ b/gdb/testsuite/gdb.base/sigall.exp
@@ -41,13 +41,14 @@ proc test_one_sig {nextsig} {
setup_xfail "i*86-pc-linuxoldld-gnu" "i*86-pc-linuxaout-gnu"
}
# On Linux SPARC64 systems SIGLOST==SIGPWR and gdb identifies
- # the raised signal as PWR.
- if {$thissig == "LOST" && [istarget "sparc64-*-linux*"]} {
+ # the raised signal as PWR. Same for Cygwin.
+ if {$thissig == "LOST"
+ && ([istarget "sparc64-*-linux*"] || [istarget "*-*-cygwin*"])} {
set esig "PWR"
}
gdb_test "continue" \
- "Continuing.*Program received signal SIG$esig.*" \
+ "Continuing.* received signal SIG$esig.*" \
"get signal $esig"
}
@@ -177,7 +178,7 @@ gdb_test "handle SIGTERM stop print" \
"SIGTERM\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes.*"
gdb_test "b handle_TERM" "Breakpoint \[0-9\]+ .*"
gdb_test "continue" \
- "Continuing.*Program received signal SIGTERM.*" \
+ "Continuing.* received signal SIGTERM.*" \
"get signal TERM"
gdb_test "continue" "Breakpoint.*handle_TERM.*" "send signal TERM"
gdb_continue_to_end "continue to sigall exit"
diff --git a/gdb/testsuite/gdb.base/source-dir.exp b/gdb/testsuite/gdb.base/source-dir.exp
index b2bf78c..3b0c5dd 100644
--- a/gdb/testsuite/gdb.base/source-dir.exp
+++ b/gdb/testsuite/gdb.base/source-dir.exp
@@ -62,7 +62,7 @@ proc test_truncated_comp_dir {} {
# /some/path/to/gdb/build/testsuite/
# We are going to copy the source file out of the source tree into
# a location like this:
- # /some/path/to/gdb/build/testsuite/output/gdb.base/soure-dir/
+ # /some/path/to/gdb/build/testsuite/output/gdb.base/source-dir/
#
# We will then switch to this directory and compile the source
# file, however, we will ask GCC to remove this prefix from the
@@ -87,11 +87,12 @@ proc test_truncated_comp_dir {} {
return
}
- set working_dir [standard_output_file ""]
+ set working_dir [build_standard_output_file ""]
with_cwd $working_dir {
- set strip_dir [file normalize "${working_dir}/../.."]
+ set strip_dir [build_file_normalize "${working_dir}/../.."]
+ set h_strip_dir [host_file_normalize $strip_dir]
- set new_srcfile [standard_output_file ${srcfile}]
+ set new_srcfile [build_standard_output_file ${srcfile}]
set fd [open "$new_srcfile" w]
puts $fd "int
main ()
@@ -100,8 +101,17 @@ proc test_truncated_comp_dir {} {
}"
close $fd
+ # We ask GCC to remove both the build and host views of the
+ # path, because we don't know which one GCC uses. E.g., we're
+ # testing on MSYS2 with an MSYS2 cross-compiler that targets
+ # MinGW, then the path GCC uses is a Unix path. If OTOH we're
+ # testing on MSYS2 with a native Windows compiler, then the
+ # path GCC uses is a Windows path.
set options \
- "debug additional_flags=-fdebug-prefix-map=${strip_dir}="
+ [list \
+ "debug" \
+ "additional_flags=-fdebug-prefix-map=${strip_dir}=" \
+ "additional_flags=-fdebug-prefix-map=${h_strip_dir}="]
if { [gdb_compile "${srcfile}" "${binfile}" \
executable ${options}] != "" } {
untested "failed to compile"
@@ -133,9 +143,9 @@ proc test_truncated_comp_dir {} {
"Does not include preprocessor macro info." ] \
"info source before setting directory search list"
- gdb_test "dir $strip_dir" \
+ gdb_test "dir $h_strip_dir" \
[search_dir_list [list \
- "$strip_dir" \
+ "$h_strip_dir" \
"\\\$cdir" \
"\\\$cwd"]] \
"setup source path search directory"
@@ -146,17 +156,23 @@ proc test_truncated_comp_dir {} {
"4\[ \t\]+return 0;" \
"5\[ \t\]+\\}" ]
- gdb_test "info source" \
- [multi_line \
- "Current source file is ${srcfile}" \
- "Compilation directory is \[^\n\r\]+" \
- "Located in ${new_srcfile}" \
- "Contains 5 lines." \
- "Source language is c." \
- "Producer is \[^\n\r\]+" \
- "\[^\n\r\]+" \
- "\[^\n\r\]+" ] \
- "info source after setting directory search list"
+ set re [multi_line \
+ "Current source file is ${srcfile}" \
+ "Compilation directory is \[^\n\r\]+" \
+ "Located in (\[^\n\r\]+)" \
+ "Contains 5 lines." \
+ "Source language is c." \
+ "Producer is \[^\n\r\]+" \
+ "\[^\n\r\]+" \
+ "\[^\n\r\]+"]
+ set test "info source after setting directory search list"
+ gdb_test_multiple "info source" $test {
+ -re -wrap "$re" {
+ set host_new_srcfile [host_file_normalize $new_srcfile]
+ set host_location [host_file_sanitize $expect_out(1,string)]
+ gdb_assert {$host_new_srcfile eq $host_location} $gdb_test_name
+ }
+ }
}
proc test_change_search_directory_with_empty_dirname {} {
diff --git a/gdb/testsuite/gdb.base/source-search.c b/gdb/testsuite/gdb.base/source-search.c
new file mode 100644
index 0000000..2320c5c
--- /dev/null
+++ b/gdb/testsuite/gdb.base/source-search.c
@@ -0,0 +1,127 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+int
+main (void)
+{
+ /* Line 21 */
+ /* Line 22 */
+ /* Line 23 */
+ /* Line 24 */
+ /* Line 25 */
+ /* Line 26 */
+ /* Line 27 */
+ /* Line 28 */
+ /* Line 29 */
+ /* Line 30 */
+ /* Line 31 */
+ /* Line 32 */
+ /* Line 33 */
+ /* Line 34 */
+ /* Line 35 */
+ /* Line 36 */
+ /* Line 37 */
+ /* Line 38 */
+ /* Line 39 */
+ /* Line 40 */
+ /* Line 41 */
+ /* Line 42 */
+ /* Line 43 */
+ /* Line 44 */
+ /* Line 45 */
+ /* Line 46 */
+ /* Line 47 */
+ /* Line 48 */
+ /* Line 49 */
+ /* Line 50 */
+ /* Line 51 */
+ /* Line 52 */
+ /* Line 53 */
+ /* Line 54 */
+ /* Line 55 */
+ /* Line 56 */
+ /* Line 57 */
+ /* Line 58 */
+ /* Line 59 */
+ /* Line 60 */
+ /* Line 61 */
+ /* Line 62 */
+ /* Line 63 */
+ /* Line 64 */
+ /* Line 65 */
+ /* Line 66 */
+ /* Line 67 */
+ /* Line 68 */
+ /* Line 69 */
+ /* Line 70 */
+ /* Line 71 */
+ /* Line 72 */
+ /* Line 73 */
+ /* Line 74 */
+ /* Line 75 */
+ /* Line 76 */
+ /* Line 77 */
+ /* Line 78 */
+ /* Line 79 */
+ /* Line 80 */
+ /* Line 81 */
+ /* Line 82 */
+ /* Line 83 */
+ /* Line 84 */
+ /* Line 85 */
+ /* Line 86 */
+ /* Line 87 */
+ /* Line 88 */
+ /* Line 89 */
+ /* Line 90 */
+ /* Line 91 */
+ /* Line 92 */
+ /* Line 93 */
+ /* Line 94 */
+ /* Line 95 */
+ /* Line 96 */
+ /* Line 97 */
+ /* Line 98 */
+ /* Line 99 */
+ /* Line 100 */
+ /* Line 101 */
+ /* Line 102 */
+ /* Line 103 */
+ /* Line 104 */
+ /* Line 105 */
+ /* Line 106 */
+ /* Line 107 */
+ /* Line 108 */
+ /* Line 109 */
+ /* Line 110 */
+ /* Line 111 */
+ /* Line 112 */
+ /* Line 113 */
+ /* Line 114 */
+ /* Line 115 */
+ /* Line 116 */
+ /* Line 117 */
+ /* Line 118 */
+ /* Line 119 */
+ /* Line 120 */
+ /* Line 121 */
+ /* Line 122 */
+ /* Line 123 */
+ /* Line 124 */
+ /* Line 125 */
+ return 0;
+} /* Last line. */
diff --git a/gdb/testsuite/gdb.base/source-search.exp b/gdb/testsuite/gdb.base/source-search.exp
new file mode 100644
index 0000000..559c500
--- /dev/null
+++ b/gdb/testsuite/gdb.base/source-search.exp
@@ -0,0 +1,106 @@
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test 'forward-search' and 'reverse-search' commands. This test
+# relies on some hard-coded line numbers relating to the source file.
+# We could switch to using gdb_get_line_number, but it doesn't feel
+# like that would add much value; just don't change the source file.
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+ return
+}
+
+gdb_test "forward-search This testcase is part" \
+ "1\\s+/\\* This testcase is part of GDB, the GNU debugger\\." \
+ "search for first line of the file"
+
+gdb_test "forward-search This testcase is part" \
+ "Expression not found" \
+ "repeated search doesn't find the same first line"
+
+# The 'reverse-search' command starts searching from the line before
+# the last line displayed. So in this case, the reverse search starts
+# from line 0, i.e. nothing is searched.
+gdb_test "reverse-search This testcase is part" \
+ "Expression not found" \
+ "reverse search doesn't find the first line either"
+
+# List some source lines, and then perform some forward-searches. The
+# searches start from the first line after the last line displayed.
+gdb_test "list 20" ".*" \
+ "list source code ahead of a forward-search"
+gdb_test "forward-search Line 2" \
+ "25\\s+/\\* Line 25 \\*/" \
+ "first forward-search after a list"
+gdb_test "forward-search Line 2" \
+ "26\\s+/\\* Line 26 \\*/" \
+ "second forward-search after a list"
+gdb_test "forward-search Line 2" \
+ "27\\s+/\\* Line 27 \\*/" \
+ "third forward-search after a list"
+
+# Now reverse-search from where we got too.
+gdb_test "reverse-search Line 2" \
+ "26\\s+/\\* Line 26 \\*/" \
+ "first reverse-search for 'Line 2'"
+gdb_test "reverse-search Line 2" \
+ "25\\s+/\\* Line 25 \\*/" \
+ "second reverse-search for 'Line 2'"
+gdb_test "reverse-search Line 2" \
+ "24\\s+/\\* Line 24 \\*/" \
+ "third reverse-search for 'Line 2'"
+
+# List some source lines, and then perform a reverse-search. The
+# search starts frm the first line before the last line displayed.
+gdb_test "list 20" ".*" \
+ "list source code ahead of a reverse-search"
+gdb_test "reverse-search Line 2" \
+ "23\\s+/\\* Line 23 \\*/" \
+ "reverse-search after a list"
+
+# List the last lines of the file, then reverse search for the last
+# line. As reverse-search starts on the line before the last line
+# displayed, this will fail to find the last line.
+gdb_test "list 127"
+gdb_test "reverse-search Last line" \
+ "Expression not found" \
+ "reverse search for the last line fails"
+
+# List some lines from the middle of the file. Then try an invalid
+# 'list' command. Finally, check searches pick up from the middle of
+# the file where the first 'list' successfully completed.
+foreach_with_prefix search_direction { forward reverse } {
+ foreach_with_prefix bad_list { out-of-range backwards } {
+ gdb_test "list 50"
+
+ if { $bad_list eq "out-of-range" } {
+ gdb_test "list 1000" \
+ "Line number 995 out of range; \[^\r\n\]+ has 127 lines\\."
+ } else {
+ gdb_test_no_output "list 60,50"
+ }
+
+ if { $search_direction eq "forward" } {
+ set line 55
+ } else {
+ set line 53
+ }
+
+ gdb_test "${search_direction}-search Line" \
+ "$line\\s+/\\* Line $line \\*/"
+ }
+}
diff --git a/gdb/testsuite/gdb.base/startup-with-shell.exp b/gdb/testsuite/gdb.base/startup-with-shell.exp
index 80dfdf3..9c016b4 100644
--- a/gdb/testsuite/gdb.base/startup-with-shell.exp
+++ b/gdb/testsuite/gdb.base/startup-with-shell.exp
@@ -22,6 +22,8 @@ require !use_gdb_stub
# (via dejagnu) yet.
require {!is_remote target}
+require {expr [have_startup_shell] != -1}
+
standard_testfile
if { [build_executable "failed to prepare" $testfile $srcfile debug] } {
diff --git a/gdb/testsuite/gdb.base/step-over-exit.exp b/gdb/testsuite/gdb.base/step-over-exit.exp
index 2370f97..6dfa7bb 100644
--- a/gdb/testsuite/gdb.base/step-over-exit.exp
+++ b/gdb/testsuite/gdb.base/step-over-exit.exp
@@ -13,11 +13,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-standard_testfile
-
# Test a thread is doing step-over a syscall instruction which is exit,
# and GDBserver should cleanup its state of step-over properly.
+# The testcase relies on follow-fork-mode child.
+require allow_fork_tests
+
+standard_testfile
+
set syscall_insn ""
# Define the syscall instruction for each target.
diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index c10be3b..6b1b08e 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+require {!is_remote host}
+
load_lib gdb-python.exp
# Test CLI output styling.
@@ -323,10 +325,10 @@ proc run_style_tests { } {
gdb_test_no_output "set style version background 255"
gdb_test_no_output "set style version foreground #FED210"
gdb_test "show style version background" \
- "The \033\\\[38;2;254;210;16;48;5;255;22;27m.*\".*version.*\".*style.*\033\\\[m background color is: 255" \
+ "The \033\\\[38;2;254;210;16;48;5;255;22;23;24;27m.*\".*version.*\".*style.*\033\\\[m background color is: 255" \
"Version's 256-color background style"
gdb_test "show style version foreground" \
- "The \033\\\[38;2;254;210;16;48;5;255;22;27m.*\".*version.*\".*style.*\033\\\[m foreground color is: #FED210" \
+ "The \033\\\[38;2;254;210;16;48;5;255;22;23;24;27m.*\".*version.*\".*style.*\033\\\[m foreground color is: #FED210" \
"Version's TrueColor foreground style"
}
@@ -751,6 +753,286 @@ proc test_enable_styling_warning { } {
}
}
+# Run an 'apropos' command. Each line of output starts with a
+# non-default style (command style). Ensure that pagination triggers
+# during the 'apropos' output such that, at the point pagination kicks
+# in, a non-default style is in effect.
+#
+# Then, at the pagination prompt, quit the command.
+#
+# Next, run a command which switches to a different style, and then
+# back to the current style.
+#
+# At one point, a bug in the pagination code would leave the
+# non-default style from the 'apropos' command recorded as the current
+# style, such that the second command would switch back to the earlier
+# style.
+proc test_pagination_cmd_after_quit_styling {} {
+ with_ansi_styling_terminal {
+ clean_restart
+ }
+
+ # We're going to use 'apropos time'. Check that with a height of
+ # 12 lines, each line starts with a non-default style, and that we
+ # do see the pagination prompt. This means that there are more
+ # than 12 lines for this command.
+ with_test_prefix "validate apropos output" {
+ gdb_test_no_output "set height 12"
+
+ set saw_pagination_prompt false
+ gdb_test_multiple "apropos time" "" {
+ -re "^apropos time\r\n" {
+ exp_continue
+ }
+ -re "^\033\\\[39;49;1;23;24;27m\[^\r\n\]+\r\n" {
+ exp_continue
+ }
+ -re "^$::pagination_prompt$" {
+ set saw_pagination_prompt true
+ send_gdb "q\n"
+ exp_continue
+ }
+ -re "^q\r\n" {
+ exp_continue
+ }
+ -re "^Quit\r\n" {
+ exp_continue
+ }
+ -re "^$::gdb_prompt $" {
+ gdb_assert { $saw_pagination_prompt } $gdb_test_name
+ }
+ -re "^\[^\r\n\]+\r\n" {
+ exp_continue
+ }
+ }
+ }
+
+ # Now reduce the height to 10 and re-run 'apropos time'. Based on
+ # the previous check, we know that this is going to present the
+ # pagination prompt when a non-default style is in use.
+ gdb_test_no_output "set height 10"
+
+ set saw_pagination_prompt false
+ gdb_test_multiple "apropos time" "" {
+ -re "$::pagination_prompt" {
+ set saw_pagination_prompt true
+ send_gdb "q\n"
+ exp_continue
+ }
+ -re "\r\n$::gdb_prompt $" {
+ gdb_assert { $saw_pagination_prompt } $gdb_test_name
+ }
+ }
+
+ # The help output for this maintenance command switches to a
+ # different style, and then back to the default. If the
+ # pagination bug still exists, then this would switch back to the
+ # non-default style that was in use when pagination kicked in
+ # above.
+ gdb_test "maintenance time" \
+ "^\"\033\\\[39;49;1;23;24;27mmaintenance time\033\\\[m\" takes a numeric argument\\."
+}
+
+# Helper for test_pagination_prompt_styling. Return false if STR, a
+# line that appears immediately before a pagination prompt, matches
+# the pattern for needing a style reset at the end, but does not have
+# the style reset.
+#
+# In all other cases, return true. So lines that don't match the
+# known pattern for neededing a style reset will always return true,
+# as will lines that match the pattern, and do have the style reset.
+proc previous_line_is_ok { str } {
+
+ # Create a copy of STR with all the '\033' characters removed.
+ # Then compare string lengths to get a count of the '\033'
+ # charactes present in STR.
+ regsub -all "\033" $str {} stripped
+ set count [expr [string length $str] - [string length $stripped]]
+
+ # If STR switched styles, then it _must_ switch back again,
+ # otherwise the pagination prompt will be in the wrong style.
+ # This means that there _must_ be an even number of '\033'
+ # characters in STR. If there is not then we switched style, but
+ # failed to switch back.
+ if { [expr $count % 2] != 0 } {
+ return false
+ }
+
+ # For lines that don't match this pattern, we cannot comment on
+ # where the style reset should occur, so lets just claim the line
+ # is fine.
+ if { ![regexp "\\s+$::hex - $::hex is \[^\r\n\]+ in \033" $str] } {
+ return true
+ }
+
+ # This line did match the above pattern, so we know that a style
+ # reset _must_ occur at the end of the line. If it doesn't then
+ # this line is not OK.
+ if { ![regexp "\033\\\[m$" $str] } {
+ return false
+ }
+
+ # All tests passed, this line looks OK.
+ return true
+}
+
+# Test that the pagination prompt is displayed unstyled. This is done
+# by looking at the 'info files' output and selecting a width that
+# will mean we should get a pagination prompt part way through a
+# styled filename.
+#
+# Then, re-run 'info files' and check that for every pagination
+# prompt, the previous line disables styling as expected.
+proc test_pagination_prompt_styling {} {
+ with_ansi_styling_terminal {
+ clean_restart $::binfile
+ }
+
+ if {![runto_main]} {
+ return
+ }
+
+ # Set height so we actually get a pagination prompt.
+ gdb_test_no_output "set height 3"
+
+ # Scan the 'info files' output and set DESIRED_WIDTH such that it
+ # will trigger pagination part-way through a styled filename.
+ set desired_width 0
+ gdb_test_multiple "info files" "find good test width" {
+ -re "^info files\r\n" {
+ exp_continue
+ }
+
+ -re "^$::pagination_prompt$" {
+ send_gdb "\n"
+ exp_continue
+ }
+
+ -re "^$::gdb_prompt $" {
+ }
+
+ -re "^((\\s+$::hex - $::hex is \[^\r\n\]+ in )\[^\r\n\]+)\r\n" {
+ if { $desired_width == 0 } {
+ set full_line $expect_out(1,string)
+ set inner_line $expect_out(2,string)
+ set desired_width [expr [string length $inner_line] + ([string length $full_line] - [string length $inner_line]) / 2]
+ }
+ exp_continue
+ }
+
+ -re "^\[^\r\n\]*\r\n" {
+ exp_continue
+ }
+ }
+
+ if { $desired_width < [string length $::pagination_prompt_str] + 2 } {
+ # Avoid readline wrapping after printing the pagination prompt.
+ return
+ }
+
+ # Now setup the screen width.
+ gdb_test_no_output "set width $desired_width" \
+ "set width to desired width"
+
+ # Re-run 'info files'. Check that the content before any
+ # pagination prompt correctly disables styling.
+ set saw_bad_line false
+ set prev_line ""
+ gdb_test_multiple "info files" "check pagination prompt styling" {
+ -re "^info files\r\n" {
+ exp_continue
+ }
+
+ -re "^$::pagination_prompt$" {
+ if { ![previous_line_is_ok $prev_line] } {
+ set saw_bad_line true
+ }
+ send_gdb "\n"
+ exp_continue
+ }
+
+ -re "^(\[^\r\n\]+)$::pagination_prompt$" {
+ set prev_line $expect_out(1,string)
+ if { ![previous_line_is_ok $prev_line] } {
+ set saw_bad_line true
+ }
+ send_gdb "\n"
+ exp_continue
+ }
+
+ -re "^$::gdb_prompt $" {
+ gdb_assert { !$saw_bad_line } $gdb_test_name
+ }
+
+ -re "^(\[^\r\n\]*)\r\n" {
+ set prev_line $expect_out(1,string)
+ exp_continue
+ }
+ }
+}
+
+# Test that GDB can correctly restore the current style after a
+# pagination prompt.
+#
+# Set the logging file to a garbage string based on LENGTH (is
+# actually 2x LENGTH), then 'show logging file'. Press return at the
+# pagination prompt, and check that the reset of the filename is
+# styled correctly, and that GDB correctly switches back to the
+# default style once the logging file has finished.
+proc test_pagination_continue_styling_1 { length } {
+ with_ansi_styling_terminal {
+ clean_restart $::binfile
+ }
+
+ set filename [string repeat "ax" $length]
+
+ gdb_test_no_output "set logging file $filename"
+
+ gdb_test_no_output "set height 3"
+ gdb_test_no_output "set width 80"
+
+ set saw_bad_styling false
+ gdb_test_multiple "show logging file" "" {
+ -re "^show logging file\r\n" {
+ exp_continue
+ }
+
+ -re "^The current logfile is \"\033\\\[32;49;22;23;24;27m(?:ax)+\033\\\[m" {
+ exp_continue
+ }
+
+ -re "^\r\n\033\\\[32;49;22;23;24;27m(?:ax)+\033\\\[m(?=--)" {
+ exp_continue
+ }
+
+ -re "^\r\n\033\\\[32;49;22;23;24;27m(?:ax)+(?=--)" {
+ set saw_bad_styling true
+ exp_continue
+ }
+
+ -re "^\r\n\033\\\[32;49;22;23;24;27m(?:ax)+\033\\\[m\"\\.\r\n" {
+ exp_continue
+ }
+
+ -re "^$::gdb_prompt $" {
+ gdb_assert { !$saw_bad_styling } $gdb_test_name
+ }
+
+ -re "^$::pagination_prompt$$" {
+ send_gdb "\n"
+ exp_continue
+ }
+ }
+}
+
+# Wrapper around test_pagination_continue_styling_1, calls that
+# function with different lengths.
+proc test_pagination_continue_styling { } {
+ foreach_with_prefix length { 80 160 } {
+ test_pagination_continue_styling_1 $length
+ }
+}
+
# Check to see if the Python styling of disassembler output is
# expected or not, this styling requires Python support in GDB, and
# the Python pygments module to be available.
@@ -793,3 +1075,6 @@ test_colorsupport_truecolor
test_colorsupport_truecolor_only
test_enable_styling_warning
+test_pagination_cmd_after_quit_styling
+test_pagination_prompt_styling
+test_pagination_continue_styling
diff --git a/gdb/testsuite/gdb.base/tls-common.exp.tcl b/gdb/testsuite/gdb.base/tls-common.exp.tcl
index 7aa7f46..fc212a9 100644
--- a/gdb/testsuite/gdb.base/tls-common.exp.tcl
+++ b/gdb/testsuite/gdb.base/tls-common.exp.tcl
@@ -1,4 +1,4 @@
-# Copyright 2024 Free Software Foundation, Inc.
+# Copyright 2024-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
diff --git a/gdb/testsuite/gdb.base/tls-dlobj-lib.c b/gdb/testsuite/gdb.base/tls-dlobj-lib.c
index c69bab7..e82a064 100644
--- a/gdb/testsuite/gdb.base/tls-dlobj-lib.c
+++ b/gdb/testsuite/gdb.base/tls-dlobj-lib.c
@@ -1,6 +1,6 @@
/* This testcase is part of GDB, the GNU debugger.
- Copyright 2024 Free Software Foundation, Inc.
+ Copyright 2024-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/testsuite/gdb.base/tls-dlobj.c b/gdb/testsuite/gdb.base/tls-dlobj.c
index 322bdda..a93f4a7 100644
--- a/gdb/testsuite/gdb.base/tls-dlobj.c
+++ b/gdb/testsuite/gdb.base/tls-dlobj.c
@@ -1,6 +1,6 @@
/* This testcase is part of GDB, the GNU debugger.
- Copyright 2024 Free Software Foundation, Inc.
+ Copyright 2024-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/testsuite/gdb.base/tls-dlobj.exp b/gdb/testsuite/gdb.base/tls-dlobj.exp
index 02f2ff8..32e869e 100644
--- a/gdb/testsuite/gdb.base/tls-dlobj.exp
+++ b/gdb/testsuite/gdb.base/tls-dlobj.exp
@@ -1,4 +1,4 @@
-# Copyright 2024 Free Software Foundation, Inc.
+# Copyright 2024-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
diff --git a/gdb/testsuite/gdb.base/tls-multiobj.c b/gdb/testsuite/gdb.base/tls-multiobj.c
index 10e67da..dd4aadb 100644
--- a/gdb/testsuite/gdb.base/tls-multiobj.c
+++ b/gdb/testsuite/gdb.base/tls-multiobj.c
@@ -1,6 +1,6 @@
/* This testcase is part of GDB, the GNU debugger.
- Copyright 2024 Free Software Foundation, Inc.
+ Copyright 2024-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/testsuite/gdb.base/tls-multiobj.exp b/gdb/testsuite/gdb.base/tls-multiobj.exp
index 97acb33..2a52610 100644
--- a/gdb/testsuite/gdb.base/tls-multiobj.exp
+++ b/gdb/testsuite/gdb.base/tls-multiobj.exp
@@ -1,4 +1,4 @@
-# Copyright 2024 Free Software Foundation, Inc.
+# Copyright 2024-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
diff --git a/gdb/testsuite/gdb.base/tls-multiobj1.c b/gdb/testsuite/gdb.base/tls-multiobj1.c
index 86e7222..6207173 100644
--- a/gdb/testsuite/gdb.base/tls-multiobj1.c
+++ b/gdb/testsuite/gdb.base/tls-multiobj1.c
@@ -1,6 +1,6 @@
/* This testcase is part of GDB, the GNU debugger.
- Copyright 2024 Free Software Foundation, Inc.
+ Copyright 2024-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/testsuite/gdb.base/tls-multiobj2.c b/gdb/testsuite/gdb.base/tls-multiobj2.c
index cea0709..9ff8b67 100644
--- a/gdb/testsuite/gdb.base/tls-multiobj2.c
+++ b/gdb/testsuite/gdb.base/tls-multiobj2.c
@@ -1,6 +1,6 @@
/* This testcase is part of GDB, the GNU debugger.
- Copyright 2024 Free Software Foundation, Inc.
+ Copyright 2024-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/testsuite/gdb.base/tls-multiobj3.c b/gdb/testsuite/gdb.base/tls-multiobj3.c
index bb0f239..3594eba0 100644
--- a/gdb/testsuite/gdb.base/tls-multiobj3.c
+++ b/gdb/testsuite/gdb.base/tls-multiobj3.c
@@ -1,6 +1,6 @@
/* This testcase is part of GDB, the GNU debugger.
- Copyright 2024 Free Software Foundation, Inc.
+ Copyright 2024-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/testsuite/gdb.base/tls-nothreads.c b/gdb/testsuite/gdb.base/tls-nothreads.c
index b3aaa33..cac20f8 100644
--- a/gdb/testsuite/gdb.base/tls-nothreads.c
+++ b/gdb/testsuite/gdb.base/tls-nothreads.c
@@ -1,6 +1,6 @@
/* This testcase is part of GDB, the GNU debugger.
- Copyright 2024 Free Software Foundation, Inc.
+ Copyright 2024-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/gdb/testsuite/gdb.base/tls-nothreads.exp b/gdb/testsuite/gdb.base/tls-nothreads.exp
index 92a5cd9..105e686 100644
--- a/gdb/testsuite/gdb.base/tls-nothreads.exp
+++ b/gdb/testsuite/gdb.base/tls-nothreads.exp
@@ -1,4 +1,4 @@
-# Copyright 2024 Free Software Foundation, Inc.
+# Copyright 2024-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
diff --git a/gdb/testsuite/gdb.base/user-namespace-attach.c b/gdb/testsuite/gdb.base/user-namespace-attach.c
new file mode 100644
index 0000000..684ce1c
--- /dev/null
+++ b/gdb/testsuite/gdb.base/user-namespace-attach.c
@@ -0,0 +1,35 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+
+volatile int spin_p = 1;
+
+int
+main ()
+{
+ alarm (60);
+
+ printf ("pid = %lld\n", ((long long) getpid ()));
+
+ while (spin_p)
+ sleep (1);
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/user-namespace-attach.exp b/gdb/testsuite/gdb.base/user-namespace-attach.exp
new file mode 100644
index 0000000..741093c
--- /dev/null
+++ b/gdb/testsuite/gdb.base/user-namespace-attach.exp
@@ -0,0 +1,148 @@
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check that GDB can attach to a process started using 'unshare'. The
+# inferior is started in a separate mnt namespace.
+
+require can_spawn_for_attach
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile] == -1} {
+ return
+}
+
+# This test relies (at least in some parts) on the sysroot being
+# 'target:'. Grab the current sysroot now so we can skip those tests
+# if the board file has changed the sysroot.
+set sysroot ""
+set test "show sysroot"
+gdb_test_multiple $test $test {
+ -re -wrap "The current system root is \"(.*)\"\\." {
+ set sysroot $expect_out(1,string)
+ }
+}
+
+# Start a process using 'unshare FLAGS', then attach to the process
+# from GDB. Check that the attach worked as expected.
+proc run_test { flags } {
+
+ # If FLAGS contains '--mount' then a separate mnt namespace will
+ # be created, in which case the executable will have been read
+ # from the 'target:'. Otherwise, the executable will have been
+ # read from the local filesystem, and there will be no prefix.
+ #
+ # Of course, this only applies if the sysroot is 'target:', some
+ # boards change this, so skip these tests on those boards.
+ if { [lsearch -exact [split $flags " "] "--mount"] != -1 } {
+ if { $::sysroot ne "target:" } {
+ return
+ }
+
+ set prefix "target:"
+ } else {
+ set prefix ""
+ }
+
+ set unshare_cmd "unshare $flags"
+
+ # Run '/bin/true' using UNSHARE_CMD. If the flags in UNSHARE_CMD
+ # aren't supported then this will fail, this means we shouldn't
+ # spawn the command with our test executable and try attaching.
+ #
+ # This will also fail if /bin/true isn't present, or doesn't work
+ # as we expect. But this should be fine for many targets.
+ set res [remote_exec target "$unshare_cmd /bin/true"]
+ if { [lindex $res 0] != 0 } {
+ unsupported "unshare flags not supported"
+ return
+ }
+
+ set inferior_spawn_id \
+ [spawn_wait_for_attach [list "$unshare_cmd $::binfile"]]
+ if { $inferior_spawn_id == -1 } {
+ unsupported "failed to spawn for attach"
+ return
+ }
+
+ set inferior_pid [spawn_id_get_pid $inferior_spawn_id]
+
+ clean_restart
+
+ set saw_bad_warning false
+ gdb_test_multiple "attach $inferior_pid" "attach to inferior" {
+ -re "^attach $::decimal\r\n" {
+ exp_continue
+ }
+
+ -re "^warning: \[^\r\n\]+: could not open as an executable file: \[^\r\n\]+\r\n" {
+ set saw_bad_warning true
+ exp_continue
+ }
+
+ -re "^warning: \[^\r\n\]+: can't open to read symbols: \[^\r\n\]+\r\n" {
+ set saw_bad_warning true
+ exp_continue
+ }
+
+ -re "^warning: Could not load vsyscall page because no executable was specified\r\n" {
+ # This warning is a secondary consequence of the above bad
+ # warnings, so don't count this as a bad warnings, ignore
+ # it instead.
+ exp_continue
+ }
+
+ -re "^warning:\\s+$::decimal\\s*\[^\r\n\]+: No such file or directory\r\n" {
+ # This unrelated warning is seen when GDB stops in libc,
+ # and the source code for libc is not available.
+ exp_continue
+ }
+
+ -re "^warning: \[^\r\n\]+\r\n" {
+ # If we ignore "other" warnings then, should the above
+ # warnings strings change we'll start ignoring the bad
+ # warnings, and the test will appear to pass.
+ #
+ # If you are seeing a warning here that really has nothing
+ # to do with the test failing, then the correct solution
+ # is to add a new regexp to specifically match _that_
+ # warning, and ignore it.
+ set saw_bad_warning true
+ exp_continue
+ }
+
+ -re "^$::gdb_prompt $" {
+ gdb_assert { !$saw_bad_warning } $gdb_test_name
+ }
+
+ -re "^\[^\r\n\]*\r\n" {
+ exp_continue
+ }
+ }
+
+ # Ensure GDB could access the executable.
+ set binfile_re [string_to_regexp $::binfile]
+ gdb_test "info inferiors" \
+ "\r\n\\*\\s+$::decimal\\s+\[^\r\n\]+\\s+${prefix}${binfile_re}\\s*"
+}
+
+set test_flags [list \
+ "--mount --map-root-user" \
+ "--user" \
+ "--user --map-root-user"]
+
+foreach_with_prefix flags $test_flags {
+ run_test $flags
+}
diff --git a/gdb/testsuite/gdb.base/vfork-follow-parent.exp b/gdb/testsuite/gdb.base/vfork-follow-parent.exp
index fca2993..8cb785d 100644
--- a/gdb/testsuite/gdb.base/vfork-follow-parent.exp
+++ b/gdb/testsuite/gdb.base/vfork-follow-parent.exp
@@ -19,6 +19,8 @@
# schedule-multiple on" or "set detach-on-fork on". Test these two resolution
# methods.
+require allow_fork_tests
+
standard_testfile .c vforked-prog.c
set binfile ${testfile}-exit
diff --git a/gdb/testsuite/gdb.base/watch-before-fork.exp b/gdb/testsuite/gdb.base/watch-before-fork.exp
index 074cfbd..509561e 100644
--- a/gdb/testsuite/gdb.base/watch-before-fork.exp
+++ b/gdb/testsuite/gdb.base/watch-before-fork.exp
@@ -20,6 +20,8 @@
# This test uses "awatch".
require allow_hw_watchpoint_access_tests
+require allow_fork_tests
+
standard_testfile
if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
diff --git a/gdb/testsuite/gdb.base/watch-vfork.exp b/gdb/testsuite/gdb.base/watch-vfork.exp
index 1bc61bc..503727d 100644
--- a/gdb/testsuite/gdb.base/watch-vfork.exp
+++ b/gdb/testsuite/gdb.base/watch-vfork.exp
@@ -17,6 +17,8 @@
standard_testfile .c
+require allow_fork_tests
+
if { [build_executable ${testfile}.exp ${testfile} $srcfile {debug}] } {
untested "failed to compile"
return -1
diff --git a/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp b/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp
index b3892f3..fa63edb 100644
--- a/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp
+++ b/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp
@@ -26,29 +26,18 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
return -1
}
-if ![runto_main] {
- return -1
-}
+set test_spawn_id [spawn_wait_for_attach $binfile]
+set testpid [spawn_id_get_pid $test_spawn_id]
-# Run to the point where mypid in the test program has been
-# populated.
-gdb_breakpoint [gdb_get_line_number "pidacquired"]
-gdb_continue_to_breakpoint "pidacquired"
-
-# Get the PID of the test process.
-set testpid [get_integer_valueof "mypid" 0]
+gdb_test "attach $testpid" "Attaching to program: .*, process $testpid.*" "attach once"
gdb_test "detach" "Detaching from program: .*, process $testpid\r\n\\\[Inferior $decimal \\(process $testpid\\) detached\\\]"
-if {$testpid == ""} {
- return -1
-}
-
# A clean restart is needed to force the hardware watchpoint setup
# logic to run post attach rather than post inferior launch.
clean_restart $binfile
-gdb_test "attach $testpid" "Attaching to program: .*, process $testpid.*" "attach"
+gdb_test "attach $testpid" "Attaching to program: .*, process $testpid.*" "attach twice"
# Ensure the test program is in the top frame so the required
# variables are in scope.
@@ -62,3 +51,5 @@ gdb_test "watch watched_variable" \
gdb_test "continue" \
"continue.*Continuing.*\.Hardware watchpoint $decimal: watched_variable.*Old value = 0.*New value = 4.*watched_variable\\);"
+
+kill_wait_spawned_process $test_spawn_id
diff --git a/gdb/testsuite/gdb.base/watchpoint-unaligned.c b/gdb/testsuite/gdb.base/watchpoint-unaligned.c
index d3c1349..ca2fa45 100644
--- a/gdb/testsuite/gdb.base/watchpoint-unaligned.c
+++ b/gdb/testsuite/gdb.base/watchpoint-unaligned.c
@@ -18,6 +18,8 @@
#include <stdint.h>
#include <assert.h>
+static volatile int volatile_dummy;
+
static int again;
static volatile struct
@@ -53,6 +55,40 @@ write_size8twice (void)
data.u.size8twice[offset] = first;
data.u.size8twice[offset + 1] = second;
#endif
+
+ /* Setting a breakpoint on an instruction after an instruction triggering a
+ watchpoint makes it ambiguous which one will be reported.
+ Insert a dummy instruction in between to make sure the watchpoint gets
+ reported. */
+ volatile_dummy = 1;
+
+ return; /* write_size8twice_return */
+}
+
+static void
+read_size8twice (void)
+{
+ static uint64_t volatile first;
+ static uint64_t volatile second;
+
+#ifdef __aarch64__
+ volatile void *p = &data.u.size8twice[offset];
+ asm volatile ("ldp %0, %1, [%2]"
+ : "=r" (first), "=r" (second) /* output */
+ : "r" (p) /* input */
+ : /* clobber */);
+#else
+ first = data.u.size8twice[offset];
+ second = data.u.size8twice[offset + 1];
+#endif
+
+ /* Setting a breakpoint on an instruction after an instruction triggering a
+ watchpoint makes it ambiguous which one will be reported.
+ Insert a dummy instruction inbetween to make sure the watchpoint gets
+ reported. */
+ volatile_dummy = 1;
+
+ return; /* read_size8twice_return */
}
int
@@ -63,6 +99,7 @@ main (void)
assert (sizeof (data) == 8 + 3 * 8);
write_size8twice ();
+ read_size8twice ();
while (size)
{
diff --git a/gdb/testsuite/gdb.base/watchpoint-unaligned.exp b/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
index 9220402..85b1eb7 100644
--- a/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
+++ b/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
@@ -151,6 +151,63 @@ foreach_with_prefix wpcount {4 7} {
gdb_assert $got_hit $test
}
+proc size8twice { function cmd offset index } {
+ clean_restart $::testfile
+
+ if { ![runto $function] } {
+ return -1
+ }
+
+ # Set offset in the inferior.
+ gdb_test_no_output "set var offset = $offset"
+
+ # Set a breakpoint.
+ set bp_src_string "${function}_return"
+ set bp_loc [gdb_get_line_number $bp_src_string]
+ gdb_breakpoint $bp_loc \
+ "Breakpoint $::decimal at $::hex" "$bp_src_string"
+
+ # Set a hardware watchpoint.
+ set watch_index [expr $offset + $index]
+ set test "$cmd data.u.size8twice\[$watch_index\]"
+ set wpnum 0
+ gdb_test_multiple $test "" {
+ -re -wrap "Hardware (read )?watchpoint ($::decimal): .*" {
+ set wpnum $expect_out(2,string)
+ pass $gdb_test_name
+ }
+ -re -wrap "Watchpoint ($::decimal): .*" {
+ if {[istarget "arm*-*-*"]} {
+ untested $gdb_test_name
+ } else {
+ fail $gdb_test_name
+ }
+ }
+ }
+
+ if { ! $wpnum } {
+ # No hardware watchpoint, we're done.
+ return 0
+ }
+
+ # Try to trigger the hardware watchpoint.
+ set got_hit 0
+ gdb_test_multiple "continue" "" {
+ -re -wrap "\r\nCould not insert hardware watchpoint .*" {
+ }
+ -re -wrap "Hardware (read )?watchpoint $wpnum:.*(New value|Value) = .*" {
+ set got_hit 1
+ send_gdb "continue\n"
+ exp_continue
+ }
+ -re -wrap " $bp_src_string .*" {
+ }
+ }
+ gdb_assert { $got_hit }
+
+ return $got_hit
+}
+
# We've got an array with 3 8-byte elements. Do a store of 16 bytes,
# to:
# - elements 0 and 1 (offset == 0), and
@@ -158,49 +215,21 @@ foreach_with_prefix wpcount {4 7} {
# For each case, check setting a watchpoint at:
# - the first written element (index == 0), and
# - the second element (index == 1).
-foreach_with_prefix offset { 0 1 } {
- foreach_with_prefix index { 0 1 } {
-
- clean_restart $binfile
-
- if ![runto_main] {
- return -1
- }
-
- gdb_test_no_output "set var offset = $offset"
- gdb_breakpoint [gdb_get_line_number "final_return"] \
- "Breakpoint $decimal at $hex" "final_return"
- set watch_index [expr $offset + $index]
- set test "watch data.u.size8twice\[$watch_index\]"
- set wpnum 0
- gdb_test_multiple $test $test {
- -re "Hardware watchpoint (\[0-9\]+): .*\r\n$gdb_prompt $" {
- set wpnum $expect_out(1,string)
- pass $gdb_test_name
- }
- -re "Watchpoint (\[0-9\]+): .*\r\n$gdb_prompt $" {
- if {[istarget "arm*-*-*"]} {
- untested $gdb_test_name
- } else {
- fail $gdb_test_name
- }
+foreach_with_prefix fun { write_size8twice read_size8twice } {
+ if { $fun == "write_size8twice" } {
+ set cmd "watch"
+ } else {
+ set cmd "rwatch"
+ }
+ foreach_with_prefix offset { 0 1 } {
+ foreach_with_prefix index { 0 1 } {
+ set res [size8twice $fun $cmd $offset $index]
+ if { $res != 1 } {
+ break
}
}
- if {$wpnum} {
- set test "continue"
- set got_hit 0
- gdb_test_multiple $test $test {
- -re "\r\nCould not insert hardware watchpoint .*\r\n$gdb_prompt $" {
- }
- -re "Hardware watchpoint $wpnum:.*New value = .*\r\n$gdb_prompt $" {
- set got_hit 1
- send_gdb "continue\n"
- exp_continue
- }
- -re " final_return .*\r\n$gdb_prompt $" {
- }
- }
- gdb_assert $got_hit "size8twice write"
+ if { $res != 1 } {
+ break
}
}
}
diff --git a/gdb/testsuite/gdb.base/wchar.exp b/gdb/testsuite/gdb.base/wchar.exp
index 70f738c..f0e4777 100644
--- a/gdb/testsuite/gdb.base/wchar.exp
+++ b/gdb/testsuite/gdb.base/wchar.exp
@@ -72,3 +72,7 @@ gdb_test "print repeat_p" "= $hex L\"A$cent$cent\"\.\.\." \
# From PR cli/14977, but here because it requires wchar_t.
gdb_test "printf \"%ls\\n\", 0" "\\(null\\)"
+
+# From PR exp/33124 - a bug when converting escapes.
+set wbs {L'\\'}
+gdb_test "print $wbs" " = $decimal [string_to_regexp $wbs]"
diff --git a/gdb/testsuite/gdb.btrace/multi-inferior.exp b/gdb/testsuite/gdb.btrace/multi-inferior.exp
index ed2acb2..d87a941 100644
--- a/gdb/testsuite/gdb.btrace/multi-inferior.exp
+++ b/gdb/testsuite/gdb.btrace/multi-inferior.exp
@@ -24,6 +24,8 @@
require allow_btrace_tests
+require allow_multi_inferior_tests
+
require !use_gdb_stub
standard_testfile
diff --git a/gdb/testsuite/gdb.cp/chained-calls.cc b/gdb/testsuite/gdb.cp/chained-calls.cc
index 9d12c98..9358c71 100644
--- a/gdb/testsuite/gdb.cp/chained-calls.cc
+++ b/gdb/testsuite/gdb.cp/chained-calls.cc
@@ -23,6 +23,8 @@ public:
S operator+ (const S &s);
+ int get ();
+
int a;
};
@@ -41,6 +43,12 @@ S::operator+ (const S &s)
return res;
}
+int
+S::get ()
+{
+ return a;
+}
+
S
f (int i)
{
@@ -162,6 +170,8 @@ public:
U (type t);
type get_type ();
+ int get ();
+
int a;
char c;
type tp[2];
@@ -191,6 +201,12 @@ U::get_type ()
}
int
+U::get ()
+{
+ return a;
+}
+
+int
main ()
{
int i = g(f(0));
@@ -198,6 +214,7 @@ main ()
B b = makeb ();
C c;
+ int z = f (42).get ();
return i + getb(b, 0); /* Break here */
}
diff --git a/gdb/testsuite/gdb.cp/chained-calls.exp b/gdb/testsuite/gdb.cp/chained-calls.exp
index 4f0597a..d34162c 100644
--- a/gdb/testsuite/gdb.cp/chained-calls.exp
+++ b/gdb/testsuite/gdb.cp/chained-calls.exp
@@ -42,3 +42,6 @@ gdb_test "p *c" ".* = {a = 5678}" "*c"
gdb_test "p *c + *c" ".* = {a = 11356}" "*c + *c"
gdb_test "p q(*c + *c)" ".* = {a = 11356}" "q(*c + *c)"
gdb_test "p make_int().get_type ()" ".* = INT" "make_int().get_type ()"
+gdb_test "p f(42).get()" " = 42" "f().get()"
+gdb_test "ptype f(42).get()" "type = int" "ptype f().get()"
+gdb_test "ptype make_int().get()" "type = int" "make_int().get()"
diff --git a/gdb/testsuite/gdb.cp/cpexprs.exp.tcl b/gdb/testsuite/gdb.cp/cpexprs.exp.tcl
index 1ac35af..5c3dfd6 100644
--- a/gdb/testsuite/gdb.cp/cpexprs.exp.tcl
+++ b/gdb/testsuite/gdb.cp/cpexprs.exp.tcl
@@ -28,17 +28,33 @@ proc test_breakpoint {func} {
delete_breakpoints
if { ! [gdb_breakpoint test_function] } {
fail "set test_function breakpoint for $func"
- } elseif { [gdb_test "continue" \
- "Continuing.\r\n\r\nBreakpoint $DEC+,.*test_function.*" \
- "continue to test_function for $func"] != 0 } {
- } else {
- gdb_breakpoint "$func"
- set i [expr {[string last : $func] + 1}]
- set efunc [string_to_regexp [string range $func $i end]]
- gdb_test "continue" \
- "Continuing.\r\n\r\nBreakpoint $DEC+,.*$efunc.*" \
- "continue to $func"
+ return
+ }
+
+ # Accept any input between "Continuing" and the breakpoint hit, as
+ # on Cygwin, we may see a "New Thread" notification. This is the
+ # Cygwin runtime spawning its own internal threads.
+ if { [gdb_test "continue" \
+ "Continuing.\r\n.*Breakpoint $DEC+,.*test_function.*" \
+ "continue to test_function for $func"] != 0 } {
+ return
}
+
+ # On some systems, the in-charge and not-in-charge dtors of a
+ # class may end up with the same address, so setting a breakpoint
+ # at a dtor like base::~base only finds one location. On other
+ # systems (e.g. Cygwin), the two dtors for the same class may have
+ # different addresses, so we find two locations for the
+ # breakpoint. Thus, expect that the breakpoint hit may or may not
+ # report a location number.
+ set bp_re "$DEC+(\.$DEC+)?"
+
+ gdb_breakpoint "$func"
+ set i [expr {[string last : $func] + 1}]
+ set efunc [string_to_regexp [string range $func $i end]]
+ gdb_test "continue" \
+ "Continuing.\r\n.*Breakpoint $bp_re,.*$efunc.*" \
+ "continue to $func"
}
# Add a function to the list of tested functions
diff --git a/gdb/testsuite/gdb.cp/method-ref-return.cc b/gdb/testsuite/gdb.cp/method-ref-return.cc
new file mode 100644
index 0000000..4169bfe
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/method-ref-return.cc
@@ -0,0 +1,42 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Test that we can access class method/data member via reference. */
+
+struct foo
+{
+ foo () : m_a (42) {}
+ int get_a () const { return m_a; }
+ int m_a;
+};
+
+struct bar
+{
+ bar () : m_foo () {}
+ const foo &get_foo () const { return m_foo; }
+ foo m_foo;
+};
+
+int
+main (int argc, char *argv[])
+{
+ bar b;
+ const foo &ref = b.get_foo ();
+ int ret = ref.m_a; // breakpoint here
+ ret += ref.get_a ();
+ return ret;
+} \ No newline at end of file
diff --git a/gdb/testsuite/gdb.cp/method-ref-return.exp b/gdb/testsuite/gdb.cp/method-ref-return.exp
new file mode 100644
index 0000000..1ac5ac9
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/method-ref-return.exp
@@ -0,0 +1,70 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test calling methods and accessing members via reference.
+
+require allow_cplus_tests
+
+standard_testfile .cc
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
+ return -1
+}
+
+if {![runto_main]} {
+ return -1
+}
+
+# Set a breakpoint after the bar object is created and the reference is obtained.
+gdb_breakpoint [gdb_get_line_number "breakpoint here"]
+gdb_continue_to_breakpoint "after reference assignment"
+
+# Test that we can call the method through reference and get the expected result.
+gdb_test_multiple "print b.get_foo()" "print method call returning reference" {
+ -re "\\$\[0-9\]+ = \\(const foo &\\) @$hex: \\{m_a = 42\\}\r\n$gdb_prompt $" {
+ pass $gdb_test_name
+ }
+ -re "Could not validate memory tag: Value can't be converted to integer\\." {
+ fail "$gdb_test_name"
+ }
+}
+
+# Test accessing the member through the reference.
+gdb_test "print b.get_foo ().m_a" \
+ "\\$\[0-9\]+ = 42" \
+ "print member access through reference"
+
+# Test calling method on the referenced object.
+gdb_test "print b.get_foo ().get_a()" \
+ "\\$\[0-9\]+ = 42" \
+ "print method call on referenced object"
+
+# Test that the stored reference works correctly.
+gdb_test_multiple "print ref" "print stored reference" {
+ -re "\\$\[0-9\]+ = \\(const foo &\\) @$hex: \\{m_a = 42\\}\r\n$gdb_prompt $" {
+ pass $gdb_test_name
+ }
+ -re "Could not validate memory tag: Value can't be converted to integer\\." {
+ fail "$gdb_test_name"
+ }
+}
+
+gdb_test "print ref.m_a" \
+ "\\$\[0-9\]+ = 42" \
+ "print member through stored reference"
+
+gdb_test "print ref.get_a()" \
+ "\\$\[0-9\]+ = 42" \
+ "print method call through stored reference" \ No newline at end of file
diff --git a/gdb/testsuite/gdb.cp/static-print-quit.exp b/gdb/testsuite/gdb.cp/static-print-quit.exp
index 8e0b61d..e4bce7f 100644
--- a/gdb/testsuite/gdb.cp/static-print-quit.exp
+++ b/gdb/testsuite/gdb.cp/static-print-quit.exp
@@ -27,32 +27,17 @@ clean_restart $testfile.o
gdb_test_no_output "set width 80"
gdb_test_no_output "set height 2"
-set test "print c - <return>"
-gdb_test_multiple "print c" $test {
- -re "\\$\[0-9\]+ = \{loooooooooooooooooooooooooooooooooooooooooooooong = 0, static field = \{\r\n--Type <RET>" {
- pass $test
+gdb_test_multiple "print c" "" {
+ -re "\\$\[0-9\]+ = \{loooooooooooooooooooooooooooooooooooooooooooooong = 0, static field = \{\r\n$pagination_prompt$" {
+ pass $gdb_test_name
}
- -re "\r\n--Type <RET>" {
+ -re "\r\n$pagination_prompt$" {
# gdb-7.1 did not crash with this testcase but it had the same bug.
untested "bug does not reproduce"
return 0
}
}
-set test "print c - q <return>"
-gdb_test_multiple "" $test {
- -re " for more, q to quit, " {
- pass $test
- }
-}
-
-set test "print c - remainder"
-gdb_test_multiple "" $test {
- -re "c to continue without paging--$" {
- pass $test
- }
-}
-
gdb_test "q" ".*"
# Now the obstack is uninitialized. Exercise it.
diff --git a/gdb/testsuite/gdb.dap/attach.exp b/gdb/testsuite/gdb.dap/attach.exp
index 37e867c..5e1f634 100644
--- a/gdb/testsuite/gdb.dap/attach.exp
+++ b/gdb/testsuite/gdb.dap/attach.exp
@@ -33,11 +33,11 @@ set attach_id [dap_attach $testpid $binfile]
dap_check_request_and_response "configurationDone" configurationDone
+dap_check_response "attach response" attach $attach_id
+
dap_wait_for_event_and_check "stopped" stopped \
"body reason" attach
-dap_check_response "attach response" attach $attach_id
-
dap_shutdown true
kill_wait_spawned_process $test_spawn_id
diff --git a/gdb/testsuite/gdb.dap/log-message.exp b/gdb/testsuite/gdb.dap/log-message.exp
index 421df14..cce367d 100644
--- a/gdb/testsuite/gdb.dap/log-message.exp
+++ b/gdb/testsuite/gdb.dap/log-message.exp
@@ -40,6 +40,15 @@ set obj [dap_check_request_and_response "set breakpoint" \
[list s $srcfile] $line]]
set fn_bpno [dap_get_breakpoint_number $obj]
+set eol {\n}
+dap_wait_for_event_and_check "set breakpoint output, part 1" output \
+ {body category} stdout \
+ {body output} "No source file named log-message.c.$eol"
+
+dap_wait_for_event_and_check "set breakpoint output, part 2" output \
+ {body category} stdout \
+ {body output} "Breakpoint 1 (-source log-message.c -line $line) pending.$eol"
+
dap_check_request_and_response "configurationDone" configurationDone
dap_check_response "launch response" launch $launch_id
diff --git a/gdb/testsuite/gdb.dap/scopes.c b/gdb/testsuite/gdb.dap/scopes.c
index d8929f1..2a1d76c 100644
--- a/gdb/testsuite/gdb.dap/scopes.c
+++ b/gdb/testsuite/gdb.dap/scopes.c
@@ -27,6 +27,8 @@ int main ()
static int scalar = 23;
+ void *ptr = (void *) &scalar;
+
{
const char *inner = "inner block";
diff --git a/gdb/testsuite/gdb.dap/scopes.exp b/gdb/testsuite/gdb.dap/scopes.exp
index 59d344b..e4e5c28 100644
--- a/gdb/testsuite/gdb.dap/scopes.exp
+++ b/gdb/testsuite/gdb.dap/scopes.exp
@@ -25,123 +25,166 @@ if {[build_executable ${testfile}.exp $testfile] == -1} {
return
}
-if {[dap_initialize] == ""} {
- return
-}
+save_vars { ::env(GLIBC_TUNABLES) } {
+
+ # If x86 shadow stack is supported we need to configure GLIBC_TUNABLES
+ # such that the feature is enabled and the register pl3_ssp is
+ # available. Otherwise the request to fetch all registers will fail
+ # with "message": "value is not available".
+ if { [allow_ssp_tests] } {
+ append_environment GLIBC_TUNABLES "glibc.cpu.hwcaps" "SHSTK"
+ }
-set launch_id [dap_launch $testfile]
+ if {[dap_initialize] == ""} {
+ return
+ }
-set line [gdb_get_line_number "BREAK"]
-set obj [dap_check_request_and_response "set breakpoint by line number" \
- setBreakpoints \
- [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \
- [list s $srcfile] $line]]
-set line_bpno [dap_get_breakpoint_number $obj]
+ set launch_id [dap_launch $testfile]
-dap_check_request_and_response "configurationDone" configurationDone
+ set line [gdb_get_line_number "BREAK"]
+ set obj [dap_check_request_and_response "set breakpoint by line number" \
+ setBreakpoints \
+ [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \
+ [list s $srcfile] $line]]
+ set line_bpno [dap_get_breakpoint_number $obj]
-dap_check_response "launch response" launch $launch_id
+ dap_check_request_and_response "configurationDone" configurationDone
-dap_wait_for_event_and_check "inferior started" thread "body reason" started
+ dap_check_response "launch response" launch $launch_id
-dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
- "body reason" breakpoint \
- "body hitBreakpointIds" $line_bpno
+ dap_wait_for_event_and_check "inferior started" thread "body reason" started
-set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
- {o threadId [i 1]}] \
- 0]
-set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id]
+ dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
+ "body reason" breakpoint \
+ "body hitBreakpointIds" $line_bpno
-set scopes [dap_check_request_and_response "get scopes" scopes \
+ set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
+ {o threadId [i 1]}] \
+ 0]
+ set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id]
+
+ set scopes [dap_check_request_and_response "get scopes" scopes \
[format {o frameId [i %d]} $frame_id]]
-set scopes [dict get [lindex $scopes 0] body scopes]
+ set scopes [dict get [lindex $scopes 0] body scopes]
-# Request the scopes twice, and verify that the results are identical.
-# GDB previously had a bug where it would return new scopes each time.
-set scopes2 [dap_check_request_and_response "get scopes again" scopes \
+ # Request the scopes twice, and verify that the results are identical.
+ # GDB previously had a bug where it would return new scopes each time.
+ set scopes2 [dap_check_request_and_response "get scopes again" scopes \
[format {o frameId [i %d]} $frame_id]]
-set scopes2 [dict get [lindex $scopes2 0] body scopes]
-gdb_assert {$scopes2 == $scopes} "identical scopes requests yield same body"
-
-gdb_assert {[llength $scopes] == 2} "two scopes"
-
-lassign $scopes scope reg_scope
-gdb_assert {[dict get $scope name] == "Locals"} "scope is locals"
-gdb_assert {[dict get $scope presentationHint] == "locals"} \
- "locals presentation hint"
-gdb_assert {[dict get $scope namedVariables] == 3} "three vars in scope"
-
-gdb_assert {[dict get $reg_scope name] == "Registers"} \
- "second scope is registers"
-gdb_assert {[dict get $reg_scope presentationHint] == "registers"} \
- "registers presentation hint"
-gdb_assert {[dict get $reg_scope namedVariables] > 0} "at least one register"
-
-set num [dict get $scope variablesReference]
-# Send two requests and combine them, to verify that using a range
-# works.
-set refs1 [lindex [dap_check_request_and_response "fetch variables 0,1" \
- "variables" \
- [format {o variablesReference [i %d] count [i 2]} \
- $num]] \
- 0]
-set refs2 [lindex [dap_check_request_and_response "fetch variables 2" \
- "variables" \
- [format {o variablesReference [i %d] \
- start [i 2] count [i 1]} \
- $num]] \
- 0]
-
-set vars [concat [dict get $refs1 body variables] \
- [dict get $refs2 body variables]]
-foreach var $vars {
- set name [dict get $var name]
-
- if {$name != "dei"} {
- gdb_assert {[dict get $var variablesReference] == 0} \
- "$name has no structure"
- }
-
- switch $name {
- "inner" {
- gdb_assert {[string match "*inner block*" [dict get $var value]]} \
- "check value of inner"
+ set scopes2 [dict get [lindex $scopes2 0] body scopes]
+ gdb_assert {$scopes2 == $scopes} "identical scopes requests yield same body"
+
+ gdb_assert {[llength $scopes] == 2} "two scopes"
+
+ lassign $scopes scope reg_scope
+ gdb_assert {[dict get $scope name] == "Locals"} "scope is locals"
+ gdb_assert {[dict get $scope presentationHint] == "locals"} \
+ "locals presentation hint"
+ set count [dict get $scope namedVariables]
+ gdb_assert {$count == 4} "four vars in scope"
+
+ gdb_assert {[dict get $reg_scope name] == "Registers"} \
+ "second scope is registers"
+ gdb_assert {[dict get $reg_scope presentationHint] == "registers"} \
+ "registers presentation hint"
+ gdb_assert {[dict get $reg_scope namedVariables] > 0} "at least one register"
+
+ set num [dict get $scope variablesReference]
+ # Send two requests and combine them, to verify that using a range
+ # works.
+ set refs1 [lindex [dap_check_request_and_response "fetch variables 0,1" \
+ "variables" \
+ [format {o variablesReference [i %d] count [i 2]} \
+ $num]] \
+ 0]
+ set refs2 [lindex [dap_check_request_and_response "fetch variables 2" \
+ "variables" \
+ [format {o variablesReference [i %d] \
+ start [i 2] count [i %d]} \
+ $num [expr {$count - 2}]]] \
+ 0]
+
+ set vars [concat [dict get $refs1 body variables] \
+ [dict get $refs2 body variables]]
+ foreach var $vars {
+ set name [dict get $var name]
+
+ if {$name != "dei"} {
+ gdb_assert {[dict get $var variablesReference] == 0} \
+ "$name has no structure"
}
- "dei" {
- gdb_assert {[dict get $var value] == ""} "check value of dei"
- set dei_ref [dict get $var variablesReference]
- }
- "scalar" {
- gdb_assert {[dict get $var value] == 23} "check value of scalar"
+
+ switch $name {
+ "inner" {
+ gdb_assert {[string match "*inner block*" [dict get $var value]]} \
+ "check value of inner"
+ }
+ "dei" {
+ gdb_assert {[dict get $var value] == ""} "check value of dei"
+ set dei_ref [dict get $var variablesReference]
+ }
+ "scalar" {
+ gdb_assert {[dict get $var value] == 23} "check value of scalar"
+ }
+ "ptr" {
+ gdb_assert {[dict get $var memoryReference] != ""} \
+ "check memoryReference of ptr"
+ }
+ default {
+ fail "unknown variable $name"
+ }
}
- default {
- fail "unknown variable $name"
+ }
+
+ set refs [lindex [dap_check_request_and_response "fetch contents of dei" \
+ "variables" \
+ [format {o variablesReference [i %d]} $dei_ref]] \
+ 0]
+ set deivals [dict get $refs body variables]
+ gdb_assert {[llength $deivals] == 2} "dei has two members"
+
+ # Request more children than exist. See PR dap/33228.
+ set seq [dap_send_request variables \
+ [format {o variablesReference [i %d] count [i 100]} $dei_ref]]
+ lassign [dap_read_response variables $seq] response ignore
+ gdb_assert {[dict get $response success] == "false"} \
+ "variables with invalid count"
+
+ set num [dict get $reg_scope variablesReference]
+ lassign [dap_check_request_and_response "fetch all registers" \
+ "variables" \
+ [format {o variablesReference [i %d] count [i %d]} $num\
+ [dict get $reg_scope namedVariables]]] \
+ val events
+
+ # If any register has children, try to fetch those as well. This is a
+ # regression test for part of PR dap/33228.
+ foreach var [dict get $val body variables] {
+ set regvar [dict get $var variablesReference]
+ if {$regvar > 0} {
+ # If variablesReference is non-zero, then there must be either
+ # named or indexed children.
+ if {[dict exists $var namedVariables]} {
+ set n [dict get $var namedVariables]
+ } else {
+ set n [dict get $var indexedVariables]
+ }
+
+ dap_check_request_and_response "fetch register children for $regvar" \
+ "variables" \
+ [format {o variablesReference [i %d] count [i %d]} $regvar $n]
}
}
-}
-set refs [lindex [dap_check_request_and_response "fetch contents of dei" \
- "variables" \
- [format {o variablesReference [i %d]} $dei_ref]] \
- 0]
-set deivals [dict get $refs body variables]
-gdb_assert {[llength $deivals] == 2} "dei has two members"
-
-set num [dict get $reg_scope variablesReference]
-# The request succeeding is sufficient.
-set val [dap_check_request_and_response "fetch first register" \
- "variables" \
- [format {o variablesReference [i %d] count [i 1]} $num]]
-
-set num [dict get $scope variablesReference]
-set refs [lindex [dap_check_request_and_response "set variable scalar" \
- "setVariable" \
- [format {o variablesReference [i %d] name [s scalar] \
- value [s 32]} \
+ set num [dict get $scope variablesReference]
+ set refs [lindex [dap_check_request_and_response "set variable scalar" \
+ "setVariable" \
+ [format {o variablesReference [i %d] name [s scalar] \
+ value [s 32]} \
$num]] \
- 0]
-gdb_assert { [dict get $refs body value] == 32 } \
- "setting variable yields updated value"
+ 0]
+ gdb_assert { [dict get $refs body value] == 32 } \
+ "setting variable yields updated value"
-dap_shutdown
+ dap_shutdown
+}
diff --git a/gdb/testsuite/gdb.dap/threads.c b/gdb/testsuite/gdb.dap/threads.c
new file mode 100644
index 0000000..168f044
--- /dev/null
+++ b/gdb/testsuite/gdb.dap/threads.c
@@ -0,0 +1,67 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2019-2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+#define NUM 2
+
+static pthread_barrier_t threads_started_barrier;
+
+static void *
+thread_function (void *arg)
+{
+ pthread_barrier_wait (&threads_started_barrier);
+
+ while (1)
+ sleep (1);
+
+ pthread_exit (NULL);
+}
+
+static void
+all_started (void)
+{
+}
+
+int
+main ()
+{
+ pthread_t threads[NUM];
+ long i;
+
+ pthread_barrier_init (&threads_started_barrier, NULL, NUM + 1);
+
+ for (i = 1; i <= NUM; i++)
+ {
+ int res;
+
+ res = pthread_create (&threads[i - 1], NULL, thread_function, NULL);
+ }
+
+ pthread_barrier_wait (&threads_started_barrier);
+
+ all_started ();
+
+ printf ("sleeping\n");
+ fflush (stdout);
+ sleep (180);
+
+ exit (EXIT_SUCCESS);
+}
diff --git a/gdb/testsuite/gdb.dap/threads.exp b/gdb/testsuite/gdb.dap/threads.exp
new file mode 100644
index 0000000..c91d107
--- /dev/null
+++ b/gdb/testsuite/gdb.dap/threads.exp
@@ -0,0 +1,81 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test DAP "threads" request.
+
+require allow_shlib_tests allow_dap_tests
+
+load_lib dap-support.exp
+
+standard_testfile
+
+set libname $testfile-solib
+set srcfile_lib $srcdir/$subdir/$libname.c
+set binfile_lib [standard_output_file $libname.so]
+
+if {[build_executable "failed to prepare" $testfile $srcfile \
+ {debug pthreads}] == -1} {
+ return
+}
+
+if {[dap_initialize] == ""} {
+ return
+}
+
+set launch_id [dap_launch $testfile]
+
+set obj [dap_check_request_and_response "set breakpoint on all_started function" \
+ setFunctionBreakpoints \
+ {o breakpoints [a [o name [s all_started]]]}]
+set fn_bpno [dap_get_breakpoint_number $obj]
+
+dap_check_request_and_response "configurationDone" configurationDone
+
+dap_check_response "launch response" launch $launch_id
+
+lassign [dap_wait_for_event_and_check "stopped at function breakpoint" \
+ stopped \
+ "body reason" breakpoint \
+ "body hitBreakpointIds" $fn_bpno] \
+ ignore \
+ all_events
+
+# Verify that we saw the correct number of thread events.
+set count 0
+foreach event $all_events {
+ if {[dict get $event type] == "event"
+ && [dict get $event event] == "thread"
+ && [dict get $event body reason] == "started"} {
+ incr count
+ }
+}
+gdb_assert {$count == 3} "correct number of thread events"
+
+dap_check_request_and_response "continue" continue \
+ {o threadId [i 1]}
+
+# Make sure that the inferior has really re-started -- note that there
+# is no "continue" event, because the "continue" request suppresses
+# those.
+dap_wait_for_event_and_check "output from inferior" output \
+ {body output} "sleeping\\n"
+
+lassign [dap_check_request_and_response "threads request" threads] \
+ response ignore
+
+gdb_assert {[llength [dict get $response body threads]] == 3} \
+ "correct number of threads"
+
+dap_shutdown true
diff --git a/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp b/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp
index 93f8f92..35bb401 100644
--- a/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp
+++ b/gdb/testsuite/gdb.debuginfod/build-id-no-debug-warning.exp
@@ -46,7 +46,7 @@ set build_id_debug_file \
[standard_output_file [build_id_debug_filename_get $binfile]]
# Get the BINFILE.debug filename. This is the file we should be
-# moving to the BUILD_ID_DEBUG_FILE location, but we wont, we're going
+# moving to the BUILD_ID_DEBUG_FILE location, but we won't, we're going
# to move something else there instead.
set debugfile [standard_output_file "${binfile}.debug"]
diff --git a/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp b/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp
index 78fa252..dac4e6c 100644
--- a/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp
+++ b/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp
@@ -49,7 +49,7 @@
#
# This obviously needs fixing, but is a separate problem from the one being
# tested here, so this test deliberately checks the mapping using a file that
-# is mmaped rather than loaded as a shared library, as such the file is in the
+# is mmapped rather than loaded as a shared library, as such the file is in the
# core-files list of mapped files, but is not in the shared library list.
#
# Despite this test living in the gdb.debuginfod/ directory, only the last
@@ -260,7 +260,7 @@ proc load_core_file { testname { line_re "" } } {
# We expect RES to be 2 (TCL_RETURN) or 1 (TCL_ERROR). If we get
# here then somehow the 'catch' above finished without hitting
# either of those cases, which is .... weird.
- perror "unexepcted return value, code = $res, value = $string"
+ perror "unexpected return value, code = $res, value = $string"
return -1
}
}
diff --git a/gdb/testsuite/gdb.debuginfod/solib-with-soname.exp b/gdb/testsuite/gdb.debuginfod/solib-with-soname.exp
index 9f1842c..1008e46 100644
--- a/gdb/testsuite/gdb.debuginfod/solib-with-soname.exp
+++ b/gdb/testsuite/gdb.debuginfod/solib-with-soname.exp
@@ -89,7 +89,7 @@ if {[lindex $status 0] != 0} {
}
# Build the executable. This links against libfoo.so, which is
-# poining at libfoo_1.so. Just to confuse things even more, this
+# pointing at libfoo_1.so. Just to confuse things even more, this
# executable uses dlopen to load libfoo_2.so. Weird!
if { [build_executable "build executable" ${binfile} ${srcfile2} \
[list debug shlib=${library_filename} shlib_load]] == -1 } {
diff --git a/gdb/testsuite/gdb.dwarf2/ada-array-bound.c b/gdb/testsuite/gdb.dwarf2/ada-array-bound.c
new file mode 100644
index 0000000..5a7d397
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/ada-array-bound.c
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* The data used for the structure. */
+
+unsigned char our_data[] = { 3, 7, 11, 13 };
+
+/* Dummy main function. */
+
+int
+main()
+{
+ asm ("main_label: .globl main_label");
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/ada-array-bound.exp b/gdb/testsuite/gdb.dwarf2/ada-array-bound.exp
new file mode 100644
index 0000000..f48df7b
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/ada-array-bound.exp
@@ -0,0 +1,89 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test handling of an array type whose bound comes from the field of a
+# structure.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+require dwarf2_support
+
+standard_testfile .c -debug.S
+
+# Set up the DWARF for the test.
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ global srcdir subdir srcfile
+
+ cu {} {
+ DW_TAG_compile_unit {
+ {DW_AT_language @DW_LANG_Ada95}
+ {DW_AT_name $srcfile}
+ } {
+ declare_labels byte array disc struct
+
+ byte: DW_TAG_base_type {
+ {DW_AT_byte_size 1 DW_FORM_sdata}
+ {DW_AT_encoding @DW_ATE_unsigned}
+ {DW_AT_name byte}
+ }
+
+ array: DW_TAG_array_type {
+ {DW_AT_name array_type}
+ {DW_AT_type :$byte}
+ } {
+ DW_TAG_subrange_type {
+ {DW_AT_type :$byte}
+ {DW_AT_upper_bound :$disc}
+ }
+ }
+
+ struct: DW_TAG_structure_type {
+ {DW_AT_name discriminated}
+ {DW_AT_byte_size 4 DW_FORM_sdata}
+ } {
+ disc: DW_TAG_member {
+ {DW_AT_name disc}
+ {DW_AT_type :$byte}
+ {DW_AT_data_member_location 0 DW_FORM_sdata}
+ }
+ DW_TAG_member {
+ {DW_AT_name nums}
+ {DW_AT_type :$array}
+ {DW_AT_data_member_location 1 DW_FORM_sdata}
+ }
+ }
+
+ DW_TAG_variable {
+ {DW_AT_name "value"}
+ {DW_AT_type :$struct}
+ {DW_AT_external 1 DW_FORM_flag}
+ {DW_AT_location {DW_OP_addr [gdb_target_symbol "our_data"]}
+ SPECIAL_expr}
+ }
+ }
+ }
+}
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile $asm_file] {nodebug}] } {
+ return -1
+}
+
+gdb_test_no_output "set language ada"
+gdb_test "print value" \
+ [string_to_regexp " = (disc => 3, nums => (7, 11, 13))"]
diff --git a/gdb/testsuite/gdb.dwarf2/backward-spec-inter-cu.exp b/gdb/testsuite/gdb.dwarf2/backward-spec-inter-cu.exp
index b62f928..1876849 100644
--- a/gdb/testsuite/gdb.dwarf2/backward-spec-inter-cu.exp
+++ b/gdb/testsuite/gdb.dwarf2/backward-spec-inter-cu.exp
@@ -20,6 +20,7 @@ load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
require dwarf2_support
+require !readnow
standard_testfile main.c -debug.S
@@ -98,6 +99,11 @@ foreach_with_prefix worker_threads $worker_threads_list {
gdb_load $binfile
+ set index [have_index $binfile]
+ if { ![string eq $index ""] } {
+ return
+ }
+
gdb_test "pipe maint print objfiles | grep ns::v" \
"$ws+qualified:$ws+ns::v" \
"v has parent ns"
diff --git a/gdb/testsuite/gdb.dwarf2/debug-names-non-ascending-cu.exp b/gdb/testsuite/gdb.dwarf2/debug-names-non-ascending-cu.exp
deleted file mode 100644
index d86b5c4..0000000
--- a/gdb/testsuite/gdb.dwarf2/debug-names-non-ascending-cu.exp
+++ /dev/null
@@ -1,81 +0,0 @@
-# Copyright 2022-2025 Free Software Foundation, Inc.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-load_lib dwarf.exp
-
-# This test can only be run on targets which support DWARF-2 and use gas.
-require dwarf2_support
-
-standard_testfile _start.c debug-names.S
-
-set func_info_vars \
- [get_func_info _start [list debug additional_flags=-nostartfiles]]
-
-# Create the DWARF.
-set asm_file [standard_output_file $srcfile2]
-Dwarf::assemble {
- filename $asm_file
- add_dummy_cus 0
-} {
- global func_info_vars
- foreach var $func_info_vars {
- global $var
- }
-
- cu { label cu_label } {
- compile_unit {{language @DW_LANG_C}} {
- subprogram {
- {DW_AT_name _start}
- {DW_AT_low_pc $_start_start DW_FORM_addr}
- {DW_AT_high_pc $_start_end DW_FORM_addr}
- }
- }
- }
-
- cu { label cu_label_2 } {
- compile_unit {{language @DW_LANG_C}} {
- base_type {
- {name int}
- {byte_size 4 sdata}
- {encoding @DW_ATE_signed}
- }
- }
- }
-
- debug_names {} {
- cu cu_label_2
- cu cu_label
- name _start subprogram cu_label 0xEDDB6232
- name int base_type cu_label 0xB888030
- }
-}
-
-if [prepare_for_testing "failed to prepare" $testfile "${asm_file} ${srcfile}" \
- [list additional_flags=-nostartfiles]] {
- return -1
-}
-
-# Check for warning.
-set re \
- [list \
- "warning:" \
- "Section .debug_names has incorrect entry in CU table," \
- "ignoring .debug_names."]
-set re [join $re]
-gdb_assert {[regexp $re $gdb_file_cmd_msg]} "warning"
-
-# Verify that .debug_names section is ignored.
-set index [have_index $binfile]
-gdb_assert { [string equal $index ""] } ".debug_names not used"
diff --git a/gdb/testsuite/gdb.dwarf2/dw-form-ref-addr-with-type-units.exp b/gdb/testsuite/gdb.dwarf2/dw-form-ref-addr-with-type-units.exp
new file mode 100644
index 0000000..6253629
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw-form-ref-addr-with-type-units.exp
@@ -0,0 +1,109 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This is a reproducer for PR 29518:
+#
+# https://sourceware.org/bugzilla/show_bug.cgi?id=29518
+#
+# The root cause for the problem was that function
+# dwarf2_find_containing_comp_unit was searching the whole "all_units" vector,
+# containing both compile units and type units, causing it to sometimes
+# erroneously return a type unit. It should have been restricted to searching
+# compile units.
+#
+# To get dwarf2_find_containing_comp_unit to be called and reproduce the
+# original bug, we need a value with form DW_FORM_ref_addr pointing to a
+# different compile unit. This is produced by `%$int_type` below.
+
+load_lib dwarf.exp
+require dwarf2_support
+standard_testfile main.c .S
+
+set asm_file [standard_output_file $srcfile2]
+
+Dwarf::assemble $asm_file {
+ global srcfile
+ declare_labels int_type
+
+ # The source CU.
+ cu {version 4} {
+ compile_unit {
+ } {
+ subprogram {
+ {MACRO_AT_func {main}}
+ {type %$int_type}
+ }
+ }
+ }
+
+ # Create a bunch of empty / dummy CUs, to make the offset of int_type a bit
+ # higher.
+ for {set i 1} {$i < 10} {incr i} {
+ cu {version 4} {
+ compile_unit {} {}
+ }
+ }
+
+ # The target CU.
+ cu {version 4} {
+ compile_unit {
+ } {
+ int_type: DW_TAG_base_type {
+ {DW_AT_byte_size 4 DW_FORM_sdata}
+ {DW_AT_encoding @DW_ATE_signed}
+ {DW_AT_name int}
+ }
+ }
+ }
+
+ # Create many TUs.
+ #
+ # We need enough type units in the "all_units" vector in order to steer the
+ # binary search in dwarf2_find_containing_comp_unit towards the type units
+ # region of the array.
+ for {set i 1} {$i < 20} {incr i} {
+ tu {version 4} $i the_type_i {
+ type_unit {} {
+ declare_labels dummy_int_type
+
+ the_type_i: structure_type {
+ {name s}
+ {byte_size 4 sdata}
+ } {
+ member {
+ {name i}
+ {type :$dummy_int_type}
+ }
+ }
+
+ dummy_int_type: base_type {
+ {name int}
+ {encoding @DW_ATE_signed}
+ {byte_size 4 sdata}
+ }
+ }
+ }
+ }
+}
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile $asm_file] {nodebug}] } {
+ return -1
+}
+
+# Without the corresponding fix, we get an internal error:
+#
+# gdb/dwarf2/read.c:3940: internal-error: load_full_comp_unit: Assertion `! this_cu->is_debug_types' failed.
+gdb_test "p main" " = {int \\(void\\)} $hex <main>"
diff --git a/gdb/testsuite/gdb.dwarf2/dw-form-strx-out-of-bounds.exp b/gdb/testsuite/gdb.dwarf2/dw-form-strx-out-of-bounds.exp
index f2123fa..cb24b19 100644
--- a/gdb/testsuite/gdb.dwarf2/dw-form-strx-out-of-bounds.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw-form-strx-out-of-bounds.exp
@@ -18,7 +18,13 @@
# Out of bounds index.
set int_str_idx 1
+# With readnow, the dwarf error is printed during the file command, so skip
+# the test.
+require !readnow
+
+set prepare_for_testing_done 0
source $srcdir/$subdir/dw-form-strx.exp.tcl
+require {expr $prepare_for_testing_done == 1}
set re_dwarf_error \
[string_list_to_regexp \
diff --git a/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp b/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp
index 9b62edf..3f739c4 100644
--- a/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp
@@ -18,6 +18,8 @@
# Correct index.
set int_str_idx 0
+set prepare_for_testing_done 0
source $srcdir/$subdir/dw-form-strx.exp.tcl
+require {expr $prepare_for_testing_done == 1}
gdb_test "ptype global_var" "type = int"
diff --git a/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp.tcl b/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp.tcl
index 15cfe27..bc5a654 100644
--- a/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp.tcl
+++ b/gdb/testsuite/gdb.dwarf2/dw-form-strx.exp.tcl
@@ -24,15 +24,15 @@ set asm_file [standard_output_file $srcfile2]
# Debug info in the main file.
Dwarf::assemble $asm_file {
- declare_labels base_offset
+ declare_labels base_offset_cu1
- debug_str_offsets base_offset int
+ debug_str_offsets { base_offset base_offset_cu1 } int
cu {
version 5
} {
DW_TAG_compile_unit {
- {DW_AT_str_offsets_base $base_offset sec_offset}
+ {DW_AT_str_offsets_base $base_offset_cu1 sec_offset}
} {
declare_labels int4_type
@@ -56,5 +56,9 @@ Dwarf::assemble $asm_file {
if { [prepare_for_testing "failed to prepare" ${testfile} \
[list $srcfile $asm_file] {nodebug}] } {
- return -1
+ return
}
+
+# Let includers know prepare_for_testing was done, without having to check
+# source return status.
+set prepare_for_testing_done 1
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-entry-points.c b/gdb/testsuite/gdb.dwarf2/dw2-entry-points.c
index ccfb150..258ebfa 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-entry-points.c
+++ b/gdb/testsuite/gdb.dwarf2/dw2-entry-points.c
@@ -33,11 +33,28 @@ bar_helper (void)
asm ("foobar_entry_label: .globl foobar_entry_label");
}
+__attribute__ ((noinline))
+void
+barso_helper (void)
+{
+ asm ("barso_helper_label: .globl barso_helper_label");
+ I++;
+ J++;
+ asm ("fooso_entry_label: .globl fooso_entry_label");
+ J++;
+ K++;
+ asm ("foobarso_entry_label: .globl foobarso_entry_label");
+}
+
int
main (void)
{
asm ("main_label: .globl main_label");
bar_helper ();
+ I = 0;
+ J = 0;
+ K = 0;
+ barso_helper ();
return 0;
}
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp b/gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp
index bd22560..bba4cfb 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp
@@ -36,6 +36,7 @@ Dwarf::assemble $asm_file {
get_func_info main
get_func_info bar_helper
+ get_func_info barso_helper
set int_size [get_sizeof "int" 4]
@@ -135,8 +136,8 @@ Dwarf::assemble $asm_file {
{decl_file 1 data1}
{decl_line $bar_line data1}
{external 1 flag}
- {low_pc $bar_helper_start addr}
- {high_pc "$bar_helper_start + $bar_helper_len" addr}
+ {low_pc $barso_helper_start addr}
+ {high_pc "$barso_helper_start + $barso_helper_len" addr}
} {
formal_parameter {
{name I}
@@ -152,7 +153,7 @@ Dwarf::assemble $asm_file {
{name fooso}
{decl_file 1 data1}
{decl_line $foo_line data1}
- {low_pc foo_entry_label addr}
+ {low_pc fooso_entry_label addr}
} {
formal_parameter {
{name J}
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-linkage-name-trust.exp b/gdb/testsuite/gdb.dwarf2/dw2-linkage-name-trust.exp
index 01eab48..7627e8e 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-linkage-name-trust.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-linkage-name-trust.exp
@@ -27,7 +27,7 @@ standard_testfile .S
set executable ${testfile}
if {[prepare_for_testing_full "failed to prepare" \
- [list $testfile c++ $testfile-main.cc {c++ debug} \
+ [list $testfile c++ $testfile-main.cc {c++ nodebug} \
$srcfile {}]]} {
return -1
}
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-modula2-self-type.S b/gdb/testsuite/gdb.dwarf2/dw2-modula2-self-type.S
index c09c6db..06a93ac 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-modula2-self-type.S
+++ b/gdb/testsuite/gdb.dwarf2/dw2-modula2-self-type.S
@@ -114,7 +114,11 @@ die221:
.byte 0x0
- .section .debug_str
+#ifdef __arm__
+ .section .debug_str,"MS",%progbits,1
+#else
+ .section .debug_str,"MS",@progbits,1
+#endif
.LASF1:
.string "2.mod"
.LASF0:
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym-warning.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym-warning.exp
index ea0fc03..6120878 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym-warning.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym-warning.exp
@@ -117,7 +117,7 @@ if ![runto_main] {
# the hole is there in the symbol table, but not the partial symbol table,
# we run into:
# (gdb) bt
-# warning: (Internal error: pc 0x555555554619 in read in psymtab, \
+# warning: (Internal error: pc 0x555555554619 in read in psymtab,
# but not in symtab.)
# ...
# (gdb)
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-simple-locdesc.S b/gdb/testsuite/gdb.dwarf2/dw2-simple-locdesc.S
index cd999f4..551dda7 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-simple-locdesc.S
+++ b/gdb/testsuite/gdb.dwarf2/dw2-simple-locdesc.S
@@ -160,7 +160,11 @@ d:
.byte 0
.byte 0
.byte 0
- .section .debug_str
+#ifdef __arm__
+ .section .debug_str,"MS",%progbits,1
+#else
+ .section .debug_str,"MS",@progbits,1
+#endif
.LASF2:
.string "GNU C 4.7.0 20110727 (experimental)"
.LASF0:
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-strp.S b/gdb/testsuite/gdb.dwarf2/dw2-strp.S
index c7ede95..db3e64f 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-strp.S
+++ b/gdb/testsuite/gdb.dwarf2/dw2-strp.S
@@ -163,7 +163,11 @@
.byte 0x0 /* Terminator */
/* String table */
- .section .debug_str
+#ifdef __arm__
+ .section .debug_str,"MS",%progbits,1
+#else
+ .section .debug_str,"MS",@progbits,1
+#endif
.Lproducer:
.string "GNU C 3.3.3"
.Lchar_str:
diff --git a/gdb/testsuite/gdb.dwarf2/dynamic-bit-offset.exp b/gdb/testsuite/gdb.dwarf2/dynamic-bit-offset.exp
new file mode 100644
index 0000000..f4e02da
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dynamic-bit-offset.exp
@@ -0,0 +1,95 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test DW_AT_data_bit_offset with an expression. This is a DWARF
+# extension, but expected to be in DWARF 6. See
+# https://dwarfstd.org/issues/250501.1.html
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+require dwarf2_support
+
+standard_testfile ada-array-bound.c -debug.S
+
+# Set up the DWARF for the test.
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ global srcdir subdir srcfile
+
+ cu {} {
+ DW_TAG_compile_unit {
+ {DW_AT_language @DW_LANG_Ada95}
+ {DW_AT_name $srcfile}
+ } {
+ declare_labels byte array struct
+
+ byte: DW_TAG_base_type {
+ {DW_AT_byte_size 1 DW_FORM_sdata}
+ {DW_AT_encoding @DW_ATE_unsigned}
+ {DW_AT_name byte}
+ }
+
+ array: DW_TAG_array_type {
+ {DW_AT_name array_type}
+ {DW_AT_type :$byte}
+ } {
+ DW_TAG_subrange_type {
+ {DW_AT_type :$byte}
+ {DW_AT_upper_bound 3 DW_FORM_sdata}
+ }
+ }
+
+ struct: DW_TAG_structure_type {
+ {DW_AT_name discriminated}
+ {DW_AT_byte_size 4 DW_FORM_sdata}
+ } {
+ DW_TAG_member {
+ {DW_AT_name disc}
+ {DW_AT_type :$byte}
+ {DW_AT_data_member_location 0 DW_FORM_sdata}
+ }
+
+ # We know this is always at offset 1 but use an
+ # expression just to test this code path. This is a
+ # DWARF extension. See
+ # https://dwarfstd.org/issues/250501.1.html.
+ DW_TAG_member {
+ {DW_AT_name nums}
+ {DW_AT_type :$array}
+ {DW_AT_data_bit_offset {DW_OP_lit8} SPECIAL_expr}
+ }
+ }
+
+ DW_TAG_variable {
+ {DW_AT_name "value"}
+ {DW_AT_type :$struct}
+ {DW_AT_external 1 DW_FORM_flag}
+ {DW_AT_location {DW_OP_addr [gdb_target_symbol "our_data"]}
+ SPECIAL_expr}
+ }
+ }
+ }
+}
+
+if {[prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile $asm_file] {nodebug}]} {
+ return -1
+}
+
+gdb_test_no_output "set language ada"
+gdb_test "print value" \
+ [string_to_regexp " = (disc => 3, nums => (7, 11, 13))"]
diff --git a/gdb/testsuite/gdb.dwarf2/fission-dw-form-strx.exp b/gdb/testsuite/gdb.dwarf2/fission-dw-form-strx.exp
new file mode 100644
index 0000000..4f5867c
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-dw-form-strx.exp
@@ -0,0 +1,88 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check support for a DW_FORM_strx attribute in a dwo file.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+require dwarf2_support
+
+standard_testfile main.c -dw.S -dwo.S
+
+set main_asm_file [standard_output_file $srcfile2]
+set dwo_asm_file [standard_output_file $srcfile3]
+
+# Debug info in the main file.
+Dwarf::assemble $main_asm_file {
+ cu {
+ version 5
+ dwo_id 0xF00D
+ } {
+ compile_unit {
+ {DW_AT_dwo_name ${::gdb_test_file_name}.dwo DW_FORM_strp}
+ } {}
+ }
+}
+
+# Debug info in the DWO file.
+Dwarf::assemble $dwo_asm_file {
+ debug_str_offsets { dwo 1 } int
+
+ cu {
+ fission 1
+ version 5
+ dwo_id 0xF00D
+ } {
+ compile_unit {} {
+ declare_labels int4_type
+
+ int4_type: DW_TAG_base_type {
+ {DW_AT_byte_size 4 DW_FORM_sdata}
+ {DW_AT_encoding @DW_ATE_signed}
+ {DW_AT_name 0 DW_FORM_strx_id}
+ }
+
+ DW_TAG_variable {
+ {DW_AT_name global_var}
+ {DW_AT_type :$int4_type}
+ {DW_AT_location {
+ DW_OP_const1u 12
+ DW_OP_stack_value
+ } SPECIAL_expr}
+ }
+ }
+ }
+}
+
+# Build main file.
+if { [build_executable "${testfile}.exp" $binfile \
+ [list ${srcfile} ${main_asm_file}] {nodebug}] } {
+ return
+}
+
+# Build DWO file.
+set dwo_file [standard_output_file ${testfile}.dwo]
+if { [gdb_compile_shlib $dwo_asm_file $dwo_file nodebug] != "" } {
+ return
+}
+
+if { [is_remote host] } {
+ gdb_remote_download host $dwo_file
+}
+
+clean_restart $binfile
+
+gdb_test "ptype global_var" "type = int"
diff --git a/gdb/testsuite/gdb.dwarf2/forward-spec-inter-cu.exp b/gdb/testsuite/gdb.dwarf2/forward-spec-inter-cu.exp
index e92e582..26d0af6 100644
--- a/gdb/testsuite/gdb.dwarf2/forward-spec-inter-cu.exp
+++ b/gdb/testsuite/gdb.dwarf2/forward-spec-inter-cu.exp
@@ -20,6 +20,7 @@ load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
require dwarf2_support
+require !readnow
standard_testfile main.c -debug.S
@@ -98,6 +99,11 @@ foreach_with_prefix worker_threads $worker_threads_list {
gdb_load $binfile
+ set index [have_index $binfile]
+ if { ![string eq $index ""] } {
+ return
+ }
+
gdb_test "pipe maint print objfiles | grep ns::v" \
"$ws+qualified:$ws+ns::v" \
"v has parent ns"
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw4.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw4.exp
index c0c2635..d4407d7 100644
--- a/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw4.exp
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw4.exp
@@ -18,6 +18,10 @@
# Generate binaries imitating different ways source file paths can be passed to
# compilers. Test printing macros from those binaries.
+load_lib dwarf.exp
+
+require dwarf2_support
+
# The do_test proc comes from macro-source-path.exp.tcl.
source $srcdir/$subdir/macro-source-path.exp.tcl
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw5.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw5.exp
index 0b3239e..23a40ba 100644
--- a/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw5.exp
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw5.exp
@@ -18,6 +18,10 @@
# Generate binaries imitating different ways source file paths can be passed to
# compilers. Test printing macros from those binaries.
+load_lib dwarf.exp
+
+require dwarf2_support
+
# The do_test proc comes from macro-source-path.exp.tcl.
source $srcdir/$subdir/macro-source-path.exp.tcl
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld234-dw5.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld234-dw5.exp
index 940f997..99f7857 100644
--- a/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld234-dw5.exp
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld234-dw5.exp
@@ -18,6 +18,10 @@
# Generate binaries imitating different ways source file paths can be passed to
# compilers. Test printing macros from those binaries.
+load_lib dwarf.exp
+
+require dwarf2_support
+
# The do_test proc comes from macro-source-path.exp.tcl.
source $srcdir/$subdir/macro-source-path.exp.tcl
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw4.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw4.exp
index dea0308..569b409 100644
--- a/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw4.exp
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw4.exp
@@ -18,6 +18,10 @@
# Generate binaries imitating different ways source file paths can be passed to
# compilers. Test printing macros from those binaries.
+load_lib dwarf.exp
+
+require dwarf2_support
+
# The do_test proc comes from macro-source-path.exp.tcl.
source $srcdir/$subdir/macro-source-path.exp.tcl
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw5.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw5.exp
index 98a278e..0517d29 100644
--- a/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw5.exp
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw5.exp
@@ -18,6 +18,10 @@
# Generate binaries imitating different ways source file paths can be passed to
# compilers. Test printing macros from those binaries.
+load_lib dwarf.exp
+
+require dwarf2_support
+
# The do_test proc comes from macro-source-path.exp.tcl.
source $srcdir/$subdir/macro-source-path.exp.tcl
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path.exp.tcl b/gdb/testsuite/gdb.dwarf2/macro-source-path.exp.tcl
index ecaf685..6254286 100644
--- a/gdb/testsuite/gdb.dwarf2/macro-source-path.exp.tcl
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path.exp.tcl
@@ -21,10 +21,6 @@
# The entry points for this test are in the various
# gdb.dwarf2/macro-source-path-*.exp files.
-load_lib dwarf.exp
-
-require dwarf2_support
-
standard_testfile macro-source-path.c
lassign [function_range main $srcdir/$subdir/$srcfile] \
diff --git a/gdb/testsuite/gdb.dwarf2/pr11465.S b/gdb/testsuite/gdb.dwarf2/pr11465.S
index fed98bc..f3f2c57 100644
--- a/gdb/testsuite/gdb.dwarf2/pr11465.S
+++ b/gdb/testsuite/gdb.dwarf2/pr11465.S
@@ -344,7 +344,11 @@ die149: .uleb128 0x16 /* DW_TAG_variable */
.byte 0x0
.byte 0x0
.byte 0x0
- .section .debug_str
+#ifdef __arm__
+ .section .debug_str,"MS",%progbits,1
+#else
+ .section .debug_str,"MS",@progbits,1
+#endif
.LASF0:
.string "_ZN1N1fE"
.LASF7:
diff --git a/gdb/testsuite/gdb.dwarf2/varval.exp b/gdb/testsuite/gdb.dwarf2/varval.exp
index 0693f43..6846ecb 100644
--- a/gdb/testsuite/gdb.dwarf2/varval.exp
+++ b/gdb/testsuite/gdb.dwarf2/varval.exp
@@ -348,6 +348,6 @@ if ![runto_main] {
}
gdb_test "print badval" "value has been optimized out"
gdb_test "print bad_die_val1" \
- "invalid dwarf2 offset 0xabcdef11"
+ {DWARF Error: could not find unit containing offset 0xabcdef11 \[in module .*/varval\]}
gdb_test "print bad_die_val2" \
"Bad DW_OP_GNU_variable_value DIE\\."
diff --git a/gdb/testsuite/gdb.gdb/index-file.exp b/gdb/testsuite/gdb.gdb/index-file.exp
index 2252b79..a9af211 100644
--- a/gdb/testsuite/gdb.gdb/index-file.exp
+++ b/gdb/testsuite/gdb.gdb/index-file.exp
@@ -30,6 +30,13 @@ if { $filename eq "" } {
return -1
}
+# If FILENAME is a libtool wrapper, then we need to get the path of the real
+# executable.
+set filename [selftest_libtool_get_real_gdb_executable $filename]
+if { $filename eq "" } {
+ return -1
+}
+
with_timeout_factor $timeout_factor {
# Start GDB, load FILENAME.
clean_restart $filename
diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
index 4b9adb0..33243c9 100644
--- a/gdb/testsuite/gdb.gdb/python-helper.exp
+++ b/gdb/testsuite/gdb.gdb/python-helper.exp
@@ -264,13 +264,31 @@ proc test_python_helper {} {
gdb_test -prompt $outer_prompt_re "print varobj_table" \
"htab_t with ${::decimal} elements"
+ set inferior_list_supported 1
+ set inferior_list_unsupported_re "type = intrusive_list"
+ gdb_test_multiple "what inferior_list" "" -prompt $outer_prompt_re {
+ -re -wrap $inferior_list_unsupported_re {
+ set inferior_list_supported 0
+ pass $gdb_test_name
+ }
+ -re -wrap "" {
+ pass $gdb_test_name
+ }
+ }
+
# Test the intrusive_list pretty-printer. A bug occurred in the
# pretty-printer for lists with more than one element. Verify that
# we see both elements of the inferior_list list being printed.
- gdb_test -prompt $outer_prompt_re "print inferior_list" "intrusive list of inferior = {.*, num = 1,.*, num = 2,.*}"
+ set test "print inferior_list"
+ if { $inferior_list_supported } {
+ gdb_test -prompt $outer_prompt_re $test \
+ "intrusive list of inferior = {.*, num = 1,.*, num = 2,.*}"
+ } else {
+ unsupported $test
+ }
return 0
}
# Use the self-test framework to run the test.
-do_self_tests captured_main test_python_helper
+do_self_tests test_python_helper
diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
index 1cf9265..f5cea1d 100644
--- a/gdb/testsuite/gdb.gdb/selftest.exp
+++ b/gdb/testsuite/gdb.gdb/selftest.exp
@@ -167,5 +167,5 @@ proc test_with_self { } {
save_vars { INTERNAL_GDBFLAGS } {
set INTERNAL_GDBFLAGS [string map {"-q" ""} $INTERNAL_GDBFLAGS]
- do_self_tests captured_main test_with_self
+ do_self_tests test_with_self
}
diff --git a/gdb/testsuite/gdb.guile/scm-cmd.exp b/gdb/testsuite/gdb.guile/scm-cmd.exp
index 9caca24..3709cb1 100644
--- a/gdb/testsuite/gdb.guile/scm-cmd.exp
+++ b/gdb/testsuite/gdb.guile/scm-cmd.exp
@@ -71,6 +71,65 @@ gdb_test_multiline "input subcommand" \
gdb_test "prefix-cmd subcmd ugh" "subcmd output, arg = ugh" "call subcmd"
+# Create a sub-command using a partial, but still unique, prefix.
+
+gdb_test_multiline "sub-command using partial prefix" \
+ "guile" "" \
+ "(register-command! (make-command \"prefix subcmd2\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:invoke (lambda (self arg from-tty)" "" \
+ " (display (format #f \"subcmd2 output, arg = ~a\\n\" arg)))))" "" \
+ "end" ""
+
+gdb_test "prefix-cmd subcmd2 ugh" "subcmd2 output, arg = ugh" "call subcmd2"
+
+# Now create a second prefix, similar to the first.
+
+gdb_test_multiline "create prefix-xxx prefix command" \
+ "guile" "" \
+ "(register-command! (make-command \"prefix-xxx\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:completer-class COMPLETE_NONE" "" \
+ " #:prefix? #t))" "" \
+ "end" ""
+
+# Now create a sub-command using an ambiguous prefix.
+
+gdb_test_multiline "sub-command using ambiguous partial prefix" \
+ "guile" "" \
+ "(register-command! (make-command \"prefix subcmd3\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:invoke (lambda (self arg from-tty)" "" \
+ " (display (format #f \"subcmd3 output, arg = ~a\\n\" arg)))))" "" \
+ "end" \
+ [multi_line \
+ "Out of range: could not find command prefix 'prefix' in position 1: \"prefix subcmd3\"" \
+ "Error while executing Scheme code\\."]
+
+# Check for errors when creating a command with an unknown prefix.
+
+gdb_test_multiline "try to create 'unknown-prefix subcmd'" \
+ "guile" "" \
+ "(register-command! (make-command \"unknown-prefix subcmd\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:invoke (lambda (self arg from-tty)" "" \
+ " (display \"called unknown-prefix subcmd\"))))" "" \
+ "end" \
+ [multi_line \
+ "Out of range: could not find command prefix 'unknown-prefix' in position 1: \"unknown-prefix subcmd\"" \
+ "Error while executing Scheme code\\."]
+
+gdb_test_multiline "try to create 'prefix-cmd unknown-prefix subcmd'" \
+ "guile" "" \
+ "(register-command! (make-command \"prefix-cmd unknown-prefix subcmd\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:invoke (lambda (self arg from-tty)" "" \
+ " (display \"called prefix-cmd unknown-prefix subcmd\"))))" "" \
+ "end" \
+ [multi_line \
+ "Out of range: could not find command prefix 'prefix-cmd unknown-prefix' in position 1: \"prefix-cmd unknown-prefix subcmd\"" \
+ "Error while executing Scheme code\\."]
+
# Test a subcommand in an existing GDB prefix.
gdb_test_multiline "input new subcommand" \
diff --git a/gdb/testsuite/gdb.guile/scm-color.exp b/gdb/testsuite/gdb.guile/scm-color.exp
index 578f712..4c6a9c2 100644
--- a/gdb/testsuite/gdb.guile/scm-color.exp
+++ b/gdb/testsuite/gdb.guile/scm-color.exp
@@ -19,6 +19,7 @@
load_lib gdb-guile.exp
require allow_guile_tests
+require {!is_remote host}
# Start GDB with styling support.
with_ansi_styling_terminal {
diff --git a/gdb/testsuite/gdb.guile/scm-frame.exp b/gdb/testsuite/gdb.guile/scm-frame.exp
index b5ec73f..9a27c42 100644
--- a/gdb/testsuite/gdb.guile/scm-frame.exp
+++ b/gdb/testsuite/gdb.guile/scm-frame.exp
@@ -52,7 +52,7 @@ gdb_test "guile (print (frame-read-var bf1 \"b\"))" \
"\"bar\"" "test b"
# Test the read-var function in another block other than the current
-# block (in this case, the super block). Test thar read-var is reading
+# block (in this case, the super block). Test that read-var is reading
# the correct variables of i and f but they are the correct value and type.
gdb_scm_test_silent_cmd "guile (define sb (block-superblock (frame-block bf1)))" \
"get superblock"
diff --git a/gdb/testsuite/gdb.guile/scm-parameter.exp b/gdb/testsuite/gdb.guile/scm-parameter.exp
index 8ab5d93..acd78b9 100644
--- a/gdb/testsuite/gdb.guile/scm-parameter.exp
+++ b/gdb/testsuite/gdb.guile/scm-parameter.exp
@@ -39,7 +39,8 @@ if { [is_remote host] } {
gdb_test "guile (print (parameter-value \"directories\"))" \
"\\\$cdir.\\\$cwd"
} else {
- set escaped_directory [string_to_regexp "$srcdir/$subdir"]
+ set directory [host_file_normalize "$::srcdir/$::subdir"]
+ set escaped_directory [string_to_regexp $directory]
gdb_test "guile (print (parameter-value \"directories\"))" \
"$escaped_directory.\\\$cdir.\\\$cwd"
}
@@ -67,9 +68,19 @@ with_test_prefix "test-param" {
gdb_test_no_output "set print test-param off"
gdb_test "show print test-param" "The state of the Test Parameter is off." "show parameter off"
gdb_test "guile (print (parameter-value test-param))" "= #f" "parameter value, false"
- gdb_test "help show print test-param" "Show the state of the boolean test-param.*" "show help"
- gdb_test "help set print test-param" "Set the state of the boolean test-param.*" "set help"
- gdb_test "help set print" "set print test-param -- Set the state of the boolean test-param.*" "general help"
+ gdb_test "help show print test-param" \
+ [multi_line \
+ "^Show the state of the boolean test-param\\." \
+ "When enabled, test param does something useful\\. When disabled, does nothing\\."] \
+ "show help"
+ gdb_test "help set print test-param" \
+ [multi_line \
+ "^Set the state of the boolean test-param\\." \
+ "When enabled, test param does something useful\\. When disabled, does nothing\\."] \
+ "set help"
+ gdb_test "help set print" \
+ "set print test-param -- Set the state of the boolean test-param.*" \
+ "general help"
gdb_test "guile (print (parameter? test-param))" "= #t"
gdb_test "guile (print (parameter? 42))" "= #f"
@@ -314,9 +325,17 @@ with_test_prefix "test-undocumented-param" {
gdb_test "show print test-undoc-param" "The state of the Test Parameter is on." "show parameter on"
gdb_test_no_output "set print test-undoc-param off"
gdb_test "show print test-undoc-param" "The state of the Test Parameter is off." "show parameter off"
- gdb_test "help show print test-undoc-param" "This command is not documented." "show help"
- gdb_test "help set print test-undoc-param" "This command is not documented." "set help"
- gdb_test "help set print" "set print test-undoc-param -- This command is not documented.*" "general help"
+ gdb_test "help show print test-undoc-param" \
+ [multi_line \
+ "^Show the current value of 'print test-undoc-param'\\." \
+ "This command is not documented\\."] \
+ "show help"
+ gdb_test "help set print test-undoc-param" \
+ [multi_line \
+ "Set the current value of 'print test-undoc-param'\\." \
+ "This command is not documented\\."] \
+ "set help"
+ gdb_test "help set print" "set print test-undoc-param -- Set the current value of 'print test-undoc-param'\\..*" "general help"
}
# Test a parameter with a restricted range, where we need to notify the user
@@ -379,60 +398,218 @@ gdb_test_no_output "guile (register-parameter! prev-ambig)"
with_test_prefix "previously-ambiguous" {
gdb_test "guile (print (parameter-value prev-ambig))" "= #f" "parameter value, false"
- gdb_test "show print s" "Command is not documented is off." "show parameter off"
+ gdb_test "show print s" \
+ "The current value of 'print s' is off\\." "show parameter off"
gdb_test_no_output "set print s on"
- gdb_test "show print s" "Command is not documented is on." "show parameter on"
+ gdb_test "show print s" \
+ "The current value of 'print s' is on\\." "show parameter on"
gdb_test "guile (print (parameter-value prev-ambig))" "= #t" "parameter value, true"
- gdb_test "help show print s" "This command is not documented." "show help"
- gdb_test "help set print s" "This command is not documented." "set help"
- gdb_test "help set print" "set print s -- This command is not documented.*" "general help"
+ gdb_test "help show print s" \
+ [multi_line \
+ "^Show the current value of 'print s'\\." \
+ "This command is not documented\\."] \
+ "show help"
+ gdb_test "help set print s" \
+ [multi_line \
+ "Set the current value of 'print s'\\." \
+ "This command is not documented\\."] \
+ "set help"
+ gdb_test "help set print" \
+ "set print s -- Set the current value of 'print s'\\..*" \
+ "general help"
}
-rename scm_param_test_maybe_no_output ""
-
-# Test a color parameter.
+gdb_test_multiline "create set/show foo1 prefix commands" \
+ "guile" "" \
+ "(register-command! (make-command \"set foo1\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:prefix? #t))" "" \
+ "(register-command! (make-command \"show foo1\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:prefix? #t))" "" \
+ "end"
-with_ansi_styling_terminal {
- # This enables 256 colors support and disables colors approximation.
- setenv TERM xterm-256color
- setenv COLORTERM truecolor
+gdb_test_multiline "create set/show foo1 baz1 prefix commands" \
+ "guile" "" \
+ "(register-command! (make-command \"set foo1 baz1\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:prefix? #t))" "" \
+ "(register-command! (make-command \"show foo1 baz1\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:prefix? #t))" "" \
+ "end"
- # Start with a fresh gdb.
- gdb_exit
- gdb_start
- gdb_reinitialize_dir $srcdir/$subdir
+gdb_test_multiline "create 'foo bar' parameter" \
+ "guile" "" \
+ "(register-parameter! (make-parameter \"foo bar\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:parameter-type PARAM_BOOLEAN" "" \
+ " #:show-func (lambda (self value)" "" \
+ " (format #f \"The state of 'foo bar' is ~a.\" value))" "" \
+ " #:initial-value #t))" "" \
+ "end"
- gdb_install_guile_utils
- gdb_install_guile_module
+gdb_test "show foo1 bar" "^The state of 'foo bar' is on\\." "show parameter 'foo bar'"
- # We use "." here instead of ":" so that this works on win32 too.
- set escaped_directory [string_to_regexp "$srcdir/$subdir"]
+gdb_test_multiline "create set/show foo2 prefix commands" \
+ "guile" "" \
+ "(register-command! (make-command \"set foo2\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:prefix? #t))" "" \
+ "(register-command! (make-command \"show foo2\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:prefix? #t))" "" \
+ "end" ""
+
+gdb_test_multiline "create ambiguous 'foo baz' parameter" \
+ "guile" "" \
+ "(register-parameter! (make-parameter \"foo baz\"" "" \
+ " #:command-class COMMAND_OBSCURE" "" \
+ " #:parameter-type PARAM_BOOLEAN" "" \
+ " #:show-func (lambda (self value)" "" \
+ " (format #f \"The state of 'foo baz' is ~a.\" value))" "" \
+ " #:initial-value #t))" "" \
+ "end" \
+ [multi_line \
+ "Out of range: could not find command prefix 'foo' in position 1: \"foo baz\"" \
+ "Error while executing Scheme code."]
- gdb_test_multiline "color gdb parameter" \
+with_test_prefix "empty doc string" {
+ gdb_test_multiline "empty doc string parameter" \
"guile" "" \
- "(define test-color-param" "" \
- " (make-parameter \"print test-color-param\"" "" \
- " #:command-class COMMAND_DATA" "" \
- " #:parameter-type PARAM_COLOR" "" \
- " #:doc \"When set, test param does something useful. When disabled, does nothing.\"" "" \
- " #:show-doc \"Show the state of the test-color-param.\"" "" \
- " #:set-doc \"Set the state of the test-color-param.\"" "" \
- " #:show-func (lambda (self value)" "" \
- " (format #f \"The state of the test-color-param is ~a.\" value))" "" \
- " #:initial-value (make-color \"green\")))" "" \
- "(register-parameter! test-color-param)" "" \
+ "(register-parameter! (make-parameter \"empty-doc-string\"" "" \
+ " #:command-class COMMAND_NONE" "" \
+ " #:parameter-type PARAM_ZINTEGER" "" \
+ " #:doc \"\"" "" \
+ " #:set-doc \"Set doc string.\"" "" \
+ " #:show-doc \"Show doc string.\"))" "" \
"end"
- with_test_prefix "test-color-param" {
- with_test_prefix "initial-value" {
- gdb_test "guile (print (parameter-value test-color-param))" "= #<gdb:color green COLORSPACE_ANSI_8COLOR>" "color parameter value (green)"
- gdb_test "show print test-color-param" "The state of the test-color-param is green." "show initial value"
- gdb_test_no_output "set print test-color-param 255"
- }
- with_test_prefix "new-value" {
- gdb_test "show print test-color-param" "The state of the test-color-param is 255." "show new value"
- gdb_test "guile (print (parameter-value test-color-param))" "= #<gdb:color 255 COLORSPACE_XTERM_256COLOR>" "color parameter value (255)"
- gdb_test "set print test-color-param 256" "integer 256 out of range.*" "set invalid color parameter"
+ gdb_test "help set empty-doc-string" "^Set doc string\\."
+ gdb_test "help show empty-doc-string" "^Show doc string\\."
+}
+
+with_test_prefix "set/show parameter" {
+ # This first set/show prefix command doesn't have an invoke
+ # method. As such, GDB installs the default invoke behaviour; set
+ # prints the full list of sub-commands, and show prints all the
+ # sub-command values.
+ gdb_test_multiline "Setup set/show parameter prefix with no invoke" \
+ "guile" "" \
+ "(register-command! (make-command \"set test-prefix\"" "" \
+ " #:prefix? #t" "" \
+ " #:command-class COMMAND_NONE))" ""\
+ "(register-command! (make-command \"show test-prefix\"" "" \
+ " #:prefix? #t" "" \
+ " #:command-class COMMAND_NONE))" ""\
+ "(register-parameter! (make-parameter \"test-prefix param-1\"" "" \
+ " #:command-class COMMAND_NONE" "" \
+ " #:parameter-type PARAM_BOOLEAN))" "" \
+ "(register-parameter! (make-parameter \"test-prefix param-2\"" "" \
+ " #:command-class COMMAND_NONE" "" \
+ " #:parameter-type PARAM_UINTEGER))" "" \
+ "(register-parameter! (make-parameter \"test-prefix param-3\"" "" \
+ " #:command-class COMMAND_NONE" "" \
+ " #:parameter-type PARAM_STRING))" "" \
+ "end" ""
+
+ gdb_test "set test-prefix" \
+ [multi_line \
+ "List of \"set test-prefix\" subcommands:" \
+ "" \
+ "set test-prefix param-1 -- Set the current value of 'test-prefix param-1'." \
+ "set test-prefix param-2 -- Set the current value of 'test-prefix param-2'." \
+ "set test-prefix param-3 -- Set the current value of 'test-prefix param-3'." \
+ "" \
+ "Type \"help set test-prefix\" followed by subcommand name for full documentation\\." \
+ "Type \"apropos word\" to search for commands related to \"word\"\\." \
+ "Type \"apropos -v word\" for full documentation of commands related to \"word\"\\." \
+ "Command name abbreviations are allowed if unambiguous\\."]
+
+ gdb_test "show test-prefix" \
+ [multi_line \
+ "test-prefix param-1: The current value of 'test-prefix param-1' is off\\." \
+ "test-prefix param-2: The current value of 'test-prefix param-2' is 0\\." \
+ "test-prefix param-3: The current value of 'test-prefix param-3' is \"\"\\."]
+
+ # This next set/show prefix has an invoke method, which will be
+ # called instead of the default behaviour tested above.
+ gdb_test_multiline "Setup set/show parameter prefix with invoke" \
+ "guile" "" \
+ "(register-command! (make-command \"set test-prefix-2\"" "" \
+ " #:prefix? #t" "" \
+ " #:command-class COMMAND_NONE" ""\
+ " #:invoke (lambda (self arg from-tty)" "" \
+ " (display \"invoke -- set\\n\"))))" "" \
+ "(register-command! (make-command \"show test-prefix-2\"" "" \
+ " #:prefix? #t" "" \
+ " #:command-class COMMAND_NONE" ""\
+ " #:invoke (lambda (self arg from-tty)" "" \
+ " (display \"invoke -- show\\n\"))))" "" \
+ "(register-parameter! (make-parameter \"test-prefix-2 param-1\"" "" \
+ " #:command-class COMMAND_NONE" "" \
+ " #:parameter-type PARAM_BOOLEAN))" "" \
+ "(register-parameter! (make-parameter \"test-prefix-2 param-2\"" "" \
+ " #:command-class COMMAND_NONE" "" \
+ " #:parameter-type PARAM_UINTEGER))" "" \
+ "(register-parameter! (make-parameter \"test-prefix-2 param-3\"" "" \
+ " #:command-class COMMAND_NONE" "" \
+ " #:parameter-type PARAM_STRING))" "" \
+ "end" ""
+
+ gdb_test "set test-prefix-2" "^invoke -- set"
+
+ gdb_test "show test-prefix-2" "^invoke -- show"
+}
+
+rename scm_param_test_maybe_no_output ""
+
+# Test a color parameter.
+
+if { ![is_remote host] } {
+ with_ansi_styling_terminal {
+
+ # This enables 256 colors support and disables colors approximation.
+ setenv TERM xterm-256color
+ setenv COLORTERM truecolor
+
+ # Start with a fresh gdb.
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+
+ gdb_install_guile_utils
+ gdb_install_guile_module
+
+ # We use "." here instead of ":" so that this works on win32 too.
+ set escaped_directory [string_to_regexp "$srcdir/$subdir"]
+
+ gdb_test_multiline "color gdb parameter" \
+ "guile" "" \
+ "(define test-color-param" "" \
+ " (make-parameter \"print test-color-param\"" "" \
+ " #:command-class COMMAND_DATA" "" \
+ " #:parameter-type PARAM_COLOR" "" \
+ " #:doc \"When set, test param does something useful. When disabled, does nothing.\"" "" \
+ " #:show-doc \"Show the state of the test-color-param.\"" "" \
+ " #:set-doc \"Set the state of the test-color-param.\"" "" \
+ " #:show-func (lambda (self value)" "" \
+ " (format #f \"The state of the test-color-param is ~a.\" value))" "" \
+ " #:initial-value (make-color \"green\")))" "" \
+ "(register-parameter! test-color-param)" "" \
+ "end"
+
+ with_test_prefix "test-color-param" {
+ with_test_prefix "initial-value" {
+ gdb_test "guile (print (parameter-value test-color-param))" "= #<gdb:color green COLORSPACE_ANSI_8COLOR>" "color parameter value (green)"
+ gdb_test "show print test-color-param" "The state of the test-color-param is green." "show initial value"
+ gdb_test_no_output "set print test-color-param 255"
+ }
+ with_test_prefix "new-value" {
+ gdb_test "show print test-color-param" "The state of the test-color-param is 255." "show new value"
+ gdb_test "guile (print (parameter-value test-color-param))" "= #<gdb:color 255 COLORSPACE_XTERM_256COLOR>" "color parameter value (255)"
+ gdb_test "set print test-color-param 256" "integer 256 out of range.*" "set invalid color parameter"
+ }
}
}
}
diff --git a/gdb/testsuite/gdb.linespec/linespec.exp b/gdb/testsuite/gdb.linespec/linespec.exp
index 69744dd..86b55bb 100644
--- a/gdb/testsuite/gdb.linespec/linespec.exp
+++ b/gdb/testsuite/gdb.linespec/linespec.exp
@@ -194,6 +194,12 @@ gdb_test "break lspec.h:$line" \
"Breakpoint \[0-9\]+ at $hex: file .*lspec.h, line $line." \
"set breakpoint in f1"
+# This should only have a single location -- in no_multi_locs.
+set line [gdb_get_line_number no_multi_locs]
+gdb_test "break $line" \
+ "Breakpoint \[0-9\]+ at $hex: file .*$srcfile, line $line." \
+ "set breakpoint at no_multi_locs"
+
#
# Multi-inferior tests.
#
diff --git a/gdb/testsuite/gdb.linespec/lspec.cc b/gdb/testsuite/gdb.linespec/lspec.cc
index bb660fb..ab0a193 100644
--- a/gdb/testsuite/gdb.linespec/lspec.cc
+++ b/gdb/testsuite/gdb.linespec/lspec.cc
@@ -13,6 +13,8 @@ int body_elsewhere()
#include "body.h"
}
+void no_multi_locs () { {int var = 0;} }
+
int main()
{
return dupname(0) + m(0) + n(0) + f1() + f2() + body_elsewhere();
diff --git a/gdb/testsuite/gdb.mi/interrupt-thread-group.exp b/gdb/testsuite/gdb.mi/interrupt-thread-group.exp
index ff35109..869fb1c 100644
--- a/gdb/testsuite/gdb.mi/interrupt-thread-group.exp
+++ b/gdb/testsuite/gdb.mi/interrupt-thread-group.exp
@@ -54,7 +54,7 @@ mi_send_resuming_command "exec-continue --thread-group i1" \
# We can't run a second inferior on stub targets. We can still test with one
# inferior and ensure that the command has the desired effect.
-set use_second_inferior [expr {![use_gdb_stub]}]
+set use_second_inferior [expr {![use_gdb_stub] && [allow_multi_inferior_tests]}]
if { $use_second_inferior } {
mi_gdb_test "-add-inferior" \
diff --git a/gdb/testsuite/gdb.mi/mi-condbreak-throw.exp b/gdb/testsuite/gdb.mi/mi-condbreak-throw.exp
index 9897b2b..0a89a8a 100644
--- a/gdb/testsuite/gdb.mi/mi-condbreak-throw.exp
+++ b/gdb/testsuite/gdb.mi/mi-condbreak-throw.exp
@@ -16,7 +16,7 @@
# Check that when GDB fails to evaluate the condition of a conditional
# breakpoint we only get one *stopped notification. In this test case
# the breakpoint condition fails due to throwing an uncaught C++
-# excpetion.
+# exception.
require allow_cplus_tests
diff --git a/gdb/testsuite/gdb.mi/mi-corefile.exp b/gdb/testsuite/gdb.mi/mi-corefile.exp
index 3f0e720..b491486 100644
--- a/gdb/testsuite/gdb.mi/mi-corefile.exp
+++ b/gdb/testsuite/gdb.mi/mi-corefile.exp
@@ -29,6 +29,7 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
set corefile [core_find $binfile {}]
if {$corefile == ""} {
+ untested "unable to create or find corefile"
return 0
}
diff --git a/gdb/testsuite/gdb.mi/mi-dlmopen.exp b/gdb/testsuite/gdb.mi/mi-dlmopen.exp
index c0208eb..936027f 100644
--- a/gdb/testsuite/gdb.mi/mi-dlmopen.exp
+++ b/gdb/testsuite/gdb.mi/mi-dlmopen.exp
@@ -65,9 +65,19 @@ if { $dyln_name eq "" } {
set bp_main [gdb_get_line_number "bp.main" $srcfile]
set bp_loaded [gdb_get_line_number "bp.loaded" $srcfile]
+# If the dynamic linker path contains a symlink, some instances show the real
+# path instead of the original path. Accept both.
+lassign [remote_exec target realpath "$dyln_name"] realpath_ret dyln_realpath_name
+
+if { $realpath_ret == 0 } {
+ set dyln_realpath_name [string trim $dyln_realpath_name]
+} else {
+ set dyln_realpath_name "not-a-valid-path"
+}
+
# Return true if FILENAME is the dynamic linker. Otherwise return false.
proc is_dyln { filename } {
- return [expr {$filename eq $::dyln_name}]
+ return [expr {$filename eq $::dyln_name || $filename eq $::dyln_realpath_name}]
}
# Run 'info sharedlibrary' and count the number of mappings that look
@@ -81,7 +91,7 @@ proc get_dyld_info {} {
set dyld_count 0
set dyld_start_addr ""
gdb_test_multiple "info sharedlibrary" "" {
- -re "~\"From\\s+To(\\s+NS)?\\s+Syms\\s+Read\\s+Shared Object Library\\\\n\"\r\n" {
+ -re "~\"From\\s+To(\\s+Linker NS)?\\s+Syms\\s+Read\\s+Shared Object Library\\\\n\"\r\n" {
exp_continue
}
-re "^~\"($::hex)\\s+${::hex}(\\s+$::decimal)?\\s+\[^/\]+(/\[^\r\n\]+)\\\\n\"\r\n" {
diff --git a/gdb/testsuite/gdb.mi/mi-exec-run.exp b/gdb/testsuite/gdb.mi/mi-exec-run.exp
index a7a61b8..43406cf 100644
--- a/gdb/testsuite/gdb.mi/mi-exec-run.exp
+++ b/gdb/testsuite/gdb.mi/mi-exec-run.exp
@@ -30,6 +30,8 @@ set MIFLAGS "-i=mi"
# cannot use it, then there is no point in running this testcase.
require !use_gdb_stub
+set have_startup_shell [have_startup_shell]
+
standard_testfile mi-start.c
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
@@ -172,6 +174,9 @@ remote_exec target "chmod \"a-x\" $binfile.nox"
foreach_with_prefix inferior-tty {"main" "separate"} {
foreach_with_prefix mi {"main" "separate"} {
foreach_with_prefix force-fail {0 1} {
+ if { ${force-fail} && $have_startup_shell == -1 } {
+ continue
+ }
test ${inferior-tty} ${mi} ${force-fail}
}
}
diff --git a/gdb/testsuite/gdb.mi/mi-multi-commands.exp b/gdb/testsuite/gdb.mi/mi-multi-commands.exp
index 20b8d46..3bc63eb 100644
--- a/gdb/testsuite/gdb.mi/mi-multi-commands.exp
+++ b/gdb/testsuite/gdb.mi/mi-multi-commands.exp
@@ -90,7 +90,7 @@ proc run_test { args } {
# looking for. However, due to the unpredictable
# intermingling, it's much easier if we drop the ^ anchor.
# However, with this gone dejagnu would sometimes match the
- # second comand output before the first commands output.
+ # second command output before the first commands output.
#
# This approach just looks for the first command output, then,
# once that has been found, we start looking for the second
diff --git a/gdb/testsuite/gdb.mi/mi-var-display.exp b/gdb/testsuite/gdb.mi/mi-var-display.exp
index 61b3894..5535368 100644
--- a/gdb/testsuite/gdb.mi/mi-var-display.exp
+++ b/gdb/testsuite/gdb.mi/mi-var-display.exp
@@ -96,7 +96,7 @@ mi_gdb_test "-var-evaluate-expression bar" \
# Desc: change value of bar
mi_gdb_test "-var-assign bar 3" \
"\\^done,value=\"0x3\"" \
- "assing to variable bar"
+ "assign to variable bar"
mi_gdb_test "-var-set-format bar decimal" \
"\\^done,format=\"decimal\",value=\"3\"" \
@@ -152,7 +152,7 @@ mi_gdb_test "-var-evaluate-expression foo" \
# Desc: change value of foo
mi_gdb_test "-var-assign foo 3" \
"\\^done,value=\"03\"" \
- "assing to variable foo"
+ "assign to variable foo"
mi_gdb_test "-var-set-format foo decimal" \
"\\^done,format=\"decimal\",value=\"3\"" \
diff --git a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
index 9198cfb..f85e108 100644
--- a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
+++ b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
@@ -40,6 +40,8 @@ standard_testfile
# gdbserver modes are supported.
require !use_gdb_stub
+require allow_multi_inferior_tests
+
set compile_options "debug pthreads"
if {[build_executable $testfile.exp $testfile ${srcfile} ${compile_options}] == -1} {
untested "failed to compile"
@@ -985,7 +987,7 @@ proc_with_prefix test_mi_stack_select_frame { mode } {
# Now use the '-stack-select-frame' command with the --frame
# option, this verifies that even when the frame GDB would
- # swith to is the same as the frame specified with --frame, an
+ # switch to is the same as the frame specified with --frame, an
# event is still sent to the CLI.
set cli_re [make_cli_re $mode -1 -1 0]
diff --git a/gdb/testsuite/gdb.multi/attach-no-multi-process.exp b/gdb/testsuite/gdb.multi/attach-no-multi-process.exp
index 28aabaf..502f309 100644
--- a/gdb/testsuite/gdb.multi/attach-no-multi-process.exp
+++ b/gdb/testsuite/gdb.multi/attach-no-multi-process.exp
@@ -59,7 +59,10 @@ proc test {target_non_stop} {
"switch to inferior 2"
set res [gdbserver_start "--multi" ""]
set gdbserver_gdbport [lindex $res 1]
- gdb_target_cmd "extended-remote" $gdbserver_gdbport
+ if { [gdb_target_cmd_ext "extended-remote" $gdbserver_gdbport] == 2 } {
+ unsupported "non-stop RSP"
+ return
+ }
# Start a program, then attach to it.
set spawn_id_list [spawn_wait_for_attach [list $binfile]]
diff --git a/gdb/testsuite/gdb.multi/attach-while-running.exp b/gdb/testsuite/gdb.multi/attach-while-running.exp
index 5b63030..723ebb2 100644
--- a/gdb/testsuite/gdb.multi/attach-while-running.exp
+++ b/gdb/testsuite/gdb.multi/attach-while-running.exp
@@ -37,6 +37,7 @@
standard_testfile
require can_spawn_for_attach
+require allow_multi_inferior_tests
if { [build_executable "failed to prepare" ${testfile} ${srcfile}] } {
return
@@ -49,7 +50,7 @@ proc do_test {} {
}
gdb_test -no-prompt-anchor "run &"
- gdb_test "add-inferior" "Added inferior 2 on connection 1 .*"
+ gdb_test -no-prompt-anchor "add-inferior" "Added inferior 2 on connection 1 .*"
gdb_test "inferior 2" "Switching to inferior 2 .*"
set spawn_id [spawn_wait_for_attach $::binfile]
diff --git a/gdb/testsuite/gdb.multi/bp-thread-specific.exp b/gdb/testsuite/gdb.multi/bp-thread-specific.exp
index 32b7602..3fe4c20 100644
--- a/gdb/testsuite/gdb.multi/bp-thread-specific.exp
+++ b/gdb/testsuite/gdb.multi/bp-thread-specific.exp
@@ -19,6 +19,8 @@
# Also check that the correct thread-ids are used in the saved
# breakpoints file.
+require allow_multi_inferior_tests
+
# The plain remote target can't do multiple inferiors.
require !use_gdb_stub
diff --git a/gdb/testsuite/gdb.multi/dummy-frame-restore.exp b/gdb/testsuite/gdb.multi/dummy-frame-restore.exp
index 1a9d413..4119e3f 100644
--- a/gdb/testsuite/gdb.multi/dummy-frame-restore.exp
+++ b/gdb/testsuite/gdb.multi/dummy-frame-restore.exp
@@ -19,6 +19,8 @@ set executable ${testfile}
# The plain remote target can't do multiple inferiors.
require !use_gdb_stub
+require allow_multi_inferior_tests
+
if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug}]} {
return -1
}
diff --git a/gdb/testsuite/gdb.multi/multi-arch.exp b/gdb/testsuite/gdb.multi/multi-arch.exp
index d0ae511..1d41ba5 100644
--- a/gdb/testsuite/gdb.multi/multi-arch.exp
+++ b/gdb/testsuite/gdb.multi/multi-arch.exp
@@ -18,6 +18,8 @@
set testfile "multi-arch"
+require allow_multi_inferior_tests
+
# The plain remote target can't do multiple inferiors.
require !use_gdb_stub
diff --git a/gdb/testsuite/gdb.multi/multi-attach.exp b/gdb/testsuite/gdb.multi/multi-attach.exp
index 2d702ee..210c8ca 100644
--- a/gdb/testsuite/gdb.multi/multi-attach.exp
+++ b/gdb/testsuite/gdb.multi/multi-attach.exp
@@ -17,6 +17,8 @@
# Test attaching to multiple threaded programs.
+require allow_multi_inferior_tests
+
standard_testfile
require can_spawn_for_attach
diff --git a/gdb/testsuite/gdb.multi/multi-exit.exp b/gdb/testsuite/gdb.multi/multi-exit.exp
index 71236c1..8393067 100644
--- a/gdb/testsuite/gdb.multi/multi-exit.exp
+++ b/gdb/testsuite/gdb.multi/multi-exit.exp
@@ -24,6 +24,8 @@
standard_testfile
+require allow_multi_inferior_tests
+
require !use_gdb_stub
if {[build_executable "failed to prepare" $testfile $srcfile]} {
diff --git a/gdb/testsuite/gdb.multi/multi-kill.exp b/gdb/testsuite/gdb.multi/multi-kill.exp
index 48a2534..7d66ab0 100644
--- a/gdb/testsuite/gdb.multi/multi-kill.exp
+++ b/gdb/testsuite/gdb.multi/multi-kill.exp
@@ -24,6 +24,8 @@
standard_testfile
+require allow_multi_inferior_tests
+
require !use_gdb_stub
if {[build_executable "failed to prepare" $testfile $srcfile {debug}]} {
diff --git a/gdb/testsuite/gdb.multi/multi-re-run.exp b/gdb/testsuite/gdb.multi/multi-re-run.exp
index 002de57..4caadea 100644
--- a/gdb/testsuite/gdb.multi/multi-re-run.exp
+++ b/gdb/testsuite/gdb.multi/multi-re-run.exp
@@ -20,6 +20,8 @@
# misbehave, including failing to load libthread_db.so. See PR
# gdb/25410.
+require allow_multi_inferior_tests
+
# Build two executables, with different symbols.
set exec1 "multi-re-run-1"
diff --git a/gdb/testsuite/gdb.multi/multi-target.exp.tcl b/gdb/testsuite/gdb.multi/multi-target.exp.tcl
index 8c24602..dc88ca4 100644
--- a/gdb/testsuite/gdb.multi/multi-target.exp.tcl
+++ b/gdb/testsuite/gdb.multi/multi-target.exp.tcl
@@ -175,6 +175,10 @@ proc multi_target_prepare {} {
return 0
}
+ if {![allow_multi_inferior_tests]} {
+ return 0
+ }
+
# The plain remote target can't do multiple inferiors.
if {[target_info gdb_protocol] != ""} {
return 0
diff --git a/gdb/testsuite/gdb.multi/multi-term-settings.exp b/gdb/testsuite/gdb.multi/multi-term-settings.exp
index 2f8b3b8..38322be 100644
--- a/gdb/testsuite/gdb.multi/multi-term-settings.exp
+++ b/gdb/testsuite/gdb.multi/multi-term-settings.exp
@@ -25,6 +25,8 @@
standard_testfile
+require allow_multi_inferior_tests
+
require can_spawn_for_attach
if [build_executable "failed to prepare" $testfile $srcfile {debug}] {
diff --git a/gdb/testsuite/gdb.multi/pending-bp.exp b/gdb/testsuite/gdb.multi/pending-bp.exp
index 1cd1cfb..2458cd7 100644
--- a/gdb/testsuite/gdb.multi/pending-bp.exp
+++ b/gdb/testsuite/gdb.multi/pending-bp.exp
@@ -328,5 +328,7 @@ proc_with_prefix py_test_clear_thread {} {
# Run all the tests.
test_no_inf_display
test_pending_toggle
-py_test_toggle_thread
-py_test_clear_thread
+if { [allow_python_tests] } {
+ py_test_toggle_thread
+ py_test_clear_thread
+}
diff --git a/gdb/testsuite/gdb.multi/start-inferior-specific.exp b/gdb/testsuite/gdb.multi/start-inferior-specific.exp
index 819c1c3..74f984c 100644
--- a/gdb/testsuite/gdb.multi/start-inferior-specific.exp
+++ b/gdb/testsuite/gdb.multi/start-inferior-specific.exp
@@ -25,6 +25,8 @@
standard_testfile .c -other.c
+require allow_multi_inferior_tests
+
require !use_gdb_stub
set srcfile_other ${srcfile2}
diff --git a/gdb/testsuite/gdb.multi/stop-all-on-exit.exp b/gdb/testsuite/gdb.multi/stop-all-on-exit.exp
index b4ff09c..47071f3 100644
--- a/gdb/testsuite/gdb.multi/stop-all-on-exit.exp
+++ b/gdb/testsuite/gdb.multi/stop-all-on-exit.exp
@@ -18,6 +18,8 @@
# Test that in all-stop mode with multiple inferiors, GDB stops all
# threads upon receiving an exit event from one of the inferiors.
+require allow_multi_inferior_tests
+
# This is a test specific for a native target, where we use the
# "-exec" argument to "add-inferior" and we explicitly don't do
# "maint set target-non-stop on".
diff --git a/gdb/testsuite/gdb.multi/tids-gid-reset.exp b/gdb/testsuite/gdb.multi/tids-gid-reset.exp
index 6cc27eb..1785ac2 100644
--- a/gdb/testsuite/gdb.multi/tids-gid-reset.exp
+++ b/gdb/testsuite/gdb.multi/tids-gid-reset.exp
@@ -54,6 +54,8 @@ with_test_prefix "single-inferior" {
# non-extended gdbserver is not supported.
require !use_gdb_stub
+require allow_multi_inferior_tests
+
# Test with multiple inferiors. This time, since we restart inferior
# 1 while inferior 2 still has threads, then the new thread 1.1 should
# end up with GID == 3, since we won't be able to reset the global
diff --git a/gdb/testsuite/gdb.multi/tids.exp b/gdb/testsuite/gdb.multi/tids.exp
index b84f908..436a38a 100644
--- a/gdb/testsuite/gdb.multi/tids.exp
+++ b/gdb/testsuite/gdb.multi/tids.exp
@@ -124,6 +124,9 @@ with_test_prefix "single inferior" {
gdb_test "print \$_inferior_thread_count" " = 1"
}
+# The rest of the tests require running multiple inferiors.
+require allow_multi_inferior_tests
+
# "info threads" while there are multiple inferiors should show
# qualified thread IDs.
with_test_prefix "two inferiors" {
@@ -290,7 +293,7 @@ with_test_prefix "two inferiors" {
# Try both the convenience variable and the literal number.
foreach thr {"\$thr" "20" "1.20" "\$inf.1" "30.1" } {
set expected [string_to_regexp $thr]
- gdb_test "info threads $thr" "No threads match '${expected}'."
+ gdb_test "info threads $thr" "No threads matched\\."
# "info threads" works like a filter. If there's any other
# valid thread in the list, there's no error.
info_threads "$thr 1.1" "1.1"
@@ -412,7 +415,7 @@ with_test_prefix "two inferiors" {
# Check that we do parse the inferior number and don't confuse it.
gdb_test "info threads 3.1" \
- "No threads match '3.1'\."
+ "No threads matched\\."
}
if { [allow_python_tests] } {
diff --git a/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp b/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp
index 70c3da9..3446296 100644
--- a/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp
+++ b/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp
@@ -17,6 +17,8 @@
# watchpoints don't end up with stale locations, preventing resumption
# of other inferiors.
+require allow_fork_tests
+
standard_testfile
if {[build_executable "failed to build" $testfile $srcfile {debug}]} {
diff --git a/gdb/testsuite/gdb.multi/watchpoint-multi.exp b/gdb/testsuite/gdb.multi/watchpoint-multi.exp
index f448689..b0c8731 100644
--- a/gdb/testsuite/gdb.multi/watchpoint-multi.exp
+++ b/gdb/testsuite/gdb.multi/watchpoint-multi.exp
@@ -16,6 +16,8 @@
standard_testfile
set executable ${testfile}
+require allow_multi_inferior_tests
+
# Multiple inferiors are needed, therefore both native and extended gdbserver
# modes are supported. Only non-extended gdbserver is not supported.
require !use_gdb_stub
diff --git a/gdb/testsuite/gdb.opt/break-on-_exit.exp b/gdb/testsuite/gdb.opt/break-on-_exit.exp
index 2b94be8..9295fea 100644
--- a/gdb/testsuite/gdb.opt/break-on-_exit.exp
+++ b/gdb/testsuite/gdb.opt/break-on-_exit.exp
@@ -25,7 +25,7 @@
# for libc, then the breakpoint is set on the exec-local _exit@plt instead,
# and that functionality will also not be used.
#
-# We may get the required setup in case of a libc with misssing separate
+# We may get the required setup in case of a libc with missing separate
# debuginfo, but we want the same effect if that debuginfo is installed.
#
# So, we use -readnever to read minimal symbols, but not non-miminal symbols.
diff --git a/gdb/testsuite/gdb.pascal/integers.exp b/gdb/testsuite/gdb.pascal/integers.exp
index 5c878c5..c9974a1 100644
--- a/gdb/testsuite/gdb.pascal/integers.exp
+++ b/gdb/testsuite/gdb.pascal/integers.exp
@@ -59,7 +59,7 @@ gdb_test "next" "l := k;" "next to 'l := k' line"
gdb_test "print j" " = 2"
# k should be equal to 3
gdb_test "print k" " = 3"
-# But l shoud still be zero
+# But l should still be zero
if { $pascal_compiler_is_gpc } {
setup_xfail *-*-*
}
diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp
index f76c176..1fa3c73 100644
--- a/gdb/testsuite/gdb.python/py-cmd.exp
+++ b/gdb/testsuite/gdb.python/py-cmd.exp
@@ -278,13 +278,7 @@ gdb_test_multiline "input multi-line-output command" \
set test "verify pagination from test_multiline"
gdb_test_multiple "test_multiline" $test {
- -re "--Type <RET>" {
- exp_continue
- }
- -re " for more, q to quit" {
- exp_continue
- }
- -re ", c to continue without paging--$" {
+ -re "$pagination_prompt$" {
pass $test
}
}
@@ -328,4 +322,89 @@ proc_with_prefix test_command_redefining_itself {} {
"call command redefining itself 2"
}
+# Try to create commands using unknown prefixes and check GDB gives an
+# error. There's also a test in here for an ambiguous prefix, which
+# gives the same error.
+proc_with_prefix test_unknown_prefix {} {
+ clean_restart
+
+ gdb_test_no_output "python gdb.Command('foo1', gdb.COMMAND_NONE, prefix=True)"
+ gdb_test_no_output "python gdb.Command('foo cmd', gdb.COMMAND_NONE)"
+
+ foreach prefix { "xxx" "foo xxx" "foo1 xxx" } {
+ gdb_test "python gdb.Command('$prefix cmd', gdb.COMMAND_NONE)" \
+ [multi_line \
+ "Python Exception <class 'RuntimeError'>: Could not find command prefix $prefix\\." \
+ "Error occurred in Python: Could not find command prefix $prefix\\."]
+ }
+
+ gdb_test_no_output "python gdb.Command('foo2', gdb.COMMAND_NONE, prefix=True)"
+
+ foreach prefix { "foo" "foo xxx" "foo1 xxx" "foo2 xxx" } {
+ gdb_test "python gdb.Command('$prefix cmd2', gdb.COMMAND_NONE)" \
+ [multi_line \
+ "Python Exception <class 'RuntimeError'>: Could not find command prefix $prefix\\." \
+ "Error occurred in Python: Could not find command prefix $prefix\\."]
+ }
+}
+
+# Check what happens if a command object is called without an 'invoke'
+# method.
+proc_with_prefix test_deleting_invoke_methods {} {
+ clean_restart
+
+ gdb_test_multiline "create 'foo' prefix command" \
+ "python" "" \
+ "class test_prefix(gdb.Command):" "" \
+ " def __init__ (self):" "" \
+ " super().__init__ (\"foo\", gdb.COMMAND_USER, prefix=True)" "" \
+ " def invoke (self, arg, from_tty):" "" \
+ " print(\"In 'foo' invoke: %s\" % arg)" "" \
+ "foo = test_prefix()" "" \
+ "end" ""
+
+ gdb_test_multiline "create 'foo bar' command" \
+ "python" "" \
+ "class test_cmd(gdb.Command):" "" \
+ " def __init__ (self):" "" \
+ " super().__init__ (\"foo bar\", gdb.COMMAND_USER)" "" \
+ " def invoke (self, arg, from_tty):" "" \
+ " print(\"In 'foo bar' invoke: %s\" % arg)" "" \
+ "foo_bar = test_cmd()" "" \
+ "end" ""
+
+ gdb_test "foo def" "In 'foo' invoke: def" \
+ "call 'foo' with an unknown sub-command"
+
+ gdb_test "foo bar def" "In 'foo bar' invoke: def" \
+ "call 'foo bar' with arguments"
+
+ gdb_test_no_output "python del(foo_bar.__class__.invoke)" \
+ "delete invoke from test_cmd class"
+
+ with_test_prefix "after deleting test_cmd.invoke" {
+ gdb_test "foo def" "In 'foo' invoke: def" \
+ "call 'foo' with an unknown sub-command"
+
+ gdb_test "foo bar def" \
+ "^Python command object missing 'invoke' method\\." \
+ "call 'foo bar' with arguments"
+ }
+
+ gdb_test_no_output "python del(foo.__class__.invoke)" \
+ "delete invoke from test_prefix class"
+
+ with_test_prefix "after deleting test_prefix.invoke" {
+ gdb_test "foo def" \
+ "^Python command object missing 'invoke' method\\." \
+ "call 'foo' with an unknown sub-command"
+
+ gdb_test "foo bar def" \
+ "^Python command object missing 'invoke' method\\." \
+ "call 'foo bar' with arguments"
+ }
+}
+
test_command_redefining_itself
+test_unknown_prefix
+test_deleting_invoke_methods
diff --git a/gdb/testsuite/gdb.python/py-color-pagination.exp b/gdb/testsuite/gdb.python/py-color-pagination.exp
new file mode 100644
index 0000000..e7a9e4f
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-color-pagination.exp
@@ -0,0 +1,137 @@
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the GDB testsuite. It tests gdb.Color and how this
+# interacts with GDB's pagination system.
+
+load_lib gdb-python.exp
+
+require allow_python_tests
+require {!is_remote host}
+
+standard_testfile
+
+set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
+
+set str "<[string repeat - 78]>"
+
+# These define all the default attributes for a style: background
+# color, intensity, italics, and underlined.
+set other_attr ";49;22;23;24;27"
+
+# These colors set the foreground color only. Everything else is the
+# default.
+set black "(?:\033\\\[30${other_attr}m)"
+set red "(?:\033\\\[31${other_attr}m)"
+set green "(?:\033\\\[32${other_attr}m)"
+set yellow "(?:\033\\\[33${other_attr}m)"
+set blue "(?:\033\\\[34${other_attr}m)"
+set magenta "(?:\033\\\[35${other_attr}m)"
+set cyan "(?:\033\\\[36${other_attr}m)"
+set white "(?:\033\\\[37${other_attr}m)"
+
+set any_color "(?:${black}|${red}|${green}|${yellow}|${blue}|${magenta}|${cyan}|${white})"
+
+# Run the command 'TYPE-fill MODE' which fills the screen with output and
+# triggers the pagination prompt. Check that styling is applied correctly
+# to the output.
+proc test_pagination { type mode } {
+
+ # Start with a fresh GDB, but enable color support.
+ with_ansi_styling_terminal {
+ clean_restart
+ }
+
+ gdb_test_no_output "source $::pyfile" "source the script"
+
+ gdb_test_no_output "set width 80"
+ gdb_test_no_output "set height 15"
+
+ set saw_bad_color_handling false
+ set expected_restore_color ""
+ set last_color ""
+ gdb_test_multiple "$type-fill $mode" "" {
+ -re "^$type-fill $mode\r\n" {
+ exp_continue
+ }
+
+ -re "^(${::any_color})(${::any_color})$::str" {
+ # After a continuation prompt GDB will restore the previous
+ # color, and then we immediately switch to a new color.
+ set restored_color $expect_out(1,string)
+ if { $restored_color ne $expected_restore_color } {
+ set saw_bad_color_handling true
+ }
+ set last_color $expect_out(2,string)
+ exp_continue
+ }
+
+ -re "^(${::any_color})$::str" {
+ # This pattern matches printing STR in all cases that are not
+ # immediately after a pagination prompt. In this case there is
+ # a single escape sequence to set the color.
+ set last_color $expect_out(1,string)
+ exp_continue
+ }
+
+ -re "^\033\\\[${::decimal}m$::str" {
+ # This catches the case where the color's escape sequence has
+ # not been converted back into a full style. This indicates
+ # something went wrong in the pager_file::puts function.
+ set saw_bad_color_handling true
+ exp_continue
+ }
+
+ -re "^\033\\\[m$::pagination_prompt$" {
+ # After a pagination prompt we expect GDB to restore the last
+ # color.
+ set expected_restore_color $last_color
+
+ # Send '\n' to view more output.
+ send_gdb "\n"
+ exp_continue
+ }
+
+ -re "^$::pagination_prompt$" {
+ # After a pagination prompt we expect GDB to restore the last
+ # color.
+ set expected_restore_color $last_color
+
+ # If we didn't see a color reset sequence before the pagination
+ # prompt, then the prompt will have been printed in the wrong
+ # color, this is a GDB bug.
+ set saw_bad_color_handling true
+
+ # Send '\n' to view more output.
+ send_gdb "\n"
+ exp_continue
+ }
+
+ -re "^\r\n" {
+ # The matches the newline sent to the continuation prompt.
+ exp_continue
+ }
+
+ -re "^\033\\\[m\r\n$::gdb_prompt $" {
+ gdb_assert { !$saw_bad_color_handling } $gdb_test_name
+ }
+ }
+}
+
+foreach_with_prefix type { color } {
+ foreach_with_prefix mode { write print } {
+ test_pagination $type $mode
+ }
+}
diff --git a/gdb/testsuite/gdb.python/py-color-pagination.py b/gdb/testsuite/gdb.python/py-color-pagination.py
new file mode 100644
index 0000000..efd501e
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-color-pagination.py
@@ -0,0 +1,46 @@
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import gdb
+
+basic_colors = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]
+
+
+def write(mode, text):
+ if mode == "write":
+ gdb.write(text)
+ else:
+ print(text, end="")
+
+
+class ColorTester(gdb.Command):
+ def __init__(self):
+ super().__init__("color-fill", gdb.COMMAND_USER)
+
+ def invoke(self, args, from_tty):
+ mode = args
+ str = "<" + "-" * 78 + ">"
+ for i in range(0, 20):
+ for color_name in basic_colors:
+ c = gdb.Color(color_name)
+ write(mode, c.escape_sequence(True))
+ write(mode, str)
+
+ default = gdb.Color("none")
+ write(mode, default.escape_sequence(True))
+ write(mode, "\n")
+
+
+ColorTester()
diff --git a/gdb/testsuite/gdb.python/py-color.exp b/gdb/testsuite/gdb.python/py-color.exp
index 2601cf3..08089e5 100644
--- a/gdb/testsuite/gdb.python/py-color.exp
+++ b/gdb/testsuite/gdb.python/py-color.exp
@@ -18,6 +18,7 @@
load_lib gdb-python.exp
require allow_python_tests
+require {!is_remote host}
# Start with a fresh GDB, but enable color support.
with_ansi_styling_terminal {
diff --git a/gdb/testsuite/gdb.python/py-format-string.exp b/gdb/testsuite/gdb.python/py-format-string.exp
index 114a606..2463185 100644
--- a/gdb/testsuite/gdb.python/py-format-string.exp
+++ b/gdb/testsuite/gdb.python/py-format-string.exp
@@ -1202,7 +1202,9 @@ with_test_prefix "format_string" {
set current_lang "c"
prepare_gdb "${binfile}"
test_all_common
- test_styling
+ if { ![is_remote host] } {
+ test_styling
+ }
}
}
}
diff --git a/gdb/testsuite/gdb.python/py-parameter-prefix.exp b/gdb/testsuite/gdb.python/py-parameter-prefix.exp
new file mode 100644
index 0000000..eb09fe7
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-parameter-prefix.exp
@@ -0,0 +1,382 @@
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the GDB testsuite. It tests
+# gdb.ParameterPrefix. See each of the test procs for a full
+# description of what is being tested.
+
+load_lib gdb-python.exp
+
+require allow_python_tests
+
+clean_restart
+
+# Helper proc to generate the output of 'show PREFIX' commands for the
+# case where the prefix command doesn't handle unknown sub-commands.
+# In this case GDB will list the value of every sub-command under
+# PREFIX.
+proc make_show_prefix_re { prefix } {
+ return "$prefix param-1:\\s+The current value of '$prefix param-1' is \"off\"\\."
+}
+
+# Helper proc to generate the help text that describes all of the sub
+# commands under PREFIX. The MODE is either 'set' or 'show'. This
+# output will appear for 'help MODE PREFIX' and also for 'set PREFIX'.
+proc make_sub_cmd_help_re { mode prefix } {
+ if { $mode == "set" } {
+ set word "Set"
+ } else {
+ set word "Show"
+ }
+
+ return \
+ [multi_line \
+ "List of \"$mode $prefix\" subcommands:" \
+ "" \
+ "$mode $prefix param-1 -- $word the current value of '$prefix param-1'\\." \
+ "" \
+ "Type \"help $mode $prefix\" followed by subcommand name for full documentation\\." \
+ "Type \"apropos word\" to search for commands related to \"word\"\\." \
+ "Type \"apropos -v word\" for full documentation of commands related to \"word\"\\." \
+ "Command name abbreviations are allowed if unambiguous\\."]
+}
+
+# Helper proc to generate the output of 'help MODE PREFIX', where MODE
+# will be either 'set' or 'show'. The HELP_TEXT is the expected help
+# text for this prefix command, this should not be a regexp, as this
+# proc converts the text to a regexp.
+#
+# Return a single regexp which should match the output.
+proc make_help_re { mode prefix help_text } {
+ set help_re [string_to_regexp $help_text]
+
+ return \
+ [multi_line \
+ "$help_re" \
+ "" \
+ [make_sub_cmd_help_re $mode $prefix]]
+}
+
+# Create gdb.ParameterPrefix without using a sub-class, both with, and
+# without a doc string. For the doc string case, test single line,
+# and multi-line doc strings.
+proc_with_prefix test_basic_usage {} {
+ gdb_test_multiline "some basic ParameterPrefix usage" \
+ "python" "" \
+ "gdb.ParameterPrefix('prefix-1', gdb.COMMAND_NONE)" "" \
+ "gdb.Parameter('prefix-1 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "gdb.Parameter('prefix-1 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "gdb.ParameterPrefix('prefix-2', gdb.COMMAND_NONE," "" \
+ " \"\"\"This is prefix-2 help string.\"\"\")" "" \
+ "gdb.Parameter('prefix-2 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "gdb.ParameterPrefix('prefix-3', gdb.COMMAND_NONE," "" \
+ " \"\"\"This is prefix-3 help string." "" \
+ " " "" \
+ " This help text spans multiple lines.\"\"\")" "" \
+ "gdb.Parameter('prefix-3 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "end"
+
+ foreach mode { "set" "show" } {
+ gdb_test "help $mode prefix-1" \
+ [make_help_re $mode "prefix-1" \
+ "This command is not documented."]
+
+ gdb_test "help $mode prefix-2" \
+ [make_help_re $mode "prefix-2" \
+ "This is prefix-2 help string."]
+
+ gdb_test "help $mode prefix-3" \
+ [make_help_re $mode "prefix-3" \
+ [multi_line \
+ "This is prefix-3 help string." \
+ "" \
+ "This help text spans multiple lines."]]
+
+ foreach prefix { prefix-1 prefix-2 prefix-3 } {
+ gdb_test "$mode $prefix xxx" \
+ "^Undefined $mode $prefix command: \"xxx\"\\. Try \"help $mode $prefix\"\\."
+ }
+ }
+
+ foreach prefix { prefix-1 prefix-2 prefix-3 } {
+ gdb_test "set $prefix" \
+ [make_sub_cmd_help_re "set" $prefix]
+
+ gdb_test "show $prefix" \
+ [make_show_prefix_re $prefix]
+ }
+}
+
+# Create a sub-class of gdb.ParameterPrefix, but don't do anything
+# particularly interesting. Again test the with and without
+# documentation string cases.
+proc_with_prefix test_simple_sub_class {} {
+ gdb_test_multiline "some basic ParameterPrefix usage" \
+ "python" "" \
+ "class BasicParamPrefix(gdb.ParameterPrefix):" "" \
+ " def __init__(self, name):" "" \
+ " super().__init__(name, gdb.COMMAND_NONE)" "" \
+ "BasicParamPrefix('prefix-4')" "" \
+ "gdb.Parameter('prefix-4 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "class BasicParamPrefixWithSingleLineDoc(gdb.ParameterPrefix):" "" \
+ " \"\"\"This is a single line doc string.\"\"\"" "" \
+ " def __init__(self, name):" "" \
+ " super().__init__(name, gdb.COMMAND_NONE)" "" \
+ "BasicParamPrefixWithSingleLineDoc('prefix-5')" "" \
+ "gdb.Parameter('prefix-5 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "class BasicParamPrefixWithMultiLineDoc(gdb.ParameterPrefix):" "" \
+ " \"\"\"This is a multi line doc string." "" \
+ " " "" \
+ " The rest of the doc string is here.\"\"\"" "" \
+ " def __init__(self, name):" "" \
+ " super().__init__(name, gdb.COMMAND_NONE)" "" \
+ "BasicParamPrefixWithMultiLineDoc('prefix-6')" "" \
+ "gdb.Parameter('prefix-6 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "class BasicParamPrefixWithDocParameter(gdb.ParameterPrefix):" "" \
+ " \"\"\"This is an unsused doc string.\"\"\"" "" \
+ " def __init__(self, name, doc):" "" \
+ " super().__init__(name, gdb.COMMAND_NONE, doc)" "" \
+ "BasicParamPrefixWithDocParameter('prefix-7'," "" \
+ " \"\"\"The doc string text is here.\"\"\")" "" \
+ "gdb.Parameter('prefix-7 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "end"
+
+ foreach mode { "set" "show" } {
+ gdb_test "help $mode prefix-4" \
+ [make_help_re $mode "prefix-4" \
+ "This command is not documented."]
+
+ gdb_test "help $mode prefix-5" \
+ [make_help_re $mode "prefix-5" \
+ "This is a single line doc string."]
+
+ gdb_test "help $mode prefix-6" \
+ [make_help_re $mode "prefix-6" \
+ [multi_line \
+ "This is a multi line doc string." \
+ "" \
+ "The rest of the doc string is here."]]
+
+ gdb_test "help $mode prefix-7" \
+ [make_help_re $mode "prefix-7" \
+ "The doc string text is here."]
+
+ foreach prefix { prefix-4 prefix-5 prefix-6 prefix-7 } {
+ gdb_test "$mode $prefix xxx" \
+ "^Undefined $mode $prefix command: \"xxx\"\\. Try \"help $mode $prefix\"\\."
+ }
+ }
+
+ foreach prefix { prefix-4 prefix-5 prefix-6 prefix-7 } {
+ gdb_test "set $prefix" \
+ [make_sub_cmd_help_re "set" $prefix]
+
+ gdb_test "show $prefix" \
+ [make_show_prefix_re $prefix]
+ }
+}
+
+# Create a sub-class of gdb.ParameterPrefix, and make use of
+# 'invoke_set' and 'invoke_show'. Test that the invoke method is
+# executed when expected, and that, by default, these invoke methods
+# repeat when the user issues an empty command.
+proc_with_prefix test_prefix_with_invoke {} {
+ gdb_test_multiline "ParameterPrefix with invoke_set" \
+ "python" "" \
+ "class PrefixWithInvokeSet(gdb.ParameterPrefix):" "" \
+ " def __init__(self, name):" "" \
+ " super().__init__(name, gdb.COMMAND_NONE)" "" \
+ " def invoke_set(self, args, from_tty):" "" \
+ " print(f\"invoke_set (a): \\\"{args}\\\" {from_tty}\")" "" \
+ "PrefixWithInvokeSet('prefix-8')" "" \
+ "gdb.Parameter('prefix-8 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "class PrefixWithInvokeShow(gdb.ParameterPrefix):" "" \
+ " def __init__(self, name):" "" \
+ " super().__init__(name, gdb.COMMAND_NONE)" "" \
+ " def invoke_show(self, args, from_tty):" "" \
+ " print(f\"invoke_show (b): \\\"{args}\\\" {from_tty}\")" "" \
+ "PrefixWithInvokeShow('prefix-9')" "" \
+ "gdb.Parameter('prefix-9 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "class PrefixWithBothInvoke(gdb.ParameterPrefix):" "" \
+ " def __init__(self, name):" "" \
+ " super().__init__(name, gdb.COMMAND_NONE)" "" \
+ " def invoke_set(self, args, from_tty):" "" \
+ " print(f\"invoke_set (c): \\\"{args}\\\" {from_tty}\")" "" \
+ " def invoke_show(self, args, from_tty):" "" \
+ " print(f\"invoke_show (d): \\\"{args}\\\" {from_tty}\")" "" \
+ "PrefixWithBothInvoke('prefix-10')" "" \
+ "gdb.Parameter('prefix-10 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "end"
+
+ gdb_test "set prefix-8 xxx yyy" \
+ "^invoke_set \\(a\\): \"xxx yyy\" True"
+
+ send_gdb "\n"
+ gdb_test "" "^\r\ninvoke_set \\(a\\): \"xxx yyy\" True" \
+ "repeat set prefix-8 xxx yyy"
+
+ gdb_test "show prefix-8 xxx yyy" \
+ "^Undefined show prefix-8 command: \"xxx yyy\"\\. Try \"help show prefix-8\"\\."
+
+ gdb_test "set prefix-9 xxx yyy" \
+ "^Undefined set prefix-9 command: \"xxx yyy\"\\. Try \"help set prefix-9\"\\."
+
+ gdb_test "show prefix-9 xxx yyy" \
+ "^invoke_show \\(b\\): \"xxx yyy\" True"
+
+ send_gdb "\n"
+ gdb_test "" "^\r\ninvoke_show \\(b\\): \"xxx yyy\" True" \
+ "repeat show prefix-9 xxx yyy"
+
+ gdb_test "set prefix-10 xxx yyy" \
+ "^invoke_set \\(c\\): \"xxx yyy\" True"
+
+ send_gdb "\n"
+ gdb_test "" "^\r\ninvoke_set \\(c\\): \"xxx yyy\" True" \
+ "repeat set prefix-10 xxx yyy"
+
+ gdb_test "show prefix-10 xxx yyy" \
+ "^invoke_show \\(d\\): \"xxx yyy\" True"
+
+ send_gdb "\n"
+ gdb_test "" "^\r\ninvoke_show \\(d\\): \"xxx yyy\" True" \
+ "repeat show prefix-10 xxx yyy"
+
+ gdb_test "set prefix-8" \
+ "^invoke_set \\(a\\): \"\" True"
+
+ gdb_test "show prefix-8" \
+ [make_show_prefix_re "prefix-8"]
+
+ gdb_test "set prefix-9" \
+ [make_sub_cmd_help_re "set" "prefix-9"]
+
+ gdb_test "show prefix-9" \
+ "^invoke_show \\(b\\): \"\" True"
+
+ gdb_test "set prefix-10" \
+ "^invoke_set \\(c\\): \"\" True"
+
+ gdb_test "show prefix-10" \
+ "^invoke_show \\(d\\): \"\" True"
+}
+
+# Create ParameterPrefix sub-classes that make use of the
+# dont_repeat() method. Check that the relevant set/show invoke
+# callback doesn't repeat when an empty command is used.
+proc_with_prefix test_dont_repeat {} {
+ gdb_test_multiline "ParameterPrefix with invoke_set and dont_repeat" \
+ "python" "" \
+ "class PrefixWithInvokeAndDoNotRepeatSet(gdb.ParameterPrefix):" "" \
+ " def __init__(self, name):" "" \
+ " super().__init__(name, gdb.COMMAND_NONE)" "" \
+ " def invoke_set(self, args, from_tty):" "" \
+ " self.dont_repeat()" "" \
+ " print(f\"invoke_set: \\\"{args}\\\" {from_tty}\")" "" \
+ " def invoke_show(self, args, from_tty):" "" \
+ " print(f\"invoke_show: \\\"{args}\\\" {from_tty}\")" "" \
+ "PrefixWithInvokeAndDoNotRepeatSet('prefix-11')" "" \
+ "gdb.Parameter('prefix-11 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "class PrefixWithInvokeAndDoNotRepeatShow(gdb.ParameterPrefix):" "" \
+ " def __init__(self, name):" "" \
+ " super().__init__(name, gdb.COMMAND_NONE)" "" \
+ " def invoke_set(self, args, from_tty):" "" \
+ " print(f\"invoke_set: \\\"{args}\\\" {from_tty}\")" "" \
+ " def invoke_show(self, args, from_tty):" "" \
+ " self.dont_repeat()" "" \
+ " print(f\"invoke_show: \\\"{args}\\\" {from_tty}\")" "" \
+ "PrefixWithInvokeAndDoNotRepeatShow('prefix-12')" "" \
+ "gdb.Parameter('prefix-12 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "end"
+
+ gdb_test "set prefix-11 xxx yyy" \
+ "^invoke_set: \"xxx yyy\" True"
+
+ send_gdb "\n"
+ gdb_test "" "^" \
+ "repeat set prefix-11 xxx yyy"
+
+ gdb_test "show prefix-11 xxx yyy" \
+ "^invoke_show: \"xxx yyy\" True"
+
+ send_gdb "\n"
+ gdb_test "" "invoke_show: \"xxx yyy\" True" \
+ "repeat show prefix-11 xxx yyy"
+
+ gdb_test "set prefix-12 xxx yyy" \
+ "^invoke_set: \"xxx yyy\" True"
+
+ send_gdb "\n"
+ gdb_test "" "^\r\ninvoke_set: \"xxx yyy\" True" \
+ "repeat set prefix-12 xxx yyy"
+
+ gdb_test "show prefix-12 xxx yyy" \
+ "^invoke_show: \"xxx yyy\" True"
+
+ send_gdb "\n"
+ gdb_test "" "^" \
+ "repeat show prefix-12 xxx yyy"
+}
+
+# Create a parameter prefixm, and immediately add another prefix under
+# the first. The important thing here is that the second prefix is
+# created into an otherwise empty prefix as this triggered a bug at
+# one point.
+proc_with_prefix test_nested {} {
+ gdb_test_multiline "Create nested parameter prefixes" \
+ "python" "" \
+ "gdb.ParameterPrefix('prefix-13', gdb.COMMAND_NONE)" "" \
+ "gdb.ParameterPrefix('prefix-13 prefix-14', gdb.COMMAND_NONE)" "" \
+ "gdb.Parameter('prefix-13 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "gdb.Parameter('prefix-13 param-2', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "gdb.Parameter('prefix-13 prefix-14 param-3', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "gdb.Parameter('prefix-13 prefix-14 param-4', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "end" ""
+
+ gdb_test "show prefix-13 prefix-14" \
+ [multi_line \
+ "^prefix-13 prefix-14 param-3: The current value of 'prefix-13 prefix-14 param-3' is \"off\"\\." \
+ "prefix-13 prefix-14 param-4: The current value of 'prefix-13 prefix-14 param-4' is \"off\"\\."]
+
+ gdb_test "show prefix-13" \
+ [multi_line \
+ "^prefix-13 param-1: The current value of 'prefix-13 param-1' is \"off\"\\." \
+ "prefix-13 param-2: The current value of 'prefix-13 param-2' is \"off\"\\." \
+ "prefix-13 prefix-14 param-3: The current value of 'prefix-13 prefix-14 param-3' is \"off\"\\." \
+ "prefix-13 prefix-14 param-4: The current value of 'prefix-13 prefix-14 param-4' is \"off\"\\."]
+
+ gdb_test "set prefix-13 prefix-14" \
+ [multi_line \
+ "" \
+ "set prefix-13 prefix-14 param-3 -- Set the current value of 'prefix-13 prefix-14 param-3'\\." \
+ "set prefix-13 prefix-14 param-4 -- Set the current value of 'prefix-13 prefix-14 param-4'\\." \
+ "" \
+ ".*"]
+
+ gdb_test "set prefix-13" \
+ [multi_line \
+ "" \
+ "set prefix-13 param-1 -- Set the current value of 'prefix-13 param-1'\\." \
+ "set prefix-13 param-2 -- Set the current value of 'prefix-13 param-2'\\." \
+ "set prefix-13 prefix-14 -- This command is not documented\\." \
+ "" \
+ ".*"]
+}
+
+test_basic_usage
+test_simple_sub_class
+test_prefix_with_invoke
+test_dont_repeat
+test_nested
diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp
index c15bef1..30a477b 100644
--- a/gdb/testsuite/gdb.python/py-parameter.exp
+++ b/gdb/testsuite/gdb.python/py-parameter.exp
@@ -38,13 +38,17 @@ proc_with_prefix test_directories { } {
# doesn't set search directories on remote host.
set directories ".*\\\$cdir.\\\$cwd"
} else {
- set escaped_directory [string_to_regexp "$::srcdir/$::subdir"]
+ set directory [host_file_normalize "$::srcdir/$::subdir"]
+ set escaped_directory [string_to_regexp $directory]
set directories "$escaped_directory.\\\$cdir.\\\$cwd"
}
gdb_test "python print (gdb.parameter ('directories'))" $directories
}
proc_with_prefix test_data_directory { } {
+ # Proc assumes local host.
+ require {!is_remote host}
+
clean_restart
# Check we can correctly read the data-directory parameter. First,
@@ -187,6 +191,8 @@ proc_with_prefix test_enum_parameter { } {
# Test an color parameter.
proc_with_prefix test_color_parameter { } {
+ require {!is_remote host}
+
global env
with_ansi_styling_terminal {
# This enables 256 colors support and disables colors approximation.
@@ -346,6 +352,91 @@ proc_with_prefix test_really_undocumented_parameter { } {
"test general help"
}
+# Test a parameter in which the __doc__ string is empty or None.
+proc_with_prefix test_empty_doc_parameter {} {
+ gdb_test_multiline "empty __doc__ parameter" \
+ "python" "" \
+ "class EmptyDocParam(gdb.Parameter):" "" \
+ " __doc__ = \"\"" "" \
+ " def __init__(self, name):" "" \
+ " super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ " self.value = True" "" \
+ "test_empty_doc_param = EmptyDocParam('print test-empty-doc-param')" ""\
+ "end"
+
+ # Setting the __doc__ string to empty means GDB will completely
+ # elide it from the output.
+ gdb_test "help set print test-empty-doc-param" \
+ "^Set the current value of 'print test-empty-doc-param'\\."
+
+ gdb_test_multiline "None __doc__ parameter" \
+ "python" "" \
+ "class NoneDocParam(gdb.Parameter):" "" \
+ " __doc__ = None" "" \
+ " def __init__(self, name):" "" \
+ " super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ " self.value = True" "" \
+ "test_none_doc_param = NoneDocParam('print test-none-doc-param')" ""\
+ "end"
+
+ # Setting the __doc__ string to None, or anything else that isn't
+ # a string, causes GDB to use a default string instead.
+ gdb_test "help set print test-none-doc-param" \
+ [multi_line \
+ "^Set the current value of 'print test-none-doc-param'\\." \
+ "This command is not documented\\."]
+}
+
+# Test a parameter in which the set_doc/show_doc strings are either
+# empty, or None.
+proc_with_prefix test_empty_set_show_doc_parameter {} {
+ gdb_test_multiline "empty set/show doc parameter" \
+ "python" "" \
+ "class EmptySetShowParam(gdb.Parameter):" "" \
+ " set_doc = \"\"" "" \
+ " show_doc = \"\"" "" \
+ " def __init__(self, name):" "" \
+ " super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ " self.value = True" "" \
+ "test_empty_set_show_param = EmptySetShowParam('print test-empty-set-show-param')" ""\
+ "end"
+
+ # Setting the set_doc/show_doc string to empty means GDB will use
+ # a suitable default string.
+ gdb_test "help set print test-empty-set-show-param" \
+ [multi_line \
+ "^Set the current value of 'print test-empty-set-show-param'\\." \
+ "This command is not documented\\."]
+
+ gdb_test "help show print test-empty-set-show-param" \
+ [multi_line \
+ "^Show the current value of 'print test-empty-set-show-param'\\." \
+ "This command is not documented\\."]
+
+ gdb_test_multiline "None set/show doc parameter" \
+ "python" "" \
+ "class NoneSetShowParam(gdb.Parameter):" "" \
+ " set_doc = None" "" \
+ " show_doc = None" "" \
+ " def __init__(self, name):" "" \
+ " super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ " self.value = True" "" \
+ "test_none_set_show_param = NoneSetShowParam('print test-none-set-show-param')" ""\
+ "end"
+
+ # Setting the set_doc/show_doc string to None (or any non-string
+ # value) means GDB will use a suitable default string.
+ gdb_test "help set print test-none-set-show-param" \
+ [multi_line \
+ "^Set the current value of 'print test-none-set-show-param'\\." \
+ "This command is not documented\\."]
+
+ gdb_test "help show print test-none-set-show-param" \
+ [multi_line \
+ "^Show the current value of 'print test-none-set-show-param'\\." \
+ "This command is not documented\\."]
+}
+
# Test deprecated API. Do not use in your own implementations.
proc_with_prefix test_deprecated_api_parameter { } {
clean_restart
@@ -669,6 +760,104 @@ proc_with_prefix test_ambiguous_parameter {} {
"Parameter .* is ambiguous.*Error occurred in Python.*"
gdb_test "python print(gdb.parameter('test-ambiguous-value-1a'))" \
"Could not find parameter.*Error occurred in Python.*"
+
+ # Create command prefixs 'set foo1' and 'show foo1'.
+ gdb_test_no_output "python gdb.Command('set foo1', gdb.COMMAND_NONE, prefix=True)"
+ gdb_test_no_output "python gdb.Command('show foo1', gdb.COMMAND_NONE, prefix=True)"
+
+ # Create a parameter under 'foo1', but use a truncated prefix. At
+ # this point though, the prefix is not ambiguous.
+ gdb_test_no_output "python gdb.Parameter('foo bar', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)"
+ gdb_test "python print(gdb.parameter('foo1 bar'))" "False"
+
+ # Create another prefix command, similar in name to the first.
+ gdb_test_no_output "python gdb.Command('set foo2', gdb.COMMAND_NONE, prefix=True)"
+ gdb_test_no_output "python gdb.Command('show foo2', gdb.COMMAND_NONE, prefix=True)"
+
+ # An attempt to create a parameter using an ambiguous prefix will give an error.
+ gdb_test "python gdb.Parameter('foo baz', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" \
+ [multi_line \
+ "Python Exception <class 'RuntimeError'>: Could not find command prefix foo\\." \
+ "Error occurred in Python: Could not find command prefix foo\\."]
+}
+
+# Check that creating a gdb.Parameter with an unknown command prefix results in an error.
+proc_with_prefix test_unknown_prefix {} {
+ gdb_test_multiline "create parameter" \
+ "python" "" \
+ "class UnknownPrefixParam(gdb.Parameter):" "" \
+ " def __init__ (self, name):" "" \
+ " super().__init__ (name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ " self.value = True" "" \
+ "end"
+
+ foreach prefix { "unknown-prefix" "style unknown-prefix" "style disassembler unknown-prefix"} {
+ gdb_test "python UnknownPrefixParam('$prefix new-param')" \
+ [multi_line \
+ "Python Exception <class 'RuntimeError'>: Could not find command prefix $prefix\\." \
+ "Error occurred in Python: Could not find command prefix $prefix\\."]
+ }
+}
+
+# Test the default behaviour of a set/show parameter prefix command.
+proc_with_prefix test_set_show_parameters {} {
+ # This first set/show prefix command doesn't have an invoke
+ # method. As such, GDB installs the default invoke behaviour; set
+ # prints the full list of sub-commands, and show prints all the
+ # sub-command values.
+ gdb_test_multiline "Setup set/show parameter prefix with no invoke" \
+ "python" "" \
+ "class TestParamPrefix(gdb.Command):" "" \
+ " \"\"\"TestParamPrefix documentation string.\"\"\"" "" \
+ " def __init__(self, name):" "" \
+ " super().__init__(name, gdb.COMMAND_NONE, prefix = True)" "" \
+ "TestParamPrefix('set test-prefix')" "" \
+ "TestParamPrefix('show test-prefix')" "" \
+ "gdb.Parameter('test-prefix param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "gdb.Parameter('test-prefix param-2', gdb.COMMAND_NONE, gdb.PARAM_INTEGER)" "" \
+ "gdb.Parameter('test-prefix param-3', gdb.COMMAND_NONE, gdb.PARAM_STRING)" "" \
+ "end"
+
+ gdb_test "set test-prefix" \
+ [multi_line \
+ "List of \"set test-prefix\" subcommands:" \
+ "" \
+ "set test-prefix param-1 -- Set the current value of 'test-prefix param-1'." \
+ "set test-prefix param-2 -- Set the current value of 'test-prefix param-2'." \
+ "set test-prefix param-3 -- Set the current value of 'test-prefix param-3'." \
+ "" \
+ "Type \"help set test-prefix\" followed by subcommand name for full documentation\\." \
+ "Type \"apropos word\" to search for commands related to \"word\"\\." \
+ "Type \"apropos -v word\" for full documentation of commands related to \"word\"\\." \
+ "Command name abbreviations are allowed if unambiguous\\."]
+
+ gdb_test "show test-prefix" \
+ [multi_line \
+ "test-prefix param-1: The current value of 'test-prefix param-1' is \"off\"\\." \
+ "test-prefix param-2: The current value of 'test-prefix param-2' is \"0\"\\." \
+ "test-prefix param-3: The current value of 'test-prefix param-3' is \"\"\\."]
+
+ # This next set/show prefix has an invoke method, which will be
+ # called instead of the default behaviour tested above.
+ gdb_test_multiline "Setup set/show parameter prefix with invoke" \
+ "python" "" \
+ "class TestParamPrefix(gdb.Command):" "" \
+ " \"\"\"TestParamPrefix documentation string.\"\"\"" "" \
+ " def __init__(self, name, mode):" "" \
+ " self._mode = mode" "" \
+ " super().__init__(self._mode + ' ' + name, gdb.COMMAND_NONE, prefix = True)" "" \
+ " def invoke(self, args, from_tty):" "" \
+ " print('invoke -- ' + self._mode)" "" \
+ "TestParamPrefix('test-prefix-2', 'set')" "" \
+ "TestParamPrefix('test-prefix-2', 'show')" "" \
+ "gdb.Parameter('test-prefix-2 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \
+ "gdb.Parameter('test-prefix-2 param-2', gdb.COMMAND_NONE, gdb.PARAM_INTEGER)" "" \
+ "gdb.Parameter('test-prefix-2 param-3', gdb.COMMAND_NONE, gdb.PARAM_STRING)" "" \
+ "end"
+
+ gdb_test "set test-prefix-2" "^invoke -- set"
+
+ gdb_test "show test-prefix-2" "^invoke -- show"
}
test_directories
@@ -679,11 +868,15 @@ test_color_parameter
test_file_parameter
test_undocumented_parameter
test_really_undocumented_parameter
+test_empty_doc_parameter
+test_empty_set_show_doc_parameter
test_deprecated_api_parameter
test_gdb_parameter
test_integer_parameter
test_throwing_parameter
test_language
test_ambiguous_parameter
+test_unknown_prefix
+test_set_show_parameters
rename py_param_test_maybe_no_output ""
diff --git a/gdb/testsuite/gdb.python/py-source-styling-2.exp b/gdb/testsuite/gdb.python/py-source-styling-2.exp
index b13ee1f..ebf7f32 100644
--- a/gdb/testsuite/gdb.python/py-source-styling-2.exp
+++ b/gdb/testsuite/gdb.python/py-source-styling-2.exp
@@ -32,7 +32,9 @@ if { [build_executable "failed to build" $testfile $srcfile $opts] == -1 } {
return
}
-clean_restart
+with_ansi_styling_terminal {
+ clean_restart
+}
gdb_test_no_output "maint set gnu-source-highlight enabled off"
@@ -40,16 +42,14 @@ gdb_load $binfile
require {gdb_py_module_available pygments}
-with_ansi_styling_terminal {
- gdb_test_no_output "set style enabled on"
-
- gdb_test_multiple "list $line_number" "Styling of c++ keyword try" {
- -re -wrap " try\r\n.*" {
- # Unstyled.
- fail $gdb_test_name
- }
- -re -wrap "" {
- pass $gdb_test_name
- }
+gdb_test_no_output "set style enabled on"
+
+gdb_test_multiple "list $line_number" "Styling of c++ keyword try" {
+ -re -wrap " try\r\n.*" {
+ # Unstyled.
+ fail $gdb_test_name
+ }
+ -re -wrap "" {
+ pass $gdb_test_name
}
}
diff --git a/gdb/testsuite/gdb.python/py-startup-opt.exp b/gdb/testsuite/gdb.python/py-startup-opt.exp
index 7410706..929c64d 100644
--- a/gdb/testsuite/gdb.python/py-startup-opt.exp
+++ b/gdb/testsuite/gdb.python/py-startup-opt.exp
@@ -17,6 +17,7 @@
# initialized.
require allow_python_tests
+require {!is_remote host}
# Return a list containing two directory paths for newly created home
# directories.
diff --git a/gdb/testsuite/gdb.python/py-styled-execute.exp b/gdb/testsuite/gdb.python/py-styled-execute.exp
index 0b27c63..198dab5 100644
--- a/gdb/testsuite/gdb.python/py-styled-execute.exp
+++ b/gdb/testsuite/gdb.python/py-styled-execute.exp
@@ -17,6 +17,7 @@
# on the value of the third argument passed to gdb.execute.
require allow_python_tests
+require {!is_remote host}
load_lib gdb-python.exp
diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.python/py-symbol.exp
index 55cdebe..dfc435e 100644
--- a/gdb/testsuite/gdb.python/py-symbol.exp
+++ b/gdb/testsuite/gdb.python/py-symbol.exp
@@ -100,7 +100,6 @@ gdb_test_multiple $cmd "print value of rr" {
fail $gdb_test_name
}
}
-
gdb_test "python print (gdb.lookup_static_symbol ('rr').needs_frame)" \
"False" \
diff --git a/gdb/testsuite/gdb.python/py-warning.exp b/gdb/testsuite/gdb.python/py-warning.exp
new file mode 100644
index 0000000..6b26a4e
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-warning.exp
@@ -0,0 +1,63 @@
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test the gdb.warning() function.
+
+load_lib gdb-python.exp
+
+require allow_python_tests
+
+clean_restart
+
+# Basic usage.
+gdb_test "python gdb.warning(\"some text\")" \
+ "warning: some text"
+
+# Basic usage with named argument.
+gdb_test "python gdb.warning(text=\"a warning message\")" \
+ "warning: a warning message"
+
+# Make sure GDB prints format specifiers correctly.
+gdb_test "python gdb.warning(\"%s %d %p\")" \
+ "warning: %s %d %p"
+
+# Empty string gives an error.
+gdb_test "python gdb.warning(\"\")" \
+ [multi_line \
+ "Python Exception <class 'ValueError'>: Empty text string passed to gdb\\.warning" \
+ "Error occurred in Python: Empty text string passed to gdb\\.warning"]
+
+# Missing argument gives an error.
+set re1 \
+ [multi_line \
+ [string_to_regexp \
+ [concat \
+ "Python Exception <class 'TypeError'>:" \
+ "function missing required argument 'text' (pos 1)"]] \
+ [string_to_regexp \
+ [concat \
+ "Error occurred in Python:" \
+ "function missing required argument 'text' (pos 1)"]]]
+set re2 \
+ [multi_line \
+ [string_to_regexp \
+ [concat \
+ "Python Exception <class 'TypeError'>:" \
+ "Required argument 'text' (pos 1) not found"]] \
+ [string_to_regexp \
+ [concat \
+ "Error occurred in Python:" \
+ "Required argument 'text' (pos 1) not found"]]]
+gdb_test "python gdb.warning()" $re1|$re2
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index 6b2f671..96977df 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -152,13 +152,7 @@ gdb_test_no_output "set height $lines"
set test "verify pagination beforehand"
gdb_test_multiple "python print (\"\\n\" * $lines)" $test {
- -re "--Type <RET>" {
- exp_continue
- }
- -re " for more, q to quit" {
- exp_continue
- }
- -re ", c to continue without paging--$" {
+ -re "$pagination_prompt$" {
pass $test
}
}
@@ -168,13 +162,7 @@ gdb_test "python if gdb.execute('python print (\"\\\\n\" * $lines)', to_string=T
set test "verify pagination afterwards"
gdb_test_multiple "python print (\"\\n\" * $lines)" $test {
- -re "--Type <RET>" {
- exp_continue
- }
- -re " for more, q to quit" {
- exp_continue
- }
- -re ", c to continue without paging--$" {
+ -re "$pagination_prompt$" {
pass $test
}
}
diff --git a/gdb/testsuite/gdb.replay/connect.exp b/gdb/testsuite/gdb.replay/connect.exp
index 5790d38..26b7aa3 100644
--- a/gdb/testsuite/gdb.replay/connect.exp
+++ b/gdb/testsuite/gdb.replay/connect.exp
@@ -13,7 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. */
#
-# Starts a communication with gdbsever setting the remotelog file.
+# Starts a communication with gdbserver setting the remotelog file.
# Modifies the remotelog with update_log proc, injects an error message
# instead of the expected replay to the vMustReplyEmpty packet in order
# to test GDB reacts to the error response properly. After the remotelog
diff --git a/gdb/testsuite/gdb.reverse/i386-avx-reverse.c b/gdb/testsuite/gdb.reverse/i386-avx-reverse.c
index a37b65a..bf6cb77 100644
--- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.c
+++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.c
@@ -30,6 +30,18 @@ char global_buf1[] = {0, 0, 0, 0, 0, 0, 0, 0,
char *dyn_buf0;
char *dyn_buf1;
+ /* Zero memory regions again, so that future tests can update them
+ without worry. */
+void
+reset_buffers ()
+{
+ for (int i = 0; i < 32; i++)
+ {
+ global_buf1[i] = 0;
+ dyn_buf1[i] = 0;
+ }
+}
+
int
vmov_test ()
{
@@ -168,6 +180,22 @@ vmov_test ()
asm volatile ("vmovapd %%xmm0, %0" : : "m"(*dyn_buf1));
asm volatile ("vmovaps %%ymm15, %0" : : "m"(*dyn_buf1));
+ /* Testing vmov[hl|lh]ps and vmov[h|l]pd. */
+ asm volatile ("vmovhlps %xmm1, %xmm8, %xmm0");
+ asm volatile ("vmovhlps %xmm1, %xmm2, %xmm15");
+ asm volatile ("vmovlhps %xmm1, %xmm8, %xmm0");
+ asm volatile ("vmovlhps %xmm1, %xmm2, %xmm15");
+
+ asm volatile ("vmovhps %0, %%xmm1, %%xmm0" : : "m"(buf0));
+ asm volatile ("vmovhps %%xmm0, %0" : "=m" (buf1));
+ asm volatile ("vmovhpd %0, %%xmm1, %%xmm15" : : "m"(global_buf0));
+ asm volatile ("vmovhpd %%xmm15, %0" : "=m" (global_buf1));
+ asm volatile ("vmovlpd %0, %%xmm1, %%xmm15" : : "m"(*dyn_buf0));
+ asm volatile ("vmovlpd %%xmm15, %0" : "=m" (*dyn_buf1));
+
+ asm volatile ("vmovddup %xmm1, %xmm15");
+ asm volatile ("vmovddup %ymm2, %ymm0");
+
/* We have a return statement to deal with
epilogue in different compilers. */
return 0; /* end vmov_test */
@@ -245,7 +273,7 @@ vpunpck_test ()
return 0; /* end vpunpck_test */
}
-/* Test if we can record vpbroadcast instructions. */
+/* Test if we can record vpbroadcast and vbroadcast instructions. */
int
vpbroadcast_test ()
{
@@ -268,6 +296,14 @@ vpbroadcast_test ()
asm volatile ("vpbroadcastq %xmm1, %ymm0");
asm volatile ("vpbroadcastq %xmm1, %ymm15");
+ asm volatile ("vbroadcastss %xmm1, %xmm0");
+ asm volatile ("vbroadcastss %xmm1, %ymm15");
+ asm volatile ("vbroadcastss %0, %%ymm0" : : "m" (global_buf0));
+ asm volatile ("vbroadcastss %0, %%xmm15": : "m" (*dyn_buf0));
+ asm volatile ("vbroadcastsd %xmm1, %ymm0");
+ asm volatile ("vbroadcastsd %0, %%ymm15": : "m" (global_buf0));
+ asm volatile ("vbroadcastf128 %0, %%ymm0" : : "m" (*dyn_buf0));
+
/* We have a return statement to deal with
epilogue in different compilers. */
return 0; /* end vpbroadcast_test */
@@ -372,6 +408,7 @@ arith_test ()
/* Using GDB, load these values onto registers for testing.
ymm0.v8_float = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5}
ymm1.v8_float = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5}
+ ymm2.v2_int128 = {0x0, 0x0}
ymm15.v2_int128 = {0x0, 0x0}
this way it's easy to confirm we're undoing things correctly. */
asm volatile ("vaddps %xmm0, %xmm1, %xmm15");
@@ -416,9 +453,318 @@ arith_test ()
asm volatile ("vmaxss %xmm0, %xmm1, %xmm15");
asm volatile ("vmaxsd %xmm0, %xmm1, %xmm15");
+ /* Some sanity checks for other arithmetic instructions. */
+ asm volatile ("vpaddb %xmm0, %xmm1, %xmm2");
+ asm volatile ("vpaddw %xmm0, %xmm1, %xmm15");
+ asm volatile ("vpaddd %ymm0, %ymm1, %ymm2");
+ asm volatile ("vpaddq %ymm0, %ymm1, %ymm15");
+
+ asm volatile ("vpmullw %xmm0, %xmm1, %xmm2");
+ asm volatile ("vpmulld %xmm0, %xmm1, %xmm15");
+ asm volatile ("vpmulhw %ymm0, %ymm1, %ymm2");
+ asm volatile ("vpmulhuw %ymm0, %ymm1, %ymm15");
+ asm volatile ("vpmuludq %ymm0, %ymm1, %ymm15");
+
+ asm volatile ("vxorps %xmm0, %xmm1, %xmm2");
+ asm volatile ("vxorpd %ymm0, %ymm1, %ymm2");
+ asm volatile ("vpand %xmm0, %xmm1, %xmm15");
+ asm volatile ("vpandn %ymm0, %ymm1, %ymm15");
+
+ asm volatile ("vpsadbw %xmm0, %xmm1, %xmm2");
+ asm volatile ("vpsadbw %ymm0, %ymm1, %ymm15");
+
return 0; /* end arith_test */
}
+int
+vaddsubpd_test ()
+{
+ /* start vaddsubpd_test */
+ /* YMM test. */
+ asm volatile ("vaddsubpd %ymm15,%ymm1,%ymm0");
+ asm volatile ("vaddsubpd %ymm0,%ymm1,%ymm15");
+ asm volatile ("vaddsubpd %ymm2,%ymm3,%ymm4");
+
+ /* XMM test. */
+ asm volatile ("vaddsubpd %xmm15,%xmm1,%xmm2");
+ asm volatile ("vaddsubpd %xmm0,%xmm1,%xmm10");
+ return 0; /* end vaddsubpd_test */
+}
+
+int
+vaddsubps_test ()
+{
+ /* start vaddsubps_test */
+ /* YMM test. */
+ asm volatile ("vaddsubps %ymm15,%ymm1,%ymm2");
+ asm volatile ("vaddsubps %ymm0,%ymm1,%ymm10");
+ asm volatile ("vaddsubps %ymm2,%ymm3,%ymm4");
+
+ /* XMM test. */
+ asm volatile ("vaddsubps %xmm0,%xmm1,%xmm15");
+ asm volatile ("vaddsubps %xmm15,%xmm1,%xmm0");
+ return 0; /* end vaddsubps_test */
+}
+
+
+/* Test record shifting instructions. */
+int
+shift_test ()
+{
+ /* start shift_test. */
+ /* Using GDB, load these values onto registers for testing.
+ ymm0.v2_int128 = {0, 0}
+ ymm1.v16_int16 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
+ xmm2.uint128 = 1
+ ymm15.v2_int128 = {0x0, 0x0}
+ this way it's easy to confirm we're undoing things correctly. */
+
+ asm volatile ("vpsllw $1, %xmm1, %xmm0");
+ asm volatile ("vpsllw %xmm2, %ymm1, %ymm0");
+ asm volatile ("vpslld $3, %ymm1, %ymm15");
+ asm volatile ("vpslld %xmm2, %xmm1, %xmm15");
+ asm volatile ("vpsllq $5, %xmm1, %xmm15");
+ asm volatile ("vpsllq %xmm2, %ymm1, %ymm15");
+
+ asm volatile ("vpsraw $1, %xmm1, %xmm0");
+ asm volatile ("vpsraw %xmm2, %ymm1, %ymm0");
+ asm volatile ("vpsrad $3, %ymm1, %ymm15");
+ asm volatile ("vpsrad %xmm2, %xmm1, %xmm15");
+
+ asm volatile ("vpsrlw $1, %xmm1, %xmm0");
+ asm volatile ("vpsrlw %xmm2, %ymm1, %ymm0");
+ asm volatile ("vpsrld $3, %ymm1, %ymm15");
+ asm volatile ("vpsrld %xmm2, %xmm1, %xmm15");
+ asm volatile ("vpsrlq $5, %xmm1, %xmm15");
+ asm volatile ("vpsrlq %xmm2, %ymm1, %ymm15");
+
+ /* The dq version is treated separately in the manual, so
+ we test it separately just to be sure. */
+ asm volatile ("vpslldq $1, %xmm1, %xmm0");
+ asm volatile ("vpslldq $2, %ymm1, %ymm0");
+ asm volatile ("vpslldq $3, %xmm1, %xmm15");
+ asm volatile ("vpslldq $4, %ymm1, %ymm15");
+
+ asm volatile ("vpsrldq $1, %xmm1, %xmm0");
+ asm volatile ("vpsrldq $2, %ymm1, %ymm0");
+ asm volatile ("vpsrldq $3, %xmm1, %xmm15");
+ asm volatile ("vpsrldq $4, %ymm1, %ymm15");
+
+ return 0; /* end shift_test */
+}
+
+int
+shuffle_test ()
+{
+ /* start shuffle_test. */
+ /* Using GDB, load these values onto registers for testing.
+ ymm0.v2_int128 = {0, 0}
+ ymm1.v16_int16 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
+ ymm2.v16_int15 = {17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}
+ ymm15.v2_int128 = {0x0, 0x0}
+ this way it's easy to confirm we're undoing things correctly. */
+
+ asm volatile ("vpshufb %xmm1, %xmm2, %xmm0");
+ asm volatile ("vpshufb %ymm1, %ymm2, %ymm15");
+ asm volatile ("vpshufd $1, %ymm2, %ymm0");
+ asm volatile ("vpshufd $2, %xmm2, %xmm15");
+
+ asm volatile ("vpshufhw $3, %xmm2, %xmm0");
+ asm volatile ("vpshufhw $4, %ymm2, %ymm15");
+ asm volatile ("vpshuflw $5, %ymm2, %ymm0");
+ asm volatile ("vpshuflw $6, %xmm2, %xmm15");
+
+ asm volatile ("vshufps $1, %xmm1, %xmm2, %xmm0");
+ asm volatile ("vshufps $2, %ymm1, %ymm2, %ymm15");
+ asm volatile ("vshufpd $4, %ymm1, %ymm2, %ymm0");
+ asm volatile ("vshufpd $8, %xmm1, %xmm2, %xmm15");
+
+ return 0; /* end shuffle_test */
+}
+
+int
+permute_test ()
+{
+ /* start permute_test. */
+ /* Using GDB, load these values onto registers for testing.
+ ymm0.v2_int128 = {0, 0}
+ ymm1.v16_int16 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
+ ymm2.v16_int16 = {17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}
+ ymm15.v2_int128 = {0x0, 0x0}
+ eax = 0
+ this way it's easy to confirm we're undoing things correctly. */
+ asm volatile ("vperm2f128 $1, %ymm1, %ymm2, %ymm0");
+ asm volatile ("vperm2f128 $0, %ymm1, %ymm2, %ymm15");
+ asm volatile ("vperm2i128 $1, %ymm2, %ymm1, %ymm0");
+ asm volatile ("vperm2i128 $0, %ymm2, %ymm1, %ymm15");
+
+ asm volatile ("vpermd %ymm1, %ymm2, %ymm0");
+ asm volatile ("vpermd %ymm1, %ymm2, %ymm15");
+ asm volatile ("vpermq $1, %ymm1, %ymm0");
+ asm volatile ("vpermq $0, %ymm2, %ymm15");
+
+ asm volatile ("vpermilpd %ymm1, %ymm2, %ymm0");
+ asm volatile ("vpermilpd %xmm1, %xmm2, %xmm15");
+ asm volatile ("vpermilpd $1, %ymm2, %ymm15");
+ asm volatile ("vpermilpd $0, %xmm2, %xmm0");
+ asm volatile ("vpermilps %ymm1, %ymm2, %ymm0");
+ asm volatile ("vpermilps %xmm1, %xmm2, %xmm15");
+ asm volatile ("vpermilps $1, %ymm2, %ymm15");
+ asm volatile ("vpermilps $0, %xmm2, %xmm0");
+
+ asm volatile ("vpermpd $0, %ymm1, %ymm15");
+ asm volatile ("vpermpd $0, %ymm2, %ymm0");
+ asm volatile ("vpermps %ymm1, %ymm2, %ymm0");
+ asm volatile ("vpermps %ymm1, %ymm2, %ymm15");
+
+ return 0; /* end permute_test */
+}
+
+int
+extract_insert_test ()
+{
+ /* start extract_insert_test. */
+ /* Using GDB, load these values onto registers for testing.
+ ymm0.v2_int128 = {0, 0}
+ ymm1.v16_int16 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
+ xmm2.uint128 = 0xcafe
+ ymm15.v2_int128 = {0x0, 0x0}
+ eax = 0
+ this way it's easy to confirm we're undoing things correctly. */
+
+ asm volatile ("vinserti128 $1, %xmm2, %ymm1, %ymm0");
+ asm volatile ("vinsertf128 $0, %xmm2, %ymm1, %ymm15");
+ asm volatile ("vextracti128 $1, %ymm1, %xmm0");
+ asm volatile ("vextractf128 $0, %ymm1, %xmm15");
+ asm volatile ("vinsertps $16, %xmm2, %xmm1, %xmm0");
+ asm volatile ("vextractps $0, %xmm2, %rax");
+
+ asm volatile ("vpextrb $5, %xmm1, %rax");
+ asm volatile ("vpextrb $4, %%xmm1, %0" : "=m" (global_buf1));
+ asm volatile ("vpextrd $3, %xmm1, %eax");
+ asm volatile ("vpextrd $2, %%xmm1, %0" : "=m" (global_buf1));
+ asm volatile ("vpextrq $1, %xmm1, %rax");
+ asm volatile ("vpextrq $0, %%xmm1, %0" : "=m" (global_buf1));
+
+ asm volatile ("vpinsrb $3, %rax, %xmm2, %xmm0");
+ asm volatile ("vpinsrw $2, %eax, %xmm2, %xmm15");
+ asm volatile ("vpinsrd $1, %eax, %xmm2, %xmm0");
+ asm volatile ("vpinsrq $0, %rax, %xmm2, %xmm15");
+
+ /* vpextrw has completely different mechanics to other vpextr
+ instructions, so separate them for ease of testing later. */
+ asm volatile ("vpextrw $1, %xmm1, %eax");
+ asm volatile ("vpextrw $1, %%xmm1, %0" : "=m" (global_buf1));
+
+ return 0; /* end extract_insert_test */
+}
+
+int
+blend_test ()
+{
+ /* start blend_test. */
+ /* Using GDB, load these values onto registers for testing.
+ ymm0.v2_int128 = {0, 0}
+ ymm1.v16_int16 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
+ ymm2.v16_int16 = {17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}
+ ymm15.v2_int128 = {0x0, 0x0}
+ this way it's easy to confirm we're undoing things correctly. */
+
+ asm volatile ("vblendps $5, %xmm1, %xmm2, %xmm0");
+ asm volatile ("vblendpd $10, %ymm1, %ymm2, %ymm15");
+ asm volatile ("vblendvps %ymm15, %ymm1, %ymm2, %ymm0");
+ asm volatile ("vblendvpd %xmm0, %xmm1, %xmm2, %xmm15");
+
+ asm volatile ("vpblendw $94, %ymm1, %ymm2, %ymm15");
+ asm volatile ("vpblendw $47, %xmm1, %xmm2, %xmm0");
+ asm volatile ("vpblendd $22, %ymm1, %ymm2, %ymm0");
+ asm volatile ("vpblendd $11, %xmm1, %xmm2, %xmm15");
+ asm volatile ("vpblendvb %xmm0, %xmm1, %xmm2, %xmm15");
+ asm volatile ("vpblendvb %ymm0, %ymm1, %ymm2, %ymm0");
+
+ return 0; /* end blend_test */
+}
+
+int
+compare_test ()
+{
+ /* start compare_test. */
+ /* Using GDB, load these values onto registers for testing.
+ xmm0.v4_float = {0, 1.5, 2, 0}
+ xmm1.v4_float = {0, 1, 2.5, -1}
+ xmm15.v4_float = {-1, -2, 10, 100}
+ eflags = 2
+ eflags can't be set to some values, if we set it to 0, it'll
+ be reset to 2, so set it to that directly to make results less
+ confusing.
+ this way it's easy to confirm we're undoing things correctly. */
+
+ asm volatile ("vcomisd %xmm0, %xmm1");
+ asm volatile ("vcomiss %xmm15, %xmm1");
+ asm volatile ("vucomiss %xmm1, %xmm15");
+ asm volatile ("vucomisd %xmm15, %xmm0");
+
+ return 0; /* end compare_test */
+}
+
+int
+pack_test ()
+{
+ /* start pack_test. */
+ /* Using GDB, load these values onto registers for testing.
+ xmm0.v4_float = {0, 1.5, 2, 0}
+ xmm1.v4_float = {0, 1, 2.5, -1}
+ xmm2.v4_float = {0, 1, 2.5, -1}
+ xmm15.v4_float = {-1, -2, 10, 100}
+ this way it's easy to confirm we're undoing things correctly. */
+
+ asm volatile ("vpacksswb %xmm1, %xmm2, %xmm0");
+ asm volatile ("vpacksswb %ymm1, %ymm2, %ymm15");
+ asm volatile ("vpackssdw %xmm1, %xmm2, %xmm15");
+ asm volatile ("vpackssdw %ymm1, %ymm2, %ymm0");
+ asm volatile ("vpackuswb %xmm1, %xmm2, %xmm0");
+ asm volatile ("vpackuswb %ymm1, %ymm2, %ymm15");
+ asm volatile ("vpackusdw %xmm1, %xmm2, %xmm15");
+ asm volatile ("vpackusdw %ymm1, %ymm2, %ymm0");
+
+ return 0; /* end pack_test */
+}
+
+int
+convert_test ()
+{
+ /* start convert_test. */
+ /* Using GDB, load these values onto registers for testing.
+ xmm0.v2_int128 = {0, 0}
+ xmm1.v4_float = {0, 1, 2.5, 10}
+ xmm15.v2_int128 = {0, 0}
+ ecx = -1
+ ebx = 0
+ this way it's easy to confirm we're undoing things correctly. */
+
+ asm volatile ("vcvtdq2ps %xmm1, %xmm0");
+ asm volatile ("vcvtdq2pd %xmm1, %xmm15");
+
+ asm volatile ("vcvtps2dq %xmm1, %xmm15");
+ asm volatile ("vcvtps2pd %xmm1, %xmm0");
+ asm volatile ("vcvtpd2ps %xmm1, %xmm15");
+ asm volatile ("vcvtpd2dq %xmm1, %xmm0");
+
+ asm volatile ("vcvtsd2si %xmm1, %rbx");
+ asm volatile ("vcvtsd2ss %xmm0, %xmm1, %xmm15");
+ asm volatile ("vcvtsi2sd %rcx, %xmm1, %xmm0");
+ asm volatile ("vcvtsi2ss %rcx, %xmm1, %xmm15");
+ asm volatile ("vcvtss2sd %xmm15, %xmm1, %xmm0");
+ asm volatile ("vcvtss2si %xmm1, %rbx");
+
+ asm volatile ("vcvttpd2dq %xmm1, %xmm0");
+ asm volatile ("vcvttps2dq %xmm1, %xmm15");
+ asm volatile ("vcvttsd2si %xmm0, %rbx");
+ asm volatile ("vcvttss2si %xmm1, %ecx");
+
+ return 0; /* end convert_test */
+}
+
/* This include is used to allocate the dynamic buffer and have
the pointers aligned to a 32-bit boundary, so we can test instructions
that require aligned memory. */
@@ -442,6 +788,7 @@ main ()
asm volatile ("vmovq %0, %%xmm15": : "m" (global_buf1));
vmov_test ();
+ reset_buffers ();
vpunpck_test ();
vpbroadcast_test ();
vzeroupper_test ();
@@ -449,5 +796,15 @@ main ()
vpcmpeq_test ();
vpmovmskb_test ();
arith_test ();
+ vaddsubpd_test ();
+ vaddsubps_test ();
+ shift_test ();
+ shuffle_test ();
+ permute_test ();
+ extract_insert_test ();
+ blend_test ();
+ compare_test ();
+ pack_test ();
+ convert_test ();
return 0; /* end of main */
}
diff --git a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp
index 0ff56dd..fb04260 100644
--- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp
+++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp
@@ -149,6 +149,33 @@ global decimal
if {[record_full_function "vmov"] == true} {
# Now execute backwards, checking all instructions.
+ test_one_register "vmovddup" "ymm0" \
+ "0x3736353433323130c004000000000000, 0x0"
+ test_one_register "vmovddup" "ymm15" \
+ "0x2726252423222120, 0x0"
+ test_one_memory "vmovlpd" "dyn_buf1" \
+ "\\\{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x28" \
+ true
+ test_one_register "vmovlpd" "ymm15" \
+ "0x1716151413121110c004000000000000, 0x0"
+ test_one_memory "vmovhpd" "global_buf1" \
+ "\\\{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x18"
+ test_one_register "vmovhpd" "ymm15" \
+ "0xc004000000000000c004000000000000, 0x0"
+ test_one_memory "vmovhps" "buf1" \
+ "\\\{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x38"
+ test_one_register "vmovhps" "ymm0" \
+ "0xc004000000000000c004000000000000, 0x0"
+
+ test_one_register "vmovlhps" "ymm15" \
+ "0x0, 0x0"
+ test_one_register "vmovlhps" "ymm0" \
+ "0x0, 0x0"
+ test_one_register "vmovhlps" "ymm15" \
+ "0x2f2e2d2c2b2a29280000000000000000, 0x2f2e2d2c2b2a29282726252423222120"
+ test_one_register "vmovhlps" "ymm0" \
+ "0x2f2e2d2c2b2a29282726252423222120, 0x0"
+
# Explicitly test for the start of the array, since the value repeats.
test_one_memory "vmovaps" "dyn_buf1" \
"\\\{0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28" true
@@ -365,6 +392,24 @@ gdb_test_no_output "set \$xmm1.v2_int64 = {0x1716151413121110, 0x1f1e1d1c1b1a191
"set xmm1 for vpbroadcast"
gdb_test_no_output "set \$ymm15.v2_int128 = {0x0, 0x0}" "set xmm15 for vpbroadcast"
if {[record_full_function "vpbroadcast"] == true} {
+ test_one_register "vbroadcastf128" "ymm0" \
+ "0x17161514131211101716151413121110, 0x17161514131211101716151413121110"
+ test_one_register "vbroadcastsd" "ymm15" \
+ "0x23222120232221202322212023222120, 0x0"
+ test_one_register "vbroadcastsd" "ymm0" \
+ "0x13121110131211101312111013121110, 0x13121110131211101312111013121110"
+
+ test_one_register "vbroadcastss" "ymm15" \
+ "0x13121110131211101312111013121110, 0x13121110131211101312111013121110" \
+ "broadcast from memory"
+ test_one_register "vbroadcastss" "ymm0" \
+ "0x13121110131211101312111013121110, 0x0" \
+ "broadcast from memory"
+ test_one_register "vbroadcastss" "ymm15" \
+ "0x17161514131211101716151413121110, 0x17161514131211101716151413121110"
+ test_one_register "vbroadcastss" "ymm0" \
+ "0x17161514131211101716151413121110, 0x17161514131211101716151413121110"
+
test_one_register "vpbroadcastq" "ymm15" "0x13121110131211101312111013121110, 0x0"
test_one_register "vpbroadcastq" "ymm0" "0x13121110131211101312111013121110, 0x0"
@@ -397,7 +442,7 @@ gdb_test_no_output "set \$ymm15.v2_int128 = {0x0, 0xcafeface}" "set ymm15 for vp
if {[record_full_function "vzeroupper"] == true} {
# Since vzeroupper needs to save 8 or 16 registers, let's check what was
# actually recorded, instead of just undoing an instruction. Only
- # really check the values of egisters 0, 1, 2 and 15 because those are
+ # really check the values of registers 0, 1, 2 and 15 because those are
# the only ones we're setting.
gdb_test "maint print record-instruction" \
[multi_line "Register ymm0h changed: 74565" \
@@ -527,9 +572,43 @@ gdb_test_no_output \
"set \$ymm0.v8_float = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5}"
gdb_test_no_output \
"set \$ymm1.v8_float = {0, 1, 2, 3, 4, 5, 6, 7}"
+gdb_test_no_output "set \$ymm2.v2_int128 = {0,0}"
gdb_test_no_output "set \$ymm15.v2_int128 = {0,0}"
if {[record_full_function "arith"] == true} {
+ test_one_register "vpsadbw" "ymm15" \
+ "0x20000000200000004000003f000000, 0x100000001000000010000000100000"
+ test_one_register "vpsadbw" "ymm2" \
+ "0x20000000200000004000003f000000, 0x100000001000000010000000100000"
+ test_one_register "vpandn" "ymm15" \
+ "0x40400000400000003f80000000000000, 0x0"
+ test_one_register "vpand" "ymm15" \
+ "0x10080000000000000000000000000000, 0x10649c00000000001044480000000000"
+ test_one_register "vxorpd" "ymm2" \
+ "0x20000000200000004000003f000000, 0x0"
+ test_one_register "vxorps" "ymm2" \
+ "0x10280000100800000fd0000000000000, 0x10740000106400001054000010440000"
+
+ test_one_register "vpmuludq" "ymm15" \
+ "0x10280000100800000fd0000000000000, 0x10740000106400001054000010440000"
+ test_one_register "vpmulhuw" "ymm15" \
+ "0x0, 0x0"
+ test_one_register "vpmulhw" "ymm2" \
+ "0x18000000000000002000000000000000, 0x0"
+ test_one_register "vpmulld" "ymm15" \
+ "0x80a00000802000007f4000003f000000, 0x81d00000819000008150000081100000"
+ test_one_register "vpmullw" "ymm2" \
+ "0x80a00000802000007f4000003f000000, 0x81d00000819000008150000081100000"
+
+ test_one_register "vpaddq" "ymm15" \
+ "0x80a00000802000007f4000003f000000, 0x0"
+ test_one_register "vpaddd" "ymm2" \
+ "0x80a00000802000007e4000003f000000, 0x0"
+ test_one_register "vpaddw" "ymm15" \
+ "0x40400000400000003fc000003f000000, 0x0"
+ test_one_register "vpaddb" "ymm2" \
+ "0x0, 0x0"
+
test_one_register "vmaxsd" "ymm15" \
"0x40400000400000003f8000003f000000, 0x0" "ymm operation: "
test_one_register "vmaxss" "ymm15" \
@@ -626,3 +705,493 @@ if {[record_full_function "arith"] == true} {
}
gdb_test "finish" "Run till exit from.*arith_test.*" \
"leaving arith"
+
+# Preparation and testing vaddsubpd instructions
+
+gdb_test_no_output "set \$ymm15.v2_int128 = {0xcafeface, 0xcafeface}" \
+ "set ymm15 for vaddsubpd"
+gdb_test_no_output "set \$ymm0.v2_int128 = {0xcafeface, 0xcafeface}" \
+ "set ymm0 for vaddsubpd"
+gdb_test_no_output "set \$xmm2.uint128 = 0xbeef" \
+ "set xmm2 for vaddsubpd"
+gdb_test_no_output "set \$xmm10.uint128 = 0xbeef" \
+ "set xmm10 for vaddsubpd"
+gdb_test_no_output "set \$ymm3.v2_int128 = {0xcafeface, 0xcafeface}" \
+ "set ymm3 for vaddsubpd"
+gdb_test_no_output "set \$ymm4.v2_int128 = {0xcafeface, 0xcafeface}" \
+ "set ymm4 for vaddsubpd"
+
+if {[record_full_function "vaddsubpd"] == true} {
+ test_one_register "vaddsubpd" "xmm10" \
+ "0xbeef" "xmm10:"
+ test_one_register "vaddsubpd" "xmm2" \
+ "0xbeef" "xmm2:"
+ test_one_register "vaddsubpd" "ymm4" \
+ "0xcafeface, 0xcafeface" "ymm4: "
+ test_one_register "vaddsubpd" "ymm15" \
+ "0xcafeface, 0xcafeface" "ymm15: "
+ test_one_register "vaddsubpd" "ymm0" \
+ "0xcafeface, 0xcafeface" "ymm0: "
+
+ gdb_test "record stop" "Process record is stopped.*" \
+ "delete history for vaddsubpd_test"
+} else {
+ untested "couldn't run vaddsubpd tests"
+}
+gdb_test "finish" "Run till exit from.*vaddsubpd_test.*" \
+ "leaving vaddsubpd"
+
+# Preparation and testing vaddsubps instruction
+
+gdb_test_no_output "set \$ymm10.v2_int128 = {0xcafeface, 0xcafeface}" \
+ "set ymm10 for vaddsubps"
+gdb_test_no_output "set \$ymm2.v2_int128 = {0xcafeface, 0xcafeface}" \
+ "set ymm2 for vaddsubps"
+gdb_test_no_output "set \$xmm15.uint128 = 0xbeef" \
+ "set xmm15 for vaddsubps"
+gdb_test_no_output "set \$xmm0.uint128 = 0xbeef" \
+ "set xmm0 for vaddsubps"
+gdb_test_no_output "set \$ymm3.v2_int128 = {0xcafeface, 0xcafeface}" \
+ "set ymm3 for vaddsubps"
+gdb_test_no_output "set \$ymm4.v2_int128 = {0xcafeface, 0xcafeface}" \
+ "set ymm4 for vaddsubps"
+
+if {[record_full_function "vaddsubps"] == true} {
+ test_one_register "vaddsubps" "xmm0" \
+ "0xbeef" "xmm0: "
+ test_one_register "vaddsubps" "xmm15" \
+ "0xbeef" "xmm15: "
+ test_one_register "vaddsubps" "ymm4" \
+ "0xcafeface, 0xcafeface" "ymm4: "
+ test_one_register "vaddsubps" "ymm10" \
+ "0xcafeface, 0xcafeface" "ymm10: "
+ test_one_register "vaddsubps" "ymm2" \
+ "0xcafeface, 0xcafeface" "ymm2: "
+
+ gdb_test "record stop" "Process record is stopped.*" \
+ "delete history for vaddsubps_test"
+} else {
+ untested "couldn't run vaddsubps tests"
+}
+gdb_test "finish" "Run till exit from.*vaddsubps_test.*" \
+ "leaving vaddsubps"
+
+# Preparation and testing shifting instructions.
+gdb_test_no_output \
+ "set \$ymm0.v2_int128 = {0, 0}" "set ymm0 for shift"
+gdb_test_no_output \
+ "set \$ymm1.v16_int16 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}" \
+ "set ymm1 for shift"
+gdb_test_no_output "set \$xmm2.uint128 = 1" "set ymm2 for shift"
+gdb_test_no_output "set \$ymm15.v2_int128 = {0,0}" "set ymm15 for shift"
+
+if {[record_full_function "shift"] == true} {
+ test_one_register "vpsrldq" "ymm15" \
+ "0x80007000600050004000300, 0x0" \
+ "High ymm register: "
+ test_one_register "vpsrldq" "ymm15" \
+ "0x60005000400030002000100000000, 0xe000d000c000b000a000900000000" \
+ "High xmm register: "
+ test_one_register "vpsrldq" "ymm0" \
+ "0x800070006000500040003000200, 0x0" \
+ "Low ymm register: "
+ test_one_register "vpsrldq" "ymm0" \
+ "0x70006000500040003000200010000, 0xf000e000d000c000b000a00090000" \
+ "Low xmm register: "
+
+ test_one_register "vpslldq" "ymm15" \
+ "0x7000600050004000300020001000000, 0x0" \
+ "High ymm register: "
+ test_one_register "vpslldq" "ymm15" \
+ "0x40003800300020002000180010000, 0x80007800700060006000580050004" \
+ "High xmm register: "
+ test_one_register "vpslldq" "ymm0" \
+ "0x8000700060005000400030002000100, 0x0" \
+ "Low ymm register: "
+ test_one_register "vpslldq" "ymm0" \
+ "0x40003000300020002000100010000, 0x80007000700060006000500050004" \
+ "Low xmm register: "
+
+ test_one_register "vpsrlq" "ymm15" \
+ "0x4000380030000000200018001000, 0x0" \
+ "from register: "
+ test_one_register "vpsrlq" "ymm15" \
+ "0x40003000300020002000100010000, 0x0" \
+ "from constant: "
+ test_one_register "vpsrld" "ymm15" \
+ "0x100000000c0000000800000004000, 0x200010001c0010001800100014001" \
+ "from register: "
+ test_one_register "vpsrld" "ymm15" \
+ "0x40003000300020002000100010000, 0x0" \
+ "from constant: "
+ test_one_register "vpsrlw" "ymm0" \
+ "0x40003000300020002000100010000, 0x0" \
+ "from register: "
+ test_one_register "vpsrlw" "ymm0" \
+ "0x40003000300020002000100010000, 0x80007000700060006000500050004" \
+ "from constant: "
+
+ test_one_register "vpsrad" "ymm15" \
+ "0x100000000c0000000800000004000, 0x200010001c0010001800100014001" \
+ "from register: "
+ test_one_register "vpsrad" "ymm15" \
+ "0x10000e000c000a0008000600040002, 0x20001e001c001a0018001600140012" \
+ "from constant: "
+ test_one_register "vpsraw" "ymm0" \
+ "0x40003000300020002000100010000, 0x0" \
+ "from register: "
+ test_one_register "vpsraw" "ymm0" \
+ "0x10000e000c000a0008000600040002, 0x20001e001c001a0018001600140012" \
+ "from constant: "
+
+ test_one_register "vpsllq" "ymm15" \
+ "0x10000e000c000a00080006000400020, 0x0" \
+ "from register: "
+ test_one_register "vpsllq" "ymm15" \
+ "0x10000e000c000a0008000600040002, 0x0" \
+ "from constant: "
+ test_one_register "vpslld" "ymm15" \
+ "0x400038003000280020001800100008, 0x800078007000680060005800500048" \
+ "from register: "
+ test_one_register "vpslld" "ymm15" "0x0, 0x0" "from constant: "
+ test_one_register "vpsllw" "ymm0" \
+ "0x10000e000c000a0008000600040002, 0x0" \
+ "from register: "
+ test_one_register "vpsllw" "ymm0" "0x0, 0x0" "from constant: "
+
+ gdb_test "record stop" "Process record is stopped.*" \
+ "delete history for shift_test"
+} else {
+ untested "couldn't run shift tests"
+}
+gdb_test "finish" "Run till exit from.*shift_test.*" \
+ "leaving shift"
+
+# Preparation and testing shuffling instructions.
+gdb_test_no_output \
+ "set \$ymm0.v2_int128 = {0, 0}" "set ymm0 for shuffle"
+gdb_test_no_output \
+ "set \$ymm1.v16_int16 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}" \
+ "set ymm1 for shuffle"
+gdb_test_no_output "set \$ymm2.v16_int16 = {17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}" \
+ "set ymm2 for shuffle"
+gdb_test_no_output "set \$ymm15.v2_int128 = {0,0}" "set ymm15 for shuffle"
+
+if {[record_full_function "shuffle"] == true} {
+ test_one_register "vshufpd" "ymm15" \
+ "0x20001000200010012001100160015, 0xa0009000a0009001a0019001e001d" \
+ "high register: "
+ test_one_register "vshufpd" "ymm0" \
+ "0x20001000200010012001100140013, 0x0" \
+ "low register: "
+ test_one_register "vshufps" "ymm15" \
+ "0x180017001600150011001100120013, 0x0" \
+ "high register: "
+ test_one_register "vshufps" "ymm0" \
+ "0x180017001600150011001100120012, 0x20001f001e001d00190019001a001a" \
+ "low register: "
+
+ test_one_register "vpshuflw" "ymm15" \
+ "0x150015001600150014001300120011, 0x1d001d001e001d001c001b001a0019" \
+ "high register: "
+ test_one_register "vpshuflw" "ymm0" \
+ "0x150015001500180014001300120011, 0x0" \
+ "low register: "
+ test_one_register "vpshufhw" "ymm15" \
+ "0x120011001200110012001100160015, 0x0" \
+ "high register: "
+ test_one_register "vpshufhw" "ymm0" \
+ "0x120011001200110012001100140013, 0x1a0019001a0019001a0019001c001b" \
+ "low register: "
+
+ test_one_register "vpshufd" "ymm15" \
+ "0x11151100111411001113110011121100, 0x1919190019201900191f1900191e1900" \
+ "high register: "
+ test_one_register "vpshufd" "ymm0" \
+ "0x11151100111411001113110011121100, 0x0" \
+ "low register: "
+ test_one_register "vpshufb" "ymm15" "0x0, 0x0" "high register: "
+ test_one_register "vpshufb" "ymm0" "0x0, 0x0" "low register: "
+
+ gdb_test "record stop" "Process record is stopped.*" \
+ "delete history for shuffle_test"
+} else {
+ untested "couldn't run shuffle tests"
+}
+gdb_test "finish" "Run till exit from.*shuffle_test.*" \
+ "leaving shuffle"
+
+# Preparation and testing permute instructions.
+gdb_test_no_output \
+ "set \$ymm0.v2_int128 = {0, 0}" "set ymm0 for permute"
+gdb_test_no_output \
+ "set \$ymm1.v16_int16 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}" \
+ "set ymm1 for permute"
+gdb_test_no_output "set \$ymm2.v16_int16 = {17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}" \
+ "set ymm2 for permute"
+gdb_test_no_output "set \$ymm15.v2_int128 = {0,0}" "set ymm15 for permute"
+
+if {[record_full_function "permute"] == true} {
+ test_one_register "vpermps" "ymm15" \
+ "0x40003000200010004000300020001, 0x40003000200010004000300020001"
+ test_one_register "vpermps" "ymm0" \
+ "0x140013001200110014001300120011, 0x140013001200110014001300120011"
+ test_one_register "vpermpd" "ymm0" \
+ "0x120011001200110012001100120011, 0x0"
+ test_one_register "vpermpd" "ymm15" \
+ "0x120011001200110012001100140013, 0x1a0019001a0019001a0019001c001b"
+
+ test_one_register "vpermilps" "ymm0" \
+ "0x180017001400130018001700140013, 0x20001f001c001b0020001f001c001b" \
+ "register version"
+ test_one_register "vpermilps" "ymm15" \
+ "0x180017001400130018001700140013, 0x0" \
+ "register version"
+ test_one_register "vpermilps" "ymm15" \
+ "0x140013001200110018001700160015, 0x1c001b001a0019001c001b001a0019" \
+ "immediate version"
+ test_one_register "vpermilps" "ymm0" \
+ "0x140013001200110014001300120011, 0x0" \
+ "immediate version"
+
+ test_one_register "vpermilpd" "ymm0" \
+ "0x140013001200110014001300120011, 0x1c001b001a0019001c001b001a0019" \
+ "register version"
+ test_one_register "vpermilpd" "ymm15" \
+ "0x140013001200110014001300120011, 0x0" \
+ "register version"
+ test_one_register "vpermilpd" "ymm15" \
+ "0x140013001200110014001300120011, 0x140013001200110014001300120011" \
+ "immediate version"
+ test_one_register "vpermilpd" "ymm0" \
+ "0x40003000200010008000700060005, 0x40003000200010004000300020001" \
+ "immediate version"
+
+ test_one_register "vpermq" "ymm15" \
+ "0x10000f000c000b0008000700040003, 0x10000f000c000b0008000700040003"
+ test_one_register "vpermq" "ymm0" \
+ "0x10000f000c000b0008000700040003, 0x10000f000c000b0008000700040003"
+ test_one_register "vpermd" "ymm15" \
+ "0x80007000600050004000300020001, 0x80007000600050004000300020001"
+ test_one_register "vpermd" "ymm0" \
+ "0x10000f000e000d000c000b000a0009, 0x80007000600050004000300020001"
+
+ test_one_register "vperm2i128" "ymm15" \
+ "0x180017001600150014001300120011, 0x180017001600150014001300120011"
+ test_one_register "vperm2i128" "ymm0" \
+ "0x20001f001e001d001c001b001a0019, 0x180017001600150014001300120011"
+ test_one_register "vperm2f128" "ymm15" "0x0, 0x0"
+ test_one_register "vperm2f128" "ymm0" "0x0, 0x0"
+
+ gdb_test "record stop" "Process record is stopped.*" \
+ "delete history for permute_test"
+} else {
+ untested "couldn't run permute tests"
+}
+gdb_test "finish" "Run till exit from.*permute_test.*" \
+ "leaving permute"
+
+# Preparation and testing extract_insert instructions.
+gdb_test_no_output \
+ "set \$ymm0.v2_int128 = {0, 0}" "set ymm0 for extract_insert"
+gdb_test_no_output \
+ "set \$ymm1.v16_int16 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}" \
+ "set ymm1 for extract_insert"
+gdb_test_no_output "set \$xmm2.uint128 = 0xcafe" \
+ "set ymm2 for extract_insert"
+gdb_test_no_output "set \$ymm15.v2_int128 = {0,0}" "set ymm15 for extract_insert"
+gdb_test_no_output "set \$rax = 0" "set eax for extract_insert"
+
+if {[record_full_function "extract_insert"] == true} {
+ test_one_memory "vpextrw" "global_buf1" \
+ "\\\{0x1, 0x0, 0x2, 0x0, 0x3, 0x0, 0x4, 0x0 <repeats 25 times>"
+ test_one_general_register "vpextrw" "rax" "0x8000700060005"
+
+ test_one_register "vpinsrq" "ymm15" \
+ "0x50000cafe, 0x0"
+ test_one_register "vpinsrd" "ymm0" \
+ "0x500cafe, 0x0"
+ test_one_register "vpinsrw" "ymm15" \
+ "0x80007000600050004000300020001, 0x0"
+ test_one_register "vpinsrb" "ymm0" \
+ "0x80007000600050000cafe00020001, 0x0"
+
+ test_one_memory "vpextrq" "global_buf1" \
+ "\\\{0x5, 0x0, 0x6, 0x0 <repeats 29 times>"
+ test_one_general_register "vpextrq" "rax" "0x80007"
+ test_one_memory "vpextrd" "global_buf1" \
+ "\\\{0x3, 0x0 <repeats 31 times>"
+ test_one_general_register "vpextrd" "rax" "0x0"
+ test_one_memory "vpextrb" "global_buf1" \
+ "\\\{0x0 <repeats 32 times>"
+ test_one_general_register "vpextrb" "rax" "0xcafe"
+
+ test_one_general_register "vextractps" "eax" "0x0"
+ test_one_register "vinsertps" "ymm0" \
+ "0x10000f000e000d000c000b000a0009, 0x0"
+ test_one_register "vextractf128" "ymm15" \
+ "0xcafe, 0x10000f000e000d000c000b000a0009"
+ test_one_register "vextracti128" "ymm0" \
+ "0x80007000600050004000300020001, 0xcafe"
+ test_one_register "vinsertf128" "ymm15" \
+ "0x0, 0x0"
+ test_one_register "vinserti128" "ymm0" \
+ "0x0, 0x0"
+
+ gdb_test "record stop" "Process record is stopped.*" \
+ "delete history for extract_insert_test"
+} else {
+ untested "couldn't run extract_insert tests"
+}
+gdb_test "finish" "Run till exit from.*extract_insert_test.*" \
+ "leaving extract_insert"
+
+# Preparation and testing blend instructions.
+gdb_test_no_output \
+ "set \$ymm0.v2_int128 = {0, 0}" "set ymm0 for blend"
+gdb_test_no_output \
+ "set \$ymm1.v16_int16 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}" \
+ "set ymm1 for blend"
+gdb_test_no_output \
+ "set \$ymm2.v16_int16 = {17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}" \
+ "set ymm2 for blend"
+gdb_test_no_output "set \$ymm15.v2_int128 = {0,0}" "set ymm15 for blend"
+
+if {[record_full_function "blend"] == true} {
+ test_one_register "vpblendvb" "ymm0" \
+ "0x180017000600050004000300120011, 0x20001f001e001d001c001b000a0009"
+ test_one_register "vpblendvb" "ymm15" \
+ "0x80007001600150004000300020001, 0x0"
+ test_one_register "vpblendd" "ymm15" \
+ "0x180007001600050004000300020011, 0x20000f001e000d000c000b000a0019"
+ test_one_register "vpblendd" "ymm0" \
+ "0x180017000600150004000300020001, 0x0"
+ test_one_register "vpblendw" "ymm0" \
+ "0x180017001600150014001300120011, 0x20001f001e001d001c001b001a0019"
+ test_one_register "vpblendw" "ymm15" \
+ "0x180017001600150014001300120011, 0x0"
+
+ test_one_register "vblendvpd" "ymm15" \
+ "0x80007000600050014001300120011, 0x10000f000e000d001c001b001a0019"
+ test_one_register "vblendvps" "ymm0" \
+ "0x180017000600050014001300020001, 0x0"
+ test_one_register "vblendpd" "ymm15" "0x0, 0x0"
+ test_one_register "vblendps" "ymm0" "0x0, 0x0"
+
+ gdb_test "record stop" "Process record is stopped.*" \
+ "delete history for blend_test"
+} else {
+ untested "couldn't run blend tests"
+}
+gdb_test "finish" "Run till exit from.*blend_test.*" \
+ "leaving blend"
+
+# Preparation and testing compare instructions.
+gdb_test_no_output \
+ "set \$xmm0.v4_float = {0, 1.5, 2, 0}" "set ymm0 for compare"
+gdb_test_no_output \
+ "set \$xmm1.v4_float = {0, 1, 2.5, -1}" "set ymm1 for compare"
+gdb_test_no_output \
+ "set \$xmm15.v4_float = {-1, -2, 10, 100}" "set ymm15 for compare"
+gdb_test_no_output "set \$eflags = 2"
+
+if {[record_full_function "compare"] == true} {
+ test_one_general_register "vucomisd" "eflags" "0x203"
+ test_one_general_register "vucomiss" "eflags" "0x202"
+ test_one_general_register "vcomiss" "eflags" "0x203"
+ test_one_general_register "vcomisd" "eflags" "0x202"
+
+ gdb_test "record stop" "Process record is stopped.*" \
+ "delete history for compare_test"
+} else {
+ untested "couldn't run compare tests"
+}
+gdb_test "finish" "Run till exit from.*compare_test.*" \
+ "leaving compare"
+
+# Preparation and testing pack instructions.
+gdb_test_no_output \
+ "set \$ymm0.v2_int128 = {0, 0}" "set ymm0 for pack"
+gdb_test_no_output \
+ "set \$ymm1.v16_int16 = {0x1020, 0x1121, 0x1222, 0x1323, 0x1424, 0x1525, 0x1626, 0x1727, 0x1828, 0x1929, 0x1a2a, 0x1b2b, 0x1c2c, 0x1d2d, 0x1e2e, 0x1f2f}" \
+ "set ymm1 for pack"
+gdb_test_no_output \
+ "set \$ymm2.v16_int16 = {0x3040, 0x3141, 0x3242, 0x3343, 0x3444, 0x3545, 0x3646, 0x3747, 0x3848, 0x3949, 0x3a4a, 0x3b4b, 0x3c4c, 0x3d4d, 0x3e4e, 0x3f4f}" \
+ "set ymm2 for pack"
+gdb_test_no_output \
+ "set \$ymm15.v2_int128 = {0, 0}" "set ymm15 for pack"
+
+if {[record_full_function "pack"] == true} {
+ test_one_register "vpackusdw" "ymm0" \
+ "0xffffffffffffffffffffffffffffffff, 0x0"
+ test_one_register "vpackusdw" "ymm15" \
+ "0xffffffffffffffffffffffffffffffff, 0xffffffffffffffffffffffffffffffff"
+ test_one_register "vpackuswb" "ymm15" \
+ "0x7fff7fff7fff7fff7fff7fff7fff7fff, 0x0"
+ test_one_register "vpackuswb" "ymm0" \
+ "0x7fff7fff7fff7fff7fff7fff7fff7fff, 0x7fff7fff7fff7fff7fff7fff7fff7fff"
+ test_one_register "vpackssdw" "ymm0" \
+ "0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f, 0x0"
+ test_one_register "vpackssdw" "ymm15" \
+ "0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f, 0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f"
+ test_one_register "vpacksswb" "ymm15" "0x0, 0x0"
+ test_one_register "vpacksswb" "ymm0" "0x0, 0x0"
+
+ gdb_test "record stop" "Process record is stopped.*" \
+ "delete history for pack_test"
+} else {
+ untested "couldn't run pack tests"
+}
+gdb_test "finish" "Run till exit from.*pack_test.*" \
+ "leaving pack"
+
+# Preparation and testing converting instructions.
+gdb_test_no_output \
+ "set \$ymm0.v2_int128 = {0,0}" \
+ "set ymm0 for convert test"
+gdb_test_no_output \
+ "set \$ymm1.v8_float = {0, 1, 2.5, 10, -1, -2.5, 0}" \
+ "set ymm1 for convert test"
+gdb_test_no_output "set \$ymm15.v2_int128 = {0,0}" \
+ "set ymm15 for convert test"
+gdb_test_no_output "set \$ecx = -1" "set ecx for convert test"
+gdb_test_no_output "set \$ebx = 1" "set ebx for convert test"
+
+if {[record_full_function "convert"] == true} {
+ gdb_test "maint print record-instruction" ".*"
+ test_one_general_register "vcvttss2si" "ecx" "0xffffffff"
+ test_one_general_register "vcvttsd2si" "ebx" "0x0"
+ test_one_register "vcvttps2dq" "ymm15" \
+ "0x41200000402000003f8000004f800000, 0x0"
+ test_one_register "vcvttpd2dq" "ymm0" \
+ "0x412000004020000041f0000000000000, 0x0"
+ test_one_general_register "vcvtss2si" "ebx" "0x0"
+
+ test_one_register "vcvtss2sd" "ymm0" \
+ "0x412000004020000041efffffffe00000, 0x0"
+ test_one_register "vcvtsi2ss" "ymm15" \
+ "0x41200000402000003f80000000000000, 0x0"
+ test_one_register "vcvtsi2sd" "ymm0" \
+ "0x8000000000000, 0x0"
+ test_one_register "vcvtsd2ss" "ymm15" \
+ "0x490000023c000000, 0x0"
+ test_one_general_register "vcvtsd2si" "ebx" "0x1"
+
+ test_one_register "vcvtpd2dq" "ymm0" \
+ "0x3ff00000000000000000000000000000, 0x0"
+ test_one_register "vcvtpd2ps" "ymm15" \
+ "0xa000000020000000100000000, 0x0"
+ test_one_register "vcvtps2pd" "ymm0" \
+ "0x4e8240004e8040004e7e000000000000, 0x0"
+ test_one_register "vcvtps2dq" "ymm15" \
+ "0x41cfc000000000000000000000000000, 0x0"
+ test_one_register "vcvtdq2pd" "ymm15" "0x0, 0x0"
+ test_one_register "vcvtdq2ps" "ymm0" "0x0, 0x0"
+
+ gdb_test "record stop" "Process record is stopped.*" \
+ "delete history for convert_test"
+} else {
+ untested "couldn't run convert tests"
+}
+gdb_test "finish" "Run till exit from.*convert_test.*" \
+ "leaving convert"
diff --git a/gdb/testsuite/gdb.reverse/solib-precsave.exp b/gdb/testsuite/gdb.reverse/solib-precsave.exp
index 277e33c..82b08cd 100644
--- a/gdb/testsuite/gdb.reverse/solib-precsave.exp
+++ b/gdb/testsuite/gdb.reverse/solib-precsave.exp
@@ -140,7 +140,7 @@ gdb_test_multiple "reverse-step" "reverse-step into solib function one" {
pass $gdb_test_name
}
}
-# Depending on wether the closing } has a line associated, we might have
+# Depending on whether the closing } has a line associated, we might have
# different acceptable results here
gdb_test_multiple "reverse-step" "reverse-step within solib function one" {
-re -wrap "return y;.*" {
diff --git a/gdb/testsuite/gdb.reverse/solib-reverse.exp b/gdb/testsuite/gdb.reverse/solib-reverse.exp
index 1e22e91..b2ef9b0 100644
--- a/gdb/testsuite/gdb.reverse/solib-reverse.exp
+++ b/gdb/testsuite/gdb.reverse/solib-reverse.exp
@@ -116,7 +116,7 @@ gdb_test_multiple "reverse-step" "reverse-step into solib function one" {
pass $gdb_test_name
}
}
-# Depending on wether the closing } has a line associated, we might have
+# Depending on whether the closing } has a line associated, we might have
# different acceptable results here
gdb_test_multiple "reverse-step" "reverse-step within solib function one" {
-re -wrap "return y;.*" {
diff --git a/gdb/testsuite/gdb.rocm/code-object-load-while-breakpoint-hit.cpp b/gdb/testsuite/gdb.rocm/code-object-load-while-breakpoint-hit.cpp
new file mode 100644
index 0000000..d75bc76
--- /dev/null
+++ b/gdb/testsuite/gdb.rocm/code-object-load-while-breakpoint-hit.cpp
@@ -0,0 +1,86 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef DEVICE
+
+#include <hip/hip_runtime.h>
+
+constexpr unsigned int NUM_BREAKPOINT_HITS = 5;
+
+static __device__ void
+break_here ()
+{
+}
+
+extern "C" __global__ void
+kernel ()
+{
+ for (int n = 0; n < NUM_BREAKPOINT_HITS; ++n)
+ break_here ();
+}
+
+#else
+
+#include <hip/hip_runtime.h>
+#include <unistd.h>
+
+constexpr unsigned int NUM_ITEMS_PER_BLOCK = 256;
+constexpr unsigned int NUM_BLOCKS = 128;
+constexpr unsigned int NUM_ITEMS = NUM_ITEMS_PER_BLOCK * NUM_BLOCKS;
+constexpr unsigned int NUM_LOAD_UNLOADS = 5;
+
+#define CHECK(cmd) \
+ { \
+ hipError_t error = cmd; \
+ if (error != hipSuccess) \
+ { \
+ fprintf (stderr, "error: '%s'(%d) at %s:%d\n", \
+ hipGetErrorString (error), error, __FILE__, __LINE__); \
+ exit (EXIT_FAILURE); \
+ } \
+ }
+
+int
+main (int argc, const char **argv)
+{
+ if (argc != 2)
+ {
+ fprintf (stderr, "Usage: %s <hip_module_path>\n", argv[0]);
+ return 1;
+ }
+
+ const auto module_path = argv[1];
+ hipModule_t module;
+ CHECK (hipModuleLoad (&module, module_path));
+
+ /* Launch the kernel. */
+ hipFunction_t function;
+ CHECK (hipModuleGetFunction (&function, module, "kernel"));
+ CHECK (hipModuleLaunchKernel (function, NUM_BLOCKS, 1, 1,
+ NUM_ITEMS_PER_BLOCK, 1, 1, 0, nullptr, nullptr,
+ nullptr));
+
+ /* Load and unload the module many times. */
+ for (int i = 0; i < NUM_LOAD_UNLOADS; ++i)
+ {
+ hipModule_t dummy_module;
+ CHECK (hipModuleLoad (&dummy_module, module_path));
+ CHECK (hipModuleUnload (dummy_module));
+ }
+}
+
+#endif
diff --git a/gdb/testsuite/gdb.rocm/code-object-load-while-breakpoint-hit.exp b/gdb/testsuite/gdb.rocm/code-object-load-while-breakpoint-hit.exp
new file mode 100644
index 0000000..3fe6a95
--- /dev/null
+++ b/gdb/testsuite/gdb.rocm/code-object-load-while-breakpoint-hit.exp
@@ -0,0 +1,68 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This file is part of GDB.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This test verifies what happens when a code object list update happens at the
+# same time as some wave stop events are reported. It was added following a
+# performance bug fix, where forward progress requirement disabled when
+# pulling events from amd-dbgapi in amd_dbgapi_target_breakpoint::check_status.
+#
+# The test launches a kernel that hits a breakpoint with an always false
+# condition a certain number of times. Meanwhile, the host loads and unloads
+# a code object in a loop, causing check_status to be called. The hope is that
+# check_status, when calling process_event_queue, will pull many WAVE_STOP
+# events from the kernel hitting the breakpoint.
+#
+# Without the appropriate fix (of disabling forward progress requirement in
+# check_status), GDB would hit the newly-added assert in process_event_queue,
+# which verifies that forward progress requirement is disabled. Even without
+# this assert, the test would likely time out (depending on the actual timeout
+# value).
+
+load_lib rocm.exp
+standard_testfile .cpp
+require allow_hipcc_tests
+
+# Build the host executable.
+if { [build_executable "failed to prepare" \
+ $testfile $srcfile {debug hip}] == -1 } {
+ return -1
+}
+
+set hipmodule_path [standard_output_file ${testfile}.co]
+
+# Build the kernel object file.
+if { [gdb_compile $srcdir/$subdir/$srcfile \
+ $hipmodule_path object \
+ { debug hip additional_flags=--genco additional_flags=-DDEVICE } ] != "" } {
+ return -1
+}
+
+proc do_test { } {
+ with_rocm_gpu_lock {
+ clean_restart $::binfile
+ gdb_test_no_output "set args $::hipmodule_path" "set args"
+
+ if { ![runto_main] } {
+ return
+ }
+
+ gdb_test "with breakpoint pending on -- break break_here if 0"
+ gdb_continue_to_end "continue to end" "continue" 1
+ }
+}
+
+do_test
diff --git a/gdb/testsuite/gdb.rocm/fork-exec-gpu-to-non-gpu.exp b/gdb/testsuite/gdb.rocm/fork-exec-gpu-to-non-gpu.exp
index 7588525..22d4b75 100644
--- a/gdb/testsuite/gdb.rocm/fork-exec-gpu-to-non-gpu.exp
+++ b/gdb/testsuite/gdb.rocm/fork-exec-gpu-to-non-gpu.exp
@@ -21,6 +21,7 @@
load_lib rocm.exp
require allow_hipcc_tests
+require allow_fork_tests
standard_testfile -execer.cpp -execee.cpp
diff --git a/gdb/testsuite/gdb.rocm/fork-exec-non-gpu-to-gpu.exp b/gdb/testsuite/gdb.rocm/fork-exec-non-gpu-to-gpu.exp
index a6bcf69..1386099 100644
--- a/gdb/testsuite/gdb.rocm/fork-exec-non-gpu-to-gpu.exp
+++ b/gdb/testsuite/gdb.rocm/fork-exec-non-gpu-to-gpu.exp
@@ -20,6 +20,7 @@
load_lib rocm.exp
require allow_hipcc_tests
+require allow_fork_tests
standard_testfile -execer.cpp -execee.cpp
diff --git a/gdb/testsuite/gdb.rocm/mi-attach.cpp b/gdb/testsuite/gdb.rocm/mi-attach.cpp
index da7659d..441d460 100644
--- a/gdb/testsuite/gdb.rocm/mi-attach.cpp
+++ b/gdb/testsuite/gdb.rocm/mi-attach.cpp
@@ -15,8 +15,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include <unistd.h>
#include <hip/hip_runtime.h>
+#include "gdb_watchdog.h"
__global__ void
kern ()
@@ -30,7 +30,7 @@ main ()
{
/* This program will run outside of GDB, make sure that if anything goes
wrong it eventually gets killed. */
- alarm (30);
+ gdb_watchdog (30);
kern<<<1, 1>>> ();
return hipDeviceSynchronize () != hipSuccess;
diff --git a/gdb/testsuite/gdb.rocm/precise-memory-fork.exp b/gdb/testsuite/gdb.rocm/precise-memory-fork.exp
index d326c2e..23c1ebe 100644
--- a/gdb/testsuite/gdb.rocm/precise-memory-fork.exp
+++ b/gdb/testsuite/gdb.rocm/precise-memory-fork.exp
@@ -21,6 +21,7 @@
load_lib rocm.exp
require allow_hipcc_tests
+require allow_fork_tests
standard_testfile .c
diff --git a/gdb/testsuite/gdb.rocm/precise-memory.exp b/gdb/testsuite/gdb.rocm/precise-memory.exp
index fbcb451..6711d80 100644
--- a/gdb/testsuite/gdb.rocm/precise-memory.exp
+++ b/gdb/testsuite/gdb.rocm/precise-memory.exp
@@ -59,7 +59,7 @@ proc do_test { } {
return
}
- # Get to the begining of the GPU kernel without precise memory enabled.
+ # Get to the beginning of the GPU kernel without precise memory enabled.
with_test_prefix "goto gpu code" {
gdb_test_no_output "set amdgpu precise-memory off"
gdb_breakpoint "kernel" allow-pending
diff --git a/gdb/testsuite/gdb.server/build-id-seqno.exp b/gdb/testsuite/gdb.server/build-id-seqno.exp
index a508a44..8475ccc 100644
--- a/gdb/testsuite/gdb.server/build-id-seqno.exp
+++ b/gdb/testsuite/gdb.server/build-id-seqno.exp
@@ -90,13 +90,13 @@ proc load_binfile_check_debug_is_found { debuginfo_file testname } {
with_test_prefix "$testname" {
with_timeout_factor 5 {
# Probing for .build-id based debug files on remote
- # targets uses the vFile:stat packet by default, though
+ # targets uses the vFile:lstat packet by default, though
# there is a work around that avoids this which can be
# used if GDB is connected to an older gdbserver without
# 'stat' support.
#
# Check the work around works by disabling use of the
- # vFile:stat packet.
+ # vFile:lstat packet.
foreach_with_prefix stat_pkt {auto off} {
clean_restart
@@ -105,7 +105,7 @@ proc load_binfile_check_debug_is_found { debuginfo_file testname } {
gdb_test_no_output "set sysroot target:"
- gdb_test "set remote hostio-stat-packet $stat_pkt"
+ gdb_test "set remote hostio-lstat-packet $stat_pkt"
# Make sure we're disconnected, in case we're testing with an
# extended-remote board, therefore already connected.
diff --git a/gdb/testsuite/gdb.server/fileio-packets.exp b/gdb/testsuite/gdb.server/fileio-packets.exp
new file mode 100644
index 0000000..9435efd
--- /dev/null
+++ b/gdb/testsuite/gdb.server/fileio-packets.exp
@@ -0,0 +1,66 @@
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test some remote file I/O. The associated Python script uses the
+# Python API to create and send vFile:* packets to gdbserver to
+# perform actions like 'stat'. The same action is then performed
+# directly from Python (e.g. a 'stat' is performed), and the results,
+# from gdbserver, and from the local syscall, are compared.
+
+load_lib gdb-python.exp
+load_lib gdbserver-support.exp
+
+require allow_python_tests
+require allow_gdbserver_tests
+require {!is_remote host}
+require {!is_remote target}
+
+standard_testfile
+
+clean_restart
+
+# Make sure we're disconnected, in case we're testing with an
+# extended-remote board, therefore already connected.
+gdb_test "disconnect" ".*"
+
+set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
+gdb_test_no_output "source $pyfile" "source the script"
+
+# Start gdbserver, but always in extended-remote mode, and then
+# connect to it from GDB.
+set res [gdbserver_start "--multi --once" ""]
+set gdbserver_protocol "extended-remote"
+set gdbserver_gdbport [lindex $res 1]
+gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
+
+gdb_test_no_output "set python print-stack full"
+
+set test_file_1 [standard_output_file "test_file_1"]
+remote_exec host "touch $test_file_1"
+
+set test_file_2 [standard_output_file "test_file_2"]
+remote_exec host "ln -s $test_file_1 $test_file_2"
+
+gdb_test "python check_lstat(\"$test_file_1\")" "PASS" \
+ "check remote lstat works on a normal file"
+
+gdb_test "python check_lstat(\"$test_file_2\")" "PASS" \
+ "check remote lstat works on a symbolic link"
+
+gdb_test "python check_stat(\"$test_file_1\")" "PASS" \
+ "check remote stat works on a normal file"
+
+gdb_test "python check_stat(\"$test_file_2\")" "PASS" \
+ "check remote stat works on a symbolic link"
diff --git a/gdb/testsuite/gdb.server/fileio-packets.py b/gdb/testsuite/gdb.server/fileio-packets.py
new file mode 100644
index 0000000..f132e91
--- /dev/null
+++ b/gdb/testsuite/gdb.server/fileio-packets.py
@@ -0,0 +1,208 @@
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import stat
+
+
+# Hex encode INPUT_STRING in the same way that GDB does. Each
+# character in INPUT_STRING is expanded to its two digit hex
+# representation in the returned string.
+#
+# Only ASCII characters may appear in INPUT_STRING, this is more
+# restrictive than GDB, but is good enough for testing.
+def hex_encode(input_string):
+ byte_string = input_string.encode("ascii")
+ hex_string = byte_string.hex()
+ return hex_string
+
+
+# Binary remote data packets can contain some escaped bytes. Decode
+# the packet now.
+def unescape_remote_data(buf):
+ escaped = False
+ res = bytearray()
+ for b in buf:
+ if escaped:
+ res.append(b ^ 0x20)
+ escaped = False
+ elif b == ord("}"):
+ escaped = True
+ else:
+ res.append(b)
+ res = bytes(res)
+ return res
+
+
+# Decode the results of a remote stat like command from BUF. Returns
+# None if BUF is not a valid stat result (e.g. if it indicates an
+# error, or the buffer is too short). If BUF is valid then the fields
+# are decoded according to the GDB remote protocol and placed into a
+# dictionary, this dictionary is then returned.
+def decode_stat_reply(buf, byteorder="big"):
+
+ buf = unescape_remote_data(buf)
+
+ if (
+ buf[0] != ord("F")
+ or buf[1] != ord("4")
+ or buf[2] != ord("0")
+ or buf[3] != ord(";")
+ or len(buf) != 68
+ ):
+ l = len(buf)
+ print(f"decode_stat_reply failed: {buf}\t(length = {l})")
+ return None
+
+ # Discard the 'F40;' prefix. The rest is the 64 bytes of data to
+ # be decoded.
+ buf = buf[4:]
+
+ st_dev = int.from_bytes(buf[0:4], byteorder=byteorder)
+ st_ino = int.from_bytes(buf[4:8], byteorder=byteorder)
+ st_mode = int.from_bytes(buf[8:12], byteorder=byteorder)
+ st_nlink = int.from_bytes(buf[12:16], byteorder=byteorder)
+ st_uid = int.from_bytes(buf[16:20], byteorder=byteorder)
+ st_gid = int.from_bytes(buf[20:24], byteorder=byteorder)
+ st_rdev = int.from_bytes(buf[24:28], byteorder=byteorder)
+ st_size = int.from_bytes(buf[28:36], byteorder=byteorder)
+ st_blksize = int.from_bytes(buf[36:44], byteorder=byteorder)
+ st_blocks = int.from_bytes(buf[44:52], byteorder=byteorder)
+ st_atime = int.from_bytes(buf[52:56], byteorder=byteorder)
+ st_mtime = int.from_bytes(buf[56:60], byteorder=byteorder)
+ st_ctime = int.from_bytes(buf[60:64], byteorder=byteorder)
+
+ return {
+ "st_dev": st_dev,
+ "st_ino": st_ino,
+ "st_mode": st_mode,
+ "st_nlink": st_nlink,
+ "st_uid": st_uid,
+ "st_gid": st_gid,
+ "st_rdev": st_rdev,
+ "st_size": st_size,
+ "st_blksize": st_blksize,
+ "st_blocks": st_blocks,
+ "st_atime": st_atime,
+ "st_mtime": st_mtime,
+ "st_ctime": st_ctime,
+ }
+
+
+# Perform an lstat of remote file FILENAME, and create a dictionary of
+# the results, the keys are the fields of the stat structure.
+def remote_lstat(filename):
+ conn = gdb.selected_inferior().connection
+ if not isinstance(conn, gdb.RemoteTargetConnection):
+ raise gdb.GdbError("connection is the wrong type")
+
+ filename_hex = hex_encode(filename)
+ reply = conn.send_packet("vFile:lstat:%s" % filename_hex)
+
+ stat = decode_stat_reply(reply)
+ return stat
+
+
+# Perform a stat of remote file FILENAME, and create a dictionary of
+# the results, the keys are the fields of the stat structure.
+def remote_stat(filename):
+ conn = gdb.selected_inferior().connection
+ if not isinstance(conn, gdb.RemoteTargetConnection):
+ raise gdb.GdbError("connection is the wrong type")
+
+ filename_hex = hex_encode(filename)
+ reply = conn.send_packet("vFile:stat:%s" % filename_hex)
+
+ stat = decode_stat_reply(reply)
+ return stat
+
+
+# Convert a stat_result object to a dictionary that should match the
+# dictionary built from the remote protocol reply.
+def stat_result_to_dict(res):
+ # GDB doesn't support the S_IFLNK flag for the remote protocol, so
+ # clear that flag in the local results.
+ if stat.S_ISLNK(res.st_mode):
+ st_mode = stat.S_IMODE(res.st_mode)
+ else:
+ st_mode = res.st_mode
+
+ # GDB returns an integer for these fields, while Python returns a
+ # floating point value. Convert back to an integer to match GDB.
+ st_atime = int(res.st_atime)
+ st_mtime = int(res.st_mtime)
+ st_ctime = int(res.st_ctime)
+
+ return {
+ "st_dev": res.st_dev,
+ "st_ino": res.st_ino,
+ "st_mode": st_mode,
+ "st_nlink": res.st_nlink,
+ "st_uid": res.st_uid,
+ "st_gid": res.st_gid,
+ "st_rdev": res.st_rdev,
+ "st_size": res.st_size,
+ "st_blksize": res.st_blksize,
+ "st_blocks": res.st_blocks,
+ "st_atime": st_atime,
+ "st_mtime": st_mtime,
+ "st_ctime": st_ctime,
+ }
+
+
+# Perform an lstat of local file FILENAME, and create a dictionary of
+# the results, the keys are the fields of the stat structure.
+def local_lstat(filename):
+ res = os.lstat(filename)
+ return stat_result_to_dict(res)
+
+
+# Perform an lstat of local file FILENAME, and create a dictionary of
+# the results, the keys are the fields of the stat structure.
+def local_stat(filename):
+ res = os.stat(filename)
+ return stat_result_to_dict(res)
+
+
+# Perform a remote lstat using GDB, and a local lstat using os.lstat.
+# Compare the results to check they are the same.
+#
+# For this test to work correctly, gdbserver, and GDB (where this
+# Python script is running), must see the same filesystem.
+def check_lstat(filename):
+ s1 = remote_lstat(filename)
+ s2 = local_lstat(filename)
+
+ print(f"remote = {s1}")
+ print(f"local = {s2}")
+
+ assert s1 == s2
+ print("PASS")
+
+
+# Perform a remote stat using GDB, and a local stat using os.stat.
+# Compare the results to check they are the same.
+#
+# For this test to work correctly, gdbserver, and GDB (where this
+# Python script is running), must see the same filesystem.
+def check_stat(filename):
+ s1 = remote_stat(filename)
+ s2 = local_stat(filename)
+
+ print(f"remote = {s1}")
+ print(f"local = {s2}")
+
+ assert s1 == s2
+ print("PASS")
diff --git a/gdb/testsuite/gdb.server/non-existing-program.exp b/gdb/testsuite/gdb.server/non-existing-program.exp
index 7119723..ec9c044 100644
--- a/gdb/testsuite/gdb.server/non-existing-program.exp
+++ b/gdb/testsuite/gdb.server/non-existing-program.exp
@@ -34,6 +34,8 @@ if { $gdbserver == "" } {
# to spawn the program before opening the connection.
set spawn_id [remote_spawn target "$gdbserver stdio non-existing-program"]
+set eol {[\r\n]}
+
set msg "gdbserver exits cleanly"
set saw_exiting 0
expect {
@@ -51,7 +53,7 @@ expect {
exp_continue
}
# This is what we get on Windows.
- -re "Error creating process\r\n\r\nExiting\r\n" {
+ -re "Error creating process.*$eol+Exiting$eol+" {
set saw_exiting 1
exp_continue
}
diff --git a/gdb/testsuite/gdb.server/pread-offset-size.S b/gdb/testsuite/gdb.server/pread-offset-size.S
new file mode 100644
index 0000000..6ca8cf0
--- /dev/null
+++ b/gdb/testsuite/gdb.server/pread-offset-size.S
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Here we are trying to create a large binary (> 2 GB),
+ 3742415472 bytes is about 3.5 gigabytes. */
+
+ .text
+ .globl _start
+_start:
+ .skip 3742415472
+ ret
+ .globl f
+ .type f, @function
+f:
+ ret
diff --git a/gdb/testsuite/gdb.server/pread-offset-size.exp b/gdb/testsuite/gdb.server/pread-offset-size.exp
new file mode 100644
index 0000000..54e67c5
--- /dev/null
+++ b/gdb/testsuite/gdb.server/pread-offset-size.exp
@@ -0,0 +1,49 @@
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Check that GDBserver's vFile::pread implementation is able to access
+# large files (> 2GB).
+
+load_lib gdbserver-support.exp
+
+require allow_gdbserver_tests
+
+standard_testfile .S
+
+if { [prepare_for_testing ${testfile}.exp $testfile \
+ $srcfile {debug additional_flags=-nostdlib} ] } {
+ return -1
+}
+
+clean_restart
+
+gdb_test_no_output "set remote exec-file $binfile" \
+ "set remote exec-file"
+
+# Make sure we're disconnected, in case we're testing with an
+# extended-remote board, therefore already connected.
+gdb_test "disconnect" ".*"
+
+set res [gdbserver_spawn ""]
+set gdbserver_protocol [lindex $res 0]
+set gdbserver_gdbport [lindex $res 1]
+
+gdb_test "target $gdbserver_protocol $gdbserver_gdbport" \
+ "Remote debugging using .*" \
+ "target $gdbserver_protocol"
+
+# If loading the large binary was successful, we should be able to
+# place a breakpoint on f.
+gdb_test "break f" "Breakpoint 1.*"
diff --git a/gdb/testsuite/gdb.stabs/weird.def b/gdb/testsuite/gdb.stabs/weird.def
index 179b126..f809963 100644
--- a/gdb/testsuite/gdb.stabs/weird.def
+++ b/gdb/testsuite/gdb.stabs/weird.def
@@ -294,7 +294,7 @@ attr69:
# Using double quotes requires an escaping, as the stabs string
# is a double quote delimited string.
.stabs "constString2:c=s\"Double quote String2\"", N_LSYM,0,0, 0
-# Escaping sinlge quote with is easy
+# Escaping single quote with is easy
.stabs "constString3:c=s'String3 with embedded quote \' in the middle'", N_LSYM,0,0, 0
# Esaping double quotes is less clear...
.stabs "constString4:c=s\"String4 with embedded quote \\" in the middle\"", N_LSYM,0,0, 0
diff --git a/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.exp b/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.exp
new file mode 100644
index 0000000..a05ce61
--- /dev/null
+++ b/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.exp
@@ -0,0 +1,84 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test gdb_test_multiple -lbl, particularly with patterns that share a
+# common prefix.
+
+standard_testfile
+
+clean_restart
+
+gdb_test_no_output "source ${srcdir}/${subdir}/$testfile.gdb" \
+ "source gdb test script"
+
+set saw_prompt 0
+set saw_prefix 0
+set saw_command 0
+set saw_prefix_foo 0
+set saw_prefix_bar 0
+
+# #1 - We need anchors so that the "prefix foo" pattern below does not
+# match when the expect output buffer contains:
+#
+# "\r\nprefix xxx\r\n\prefix foo\r\n"
+#
+# #2 - We need an anchor on the prompt match as otherwise the prompt
+# regexp would match:
+#
+# "\r\nmeant-to-be-matched-by-lbl-2\r\nprefix xxx\r\n(gdb) "
+#
+# This test would fail if -lbl did not force the built-in prompt match
+# regexp to have an anchor as well, as without it, the built-in prompt
+# regexp would have the exact same issue as #2 above.
+
+gdb_test_multiple "command" "" -lbl {
+ -re "^command(?=\r\n)" {
+ verbose -log <COMMAND>
+ incr saw_command
+ exp_continue
+ }
+ -re "^\r\nprefix foo(?=\r\n)" {
+ verbose -log <PREFIX-FOO>
+ incr saw_prefix_foo
+ exp_continue
+ }
+ -re "^\r\nprefix bar(?=\r\n)" {
+ verbose -log <PREFIX-BAR>
+ incr saw_prefix_bar
+ exp_continue
+ }
+ -re "^\r\nprefix \[^\r\n\]*(?=\r\n)" {
+ verbose -log <PREFIX>
+ incr saw_prefix
+ exp_continue
+ }
+ -re "^\r\n$gdb_prompt $" {
+ verbose -log <PROMPT>
+ incr saw_prompt
+ pass $gdb_test_name
+ }
+}
+
+verbose -log "saw_command: $saw_command"
+verbose -log "saw_prefix_foo: $saw_prefix_foo"
+verbose -log "saw_prefix_bar: $saw_prefix_bar"
+verbose -log "saw_prefix: $saw_prefix"
+verbose -log "saw_prompt: $saw_prompt"
+
+gdb_assert {$saw_command == 1}
+gdb_assert {$saw_prefix_foo == 1}
+gdb_assert {$saw_prefix_bar == 1}
+gdb_assert {$saw_prefix == 3}
+gdb_assert {$saw_prompt == 1}
diff --git a/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.gdb b/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.gdb
new file mode 100755
index 0000000..8c94dfa
--- /dev/null
+++ b/gdb/testsuite/gdb.testsuite/gdb_test_multiple-lbl.gdb
@@ -0,0 +1,25 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+define command
+ echo prefix xxx\n
+ echo meant-to-be-matched-by-lbl-1\n
+ echo prefix foo\n
+ echo prefix bar\n
+ echo meant-to-be-matched-by-lbl-2\n
+ echo prefix xxx\n
+ echo prefix xxx\n
+ echo meant-to-be-matched-by-lbl-3\n
+end
diff --git a/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp b/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp
index b41e3b2..fec31c3 100644
--- a/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp
+++ b/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp
@@ -74,42 +74,45 @@ proc test { non_stop } {
delete_breakpoints
# Start the second inferior.
- with_test_prefix "second inferior" {
- # With stub targets that do reload on run, if we let the new
- # inferior share inferior 1's connection, runto would
- # fail because GDB is already connected to something, like
- # e.g. with --target_board=native-gdbserver:
- #
- # (gdb) kill
- # ...
- # (gdb) target remote localhost:2348
- # Already connected to a remote target. Disconnect? (y or n)
- #
- # Instead, start the inferior with no connection, and let
- # gdb_load/runto spawn a new remote connection/gdbserver.
- #
- # OTOH, with extended-remote, we must let the new inferior
- # reuse the current connection, so that runto below can
- # issue the "run" command, and have the inferior run on the
- # remote target. If we forced no connection, then "run" would
- # either fail if "set auto-connect-native-target" is on, like
- # the native-extended-gdbserver board enforces, or it would
- # run the inferior on the native target, which isn't what is
- # being tested.
- #
- # Since it's reload_on_run targets that need special care, we
- # default to reusing the connection on most targets.
- if [target_info exists gdb,do_reload_on_run] {
- gdb_test "add-inferior -no-connection" "New inferior 2.*"
- } else {
- gdb_test "add-inferior" "New inferior 2.*"
- }
- gdb_test "inferior 2" "Switching to inferior 2 .*"
-
- gdb_load $binfile
-
- if ![runto setup_done] {
- return -1
+ if {[allow_multi_inferior_tests]} {
+ with_test_prefix "second inferior" {
+ # With stub targets that do reload on run, if we let the
+ # new inferior share inferior 1's connection, runto would
+ # fail because GDB is already connected to something, like
+ # e.g. with --target_board=native-gdbserver:
+ #
+ # (gdb) kill
+ # ...
+ # (gdb) target remote localhost:2348
+ # Already connected to a remote target. Disconnect? (y or n)
+ #
+ # Instead, start the inferior with no connection, and let
+ # gdb_load/runto spawn a new remote connection/gdbserver.
+ #
+ # OTOH, with extended-remote, we must let the new inferior
+ # reuse the current connection, so that runto below can
+ # issue the "run" command, and have the inferior run on
+ # the remote target. If we forced no connection, then
+ # "run" would either fail if "set
+ # auto-connect-native-target" is on, like the
+ # native-extended-gdbserver board enforces, or it would
+ # run the inferior on the native target, which isn't what
+ # is being tested.
+ #
+ # Since it's reload_on_run targets that need special care,
+ # we default to reusing the connection on most targets.
+ if [target_info exists gdb,do_reload_on_run] {
+ gdb_test "add-inferior -no-connection" "New inferior 2.*"
+ } else {
+ gdb_test "add-inferior" "New inferior 2.*"
+ }
+ gdb_test "inferior 2" "Switching to inferior 2 .*"
+
+ gdb_load $binfile
+
+ if ![runto setup_done] {
+ return -1
+ }
}
}
@@ -158,13 +161,15 @@ proc test { non_stop } {
verbose -log "xxxxx: iteration $iter"
gdb_test -nopass "info threads"
- if {$inf == 1} {
- set inf 2
- } else {
- set inf 1
- }
+ if {[allow_multi_inferior_tests]} {
+ if {$inf == 1} {
+ set inf 2
+ } else {
+ set inf 1
+ }
- my_gdb_test "inferior $inf" ".*" "inferior $inf"
+ my_gdb_test "inferior $inf" ".*" "inferior $inf"
+ }
my_gdb_test "print global_var = 555" " = 555" \
"write to global_var"
diff --git a/gdb/testsuite/gdb.threads/corethreads.exp b/gdb/testsuite/gdb.threads/corethreads.exp
index 3b50ae3..0011dc3 100644
--- a/gdb/testsuite/gdb.threads/corethreads.exp
+++ b/gdb/testsuite/gdb.threads/corethreads.exp
@@ -29,6 +29,7 @@ if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executa
set corefile [core_find $binfile]
if {$corefile == ""} {
+ untested "unable to create or find corefile"
return 0
}
diff --git a/gdb/testsuite/gdb.threads/current-lwp-dead.exp b/gdb/testsuite/gdb.threads/current-lwp-dead.exp
index 7aa7ab9..c8364df 100644
--- a/gdb/testsuite/gdb.threads/current-lwp-dead.exp
+++ b/gdb/testsuite/gdb.threads/current-lwp-dead.exp
@@ -47,6 +47,6 @@ gdb_breakpoint $line
gdb_continue_to_breakpoint "fn_return" ".*at-fn_return.*"
# Confirm thread 2 is really gone.
-gdb_test "info threads 2" "No threads match '2'\\."
+gdb_test "info threads 2" "No threads matched\\."
gdb_continue_to_end "" continue 1
diff --git a/gdb/testsuite/gdb.threads/detach-step-over.exp b/gdb/testsuite/gdb.threads/detach-step-over.exp
index e48b83c..8a1cb29 100644
--- a/gdb/testsuite/gdb.threads/detach-step-over.exp
+++ b/gdb/testsuite/gdb.threads/detach-step-over.exp
@@ -50,6 +50,8 @@
require can_spawn_for_attach
+require allow_multi_inferior_tests
+
standard_testfile
set bp_lineno [gdb_get_line_number "Set breakpoint here"]
diff --git a/gdb/testsuite/gdb.threads/foll-fork-other-thread.exp b/gdb/testsuite/gdb.threads/foll-fork-other-thread.exp
index 5245988..8ab540c 100644
--- a/gdb/testsuite/gdb.threads/foll-fork-other-thread.exp
+++ b/gdb/testsuite/gdb.threads/foll-fork-other-thread.exp
@@ -17,6 +17,8 @@
# another thread, in different combinations of "set follow-fork
# parent/child", and other execution modes.
+require allow_fork_tests
+
standard_testfile
# Line where to stop the main thread.
diff --git a/gdb/testsuite/gdb.threads/fork-child-threads.exp b/gdb/testsuite/gdb.threads/fork-child-threads.exp
index abe9769..ba9dfc2 100644
--- a/gdb/testsuite/gdb.threads/fork-child-threads.exp
+++ b/gdb/testsuite/gdb.threads/fork-child-threads.exp
@@ -13,10 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# Only GNU/Linux is known to support `set follow-fork-mode child'.
-if { ! [istarget "*-*-linux*"] } {
- return 0
-}
+require allow_fork_tests
standard_testfile
diff --git a/gdb/testsuite/gdb.threads/fork-plus-threads.exp b/gdb/testsuite/gdb.threads/fork-plus-threads.exp
index 3a5e66a..4ce88d3 100644
--- a/gdb/testsuite/gdb.threads/fork-plus-threads.exp
+++ b/gdb/testsuite/gdb.threads/fork-plus-threads.exp
@@ -20,6 +20,8 @@
#
# See https://sourceware.org/bugzilla/show_bug.cgi?id=18600
+require allow_fork_tests
+
# In remote mode, we cannot continue debugging after all
# inferiors have terminated, and this test requires that.
if { [target_info exists gdb_protocol]
diff --git a/gdb/testsuite/gdb.threads/fork-thread-pending.exp b/gdb/testsuite/gdb.threads/fork-thread-pending.exp
index d0a1ca1..538e1ca 100644
--- a/gdb/testsuite/gdb.threads/fork-thread-pending.exp
+++ b/gdb/testsuite/gdb.threads/fork-thread-pending.exp
@@ -13,11 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# Only GNU/Linux is known to support `set follow-fork-mode child'.
-#
-if { ! [istarget "*-*-linux*"] } {
- return 0
-}
+require allow_fork_tests
standard_testfile
diff --git a/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp b/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp
index 1f76898..c668a65 100644
--- a/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp
+++ b/gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp
@@ -16,6 +16,8 @@
# This test verifies that several threads forking while another thread
# is constantly stepping over a breakpoint is properly handled.
+require allow_fork_tests
+
standard_testfile
set linenum [gdb_get_line_number "set break here"]
diff --git a/gdb/testsuite/gdb.threads/info-threads-options.c b/gdb/testsuite/gdb.threads/info-threads-options.c
new file mode 100644
index 0000000..2c4cd85
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/info-threads-options.c
@@ -0,0 +1,77 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2022-2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+#define NUM 4
+
+static pthread_barrier_t threads_started_barrier;
+
+static void
+stop_here ()
+{
+}
+
+static void
+spin ()
+{
+ while (1)
+ usleep (1);
+}
+
+static void *
+work (void *arg)
+{
+ int id = *(int *) arg;
+
+ pthread_barrier_wait (&threads_started_barrier);
+
+ if (id % 2 == 0)
+ stop_here ();
+ else
+ spin ();
+
+ pthread_exit (NULL);
+}
+
+int
+main ()
+{
+ /* Ensure we stop if GDB crashes and DejaGNU fails to kill us. */
+ alarm (10);
+
+ pthread_t threads[NUM];
+ int ids[NUM];
+
+ pthread_barrier_init (&threads_started_barrier, NULL, NUM + 1);
+
+ for (int i = 0; i < NUM; i++)
+ {
+ ids[i] = i;
+ pthread_create (&threads[i], NULL, work, &ids[i]);
+ }
+
+ /* Wait until all threads are seen running. */
+ pthread_barrier_wait (&threads_started_barrier);
+
+ stop_here ();
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.threads/info-threads-options.exp b/gdb/testsuite/gdb.threads/info-threads-options.exp
new file mode 100644
index 0000000..38e4e67
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/info-threads-options.exp
@@ -0,0 +1,131 @@
+# Copyright (C) 2022-2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test the filter flags of the "info threads" command.
+
+standard_testfile
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
+ executable debug] != "" } {
+ return -1
+}
+
+save_vars { GDBFLAGS } {
+ append GDBFLAGS " -ex \"set non-stop on\""
+ clean_restart $binfile
+}
+
+if ![runto_main] {
+ return -1
+}
+
+gdb_breakpoint "stop_here"
+gdb_test_multiple "continue -a&" "" {
+ -re "Continuing.\r\n$gdb_prompt " {
+ pass $gdb_test_name
+ }
+}
+
+set expected_hits 3
+set fill "\[^\r\n\]+"
+set num_hits 0
+gdb_test_multiple "" "hit the breakpoint" -lbl {
+ -re "\r\nThread ${fill} hit Breakpoint ${decimal}," {
+ incr num_hits
+ if {$num_hits < $expected_hits} {
+ exp_continue
+ }
+ }
+}
+gdb_assert {$num_hits == $expected_hits} "expected threads hit the bp"
+
+# Count the number of running/stopped threads reported
+# by the "info threads" command. We also capture thread ids
+# for additional tests.
+set running_tid "invalid"
+set stopped_tid "invalid"
+
+set eol "(?=\r\n)"
+
+foreach_with_prefix flag {"" "-running" "-stopped" "-running -stopped"} {
+ set num_running 0
+ set num_stopped 0
+ gdb_test_multiple "info threads $flag" "info threads $flag" -lbl {
+ -re "Id${fill}Target Id${fill}Frame${fill}${eol}" {
+ exp_continue
+ }
+ -re "^\r\n. (${decimal})${fill}Thread ${fill}.running.${eol}" {
+ incr num_running
+ set running_tid $expect_out(1,string)
+ exp_continue
+ }
+ -re "^\r\n. (${decimal})${fill}Thread ${fill}stop_here ${fill}${eol}" {
+ incr num_stopped
+ set stopped_tid $expect_out(1,string)
+ exp_continue
+ }
+ -re "^\r\n$gdb_prompt $" {
+ pass $gdb_test_name
+ }
+ }
+
+ if {$flag eq "-running"} {
+ gdb_assert {$num_running == 2} "num running"
+ gdb_assert {$num_stopped == 0} "num stopped"
+ } elseif {$flag eq "-stopped"} {
+ gdb_assert {$num_running == 0} "num running"
+ gdb_assert {$num_stopped == 3} "num stopped"
+ } else {
+ gdb_assert {$num_running == 2} "num running"
+ gdb_assert {$num_stopped == 3} "num stopped"
+ }
+}
+
+verbose -log "running_tid=$running_tid, stopped_tid=$stopped_tid"
+
+# Test specifying thread ids.
+gdb_test "info threads -running $stopped_tid" \
+ "No threads matched\\." \
+ "info thread -running for a stopped thread"
+gdb_test "info threads -stopped $running_tid" \
+ "No threads matched\\." \
+ "info thread -stopped for a running thread"
+
+set ws "\[ \t\]+"
+foreach tid "\"$running_tid\" \"$running_tid $stopped_tid\"" {
+ gdb_test "info threads -running $tid" \
+ [multi_line \
+ "${ws}Id${ws}Target Id${ws}Frame${ws}" \
+ "${ws}${running_tid}${ws}Thread ${fill}.running."] \
+ "info thread -running with [llength $tid] thread ids"
+}
+
+foreach tid "\"$stopped_tid\" \"$stopped_tid $running_tid\"" {
+ gdb_test "info threads -stopped $tid" \
+ [multi_line \
+ "${ws}Id${ws}Target Id${ws}Frame${ws}" \
+ "${ws}${stopped_tid}${ws}Thread ${fill} stop_here ${fill}"] \
+ "info thread -stopped with [llength $tid] thread ids"
+}
+
+gdb_test_multiple "info threads -stopped -running $stopped_tid $running_tid" \
+ "filter flags and tids combined" {
+ -re -wrap ".*stop_here.*running.*" {
+ pass $gdb_test_name
+ }
+ -re -wrap ".*running.*stop_here.*" {
+ pass $gdb_test_name
+ }
+}
diff --git a/gdb/testsuite/gdb.threads/next-fork-exec-other-thread.exp b/gdb/testsuite/gdb.threads/next-fork-exec-other-thread.exp
index bd81438..3a97127 100644
--- a/gdb/testsuite/gdb.threads/next-fork-exec-other-thread.exp
+++ b/gdb/testsuite/gdb.threads/next-fork-exec-other-thread.exp
@@ -25,6 +25,8 @@
# 20.04.5 LTS with 32-bit kernel + 32-bit userland. It was NOT reproducible
# using a circa 2023 Raspberry Pi OS w/ 64-bit kernel and 32-bit userland.
+require allow_fork_tests
+
standard_testfile
# Line where to stop the main thread.
diff --git a/gdb/testsuite/gdb.threads/next-fork-other-thread.exp b/gdb/testsuite/gdb.threads/next-fork-other-thread.exp
index 183fda6..1cd6685 100644
--- a/gdb/testsuite/gdb.threads/next-fork-other-thread.exp
+++ b/gdb/testsuite/gdb.threads/next-fork-other-thread.exp
@@ -16,6 +16,8 @@
# Test doing a "next" on a thread during which forks or vforks happen in other
# threads.
+require allow_fork_tests
+
standard_testfile
# Line where to stop the main thread.
diff --git a/gdb/testsuite/gdb.threads/pending-fork-event-detach-ns.exp b/gdb/testsuite/gdb.threads/pending-fork-event-detach-ns.exp
index e6e311e..29a011e 100644
--- a/gdb/testsuite/gdb.threads/pending-fork-event-detach-ns.exp
+++ b/gdb/testsuite/gdb.threads/pending-fork-event-detach-ns.exp
@@ -29,6 +29,8 @@
# parent thread from waitpid'ing it, preventing the main thread from joining
# it, prevent it from writing the flag file, failing the test.
+require allow_fork_tests
+
standard_testfile
if { [is_remote target] } {
diff --git a/gdb/testsuite/gdb.threads/pending-fork-event-detach.exp b/gdb/testsuite/gdb.threads/pending-fork-event-detach.exp
index 8e77ab0..e627241 100644
--- a/gdb/testsuite/gdb.threads/pending-fork-event-detach.exp
+++ b/gdb/testsuite/gdb.threads/pending-fork-event-detach.exp
@@ -34,6 +34,8 @@
# event, and erroneously create a new inferior for it. Once fixed, the child
# process' thread is hidden by whoever holds the pending fork event.
+require allow_fork_tests
+
standard_testfile .c -touch-file.c
set touch_file_bin $binfile-touch-file
diff --git a/gdb/testsuite/gdb.threads/thread-bp-deleted.exp b/gdb/testsuite/gdb.threads/thread-bp-deleted.exp
index 2eadd38..8cabb70 100644
--- a/gdb/testsuite/gdb.threads/thread-bp-deleted.exp
+++ b/gdb/testsuite/gdb.threads/thread-bp-deleted.exp
@@ -147,7 +147,7 @@ if {$is_remote} {
exp_continue
}
- -re "No threads match '99'\\.\r\n$gdb_prompt $" {
+ -re "No threads matched\\.\r\n$gdb_prompt $" {
if {!$saw_thread_exited && !$saw_bp_deleted && $attempt_count > 0} {
sleep 1
incr attempt_count -1
diff --git a/gdb/testsuite/gdb.threads/thread-execl.c b/gdb/testsuite/gdb.threads/thread-execl.c
index 403aa31..2d312d4 100644
--- a/gdb/testsuite/gdb.threads/thread-execl.c
+++ b/gdb/testsuite/gdb.threads/thread-execl.c
@@ -25,8 +25,9 @@ static const char *image;
void *
thread_execler (void *arg)
{
- /* Exec ourselves again. */
- if (execl (image, image, NULL) == -1)
+ /* Exec ourselves again. Pass an extra argument so that the
+ post-exec image knows to not re-exec yet again. */
+ if (execl (image, image, "1", NULL) == -1)
{
perror ("execl");
abort ();
@@ -40,6 +41,11 @@ main (int argc, char **argv)
{
pthread_t thread;
+ /* An extra argument means we're in the post-exec image, so we're
+ done. Don't re-exec again. */
+ if (argc > 1)
+ exit (0);
+
image = argv[0];
pthread_create (&thread, NULL, thread_execler, NULL);
diff --git a/gdb/testsuite/gdb.threads/threadapply.exp b/gdb/testsuite/gdb.threads/threadapply.exp
index c53db79..9110617 100644
--- a/gdb/testsuite/gdb.threads/threadapply.exp
+++ b/gdb/testsuite/gdb.threads/threadapply.exp
@@ -224,6 +224,8 @@ proc kill_and_remove_inferior {thread_set} {
# Test both "all" and a thread list, because those are implemented as
# different commands in GDB.
-foreach_with_prefix thread_set {"all" "1.1"} {
- kill_and_remove_inferior $thread_set
+if {[allow_multi_inferior_tests]} {
+ foreach_with_prefix thread_set {"all" "1.1"} {
+ kill_and_remove_inferior $thread_set
+ }
}
diff --git a/gdb/testsuite/gdb.threads/vfork-follow-child-exec.exp b/gdb/testsuite/gdb.threads/vfork-follow-child-exec.exp
index e23db0a..0b95a75 100644
--- a/gdb/testsuite/gdb.threads/vfork-follow-child-exec.exp
+++ b/gdb/testsuite/gdb.threads/vfork-follow-child-exec.exp
@@ -16,6 +16,8 @@
# Test following a vfork child that execs, when the vfork parent is a
# threaded program, and it's a non-main thread that vforks.
+require allow_fork_tests
+
standard_testfile
if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}]} {
diff --git a/gdb/testsuite/gdb.threads/vfork-follow-child-exit.exp b/gdb/testsuite/gdb.threads/vfork-follow-child-exit.exp
index a6b7f49..ced52df 100644
--- a/gdb/testsuite/gdb.threads/vfork-follow-child-exit.exp
+++ b/gdb/testsuite/gdb.threads/vfork-follow-child-exit.exp
@@ -16,6 +16,8 @@
# Test following a vfork child that exits, when the vfork parent is a
# threaded program, and it's a non-main thread that vforks.
+require allow_fork_tests
+
standard_testfile
if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}]} {
diff --git a/gdb/testsuite/gdb.threads/vfork-multi-inferior.exp b/gdb/testsuite/gdb.threads/vfork-multi-inferior.exp
index fd081b3..1f87427 100644
--- a/gdb/testsuite/gdb.threads/vfork-multi-inferior.exp
+++ b/gdb/testsuite/gdb.threads/vfork-multi-inferior.exp
@@ -25,6 +25,10 @@
# To catch the bug, this test verifies that we can hit a breakpoint after a
# vfork call, while a second inferior runs in the background.
+require allow_fork_tests
+
+require allow_multi_inferior_tests
+
require !use_gdb_stub
standard_testfile .c -sleep.c
diff --git a/gdb/testsuite/gdb.threads/vfork-multi-thread.exp b/gdb/testsuite/gdb.threads/vfork-multi-thread.exp
index 2b9294d..61811ae 100644
--- a/gdb/testsuite/gdb.threads/vfork-multi-thread.exp
+++ b/gdb/testsuite/gdb.threads/vfork-multi-thread.exp
@@ -30,6 +30,8 @@
# breakpoints are removed, so the main thread would miss the breakpoint and run
# until exit.
+require allow_fork_tests
+
standard_testfile
if { [build_executable "failed to prepare" ${testfile} ${srcfile} {debug pthreads}] } {
diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.exp b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
index 376ca2a..8e9b1c3 100644
--- a/gdb/testsuite/gdb.threads/watchpoint-fork.exp
+++ b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
@@ -21,6 +21,8 @@
# must be done before starting the test so as to not disrupt the execution
# of the actual test.
+require allow_fork_tests
+
set allow_hw_watchpoint_tests_p [allow_hw_watchpoint_tests]
set testfile watchpoint-fork
diff --git a/gdb/testsuite/gdb.trace/tspeed.exp b/gdb/testsuite/gdb.trace/tspeed.exp
index 25862bf..be7f37e 100644
--- a/gdb/testsuite/gdb.trace/tspeed.exp
+++ b/gdb/testsuite/gdb.trace/tspeed.exp
@@ -17,7 +17,7 @@ load_lib "trace-support.exp"
require allow_shlib_tests
-# Do not run if gdbsever debug is enabled - the output file is many Gb.
+# Do not run if gdbserver debug is enabled - the output file is many Gb.
if [gdbserver_debug_enabled] {
return 0
}
diff --git a/gdb/testsuite/gdb.tui/basic.exp b/gdb/testsuite/gdb.tui/basic.exp
index 35c99bd..8ecc91a 100644
--- a/gdb/testsuite/gdb.tui/basic.exp
+++ b/gdb/testsuite/gdb.tui/basic.exp
@@ -112,5 +112,9 @@ set re_noattr "\[^<\]"
set status_window_line 15
set status [Term::get_line_with_attrs $status_window_line]
-gdb_assert { [regexp "^<reverse:1>$re_noattr*<reverse:0>$" $status] == 1} \
+verbose -log "status line: '$status'"
+
+# The status line uses standout, which may translate to different attributes
+# depending on the terminal settings. Just check for at least one attribute.
+gdb_assert { [regexp "^<.*>(exec|extended-r)" $status] == 1 } \
"status window: reverse"
diff --git a/gdb/testsuite/gdb.tui/color-prompt.exp b/gdb/testsuite/gdb.tui/color-prompt.exp
index a95b24a..af6e467 100644
--- a/gdb/testsuite/gdb.tui/color-prompt.exp
+++ b/gdb/testsuite/gdb.tui/color-prompt.exp
@@ -15,18 +15,16 @@
# Check using a prompt with color in TUI.
+require allow_tui_tests
+
tuiterm_env
Term::clean_restart 24 80
-# Set colored prompt.
if {![Term::enter_tui]} {
unsupported "TUI not supported"
return
}
-Term::command "set prompt \\033\[31m(gdb) \\033\[0m"
-
-set line [Term::get_line_with_attrs $Term::_cur_row]
-gdb_assert { [regexp "^<fg:red>$gdb_prompt <fg:default> *$" $line] } \
- "prompt with color"
+set tui 1
+source $srcdir/$subdir/color-prompt.exp.tcl
diff --git a/gdb/testsuite/gdb.tui/color-prompt.exp.tcl b/gdb/testsuite/gdb.tui/color-prompt.exp.tcl
new file mode 100644
index 0000000..e6f4d3b
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/color-prompt.exp.tcl
@@ -0,0 +1,80 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check using a prompt with color in TUI ($tui == 0) or CLI ($tui == 0).
+
+set csi [string cat {\033} "\["]
+set rl_prompt_start_ignore {\001}
+set rl_prompt_end_ignore {\002}
+
+foreach_with_prefix rl_prompt_start_end_ignore { 0 1 } {
+ set color_on [string cat $csi 31m]
+ set color_off [string cat $csi 0m]
+
+ if { $rl_prompt_start_end_ignore } {
+ set color_on \
+ [string cat \
+ $rl_prompt_start_ignore \
+ $color_on \
+ $rl_prompt_end_ignore]
+ set color_off \
+ [string cat \
+ $rl_prompt_start_ignore \
+ $color_off \
+ $rl_prompt_end_ignore]
+ }
+
+ # Set prompt with color.
+ set prompt "${color_on}(gdb) $color_off"
+ Term::command "set prompt $prompt"
+
+ # Check the color.
+ set line [Term::get_line_with_attrs $Term::_cur_row]
+ gdb_assert { [regexp "^<fg:red>$gdb_prompt <fg:default> *$" $line] } \
+ "prompt with color"
+
+ # Type a string.
+ set cmd "some long command"
+ send_gdb $cmd
+ Term::wait_for_line ^[string_to_regexp "(gdb) $cmd"] 23
+
+ # Send ^A, aka C-a, trigger beginning-of-line.
+ send_gdb "\001"
+ if { $tui || $rl_prompt_start_end_ignore } {
+ Term::wait_for_line ^[string_to_regexp "(gdb) $cmd"] 6
+ } else {
+ # Without the markers, readline may get the cursor position wrong, so
+ # match less strict.
+ Term::wait_for_line ^[string_to_regexp "(gdb) $cmd"]
+ }
+ Term::dump_screen
+
+ # Type something else to flush out the effect of the ^A.
+ set prefix "A"
+ send_gdb $prefix
+ if { $tui || $rl_prompt_start_end_ignore } {
+ Term::wait_for_line ^[string_to_regexp "(gdb) $prefix$cmd"] 7
+ } else {
+ # Without the markers, readline may get the cursor position wrong, so
+ # match less strict.
+ Term::wait_for_line [string_to_regexp "$prefix"]
+ }
+
+ # Abort command line editing, and regenerate prompt.
+ send_gdb "\003"
+
+ # Reset prompt to default prompt.
+ Term::command "set prompt (gdb) "
+}
diff --git a/gdb/testsuite/gdb.tui/esc-match.exp b/gdb/testsuite/gdb.tui/esc-match.exp
new file mode 100644
index 0000000..db78ebe
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/esc-match.exp
@@ -0,0 +1,48 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test that the ANSI escape sequence matcher works
+# character-by-character.
+
+load_lib gdb-python.exp
+require allow_python_tests allow_tui_tests
+
+tuiterm_env
+
+Term::clean_restart 24 80
+
+set remote_python_file [gdb_remote_download host \
+ ${srcdir}/${subdir}/esc-match.py]
+gdb_test_no_output "source ${remote_python_file}" \
+ "source esc-match.py"
+
+if {![Term::enter_tui]} {
+ unsupported "TUI not supported"
+ return
+}
+
+Term::command "python print_it()"
+
+Term::dump_screen
+
+set text [Term::get_all_lines]
+# We should not see the control sequence here.
+gdb_assert {![regexp -- "\\\[35;1mOUTPUT\\\[m" $text]} \
+ "output visible without control sequences"
+
+# Also check the styling.
+set text [Term::get_region 0 1 78 23 "\n" true]
+gdb_assert {[regexp -- "<fg:magenta>.*OUTPUT" $text]} \
+ "output is magenta"
diff --git a/gdb/testsuite/gdb.tui/esc-match.py b/gdb/testsuite/gdb.tui/esc-match.py
new file mode 100644
index 0000000..7816002
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/esc-match.py
@@ -0,0 +1,26 @@
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+
+# Some text to print that includes styling.
+OUT = "\033[35;1mOUTPUT\033[m"
+
+
+def print_it():
+ # Print to stderr avoids any buffering, showing the bug.
+ for c in OUT:
+ print(c, end="", file=sys.stderr)
+ print(file=sys.stderr)
diff --git a/gdb/testsuite/gdb.tui/gdb.tcl b/gdb/testsuite/gdb.tui/gdb.tcl
new file mode 100755
index 0000000..ca207ed
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/gdb.tcl
@@ -0,0 +1,20 @@
+#!/usr/bin/env tclsh
+
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+puts "foo\033(%5"
+
+gets stdin
diff --git a/gdb/testsuite/gdb.tui/main-2.exp b/gdb/testsuite/gdb.tui/main-2.exp
index 2b0fb6b..14a7cb1 100644
--- a/gdb/testsuite/gdb.tui/main-2.exp
+++ b/gdb/testsuite/gdb.tui/main-2.exp
@@ -41,7 +41,7 @@ if {![Term::enter_tui]} {
set line " return 0;"
set nr [gdb_get_line_number $line]
-set screen_line [Term::get_line_with_attrs 6]
+set screen_line [Term::get_string_with_attrs 6 11 79]
verbose -log "screen line 6: '$screen_line'"
-gdb_assert { [regexp "$nr <reverse:1>$line<reverse:0>" $screen_line] } \
+gdb_assert { [regexp "<reverse:1>$line<reverse:0>" $screen_line] } \
"highlighted line in middle of source window"
diff --git a/gdb/testsuite/gdb.tui/main.exp b/gdb/testsuite/gdb.tui/main.exp
index d6960c7..e49da35 100644
--- a/gdb/testsuite/gdb.tui/main.exp
+++ b/gdb/testsuite/gdb.tui/main.exp
@@ -43,7 +43,10 @@ if {![Term::enter_tui]} {
}
send_gdb "file [standard_output_file $testfile]\n"
-gdb_assert { [Term::wait_for "Reading symbols from"] } "file command"
+# Matching the output is difficult because it may or may not wrap. Simply
+# match the resulting prompt.
+gdb_assert { [Term::wait_for ""] } "file command"
+
Term::check_contents "show main after file" \
[string_to_regexp "|___[format %06d $nr]_$line"]
diff --git a/gdb/testsuite/gdb.tui/new-layout.exp b/gdb/testsuite/gdb.tui/new-layout.exp
index f517997..914e10c 100644
--- a/gdb/testsuite/gdb.tui/new-layout.exp
+++ b/gdb/testsuite/gdb.tui/new-layout.exp
@@ -150,4 +150,7 @@ Term::check_box "before cmd_only: src box in src layout" 0 0 80 15
Term::command "layout cmd_only"
Term::command "layout src"
+
+# Flush out and check the resulting src box.
+Term::command "print 1"
Term::check_box "after cmd_only: src box in src layout" 0 0 80 15
diff --git a/gdb/testsuite/gdb.tui/pr30056.exp b/gdb/testsuite/gdb.tui/pr30056.exp
index 1123593..dd3b25c 100644
--- a/gdb/testsuite/gdb.tui/pr30056.exp
+++ b/gdb/testsuite/gdb.tui/pr30056.exp
@@ -72,16 +72,15 @@ save_vars { env(LC_ALL) } {
# Send ^C to clear the command line.
send_gdb "\003"
} else {
- # Sending ^C currently doesn't abort the i-search. PR cli/30498 is
- # open about this.
- kfail cli/30498 $test
+ # Sending ^C currently doesn't abort the i-search.
+ fail $test
- # At this point we don't have a reponsive prompt. Send ^G to abort
+ # At this point we don't have a responsive prompt. Send ^G to abort
# the i-search.
send_gdb "\007"
}
- # We need a reponsive prompt here, to deal with the "monitor exit"
+ # We need a responsive prompt here, to deal with the "monitor exit"
# that native-extended-gdbserver will send. Check that we have a
# responsive prompt.
Term::command "echo \\n"
diff --git a/gdb/testsuite/gdb.tui/source-search.c b/gdb/testsuite/gdb.tui/source-search.c
new file mode 100644
index 0000000..2320c5c
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/source-search.c
@@ -0,0 +1,127 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+int
+main (void)
+{
+ /* Line 21 */
+ /* Line 22 */
+ /* Line 23 */
+ /* Line 24 */
+ /* Line 25 */
+ /* Line 26 */
+ /* Line 27 */
+ /* Line 28 */
+ /* Line 29 */
+ /* Line 30 */
+ /* Line 31 */
+ /* Line 32 */
+ /* Line 33 */
+ /* Line 34 */
+ /* Line 35 */
+ /* Line 36 */
+ /* Line 37 */
+ /* Line 38 */
+ /* Line 39 */
+ /* Line 40 */
+ /* Line 41 */
+ /* Line 42 */
+ /* Line 43 */
+ /* Line 44 */
+ /* Line 45 */
+ /* Line 46 */
+ /* Line 47 */
+ /* Line 48 */
+ /* Line 49 */
+ /* Line 50 */
+ /* Line 51 */
+ /* Line 52 */
+ /* Line 53 */
+ /* Line 54 */
+ /* Line 55 */
+ /* Line 56 */
+ /* Line 57 */
+ /* Line 58 */
+ /* Line 59 */
+ /* Line 60 */
+ /* Line 61 */
+ /* Line 62 */
+ /* Line 63 */
+ /* Line 64 */
+ /* Line 65 */
+ /* Line 66 */
+ /* Line 67 */
+ /* Line 68 */
+ /* Line 69 */
+ /* Line 70 */
+ /* Line 71 */
+ /* Line 72 */
+ /* Line 73 */
+ /* Line 74 */
+ /* Line 75 */
+ /* Line 76 */
+ /* Line 77 */
+ /* Line 78 */
+ /* Line 79 */
+ /* Line 80 */
+ /* Line 81 */
+ /* Line 82 */
+ /* Line 83 */
+ /* Line 84 */
+ /* Line 85 */
+ /* Line 86 */
+ /* Line 87 */
+ /* Line 88 */
+ /* Line 89 */
+ /* Line 90 */
+ /* Line 91 */
+ /* Line 92 */
+ /* Line 93 */
+ /* Line 94 */
+ /* Line 95 */
+ /* Line 96 */
+ /* Line 97 */
+ /* Line 98 */
+ /* Line 99 */
+ /* Line 100 */
+ /* Line 101 */
+ /* Line 102 */
+ /* Line 103 */
+ /* Line 104 */
+ /* Line 105 */
+ /* Line 106 */
+ /* Line 107 */
+ /* Line 108 */
+ /* Line 109 */
+ /* Line 110 */
+ /* Line 111 */
+ /* Line 112 */
+ /* Line 113 */
+ /* Line 114 */
+ /* Line 115 */
+ /* Line 116 */
+ /* Line 117 */
+ /* Line 118 */
+ /* Line 119 */
+ /* Line 120 */
+ /* Line 121 */
+ /* Line 122 */
+ /* Line 123 */
+ /* Line 124 */
+ /* Line 125 */
+ return 0;
+} /* Last line. */
diff --git a/gdb/testsuite/gdb.tui/source-search.exp b/gdb/testsuite/gdb.tui/source-search.exp
new file mode 100644
index 0000000..41bf121
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/source-search.exp
@@ -0,0 +1,72 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test forward-search and reverse-search within the TUI src window.
+
+tuiterm_env
+
+standard_testfile .c
+
+if {[build_executable "failed to build" ${testfile} ${srcfile}] == -1} {
+ return
+}
+
+Term::clean_restart 24 80 $testfile
+if {![Term::enter_tui]} {
+ unsupported "TUI not supported"
+ return
+}
+
+proc check_src_window { testname first_line } {
+ set last_line [expr $first_line + 12]
+ Term::check_box_contents $testname 0 0 80 15 \
+ "^\\s+${first_line}\\s+.*\\s+${last_line}\\s+/\\* Line ${last_line} \\*/\\s+$"
+
+}
+
+# Initialise the src window so that it is displaying known contents.
+# Check that the expected contents are displayed.
+Term::command "list 20"
+set first_line 15
+check_src_window "initial src contents" $first_line
+
+# Search forward. Searches are from the last line displayed, so this
+# will move the next source line onto the screen each time.
+for { set i 1 } { $i < 4 } { incr i } {
+ incr first_line
+ Term::command "forward-search Line"
+ check_src_window "src windows after forward-search $i" $first_line
+}
+
+# Reverse search. Like forward-search, but move backward through the
+# source.
+for { set i 1 } { $i < 3 } { incr i } {
+ incr first_line -1
+ Term::command "reverse-search Line"
+ check_src_window "src windows after reverse-search $i" $first_line
+}
+
+# Until there are no matching lines left.
+Term::command "reverse-search Line"
+gdb_assert {[regexp -- "^Expression not found\\s+$" [Term::get_line 22]]} \
+ "check start of source was reached"
+
+Term::command "forward-search Last line"
+Term::check_box_contents "forward-search to end of file" 0 0 80 15 \
+ "^\\s+122\\s+.*/\\* Last line\\. \\*/\\s+$"
+
+Term::command "reverse-search This testcase is part"
+Term::check_box_contents "reverse-search to start of file" 0 0 80 15 \
+ "^\\s+1\\s+.*\\s+13\\s+GNU General Public License for more details\\.\\s+$"
diff --git a/gdb/testsuite/gdb.tui/tui-disasm-styling.exp b/gdb/testsuite/gdb.tui/tui-disasm-styling.exp
index 513d787..43b8ecf 100644
--- a/gdb/testsuite/gdb.tui/tui-disasm-styling.exp
+++ b/gdb/testsuite/gdb.tui/tui-disasm-styling.exp
@@ -43,6 +43,9 @@ if {![Term::enter_tui]} {
return
}
+# Proc enter_tui switches off styling, re-enable it.
+Term::command "set style enabled on"
+
Term::command "layout asm"
Term::check_box "asm box" 0 0 80 15
diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp
index 4c9d2a0..26e5060 100644
--- a/gdb/testsuite/gdb.tui/tui-focus.exp
+++ b/gdb/testsuite/gdb.tui/tui-focus.exp
@@ -73,7 +73,7 @@ foreach spec {{src true} {cmd true} {status true} {regs false} \
}
}
-# Use the Python TUI API to exercise some of the ambigous window name
+# Use the Python TUI API to exercise some of the ambiguous window name
# handling parts of the 'focus' command.
Term::clean_restart 24 80 $binfile
if {[allow_python_tests]} {
diff --git a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp
index 51623e8..47482a2 100644
--- a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp
+++ b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp
@@ -20,9 +20,13 @@ tuiterm_env
standard_testfile tui-layout-asm-short-prog.S
-if {[build_executable "failed to prepare" ${testfile} ${srcfile} \
- {debug additional_flags=-nostdlib \
- additional_flags=-nostartfiles}] == -1} {
+set opts {}
+lappend opts debug
+lappend opts additional_flags=-static
+lappend opts additional_flags=-nostdlib
+lappend opts additional_flags=-nostartfiles
+
+if { [build_executable "failed to prepare" $testfile $srcfile $opts] == -1 } {
return -1
}
diff --git a/gdb/testsuite/gdb.tui/tui-missing-src.exp b/gdb/testsuite/gdb.tui/tui-missing-src.exp
index f29ec8c..aca417c 100644
--- a/gdb/testsuite/gdb.tui/tui-missing-src.exp
+++ b/gdb/testsuite/gdb.tui/tui-missing-src.exp
@@ -64,10 +64,8 @@ f2 (int x)
close $fd
# Step 3: Compile the source files.
-if { [gdb_compile "${srcfiles}" "${binfile}" \
- executable {debug additional_flags=-O0}] != "" } {
- untested "failed to compile"
- return -1
+if { [build_executable "failed to prepare" $testfile $srcfiles] == -1 } {
+ return
}
# Step 4: Remove the main.c file.
diff --git a/gdb/testsuite/gdb.tui/tui-mode-switch.exp b/gdb/testsuite/gdb.tui/tui-mode-switch.exp
new file mode 100644
index 0000000..c605962
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/tui-mode-switch.exp
@@ -0,0 +1,57 @@
+require allow_tui_tests
+
+tuiterm_env
+
+if { [ishost *-*-*bsd*] } {
+ # We need support for alternate screen, and xterm doesn't have it.
+ set term xterm-clear
+} else {
+ set term xterm
+}
+
+Term::with_term $term {
+ Term::clean_restart 12 40
+}
+
+if {![Term::prepare_for_tui]} {
+ unsupported "TUI not supported"
+ return 0
+}
+
+# Generate prompt.
+Term::gen_prompt
+
+# Move to last line.
+for { set i 1 } { $i <= 11 } { incr i } {
+ send_gdb "\n"
+ Term::wait_for ""
+}
+
+# Type "foo".
+send_gdb "foo"
+set line { 0 11 40 1 }
+gdb_assert { [Term::wait_for_region_contents {*}$line "^$gdb_prompt foo"] } \
+ "type foo"
+
+# Enter TUI.
+send_gdb "\030\001"
+gdb_assert { [Term::wait_for ""] } "enter TUI"
+
+# Exit TUI.
+send_gdb "\030\001"
+gdb_assert { [Term::wait_for ""] } "exit TUI"
+
+# Type b.
+send_gdb "b"
+gdb_assert { [Term::wait_for_region_contents {*}$line "^$gdb_prompt b"] } \
+ "type b"
+
+# Check that we don't see "boo".
+gdb_assert { ![Term::check_region_contents_p {*}$line "^$gdb_prompt boo"] } \
+ "no boo"
+Term::dump_screen
+
+# We need an empty prompt here, to deal with the "monitor exit" that
+# native-extended-gdbserver will send. Send a backspace.
+send_gdb "\010"
+Term::wait_for ""
diff --git a/gdb/testsuite/gdb.tui/tuiterm-2.exp b/gdb/testsuite/gdb.tui/tuiterm-2.exp
index 5992271..a451834 100644
--- a/gdb/testsuite/gdb.tui/tuiterm-2.exp
+++ b/gdb/testsuite/gdb.tui/tuiterm-2.exp
@@ -106,6 +106,76 @@ with_override Term::accept_gdb_output test_accept_gdb_output {
}
gdb_assert { [Term::wait_for ""] }
}
+
+ with_test_prefix "Term::wait_for 2" {
+ Term::_setup 4 20
+ set send_cnt 0
+ set expect_send {}
+ set action_cnt 0
+ set actions {
+ {
+ Term::_move_cursor 0 0
+
+ Term::_insert "${::border}(gdb) "
+ set pos $Term::_cur_col
+
+ Term::_insert "foo"
+
+ Term::_move_cursor 19 0
+ Term::_insert "$::border"
+
+ Term::_move_cursor $pos 0
+ }
+ {
+ Term::_move_cursor 0 1
+
+ Term::_insert "${::border}(gdb) "
+ set pos $Term::_cur_col
+
+ Term::_move_cursor 19 1
+ Term::_insert "$::border"
+
+ Term::_move_cursor $pos 1
+ }
+ }
+
+ # Wait for a prompt.
+ gdb_assert { [Term::wait_for ""] }
+
+ # The first action sets the cursor after the prompt on the
+ # first line. The second action sets the cursor after the
+ # prompt on the second line. Check that wait_for returns
+ # after the second action, not the first.
+ gdb_assert { $Term::_cur_row == 1 }
+ }
}
}
}
+
+with_test_prefix "Unrecognized escape sequence" {
+ spawn $srcdir/$subdir/gdb.tcl
+ switch_gdb_spawn_id $spawn_id
+
+ Term::_setup 4 20
+
+ save_vars timeout {
+ set timeout 1
+
+ set line { 0 0 20 1 }
+
+ # Parse "foo".
+ gdb_assert { [Term::wait_for_region_contents \
+ {*}$line \
+ [string_to_regexp "foo"]] } \
+ "foo"
+
+ # Parse "\033(%5".
+ gdb_assert { ![Term::accept_gdb_output 0] } \
+ "fail to parse escape sequence"
+ gdb_assert { [Term::wait_for_region_contents \
+ {*}$line \
+ [string_to_regexp "^\[(%5"]] } \
+ "echoed escape sequence"
+ }
+ Term::dump_screen
+}
diff --git a/gdb/testsuite/gdb.tui/tuiterm.exp b/gdb/testsuite/gdb.tui/tuiterm.exp
index 9dc2402..ed9478a 100644
--- a/gdb/testsuite/gdb.tui/tuiterm.exp
+++ b/gdb/testsuite/gdb.tui/tuiterm.exp
@@ -102,7 +102,7 @@ proc test_backspace {} {
Term::_move_cursor 1 2
- Term::_ctl_0x08
+ Term::_ctl_0x08 0
check "backspace one" {
"abcdefgh"
"ijklmnop"
@@ -111,13 +111,22 @@ proc test_backspace {} {
} 0 2
# Cursor should not move if it is already at column 0.
- Term::_ctl_0x08
+ Term::_ctl_0x08 0
check "backspace 2" {
"abcdefgh"
"ijklmnop"
"qrstuvwx"
"yz01234 "
} 0 2
+
+ # Cursor should wrap to previous line.
+ Term::_ctl_0x08 1
+ check "backspace 3" {
+ "abcdefgh"
+ "ijklmnop"
+ "qrstuvwx"
+ "yz01234 "
+ } 7 1
}
proc test_linefeed { } {
@@ -435,6 +444,30 @@ proc test_horizontal_absolute { } {
"qrstuvwx"
"yz01234 "
} 3 2
+
+ Term::_csi_G 8
+ check "cursor horizontal absolute 3" {
+ "abcdefgh"
+ "ijklmnop"
+ "qrstuvwx"
+ "yz01234 "
+ } 7 2
+
+ Term::_csi_G 9
+ check "cursor horizontal absolute 4" {
+ "abcdefgh"
+ "ijklmnop"
+ "qrstuvwx"
+ "yz01234 "
+ } 7 2
+
+ Term::_csi_`
+ check "horizontal position absolute 1" {
+ "abcdefgh"
+ "ijklmnop"
+ "qrstuvwx"
+ "yz01234 "
+ } 0 2
}
proc test_cursor_position { } {
@@ -620,13 +653,21 @@ proc test_cursor_backward_tabulation { } {
}
proc test_repeat { } {
- Term::_move_cursor 2 1
- set Term::_last_char X
+ Term::_move_cursor 0 1
- Term::_csi_b 3
+ Term::_insert "xxX"
+ gdb_assert { $Term::_last_char == "X" }
+ check "insert" {
+ "abcdefgh"
+ "xxXlmnop"
+ "qrstuvwx"
+ "yz01234 "
+ } 3 1
+
+ Term::_csi_b 2
check "repeat" {
"abcdefgh"
- "ijXXXnop"
+ "xxXXXnop"
"qrstuvwx"
"yz01234 "
} 5 1
@@ -750,6 +791,15 @@ proc test_attrs {} {
set line [Term::get_line_with_attrs 0]
gdb_assert { [regexp $re $line] } "attribute: $attr"
}
+
+ # Regression test: Check that _csi_m works without arguments.
+ setup_terminal 4 1
+ Term::_csi_m 7
+ Term::_insert "a"
+ Term::_csi_m
+ Term::_insert "a"
+ set line [Term::get_line_with_attrs 0]
+ gdb_assert { [string equal $line "<reverse:1>a<reverse:0>a "] }
}
# Run proc TEST_PROC_NAME with a "small" terminal.
diff --git a/gdb/testsuite/gdb.xml/bad-include.xml b/gdb/testsuite/gdb.xml/bad-include.xml
index f7a2b72..cd9cce3 100644
--- a/gdb/testsuite/gdb.xml/bad-include.xml
+++ b/gdb/testsuite/gdb.xml/bad-include.xml
@@ -1 +1 @@
-<xi:include href="nonexistant.xml"/>
+<xi:include href="nonexistent.xml"/>
diff --git a/gdb/testsuite/gdb.xml/tdesc-xinclude.exp b/gdb/testsuite/gdb.xml/tdesc-xinclude.exp
index 885d217..b934c80 100644
--- a/gdb/testsuite/gdb.xml/tdesc-xinclude.exp
+++ b/gdb/testsuite/gdb.xml/tdesc-xinclude.exp
@@ -43,7 +43,7 @@ set_arch "includes.xml" \
# This file contains a missing include. We should warn the user about
# it.
set_arch "bad-include.xml" \
- "warning:.*Could not load XML document \"nonexistant.xml\"$common_warn"
+ "warning:.*Could not load XML document \"nonexistent.xml\"$common_warn"
# Make sure we detect infinite loops, eventually.
set_arch "loop.xml" \
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index b347437..3a182c2 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -1072,7 +1072,10 @@ namespace eval Dwarf {
}
proc _section {name {flags ""} {type ""}} {
- if {$flags == "" && $type == ""} {
+ if {$name == ".debug_str"} {
+ # Hard-code this because it's always desirable.
+ _emit " .section $name, \"MS\", %progbits, 1"
+ } elseif {$flags == "" && $type == ""} {
_emit " .section $name"
} elseif {$type == ""} {
_emit " .section $name, \"$flags\""
@@ -3398,9 +3401,24 @@ namespace eval Dwarf {
# Add the strings in ARGS to the .debug_str section, and create a
# .debug_str_offsets section pointing to those strings.
- # BASE_OFFSET is the label for DW_AT_str_offsets_base.
- proc debug_str_offsets { base_offset args } {
- _section .debug_str
+ # Current options are:
+ # dwo 0|1 - boolean indicating if the sections have the dwo suffix.
+ # default = 0 (no .dwo suffix)
+ # base_offset label
+ # - generate label, to be used in DW_AT_str_offsets_base.
+ # default = "" (don't generate a label).
+ proc debug_str_offsets { options args } {
+ parse_options {
+ { dwo 0 }
+ { base_offset "" }
+ }
+
+ if { $dwo } {
+ _section .debug_str.dwo
+ } else {
+ _section .debug_str
+ }
+
set num 0
foreach arg $args {
set str_label [_compute_label "str_${num}"]
@@ -3412,12 +3430,18 @@ namespace eval Dwarf {
declare_labels debug_str_offsets_start debug_str_offsets_end
set initial_length "$debug_str_offsets_end - $debug_str_offsets_start"
- _section .debug_str_offsets
+ if { $dwo } {
+ _section .debug_str_offsets.dwo
+ } else {
+ _section .debug_str_offsets
+ }
_op .4byte $initial_length "Initial_length"
debug_str_offsets_start:
_op .2byte 0x5 "version"
_op .2byte 0x0 "padding"
- $base_offset:
+ if { $base_offset != "" } {
+ $base_offset:
+ }
set num 0
foreach arg $args {
set str_label [_compute_label "str_${num}"]
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index fe2cfca..c24e7ed 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -70,6 +70,8 @@ proc style {str style} {
set fg 39
set bg 49
set intensity 22
+ set italic 23
+ set underline 24
set reverse 27
switch -exact -- $style {
title { set intensity 1 }
@@ -84,7 +86,7 @@ proc style {str style} {
line-number { set intensity 2 }
none { return $str }
}
- return "\033\\\[${fg};${bg};${intensity};${reverse}m${str}\033\\\[m"
+ return "\033\\\[${fg};${bg};${intensity};${italic};${underline};${reverse}m${str}\033\\\[m"
}
# gdb_get_bp_addr num
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 2a5d37c..9970af6 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -269,6 +269,13 @@ if ![info exists INTERNAL_GDBFLAGS] {
}
set INTERNAL_GDBFLAGS [append_gdb_data_directory_option $INTERNAL_GDBFLAGS]
+
+ # Handle the case that "interactive-mode auto" reports off.
+ append INTERNAL_GDBFLAGS { -iex "set interactive-mode on"}
+
+ if { [ishost "*-*-mingw*"] } {
+ append INTERNAL_GDBFLAGS { -iex "maint set console-translation-mode binary"}
+ }
}
# The variable gdb_prompt is a regexp which matches the gdb prompt.
@@ -280,10 +287,13 @@ if {![info exists gdb_prompt]} {
set gdb_prompt "\\(gdb\\)"
}
-# A regexp that matches the pagination prompt.
-set pagination_prompt \
+# The pagination prompt.
+set pagination_prompt_str \
"--Type <RET> for more, q to quit, c to continue without paging--"
+# A regexp that matches the pagination prompt.
+set pagination_prompt [string_to_regexp $pagination_prompt_str]
+
# The variable fullname_syntax_POSIX is a regexp which matches a POSIX
# absolute path ie. /foo/
set fullname_syntax_POSIX {/[^\n]*/}
@@ -1026,7 +1036,10 @@ proc command_to_message { command } {
# should not be anchored at the end of the buffer. This means that the
# pattern can match even if there is stuff output after the prompt. Does not
# have any effect if -prompt is specified.
-# -lbl specifies that line-by-line matching will be used.
+# -lbl specifies that line-by-line matching will be used. This means
+# that lines from GDB not matched by any pattern will be consumed from
+# the output buffer. This helps avoid buffer overflows and timeouts
+# when testing verbose commands.
# EXPECT_ARGUMENTS will be fed to expect in addition to the standard
# patterns. Pattern elements will be evaluated in the caller's
# context; action elements will be executed in the caller's context.
@@ -1124,6 +1137,7 @@ proc gdb_test_multiple { command message args } {
global any_spawn_id
set line_by_line 0
+ set lbl_anchor_re ""
set prompt_regexp ""
set prompt_anchor 1
for {set i 0} {$i < [llength $args]} {incr i} {
@@ -1133,6 +1147,7 @@ proc gdb_test_multiple { command message args } {
set prompt_regexp [lindex $args $i]
} elseif { $arg == "-lbl" } {
set line_by_line 1
+ set lbl_anchor_re "^"
} elseif { $arg == "-no-prompt-anchor" } {
set prompt_anchor 0
} else {
@@ -1391,7 +1406,7 @@ proc gdb_test_multiple { command message args } {
fail "$errmsg"
set result -1
}
- -re "\r\n$prompt_regexp" {
+ -re "${lbl_anchor_re}\r\n$prompt_regexp" {
if {![string match "" $message]} {
fail "$message"
}
@@ -2237,6 +2252,177 @@ proc gdb_assert { condition {message ""} } {
return $res
}
+# Comparison command for "lsort -command". Sorts two strings by
+# descending file name length.
+
+proc compare_length_desc {a b} {
+ expr {[string length $b] - [string length $a]}
+}
+
+# Fill in and return the global cache for Windows <=> Unix mount point
+# mappings, for Windows.
+#
+# Calling external processes on MSYS2/Cygwin is expensive so instead
+# of calling "cygpath -ua $FILENAME" or "cygpath -ma $FILENAME" for
+# every file name, we extract the Windows and Unix file names of each
+# mount point using the 'mount' command output, and cache the
+# mappings, for both directions.
+
+gdb_caching_proc get_mount_point_map {} {
+ array set win_to_unix {}
+ array set unix_to_win {}
+
+ # The 'mount' command provides all mappings. The general format
+ # is: 'WindowsFileName on UnixFileName type ...'
+ #
+ # For example:
+ # 'C:/msys64 on / type ntfs (binary,auto)'
+ # 'C: on /c type ntfs (binary,posix=0,user,noumount,auto)'
+ set mount_output [exec mount]
+
+ foreach line [split $mount_output \n] {
+ if {[regexp {^(.+) on (.+) type } $line -> win_filename unix_filename]} {
+ set win_to_unix($win_filename) $unix_filename
+ set unix_to_win($unix_filename) $win_filename
+ }
+ }
+
+ # Sort each mapping's keys by descending file name length,
+ # otherwise we wouldn't be able to look for '/foo' in '/' (for
+ # example).
+
+ set sorted_win {}
+ foreach k [lsort -command compare_length_desc [array names win_to_unix]] {
+ lappend sorted_win $k $win_to_unix($k)
+ }
+
+ set sorted_unix {}
+ foreach k [lsort -command compare_length_desc [array names unix_to_win]] {
+ lappend sorted_unix $k $unix_to_win($k)
+ }
+
+ # Return both sorted lists: {win => unix} {unix => win}
+ return [list $sorted_win $sorted_unix]
+}
+
+# Normalize backward slashes to forward slashes.
+
+proc normalize_slashes {filename} {
+ return [string map {\\ /} $filename]
+}
+
+# Sanitize a host file name, without making it absolute or resolving
+# symlinks. On native Windows, this normalizes slashes to forward
+# slashes, and makes sure that if the file name starts with a drive
+# letter, it is upper case. On other systems, it just returns the
+# file name unmodified.
+
+proc host_file_sanitize {filename} {
+ if {[ishost *-*-mingw*]} {
+ set filename [normalize_slashes $filename]
+
+ # If the file name starts with a drive letter, uppercase it.
+ if {[regexp {^([a-zA-Z]):(/.*)?} $filename -> drive rest]} {
+ set filename "[string toupper $drive]:$rest"
+ }
+ }
+
+ return $filename
+}
+
+# Normalize a file name for the build machine. If running native
+# Windows GDB, this converts a Windows file name to the corresponding
+# Unix filename, per the mount table. For example, this replaces
+# 'c:/foo' with '/c/foo' (on MSYS2) or '/cygdrive/c/foo' (on Cygwin).
+# On other systems, it just wraps "file normalize".
+
+proc build_file_normalize {filename} {
+ if {[ishost *-*-mingw*]} {
+ set filename [host_file_sanitize $filename]
+
+ # Handle Windows => Unix mount point conversion. We assume
+ # there are no symlinks to resolve, which is a reasonable
+ # assumption for native Windows testing.
+
+ # Get Windows => Unix map.
+ lassign [get_mount_point_map] win_to_unix _
+
+ foreach {win_filename unix_filename} $win_to_unix {
+ if {[string equal -length [string length $win_filename] \
+ $win_filename $filename]} {
+ set rest [string range $filename \
+ [string length $win_filename] end]
+ return "${unix_filename}$rest"
+ }
+ }
+ }
+
+ return [file normalize $filename]
+}
+
+# Normalize a file name for the host machine. If running native
+# Windows GDB, this converts a Unix file name to a Windows filename,
+# per the mount table. E.g., '/c/foo' (on MSYS2) or '/cygdrive/c/foo'
+# (on Cygwin) is converted to 'c:/foo'.
+
+proc host_file_normalize {filename} {
+ if {[ishost *-*-mingw*]} {
+ set filename [host_file_sanitize $filename]
+
+ # If the file name already starts with a drive letter (e.g.,
+ # C:/foo), we're done. Don't let it fallthrough to "file
+ # normalize", which would misinterpret it as a relative file
+ # name.
+ if {[regexp {^[A-Z]:/} $filename]} {
+ return $filename
+ }
+
+ # Get Unix => Windows map.
+ lassign [get_mount_point_map] _ unix_to_win
+
+ foreach {unix_filename win_filename} $unix_to_win {
+ set mount_len [string length $unix_filename]
+ if {[string equal -length $mount_len $unix_filename $filename]} {
+ if {[string length $filename] == $mount_len} {
+ return "$win_filename/"
+ } elseif {[string index $filename $mount_len] eq "/"} {
+ set rest [string range $filename $mount_len end]
+ return "$win_filename$rest"
+ }
+ }
+ }
+ }
+
+ return [file normalize $filename]
+}
+
+# Wrapper around "file join" that handles host-specific details.
+#
+# For Cygwin/MSYS2's Tcl, file names that start with a drive letter
+# are not considered absolute file names, thus 'file join "c:/" "d:/"'
+# returns "c:/d:". This procedure thus detects absolute Windows-style
+# file names, and treats them as absolute, bypassing "file join".
+
+proc host_file_join {args} {
+ if {[isbuild *-*-mingw*]} {
+ set result ""
+ foreach filename $args {
+ set filename [host_file_sanitize $filename]
+
+ # If the file name starts with drive letter and colon
+ # (e.g., "C:/"), treat it as absolute.
+ if {[regexp {^[A-Z]:/} $filename]} {
+ set result $filename
+ } else {
+ set result [file join $result $filename]
+ }
+ }
+ return $result
+ } else {
+ return [file join {*}$args]
+ }
+}
+
proc gdb_reinitialize_dir { subdir } {
global gdb_prompt
@@ -2251,7 +2437,8 @@ proc gdb_reinitialize_dir { subdir } {
}
gdb_expect 60 {
-re "Source directories searched.*$gdb_prompt $" {
- send_gdb "dir $subdir\n"
+ set dir [host_file_normalize $subdir]
+ send_gdb "dir $dir\n"
gdb_expect 60 {
-re "Source directories searched.*$gdb_prompt $" {
verbose "Dir set to $subdir"
@@ -2301,7 +2488,8 @@ proc default_gdb_exit {} {
}
}
- if { [is_remote host] && [board_info host exists fileid] } {
+ if { ([is_remote host] && [board_info host exists fileid])
+ || [istarget *-*-mingw*] } {
send_gdb "quit\n"
gdb_expect 10 {
-re "y or n" {
@@ -2314,7 +2502,9 @@ proc default_gdb_exit {} {
}
if ![is_remote host] {
- remote_close host
+ if {[catch { remote_close host } message]} {
+ warning "closing gdb failed with: $message"
+ }
}
unset gdb_spawn_id
unset ::gdb_tty_name
@@ -2577,6 +2767,17 @@ proc default_gdb_start { } {
# Output with -q, and bracketed paste mode enabled, see above.
verbose "GDB initialized."
}
+ -re "^\033\\\[6n$gdb_prompt $" {
+ # With MSYS2 and TERM={xterm,ansi}, I get:
+ #
+ # builtin_spawn gdb -q ...
+ # ^[[6n(gdb)
+ #
+ # We set TERM to dumb by default to avoid this, but some
+ # test-cases set TERM to xterm or ansi, in which case we get this
+ # output.
+ verbose "GDB initialized."
+ }
-re "$gdb_prompt $" {
perror "GDB never initialized."
unset gdb_spawn_id
@@ -4265,6 +4466,76 @@ gdb_caching_proc allow_tsx_tests {} {
return $allow_tsx_tests
}
+# Run a test on the target to check if it supports x86 shadow stack. Return 1
+# if shadow stack is enabled, 0 otherwise.
+
+gdb_caching_proc allow_ssp_tests {} {
+ global srcdir subdir gdb_prompt hex
+
+ set me "allow_ssp_tests"
+
+ if { ![istarget i?86-*-*] && ![istarget x86_64-*-* ] } {
+ verbose "$me: target known to not support shadow stack."
+ return 0
+ }
+
+ # There is no need to check the actual HW in addition to ptrace support.
+ # We need both checks and ptrace will tell us about the HW state.
+ set compile_flags "{additional_flags=-fcf-protection=return}"
+ set src { int main() { return 0; } }
+ if {![gdb_simple_compile $me $src executable $compile_flags]} {
+ return 0
+ }
+
+ save_vars { ::env(GLIBC_TUNABLES) } {
+
+ append_environment GLIBC_TUNABLES "glibc.cpu.hwcaps" "SHSTK"
+
+ # No error message, compilation succeeded so now run it via gdb.
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load $obj
+ if {![runto_main]} {
+ remote_file build delete $obj
+ return 0
+ }
+ set shadow_stack_disabled_re "(<unavailable>)"
+ if {[istarget *-*-linux*]} {
+ # Starting with v6.6, the Linux kernel supports CET shadow stack.
+ # Dependent on the target we can see a nullptr or "<unavailable>"
+ # when shadow stack is supported by HW and the Linux kernel but
+ # not enabled for the current thread (for example due to a lack
+ # of compiler or glibc support for -fcf-protection).
+ set shadow_stack_disabled_re "$shadow_stack_disabled_re|(.*0x0)"
+ }
+
+ set allow_ssp_tests 0
+ gdb_test_multiple "print \$pl3_ssp" "test shadow stack support" {
+ -re -wrap "(.*$hex)((?!(.*0x0)).)" {
+ verbose -log "$me: Shadow stack support detected."
+ set allow_ssp_tests 1
+ }
+ -re -wrap $shadow_stack_disabled_re {
+ # In case shadow stack is not enabled (for example due to a
+ # lack of compiler or glibc support for -fcf-protection).
+ verbose -log "$me: Shadow stack is not enabled."
+ }
+ -re -wrap "void" {
+ # In case we don't have hardware or kernel support.
+ verbose -log "$me: No shadow stack support."
+ }
+ }
+
+ gdb_exit
+ }
+
+ remote_file build delete $obj
+
+ verbose "$me: returning $allow_ssp_tests" 2
+ return $allow_ssp_tests
+}
+
# Run a test on the target to see if it supports avx512bf16. Return 1 if so,
# 0 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
@@ -5024,6 +5295,57 @@ gdb_caching_proc allow_aarch64_mops_tests {} {
return $allow_mops_tests
}
+# Run a test on the target to see if it supports AArch64 GCS extensions.
+# Return 1 if so, 0 if it does not. Note this causes a restart of GDB.
+
+gdb_caching_proc allow_aarch64_gcs_tests {} {
+ global srcdir subdir gdb_prompt inferior_exited_re
+
+ set me "allow_aarch64_gcs_tests"
+
+ if { ![is_aarch64_target]} {
+ return 0
+ }
+
+ # Compile a program that tests the GCS feature.
+ set src {
+ #include <stdbool.h>
+ #include <sys/auxv.h>
+
+ /* Feature check for Guarded Control Stack. */
+ #ifndef HWCAP_GCS
+ #define HWCAP_GCS (1UL << 32)
+ #endif
+
+ int main (void) {
+ bool gcs_supported = getauxval (AT_HWCAP) & HWCAP_GCS;
+
+ /* Return success if GCS is supported. */
+ return !gcs_supported;
+ }
+ }
+
+ if {![gdb_simple_compile $me $src executable]} {
+ return 0
+ }
+
+ # Compilation succeeded so now run it via gdb.
+ set allow_gcs_tests 0
+ clean_restart $obj
+ gdb_run_cmd
+ gdb_expect {
+ -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
+ verbose -log "\n$me: gcs support detected"
+ set allow_gcs_tests 1
+ }
+ }
+ gdb_exit
+ remote_file build delete $obj
+
+ verbose "$me: returning $allow_gcs_tests" 2
+ return $allow_gcs_tests
+}
+
# A helper that compiles a test case to see if __int128 is supported.
proc gdb_int128_helper {lang} {
return [gdb_can_simple_compile "i128-for-$lang" {
@@ -5087,6 +5409,40 @@ proc skip_inline_var_tests {} {
return 0
}
+# Return whether we allow running fork-related testcases. Targets
+# that don't even have any concept of fork will just fail to compile
+# the testcases and skip the tests that way if this returns true for
+# them. Unix targets that do have a fork system call, but don't
+# support intercepting forks will want to return false here, otherwise
+# the testcases that exercise fork may hit a number of long cascading
+# time out sequences.
+
+proc allow_fork_tests {} {
+ if {[istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"]} {
+ return 0
+ }
+
+ return 1
+}
+
+# Return whether we allow running testcases that want to debug
+# multiple inferiors with the same target. Not all targets support
+# this. Note that some tests add a second inferior but never start
+# it. Those tests should not be skipped due to this proc returning
+# false.
+
+proc allow_multi_inferior_tests {} {
+ if {[istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"]} {
+ return 0
+ }
+
+ if {[use_gdb_stub]} {
+ return 0
+ }
+
+ return 1
+}
+
# Return a 1 if we should run tests that require hardware breakpoints
proc allow_hw_breakpoint_tests {} {
@@ -5666,6 +6022,10 @@ proc gdb_simple_compile {name code {type object} {compile_flags {}} {object obj}
set ext "d"
break
}
+ if { "$flag" eq "rust" } {
+ set ext "rs"
+ break
+ }
}
set src [standard_temp_file $name.$ext]
set obj [standard_temp_file $name.$postfix]
@@ -6244,6 +6604,9 @@ proc gdb_compile {source dest type options} {
}
}
+ # Automatically handle includes in testsuite/lib/.
+ auto_lappend_include_files options $source
+
cond_wrap [expr $pie != -1 || $nopie != -1] \
with_PIE_multilib_flags_filtered {
set result [target_compile $source $dest $type $options]
@@ -6779,7 +7142,20 @@ gdb_caching_proc can_spawn_for_attach {} {
set me "can_spawn_for_attach"
set src {
- #include <unistd.h>
+ #ifdef _WIN32
+ # include <windows.h>
+ #else
+ # include <unistd.h>
+ #endif
+
+ #ifdef _WIN32
+ unsigned
+ sleep (unsigned seconds)
+ {
+ Sleep (seconds * 1000);
+ return 0;
+ }
+ #endif
int
main (void)
@@ -6920,7 +7296,7 @@ proc kill_wait_spawned_process { proc_spawn_id } {
proc spawn_id_get_pid { spawn_id } {
set testpid [exp_pid -i $spawn_id]
- if { [istarget "*-*-cygwin*"] } {
+ if { [istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"] } {
# testpid is the Cygwin PID, GDB uses the Windows PID, which
# might be different due to the way fork/exec works.
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
@@ -7390,13 +7766,13 @@ proc clean_standard_output_dir {} {
}
# Directory containing the standard output files.
- set standard_output_dir [file normalize [standard_output_file ""]]
+ set standard_output_dir [build_standard_output_file ""]
# Ensure that standard_output_dir is clean, or only contains
# gdb.log / gdb.sum.
set log_file_info [split [log_file -info]]
set log_file [file normalize [lindex $log_file_info end]]
- if { $log_file == [file normalize [standard_output_file gdb.log]] } {
+ if { $log_file == [file normalize [build_standard_output_file gdb.log]] } {
# Dir already contains active gdb.log. Don't remove the dir, but
# check that it's clean otherwise.
set res [glob -directory $standard_output_dir -tails *]
@@ -7489,6 +7865,22 @@ proc default_gdb_init { test_file_name } {
setenv LC_CTYPE C
setenv LANG C
+ # With MSYS2 and TERM={xterm,ansi}, I get:
+ #
+ # builtin_spawn gdb -q ...
+ # ^[[6n(gdb)
+ #
+ # While we're addressing this in default_gdb_start, this is not specific
+ # to gdb, other tools produce the same CSI sequence, and consequently we
+ # run into trouble in other places (like get_compiler_info).
+ #
+ # Set TERM to dumb to prevent the '^[[6n' from occurring.
+ #
+ # We could do this only for ishost *-*-mingw*, but that introduces
+ # inconsistency between platforms, with test-cases passing on one platform
+ # but failing on the other. So, we do this for all platforms.
+ setenv TERM dumb
+
# Don't let a .inputrc file or an existing setting of INPUTRC mess
# up the test results. Certain tests (style tests and TUI tests)
# want to set the terminal to a non-"dumb" value, and for those we
@@ -7635,22 +8027,39 @@ proc make_gdb_parallel_path { args } {
}
# Turn BASENAME into a full file name in the standard output
-# directory. It is ok if BASENAME is the empty string; in this case
-# the directory is returned.
+# directory, as seen from the build machine. I.e., as seen from the
+# system driving DejaGnu. (E.g., if DejaGnu is being driven by MSYS2
+# to test native Windows GDB, the "build" file names should be file
+# names TCL understands, i.e., Unix file names.) It is OK if BASENAME
+# is the empty string; in this case the directory is returned.
-proc standard_output_file {basename} {
+proc build_standard_output_file {basename} {
global objdir subdir gdb_test_file_name
set dir [make_gdb_parallel_path outputs $subdir $gdb_test_file_name]
file mkdir $dir
- # If running on MinGW, replace /c/foo with c:/foo
- if { [ishost *-*-mingw*] } {
- set dir [exec sh -c "cd ${dir} && pwd -W"]
- }
return [file join $dir $basename]
}
-# Turn BASENAME into a file name on host.
+# Turn BASENAME into a full file name in the standard output
+# directory, as seen from a non-remote host. I.e., assuming the build
+# and the host share the filesystem. E.g., if DejaGnu is being driven
+# by MSYS2 to test native Windows GDB, the "host" file names should be
+# file names GDB understands, i.e., Windows file names. It is OK if
+# BASENAME is the empty string; in this case the directory is
+# returned.
+
+proc standard_output_file {basename} {
+ global objdir subdir gdb_test_file_name
+
+ set dir [make_gdb_parallel_path outputs $subdir $gdb_test_file_name]
+ file mkdir $dir
+ set dir [host_file_normalize $dir]
+ return [host_file_join $dir $basename]
+}
+
+# Like standard_output_file, but handles remote hosts. Turn BASENAME
+# into a file name on (potentially remote) host.
proc host_standard_output_file { basename } {
if { [is_remote host] } {
@@ -9280,7 +9689,13 @@ proc remove_core {pid {test ""}} {
}
}
-proc core_find {binfile {deletefiles {}} {arg ""}} {
+# Runs ${binfile} expecting it to crash and generate a core file.
+# If DELETEFILES is provided, remove these files after running the program.
+# If ARG is provided, pass it as a command line argument to the program.
+# If OUTPUT_FILE is provided, save the program output to it.
+# Returns the name of the core dump, or empty string if not found.
+
+proc core_find {binfile {deletefiles {}} {arg ""} {output_file "/dev/null"}} {
global objdir subdir
set destcore "$binfile.core"
@@ -9302,9 +9717,14 @@ proc core_find {binfile {deletefiles {}} {arg ""}} {
set found 0
set coredir [standard_output_file coredir.[getpid]]
file mkdir $coredir
- catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
+ catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >${output_file} 2>&1\""
# remote_exec host "${binfile}"
- foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
+ set binfile_basename [file tail $binfile]
+ foreach i [list \
+ ${coredir}/core \
+ ${coredir}/core.coremaker.c \
+ ${coredir}/${binfile_basename}.core \
+ ${coredir}/${binfile_basename}.exe.core] {
if [remote_file build exists $i] {
remote_exec build "mv $i $destcore"
set found 1
@@ -9909,6 +10329,10 @@ proc gdb_stdin_log_init { } {
set logfile [standard_output_file_with_gdb_instance gdb.in]
set in_file [open $logfile w]
+
+ verbose -log ""
+ verbose -log "Starting logfile: $logfile"
+ verbose -log ""
}
# Write to the file for logging gdb input.
@@ -10342,7 +10766,11 @@ proc with_override { name override body } {
proc with_ansi_styling_terminal { body } {
save_vars { ::env(TERM) ::env(NO_COLOR) ::env(COLORTERM) } {
# Set environment variables to allow styling.
- setenv TERM ansi
+ if { [ishost *-*-*bsd*] } {
+ setenv TERM ansiw
+ } else {
+ setenv TERM ansi
+ }
unset -nocomplain ::env(NO_COLOR)
unset -nocomplain ::env(COLORTERM)
@@ -11018,6 +11446,66 @@ proc lappend_include_file { flags file } {
}
}
+# Helper for auto_lappend_include_files that handles one source file,
+# and tracks the list of already-visited files.
+
+proc auto_lappend_include_files_1 {flags source {visited {}}} {
+ upvar $flags up_flags
+ upvar $visited up_visited
+ global srcdir
+
+ set ext [string tolower [file extension $source]]
+ if {$ext ni {".c" ".cpp" ".cc" ".h" ".s"}} {
+ return
+ }
+
+ if {[catch {open $source r} fh err]} {
+ error "Failed to open file '$source': $err"
+ }
+ set contents [read $fh]
+ close $fh
+
+ lappend up_visited $source
+
+ # Match lines like:
+ # #include "gdb_foo.h"
+ set re "^\\s*#include\\s+\"(.*)\""
+
+ foreach line [split $contents "\n"] {
+ if {[regexp $re $line -> basename]} {
+ set lib_file "$srcdir/lib/$basename"
+
+ # If already processed, skip.
+ if {[lsearch -exact $up_visited $lib_file] != -1} {
+ continue
+ }
+
+ if {![file exists $lib_file]} {
+ continue
+ }
+
+ # Append to include list, and recurse into the included
+ # file.
+ lappend_include_file up_flags $lib_file
+ auto_lappend_include_files_1 up_flags $lib_file up_visited
+ }
+ }
+}
+
+# Automatically handle includes under gdb/testsuite/lib/.
+#
+# For each source file in SOURCES, look for #include directives
+# including files that live in testsuite/lib/. For each such included
+# file, call lappend_include_file for it.
+
+proc auto_lappend_include_files {flags sources} {
+ upvar $flags up_flags
+ set visited {}
+ foreach src $sources {
+ auto_lappend_include_files_1 up_flags $src visited
+ }
+}
+
# Return a list of supported host locales.
gdb_caching_proc host_locales { } {
@@ -11129,5 +11617,46 @@ gdb_caching_proc have_builtin_trap {} {
} executable]
}
+# Return 1 if there is a startup shell. Return -1 if there's no startup shell.
+# Return -1 otherwise.
+
+gdb_caching_proc have_startup_shell {} {
+ if { [is_remote target] } {
+ # For remote debugging targets, there is no guarantee that a "shell"
+ # is used.
+ return -1
+ }
+
+
+ gdb_exit
+ gdb_start
+
+ set re_on \
+ [string_to_regexp "Use of shell to start subprocesses is on."]
+ set re_off \
+ [string_to_regexp "Use of shell to start subprocesses is off."]
+ set re_cmd_unsupported \
+ [string_to_regexp \
+ {Undefined show command: "startup-with-shell". Try "help show".}]
+
+ set supported -1
+ gdb_test_multiple "show startup-with-shell" "" {
+ -re -wrap $re_on {
+ set supported 1
+ }
+ -re -wrap $re_off {
+ set supported 0
+ }
+ -re -wrap $re_cmd_unsupported {
+ }
+ -re -wrap "" {
+ }
+ }
+
+ gdb_exit
+
+ return $supported
+}
+
# Always load compatibility stuff.
load_lib future.exp
diff --git a/gdb/testsuite/lib/gdb_watchdog.h b/gdb/testsuite/lib/gdb_watchdog.h
new file mode 100644
index 0000000..15d63e7
--- /dev/null
+++ b/gdb/testsuite/lib/gdb_watchdog.h
@@ -0,0 +1,75 @@
+/* This file is part of GDB, the GNU debugger.
+
+ Copyright 2025 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Set a watchdog that aborts the testcase after a timeout. */
+
+#ifndef GDB_WATCHDOG_H
+#define GDB_WATCHDOG_H
+
+/* Forward declaration to make sure the definitions have the right
+ prototype, at least in C. */
+static void gdb_watchdog (unsigned int seconds);
+
+static const char _gdb_watchdog_msg[]
+ = "gdb_watchdog: timeout expired - aborting test\n";
+
+#ifdef _WIN32
+#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static VOID CALLBACK
+_gdb_watchdog_timer_routine (PVOID lpParam, BOOLEAN TimerOrWaitFired)
+{
+ fputs (_gdb_watchdog_msg, stderr);
+ abort ();
+}
+
+static void
+gdb_watchdog (unsigned int seconds)
+{
+ HANDLE timer;
+
+ if (!CreateTimerQueueTimer (&timer, NULL,
+ _gdb_watchdog_timer_routine, NULL,
+ seconds * 1000, 0, 0))
+ abort ();
+}
+
+#else /* POSIX systems */
+
+#include <unistd.h>
+#include <signal.h>
+#include <stdlib.h>
+
+static void
+_gdb_sigalrm_handler (int signo)
+{
+ write (2, _gdb_watchdog_msg, sizeof (_gdb_watchdog_msg) - 1);
+ abort ();
+}
+
+static void
+gdb_watchdog (unsigned int seconds)
+{
+ signal (SIGALRM, _gdb_sigalrm_handler);
+ alarm (seconds);
+}
+
+#endif
+
+#endif /* GDB_WATCHDOG_H */
diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index c285072..2389206 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -69,7 +69,7 @@ proc gdb_target_cmd_ext { targetname serialport {additional_text ""} } {
}
-re "Non-stop mode requested, but remote does not support non-stop.*$gdb_prompt $" {
verbose "remote does not support non-stop"
- return 1
+ return 2
}
-re "Remote MIPS debugging.*$additional_text.*$gdb_prompt" {
verbose "Set target to $targetname"
diff --git a/gdb/testsuite/lib/selftest-support.exp b/gdb/testsuite/lib/selftest-support.exp
index e037664..af8ec6f 100644
--- a/gdb/testsuite/lib/selftest-support.exp
+++ b/gdb/testsuite/lib/selftest-support.exp
@@ -16,7 +16,7 @@
# Find a pathname to a file that we would execute if the shell was asked
# to run $arg using the current PATH.
-proc find_gdb { arg } {
+proc _selftest_find_gdb { arg } {
# If the arg directly specifies an existing executable file, then
# simply use it.
@@ -36,65 +36,163 @@ proc find_gdb { arg } {
return $arg
}
-# A helper proc that sets up for self-testing.
-# EXECUTABLE is the gdb to use.
-# FUNCTION is the function to break in, either captured_main
-# or captured_command_loop.
-# Return 0 in case of success, -1 in case of failure, and -2 in case of
-# skipping the test-case.
+# Return true if the GDB under test is installed (as opposed to a GDB in its
+# build directory).
-proc selftest_setup { executable function } {
- global gdb_prompt
- global INTERNAL_GDBFLAGS
+proc _selftest_gdb_is_installed {} {
+ # If GDB_DATA_DIRECTORY is empty, assume that it is an installed GDB. It is
+ # not a perfectly accurate check, but should be good enough.
+ return [expr {"$::GDB_DATA_DIRECTORY" == ""}]
+}
+
+# Return true if the libtool binary is present on the host.
+
+proc _selftest_has_libtool {} {
+ lassign [remote_exec host "sh -c \"command -v libtool\""] status output
+ return [expr {$status == 0}]
+}
+
+# If GDB is executed from a build tree, run libtool to obtain the real
+# executable path for EXECUTABLE, which may be a libtool wrapper. Return
+# the path on success. On failure, issue an UNTESTED test result and return
+# an empty string.
+#
+# If GDB is executed from an installed location, return EXECUTABLE unchanged.
+#
+# If libtool is not present on the host system, return EXECUTABLE unchanged.
+# The test might still work, because the GDB binary is not always a libtool
+# wrapper.
+
+proc selftest_libtool_get_real_gdb_executable { executable } {
+ if [_selftest_gdb_is_installed] {
+ return $executable
+ }
- # load yourself into the debugger
+ if ![_selftest_has_libtool] {
+ return $executable
+ }
+
+ lassign [remote_exec host libtool "--mode=execute echo -n $executable"] \
+ status executable
+
+ if { $status != 0 } {
+ untested "failed to run libtool"
+ return ""
+ }
- global gdb_file_cmd_debug_info
- set gdb_file_cmd_debug_info "unset"
+ return $executable
+}
+
+# Return true if EXECUTABLE has debug info.
+#
+# If it doesn't, or if it's not possible to determine, issue an UNTESTED test
+# result and return false.
+
+proc _selftest_check_executable_debug_info { executable } {
+ set ::gdb_file_cmd_debug_info "unset"
+ set result true
+
+ # On Cygwin (at least), gdb/gdb.exe is a libtool wrapper (which happens to
+ # be a PE executable). The real binary is gdb/.libs/gdb.exe. If we load
+ # gdb/gdb.exe, we won't see any debug info and conclude that we can't run
+ # the test. Obtain the real executable path using libtool.
+ #
+ # At the time of writing, we don't see a libtool wrapper generated on Linux.
+ # But if there was one, it would be a shell script, and it would not be
+ # possible to load it in gdb. This conversion would therefore also be
+ # necessary.
+ #
+ # If testing against an installed GDB, then there won't be a libtool
+ # wrapper, no need to convert.
+ set executable [selftest_libtool_get_real_gdb_executable $executable]
+
+ if { $executable == "" } {
+ # selftest_libtool_get_real_gdb_executable already records an UNTESTED
+ # on failure.
+ return false
+ }
- set result [gdb_load $executable]
+ gdb_start
- if {$result != 0} {
- return -1
+ if {[gdb_load $executable] != 0} {
+ untested "failed to load executable when checking for debug info"
+ set result false
}
- if {$gdb_file_cmd_debug_info != "debug"} {
+ if {$::gdb_file_cmd_debug_info != "debug"} {
untested "no debug information, skipping testcase."
- return -2
+ set result false
}
- # Set a breakpoint at $function.
+ gdb_exit
+
+ return $result
+}
+
+# A helper proc that sets up for self-testing.
+#
+# Assumes that the inferior GDB is already loaded in the top-level GDB.
+#
+# Return 0 in case of success, -1 in case of failure, and -2 in case of
+# skipping the test-case.
+
+proc _selftest_setup { } {
+ global gdb_prompt
+ global INTERNAL_GDBFLAGS
+
+ # Set a breakpoint at main
+ set function main
if { [gdb_breakpoint $function "no-message"] != 1 } {
untested "Cannot set breakpoint at $function, skipping testcase."
return -2
}
+ # Debugging on Windows shows random threads starting and exiting,
+ # interfering with the tests. Disable them, since they are not useful here.
+ gdb_test_no_output "set print thread-events off"
+
# run yourself
set description "run until breakpoint at $function"
+ set re_hs {[^\r\n]+}
+ set re_args [string cat \
+ [string_to_regexp "("] \
+ $re_hs \
+ [string_to_regexp ")"]]
+ set re_pass \
+ [multi_line \
+ "Starting program: $re_hs" \
+ ".*" \
+ [string cat "Breakpoint $::decimal, $function $re_args at" \
+ " ${re_hs}gdb.c:$re_hs"] \
+ ".*"]
+ set re_xfail \
+ [multi_line \
+ "Starting program: $re_hs" \
+ ".*" \
+ "Breakpoint $::decimal, $function $re_args$re_hs" \
+ ".*"]
gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
- -re "Starting program.*Breakpoint \[0-9\]+,.*$function \\(.*\\).* at .*main.c:.*$gdb_prompt $" {
- pass "$description"
- }
- -re "Starting program.*Breakpoint \[0-9\]+,.*$function \\(.*\\).*$gdb_prompt $" {
- xfail "$description (line numbers scrambled?)"
- }
- -re "vfork: No more processes.*$gdb_prompt $" {
- fail "$description (out of virtual memory)"
- return -1
- }
- -re ".*$gdb_prompt $" {
- fail "$description"
- return -1
- }
+ -re -wrap $re_pass {
+ pass $description
+ }
+ -re -wrap $re_xfail {
+ xfail "$description (line numbers scrambled?)"
+ }
+ -re -wrap "vfork: No more processes.*" {
+ fail "$description (out of virtual memory)"
+ return -1
+ }
+ -re -wrap "" {
+ fail $description
+ return -1
+ }
}
return 0
}
-# Prepare for running a self-test by moving the GDB executable to a
-# location where we can use it as the inferior. Return the filename
-# of the new location.
+# Return the location of the gdb executable to test.
#
# If the current testing setup is not suitable for running a
# self-test, then return an empty string.
@@ -114,52 +212,54 @@ proc selftest_prepare {} {
# ... or with a stub-like server? I.e., gdbserver + "target
# remote"? In that case we won't be able to pass command line
- # arguments to GDB, and selftest_setup wants to do exactly that.
+ # arguments to GDB, and _selftest_setup wants to do exactly that.
if [use_gdb_stub] {
return
}
- # Run the test with self. Copy the file executable file in case
- # this OS doesn't like to edit its own text space.
-
- set gdb_fullpath [find_gdb $::GDB]
-
- if {[is_remote host]} {
- set xgdb x$::tool
- } else {
- set xgdb [standard_output_file x$::tool]
- }
-
- # Remove any old copy lying around.
- remote_file host delete $xgdb
-
- set filename [remote_download host $gdb_fullpath $xgdb]
-
- return $filename
+ return [_selftest_find_gdb $::GDB]
}
# A simple way to run some self-tests.
-proc do_self_tests {function body} {
+proc do_self_tests {body} {
set file [selftest_prepare]
if { $file eq "" } {
return
}
- gdb_start
+ # Check if the gdb executable has debug info.
+ if { ![_selftest_check_executable_debug_info $file] } {
+ return
+ }
+
+ # FILE might be a libtool wrapper. In order to debug the real thing, pass
+ # FILE on the command-line of the top-level gdb, and run under
+ # `libtool --mode=execute. libtool will replace FILE with the path to the
+ # real executable and set any path required for it to find its dependent
+ # libraries.
+ #
+ # If testing against an installed GDB, there won't be a libtool wrapper.
+ save_vars { ::GDB ::GDBFLAGS } {
+ if { ![_selftest_gdb_is_installed] && [_selftest_has_libtool] } {
+ set ::GDB "libtool --mode=execute $::GDB"
+ }
+
+ set ::GDBFLAGS "$::GDBFLAGS $file"
+ gdb_start
+ }
# When debugging GDB with GDB, some operations can take a relatively long
# time, especially if the build is non-optimized. Bump the timeout for the
# duration of the test.
with_timeout_factor 10 {
- set result [selftest_setup $file $function]
+ set result [_selftest_setup]
if {$result == 0} {
set result [uplevel $body]
}
}
gdb_exit
- catch "remote_file host delete $file"
if {$result == -1} {
warning "Couldn't test self"
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index a0cd199..e1af223 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -33,1264 +33,1690 @@ namespace eval Term {
variable _resize_count
- proc _log { what } {
- verbose "+++ $what"
- }
+ variable _TERM
+ set _TERM ""
- # Call BODY, then log WHAT along with the original and new cursor position.
- proc _log_cur { what body } {
- variable _cur_row
- variable _cur_col
+ variable _alternate
+ variable _alternate_setup
+ set _alternate 0
+ set _alternate_setup 0
+}
+
+proc Term::_log { what } {
+ verbose "+++ $what"
+}
- set orig_cur_row $_cur_row
- set orig_cur_col $_cur_col
+# Call BODY, then log WHAT along with the original and new cursor position.
+proc Term::_log_cur { what body } {
+ variable _cur_row
+ variable _cur_col
- uplevel $body
+ set orig_cur_row $_cur_row
+ set orig_cur_col $_cur_col
+
+ set code [catch {uplevel $body} result]
- _log "$what, cursor: ($orig_cur_row, $orig_cur_col) -> ($_cur_row, $_cur_col)"
+ _log "$what, cursor: ($orig_cur_row, $orig_cur_col) -> ($_cur_row, $_cur_col)"
+
+ if { $code == 1 } {
+ global errorInfo errorCode
+ return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
+ } else {
+ return -code $code $result
}
+}
- # If ARG is empty, return DEF: otherwise ARG. This is useful for
- # defaulting arguments in CSIs.
- proc _default {arg def} {
- if {$arg == ""} {
- return $def
- }
- return $arg
+# If ARG is empty, return DEF: otherwise ARG. This is useful for
+# defaulting arguments in CSIs.
+proc Term::_default {arg def} {
+ if {$arg == ""} {
+ return $def
}
+ return $arg
+}
- # Erase in the line Y from SX to just before EX.
- proc _clear_in_line {sx ex y} {
- variable _attrs
- variable _chars
- set lattr [array get _attrs]
- while {$sx < $ex} {
- set _chars($sx,$y) [list " " $lattr]
- incr sx
- }
+# Erase in the line Y from SX to just before EX.
+proc Term::_clear_in_line {sx ex y} {
+ variable _attrs
+ variable _chars
+ set lattr [array get _attrs]
+ while {$sx < $ex} {
+ set _chars($sx,$y) [list " " $lattr]
+ incr sx
}
+}
- # Erase the lines from SY to just before EY.
- proc _clear_lines {sy ey} {
- variable _cols
- while {$sy < $ey} {
- _clear_in_line 0 $_cols $sy
- incr sy
- }
+# Erase the lines from SY to just before EY.
+proc Term::_clear_lines {sy ey} {
+ variable _cols
+ while {$sy < $ey} {
+ _clear_in_line 0 $_cols $sy
+ incr sy
}
+}
+
+# Beep.
+proc Term::_ctl_0x07 {} {
+}
+
+# Return 1 if tuiterm has the bw/auto_left_margin enabled.
+proc Term::_have_bw {} {
+ return [expr \
+ [string equal $Term::_TERM "ansiw"] \
+ || [string equal $Term::_TERM "ansis"]]
+}
- # Beep.
- proc _ctl_0x07 {} {
+# Backspace.
+proc Term::_ctl_0x08 { {bw -1} } {
+ if { $bw == -1 } {
+ set bw [_have_bw]
}
+ _log_cur "Backspace, bw == $bw" {
+ variable _cur_col
+ variable _cur_row
+ variable _cols
- # Backspace.
- proc _ctl_0x08 {} {
- _log_cur "Backspace" {
- variable _cur_col
+ if { $_cur_col > 0 } {
+ # No wrapping needed.
+ incr _cur_col -1
+ return
+ }
- if {$_cur_col > 0} {
- incr _cur_col -1
- }
+ if { ! $bw } {
+ # Wrapping not enabled.
+ return
}
+
+ if { $_cur_row == 0 } {
+ # Can't wrap.
+ return
+ }
+
+ # Wrap to previous line.
+ set _cur_col [expr $_cols - 1]
+ incr _cur_row -1
}
+}
- # Linefeed.
- proc _ctl_0x0a {} {
- _log_cur "Line feed" {
- variable _cur_row
- variable _rows
- variable _cols
- variable _chars
-
- incr _cur_row 1
- while {$_cur_row >= $_rows} {
- # Scroll the display contents. We scroll one line at
- # a time here; as _cur_row was only increased by one,
- # a single line scroll should be enough to put the
- # cursor back on the screen. But we wrap the
- # scrolling inside a while loop just to be on the safe
- # side.
- for {set y 0} {$y < [expr $_rows - 1]} {incr y} {
- set next_y [expr $y + 1]
- for {set x 0} {$x < $_cols} {incr x} {
- set _chars($x,$y) $_chars($x,$next_y)
- }
- }
+# Linefeed.
+proc Term::_ctl_0x0a {} {
+ _log_cur "Line feed" {
+ variable _cur_row
+ variable _rows
+ variable _cols
+ variable _chars
- incr _cur_row -1
+ incr _cur_row 1
+ while {$_cur_row >= $_rows} {
+ # Scroll the display contents. We scroll one line at
+ # a time here; as _cur_row was only increased by one,
+ # a single line scroll should be enough to put the
+ # cursor back on the screen. But we wrap the
+ # scrolling inside a while loop just to be on the safe
+ # side.
+ for {set y 0} {$y < [expr $_rows - 1]} {incr y} {
+ set next_y [expr $y + 1]
+ for {set x 0} {$x < $_cols} {incr x} {
+ set _chars($x,$y) $_chars($x,$next_y)
+ }
}
+
+ incr _cur_row -1
}
}
+}
- # Carriage return.
- proc _ctl_0x0d {} {
- _log_cur "Carriage return" {
- variable _cur_col
+# Carriage return.
+proc Term::_ctl_0x0d {} {
+ _log_cur "Carriage return" {
+ variable _cur_col
- set _cur_col 0
- }
+ set _cur_col 0
}
+}
- # Insert Character.
- #
- # https://vt100.net/docs/vt510-rm/ICH.html
- proc _csi_@ {args} {
- set n [_default [lindex $args 0] 1]
+# Designate G0 Character Set, USASCII (ESC ( B)
+#
+# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html (see "ESC ( C", case C = B)
+proc Term::_esc_0x28_B {} {
+ _log "ignored: G0: USASCII"
+}
- _log_cur "Insert Character ($n)" {
- variable _cur_col
- variable _cur_row
- variable _cols
- variable _chars
+# Designate G0 Character Set, DEC Special Character and Line Drawing Set (ESC ( 0)
+#
+# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html (see "ESC ( C", case C = 0)
+proc Term::_esc_0x28_0 {} {
+ _log "ignored: G0: DEC Special Character and Line Drawing Set"
+}
- # Move characters right of the cursor right by N positions,
- # starting with the rightmost one.
- for {set in_col [expr $_cols - $n - 1]} {$in_col >= $_cur_col} {incr in_col -1} {
- set out_col [expr $in_col + $n]
- set _chars($out_col,$_cur_row) $_chars($in_col,$_cur_row)
- }
+# DECKPAM (Application Keypad, ESC =)
+#
+# https://vt100.net/docs/vt510-rm/DECKPAM.html
+proc Term::_esc_0x3d {} {
+ _log "ignored: Application Keypad"
+}
+
+# DECKPNM (Normal Keypad, ESC >)
+#
+# https://vt100.net/docs/vt510-rm/DECKPNM.html
+proc Term::_esc_0x3e {} {
+ _log "ignored: Normal Keypad"
+}
- # Write N blank spaces starting from the cursor.
- _clear_in_line $_cur_col [expr $_cur_col + $n] $_cur_row
+# Insert Character.
+#
+# https://vt100.net/docs/vt510-rm/ICH.html
+proc Term::_csi_@ {args} {
+ set n [_default [lindex $args 0] 1]
+
+ _log_cur "Insert Character ($n)" {
+ variable _cur_col
+ variable _cur_row
+ variable _cols
+ variable _chars
+
+ # Move characters right of the cursor right by N positions,
+ # starting with the rightmost one.
+ for {set in_col [expr $_cols - $n - 1]} {$in_col >= $_cur_col} {incr in_col -1} {
+ set out_col [expr $in_col + $n]
+ set _chars($out_col,$_cur_row) $_chars($in_col,$_cur_row)
}
+
+ # Write N blank spaces starting from the cursor.
+ _clear_in_line $_cur_col [expr $_cur_col + $n] $_cur_row
}
+}
- # Cursor Up.
- #
- # https://vt100.net/docs/vt510-rm/CUU.html
- proc _csi_A {args} {
- set arg [_default [lindex $args 0] 1]
+# Horizontal Position Absolute.
+#
+# https://vt100.net/docs/vt510-rm/HPA.html
+proc Term::_csi_` {args} {
+ # Same as Cursor Horizontal Absolute.
+ return [Term::_csi_G {*}$args]
+}
- _log_cur "Cursor Up ($arg)" {
- variable _cur_row
+# Cursor Up.
+#
+# https://vt100.net/docs/vt510-rm/CUU.html
+proc Term::_csi_A {args} {
+ set arg [_default [lindex $args 0] 1]
- set _cur_row [expr {max ($_cur_row - $arg, 0)}]
- }
+ _log_cur "Cursor Up ($arg)" {
+ variable _cur_row
+
+ set _cur_row [expr {max ($_cur_row - $arg, 0)}]
}
+}
- # Cursor Down.
- #
- # https://vt100.net/docs/vt510-rm/CUD.html
- proc _csi_B {args} {
- set arg [_default [lindex $args 0] 1]
+# Cursor Down.
+#
+# https://vt100.net/docs/vt510-rm/CUD.html
+proc Term::_csi_B {args} {
+ set arg [_default [lindex $args 0] 1]
- _log_cur "Cursor Down ($arg)" {
- variable _cur_row
- variable _rows
+ _log_cur "Cursor Down ($arg)" {
+ variable _cur_row
+ variable _rows
- set _cur_row [expr {min ($_cur_row + $arg, $_rows - 1)}]
- }
+ set _cur_row [expr {min ($_cur_row + $arg, $_rows - 1)}]
}
+}
- # Cursor Forward.
- #
- # https://vt100.net/docs/vt510-rm/CUF.html
- proc _csi_C {args} {
- set arg [_default [lindex $args 0] 1]
+# Cursor Forward.
+#
+# https://vt100.net/docs/vt510-rm/CUF.html
+proc Term::_csi_C {args} {
+ set arg [_default [lindex $args 0] 1]
- _log_cur "Cursor Forward ($arg)" {
- variable _cur_col
- variable _cols
+ _log_cur "Cursor Forward ($arg)" {
+ variable _cur_col
+ variable _cols
- set _cur_col [expr {min ($_cur_col + $arg, $_cols - 1)}]
- }
+ set _cur_col [expr {min ($_cur_col + $arg, $_cols - 1)}]
}
+}
- # Cursor Backward.
- #
- # https://vt100.net/docs/vt510-rm/CUB.html
- proc _csi_D {args} {
- set arg [_default [lindex $args 0] 1]
+# Cursor Backward.
+#
+# https://vt100.net/docs/vt510-rm/CUB.html
+proc Term::_csi_D {args} {
+ set arg [_default [lindex $args 0] 1]
- _log_cur "Cursor Backward ($arg)" {
- variable _cur_col
+ _log_cur "Cursor Backward ($arg)" {
+ variable _cur_col
- set _cur_col [expr {max ($_cur_col - $arg, 0)}]
- }
+ set _cur_col [expr {max ($_cur_col - $arg, 0)}]
}
+}
- # Cursor Next Line.
- #
- # https://vt100.net/docs/vt510-rm/CNL.html
- proc _csi_E {args} {
- set arg [_default [lindex $args 0] 1]
+# Cursor Next Line.
+#
+# https://vt100.net/docs/vt510-rm/CNL.html
+proc Term::_csi_E {args} {
+ set arg [_default [lindex $args 0] 1]
- _log_cur "Cursor Next Line ($arg)" {
- variable _cur_col
- variable _cur_row
- variable _rows
+ _log_cur "Cursor Next Line ($arg)" {
+ variable _cur_col
+ variable _cur_row
+ variable _rows
- set _cur_col 0
- set _cur_row [expr {min ($_cur_row + $arg, $_rows - 1)}]
- }
+ set _cur_col 0
+ set _cur_row [expr {min ($_cur_row + $arg, $_rows - 1)}]
}
+}
- # Cursor Previous Line.
- #
- # https://vt100.net/docs/vt510-rm/CPL.html
- proc _csi_F {args} {
- set arg [_default [lindex $args 0] 1]
+# Cursor Previous Line.
+#
+# https://vt100.net/docs/vt510-rm/CPL.html
+proc Term::_csi_F {args} {
+ set arg [_default [lindex $args 0] 1]
- _log_cur "Cursor Previous Line ($arg)" {
- variable _cur_col
- variable _cur_row
- variable _rows
+ _log_cur "Cursor Previous Line ($arg)" {
+ variable _cur_col
+ variable _cur_row
+ variable _rows
- set _cur_col 0
- set _cur_row [expr {max ($_cur_row - $arg, 0)}]
- }
+ set _cur_col 0
+ set _cur_row [expr {max ($_cur_row - $arg, 0)}]
}
+}
- # Cursor Horizontal Absolute.
- #
- # https://vt100.net/docs/vt510-rm/CHA.html
- proc _csi_G {args} {
- set arg [_default [lindex $args 0] 1]
+# Cursor Horizontal Absolute.
+#
+# https://vt100.net/docs/vt510-rm/CHA.html
+proc Term::_csi_G {args} {
+ set arg [_default [lindex $args 0] 1]
- _log_cur "Cursor Horizontal Absolute ($arg)" {
- variable _cur_col
- variable _cols
+ _log_cur "Cursor Horizontal Absolute ($arg)" {
+ variable _cur_col
+ variable _cols
- set _cur_col [expr {min ($arg - 1, $_cols)}]
- }
+ set _cur_col [expr {min ($arg, $_cols)} - 1]
}
+}
- # Cursor Position.
- #
- # https://vt100.net/docs/vt510-rm/CUP.html
- proc _csi_H {args} {
- set row [_default [lindex $args 0] 1]
- set col [_default [lindex $args 1] 1]
+# Cursor Position.
+#
+# https://vt100.net/docs/vt510-rm/CUP.html
+proc Term::_csi_H {args} {
+ set row [_default [lindex $args 0] 1]
+ set col [_default [lindex $args 1] 1]
- _log_cur "Cursor Position ($row, $col)" {
- variable _cur_col
- variable _cur_row
+ _log_cur "Cursor Position ($row, $col)" {
+ variable _cur_col
+ variable _cur_row
- set _cur_row [expr {$row - 1}]
- set _cur_col [expr {$col - 1}]
- }
+ set _cur_row [expr {$row - 1}]
+ set _cur_col [expr {$col - 1}]
}
+}
- # Cursor Horizontal Forward Tabulation.
- #
- # https://vt100.net/docs/vt510-rm/CHT.html
- proc _csi_I {args} {
- set n [_default [lindex $args 0] 1]
+# Cursor Horizontal Forward Tabulation.
+#
+# https://vt100.net/docs/vt510-rm/CHT.html
+proc Term::_csi_I {args} {
+ set n [_default [lindex $args 0] 1]
- _log_cur "Cursor Horizontal Forward Tabulation ($n)" {
- variable _cur_col
- variable _cols
+ _log_cur "Cursor Horizontal Forward Tabulation ($n)" {
+ variable _cur_col
+ variable _cols
- incr _cur_col [expr {$n * 8 - $_cur_col % 8}]
- if {$_cur_col >= $_cols} {
- set _cur_col [expr {$_cols - 1}]
- }
+ incr _cur_col [expr {$n * 8 - $_cur_col % 8}]
+ if {$_cur_col >= $_cols} {
+ set _cur_col [expr {$_cols - 1}]
}
}
+}
- # Erase in Display.
- #
- # https://vt100.net/docs/vt510-rm/ED.html
- proc _csi_J {args} {
- set arg [_default [lindex $args 0] 0]
-
- _log_cur "Erase in Display ($arg)" {
- variable _cur_col
- variable _cur_row
- variable _rows
- variable _cols
-
- if {$arg == 0} {
- # Cursor (inclusive) to end of display.
- _clear_in_line $_cur_col $_cols $_cur_row
- _clear_lines [expr {$_cur_row + 1}] $_rows
- } elseif {$arg == 1} {
- # Beginning of display to cursor (inclusive).
- _clear_lines 0 $_cur_row
- _clear_in_line 0 [expr $_cur_col + 1] $_cur_row
- } elseif {$arg == 2} {
- # Entire display.
- _clear_lines 0 $_rows
- }
+# Erase in Display.
+#
+# https://vt100.net/docs/vt510-rm/ED.html
+proc Term::_csi_J {args} {
+ set arg [_default [lindex $args 0] 0]
+
+ _log_cur "Erase in Display ($arg)" {
+ variable _cur_col
+ variable _cur_row
+ variable _rows
+ variable _cols
+
+ if {$arg == 0} {
+ # Cursor (inclusive) to end of display.
+ _clear_in_line $_cur_col $_cols $_cur_row
+ _clear_lines [expr {$_cur_row + 1}] $_rows
+ } elseif {$arg == 1} {
+ # Beginning of display to cursor (inclusive).
+ _clear_lines 0 $_cur_row
+ _clear_in_line 0 [expr $_cur_col + 1] $_cur_row
+ } elseif {$arg == 2} {
+ # Entire display.
+ _clear_lines 0 $_rows
}
}
+}
- # Erase in Line.
- #
- # https://vt100.net/docs/vt510-rm/EL.html
- proc _csi_K {args} {
- set arg [_default [lindex $args 0] 0]
+# Erase in Line.
+#
+# https://vt100.net/docs/vt510-rm/EL.html
+proc Term::_csi_K {args} {
+ set arg [_default [lindex $args 0] 0]
- _log_cur "Erase in Line ($arg)" {
- variable _cur_col
- variable _cur_row
- variable _cols
+ _log_cur "Erase in Line ($arg)" {
+ variable _cur_col
+ variable _cur_row
+ variable _cols
- if {$arg == 0} {
- # Cursor (inclusive) to end of line.
- _clear_in_line $_cur_col $_cols $_cur_row
- } elseif {$arg == 1} {
- # Beginning of line to cursor (inclusive).
- _clear_in_line 0 [expr $_cur_col + 1] $_cur_row
- } elseif {$arg == 2} {
- # Entire line.
- _clear_in_line 0 $_cols $_cur_row
- }
+ if {$arg == 0} {
+ # Cursor (inclusive) to end of line.
+ _clear_in_line $_cur_col $_cols $_cur_row
+ } elseif {$arg == 1} {
+ # Beginning of line to cursor (inclusive).
+ _clear_in_line 0 [expr $_cur_col + 1] $_cur_row
+ } elseif {$arg == 2} {
+ # Entire line.
+ _clear_in_line 0 $_cols $_cur_row
}
}
+}
- # Insert Line
- #
- # https://vt100.net/docs/vt510-rm/IL.html
- proc _csi_L {args} {
- set arg [_default [lindex $args 0] 1]
+# Insert Line
+#
+# https://vt100.net/docs/vt510-rm/IL.html
+proc Term::_csi_L {args} {
+ set arg [_default [lindex $args 0] 1]
- _log_cur "Insert Line ($arg)" {
- variable _cur_col
- variable _cur_row
- variable _rows
- variable _cols
- variable _chars
+ _log_cur "Insert Line ($arg)" {
+ variable _cur_col
+ variable _cur_row
+ variable _rows
+ variable _cols
+ variable _chars
- set y [expr $_rows - 2]
- set next_y [expr $y + $arg]
- while {$y >= $_cur_row} {
- for {set x 0} {$x < $_cols} {incr x} {
- set _chars($x,$next_y) $_chars($x,$y)
- }
- incr y -1
- incr next_y -1
+ set y [expr $_rows - 2]
+ set next_y [expr $y + $arg]
+ while {$y >= $_cur_row} {
+ for {set x 0} {$x < $_cols} {incr x} {
+ set _chars($x,$next_y) $_chars($x,$y)
}
-
- _clear_lines $_cur_row [expr $_cur_row + $arg]
+ incr y -1
+ incr next_y -1
}
+
+ _clear_lines $_cur_row [expr $_cur_row + $arg]
}
+}
- # Delete line.
- #
- # https://vt100.net/docs/vt510-rm/DL.html
- proc _csi_M {args} {
- set count [_default [lindex $args 0] 1]
+# Delete line.
+#
+# https://vt100.net/docs/vt510-rm/DL.html
+proc Term::_csi_M {args} {
+ set count [_default [lindex $args 0] 1]
- _log_cur "Delete line ($count)" {
- variable _cur_row
- variable _rows
- variable _cols
- variable _chars
+ _log_cur "Delete line ($count)" {
+ variable _cur_row
+ variable _rows
+ variable _cols
+ variable _chars
- set y $_cur_row
- set next_y [expr {$y + $count}]
- while {$next_y < $_rows} {
- for {set x 0} {$x < $_cols} {incr x} {
- set _chars($x,$y) $_chars($x,$next_y)
- }
- incr y
- incr next_y
+ set y $_cur_row
+ set next_y [expr {$y + $count}]
+ while {$next_y < $_rows} {
+ for {set x 0} {$x < $_cols} {incr x} {
+ set _chars($x,$y) $_chars($x,$next_y)
}
- _clear_lines $y $_rows
+ incr y
+ incr next_y
}
+ _clear_lines $y $_rows
}
+}
- # Delete Character.
- #
- # https://vt100.net/docs/vt510-rm/DCH.html
- proc _csi_P {args} {
- set count [_default [lindex $args 0] 1]
-
- _log_cur "Delete character ($count)" {
- variable _cur_row
- variable _cur_col
- variable _chars
- variable _cols
+# Delete Character.
+#
+# https://vt100.net/docs/vt510-rm/DCH.html
+proc Term::_csi_P {args} {
+ set count [_default [lindex $args 0] 1]
- # Move all characters right of the cursor N positions left.
- set out_col [expr $_cur_col]
- set in_col [expr $_cur_col + $count]
+ _log_cur "Delete character ($count)" {
+ variable _cur_row
+ variable _cur_col
+ variable _chars
+ variable _cols
- while {$in_col < $_cols} {
- set _chars($out_col,$_cur_row) $_chars($in_col,$_cur_row)
- incr in_col
- incr out_col
- }
+ # Move all characters right of the cursor N positions left.
+ set out_col [expr $_cur_col]
+ set in_col [expr $_cur_col + $count]
- # Clear the rest of the line.
- _clear_in_line $out_col $_cols $_cur_row
+ while {$in_col < $_cols} {
+ set _chars($out_col,$_cur_row) $_chars($in_col,$_cur_row)
+ incr in_col
+ incr out_col
}
+
+ # Clear the rest of the line.
+ _clear_in_line $out_col $_cols $_cur_row
}
+}
- # Pan Down
- #
- # https://vt100.net/docs/vt510-rm/SU.html
- proc _csi_S {args} {
- set count [_default [lindex $args 0] 1]
+# Pan Down
+#
+# https://vt100.net/docs/vt510-rm/SU.html
+proc Term::_csi_S {args} {
+ set count [_default [lindex $args 0] 1]
- _log_cur "Pan Down ($count)" {
- variable _cur_col
- variable _cur_row
- variable _cols
- variable _rows
- variable _chars
+ _log_cur "Pan Down ($count)" {
+ variable _cur_col
+ variable _cur_row
+ variable _cols
+ variable _rows
+ variable _chars
- # The following code is written without consideration for
- # the scroll margins. At this time this comment was
- # written the tuiterm library doesn't support the scroll
- # margins. If/when that changes, then the following will
- # need to be updated.
+ # The following code is written without consideration for
+ # the scroll margins. At this time this comment was
+ # written the tuiterm library doesn't support the scroll
+ # margins. If/when that changes, then the following will
+ # need to be updated.
- set dy 0
- set y $count
+ set dy 0
+ set y $count
- while {$y < $_rows} {
- for {set x 0} {$x < $_cols} {incr x} {
- set _chars($x,$dy) $_chars($x,$y)
- }
- incr y 1
- incr dy 1
+ while {$y < $_rows} {
+ for {set x 0} {$x < $_cols} {incr x} {
+ set _chars($x,$dy) $_chars($x,$y)
}
-
- _clear_lines $dy $_rows
+ incr y 1
+ incr dy 1
}
+
+ _clear_lines $dy $_rows
}
+}
- # Pan Up
- #
- # https://vt100.net/docs/vt510-rm/SD.html
- proc _csi_T {args} {
- set count [_default [lindex $args 0] 1]
+# Pan Up
+#
+# https://vt100.net/docs/vt510-rm/SD.html
+proc Term::_csi_T {args} {
+ set count [_default [lindex $args 0] 1]
- _log_cur "Pan Up ($count)" {
- variable _cur_col
- variable _cur_row
- variable _cols
- variable _rows
- variable _chars
+ _log_cur "Pan Up ($count)" {
+ variable _cur_col
+ variable _cur_row
+ variable _cols
+ variable _rows
+ variable _chars
- # The following code is written without consideration for
- # the scroll margins. At this time this comment was
- # written the tuiterm library doesn't support the scroll
- # margins. If/when that changes, then the following will
- # need to be updated.
+ # The following code is written without consideration for
+ # the scroll margins. At this time this comment was
+ # written the tuiterm library doesn't support the scroll
+ # margins. If/when that changes, then the following will
+ # need to be updated.
- set y [expr $_rows - $count]
- set dy $_rows
+ set y [expr $_rows - $count]
+ set dy $_rows
- while {$dy >= $count} {
- for {set x 0} {$x < $_cols} {incr x} {
- set _chars($x,$dy) $_chars($x,$y)
- }
- incr y -1
- incr dy -1
+ while {$dy >= $count} {
+ for {set x 0} {$x < $_cols} {incr x} {
+ set _chars($x,$dy) $_chars($x,$y)
}
-
- _clear_lines 0 $count
+ incr y -1
+ incr dy -1
}
+
+ _clear_lines 0 $count
}
+}
- # Erase chars.
- #
- # https://vt100.net/docs/vt510-rm/ECH.html
- proc _csi_X {args} {
- set n [_default [lindex $args 0] 1]
+# Erase chars.
+#
+# https://vt100.net/docs/vt510-rm/ECH.html
+proc Term::_csi_X {args} {
+ set n [_default [lindex $args 0] 1]
- _log_cur "Erase chars ($n)" {
- # Erase characters but don't move cursor.
- variable _cur_col
- variable _cur_row
- variable _attrs
- variable _chars
+ _log_cur "Erase chars ($n)" {
+ # Erase characters but don't move cursor.
+ variable _cur_col
+ variable _cur_row
+ variable _attrs
+ variable _chars
- set lattr [array get _attrs]
- set x $_cur_col
- for {set i 0} {$i < $n} {incr i} {
- set _chars($x,$_cur_row) [list " " $lattr]
- incr x
- }
+ set lattr [array get _attrs]
+ set x $_cur_col
+ for {set i 0} {$i < $n} {incr i} {
+ set _chars($x,$_cur_row) [list " " $lattr]
+ incr x
}
}
+}
- # Cursor Backward Tabulation.
- #
- # https://vt100.net/docs/vt510-rm/CBT.html
- proc _csi_Z {args} {
- set n [_default [lindex $args 0] 1]
+# Cursor Backward Tabulation.
+#
+# https://vt100.net/docs/vt510-rm/CBT.html
+proc Term::_csi_Z {args} {
+ set n [_default [lindex $args 0] 1]
- _log_cur "Cursor Backward Tabulation ($n)" {
- variable _cur_col
+ _log_cur "Cursor Backward Tabulation ($n)" {
+ variable _cur_col
- set _cur_col [expr {max (int (($_cur_col - 1) / 8) * 8 - ($n - 1) * 8, 0)}]
- }
+ set _cur_col [expr {max (int (($_cur_col - 1) / 8) * 8 - ($n - 1) * 8, 0)}]
}
+}
- # Repeat.
- #
- # https://www.xfree86.org/current/ctlseqs.html (See `(REP)`)
- proc _csi_b {args} {
- set n [_default [lindex $args 0] 1]
+# Repeat.
+#
+# https://www.xfree86.org/current/ctlseqs.html (See `(REP)`)
+proc Term::_csi_b {args} {
+ set n [_default [lindex $args 0] 1]
- _log_cur "Repeat ($n)" {
- variable _last_char
+ _log_cur "Repeat ($n)" {
+ variable _last_char
- _insert [string repeat $_last_char $n]
- }
+ _insert [string repeat $_last_char $n]
}
+}
- # Vertical Line Position Absolute.
- #
- # https://vt100.net/docs/vt510-rm/VPA.html
- proc _csi_d {args} {
- set row [_default [lindex $args 0] 1]
+# Vertical Line Position Absolute.
+#
+# https://vt100.net/docs/vt510-rm/VPA.html
+proc Term::_csi_d {args} {
+ set row [_default [lindex $args 0] 1]
- _log_cur "Vertical Line Position Absolute ($row)" {
- variable _cur_row
- variable _rows
+ _log_cur "Vertical Line Position Absolute ($row)" {
+ variable _cur_row
+ variable _rows
- set _cur_row [expr min ($row - 1, $_rows - 1)]
- }
+ set _cur_row [expr min ($row - 1, $_rows - 1)]
}
+}
- # Reset the attributes in attributes array UPVAR_NAME to the default values.
- proc _reset_attrs { upvar_name } {
- upvar $upvar_name var
- array set var {
- intensity normal
- fg default
- bg default
- underline 0
- reverse 0
- invisible 0
- blinking 0
+# Set Mode (SM, CSI h)
+#
+# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
+proc Term::_csi_h { args } {
+ foreach item $args {
+ switch -exact -- $item {
+ 4 {
+ # Insert Mode (IRM)
+ _log "ignored: insert mode"
+ }
+ default {
+ error unsupported
+ }
}
}
+}
- # Translate the color numbers as used in proc _csi_m to a name.
- proc _color_attr { n } {
- switch -exact -- $n {
- 0 {
- return black
+# Reset Mode (RM, CSI l)
+#
+# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
+proc Term::_csi_l { args } {
+ foreach item $args {
+ switch -exact -- $item {
+ 4 {
+ # Replace Mode (IRM)
+ _log "ignored: replace mode"
+ }
+ default {
+ error unsupported
}
+ }
+ }
+}
+
+# Set Scrolling Region (DECSTBM, CSI Ps ; Ps r)
+#
+# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
+proc Term::_csi_r { top bottom } {
+ _log "ignored: set scrolling region"
+}
+
+# Window manipulation (XTWINOPS, CSI Ps ; Ps ; Ps t)
+#
+# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
+proc Term::_csi_t { arg1 arg2 arg3 } {
+ if { $arg1 == 22 && $arg2 == 0 && $arg3 == 0 } {
+ _log "ignored: Save xterm icon and window title on stack"
+ return
+ }
+
+ if { $arg1 == 23 && $arg2 == 0 && $arg3 == 0 } {
+ _log "ignored: Restore xterm icon and window title from stack"
+ return
+ }
+
+ error unsupported
+}
+
+# DECSET (CSI ? h)
+#
+# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
+proc Term::_csi_0x3f_h { args } {
+ foreach item $args {
+ switch -exact -- $item {
1 {
- return red
+ _log "ignored: Application Cursor Keys"
}
- 2 {
- return green
+ 7 {
+ _log "ignored: autowrap mode"
}
- 3 {
- return yellow
+ 1000 {
+ _log "ignored: Send Mouse X & Y on button press and release"
}
- 4 {
- return blue
+ 1006 {
+ _log "ignored: Enable SGR Mouse Mode"
}
- 5 {
- return magenta
+ 1049 {
+ _log "switch to alternate screen"
+ _set_alternate 1
}
- 6 {
- return cyan
+ default {
+ error unsupported
+ }
+ }
+ }
+}
+
+# DECRST (CSI ? l)
+#
+# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
+proc Term::_csi_0x3f_l { args } {
+ foreach item $args {
+ switch -exact -- $item {
+ 1 {
+ _log "ignored: Normal Cursor Keys"
}
7 {
- return white
+ _log "ignored: no autowrap mode"
+ }
+ 1000 {
+ _log "ignored: Don't send Mouse X & Y on button press and release"
+ }
+ 1006 {
+ _log "ignored: Disable SGR Mouse Mode"
+ }
+ 1049 {
+ _log "switch from alternate screen"
+ _set_alternate 0
+ }
+ default {
+ error "unsupported"
}
- default { error "unsupported color number: $n" }
}
}
+}
- # Select Graphic Rendition.
- #
- # https://vt100.net/docs/vt510-rm/SGR.html
- proc _csi_m {args} {
- _log_cur "Select Graphic Rendition ([join $args {, }])" {
- variable _attrs
+# Reset the attributes in attributes array UPVAR_NAME to the default values.
+proc Term::_reset_attrs { upvar_name } {
+ upvar $upvar_name var
+ array set var {
+ intensity normal
+ fg default
+ bg default
+ underline 0
+ reverse 0
+ invisible 0
+ blinking 0
+ }
+}
- foreach item $args {
- switch -exact -- $item {
- "" - 0 {
- _reset_attrs _attrs
- }
- 1 {
- set _attrs(intensity) bold
- }
- 2 {
- set _attrs(intensity) dim
- }
- 4 {
- set _attrs(underline) 1
- }
- 5 {
- set _attrs(blinking) 1
- }
- 7 {
- set _attrs(reverse) 1
- }
- 8 {
- set _attrs(invisible) 1
- }
- 22 {
- set _attrs(intensity) normal
- }
- 24 {
- set _attrs(underline) 0
- }
- 25 {
- set _attrs(blinking) 0
- }
- 27 {
- set _attrs(reverse) 0
- }
- 28 {
- set _attrs(invisible) 0
- }
- 30 - 31 - 32 - 33 - 34 - 35 - 36 - 37 {
- set _attrs(fg) [_color_attr [expr $item - 30]]
- }
- 39 {
- set _attrs(fg) default
- }
- 40 - 41 - 42 - 43 - 44 - 45 - 46 - 47 {
- set _attrs(bg) [_color_attr [expr $item - 40]]
- }
- 49 {
- set _attrs(bg) default
- }
+# Translate the color numbers as used in proc _csi_m to a name.
+proc Term::_color_attr { n } {
+ switch -exact -- $n {
+ 0 {
+ return black
+ }
+ 1 {
+ return red
+ }
+ 2 {
+ return green
+ }
+ 3 {
+ return yellow
+ }
+ 4 {
+ return blue
+ }
+ 5 {
+ return magenta
+ }
+ 6 {
+ return cyan
+ }
+ 7 {
+ return white
+ }
+ default { error "unsupported color number: $n" }
+ }
+}
+
+# Select Graphic Rendition.
+#
+# https://vt100.net/docs/vt510-rm/SGR.html
+proc Term::_csi_m {args} {
+ if { [llength $args] == 0 } {
+ # Apply default.
+ set args [list 0]
+ }
+
+ _log_cur "Select Graphic Rendition ([join $args {, }])" {
+ variable _attrs
+
+ foreach item $args {
+ switch -exact -- $item {
+ "" - 0 {
+ _reset_attrs _attrs
+ }
+ 1 {
+ set _attrs(intensity) bold
+ }
+ 2 {
+ set _attrs(intensity) dim
+ }
+ 4 {
+ set _attrs(underline) 1
+ }
+ 5 {
+ set _attrs(blinking) 1
+ }
+ 7 {
+ set _attrs(reverse) 1
+ }
+ 8 {
+ set _attrs(invisible) 1
+ }
+ 22 {
+ set _attrs(intensity) normal
+ }
+ 24 {
+ set _attrs(underline) 0
+ }
+ 25 {
+ set _attrs(blinking) 0
+ }
+ 27 {
+ set _attrs(reverse) 0
+ }
+ 28 {
+ set _attrs(invisible) 0
+ }
+ 30 - 31 - 32 - 33 - 34 - 35 - 36 - 37 {
+ set _attrs(fg) [_color_attr [expr $item - 30]]
+ }
+ 39 {
+ set _attrs(fg) default
+ }
+ 40 - 41 - 42 - 43 - 44 - 45 - 46 - 47 {
+ set _attrs(bg) [_color_attr [expr $item - 40]]
+ }
+ 49 {
+ set _attrs(bg) default
}
}
}
}
+}
- # Insert string at the cursor location.
- proc _insert {str} {
- _log_cur "Inserted string '$str'" {
- _log "Inserting string '$str'"
-
- variable _cur_col
- variable _cur_row
- variable _rows
- variable _cols
- variable _attrs
- variable _chars
- set lattr [array get _attrs]
- foreach char [split $str {}] {
- _log_cur " Inserted char '$char'" {
- set _chars($_cur_col,$_cur_row) [list $char $lattr]
- incr _cur_col
- if {$_cur_col >= $_cols} {
- set _cur_col 0
- incr _cur_row
- if {$_cur_row >= $_rows} {
- error "FIXME scroll"
- }
+# Request Terminal Parameters (DECREQTPARM)
+#
+# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
+# https://vt100.net/docs/vt100-ug/chapter3.html
+proc Term::_csi_x {} {
+ # Ignore.
+}
+
+# Insert string at the cursor location.
+proc Term::_insert {str} {
+ _log_cur "Inserted string '$str'" {
+ _log "Inserting string '$str'"
+
+ variable _cur_col
+ variable _cur_row
+ variable _rows
+ variable _cols
+ variable _attrs
+ variable _chars
+ set lattr [array get _attrs]
+ foreach char [split $str {}] {
+ _log_cur " Inserted char '$char'" {
+ set _chars($_cur_col,$_cur_row) [list $char $lattr]
+ incr _cur_col
+ if {$_cur_col >= $_cols} {
+ set _cur_col 0
+ incr _cur_row
+ if {$_cur_row >= $_rows} {
+ error "FIXME scroll"
}
}
}
}
+
+ variable _last_char
+ set _last_char [string index $str end]
}
+}
- # Move the cursor to the (0-based) COL and ROW positions.
- proc _move_cursor { col row } {
- variable _cols
- variable _rows
- variable _cur_col
- variable _cur_row
+# Move the cursor to the (0-based) COL and ROW positions.
+proc Term::_move_cursor { col row } {
+ variable _cols
+ variable _rows
+ variable _cur_col
+ variable _cur_row
- if { $col < 0 || $col >= $_cols } {
- error "_move_cursor: invalid col value: $col"
- }
+ if { $col < 0 || $col >= $_cols } {
+ error "_move_cursor: invalid col value: $col"
+ }
+
+ if { $row < 0 || $row >= $_rows } {
+ error "_move_cursor: invalid row value: $row"
+ }
- if { $row < 0 || $row >= $_rows } {
- error "_move_cursor: invalid row value: $row"
- }
+ set _cur_col $col
+ set _cur_row $row
+}
- set _cur_col $col
- set _cur_row $row
+# Enable or disable alternate screen.
+proc Term::_set_alternate { enable } {
+ variable _alternate
+ if { $enable == $_alternate } {
+ return
}
+ set _alternate $enable
- # Initialize.
- proc _setup {rows cols} {
- global stty_init
- set stty_init "rows $rows columns $cols"
+ variable _attrs
+ variable _chars
+ variable _cur_col
+ variable _cur_row
- variable _rows
- variable _cols
- variable _cur_col
- variable _cur_row
- variable _attrs
- variable _resize_count
+ variable _save_attrs
+ variable _save_chars
+ variable _save_cur_col
+ variable _save_cur_row
- set _rows $rows
- set _cols $cols
- set _cur_col 0
- set _cur_row 0
- set _resize_count 0
- _reset_attrs _attrs
-
- _clear_lines 0 $_rows
- }
-
- # Accept some output from gdb and update the screen.
- # Return 1 if successful, or 0 if a timeout occurred.
- proc accept_gdb_output { } {
- global expect_out
- gdb_expect {
- -re "^\[\x07\x08\x0a\x0d\]" {
- scan $expect_out(0,string) %c val
- set hexval [format "%02x" $val]
- _log "wait_for: _ctl_0x${hexval}"
- _ctl_0x${hexval}
- }
- -re "^\x1b(\[0-9a-zA-Z\])" {
- _log "wait_for: unsupported escape"
- error "unsupported escape"
- }
- -re "^\x1b\\\[(\[0-9;\]*)(\[a-zA-Z@\])" {
- set cmd $expect_out(2,string)
- set params [split $expect_out(1,string) ";"]
- _log "wait_for: _csi_$cmd <<<$expect_out(1,string)>>>"
- eval _csi_$cmd $params
- }
- -re "^\[^\x07\x08\x0a\x0d\x1b\]+" {
- _insert $expect_out(0,string)
- variable _last_char
- set _last_char [string index $expect_out(0,string) end]
- }
+ variable _alternate_setup
- timeout {
- # Assume a timeout means we somehow missed the
- # expected result, and carry on.
- warning "timeout in accept_gdb_output"
- dump_screen
- return 0
- }
- }
+ if { $_alternate_setup } {
+ set tmp $_save_chars
+ }
+ set _save_chars [array get _chars]
+ if { $_alternate_setup } {
+ array set _chars $tmp
+ }
- return 1
+ if { $_alternate_setup } {
+ set tmp $_save_attrs
+ }
+ set _save_attrs [array get _attrs]
+ if { $_alternate_setup } {
+ array set _attrs $tmp
}
- # Print arg using "verbose -log" if DEBUG_TUI_MATCHING == 1.
- proc debug_tui_matching { arg } {
- set debug 0
- if { [info exists ::DEBUG_TUI_MATCHING] } {
- set debug $::DEBUG_TUI_MATCHING
- }
+ if { $_alternate_setup } {
+ set tmp $_save_cur_col
+ }
+ set _save_cur_col $_cur_col
+ if { $_alternate_setup } {
+ set _cur_col $tmp
+ }
- if { ! $debug } {
- return
- }
+ if { $_alternate_setup } {
+ set tmp $_save_cur_row
+ }
+ set _save_cur_row $_cur_row
+ if { $_alternate_setup } {
+ set _cur_row $tmp
+ }
- verbose -log "$arg"
+ if { ! $_alternate_setup } {
+ variable _rows
+ variable _cols
+ _setup $_rows $_cols
+ set _alternate_setup 1
}
+}
- # Accept some output from gdb and update the screen. WAIT_FOR is
- # a regexp matching the line to wait for. Return 0 on timeout, 1
- # on success.
- proc wait_for {wait_for} {
- global gdb_prompt
- variable _cur_col
- variable _cur_row
+# Initialize.
+proc Term::_setup {rows cols} {
+ global stty_init
+ set stty_init "rows $rows columns $cols"
+
+ variable _rows
+ variable _cols
+ variable _cur_col
+ variable _cur_row
+ variable _attrs
+ variable _resize_count
+
+ set _rows $rows
+ set _cols $cols
+ set _cur_col 0
+ set _cur_row 0
+ set _resize_count 0
+ _reset_attrs _attrs
- set fn "wait_for"
+ _clear_lines 0 $_rows
+}
- set prompt_wait_for "(^|\\|)$gdb_prompt \$"
- if { $wait_for == "" } {
- set wait_for $prompt_wait_for
+# Accept some output from gdb and update the screen.
+# Return 1 if successful, or 0 if a timeout occurred.
+proc Term::accept_gdb_output { {warn 1} } {
+ global expect_out
+
+ set ctls "\x07\x08\x0a\x0d"
+ set esc "\x1b"
+ set re_ctls "\[$ctls\]"
+ set re_others "\[^$esc$ctls\]"
+ set have_esc 0
+ gdb_expect {
+ -re ^$re_ctls {
+ scan $expect_out(0,string) %c val
+ set hexval [format "%02x" $val]
+ _log "wait_for: _ctl_0x${hexval}"
+ _ctl_0x${hexval}
+ }
+ -re "^$esc" {
+ _log "wait_for: ESC"
+ set have_esc 1
+ }
+ -re "^$re_others+" {
+ _insert $expect_out(0,string)
+ }
+
+ timeout {
+ # Assume a timeout means we somehow missed the
+ # expected result, and carry on.
+ warning "timeout in accept_gdb_output"
+ dump_screen
+ return 0
}
+ }
- debug_tui_matching "$fn: regexp: '$wait_for'"
+ if { !$have_esc } {
+ return 1
+ }
- while 1 {
- if { [accept_gdb_output] == 0 } {
- return 0
- }
+ set re_csi [string_to_regexp "\["]
+ set have_csi 0
+ gdb_expect {
+ -re "^(\[0-9a-zA-Z\])" {
+ _log "wait_for: unsupported escape"
+ error "unsupported escape"
+ }
+ -re "^(\[\\(\])(\[a-zA-Z\])" {
+ scan $expect_out(1,string) %c val
+ set hexval [format "%02x" $val]
+ set cmd $expect_out(2,string)
+ eval _esc_0x${hexval}_$cmd
+ }
+ -re "^(\[=>\])" {
+ scan $expect_out(1,string) %c val
+ set hexval [format "%02x" $val]
+ _esc_0x$hexval
+ }
+ -re "^$re_csi" {
+ _log "wait_for: CSI"
+ set have_csi 1
+ }
- # If the cursor appears just after the prompt, return. It
- # isn't reliable to check this only after an insertion,
- # because curses may make "unusual" redrawing decisions.
- if {$wait_for == "$prompt_wait_for"} {
- set prev [get_line $_cur_row $_cur_col]
- } else {
- set prev [get_line $_cur_row]
- }
- if {[regexp -- $wait_for $prev]} {
- debug_tui_matching "$fn: match: '$prev'"
- if {$wait_for == "$prompt_wait_for"} {
- break
- }
- set wait_for $prompt_wait_for
- debug_tui_matching "$fn: regexp prompt: '$wait_for'"
- } else {
- debug_tui_matching "$fn: mismatch: '$prev'"
+ timeout {
+ # Assume a timeout means we somehow missed the
+ # expected result, and carry on.
+ if { $warn } {
+ warning "timeout in accept_gdb_output following ESC"
+ dump_screen
}
+ _insert "^\["
+ return 0
}
+ }
+ if { !$have_csi } {
return 1
}
- # Accept some output from gdb and update the screen. Wait for the screen
- # region X/Y/WIDTH/HEIGTH to matches REGEXP. Return 0 on timeout, 1 on
- # success.
- proc wait_for_region_contents {x y width height regexp} {
- while 1 {
- if { [accept_gdb_output] == 0 } {
- return 0
- }
-
- if { [check_region_contents_p $x $y $width $height $regexp] } {
- break
+ set re_csi_prefix {[?]}
+ set re_csi_args {[0-9;]}
+ set re_csi_cmd {[a-zA-Z@`]}
+ gdb_expect {
+ -re "^($re_csi_cmd)" {
+ set cmd $expect_out(1,string)
+ _log "wait_for: _csi_$cmd"
+ eval _csi_$cmd
+ }
+ -re "^($re_csi_args*)($re_csi_cmd)" {
+ set params [split $expect_out(1,string) ";"]
+ set cmd $expect_out(2,string)
+ _log "wait_for: _csi_$cmd <<<$params>>>"
+ eval _csi_$cmd $params
+ }
+ -re "^($re_csi_prefix?)($re_csi_args*)($re_csi_cmd)" {
+ set prefix $expect_out(1,string)
+ set params [split $expect_out(2,string) ";"]
+ set cmd $expect_out(3,string)
+ scan $prefix %c val
+ set hexval [format "%02x" $val]
+ _log "wait_for: _csi_0x${hexval}_$cmd <<<$expect_out(1,string)>>>"
+ eval _csi_0x${hexval}_$cmd $params
+ }
+
+ timeout {
+ # Assume a timeout means we somehow missed the
+ # expected result, and carry on.
+ if { $warn } {
+ warning "timeout in accept_gdb_output following CSI"
+ dump_screen
}
+ _insert "^\[\["
+ return 0
}
+ }
- return 1
+ return 1
+}
+
+# Print arg using "verbose -log" if DEBUG_TUI_MATCHING == 1.
+proc Term::debug_tui_matching { arg } {
+ set debug 0
+ if { [info exists ::DEBUG_TUI_MATCHING] } {
+ set debug $::DEBUG_TUI_MATCHING
}
- # Setup the terminal with dimensions ROWSxCOLS, TERM=ansi, and execute
- # BODY.
- proc with_tuiterm {rows cols body} {
- global env stty_init
- save_vars {env(TERM) env(NO_COLOR) stty_init} {
- setenv TERM ansi
- setenv NO_COLOR ""
- _setup $rows $cols
+ if { ! $debug } {
+ return
+ }
- uplevel $body
- }
+ verbose -log "$arg"
+}
+
+# Accept some output from gdb and update the screen. WAIT_FOR is
+# a regexp matching the line to wait for. Return 0 on timeout, 1
+# on success.
+proc Term::wait_for {wait_for} {
+ global gdb_prompt
+ variable _cur_col
+ variable _cur_row
+
+ set fn "wait_for"
+
+ set prompt_wait_for "(^|\\|)$gdb_prompt \$"
+ if { $wait_for == "" } {
+ set wait_for $prompt_wait_for
}
- # Like ::clean_restart, but ensures that gdb starts in an
- # environment where the TUI can work. ROWS and COLS are the size
- # of the terminal. EXECUTABLE, if given, is passed to
- # clean_restart.
- proc clean_restart {rows cols {executable {}}} {
- with_tuiterm $rows $cols {
- save_vars { ::GDBFLAGS } {
- # Make GDB not print the directory names. Use this setting to
- # remove the differences in test runs due to varying directory
- # names.
- append ::GDBFLAGS " -ex \"set filename-display basename\""
+ debug_tui_matching "$fn: regexp: '$wait_for'"
- if {$executable == ""} {
- ::clean_restart
- } else {
- ::clean_restart $executable
- }
- }
+ while 1 {
+ if { [accept_gdb_output] == 0 } {
+ return 0
+ }
- ::gdb_test_no_output "set pagination off"
+ # If the cursor appears just after the prompt, return. It
+ # isn't reliable to check this only after an insertion,
+ # because curses may make "unusual" redrawing decisions.
+ if {$wait_for == "$prompt_wait_for"} {
+ set prev [get_line $_cur_row $_cur_col]
+ } else {
+ set prev [get_line $_cur_row]
}
- }
- # Generate prompt on TUIterm.
- proc gen_prompt {} {
- # Generate a prompt.
- send_gdb "echo\n"
+ if { ![regexp -- $wait_for $prev] } {
+ debug_tui_matching "$fn: mismatch: '$prev'"
+ continue
+ }
- # Drain the output before the prompt.
- gdb_expect {
- -re "echo\r\n" {
+ if {$wait_for == "$prompt_wait_for"} {
+ # We've detected that the cursor is just after the prompt.
+ # Now check that there's nothing else on the line.
+ set prev [get_line $_cur_row]
+ if { ![regexp -- "(^|\\|)$gdb_prompt +($|\\||\\+)" $prev] } {
+ debug_tui_matching "$fn: mismatch: '$prev'"
+ continue
}
}
- # Interpret prompt using TUIterm.
- wait_for ""
- }
+ debug_tui_matching "$fn: match: '$prev'"
- # Setup ready for starting the tui, but don't actually start it.
- # Returns 1 on success, 0 if TUI tests should be skipped.
- proc prepare_for_tui {} {
- if { [is_remote host] } {
- # In clean_restart, we're using "setenv TERM ansi", which has
- # effect on build. If we have [is_remote host] == 0, so
- # build == host, then it also has effect on host. But for
- # [is_remote host] == 1, it has no effect on host.
- return 0
+ if {$wait_for == "$prompt_wait_for"} {
+ # Matched the prompt, we're done.
+ break
}
- if {![allow_tui_tests]} {
+ # Now try to match the prompt.
+ set wait_for $prompt_wait_for
+ debug_tui_matching "$fn: regexp prompt: '$wait_for'"
+ }
+
+ return 1
+}
+
+# Accept some output from gdb and update the screen. Wait for the screen
+# region X/Y/WIDTH/HEIGTH to matches REGEXP. Return 0 on timeout, 1 on
+# success.
+proc Term::wait_for_region_contents {x y width height regexp} {
+ while 1 {
+ if { [accept_gdb_output] == 0 } {
return 0
}
- gdb_test_no_output "set tui border-kind ascii"
- gdb_test_no_output "maint set tui-resize-message on"
- return 1
+ if { [check_region_contents_p $x $y $width $height $regexp] } {
+ break
+ }
}
- # Start the TUI. Returns 1 on success, 0 if TUI tests should be
- # skipped.
- proc enter_tui {} {
- if {![prepare_for_tui]} {
+ return 1
+}
+
+# Accept some output from gdb and update the screen. Wait for the current
+# screen line to match REGEXP and cursor position POS, unless POS is empty.
+# Return 0 on timeout, 1 on success.
+proc Term::wait_for_line { regexp {pos ""} } {
+ variable _cur_row
+ variable _cur_col
+ variable _cols
+
+ while 1 {
+ if { [accept_gdb_output] == 0 } {
return 0
}
- command_no_prompt_prefix "tui enable"
- return 1
- }
+ if { ![check_region_contents_p 0 $_cur_row $_cols 1 $regexp] } {
+ continue
+ }
- # Send the command CMD to gdb, then wait for a gdb prompt to be
- # seen in the TUI. CMD should not end with a newline -- that will
- # be supplied by this function.
- proc command {cmd} {
- global gdb_prompt
- send_gdb "$cmd\n"
- set str [string_to_regexp $cmd]
- set str "(^|\\|)$gdb_prompt $str"
- wait_for $str
- }
-
- # As proc command, but don't wait for an initial prompt. This is used for
- # initial terminal commands, where there's no prompt yet.
- proc command_no_prompt_prefix {cmd} {
- gen_prompt
- command $cmd
- }
-
- # Apply the attribute list in ATTRS to attributes array UPVAR_NAME.
- # Return a string annotating the changed attributes.
- proc apply_attrs { upvar_name attrs } {
- set res ""
- upvar $upvar_name var
- foreach { attr val } $attrs {
- if { $var($attr) != $val } {
- append res "<$attr:$val>"
- set var($attr) $val
- }
+ if { $pos == "" || $_cur_col == $pos } {
+ break
}
+ }
- return $res
+ return 1
+}
+
+# In BODY, when using Term::with_tuiterm, use TERM instead of the default.
+
+proc Term::with_term { term body } {
+ save_vars { Term::_TERM } {
+ set Term::_TERM $term
+ uplevel $body
}
+}
- # Return the text of screen line N. Lines are 0-based. If C is given,
- # stop before column C. Columns are also zero-based. If ATTRS, annotate
- # with attributes.
- proc get_line_1 {n c attrs} {
- variable _rows
- # This can happen during resizing, if the cursor seems to
- # temporarily be off-screen.
- if {$n >= $_rows} {
- return ""
+# Setup the terminal with dimensions ROWSxCOLS, TERM=ansi, and execute
+# BODY.
+proc Term::with_tuiterm {rows cols body} {
+ global env stty_init
+ variable _TERM
+ save_vars {env(TERM) env(NO_COLOR) stty_init} {
+ if { $Term::_TERM != "" } {
+ setenv TERM $Term::_TERM
+ } elseif { [ishost *-*-*bsd*] } {
+ setenv TERM ansiw
+ } else {
+ setenv TERM ansi
}
+ # Save active TERM variable.
+ set Term::_TERM $env(TERM)
- set result ""
- variable _cols
- variable _chars
- set c [_default $c $_cols]
- set x 0
- if { $attrs } {
- _reset_attrs line_attrs
- }
- while {$x < $c} {
- if { $attrs } {
- set char_attrs [lindex $_chars($x,$n) 1]
- append result [apply_attrs line_attrs $char_attrs]
+ setenv NO_COLOR ""
+ _setup $rows $cols
+
+ uplevel $body
+ }
+}
+
+# Like ::clean_restart, but ensures that gdb starts in an
+# environment where the TUI can work. ROWS and COLS are the size
+# of the terminal. EXECUTABLE, if given, is passed to
+# clean_restart.
+proc Term::clean_restart {rows cols {executable {}}} {
+ with_tuiterm $rows $cols {
+ save_vars { ::GDBFLAGS } {
+ # Make GDB not print the directory names. Use this setting to
+ # remove the differences in test runs due to varying directory
+ # names.
+ append ::GDBFLAGS " -ex \"set filename-display basename\""
+
+ if {$executable == ""} {
+ ::clean_restart
+ } else {
+ ::clean_restart $executable
}
- append result [lindex $_chars($x,$n) 0]
- incr x
}
- if { $attrs } {
- _reset_attrs zero_attrs
- set char_attrs [array get zero_attrs]
- append result [apply_attrs line_attrs $char_attrs]
+
+ ::gdb_test_no_output "set pagination off"
+ }
+}
+
+# Generate prompt on TUIterm.
+proc Term::gen_prompt {} {
+ # Generate a prompt.
+ send_gdb "echo\n"
+
+ # Drain the output before the prompt.
+ gdb_expect {
+ -re "echo\r\n" {
}
- return $result
}
- # Return the text of screen line N, without attributes. Lines are
- # 0-based. If C is given, stop before column C. Columns are also
- # zero-based.
- proc get_line {n {c ""} } {
- return [get_line_1 $n $c 0]
+ # Interpret prompt using TUIterm.
+ wait_for ""
+}
+
+# Setup ready for starting the tui, but don't actually start it.
+# Returns 1 on success, 0 if TUI tests should be skipped.
+proc Term::prepare_for_tui {} {
+ if { [is_remote host] } {
+ # In clean_restart, we're using "setenv TERM ansi", which has
+ # effect on build. If we have [is_remote host] == 0, so
+ # build == host, then it also has effect on host. But for
+ # [is_remote host] == 1, it has no effect on host.
+ return 0
}
- # As get_line, but annotate with attributes.
- proc get_line_with_attrs {n {c ""}} {
- return [get_line_1 $n $c 1]
+ if {![allow_tui_tests]} {
+ return 0
}
- # Get just the character at (X, Y).
- proc get_char {x y} {
- variable _chars
- return [lindex $_chars($x,$y) 0]
+ gdb_test_no_output "set tui border-kind ascii"
+ gdb_test_no_output "maint set tui-resize-message on"
+ # When matching GDB output using Term::wait_for, the number of
+ # matching attempts in wait_for can be influenced by CLI styling.
+ # Disable it by default to avoid this.
+ gdb_test_no_output "set style enabled off"
+ return 1
+}
+
+# Start the TUI. Returns 1 on success, 0 if TUI tests should be
+# skipped.
+proc Term::enter_tui {} {
+ if {![prepare_for_tui]} {
+ return 0
}
- # Get the entire screen as a string.
- proc get_all_lines {} {
- variable _rows
- variable _cols
- variable _chars
+ command_no_prompt_prefix "tui enable"
+ return 1
+}
- set result ""
- for {set y 0} {$y < $_rows} {incr y} {
- for {set x 0} {$x < $_cols} {incr x} {
- append result [lindex $_chars($x,$y) 0]
- }
- append result "\n"
+# Send the command CMD to gdb, then wait for a gdb prompt to be
+# seen in the TUI. CMD should not end with a newline -- that will
+# be supplied by this function.
+proc Term::command {cmd} {
+ global gdb_prompt
+ send_gdb "$cmd\n"
+ set str [string_to_regexp $cmd]
+ set str "(^|\\|)$gdb_prompt $str"
+ wait_for $str
+}
+
+# As proc command, but don't wait for an initial prompt. This is used for
+# initial terminal commands, where there's no prompt yet.
+proc Term::command_no_prompt_prefix {cmd} {
+ gen_prompt
+ command $cmd
+}
+
+# Apply the attribute list in ATTRS to attributes array UPVAR_NAME.
+# Return a string annotating the changed attributes.
+proc Term::apply_attrs { upvar_name attrs } {
+ set res ""
+ upvar $upvar_name var
+ foreach { attr val } $attrs {
+ if { $var($attr) != $val } {
+ append res "<$attr:$val>"
+ set var($attr) $val
}
+ }
- return $result
+ return $res
+}
+
+# Return the text of screen line N. Lines are 0-based. Start at column
+# X. If C is non-empty, stop before column C. Columns are also
+# zero-based. If ATTRS, annotate with attributes.
+proc Term::get_string {n x c {attrs 0}} {
+ variable _rows
+ # This can happen during resizing, if the cursor seems to
+ # temporarily be off-screen.
+ if {$n >= $_rows} {
+ return ""
}
- # Get the text just before the cursor.
- proc get_current_line {} {
- variable _cur_col
- variable _cur_row
- return [get_line $_cur_row $_cur_col]
+ set result ""
+ variable _cols
+ variable _chars
+ set c [_default $c $_cols]
+ if { $attrs } {
+ _reset_attrs line_attrs
}
+ while {$x < $c} {
+ if { $attrs } {
+ set char_attrs [lindex $_chars($x,$n) 1]
+ append result [apply_attrs line_attrs $char_attrs]
+ }
+ append result [lindex $_chars($x,$n) 0]
+ incr x
+ }
+ if { $attrs } {
+ _reset_attrs zero_attrs
+ set char_attrs [array get zero_attrs]
+ append result [apply_attrs line_attrs $char_attrs]
+ }
+ return $result
+}
- # Helper function for check_box. Returns empty string if the box
- # is found, description of why not otherwise.
- proc _check_box {x y width height} {
- set x2 [expr {$x + $width - 1}]
- set y2 [expr {$y + $height - 1}]
+# Return the text of screen line N. Lines are 0-based. Start at column
+# X. If C is non-empty, stop before column C. Columns are also
+# zero-based. Annotate with attributes.
+proc Term::get_string_with_attrs { n x c } {
+ return [get_string $n $x $c 1]
+}
- verbose -log "_check_box x=$x, y=$y, x2=$x2, y2=$y2, width=$width, height=$height"
+# Return the text of screen line N. Lines are 0-based. If C is
+# non-empty, stop before column C. Columns are also zero-based. If
+# ATTRS, annotate with attributes.
+proc Term::get_line_1 {n c attrs} {
+ return [get_string $n 0 $c $attrs]
+}
- set c [get_char $x $y]
- if {$c != "+"} {
- return "ul corner is $c, not +"
- }
+# Return the text of screen line N, without attributes. Lines are
+# 0-based. If C is given, stop before column C. Columns are also
+# zero-based.
+proc Term::get_line {n {c ""} } {
+ return [get_line_1 $n $c 0]
+}
- set c [get_char $x $y2]
- if {$c != "+"} {
- return "ll corner is $c, not +"
- }
+# As get_line, but annotate with attributes.
+proc Term::get_line_with_attrs {n {c ""}} {
+ return [get_line_1 $n $c 1]
+}
- set c [get_char $x2 $y]
- if {$c != "+"} {
- return "ur corner is $c, not +"
- }
+# Get just the character at (X, Y).
+proc Term::get_char {x y} {
+ variable _chars
+ return [lindex $_chars($x,$y) 0]
+}
- set c [get_char $x2 $y2]
- if {$c != "+"} {
- return "lr corner is $c, not +"
- }
+# Get the entire screen as a string.
+proc Term::get_all_lines {} {
+ variable _rows
+ variable _cols
+ variable _chars
- # Note we do not check the full horizonal borders of the box.
- # The top will contain a title, and the bottom may as well, if
- # it is overlapped by some other border. However, at most a
- # title should appear as '+-VERY LONG TITLE-+', so we can
- # check for the '+-' on the left, and '-+' on the right.
- set c [get_char [expr {$x + 1}] $y]
- if {$c != "-"} {
- return "ul title padding is $c, not -"
+ set result ""
+ for {set y 0} {$y < $_rows} {incr y} {
+ for {set x 0} {$x < $_cols} {incr x} {
+ append result [lindex $_chars($x,$y) 0]
}
+ append result "\n"
+ }
- set c [get_char [expr {$x2 - 1}] $y]
- if {$c != "-"} {
- return "ul title padding is $c, not -"
- }
+ return $result
+}
- # Now check the vertical borders.
- for {set i [expr {$y + 1}]} {$i < $y2 - 1} {incr i} {
- set c [get_char $x $i]
- if {$c != "|"} {
- return "left side $i is $c, not |"
- }
+# Get the text just before the cursor.
+proc Term::get_current_line {} {
+ variable _cur_col
+ variable _cur_row
+ return [get_line $_cur_row $_cur_col]
+}
- set c [get_char $x2 $i]
- if {$c != "|"} {
- return "right side $i is $c, not |"
- }
- }
+# Helper function for check_box. Returns empty string if the box
+# is found, description of why not otherwise.
+proc Term::_check_box {x y width height} {
+ set x2 [expr {$x + $width - 1}]
+ set y2 [expr {$y + $height - 1}]
- return ""
+ verbose -log "_check_box x=$x, y=$y, x2=$x2, y2=$y2, width=$width, height=$height"
+
+ set c [get_char $x $y]
+ if {$c != "+"} {
+ return "ul corner is $c, not +"
}
- # Check for a box at the given coordinates.
- proc check_box {test_name x y width height} {
- dump_box $x $y $width $height
- set why [_check_box $x $y $width $height]
- if {$why == ""} {
- pass $test_name
- } else {
- fail "$test_name ($why)"
- }
+ set c [get_char $x $y2]
+ if {$c != "+"} {
+ return "ll corner is $c, not +"
}
- # Wait until a box appears at the given coordinates.
- proc wait_for_box {test_name x y width height} {
- while 1 {
- if { [accept_gdb_output] == 0 } {
- return 0
- }
+ set c [get_char $x2 $y]
+ if {$c != "+"} {
+ return "ur corner is $c, not +"
+ }
- set why [_check_box $x $y $width $height]
- if {$why == ""} {
- pass $test_name
- break
- }
- }
+ set c [get_char $x2 $y2]
+ if {$c != "+"} {
+ return "lr corner is $c, not +"
}
- # Check whether the text contents of the terminal match the
- # regular expression. Note that text styling is not considered.
- proc check_contents {test_name regexp} {
- dump_screen
- set contents [get_all_lines]
- gdb_assert {[regexp -- $regexp $contents]} $test_name
+ # Note we do not check the full horizonal borders of the box.
+ # The top will contain a title, and the bottom may as well, if
+ # it is overlapped by some other border. However, at most a
+ # title should appear as '+-VERY LONG TITLE-+', so we can
+ # check for the '+-' on the left, and '-+' on the right.
+ set c [get_char [expr {$x + 1}] $y]
+ if {$c != "-"} {
+ return "ul title padding is $c, not -"
}
- # As check_contents, but check that the text contents of the terminal does
- # not match the regular expression.
- proc check_contents_not {test_name regexp} {
- dump_screen
- set contents [get_all_lines]
- gdb_assert {![regexp -- $regexp $contents]} $test_name
+ set c [get_char [expr {$x2 - 1}] $y]
+ if {$c != "-"} {
+ return "ul title padding is $c, not -"
}
- # Get the region of the screen described by X, Y, WIDTH, and
- # HEIGHT, and separate the lines using SEP. If ATTRS is true then
- # include attribute information in the output.
- proc get_region { x y width height sep { attrs false } } {
- variable _chars
+ # Now check the vertical borders.
+ for {set i [expr {$y + 1}]} {$i < $y2 - 1} {incr i} {
+ set c [get_char $x $i]
+ if {$c != "|"} {
+ return "left side $i is $c, not |"
+ }
- if { $attrs } {
- _reset_attrs region_attrs
+ set c [get_char $x2 $i]
+ if {$c != "|"} {
+ return "right side $i is $c, not |"
}
+ }
- # Grab the contents of the box, join each line together
- # using $sep.
- set result ""
- for {set yy $y} {$yy < [expr {$y + $height}]} {incr yy} {
- if {$yy > $y} {
- # Add the end of line sequence only if this isn't the
- # first line.
- append result $sep
- }
- for {set xx $x} {$xx < [expr {$x + $width}]} {incr xx} {
- if { $attrs } {
- set char_attrs [lindex $_chars($xx,$yy) 1]
- append result [apply_attrs region_attrs $char_attrs]
- }
+ return ""
+}
- append result [get_char $xx $yy]
- }
+# Check for a box at the given coordinates.
+proc Term::check_box {test_name x y width height} {
+ dump_box $x $y $width $height
+ set why [_check_box $x $y $width $height]
+ if {$why == ""} {
+ pass $test_name
+ } else {
+ fail "$test_name ($why)"
+ }
+}
+
+# Wait until a box appears at the given coordinates.
+proc Term::wait_for_box {test_name x y width height} {
+ while 1 {
+ if { [accept_gdb_output] == 0 } {
+ return 0
}
- if { $attrs } {
- _reset_attrs zero_attrs
- set char_attrs [array get zero_attrs]
- append result [apply_attrs region_attrs $char_attrs]
+
+ set why [_check_box $x $y $width $height]
+ if {$why == ""} {
+ pass $test_name
+ break
}
- return $result
}
+}
- # Check that the region of the screen described by X, Y, WIDTH,
- # and HEIGHT match REGEXP. This is like check_contents except
- # only part of the screen is checked. This can be used to check
- # the contents within a box (though check_box_contents is a better
- # choice for boxes with a border). Return 1 if check succeeded.
- proc check_region_contents_p { x y width height regexp } {
- variable _chars
- dump_box $x $y $width $height
+# Check whether the text contents of the terminal match the
+# regular expression. Note that text styling is not considered.
+proc Term::check_contents {test_name regexp} {
+ dump_screen
+ set contents [get_all_lines]
+ gdb_assert {[regexp -- $regexp $contents]} $test_name
+}
- # Now grab the contents of the box, join each line together
- # with a '\r\n' sequence and match against REGEXP.
- set result [get_region $x $y $width $height "\r\n"]
- return [regexp -- $regexp $result]
- }
+# As check_contents, but check that the text contents of the terminal does
+# not match the regular expression.
+proc Term::check_contents_not {test_name regexp} {
+ dump_screen
+ set contents [get_all_lines]
+ gdb_assert {![regexp -- $regexp $contents]} $test_name
+}
- # Check that the region of the screen described by X, Y, WIDTH,
- # and HEIGHT match REGEXP. As check_region_contents_p, but produce
- # a pass/fail message.
- proc check_region_contents { test_name x y width height regexp } {
- set ok [check_region_contents_p $x $y $width $height $regexp]
- gdb_assert {$ok} $test_name
- }
+# Get the region of the screen described by X, Y, WIDTH, and
+# HEIGHT, and separate the lines using SEP. If ATTRS is true then
+# include attribute information in the output.
+proc Term::get_region { x y width height sep { attrs false } } {
+ variable _chars
- # Check the contents of a box on the screen. This is a little
- # like check_contents, but doesn't check the whole screen
- # contents, only the contents of a single box. This procedure
- # includes (effectively) a call to check_box to ensure there is a
- # box where expected, if there is then the contents of the box are
- # matched against REGEXP.
- proc check_box_contents {test_name x y width height regexp} {
- variable _chars
+ if { $attrs } {
+ _reset_attrs region_attrs
+ }
- dump_box $x $y $width $height
- set why [_check_box $x $y $width $height]
- if {$why != ""} {
- fail "$test_name (box check: $why)"
- return
+ # Grab the contents of the box, join each line together
+ # using $sep.
+ set result ""
+ for {set yy $y} {$yy < [expr {$y + $height}]} {incr yy} {
+ if {$yy > $y} {
+ # Add the end of line sequence only if this isn't the
+ # first line.
+ append result $sep
}
+ for {set xx $x} {$xx < [expr {$x + $width}]} {incr xx} {
+ if { $attrs } {
+ set char_attrs [lindex $_chars($xx,$yy) 1]
+ append result [apply_attrs region_attrs $char_attrs]
+ }
- check_region_contents $test_name [expr {$x + 1}] [expr {$y + 1}] \
- [expr {$width - 2}] [expr {$height - 2}] $regexp
+ append result [get_char $xx $yy]
+ }
+ }
+ if { $attrs } {
+ _reset_attrs zero_attrs
+ set char_attrs [array get zero_attrs]
+ append result [apply_attrs region_attrs $char_attrs]
}
+ return $result
+}
- # A debugging function to dump the current screen, with line
- # numbers. If ATTRS, annotate with attributes.
- proc dump_screen { {attrs 0} } {
- variable _rows
- variable _cols
- variable _cur_row
- variable _cur_col
+# Check that the region of the screen described by X, Y, WIDTH,
+# and HEIGHT match REGEXP. This is like check_contents except
+# only part of the screen is checked. This can be used to check
+# the contents within a box (though check_box_contents is a better
+# choice for boxes with a border). Return 1 if check succeeded.
+proc Term::check_region_contents_p { x y width height regexp } {
+ variable _chars
+ dump_box $x $y $width $height
- verbose -log "Screen Dump (size $_cols columns x $_rows rows, cursor at column $_cur_col, row $_cur_row):"
+ # Now grab the contents of the box, join each line together
+ # with a '\r\n' sequence and match against REGEXP.
+ set result [get_region $x $y $width $height "\r\n"]
+ return [regexp -- $regexp $result]
+}
- for {set y 0} {$y < $_rows} {incr y} {
- set fmt [format %5d $y]
- verbose -log "$fmt [get_line_1 $y "" $attrs]"
- }
+# Check that the region of the screen described by X, Y, WIDTH,
+# and HEIGHT match REGEXP. As check_region_contents_p, but produce
+# a pass/fail message.
+proc Term::check_region_contents { test_name x y width height regexp } {
+ set ok [check_region_contents_p $x $y $width $height $regexp]
+ gdb_assert {$ok} $test_name
+}
+
+# Check the contents of a box on the screen. This is a little
+# like check_contents, but doesn't check the whole screen
+# contents, only the contents of a single box. This procedure
+# includes (effectively) a call to check_box to ensure there is a
+# box where expected, if there is then the contents of the box are
+# matched against REGEXP.
+proc Term::check_box_contents {test_name x y width height regexp} {
+ variable _chars
+
+ dump_box $x $y $width $height
+ set why [_check_box $x $y $width $height]
+ if {$why != ""} {
+ fail "$test_name (box check: $why)"
+ return
}
- # As dump_screen, but with attributes annotation.
- proc dump_screen_with_attrs {} {
- return [dump_screen 1]
+ check_region_contents $test_name [expr {$x + 1}] [expr {$y + 1}] \
+ [expr {$width - 2}] [expr {$height - 2}] $regexp
+}
+
+# A debugging function to dump the current screen, with line
+# numbers. If ATTRS, annotate with attributes.
+proc Term::dump_screen { {attrs 0} } {
+ variable _rows
+ variable _cols
+ variable _cur_row
+ variable _cur_col
+
+ verbose -log "Screen Dump (size $_cols columns x $_rows rows, cursor at column $_cur_col, row $_cur_row):"
+
+ for {set y 0} {$y < $_rows} {incr y} {
+ set fmt [format %5d $y]
+ verbose -log "$fmt [get_line_1 $y {} $attrs]"
}
+}
- # A debugging function to dump a box from the current screen, with line
- # numbers.
- proc dump_box { x y width height } {
- verbose -log "Box Dump ($width x $height) @ ($x, $y):"
- set region [get_region $x $y $width $height "\n"]
- set lines [split $region "\n"]
- set nr $y
- foreach line $lines {
- set fmt [format %5d $nr]
- verbose -log "$fmt $line"
- incr nr
- }
+# As dump_screen, but with attributes annotation.
+proc Term::dump_screen_with_attrs {} {
+ return [dump_screen 1]
+}
+
+# A debugging function to dump a box from the current screen, with line
+# numbers.
+proc Term::dump_box { x y width height } {
+ verbose -log "Box Dump ($width x $height) @ ($x, $y):"
+ set region [get_region $x $y $width $height "\n"]
+ set lines [split $region "\n"]
+ set nr $y
+ foreach line $lines {
+ set fmt [format %5d $nr]
+ verbose -log "$fmt $line"
+ incr nr
}
+}
- # Resize the terminal.
- proc _do_resize {rows cols} {
- variable _chars
- variable _rows
- variable _cols
+# Resize the terminal.
+proc Term::_do_resize {rows cols} {
+ variable _chars
+ variable _rows
+ variable _cols
- set old_rows [expr {min ($_rows, $rows)}]
- set old_cols [expr {min ($_cols, $cols)}]
+ set old_rows [expr {min ($_rows, $rows)}]
+ set old_cols [expr {min ($_cols, $cols)}]
- # Copy locally.
- array set local_chars [array get _chars]
- unset _chars
+ # Copy locally.
+ array set local_chars [array get _chars]
+ unset _chars
- set _rows $rows
- set _cols $cols
- _clear_lines 0 $_rows
+ set _rows $rows
+ set _cols $cols
+ _clear_lines 0 $_rows
- for {set x 0} {$x < $old_cols} {incr x} {
- for {set y 0} {$y < $old_rows} {incr y} {
- set _chars($x,$y) $local_chars($x,$y)
- }
+ for {set x 0} {$x < $old_cols} {incr x} {
+ for {set y 0} {$y < $old_rows} {incr y} {
+ set _chars($x,$y) $local_chars($x,$y)
}
}
+}
- proc resize {rows cols {wait_for_msg 1}} {
- variable _rows
- variable _cols
- variable _resize_count
+proc Term::resize {rows cols {wait_for_msg 1}} {
+ variable _rows
+ variable _cols
+ variable _resize_count
- # expect handles each argument to stty separately. This means
- # that gdb will see SIGWINCH twice. Rather than rely on this
- # behavior (which, after all, could be changed), we make it
- # explicit here. This also simplifies waiting for the redraw.
- _do_resize $rows $_cols
- stty rows $_rows < $::gdb_tty_name
- if { $wait_for_msg } {
- wait_for "@@ resize done $_resize_count, size = ${_cols}x${rows}"
- }
- incr _resize_count
- _do_resize $_rows $cols
- stty columns $_cols < $::gdb_tty_name
- if { $wait_for_msg } {
- wait_for "@@ resize done $_resize_count, size = ${_cols}x${rows}"
- }
- incr _resize_count
- }
+ # expect handles each argument to stty separately. This means
+ # that gdb will see SIGWINCH twice. Rather than rely on this
+ # behavior (which, after all, could be changed), we make it
+ # explicit here. This also simplifies waiting for the redraw.
+ _do_resize $rows $_cols
+ stty rows $_rows < $::gdb_tty_name
+ if { $wait_for_msg } {
+ wait_for "@@ resize done $_resize_count, size = ${_cols}x${rows}"
+ }
+ incr _resize_count
+ _do_resize $_rows $cols
+ stty columns $_cols < $::gdb_tty_name
+ if { $wait_for_msg } {
+ wait_for "@@ resize done $_resize_count, size = ${_cols}x${rows}"
+ }
+ incr _resize_count
}
diff --git a/gdb/testsuite/make-check-all.sh b/gdb/testsuite/make-check-all.sh
index c2fbadb..ab72574 100755
--- a/gdb/testsuite/make-check-all.sh
+++ b/gdb/testsuite/make-check-all.sh
@@ -192,7 +192,7 @@ do_tests ()
# Run make check.
make $maketarget \
- RUNTESTFLAGS="${rtf[*]} ${tests[*]}" \
+ RUNTESTFLAGS="${rtf[*]}" TESTS="${tests[*]}" \
2>&1 \
| summary
@@ -216,7 +216,7 @@ do_tests ()
cp gdb.sum gdb.log "$dir"
# Record the 'make check' command to enable easy re-running.
- echo "make $maketarget RUNTESTFLAGS=\"${rtf[*]} ${tests[*]}\"" \
+ echo "make $maketarget RUNTESTFLAGS=\"${rtf[*]}\" TESTS=\"${tests[*]}\"" \
> "$dir/make-check.sh"
fi
}