* [PATCH] Make host_address_to_string/gdb_print_host_address cast parameter to 'void *' @ 2015-10-27 21:28 Pedro Alves 2015-10-27 21:30 ` Simon Marchi 0 siblings, 1 reply; 5+ messages in thread From: Pedro Alves @ 2015-10-27 21:28 UTC (permalink / raw) To: gdb-patches; +Cc: Simon Marchi Fixes a set of errors like: ../../src/gdb/symfile-debug.c: In function âint debug_qf_map_symtabs_matching_filename(objfile*, const char*, const char*, int (*)(symtab*, void*), void*)â: ../../src/gdb/symfile-debug.c:137:39: error: invalid conversion from âint (*)(symtab*, void*)â to âconst void*â [-fpermissive] host_address_to_string (callback), ^ Note this has to work with data and function pointers. In C++11 we may perhaps do something a bit safer, but we're not there yet, and I don't think it really matters. For now just always do a simple C-style cast in host_address_to_string itself. No point in adding a void * cast to each and every caller. gdb/ChangeLog: 2015-10-27 Pedro Alves <palves@redhat.com> * common/print-utils.c (host_address_to_string): Undef. * common/print-utils.h (host_address_to_string): Add a wrapper macro around the host_address_to_string function. * utils.c (): * utils.c (gdb_print_host_address): Undef. * utils.h (gdb_print_host_address): Add a wrapper macro around the host_address_to_string function. --- gdb/common/print-utils.c | 2 ++ gdb/common/print-utils.h | 4 ++++ gdb/utils.c | 2 ++ gdb/utils.h | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/gdb/common/print-utils.c b/gdb/common/print-utils.c index 1c1a5c1..bd62503 100644 --- a/gdb/common/print-utils.c +++ b/gdb/common/print-utils.c @@ -315,6 +315,8 @@ core_addr_to_string_nz (const CORE_ADDR addr) /* See print-utils.h. */ +#undef host_address_to_string + const char * host_address_to_string (const void *addr) { diff --git a/gdb/common/print-utils.h b/gdb/common/print-utils.h index 8d16966..abeb003 100644 --- a/gdb/common/print-utils.h +++ b/gdb/common/print-utils.h @@ -67,4 +67,8 @@ extern const char *core_addr_to_string_nz (const CORE_ADDR addr); extern const char *host_address_to_string (const void *addr); +/* Wrapper that avoids adding a pointless cast to all callers. */ +#define host_address_to_string(ADDR) \ + host_address_to_string ((const void *) (ADDR)) + #endif /* COMMON_CELLS_H */ diff --git a/gdb/utils.c b/gdb/utils.c index afeff12..101e438 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1103,6 +1103,8 @@ print_spaces (int n, struct ui_file *file) /* Print a host address. */ +#undef gdb_print_host_address + void gdb_print_host_address (const void *addr, struct ui_file *stream) { diff --git a/gdb/utils.h b/gdb/utils.h index 995a1cf..a226744 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -248,6 +248,10 @@ extern int filtered_printing_initialized (void); /* Display the host ADDR on STREAM formatted as ``0x%x''. */ extern void gdb_print_host_address (const void *addr, struct ui_file *stream); +/* Wrapper that avoids adding a pointless cast to all callers. */ +#define gdb_print_host_address(ADDR, STREAM) \ + gdb_print_host_address ((const void *) ADDR, STREAM) + /* Convert CORE_ADDR to string in platform-specific manner. This is usually formatted similar to 0x%lx. */ extern const char *paddress (struct gdbarch *gdbarch, CORE_ADDR addr); -- 1.9.3 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Make host_address_to_string/gdb_print_host_address cast parameter to 'void *' 2015-10-27 21:28 [PATCH] Make host_address_to_string/gdb_print_host_address cast parameter to 'void *' Pedro Alves @ 2015-10-27 21:30 ` Simon Marchi 2015-10-28 14:59 ` Pedro Alves 0 siblings, 1 reply; 5+ messages in thread From: Simon Marchi @ 2015-10-27 21:30 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches On 27 October 2015 at 12:01, Pedro Alves <palves@redhat.com> wrote: > Fixes a set of errors like: > > ../../src/gdb/symfile-debug.c: In function ‘int debug_qf_map_symtabs_matching_filename(objfile*, const char*, const char*, int (*)(symtab*, void*), void*)’: > ../../src/gdb/symfile-debug.c:137:39: error: invalid conversion from ‘int (*)(symtab*, void*)’ to ‘const void*’ [-fpermissive] > host_address_to_string (callback), > ^ > > Note this has to work with data and function pointers. In C++11 we > may perhaps do something a bit safer, but we're not there yet, and I > don't think it really matters. For now just always do a simple > C-style cast in host_address_to_string itself. No point in adding a > void * cast to each and every caller. > > gdb/ChangeLog: > 2015-10-27 Pedro Alves <palves@redhat.com> > > * common/print-utils.c (host_address_to_string): Undef. > * common/print-utils.h (host_address_to_string): Add a wrapper > macro around the host_address_to_string function. > * utils.c (): You can drop this last line. > * utils.c (gdb_print_host_address): Undef. > * utils.h (gdb_print_host_address): Add a wrapper macro around the > host_address_to_string function. > --- > gdb/common/print-utils.c | 2 ++ > gdb/common/print-utils.h | 4 ++++ > gdb/utils.c | 2 ++ > gdb/utils.h | 4 ++++ > 4 files changed, 12 insertions(+) > > diff --git a/gdb/common/print-utils.c b/gdb/common/print-utils.c > index 1c1a5c1..bd62503 100644 > --- a/gdb/common/print-utils.c > +++ b/gdb/common/print-utils.c > @@ -315,6 +315,8 @@ core_addr_to_string_nz (const CORE_ADDR addr) > > /* See print-utils.h. */ > > +#undef host_address_to_string > + > const char * > host_address_to_string (const void *addr) > { > diff --git a/gdb/common/print-utils.h b/gdb/common/print-utils.h > index 8d16966..abeb003 100644 > --- a/gdb/common/print-utils.h > +++ b/gdb/common/print-utils.h > @@ -67,4 +67,8 @@ extern const char *core_addr_to_string_nz (const CORE_ADDR addr); > > extern const char *host_address_to_string (const void *addr); > > +/* Wrapper that avoids adding a pointless cast to all callers. */ > +#define host_address_to_string(ADDR) \ > + host_address_to_string ((const void *) (ADDR)) > + > #endif /* COMMON_CELLS_H */ > diff --git a/gdb/utils.c b/gdb/utils.c > index afeff12..101e438 100644 > --- a/gdb/utils.c > +++ b/gdb/utils.c > @@ -1103,6 +1103,8 @@ print_spaces (int n, struct ui_file *file) > > /* Print a host address. */ > > +#undef gdb_print_host_address > + > void > gdb_print_host_address (const void *addr, struct ui_file *stream) > { > diff --git a/gdb/utils.h b/gdb/utils.h > index 995a1cf..a226744 100644 > --- a/gdb/utils.h > +++ b/gdb/utils.h > @@ -248,6 +248,10 @@ extern int filtered_printing_initialized (void); > /* Display the host ADDR on STREAM formatted as ``0x%x''. */ > extern void gdb_print_host_address (const void *addr, struct ui_file *stream); > > +/* Wrapper that avoids adding a pointless cast to all callers. */ > +#define gdb_print_host_address(ADDR, STREAM) \ > + gdb_print_host_address ((const void *) ADDR, STREAM) > + > /* Convert CORE_ADDR to string in platform-specific manner. > This is usually formatted similar to 0x%lx. */ > extern const char *paddress (struct gdbarch *gdbarch, CORE_ADDR addr); > -- > 1.9.3 I'm not a fan of the #undef, it makes it harder to follow what's happening. Why not just rename the existing function to host_address_to_string_1? Same for gdb_print_host_address. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Make host_address_to_string/gdb_print_host_address cast parameter to 'void *' 2015-10-27 21:30 ` Simon Marchi @ 2015-10-28 14:59 ` Pedro Alves 2015-10-28 14:59 ` Simon Marchi 0 siblings, 1 reply; 5+ messages in thread From: Pedro Alves @ 2015-10-28 14:59 UTC (permalink / raw) To: Simon Marchi; +Cc: gdb-patches On 10/27/2015 04:55 PM, Simon Marchi wrote: > On 27 October 2015 at 12:01, Pedro Alves <palves@redhat.com> wrote: >> Fixes a set of errors like: >> >> ../../src/gdb/symfile-debug.c: In function âint debug_qf_map_symtabs_matching_filename(objfile*, const char*, const char*, int (*)(symtab*, void*), void*)â: >> ../../src/gdb/symfile-debug.c:137:39: error: invalid conversion from âint (*)(symtab*, void*)â to âconst void*â [-fpermissive] >> host_address_to_string (callback), >> ^ >> >> Note this has to work with data and function pointers. In C++11 we >> may perhaps do something a bit safer, but we're not there yet, and I >> don't think it really matters. For now just always do a simple >> C-style cast in host_address_to_string itself. No point in adding a >> void * cast to each and every caller. >> >> gdb/ChangeLog: >> 2015-10-27 Pedro Alves <palves@redhat.com> >> >> * common/print-utils.c (host_address_to_string): Undef. >> * common/print-utils.h (host_address_to_string): Add a wrapper >> macro around the host_address_to_string function. >> * utils.c (): > > You can drop this last line. Whoops. > I'm not a fan of the #undef, it makes it harder to follow what's > happening. Why not just rename the existing function to > host_address_to_string_1? > > Same for gdb_print_host_address. I guess I was trying to keep "b gdb_print_host_address" working or something. Aka, no real good reason. Here's the updated patch. From d9ede3df945232d574c9421270f95a650d2238c8 Mon Sep 17 00:00:00 2001 From: Pedro Alves <palves@redhat.com> Date: Tue, 27 Oct 2015 14:57:06 +0000 Subject: [PATCH] Make host_address_to_string/gdb_print_host_address cast parameter to 'void *' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes a set of errors like: ../../src/gdb/symfile-debug.c: In function âint debug_qf_map_symtabs_matching_filename(objfile*, const char*, const char*, int (*)(symtab*, void*), void*)â: ../../src/gdb/symfile-debug.c:137:39: error: invalid conversion from âint (*)(symtab*, void*)â to âconst void*â [-fpermissive] host_address_to_string (callback), ^ Note this has to work with data and function pointers. In C++11 we may perhaps do something a bit safer, but we're not there yet, and I don't think it really matters. For now just always do a simple C-style cast in host_address_to_string itself. No point in adding a void * cast to each and every caller. gdb/ChangeLog: 2015-10-27 Pedro Alves <palves@redhat.com> * common/print-utils.c (host_address_to_string): Rename to ... (host_address_to_string_1): ... this. * common/print-utils.h (host_address_to_string): Reimplement as wrapper around host_address_to_string_1. * utils.c (gdb_print_host_address): Rename to ... (gdb_print_host_address_1): ... this. * utils.h (gdb_print_host_address): Reimplement as wrapper macro around host_address_to_string_1. --- gdb/common/print-utils.c | 2 +- gdb/common/print-utils.h | 6 +++++- gdb/utils.c | 2 +- gdb/utils.h | 6 +++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gdb/common/print-utils.c b/gdb/common/print-utils.c index 1c1a5c1..7eba07d 100644 --- a/gdb/common/print-utils.c +++ b/gdb/common/print-utils.c @@ -316,7 +316,7 @@ core_addr_to_string_nz (const CORE_ADDR addr) /* See print-utils.h. */ const char * -host_address_to_string (const void *addr) +host_address_to_string_1 (const void *addr) { char *str = get_cell (); diff --git a/gdb/common/print-utils.h b/gdb/common/print-utils.h index 8d16966..49bc09a 100644 --- a/gdb/common/print-utils.h +++ b/gdb/common/print-utils.h @@ -65,6 +65,10 @@ extern const char *core_addr_to_string (const CORE_ADDR addr); extern const char *core_addr_to_string_nz (const CORE_ADDR addr); -extern const char *host_address_to_string (const void *addr); +extern const char *host_address_to_string_1 (const void *addr); + +/* Wrapper that avoids adding a pointless cast to all callers. */ +#define host_address_to_string(ADDR) \ + host_address_to_string_1 ((const void *) (ADDR)) #endif /* COMMON_CELLS_H */ diff --git a/gdb/utils.c b/gdb/utils.c index afeff12..255aee8 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1104,7 +1104,7 @@ print_spaces (int n, struct ui_file *file) /* Print a host address. */ void -gdb_print_host_address (const void *addr, struct ui_file *stream) +gdb_print_host_address_1 (const void *addr, struct ui_file *stream) { fprintf_filtered (stream, "%s", host_address_to_string (addr)); } diff --git a/gdb/utils.h b/gdb/utils.h index 995a1cf..e1f3827 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -246,7 +246,11 @@ extern void fputstrn_unfiltered (const char *str, int n, int quotr, extern int filtered_printing_initialized (void); /* Display the host ADDR on STREAM formatted as ``0x%x''. */ -extern void gdb_print_host_address (const void *addr, struct ui_file *stream); +extern void gdb_print_host_address_1 (const void *addr, struct ui_file *stream); + +/* Wrapper that avoids adding a pointless cast to all callers. */ +#define gdb_print_host_address(ADDR, STREAM) \ + gdb_print_host_address_1 ((const void *) ADDR, STREAM) /* Convert CORE_ADDR to string in platform-specific manner. This is usually formatted similar to 0x%lx. */ -- 1.9.3 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Make host_address_to_string/gdb_print_host_address cast parameter to 'void *' 2015-10-28 14:59 ` Pedro Alves @ 2015-10-28 14:59 ` Simon Marchi 2015-10-28 14:59 ` Pedro Alves 0 siblings, 1 reply; 5+ messages in thread From: Simon Marchi @ 2015-10-28 14:59 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches On 27 October 2015 at 13:21, Pedro Alves <palves@redhat.com> wrote: > I guess I was trying to keep "b gdb_print_host_address" working > or something. Aka, no real good reason. Here's the updated patch. Is that something you do frequently? Anyway, now you can do "b gdb_print_host_address_1" :). Looks good. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Make host_address_to_string/gdb_print_host_address cast parameter to 'void *' 2015-10-28 14:59 ` Simon Marchi @ 2015-10-28 14:59 ` Pedro Alves 0 siblings, 0 replies; 5+ messages in thread From: Pedro Alves @ 2015-10-28 14:59 UTC (permalink / raw) To: Simon Marchi; +Cc: gdb-patches On 10/27/2015 05:26 PM, Simon Marchi wrote: > On 27 October 2015 at 13:21, Pedro Alves <palves@redhat.com> wrote: >> I guess I was trying to keep "b gdb_print_host_address" working >> or something. Aka, no real good reason. Here's the updated patch. > > Is that something you do frequently? Pffft, what, you don't??? > Anyway, now you can do "b gdb_print_host_address_1" :). Looks good. Pushed. Thanks, Pedro Alves ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-10-27 17:35 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-10-27 21:28 [PATCH] Make host_address_to_string/gdb_print_host_address cast parameter to 'void *' Pedro Alves 2015-10-27 21:30 ` Simon Marchi 2015-10-28 14:59 ` Pedro Alves 2015-10-28 14:59 ` Simon Marchi 2015-10-28 14:59 ` Pedro Alves
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox