Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: [pushed] gdb: Constify solib_find (Re: [RFA 2/8] Use class to manage BFD reference counts)
Date: Tue, 20 Dec 2016 17:19:00 -0000	[thread overview]
Message-ID: <ed9078ef-a1d8-46be-a15f-dbddecc52f83@redhat.com> (raw)
In-Reply-To: <87fulseza9.fsf@tromey.com>

On 12/13/2016 01:25 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
> 
>>> -    return NULL;
>>> +    return gdb_bfd_ref_ptr ();
> 
> Pedro> This provides a good reason to have an implicit construction from
> Pedro> nullptr_t.  You had it in the original gdbpy_reference
> Pedro> submission, but I had asked to remove it.  If we add it back,
> Pedro> these cases could be more clearly written as "return
> Pedro> NULL/nullptr".  Could you do that, and then drop all the hunks
> Pedro> like:
> 
>>> -    return NULL;
>>> +    return gdb_bfd_ref_ptr ();
> 
> Pedro> ?
> 
> I did this.

Thanks!

> Pedro> I think these could be:
> Pedro>     std::string filename
> Pedro>       = string_printf ("%.*s", filename_len, pathname);
> Pedro>     std::string member_name
> Pedro>       = string_printf ("%.*s", path_len - filename_len - 2, sep + 1));
> 
> I did this, but it's a bit ugly as solib_find isn't const-correct.

That doesn't look hard to fix.  I've pushed in the patch below.
What uglification does this allow removing?

From 992f1ddc3be1f5195f18beaa801ac50f284b10c5 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Tue, 20 Dec 2016 17:07:19 +0000
Subject: [PATCH] gdb: Constify solib_find

gdb/ChangeLog:
2016-12-20  Pedro Alves  <palves@redhat.com>

	* nto-tdep.c (nto_find_and_open_solib): Constify 'solib'
	parameter.
	* nto-tdep.h (nto_find_and_open_solib): Constify 'solib'
	parameter.
	* solib.c (solib_find_1, exec_file_find, solib_find): Constify
	in_pathname' parameter.
	* solist.h (struct target_so_ops) <find_and_open_solib>: Constify
	'soname' parameter.
	(exec_file_find, solib_find): Constify 'in_pathname' parameter.
---
 gdb/ChangeLog  | 12 ++++++++++++
 gdb/nto-tdep.c |  3 ++-
 gdb/nto-tdep.h |  2 +-
 gdb/solib.c    |  8 ++++----
 gdb/solist.h   |  6 +++---
 5 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5f0e6fe..2041dd5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,4 +1,16 @@
 2016-12-20  Pedro Alves  <palves@redhat.com>
+
+	* nto-tdep.c (nto_find_and_open_solib): Constify 'solib'
+	parameter.
+	* nto-tdep.h (nto_find_and_open_solib): Constify 'solib'
+	parameter.
+	* solib.c (solib_find_1, exec_file_find, solib_find): Constify
+	in_pathname' parameter.
+	* solist.h (struct target_so_ops) <find_and_open_solib>: Constify
+	'soname' parameter.
+	(exec_file_find, solib_find): Constify 'in_pathname' parameter.
+
+2016-12-20  Pedro Alves  <palves@redhat.com>
 	    Yao Qi  <yao.qi@linaro.org>
 
 	PR gdb/20977
diff --git a/gdb/nto-tdep.c b/gdb/nto-tdep.c
index 47d8a2b..1b18de1 100644
--- a/gdb/nto-tdep.c
+++ b/gdb/nto-tdep.c
@@ -87,7 +87,8 @@ nto_map_arch_to_cputype (const char *arch)
 }
 
 int
-nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname)
+nto_find_and_open_solib (const char *solib, unsigned o_flags,
+			 char **temp_pathname)
 {
   char *buf, *arch_path, *nto_root;
   const char *endian;
diff --git a/gdb/nto-tdep.h b/gdb/nto-tdep.h
index 81ed50c..06a1f9a 100644
--- a/gdb/nto-tdep.h
+++ b/gdb/nto-tdep.h
@@ -164,7 +164,7 @@ void nto_relocate_section_addresses (struct so_list *,
 
 int nto_map_arch_to_cputype (const char *);
 
-int nto_find_and_open_solib (char *, unsigned, char **);
+int nto_find_and_open_solib (const char *, unsigned, char **);
 
 enum gdb_osabi nto_elf_osabi_sniffer (bfd *abfd);
 
diff --git a/gdb/solib.c b/gdb/solib.c
index c4b2cdc..82214d0 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -152,7 +152,7 @@ show_solib_search_path (struct ui_file *file, int from_tty,
 */
 
 static char *
-solib_find_1 (char *in_pathname, int *fd, int is_solib)
+solib_find_1 (const char *in_pathname, int *fd, int is_solib)
 {
   const struct target_so_ops *ops = solib_ops (target_gdbarch ());
   int found_file = -1;
@@ -383,7 +383,7 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
    file handle for the main executable.  */
 
 char *
-exec_file_find (char *in_pathname, int *fd)
+exec_file_find (const char *in_pathname, int *fd)
 {
   char *result;
   const char *fskind = effective_target_file_system_kind ();
@@ -434,7 +434,7 @@ exec_file_find (char *in_pathname, int *fd)
    above.  */
 
 char *
-solib_find (char *in_pathname, int *fd)
+solib_find (const char *in_pathname, int *fd)
 {
   const char *solib_symbols_extension
     = gdbarch_solib_symbols_extension (target_gdbarch ());
@@ -443,7 +443,7 @@ solib_find (char *in_pathname, int *fd)
      extension.  */
   if (solib_symbols_extension != NULL)
     {
-      char *p = in_pathname + strlen (in_pathname);
+      const char *p = in_pathname + strlen (in_pathname);
 
       while (p > in_pathname && *p != '.')
 	p--;
diff --git a/gdb/solist.h b/gdb/solist.h
index f709483..948ad31 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -127,7 +127,7 @@ struct target_so_ops
        If TEMP_PATHNAME is non-NULL: If the file is successfully opened a
        pointer to a malloc'd and realpath'd copy of SONAME is stored there,
        otherwise NULL is stored there.  */
-    int (*find_and_open_solib) (char *soname,
+    int (*find_and_open_solib) (const char *soname,
         unsigned o_flags, char **temp_pathname);
 
     /* Hook for looking up global symbols in a library-specific way.  */
@@ -172,10 +172,10 @@ void free_so (struct so_list *so);
 struct so_list *master_so_list (void);
 
 /* Find main executable binary file.  */
-extern char *exec_file_find (char *in_pathname, int *fd);
+extern char *exec_file_find (const char *in_pathname, int *fd);
 
 /* Find shared library binary file.  */
-extern char *solib_find (char *in_pathname, int *fd);
+extern char *solib_find (const char *in_pathname, int *fd);
 
 /* Open BFD for shared library file.  */
 extern bfd *solib_bfd_fopen (char *pathname, int fd);
-- 
2.5.5



  parent reply	other threads:[~2016-12-20 17:19 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29  5:06 [RFA 0/8] C++-ification series #5 Tom Tromey
2016-11-29  5:06 ` [RFA 7/8] Use unique_xmalloc_ptr in execute_gdb_command Tom Tromey
2016-11-29  5:22   ` Tom Tromey
2016-12-15  3:49     ` Tom Tromey
2016-12-20 17:48       ` Pedro Alves
2016-12-20 18:13         ` Tom Tromey
2016-12-23 20:01           ` Tom Tromey
2017-01-10 17:59             ` Pedro Alves
2017-01-10 19:22               ` Tom Tromey
2016-12-20 23:31         ` Tom Tromey
2016-12-20 23:56           ` Pedro Alves
2016-12-22 14:50             ` Tom Tromey
2016-12-22 15:09               ` Pedro Alves
2016-12-22 15:29                 ` Tom Tromey
2016-12-22 15:40                   ` Pedro Alves
2016-12-02 14:49   ` Pedro Alves
2016-12-13 13:30     ` Tom Tromey
2016-11-29  5:06 ` [RFA 4/8] Remove make_cleanup_discard_psymtabs Tom Tromey
2016-12-02 14:21   ` Pedro Alves
2016-11-29  5:06 ` [RFA 3/8] Introduce and use gdb::unlinker Tom Tromey
2016-12-02 13:17   ` Pedro Alves
2016-11-29  5:06 ` [RFA 5/8] Add value_freer Tom Tromey
2016-12-02 14:24   ` Pedro Alves
2016-11-29  5:06 ` [RFA 8/8] Add constructor and destructor to demangle_parse_info Tom Tromey
2016-12-02 15:04   ` Pedro Alves
2016-12-13 13:50     ` Tom Tromey
2016-11-29  5:06 ` [RFA 1/8] Add gdb_ref_ptr.h Tom Tromey
2016-12-02 13:08   ` Pedro Alves
2016-12-02 17:46     ` Tom Tromey
2016-12-02 18:11       ` Pedro Alves
2016-12-02 19:52         ` Tom Tromey
2016-12-02 23:45           ` Pedro Alves
2016-12-03  0:05   ` Pedro Alves
2016-12-13 13:13     ` Tom Tromey
2016-11-29  5:06 ` [RFA 2/8] Use class to manage BFD reference counts Tom Tromey
2016-12-02 13:05   ` Pedro Alves
2016-12-13 13:26     ` Tom Tromey
2016-12-15  4:12       ` Tom Tromey
2016-12-20 18:18         ` Pedro Alves
2016-12-20 17:19       ` Pedro Alves [this message]
2016-12-20 18:05         ` [pushed] gdb: Constify solib_find (Re: [RFA 2/8] Use class to manage BFD reference counts) Tom Tromey
2016-11-29  5:06 ` [RFA 6/8] Use value_freer in dwarf2_evaluate_loc_desc_full Tom Tromey
2016-12-02 14:45   ` Pedro Alves
2016-12-13 13:29     ` Tom Tromey
2016-12-20 14:49       ` Pedro Alves
2016-12-23 19:05         ` Tom Tromey
2016-12-23 19:59           ` Tom Tromey
2017-01-10 17:58             ` Pedro Alves
2016-12-23 19:59           ` Tom Tromey
2017-01-10 17:57             ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed9078ef-a1d8-46be-a15f-dbddecc52f83@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox