btrace, gdbserver: check btrace target pointers
By removing the supports_btrace gdbserver target method we relied on GDB trying to enable branch tracing and failing on the attempt. For targets that do not provide the btrace methods, however, an initial request from GDB for the branch trace configuration to detect whether gdbserver is already recording resulted in a protocol error. Have the btrace target methods throw a "Target does not suppor branch tracing" error and be prepared to handle exceptions in all functions that call btrace target methods. We therefore turn the target_* macros into static inline functions. Also remove the additional btrace target method checks that resulted in the above protocol error. Thanks to Maciej W. Rozycki <macro@mips.com> for reporting this. gdbserver/ * target.h (target_enable_btrace, target_disable_btrace) (target_read_btrace, target_read_btrace_conf): Turn macro into inline function. Throw error if target method is not defined. * server.c (handle_qxfer_btrace, handle_qxfer_btrace_conf): Remove check for btrace target method. Be prepared to handle exceptions from btrace target methods.
This commit is contained in:
parent
ca8e0133c4
commit
b1223e7890
|
@ -1,3 +1,12 @@
|
||||||
|
2018-03-01 Markus Metzger <markus.t.metzger@intel.com>
|
||||||
|
|
||||||
|
* target.h (target_enable_btrace, target_disable_btrace)
|
||||||
|
(target_read_btrace, target_read_btrace_conf): Turn macro into
|
||||||
|
inline function. Throw error if target method is not defined.
|
||||||
|
* server.c (handle_qxfer_btrace handle_qxfer_btrace_conf): Remove
|
||||||
|
check for btrace target method. Be prepared to handle exceptions
|
||||||
|
from btrace target methods.
|
||||||
|
|
||||||
2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com>
|
2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com>
|
||||||
|
|
||||||
* server.c (captured_main): Change order of error message printed
|
* server.c (captured_main): Change order of error message printed
|
||||||
|
|
|
@ -1852,7 +1852,7 @@ handle_qxfer_btrace (const char *annex,
|
||||||
enum btrace_read_type type;
|
enum btrace_read_type type;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (the_target->read_btrace == NULL || writebuf != NULL)
|
if (writebuf != NULL)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
if (ptid_equal (general_thread, null_ptid)
|
if (ptid_equal (general_thread, null_ptid)
|
||||||
|
@ -1891,12 +1891,21 @@ handle_qxfer_btrace (const char *annex,
|
||||||
{
|
{
|
||||||
buffer_free (&cache);
|
buffer_free (&cache);
|
||||||
|
|
||||||
|
TRY
|
||||||
|
{
|
||||||
result = target_read_btrace (thread->btrace, &cache, type);
|
result = target_read_btrace (thread->btrace, &cache, type);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
|
||||||
memcpy (own_buf, cache.buffer, cache.used_size);
|
memcpy (own_buf, cache.buffer, cache.used_size);
|
||||||
return -3;
|
|
||||||
}
|
}
|
||||||
|
CATCH (exception, RETURN_MASK_ERROR)
|
||||||
|
{
|
||||||
|
sprintf (own_buf, "E.%s", exception.message);
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
END_CATCH
|
||||||
|
|
||||||
|
if (result != 0)
|
||||||
|
return -3;
|
||||||
}
|
}
|
||||||
else if (offset > cache.used_size)
|
else if (offset > cache.used_size)
|
||||||
{
|
{
|
||||||
|
@ -1923,7 +1932,7 @@ handle_qxfer_btrace_conf (const char *annex,
|
||||||
struct thread_info *thread;
|
struct thread_info *thread;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (the_target->read_btrace_conf == NULL || writebuf != NULL)
|
if (writebuf != NULL)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
if (annex[0] != '\0')
|
if (annex[0] != '\0')
|
||||||
|
@ -1953,12 +1962,21 @@ handle_qxfer_btrace_conf (const char *annex,
|
||||||
{
|
{
|
||||||
buffer_free (&cache);
|
buffer_free (&cache);
|
||||||
|
|
||||||
|
TRY
|
||||||
|
{
|
||||||
result = target_read_btrace_conf (thread->btrace, &cache);
|
result = target_read_btrace_conf (thread->btrace, &cache);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
|
||||||
memcpy (own_buf, cache.buffer, cache.used_size);
|
memcpy (own_buf, cache.buffer, cache.used_size);
|
||||||
return -3;
|
|
||||||
}
|
}
|
||||||
|
CATCH (exception, RETURN_MASK_ERROR)
|
||||||
|
{
|
||||||
|
sprintf (own_buf, "E.%s", exception.message);
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
END_CATCH
|
||||||
|
|
||||||
|
if (result != 0)
|
||||||
|
return -3;
|
||||||
}
|
}
|
||||||
else if (offset > cache.used_size)
|
else if (offset > cache.used_size)
|
||||||
{
|
{
|
||||||
|
|
|
@ -620,17 +620,44 @@ int kill_inferior (int);
|
||||||
(the_target->supports_agent ? \
|
(the_target->supports_agent ? \
|
||||||
(*the_target->supports_agent) () : 0)
|
(*the_target->supports_agent) () : 0)
|
||||||
|
|
||||||
#define target_enable_btrace(ptid, conf) \
|
static inline struct btrace_target_info *
|
||||||
(*the_target->enable_btrace) (ptid, conf)
|
target_enable_btrace (ptid_t ptid, const struct btrace_config *conf)
|
||||||
|
{
|
||||||
|
if (the_target->enable_btrace == nullptr)
|
||||||
|
error (_("Target does not support branch tracing."));
|
||||||
|
|
||||||
#define target_disable_btrace(tinfo) \
|
return (*the_target->enable_btrace) (ptid, conf);
|
||||||
(*the_target->disable_btrace) (tinfo)
|
}
|
||||||
|
|
||||||
#define target_read_btrace(tinfo, buffer, type) \
|
static inline int
|
||||||
(*the_target->read_btrace) (tinfo, buffer, type)
|
target_disable_btrace (struct btrace_target_info *tinfo)
|
||||||
|
{
|
||||||
|
if (the_target->disable_btrace == nullptr)
|
||||||
|
error (_("Target does not support branch tracing."));
|
||||||
|
|
||||||
#define target_read_btrace_conf(tinfo, buffer) \
|
return (*the_target->disable_btrace) (tinfo);
|
||||||
(*the_target->read_btrace_conf) (tinfo, buffer)
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
target_read_btrace (struct btrace_target_info *tinfo,
|
||||||
|
struct buffer *buffer,
|
||||||
|
enum btrace_read_type type)
|
||||||
|
{
|
||||||
|
if (the_target->read_btrace == nullptr)
|
||||||
|
error (_("Target does not support branch tracing."));
|
||||||
|
|
||||||
|
return (*the_target->read_btrace) (tinfo, buffer, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
target_read_btrace_conf (struct btrace_target_info *tinfo,
|
||||||
|
struct buffer *buffer)
|
||||||
|
{
|
||||||
|
if (the_target->read_btrace_conf == nullptr)
|
||||||
|
error (_("Target does not support branch tracing."));
|
||||||
|
|
||||||
|
return (*the_target->read_btrace_conf) (tinfo, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
#define target_supports_range_stepping() \
|
#define target_supports_range_stepping() \
|
||||||
(the_target->supports_range_stepping ? \
|
(the_target->supports_range_stepping ? \
|
||||||
|
|
Loading…
Reference in New Issue