Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: dominikmascherbauer <dominik.mascherbauer@gmail.com>
To: gdb-patches@sourceware.org
Cc: dominikmascherbauer <dominik.mascherbauer@oracle.com>
Subject: [PATCH 3/3] Add testing for type signature fallback.
Date: Tue, 11 Mar 2025 15:57:20 +0100	[thread overview]
Message-ID: <486562227f9adc935db44ab048eecf7e9f10de2f.1741701275.git.dominik.mascherbauer@oracle.com> (raw)
In-Reply-To: <cover.1741701275.git.dominik.mascherbauer@oracle.com>

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

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
-- 
2.34.1


  parent reply	other threads:[~2025-03-11 15:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-11 14:57 [PATCH 0/3] DWARF type signature lookup fallback dominikmascherbauer
2025-03-11 14:57 ` [PATCH 1/3] Add new commands for controlling type signature fallback dominikmascherbauer
2025-03-11 17:33   ` Eli Zaretskii
2025-03-12  9:12     ` Dominik Mascherbauer
2025-03-12 14:38       ` Eli Zaretskii
2025-03-12 14:44         ` Dominik Mascherbauer
2025-03-11 14:57 ` [PATCH 2/3] Add type signature fallback and JIT objfile restriction dominikmascherbauer
2025-03-11 14:57 ` dominikmascherbauer [this message]
2025-03-12 15:37 ` [PATCH v2 0/3] DWARF type signature lookup fallback dominikmascherbauer
2025-03-12 15:37   ` [PATCH v2 1/3] Add new commands for controlling type signature fallback dominikmascherbauer
2025-03-12 15:43     ` Eli Zaretskii
2025-03-12 15:37   ` [PATCH v2 2/3] Add type signature fallback and JIT objfile restriction dominikmascherbauer
2025-03-12 15:37   ` [PATCH v2 3/3] Add testing for type signature fallback dominikmascherbauer
2025-03-12 16:32 ` [PATCH 0/3] DWARF type signature lookup fallback Tom Tromey
2025-03-13 10:42   ` Dominik Mascherbauer
2025-03-13 15:37     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=486562227f9adc935db44ab048eecf7e9f10de2f.1741701275.git.dominik.mascherbauer@oracle.com \
    --to=dominik.mascherbauer@gmail.com \
    --cc=dominik.mascherbauer@oracle.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox