[1/3] Move core_bfd to program space

Message ID 20180503162234.15371-2-palves@redhat.com
State New, archived
Headers

Commit Message

Pedro Alves May 3, 2018, 4:22 p.m. UTC
  From: Tom Tromey <tromey@redhat.com>

This moves the core_bfd global to be a field of the program space.  It
then replaces core_bfd with a macro to avoid a massive patch -- the
same approach taken for various other program space fields.

This is a basic transformation for multi-target work.

yyyy-mm-dd  Tom Tromey  <tromey@redhat.com>
	    Pedro Alves  <tromey@redhat.com>

	* corefile.c (core_bfd): Remove.
	* gdbcore.h (core_bfd): Now a macro.
	* progspace.h (struct program_space) <cbfd>: New field.
---
 gdb/corefile.c  | 4 ----
 gdb/gdbcore.h   | 2 +-
 gdb/progspace.h | 3 +++
 3 files changed, 4 insertions(+), 5 deletions(-)
  

Comments

Tom Tromey May 4, 2018, 3:41 p.m. UTC | #1
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> This moves the core_bfd global to be a field of the program space.  It
Pedro> then replaces core_bfd with a macro to avoid a massive patch -- the
Pedro> same approach taken for various other program space fields.

I am curious to know whether you would want to remove this macro in the
future.  I don't mean that you should do it -- just more a question of
what direction to go.  There are other macros like this too:
symfile_objfile, object_files, exec_bfd, ...

Also, I can't remember why I moved core_bfd to the progspace.  Would it
be better to have it just be a member of the target?  Or maybe in your
design these end up being basically equivalent, because core targets are
inherently single-process?

Tom
  
Pedro Alves May 4, 2018, 4:09 p.m. UTC | #2
On 05/04/2018 04:41 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
> 
> Pedro> This moves the core_bfd global to be a field of the program space.  It
> Pedro> then replaces core_bfd with a macro to avoid a massive patch -- the
> Pedro> same approach taken for various other program space fields.
> 
> I am curious to know whether you would want to remove this macro in the
> future.  I don't mean that you should do it -- just more a question of
> what direction to go.  There are other macros like this too:
> symfile_objfile, object_files, exec_bfd, ...

Yeah, I have no plans to do that myself, but I wouldn't oppose
changing it.

> Also, I can't remember why I moved core_bfd to the progspace.  Would it
> be better to have it just be a member of the target?  Or maybe in your
> design these end up being basically equivalent, because core targets are
> inherently single-process?
Yeah, I guess program space just felt natural given exec_bfd is there
too.  Not sure about putting it in the target.  Making it a data field of
target_ops I think would be odd.  It might work if we replaced it
with something like (in the multi-target branch):

bfd *
core_bfd ()
{
  if (core_target *core 
      = dynamic_cast<core_target *> 
          (current_inferior ()->process_target ()))
    return core->core_bfd;
  return nullptr;
}

though that's a bit smelly, and when I see dynamic_cast
I can't avoid thinking about how inefficient it is.  :-)

Alternatively, we could make core_bfd() a virtual method of
target_ops instead, that has most targets except the
core_target target return NULL.

Not sure.  Putting it in program space just seemed like an
easy and OK thing to do.

Thanks,
Pedro Alves
  
Tom Tromey May 4, 2018, 4:46 p.m. UTC | #3
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

>> I am curious to know whether you would want to remove this macro in the
>> future.  I don't mean that you should do it -- just more a question of
>> what direction to go.  There are other macros like this too:
>> symfile_objfile, object_files, exec_bfd, ...

Pedro> Yeah, I have no plans to do that myself, but I wouldn't oppose
Pedro> changing it.

Thanks.

Pedro> Yeah, I guess program space just felt natural given exec_bfd is there
Pedro> too.

That makes sense, thanks.

Tom
  

Patch

diff --git a/gdb/corefile.c b/gdb/corefile.c
index 114de83640..e0c7540140 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -49,10 +49,6 @@  static hook_type *exec_file_extra_hooks;	/* Array of additional
 						   hooks.  */
 static int exec_file_hook_count = 0;		/* Size of array.  */
 
-/* Binary file diddling handle for the core file.  */
-
-bfd *core_bfd = NULL;
-
 
 
 /* Backward compatability with old way of specifying core files.  */
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index 401c213d48..d06ccc3507 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -133,7 +133,7 @@  extern void specify_exec_file_hook (void (*hook) (const char *filename));
 
 /* Binary File Diddler for the core file.  */
 
-extern bfd *core_bfd;
+#define core_bfd (current_program_space->cbfd)
 
 /* corelow.c target.  It is never NULL after GDB initialization.  */
 
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 67c0a240da..835fcfdd5d 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -157,6 +157,9 @@  struct program_space
      It needs to be freed by xfree.  It is not NULL iff EBFD is not NULL.  */
   char *pspace_exec_filename = NULL;
 
+  /* Binary file diddling handle for the core file.  */
+  bfd *cbfd = NULL;
+
   /* The address space attached to this program space.  More than one
      program space may be bound to the same address space.  In the
      traditional unix-like debugging scenario, this will usually