Add gdb.base/set-solib-absolute-prefix.exp

Message ID 20250319123254.351647-1-ahajkova@redhat.com
State New
Headers
Series Add gdb.base/set-solib-absolute-prefix.exp |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Alexandra Hájková March 19, 2025, 12:32 p.m. UTC
  From: Alexandra Hajkova <ahajkova@redhat.com>

This test tests GDB displays backtrace properly when
sysroot is set to non-existing directory and GDB
attempts to load the vDSO from the filesystem and cannot.

This test was present in Fedora for a long time and was
originally written by Jan Kratochvil for this fix
829a902da291e72ad17e8c44fa8d9ead3db41b1f.

Co-Authored-By: Jan Kratochvil <jan.kratochvil@redhat.com>
---
 .../gdb.base/set-solib-absolute-prefix.c      | 32 +++++++++++
 .../gdb.base/set-solib-absolute-prefix.exp    | 54 +++++++++++++++++++
 2 files changed, 86 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/set-solib-absolute-prefix.c
 create mode 100644 gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp
  

Comments

Andrew Burgess March 26, 2025, 3 p.m. UTC | #1
Alexandra Hájková <ahajkova@redhat.com> writes:

> From: Alexandra Hajkova <ahajkova@redhat.com>
>
> This test tests GDB displays backtrace properly when
> sysroot is set to non-existing directory and GDB
> attempts to load the vDSO from the filesystem and cannot.

Is that really what happens?  I'd expect the vDSO symbols to be read
from memory, not disk, and the commit message for 829a902da291e72ad17
talks about not trying to reload libraries that don't need
reloading... which I would expect to include vDSO.

I've not experimented with that patch (829a902da291e72ad17) to see
exactly how vDSO is handled though, so maybe I'm wrong.  But your text
here seems to differ from the text at the head of the .exp file you're
adding.

>
> This test was present in Fedora for a long time and was
> originally written by Jan Kratochvil for this fix
> 829a902da291e72ad17e8c44fa8d9ead3db41b1f.
>
> Co-Authored-By: Jan Kratochvil <jan.kratochvil@redhat.com>
> ---
>  .../gdb.base/set-solib-absolute-prefix.c      | 32 +++++++++++
>  .../gdb.base/set-solib-absolute-prefix.exp    | 54 +++++++++++++++++++
>  2 files changed, 86 insertions(+)
>  create mode 100644 gdb/testsuite/gdb.base/set-solib-absolute-prefix.c
>  create mode 100644 gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp
>
> diff --git a/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c
> new file mode 100644
> index 00000000000..685a22e0d77
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c
> @@ -0,0 +1,32 @@
> +/* Copyright (C) 2012-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/>.  */
> +
> +#include <stdlib.h>
> +
> +/* Global var used to generate filler code.  */
> +volatile int global_var = 0;
> +
> +int
> +main ()
> +{
> +  global_var++;
> +  global_var++;
> +
> +  abort ();
> +
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp
> new file mode 100644
> index 00000000000..21555ae29c4
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp
> @@ -0,0 +1,54 @@
> +# Copyright 2012-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/>.
> +#
> +# Compile a 32-bit x86 executable and then stop within a system call.
> +# Change the sysroot to a non-existent directory, GDB should try (and
> +# fail) to reload the currently loaded shared libraries.  However, GDB
> +# should retain the symbols for the vDSO library as that is not loaded
> +# from the file system.
> +#
> +# Check the backtrace to ensure that the __kernel_vsyscall symbol is
> +# still in the backtrace, this indicates GDB still has the vDSO
> +# symbols available.
> +
> +require {is_any_target "i?86-*-linux*" "x86_64-*-linux*"}
> +standard_testfile
> +
> +# The binary must be compiled as 32-bit so that the system call
> +# `__kernel_vsyscall' originates from vDSO.
> +set flags { debug }
> +if { ![is_ilp32_target] } {
> +     lappend flags  "additional_flags=-m32"
> +}
> +
> +if { [prepare_for_testing $testfile.exp $testfile $srcfile $flags] } {
> +    return
> +}
> +
> +if { ![runto_main] } {
> +    return
> +}
> +
> +set non_existing_directory "/BOGUS_DIRECT"
> +if { [file exists $non_existing_directory] } {
> +    return
> +}

I think it would be better to just do:

  set non_existing_directory [standard_output_file "BOGUS"]

Then you can drop the 'file exists' check.

Thanks,
Andrew

> +
> +gdb_test "continue" "Program received signal SIGABRT, Aborted.*" \
> +    "continue until abort"
> +gdb_test "set sysroot $non_existing_directory" \
> +    ".*warning: Unable to find dynamic linker breakpoint function.*" \
> +    "set sysroot"
> +gdb_test "bt" "__kernel_vsyscall.*" "backtrace with __kernel_vsyscall"
> -- 
> 2.48.1
  

Patch

diff --git a/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c
new file mode 100644
index 00000000000..685a22e0d77
--- /dev/null
+++ b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c
@@ -0,0 +1,32 @@ 
+/* Copyright (C) 2012-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/>.  */
+
+#include <stdlib.h>
+
+/* Global var used to generate filler code.  */
+volatile int global_var = 0;
+
+int
+main ()
+{
+  global_var++;
+  global_var++;
+
+  abort ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp
new file mode 100644
index 00000000000..21555ae29c4
--- /dev/null
+++ b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp
@@ -0,0 +1,54 @@ 
+# Copyright 2012-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/>.
+#
+# Compile a 32-bit x86 executable and then stop within a system call.
+# Change the sysroot to a non-existent directory, GDB should try (and
+# fail) to reload the currently loaded shared libraries.  However, GDB
+# should retain the symbols for the vDSO library as that is not loaded
+# from the file system.
+#
+# Check the backtrace to ensure that the __kernel_vsyscall symbol is
+# still in the backtrace, this indicates GDB still has the vDSO
+# symbols available.
+
+require {is_any_target "i?86-*-linux*" "x86_64-*-linux*"}
+standard_testfile
+
+# The binary must be compiled as 32-bit so that the system call
+# `__kernel_vsyscall' originates from vDSO.
+set flags { debug }
+if { ![is_ilp32_target] } {
+     lappend flags  "additional_flags=-m32"
+}
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile $flags] } {
+    return
+}
+
+if { ![runto_main] } {
+    return
+}
+
+set non_existing_directory "/BOGUS_DIRECT"
+if { [file exists $non_existing_directory] } {
+    return
+}
+
+gdb_test "continue" "Program received signal SIGABRT, Aborted.*" \
+    "continue until abort"
+gdb_test "set sysroot $non_existing_directory" \
+    ".*warning: Unable to find dynamic linker breakpoint function.*" \
+    "set sysroot"
+gdb_test "bt" "__kernel_vsyscall.*" "backtrace with __kernel_vsyscall"