diff options
Diffstat (limited to 'gdb/testsuite/gdb.base')
-rw-r--r-- | gdb/testsuite/gdb.base/bg-execution-repeat.c | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/corefile3.c | 118 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/corefile3.exp | 71 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/dlmopen-ns-ids.exp | 20 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/printcmds.exp | 7 |
5 files changed, 208 insertions, 10 deletions
diff --git a/gdb/testsuite/gdb.base/bg-execution-repeat.c b/gdb/testsuite/gdb.base/bg-execution-repeat.c index 8e9bae4..3c0cc76 100644 --- a/gdb/testsuite/gdb.base/bg-execution-repeat.c +++ b/gdb/testsuite/gdb.base/bg-execution-repeat.c @@ -37,9 +37,9 @@ main (void) { alarm (60); + do_wait = 1; foo (); - do_wait = 1; wait (); /* do_wait set to 0 externally. */ diff --git a/gdb/testsuite/gdb.base/corefile3.c b/gdb/testsuite/gdb.base/corefile3.c new file mode 100644 index 0000000..16030dd --- /dev/null +++ b/gdb/testsuite/gdb.base/corefile3.c @@ -0,0 +1,118 @@ +/* Copyright 1992-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 file is based on coremaker.c. */ + +#include <stdio.h> +#include <sys/types.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <signal.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <assert.h> +#include <sys/ipc.h> +#include <sys/shm.h> + +#define MAPSIZE (8 * 1024) + +/* Global pointers so it's easier to access them from GDB. */ + +char *rw_mapping = NULL; +char *malloc_buffer = NULL; +char *anon_mapping = NULL; +char *shm_mapping = NULL; + +/* Create mappings within this process. */ + +void +mmapdata () +{ + /* Allocate and initialize a buffer that will be used to write the file + that is later mapped in. */ + + malloc_buffer = (char *) malloc (MAPSIZE); + for (int j = 0; j < MAPSIZE; ++j) + malloc_buffer[j] = j; + + /* Write the file to map in. */ + + int fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666); + assert (fd != -1); + write (fd, malloc_buffer, MAPSIZE); + + /* Now map the file into our address space as RW_MAPPING. */ + + rw_mapping + = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + assert (rw_mapping != (char *) MAP_FAILED); + + /* Verify that the original data and the mapped data are identical. If + not, we'd rather fail now than when trying to access the mapped data + from the core file. */ + + for (int j = 0; j < MAPSIZE; ++j) + assert (malloc_buffer[j] == rw_mapping[j]); + + /* Touch RW_MAPPING so the kernel writes it out into 'core'. */ + rw_mapping[0] = malloc_buffer[0]; + + /* Create yet another region which is allocated, but not written to. */ + anon_mapping = mmap (NULL, MAPSIZE, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + assert (anon_mapping != MAP_FAILED); + + /* Create a shared memory mapping. */ + int sid = shmget (IPC_PRIVATE, MAPSIZE, IPC_CREAT | IPC_EXCL | 0777); + assert (sid != -1); + shm_mapping = (char *) shmat (sid, NULL, 0); + int res = shmctl (sid, IPC_RMID, NULL); + assert (res == 0); + assert (shm_mapping != MAP_FAILED); +} + +void +func2 () +{ +#ifdef SA_FULLDUMP + /* Force a corefile that includes the data section for AIX. */ + { + struct sigaction sa; + + sigaction (SIGABRT, (struct sigaction *)0, &sa); + sa.sa_flags |= SA_FULLDUMP; + sigaction (SIGABRT, &sa, (struct sigaction *)0); + } +#endif + + abort (); +} + +void +func1 () +{ + func2 (); +} + +int +main (void) +{ + mmapdata (); + func1 (); + return 0; +} diff --git a/gdb/testsuite/gdb.base/corefile3.exp b/gdb/testsuite/gdb.base/corefile3.exp new file mode 100644 index 0000000..57b2300 --- /dev/null +++ b/gdb/testsuite/gdb.base/corefile3.exp @@ -0,0 +1,71 @@ +# 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/>. + +# Create a core file with some mapped file regions, but ensure that +# the the kernel should write the regions into the core file (e.g. r/w +# file backed mapping). +# +# We then delete the file that backed the mapping and load the core +# file into GDB. +# +# GDB shouldn't warn about the file being missing. It doesn't matter; +# the file contents can all be found in the core file itself. + +require isnative +require {!is_remote host} + +standard_testfile + +if {[build_executable $testfile.exp $testfile $srcfile] == -1} { + return +} + +set corefile [core_find $binfile {}] +if {$corefile == ""} { + return +} + +# Move the coremap.data file out of the way, so it cannot be found +# when we later load the core file into GDB. This file was generated +# by the inferior as it was running. +set data_filename \ + [standard_output_file coredir.[getpid]/coremmap.data] +set backup_filename \ + [standard_output_file coredir.[getpid]/coremmap.data.backup] +remote_exec host "mv ${data_filename} ${backup_filename}" + +clean_restart $binfile + +# Load the core file. The 'coremap.data' file cannot be found by GDB, +# but all the mappings for that file are r/w and should be present in +# the core file, so we shouldn't get any warnings from GDB about it. +set warnings_seen 0 +gdb_test_multiple "core-file $corefile" "core-file command" { + -re "^warning: Can't open file \[^\r\n\]+ during file-backed mapping note processing\r\n" { + incr warnings_seen + exp_continue + } + -re "^$gdb_prompt $" { + gdb_assert { $warnings_seen == 0 } $gdb_test_name + } + -re "^\[^\r\n\]*\r\n" { + exp_continue + } +} + +# Check the mappings are all readable. +foreach label { rw_mapping malloc_buffer anon_mapping shm_mapping } { + gdb_test "x/1wd $label" "^$hex:\\s+$decimal" +} diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp index 03b7a52..3ddc07e 100644 --- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp +++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp @@ -24,7 +24,8 @@ require allow_dlmopen_tests standard_testfile -main.c -lib.c set srcfile_lib $srcfile2 -set binfile_lib [standard_output_file dlmopen-lib.so] +set so_name dlmopen-lib.so +set binfile_lib [standard_output_file $so_name] if { [build_executable "build shlib" $binfile_lib $srcfile_lib \ [list debug shlib]] == -1 } { @@ -41,18 +42,19 @@ if { [build_executable "failed to build" $testfile $srcfile \ # for the so proc get_first_so_ns {} { set ns -1 - gdb_test_multiple "info sharedlibrary" "get SO namespace" -lbl { - -re "From\\s+To\\s+\(NS\\s+\)?Syms\\s+Read\\s+Shared Object Library\r\n" { + 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)" { exp_continue } - -re "^$::hex\\s+$::hex\\s+\\\[\\\[($::decimal)\\\]\\\]\\s+\[^\r\n]+$::binfile_lib.*" { - set ns $expect_out(1,string) - } - -re "^$::gdb_prompt $" { - } - -re "^\[^\r\n\]+\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) + } exp_continue } + -re -wrap "" { + } } return $ns } diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp index e1c996e..8634668 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -744,6 +744,12 @@ proc test_print_char_arrays {} { gdb_test_no_output "set print address off" "address off char arrays" } +proc test_print_arrays_negative {} { + # Check whether correct error messages are printed + gdb_test "p 1 == { }" "size of the array element must not be zero" + gdb_test "p 1 == { 1, 'a' }" "array elements must all be the same size" +} + proc test_print_nibbles {} { gdb_test_no_output "set print nibbles on" foreach lang_line { @@ -1235,6 +1241,7 @@ test_print_int_arrays test_print_typedef_arrays test_artificial_arrays test_print_char_arrays +test_print_arrays_negative test_print_nibbles # We used to do the runto main here. test_print_string_constants |