From 86fe51fcc7a78def0b3ed289c0e1e7e8af283acc Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Thu, 9 Sep 2021 12:29:39 +0200 Subject: [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 fn); - std::string execute_fn_to_string (std::function fn, bool term_out); and use the latter to capture the complaints output. Tested on x86_64-linux. --- gdb/top.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'gdb/top.c') 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 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 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. */ -- cgit v1.1