aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2022-01-24 20:00:46 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2022-01-26 10:01:40 -0500
commit5d10a2041eb843fd321ce1d850cf3e0df7648bc7 (patch)
treea1bd00ecbd780dc194da8d44b713b09f10446c0a /gdb/tui
parentb583c328e71369f90f4042ac7973ce9edfdb44b3 (diff)
downloadgdb-5d10a2041eb843fd321ce1d850cf3e0df7648bc7.zip
gdb-5d10a2041eb843fd321ce1d850cf3e0df7648bc7.tar.gz
gdb-5d10a2041eb843fd321ce1d850cf3e0df7648bc7.tar.bz2
gdb: add string_file::release method
A common pattern for string_file is to want to move out the internal string buffer, because it is the result of the computation that we want to return. It is the reason why string_file::string returns a non-const reference, as explained in the comment. I think it would make sense to have a dedicated method for that instead and make string_file::string return a const reference. This allows removing the explicit std::move in the typical case. Note that compile_program::compute was missing a move, meaning that the resulting string was copied. With the new version, it's not possible to forget to move. Change-Id: Ieaefa35b73daa7930b2f3a26988b6e3b4121bb79
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-disasm.c6
-rw-r--r--gdb/tui/tui-regs.c2
-rw-r--r--gdb/tui/tui-stack.c8
3 files changed, 8 insertions, 8 deletions
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index f40d4e2..445503a 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -130,14 +130,12 @@ tui_disassemble (struct gdbarch *gdbarch,
}
/* Capture the disassembled instruction. */
- tal.insn = std::move (gdb_dis_out.string ());
- gdb_dis_out.clear ();
+ tal.insn = gdb_dis_out.release ();
/* And capture the address the instruction is at. */
tal.addr = orig_pc;
print_address (gdbarch, orig_pc, &gdb_dis_out);
- tal.addr_string = std::move (gdb_dis_out.string ());
- gdb_dis_out.clear ();
+ tal.addr_string = std::move (gdb_dis_out.release ());
if (addr_size != nullptr)
{
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 16b6c08..d53ce54 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -100,7 +100,7 @@ tui_register_format (struct frame_info *frame, int regnum)
gdbarch_print_registers_info (gdbarch, &stream, frame, regnum, 1);
/* Remove the possible \n. */
- std::string &str = stream.string ();
+ std::string str = stream.release ();
if (!str.empty () && str.back () == '\n')
str.resize (str.size () - 1);
diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index 0489a5f..be8ffbd 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -181,12 +181,14 @@ tui_locator_window::make_status_line () const
string.puts (pc_buf);
}
+ std::string string_val = string.release ();
+
if (string.size () < status_size)
- string.puts (n_spaces (status_size - string.size ()));
+ string_val.append (status_size - string.size (), ' ');
else if (string.size () > status_size)
- string.string ().erase (status_size, string.size ());
+ string_val.erase (status_size, string.size ());
- return std::move (string.string ());
+ return string_val;
}
/* Get a printable name for the function at the address. The symbol