[5/9] Remove current_target_sections macro

Message ID 20200722033444.18522-6-tom@tromey.com
State New
Headers show
Series
  • Remove some macros from exec.h and progspace.h
Related show

Commit Message

Tom Tromey July 22, 2020, 3:34 a.m.
This removes the current_target_sections macro, replacing it with uses
of the appropriate member from current_program_space.

gdb/ChangeLog
2020-07-21  Tom Tromey  <tom@tromey.com>

	* progspace.h (current_target_sections): Remove macro.
	* solib-svr4.c (scan_dyntag): Update.
	* solib-dsbt.c (scan_dyntag): Update.
	* exec.c (exec_target::close): Update.
	(add_target_sections, add_target_sections_of_objfile)
	(remove_target_sections, exec_target::get_section_table)
	(exec_target::files_info, set_section_command)
	(exec_set_section_address, exec_target::has_memory)
	(exec_target::has_memory): Update.
---
 gdb/ChangeLog    | 12 ++++++++++++
 gdb/exec.c       | 23 +++++++++++++----------
 gdb/progspace.h  |  4 ----
 gdb/solib-dsbt.c |  6 +++---
 gdb/solib-svr4.c |  6 +++---
 5 files changed, 31 insertions(+), 20 deletions(-)

-- 
2.17.2

Comments

Simon Marchi July 22, 2020, 12:20 p.m. | #1
On 2020-07-21 11:34 p.m., Tom Tromey wrote:
> This removes the current_target_sections macro, replacing it with uses

> of the appropriate member from current_program_space.

> 

> gdb/ChangeLog

> 2020-07-21  Tom Tromey  <tom@tromey.com>

> 

> 	* progspace.h (current_target_sections): Remove macro.

> 	* solib-svr4.c (scan_dyntag): Update.

> 	* solib-dsbt.c (scan_dyntag): Update.

> 	* exec.c (exec_target::close): Update.

> 	(add_target_sections, add_target_sections_of_objfile)

> 	(remove_target_sections, exec_target::get_section_table)

> 	(exec_target::files_info, set_section_command)

> 	(exec_set_section_address, exec_target::has_memory)

> 	(exec_target::has_memory): Update.

> ---

>  gdb/ChangeLog    | 12 ++++++++++++

>  gdb/exec.c       | 23 +++++++++++++----------

>  gdb/progspace.h  |  4 ----

>  gdb/solib-dsbt.c |  6 +++---

>  gdb/solib-svr4.c |  6 +++---

>  5 files changed, 31 insertions(+), 20 deletions(-)

> 

> diff --git a/gdb/exec.c b/gdb/exec.c

> index 6ca867ab53e..e2a0cae787c 100644

> --- a/gdb/exec.c

> +++ b/gdb/exec.c

> @@ -159,7 +159,7 @@ exec_target::close ()

>    for (struct program_space *ss : program_spaces)

>      {

>        set_current_program_space (ss);

> -      clear_section_table (current_target_sections);

> +      clear_section_table (&ss->target_sections);

>        ss->exec_close ();


I hoped that the call to set_current_program_space could be removed, but no.  exec_close
ends up calling remove_target_sections, which uses current_program_space.

But once we make remove_target_sections take a program_space parameter, I think it will
be fine to remove it.

Simon
Simon Marchi July 22, 2020, 12:39 p.m. | #2
On 2020-07-22 8:20 a.m., Simon Marchi wrote:
> On 2020-07-21 11:34 p.m., Tom Tromey wrote:

>> This removes the current_target_sections macro, replacing it with uses

>> of the appropriate member from current_program_space.

>>

>> gdb/ChangeLog

>> 2020-07-21  Tom Tromey  <tom@tromey.com>

>>

>> 	* progspace.h (current_target_sections): Remove macro.

>> 	* solib-svr4.c (scan_dyntag): Update.

>> 	* solib-dsbt.c (scan_dyntag): Update.

>> 	* exec.c (exec_target::close): Update.

>> 	(add_target_sections, add_target_sections_of_objfile)

>> 	(remove_target_sections, exec_target::get_section_table)

>> 	(exec_target::files_info, set_section_command)

>> 	(exec_set_section_address, exec_target::has_memory)

>> 	(exec_target::has_memory): Update.

>> ---

>>  gdb/ChangeLog    | 12 ++++++++++++

>>  gdb/exec.c       | 23 +++++++++++++----------

>>  gdb/progspace.h  |  4 ----

>>  gdb/solib-dsbt.c |  6 +++---

>>  gdb/solib-svr4.c |  6 +++---

>>  5 files changed, 31 insertions(+), 20 deletions(-)

>>

>> diff --git a/gdb/exec.c b/gdb/exec.c

>> index 6ca867ab53e..e2a0cae787c 100644

>> --- a/gdb/exec.c

>> +++ b/gdb/exec.c

>> @@ -159,7 +159,7 @@ exec_target::close ()

>>    for (struct program_space *ss : program_spaces)

>>      {

>>        set_current_program_space (ss);

>> -      clear_section_table (current_target_sections);

>> +      clear_section_table (&ss->target_sections);

>>        ss->exec_close ();

> 

> I hoped that the call to set_current_program_space could be removed, but no.  exec_close

> ends up calling remove_target_sections, which uses current_program_space.

> 

> But once we make remove_target_sections take a program_space parameter, I think it will

> be fine to remove it.


This is handled in the next patch, so forget it.  Although I get a build failure on this
patch:

/home/smarchi/src/binutils-gdb/gdb/solib-dsbt.c: In function ‘int scan_dyntag(int, bfd*, CORE_ADDR*)’:
/home/smarchi/src/binutils-gdb/gdb/solib-dsbt.c:427:63: error: base operand of ‘->’ has non-pointer type ‘target_section_table’
  427 |   for (target_section = current_program_space->target_sections->sections;
      |                                                               ^~

Simon
Tom Tromey July 22, 2020, 2:11 p.m. | #3
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:


Simon> This is handled in the next patch, so forget it.  Although I get a build failure on this
Simon> patch:

Simon> /home/smarchi/src/binutils-gdb/gdb/solib-dsbt.c: In function ‘int scan_dyntag(int, bfd*, CORE_ADDR*)’:
Simon> /home/smarchi/src/binutils-gdb/gdb/solib-dsbt.c:427:63: error: base operand of ‘->’ has non-pointer type ‘target_section_table’
Simon>   427 |   for (target_section = current_program_space->target_sections->sections;
Simon>       |                                                               ^~

Oops, either I sent the wrong version, or the fix ended up in a
different patch.  I'll have to check; but either way I'll fix it.

Tom

Patch

diff --git a/gdb/exec.c b/gdb/exec.c
index 6ca867ab53e..e2a0cae787c 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -159,7 +159,7 @@  exec_target::close ()
   for (struct program_space *ss : program_spaces)
     {
       set_current_program_space (ss);
-      clear_section_table (current_target_sections);
+      clear_section_table (&ss->target_sections);
       ss->exec_close ();
     }
 }
@@ -660,7 +660,8 @@  add_target_sections (void *owner,
 		     struct target_section *sections_end)
 {
   int count;
-  struct target_section_table *table = current_target_sections;
+  struct target_section_table *table
+    = &current_program_space->target_sections;
 
   count = sections_end - sections;
 
@@ -700,7 +701,8 @@  add_target_sections (void *owner,
 void
 add_target_sections_of_objfile (struct objfile *objfile)
 {
-  struct target_section_table *table = current_target_sections;
+  struct target_section_table *table
+    = &current_program_space->target_sections;
   struct obj_section *osect;
   int space;
   unsigned count = 0;
@@ -747,7 +749,8 @@  void
 remove_target_sections (void *owner)
 {
   struct target_section *src, *dest;
-  struct target_section_table *table = current_target_sections;
+  struct target_section_table *table
+    = &current_program_space->target_sections;
 
   gdb_assert (owner != NULL);
 
@@ -1006,7 +1009,7 @@  section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
 struct target_section_table *
 exec_target::get_section_table ()
 {
-  return current_target_sections;
+  return &current_program_space->target_sections;
 }
 
 enum target_xfer_status
@@ -1105,7 +1108,7 @@  void
 exec_target::files_info ()
 {
   if (exec_bfd)
-    print_section_info (current_target_sections, exec_bfd);
+    print_section_info (&current_program_space->target_sections, exec_bfd);
   else
     puts_filtered (_("\t<no file loaded>\n"));
 }
@@ -1131,7 +1134,7 @@  set_section_command (const char *args, int from_tty)
   /* Parse out new virtual address.  */
   secaddr = parse_and_eval_address (args);
 
-  table = current_target_sections;
+  table = &current_program_space->target_sections;
   for (p = table->sections; p < table->sections_end; p++)
     {
       if (!strncmp (secname, bfd_section_name (p->the_bfd_section), seclen)
@@ -1161,7 +1164,7 @@  exec_set_section_address (const char *filename, int index, CORE_ADDR address)
   struct target_section *p;
   struct target_section_table *table;
 
-  table = current_target_sections;
+  table = &current_program_space->target_sections;
   for (p = table->sections; p < table->sections_end; p++)
     {
       if (filename_cmp (filename,
@@ -1179,8 +1182,8 @@  exec_target::has_memory ()
 {
   /* We can provide memory if we have any file/target sections to read
      from.  */
-  return (current_target_sections->sections
-	  != current_target_sections->sections_end);
+  return (current_program_space->target_sections.sections
+	  != current_program_space->target_sections.sections_end);
 }
 
 char *
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 777bef2e38e..ef39f8a1dab 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -365,10 +365,6 @@  struct address_space
 
 #define symfile_objfile current_program_space->symfile_object_file
 
-/* The set of target sections matching the sections mapped into the
-   current program space.  */
-#define current_target_sections (&current_program_space->target_sections)
-
 /* The list of all program spaces.  There's always at least one.  */
 extern std::vector<struct program_space *>program_spaces;
 
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 94a6ac83754..ae76bb74c05 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -424,12 +424,12 @@  scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
   if (sect == NULL)
     return 0;
 
-  for (target_section = current_target_sections->sections;
-       target_section < current_target_sections->sections_end;
+  for (target_section = current_program_space->target_sections->sections;
+       target_section < current_program_space->target_sections->sections_end;
        target_section++)
     if (sect == target_section->the_bfd_section)
       break;
-  if (target_section < current_target_sections->sections_end)
+  if (target_section < current_program_space->target_sections->sections_end)
     dyn_addr = target_section->addr;
   else
     {
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 570450c5400..520d9e8ed12 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -608,12 +608,12 @@  scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr,
   if (sect == NULL)
     return 0;
 
-  for (target_section = current_target_sections->sections;
-       target_section < current_target_sections->sections_end;
+  for (target_section = current_program_space->target_sections.sections;
+       target_section < current_program_space->target_sections.sections_end;
        target_section++)
     if (sect == target_section->the_bfd_section)
       break;
-  if (target_section < current_target_sections->sections_end)
+  if (target_section < current_program_space->target_sections.sections_end)
     dyn_addr = target_section->addr;
   else
     {