[gdb/testsuite] Reimplement gdb.gdb/complaints.exp as unittest
authorTom de Vries <tdevries@suse.de>
Thu, 9 Sep 2021 10:29:39 +0000 (12:29 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 9 Sep 2021 10:29:39 +0000 (12:29 +0200)
commit86fe51fcc7a78def0b3ed289c0e1e7e8af283acc
tree253f4db9ce3f893e710d1163aabb08179dee46bc
parent0b233e34c801eac78a5e03b66f18585cf368e4d5
[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.
gdb/complaints.c
gdb/gdbcmd.h
gdb/testsuite/gdb.gdb/complaints.exp [deleted file]
gdb/top.c