[v2,3/6] Cast to bfd_vma in arm-tdep.c

Message ID 20200225222243.8260-4-tom@tromey.com
State New
Headers show
Series
  • Change gdbserver to use existing gdbsupport
Related show

Commit Message

Tom Tromey Feb. 25, 2020, 10:22 p.m.
Some arm-tdep.c data structures use a bfd_vma.  A couple of spots will
warn about an implicit narrowing cast when building a gdb where
CORE_ADDR is 64-bit but bfd_vma is 32-bit.

This patch silences these warnings by introducing an explicit cast.
This seemed both simplest and correct.

2020-02-25  Tom Tromey  <tom@tromey.com>

	* arm-tdep.c (map_key, arm_find_exidx_entry): Cast to bfd_vma.
---
 gdb/ChangeLog  | 4 ++++
 gdb/arm-tdep.c | 5 +++--
 2 files changed, 7 insertions(+), 2 deletions(-)

-- 
2.17.2

Comments

Simon Marchi March 11, 2020, 3:38 a.m. | #1
On 2020-02-25 5:22 p.m., Tom Tromey wrote:
> Some arm-tdep.c data structures use a bfd_vma.  A couple of spots will

> warn about an implicit narrowing cast when building a gdb where

> CORE_ADDR is 64-bit but bfd_vma is 32-bit.

> 

> This patch silences these warnings by introducing an explicit cast.

> This seemed both simplest and correct.


Did you consider changing arm_mapping_symbol::value to be a CORE_ADDR?  It would
seem even simpler and safe to me.

Simon
Tom Tromey March 12, 2020, 5:58 p.m. | #2
Simon> Did you consider changing arm_mapping_symbol::value to be a
Simon> CORE_ADDR?  It would seem even simpler and safe to me.

For some reason I thought this was harder, but I tried it and it is
fine.  Here's the updated patch.

Tom

commit a01a37e95dc6927020783184eff1c82660b1cbf5
Author: Tom Tromey <tom@tromey.com>
Date:   Tue Mar 10 16:09:37 2020 -0600

    Cast to bfd_vma in arm-tdep.c
    
    Some arm-tdep.c data structures use a bfd_vma.  A couple of spots will
    warn about an implicit narrowing cast when building a gdb where
    CORE_ADDR is 64-bit but bfd_vma is 32-bit.
    
    This patch silences these warnings by changing the types in question
    to CORE_ADDR.
    
    gdb/ChangeLog
    2020-03-10  Tom Tromey  <tom@tromey.com>
    
            * arm-tdep.c (struct arm_mapping_symbol) <value>: Now a
            CORE_ADDR.
            (struct arm_exidx_entry) <addr>: Now a CORE_ADDR.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 86bbcaaa39f..280cf03a6a6 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-10  Tom Tromey  <tom@tromey.com>
+
+	* arm-tdep.c (struct arm_mapping_symbol) <value>: Now a
+	CORE_ADDR.
+	(struct arm_exidx_entry) <addr>: Now a CORE_ADDR.
+
 2020-03-10  Tom Tromey  <tom@tromey.com>
 
 	* remote.c (remote_target::download_tracepoint)
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 175c5b956e7..44c439a85f5 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -81,7 +81,7 @@ static bool arm_debug;
 
 struct arm_mapping_symbol
 {
-  bfd_vma value;
+  CORE_ADDR value;
   char type;
 
   bool operator< (const arm_mapping_symbol &other) const
@@ -1986,7 +1986,7 @@ struct frame_unwind arm_prologue_unwind = {
 
 struct arm_exidx_entry
 {
-  bfd_vma addr;
+  CORE_ADDR addr;
   gdb_byte *entry;
 
   bool operator< (const arm_exidx_entry &other) const
Simon Marchi March 12, 2020, 6:05 p.m. | #3
On 2020-03-12 1:58 p.m., Tom Tromey wrote:
> Simon> Did you consider changing arm_mapping_symbol::value to be a

> Simon> CORE_ADDR?  It would seem even simpler and safe to me.

> 

> For some reason I thought this was harder, but I tried it and it is

> fine.  Here's the updated patch.

> 

> Tom


Nice, thanks.

The series LGTM otherwise.

Simon
Tom Tromey March 12, 2020, 7:35 p.m. | #4
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:


Simon> The series LGTM otherwise.

Thanks.  I'm going to check it in now.

Tom

Patch

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 175c5b956e7..d395c7f7b75 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -366,7 +366,7 @@  arm_find_mapping_symbol (CORE_ADDR memaddr, CORE_ADDR *start)
 	    }
 
 	  struct arm_mapping_symbol map_key
-	    = { memaddr - obj_section_addr (sec), 0 };
+	    = { (bfd_vma) (memaddr - obj_section_addr (sec)), 0 };
 	  arm_mapping_symbol_vec::const_iterator it
 	    = std::lower_bound (map.begin (), map.end (), map_key);
 
@@ -2246,7 +2246,8 @@  arm_find_exidx_entry (CORE_ADDR memaddr, CORE_ADDR *start)
   if (sec != NULL)
     {
       struct arm_exidx_data *data;
-      struct arm_exidx_entry map_key = { memaddr - obj_section_addr (sec), 0 };
+      struct arm_exidx_entry map_key
+	= { (bfd_vma) (memaddr - obj_section_addr (sec)), 0 };
 
       data = arm_exidx_data_key.get (sec->objfile->obfd);
       if (data != NULL)