diff options
author | Tom Tromey <tromey@adacore.com> | 2023-08-24 08:47:54 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-09-28 10:46:38 -0600 |
commit | bb75a8698c262383fc7720edfa0685a14eea1400 (patch) | |
tree | 0fe925b12aa1893392de1c7148c7fe5686e9e8c3 /gdb/gdb_bfd.h | |
parent | c7bdb38bafacde3d4bf4fa21951c577380259750 (diff) | |
download | binutils-bb75a8698c262383fc7720edfa0685a14eea1400.zip binutils-bb75a8698c262383fc7720edfa0685a14eea1400.tar.gz binutils-bb75a8698c262383fc7720edfa0685a14eea1400.tar.bz2 |
Introduce type-safe variant of gdb_bfd_openr_iovec
This patch adds a new, type-safe variant of gdb_bfd_openr_iovec. In
this approach, the underlying user data is simply an object, the
callbacks are methods, and the "open" function is a function view.
Nothing uses this new code yet.
Reviewed-By: Lancelot Six <lancelot.six@amd.com>
Diffstat (limited to 'gdb/gdb_bfd.h')
-rw-r--r-- | gdb/gdb_bfd.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h index d15b110..ae374f5 100644 --- a/gdb/gdb_bfd.h +++ b/gdb/gdb_bfd.h @@ -22,6 +22,7 @@ #include "registry.h" #include "gdbsupport/byte-vector.h" +#include "gdbsupport/function-view.h" #include "gdbsupport/gdb_ref_ptr.h" #include "gdbsupport/iterator-range.h" #include "gdbsupport/next-iterator.h" @@ -150,6 +151,36 @@ gdb_bfd_ref_ptr gdb_bfd_openr (const char *, const char *); gdb_bfd_ref_ptr gdb_bfd_openw (const char *, const char *); +/* The base class for BFD "iovec" implementations. This is used by + gdb_bfd_openr_iovec and enables better type safety. */ + +class gdb_bfd_iovec_base +{ +protected: + + gdb_bfd_iovec_base () = default; + +public: + + virtual ~gdb_bfd_iovec_base () = default; + + /* The "read" callback. */ + virtual file_ptr read (bfd *abfd, void *buffer, file_ptr nbytes, + file_ptr offset) = 0; + + /* The "stat" callback. */ + virtual int stat (struct bfd *abfd, struct stat *sb) = 0; +}; + +/* The type of the function used to open a new iovec-based BFD. */ +using gdb_iovec_opener_ftype + = gdb::function_view<gdb_bfd_iovec_base * (bfd *)>; + +/* A type-safe wrapper for bfd_openr_iovec. */ + +gdb_bfd_ref_ptr gdb_bfd_openr_iovec (const char *filename, const char *target, + gdb_iovec_opener_ftype open_fn); + /* A wrapper for bfd_openr_iovec that initializes the gdb-specific reference count. */ |