aboutsummaryrefslogtreecommitdiff
path: root/gdb/top.c
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2021-09-09 12:29:39 +0200
committerTom de Vries <tdevries@suse.de>2021-09-09 12:29:39 +0200
commit86fe51fcc7a78def0b3ed289c0e1e7e8af283acc (patch)
tree253f4db9ce3f893e710d1163aabb08179dee46bc /gdb/top.c
parent0b233e34c801eac78a5e03b66f18585cf368e4d5 (diff)
downloadfsf-binutils-gdb-86fe51fcc7a78def0b3ed289c0e1e7e8af283acc.zip
fsf-binutils-gdb-86fe51fcc7a78def0b3ed289c0e1e7e8af283acc.tar.gz
fsf-binutils-gdb-86fe51fcc7a78def0b3ed289c0e1e7e8af283acc.tar.bz2
[gdb/testsuite] Reimplement gdb.gdb/complaints.exp as unittest
When building gdb with "-Wall -O2 -g -flto=auto", I run into: ... (gdb) call clear_complaints()^M No symbol "clear_complaints" in current context.^M (gdb) FAIL: gdb.gdb/complaints.exp: clear complaints ... The problem is that lto has optimized away the clear_complaints function and consequently the selftest doesn't work. Fix this by reimplementing the selftest as a unit test. Factor out two new functions: - void execute_fn_to_ui_file (struct ui_file *file, std::function<void(void)> fn); - std::string execute_fn_to_string (std::function<void(void)> fn, bool term_out); and use the latter to capture the complaints output. Tested on x86_64-linux.
Diffstat (limited to 'gdb/top.c')
-rw-r--r--gdb/top.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/gdb/top.c b/gdb/top.c
index 0c49f4f..7e95ed3 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -696,12 +696,10 @@ execute_command (const char *p, int from_tty)
cleanup_if_error.release ();
}
-/* Run execute_command for P and FROM_TTY. Sends its output to FILE,
- do not display it to the screen. BATCH_FLAG will be
- temporarily set to true. */
+/* See gdbcmd.h. */
void
-execute_command_to_ui_file (struct ui_file *file, const char *p, int from_tty)
+execute_fn_to_ui_file (struct ui_file *file, std::function<void(void)> fn)
{
/* GDB_STDOUT should be better already restored during these
restoration callbacks. */
@@ -724,22 +722,39 @@ execute_command_to_ui_file (struct ui_file *file, const char *p, int from_tty)
scoped_restore save_stdtargerr
= make_scoped_restore (&gdb_stdtargerr, file);
- execute_command (p, from_tty);
+ fn ();
}
}
/* See gdbcmd.h. */
std::string
-execute_command_to_string (const char *p, int from_tty,
- bool term_out)
+execute_fn_to_string (std::function<void(void)> fn, bool term_out)
{
string_file str_file (term_out);
- execute_command_to_ui_file (&str_file, p, from_tty);
+ execute_fn_to_ui_file (&str_file, fn);
return std::move (str_file.string ());
}
+/* See gdbcmd.h. */
+
+void
+execute_command_to_ui_file (struct ui_file *file,
+ const char *p, int from_tty)
+{
+ execute_fn_to_ui_file (file, [=]() { execute_command (p, from_tty); });
+}
+
+/* See gdbcmd.h. */
+
+std::string
+execute_command_to_string (const char *p, int from_tty,
+ bool term_out)
+{
+ return
+ execute_fn_to_string ([=]() { execute_command (p, from_tty); }, term_out);
+}
/* When nonzero, cause dont_repeat to do nothing. This should only be
set via prevent_dont_repeat. */