diff options
author | Tom Tromey <tom@tromey.com> | 2017-11-22 23:37:38 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-03-07 15:36:28 -0700 |
commit | e0d3522b888033febd153a4a7d3b7c5c13641f09 (patch) | |
tree | 9c5c11152ba3b7202fac5dba1a9f21a35c85d3d5 /gdb/linux-tdep.c | |
parent | d6ab64818b9d212691c200c292dc0f18d193598c (diff) | |
download | gdb-e0d3522b888033febd153a4a7d3b7c5c13641f09.zip gdb-e0d3522b888033febd153a4a7d3b7c5c13641f09.tar.gz gdb-e0d3522b888033febd153a4a7d3b7c5c13641f09.tar.bz2 |
Return gdb::optional<std::string> from target_fileio_readlink
This changes to_fileio_readlink and target_fileio_readlink to return a
gdb::optional<std::sring>, and then fixes up the callers and
implementations. This allows the removal of some cleanups.
Regression tested by the buildbot.
gdb/ChangeLog
2018-03-07 Tom Tromey <tom@tromey.com>
* linux-tdep.c (linux_info_proc): Update.
* target.h (struct target_ops) <to_fileio_readlink>: Return
optional<string>.
(target_fileio_readlink): Return optional<string>.
* remote.c (remote_hostio_readlink): Return optional<string>.
* inf-child.c (inf_child_fileio_readlink): Return
optional<string>.
* target.c (target_fileio_readlink): Return optional<string>.
Diffstat (limited to 'gdb/linux-tdep.c')
-rw-r--r-- | gdb/linux-tdep.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index d54e56c..b5bb162 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -764,26 +764,20 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, if (cwd_f) { xsnprintf (filename, sizeof filename, "/proc/%ld/cwd", pid); - data = target_fileio_readlink (NULL, filename, &target_errno); - if (data) - { - struct cleanup *cleanup = make_cleanup (xfree, data); - printf_filtered ("cwd = '%s'\n", data); - do_cleanups (cleanup); - } + gdb::optional<std::string> contents + = target_fileio_readlink (NULL, filename, &target_errno); + if (contents.has_value ()) + printf_filtered ("cwd = '%s'\n", contents->c_str ()); else warning (_("unable to read link '%s'"), filename); } if (exe_f) { xsnprintf (filename, sizeof filename, "/proc/%ld/exe", pid); - data = target_fileio_readlink (NULL, filename, &target_errno); - if (data) - { - struct cleanup *cleanup = make_cleanup (xfree, data); - printf_filtered ("exe = '%s'\n", data); - do_cleanups (cleanup); - } + gdb::optional<std::string> contents + = target_fileio_readlink (NULL, filename, &target_errno); + if (contents.has_value ()) + printf_filtered ("exe = '%s'\n", contents->c_str ()); else warning (_("unable to read link '%s'"), filename); } |