[3/3] Add testing for type signature fallback.

Message ID 486562227f9adc935db44ab048eecf7e9f10de2f.1741701275.git.dominik.mascherbauer@oracle.com
State New
Headers
Series DWARF type signature lookup fallback. |

Checks

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

Commit Message

Dominik Mascherbauer March 11, 2025, 2:57 p.m. UTC
  Create an executable with a type unit that loads a JIT objfile with a reference its type unit.
Then in the context of the JIT objfile the type is checked.
This causes a type signature lookup with a fallback to the main objfile.
---
 .../gdb.dwarf2/sig-type-fallback-jit.c        | 62 +++++++++++++++
 .../gdb.dwarf2/sig-type-fallback-jit.exp      | 75 +++++++++++++++++++
 2 files changed, 137 insertions(+)
 create mode 100644 gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.c
 create mode 100644 gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.exp
  

Patch

diff --git a/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.c b/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.c
new file mode 100644
index 00000000000..da83e27ad64
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.c
@@ -0,0 +1,62 @@ 
+/* This test program is part of GDB, the GNU debugger.
+
+   Copyright 2024 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/>.  */
+
+/* Simulate loading of JIT code.  */
+
+#include "../gdb.base/jit-elf-util.h"
+#include "../gdb.base/jit-protocol.h"
+
+/* Must be defined by .exp file when compiling to know
+   what address to map the ELF binary to.  */
+#ifndef LIB_ADDRESS
+#error "Must define LOAD_ADDRESS"
+#endif
+#ifndef LIB_NAME_STRING
+#error "Must define LIB_NAME_STRING"
+#endif
+
+int
+main ()
+{
+  size_t obj_size;
+  void *load_addr = (void *) (size_t) (LIB_ADDRESS);
+  void *addr = load_elf (LIB_NAME_STRING, &obj_size, load_addr);
+
+  /* Link entry at the end of the list.  */
+  struct jit_code_entry *const entry = calloc (1, sizeof (*entry));
+  entry->symfile_addr = (const char *) addr;
+  entry->symfile_size = obj_size;
+  __jit_debug_descriptor.relevant_entry = entry;
+  __jit_debug_descriptor.first_entry = entry;
+
+  /* Notify GDB.  */
+  __jit_debug_descriptor.action_flag = JIT_REGISTER;
+  __jit_debug_register_code ();
+
+  // breakpoint 1
+
+  /* Now unregister entry.  */
+  /* Notify GDB.  */
+  __jit_debug_descriptor.action_flag = JIT_UNREGISTER;
+  __jit_debug_register_code ();
+
+  __jit_debug_descriptor.first_entry = NULL;
+  __jit_debug_descriptor.relevant_entry = NULL;
+  free (entry);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.exp b/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.exp
new file mode 100644
index 00000000000..91465118c5f
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.exp
@@ -0,0 +1,75 @@ 
+# Copyright 2024 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
+
+require dwarf2_support allow_shlib_tests
+
+set lib_address 0x7000000
+set lib_name libfoo.so
+
+standard_testfile .c .S -lib.S
+
+# Create fake DWARF TU for the main objfile.
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble ${asm_file} {
+    tu {version 5} 0x1122334455667788 the_type {
+ 	type_unit {} {
+   	    the_type: base_type {
+   		{name myType}
+   		{encoding @DW_ATE_signed}
+   		{byte_size 4 sdata}
+   	    }
+   	}
+   	}
+}
+
+# Create fake DWARF CU with type reference for the jit object file.
+set asm_file_lib [standard_output_file $srcfile3]
+Dwarf::assemble ${asm_file_lib} {
+    cu {} {
+  	compile_unit {} {
+   	    declare_labels typedef_label
+
+   	    typedef_label: typedef {
+   		{name bar}
+   		{type 0x1122334455667788 ref_sig8 }
+   	    }
+   	}
+    }
+}
+
+
+set libobj [standard_output_file $lib_name]
+if {[build_executable "build shared library" $libobj $asm_file_lib \
+	 [list debug text_segment=$lib_address shlib]] != 0} {
+    return -1
+}
+
+if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $asm_file] \
+	 [list debug additional_flags=-DLIB_ADDRESS=$lib_address \
+	 additional_flags=-DLIB_NAME_STRING=\"$libobj\" ]]} {
+    return -1
+}
+
+if {![runto_main]} {
+    return -1
+}
+
+gdb_test_no_output "set dwarf-type-signature-fallback main"
+gdb_breakpoint [gdb_get_line_number "breakpoint 1"]
+gdb_continue_to_breakpoint "first breakpoint"
+gdb_test "ptype bar" "type = myType"
\ No newline at end of file