[c++,4/6] gdb_bfd_lookup_symbol: Cast const char* arguments to void*

Message ID 561BDC5C.4030309@gmail.com
State New, archived
Headers

Commit Message

Simon Marchi Oct. 12, 2015, 4:14 p.m. UTC
  On 12/10/15 06:16 AM, Yao Qi wrote:
> Simon Marchi <simon.marchi@polymtl.ca> writes:
> 
>> /home/pedro/gdb/mygit/src/gdb/solib-frv.c: In function ‘int enable_break2()’:
>> /home/pedro/gdb/mygit/src/gdb/solib-frv.c:622:72: error: invalid conversion from ‘const void*’ to ‘void*’ [-fpermissive]
>>        addr = gdb_bfd_lookup_symbol (tmp_bfd, cmp_name, "_dl_debug_addr");
>>                                                                         ^
>> In file included from /home/pedro/gdb/mygit/src/gdb/solib-frv.c:23:0:
>> /home/pedro/gdb/mygit/src/gdb/solib.h:82:18: error:   initializing argument 3 of ‘CORE_ADDR gdb_bfd_lookup_symbol(bfd*, int (*)(asymbol*, void*), void*)’ [-fpermissive]
>>  extern CORE_ADDR gdb_bfd_lookup_symbol (bfd *abfd,
>>                   ^
>>
>> The call in question is:
>>
>>       addr = gdb_bfd_lookup_symbol (tmp_bfd, cmp_name, "_dl_debug_addr");
> 
> Hi Simon,
> Did you consider the possibility that changing argument 'data' type to
> 'const void *'? like this,
> 
> CORE_ADDR
> gdb_bfd_lookup_symbol (bfd *abfd,
> 		       int (*match_sym) (asymbol *, void *),
> 		       const void *data)

Hi Yao,

I thought I did and that it wasn't possible, but I guess I confused this
change with another one.  It seems to be possible, here is the updated patch:



From 83c9c91ae836a67faecaff4cf73d410b298508f4 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Mon, 12 Oct 2015 10:36:33 -0400
Subject: [PATCH] Constify arguments of gdb_bfd_lookup_symbol and related
 functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

/home/pedro/gdb/mygit/src/gdb/solib-frv.c: In function ‘int enable_break2()’:
/home/pedro/gdb/mygit/src/gdb/solib-frv.c:622:72: error: invalid conversion from ‘const void*’ to ‘void*’ [-fpermissive]
       addr = gdb_bfd_lookup_symbol (tmp_bfd, cmp_name, "_dl_debug_addr");
                                                                        ^
In file included from /home/pedro/gdb/mygit/src/gdb/solib-frv.c:23:0:
/home/pedro/gdb/mygit/src/gdb/solib.h:82:18: error:   initializing argument 3 of ‘CORE_ADDR gdb_bfd_lookup_symbol(bfd*, int (*)(asymbol*, void*), void*)’ [-fpermissive]
 extern CORE_ADDR gdb_bfd_lookup_symbol (bfd *abfd,
                  ^

The call in question is:

      addr = gdb_bfd_lookup_symbol (tmp_bfd, cmp_name, "_dl_debug_addr");


gdb/ChangeLog:

	* solib-dsbt.c (cmp_name): Constify arguments.
	* solib-frv.c (cmp_name): Likewise.
	* solib-svr4.c (svr4_create_solib_event_breakpoints): Likewise.
	* solib.c (gdb_bfd_lookup_symbol_from_symtab): Likewise.
	(bfd_lookup_symbol_from_dyn_symtab): Likewise.
	(gdb_bfd_lookup_symbol): Likewise.
	* solib.h (gdb_bfd_lookup_symbol): Likewise.
	(gdb_bfd_lookup_symbol_from_symtab): Likewise.
---
 gdb/solib-dsbt.c |  2 +-
 gdb/solib-frv.c  |  2 +-
 gdb/solib-svr4.c |  4 ++--
 gdb/solib.c      | 14 ++++++++------
 gdb/solib.h      | 12 +++++++-----
 5 files changed, 19 insertions(+), 15 deletions(-)
  

Comments

Yao Qi Oct. 13, 2015, 4:09 p.m. UTC | #1
Simon Marchi <thundersim@gmail.com> writes:

> gdb/ChangeLog:
>
> 	* solib-dsbt.c (cmp_name): Constify arguments.
> 	* solib-frv.c (cmp_name): Likewise.
> 	* solib-svr4.c (svr4_create_solib_event_breakpoints): Likewise.
> 	* solib.c (gdb_bfd_lookup_symbol_from_symtab): Likewise.
> 	(bfd_lookup_symbol_from_dyn_symtab): Likewise.
> 	(gdb_bfd_lookup_symbol): Likewise.
> 	* solib.h (gdb_bfd_lookup_symbol): Likewise.
> 	(gdb_bfd_lookup_symbol_from_symtab): Likewise.

Patch is OK.
  
Simon Marchi Oct. 13, 2015, 4:43 p.m. UTC | #2
On 13 October 2015 at 12:09, Yao Qi <qiyaoltc@gmail.com> wrote:
> Patch is OK.


Thanks, pushed!
  

Patch

diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 3218bbe..d01f9db 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -777,7 +777,7 @@  enable_break_failure_warning (void)
 /* Helper function for gdb_bfd_lookup_symbol.  */

 static int
-cmp_name (asymbol *sym, void *data)
+cmp_name (const asymbol *sym, const void *data)
 {
   return (strcmp (sym->name, (const char *) data) == 0);
 }
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index 922ee36..451bbdf 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -484,7 +484,7 @@  enable_break_failure_warning (void)
 /* Helper function for gdb_bfd_lookup_symbol.  */

 static int
-cmp_name (asymbol *sym, void *data)
+cmp_name (const asymbol *sym, const void *data)
 {
   return (strcmp (sym->name, (const char *) data) == 0);
 }
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 55b8f55..2dc1692 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -2220,7 +2220,7 @@  svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
 /* Helper function for gdb_bfd_lookup_symbol.  */

 static int
-cmp_name_and_sec_flags (asymbol *sym, void *data)
+cmp_name_and_sec_flags (const asymbol *sym, const void *data)
 {
   return (strcmp (sym->name, (const char *) data) == 0
 	  && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0);
@@ -2480,7 +2480,7 @@  enable_break (struct svr4_info *info, int from_tty)
       for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
 	{
 	  sym_addr = gdb_bfd_lookup_symbol (tmp_bfd, cmp_name_and_sec_flags,
-					    (void *) *bkpt_namep);
+					    *bkpt_namep);
 	  if (sym_addr != 0)
 	    break;
 	}
diff --git a/gdb/solib.c b/gdb/solib.c
index 9a6e7de..ca2c9ab 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1533,8 +1533,9 @@  solib_global_lookup (struct objfile *objfile,

 CORE_ADDR
 gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
-				   int (*match_sym) (asymbol *, void *),
-				   void *data)
+				   int (*match_sym) (const asymbol *,
+						     const void *),
+				   const void *data)
 {
   long storage_needed = bfd_get_symtab_upper_bound (abfd);
   CORE_ADDR symaddr = 0;
@@ -1592,8 +1593,9 @@  gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,

 static CORE_ADDR
 bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
-				   int (*match_sym) (asymbol *, void *),
-				   void *data)
+				   int (*match_sym) (const asymbol *,
+						     const void *),
+				   const void *data)
 {
   long storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
   CORE_ADDR symaddr = 0;
@@ -1630,8 +1632,8 @@  bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,

 CORE_ADDR
 gdb_bfd_lookup_symbol (bfd *abfd,
-		       int (*match_sym) (asymbol *, void *),
-		       void *data)
+		       int (*match_sym) (const asymbol *, const void *),
+		       const void *data)
 {
   CORE_ADDR symaddr = gdb_bfd_lookup_symbol_from_symtab (abfd, match_sym, data);

diff --git a/gdb/solib.h b/gdb/solib.h
index 336971d..165df9c 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -80,15 +80,17 @@  extern int libpthread_name_p (const char *name);
 /* Look up symbol from both symbol table and dynamic string table.  */

 extern CORE_ADDR gdb_bfd_lookup_symbol (bfd *abfd,
-					int (*match_sym) (asymbol *, void *),
-					void *data);
+					int (*match_sym) (const asymbol *,
+							  const void *),
+					const void *data);

 /* Look up symbol from symbol table.  */

 extern CORE_ADDR gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
-						    int (*match_sym) (asymbol *,
-								      void *),
-						    void *data);
+						    int (*match_sym)
+						      (const asymbol *,
+						       const void *),
+						    const void *data);

 /* Enable or disable optional solib event breakpoints as appropriate.  */