btrace, gdbserver: use exceptions to convey btrace enable/disable errors

Change error reporting to use exceptions and be prepared to catch them in
gdbserver.  We use the exception message in our error reply to GDB.

This may remove some detail from the error message in the native case since
errno is no longer printed.  Later patches will improve that.

We're still using error strings on the RSP level.  This patch does not affect
the interoperability of older/newer GDB/gdbserver.

gdbserver/
	* server.c (handle_btrace_enable_bts, handle_btrace_enable_pt)
	(handle_btrace_disable): Change return type to void.  Use exceptions
	to report errors.
	(handle_btrace_general_set): Catch exception and copy message to
	return message.

gdb/
	* nat/linux-btrace.c (linux_enable_btrace): Throw exception if enabling
	btrace failed.
	* x86-linux-nat.c (x86_linux_enable_btrace): Catch btrace enabling
	exception and use message in own exception.
This commit is contained in:
Markus Metzger 2018-01-19 09:41:42 +01:00
parent 5c3284c1ec
commit 9ee23a853c
5 changed files with 53 additions and 39 deletions

View file

@ -216,14 +216,17 @@ static struct btrace_target_info *
x86_linux_enable_btrace (struct target_ops *self, ptid_t ptid,
const struct btrace_config *conf)
{
struct btrace_target_info *tinfo;
errno = 0;
tinfo = linux_enable_btrace (ptid, conf);
if (tinfo == NULL)
error (_("Could not enable branch tracing for %s: %s."),
target_pid_to_str (ptid), safe_strerror (errno));
struct btrace_target_info *tinfo = nullptr;
TRY
{
tinfo = linux_enable_btrace (ptid, conf);
}
CATCH (exception, RETURN_MASK_ERROR)
{
error (_("Could not enable branch tracing for %s: %s"),
target_pid_to_str (ptid), exception.message);
}
END_CATCH
return tinfo;
}