public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/7] Convert solib-rocm to new type-safe gdb_bfd_openr_iovec
Date: Thu, 24 Aug 2023 11:12:23 -0600	[thread overview]
Message-ID: <20230824-gdb-bfd-vec-v1-6-850e4e907ed1@adacore.com> (raw)
In-Reply-To: <20230824-gdb-bfd-vec-v1-0-850e4e907ed1@adacore.com>

This converts the solib-rocm BFD iovec implementations to the new
type-safe gdb_bfd_openr_iovec.  They were already essentially using
this approach, just without the type-safe wrapper.

I can't build or test this patch.
---
 gdb/solib-rocm.c | 39 +++++++++------------------------------
 1 file changed, 9 insertions(+), 30 deletions(-)

diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c
index 882920a3711..145624b888a 100644
--- a/gdb/solib-rocm.c
+++ b/gdb/solib-rocm.c
@@ -268,7 +268,7 @@ namespace {
 
 /* Interface to interact with a ROCm code object stream.  */
 
-struct rocm_code_object_stream
+struct rocm_code_object_stream : public gdb_bfd_iovec_base
 {
   DISABLE_COPY_AND_ASSIGN (rocm_code_object_stream);
 
@@ -457,8 +457,8 @@ rocm_code_object_stream_memory::read (void *buf, file_ptr size,
 
 } /* anonymous namespace */
 
-static void *
-rocm_bfd_iovec_open (bfd *abfd, void *inferior_void)
+static gdb_bfd_iovec_base *
+rocm_bfd_iovec_open (bfd *abfd, inferior *inferior)
 {
   gdb::string_view uri (bfd_get_filename (abfd));
   gdb::string_view protocol_delim = "://";
@@ -522,7 +522,6 @@ rocm_bfd_iovec_open (bfd *abfd, void *inferior_void)
     {
       ULONGEST offset = 0;
       ULONGEST size = 0;
-      inferior *inferior = static_cast<struct inferior *> (inferior_void);
 
       auto try_strtoulst = [] (gdb::string_view v)
 	{
@@ -607,28 +606,6 @@ rocm_bfd_iovec_open (bfd *abfd, void *inferior_void)
     }
 }
 
-static int
-rocm_bfd_iovec_close (bfd *nbfd, void *data)
-{
-  delete static_cast<rocm_code_object_stream *> (data);
-
-  return 0;
-}
-
-static file_ptr
-rocm_bfd_iovec_pread (bfd *abfd, void *data, void *buf, file_ptr size,
-		      file_ptr offset)
-{
-  return static_cast<rocm_code_object_stream *> (data)->read (buf, size,
-							      offset);
-}
-
-static int
-rocm_bfd_iovec_stat (bfd *abfd, void *data, struct stat *sb)
-{
-  return static_cast<rocm_code_object_stream *> (data)->stat (sb);
-}
-
 static gdb_bfd_ref_ptr
 rocm_solib_bfd_open (const char *pathname)
 {
@@ -636,10 +613,12 @@ rocm_solib_bfd_open (const char *pathname)
   if (strstr (pathname, "://") == nullptr)
     return svr4_so_ops.bfd_open (pathname);
 
-  gdb_bfd_ref_ptr abfd
-    = gdb_bfd_openr_iovec (pathname, "elf64-amdgcn", rocm_bfd_iovec_open,
-			   current_inferior (), rocm_bfd_iovec_pread,
-			   rocm_bfd_iovec_close, rocm_bfd_iovec_stat);
+  auto open = [&] (bfd *nbfd) -> gdb_bfd_iovec_base *
+  {
+    return rocm_bfd_iovec_open (nbfd, current_inferior ());
+  };
+
+  gdb_bfd_ref_ptr abfd = gdb_bfd_openr_iovec (pathname, "elf64-amdgcn", open);
 
   if (abfd == nullptr)
     error (_("Could not open `%s' as an executable file: %s"), pathname,

-- 
2.40.1


  parent reply	other threads:[~2023-08-24 17:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24 17:12 [PATCH 0/7] Rewrite gdb_bfd_openr_iovec to be type-safe Tom Tromey
2023-08-24 17:12 ` [PATCH 1/7] Introduce type-safe variant of gdb_bfd_openr_iovec Tom Tromey
2023-09-18 10:29   ` Lancelot SIX
2023-09-18 14:44     ` Tom Tromey
2023-08-24 17:12 ` [PATCH 2/7] Small constructor change to target_buffer Tom Tromey
2023-08-24 17:12 ` [PATCH 3/7] Convert mem_bfd_iovec to new type-safe gdb_bfd_openr_iovec Tom Tromey
2023-08-24 17:12 ` [PATCH 4/7] Convert target fileio " Tom Tromey
2023-08-24 17:12 ` [PATCH 5/7] Convert minidebug " Tom Tromey
2023-08-24 17:12 ` Tom Tromey [this message]
2023-09-18  9:41   ` [PATCH 6/7] Convert solib-rocm " Lancelot SIX
2023-09-18 14:49     ` Tom Tromey
2023-08-24 17:12 ` [PATCH 7/7] Remove old gdb_bfd_openr_iovec Tom Tromey
2023-09-18 12:34 ` [PATCH 0/7] Rewrite gdb_bfd_openr_iovec to be type-safe Lancelot SIX

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=20230824-gdb-bfd-vec-v1-6-850e4e907ed1@adacore.com \
    --to=tromey@adacore.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).