[RFA,05/13] Make a few calls in *-tdep.c for effect

Message ID 20180712205208.32646-6-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey July 12, 2018, 8:52 p.m. UTC
  In a few cases, there were calls in *-tdep.c that I did not want to
remove because I was not certain that it was safe -- perhaps the side
effect of the function (generally throwing an error) was desired.

2018-07-12  Tom Tromey  <tom@tromey.com>

	* tic6x-tdep.c (tic6x_push_dummy_call): Call find_function_addr
	for effect.
	* sparc64-tdep.c (adi_examine_command): Call get_adi_info_proc for
	effect.
	* rs6000-lynx178-tdep.c (rs6000_lynx178_push_dummy_call): Call
	find_function_addr for effect.
	* nios2-tdep.c (nios2_push_dummy_call): Call find_function_addr
	for effect.
	* mep-tdep.c (mep_push_dummy_call): Call find_function_addr for
	effect.
---
 gdb/ChangeLog             | 13 +++++++++++++
 gdb/mep-tdep.c            |  4 +++-
 gdb/nios2-tdep.c          |  4 +++-
 gdb/rs6000-lynx178-tdep.c |  4 +++-
 gdb/sparc64-tdep.c        |  3 ++-
 gdb/tic6x-tdep.c          |  4 +++-
 6 files changed, 27 insertions(+), 5 deletions(-)
  

Comments

Simon Marchi July 12, 2018, 9:58 p.m. UTC | #1
On 2018-07-12 04:52 PM, Tom Tromey wrote:
> In a few cases, there were calls in *-tdep.c that I did not want to
> remove because I was not certain that it was safe -- perhaps the side
> effect of the function (generally throwing an error) was desired.

I am fairly confident that the find_function_addr calls are not necessary.
If you look at call_function_by_hand_dummy, it calls find_function_addr
with the same function argument before calling push_dummy_call:

  CORE_ADDR funaddr = find_function_addr (function, &values_type, &ftype);

So if the function has to throw, it will be in this invocation.  The fact
that no widely tested architecture does that also leads me to think it's
unnecessary.

I don't think the get_adi_info_proc call is useful either.  All it does
is return the sparc64_adi_info belonging to inferior_ptid.  If it already
exists, the call does nothing.  If it does not already exist, it will be
created.  The call adi_available just before will have created it, if it
didn't already.

Simon
  
Tom Tromey July 13, 2018, 8:46 p.m. UTC | #2
>>>>> "Simon" == Simon Marchi <simon.marchi@ericsson.com> writes:

Simon> I am fairly confident that the find_function_addr calls are not necessary.
[...]

I'll just merge this into the first patch.

Tom
  
Pedro Alves July 16, 2018, 2:03 p.m. UTC | #3
On 07/12/2018 10:58 PM, Simon Marchi wrote:
> On 2018-07-12 04:52 PM, Tom Tromey wrote:
>> In a few cases, there were calls in *-tdep.c that I did not want to
>> remove because I was not certain that it was safe -- perhaps the side
>> effect of the function (generally throwing an error) was desired.
> 
> I am fairly confident that the find_function_addr calls are not necessary.
> If you look at call_function_by_hand_dummy, it calls find_function_addr
> with the same function argument before calling push_dummy_call:
> 
>   CORE_ADDR funaddr = find_function_addr (function, &values_type, &ftype);
> 
> So if the function has to throw, it will be in this invocation.  The fact
> that no widely tested architecture does that also leads me to think it's
> unnecessary.
> 
> I don't think the get_adi_info_proc call is useful either.  All it does
> is return the sparc64_adi_info belonging to inferior_ptid.  If it already
> exists, the call does nothing.  If it does not already exist, it will be
> created.  The call adi_available just before will have created it, if it
> didn't already.

Agreed.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index c8a5ecfbe07..0a6fe7de663 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -2264,9 +2264,11 @@  mep_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR *copy = (CORE_ADDR *) alloca (argc * sizeof (copy[0]));
-  CORE_ADDR func_addr = find_function_addr (function, NULL);
   int i;
 
+  /* Call for side effects.  */
+  find_function_addr (function, NULL);
+
   /* The number of the next register available to hold an argument.  */
   int arg_reg;
 
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index 91b4381f0b7..230e39d6671 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -1820,9 +1820,11 @@  nios2_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int argnum;
   int len = 0;
   int stack_offset = 0;
-  CORE_ADDR func_addr = find_function_addr (function, NULL);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
+  /* Call for side effects.  */
+  find_function_addr (function, NULL);
+
   /* Set the return address register to point to the entry point of
      the program, where a breakpoint lies in wait.  */
   regcache_cooked_write_signed (regcache, NIOS2_RA_REGNUM, bp_addr);
diff --git a/gdb/rs6000-lynx178-tdep.c b/gdb/rs6000-lynx178-tdep.c
index 13eed3aeaea..cbd235791ea 100644
--- a/gdb/rs6000-lynx178-tdep.c
+++ b/gdb/rs6000-lynx178-tdep.c
@@ -44,7 +44,9 @@  rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
   gdb_byte tmp_buffer[50];
   int f_argno = 0;		/* current floating point argno */
   int wordsize = gdbarch_tdep (gdbarch)->wordsize;
-  CORE_ADDR func_addr = find_function_addr (function, NULL);
+
+  /* Call for side effects.  */
+  find_function_addr (function, NULL);
 
   struct value *arg = 0;
   struct type *type;
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index 8d96cfc0969..e8befaed6ec 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -462,7 +462,8 @@  adi_examine_command (const char *args, int from_tty)
     error (_("No ADI information"));
 
   pid_t pid = inferior_ptid.pid ();
-  sparc64_adi_info *proc = get_adi_info_proc (pid);
+  /* Call for side effects.  */
+  get_adi_info_proc (pid);
   int cnt = 1;
   const char *p = args;
   if (p && *p == '/')
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index efb8b0561b4..6a143422dca 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -882,13 +882,15 @@  tic6x_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int argnum;
   int stack_offset = 4;
   int references_offset = 4;
-  CORE_ADDR func_addr = find_function_addr (function, NULL);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct type *func_type = value_type (function);
   /* The first arg passed on stack.  Mostly the first 10 args are passed by
      registers.  */
   int first_arg_on_stack = 10;
 
+  /* Call for side effects.  */
+  find_function_addr (function, NULL);
+
   /* Set the return address register to point to the entry point of
      the program, where a breakpoint lies in wait.  */
   regcache_cooked_write_unsigned (regcache, TIC6X_RA_REGNUM, bp_addr);