diff options
author | Markus Metzger <mmetzger@sourceware.org> | 2013-03-11 08:35:11 +0000 |
---|---|---|
committer | Markus Metzger <mmetzger@sourceware.org> | 2013-03-11 08:35:11 +0000 |
commit | 9accd112a61b0eaee2724185171761707b4f53e1 (patch) | |
tree | b013f3c141d0cc1e19ed02d848b90d215b89871f /gdb/gdbserver/server.c | |
parent | 5cc22e4cf71283b8f54e27511b3a9e1c54adfe9f (diff) | |
download | gdb-9accd112a61b0eaee2724185171761707b4f53e1.zip gdb-9accd112a61b0eaee2724185171761707b4f53e1.tar.gz gdb-9accd112a61b0eaee2724185171761707b4f53e1.tar.bz2 |
Add the gdb remote target operations for branch tracing.
We define the following packets:
Qbtrace:bts enable branch tracing for the current thread
returns "OK" or "Enn"
Qbtrace:off disable branch tracing for the current thread
returns "OK" or "Enn"
qXfer:btrace:read read the full branch trace data for the current thread
gdb/
* target.h (enum target_object): Add TARGET_OBJECT_BTRACE.
* remote.c: Include btrace.h.
(struct btrace_target_info): New struct.
(remote_supports_btrace): New function.
(send_Qbtrace): New function.
(remote_enable_btrace): New function.
(remote_disable_btrace): New function.
(remote_teardown_btrace): New function.
(remote_read_btrace): New function.
(init_remote_ops): Add btrace ops.
(enum <unnamed>): Add btrace packets.
(struct protocol_feature remote_protocol_features[]): Add btrace packets.
(_initialize_remote): Add packet configuration for branch tracing.
gdbserver/
* target.h (struct target_ops): Add btrace ops.
(target_supports_btrace): New macro.
(target_enable_btrace): New macro.
(target_disable_btrace): New macro.
(target_read_btrace): New macro.
* gdbthread.h (struct thread_info): Add btrace field.
* server.c: Include btrace-common.h.
(handle_btrace_general_set): New function.
(handle_btrace_enable): New function.
(handle_btrace_disable): New function.
(handle_general_set): Call handle_btrace_general_set.
(handle_qxfer_btrace): New function.
(struct qxfer qxfer_packets[]): Add btrace entry.
* inferiors.c (remove_thread): Disable btrace.
* linux-low: Include linux-btrace.h.
(linux_low_enable_btrace): New function.
(linux_low_read_btrace): New function.
(linux_target_ops): Add btrace ops.
* configure.srv (i[34567]86-*-linux*): Add linux-btrace.o.
Add srv_linux_btrace=yes.
(x86_64-*-linux*): Add linux-btrace.o.
Add srv_linux_btrace=yes.
* configure.ac: Define HAVE_LINUX_BTRACE.
* config.in: Regenerated.
* configure: Regenerated.
Diffstat (limited to 'gdb/gdbserver/server.c')
-rw-r--r-- | gdb/gdbserver/server.c | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index 9592c69..6bb36d8 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -28,6 +28,7 @@ #include <signal.h> #endif #include "gdb_wait.h" +#include "btrace-common.h" /* The thread set with an `Hc' packet. `Hc' is deprecated in favor of `vCont'. Note the multi-process extensions made `vCont' a @@ -396,6 +397,88 @@ write_qxfer_response (char *buf, const void *data, int len, int is_more) PBUFSIZ - 2) + 1; } +/* Handle btrace enabling. */ + +static const char * +handle_btrace_enable (struct thread_info *thread) +{ + if (thread->btrace != NULL) + return "E.Btrace already enabled."; + + thread->btrace = target_enable_btrace (thread->entry.id); + if (thread->btrace == NULL) + return "E.Could not enable btrace."; + + return NULL; +} + +/* Handle btrace disabling. */ + +static const char * +handle_btrace_disable (struct thread_info *thread) +{ + + if (thread->btrace == NULL) + return "E.Branch tracing not enabled."; + + if (target_disable_btrace (thread->btrace) != 0) + return "E.Could not disable branch tracing."; + + thread->btrace = NULL; + return NULL; +} + +/* Handle the "Qbtrace" packet. */ + +static int +handle_btrace_general_set (char *own_buf) +{ + struct thread_info *thread; + const char *err; + char *op; + + if (strncmp ("Qbtrace:", own_buf, strlen ("Qbtrace:")) != 0) + return 0; + + op = own_buf + strlen ("Qbtrace:"); + + if (!target_supports_btrace ()) + { + strcpy (own_buf, "E.Target does not support branch tracing."); + return -1; + } + + if (ptid_equal (general_thread, null_ptid) + || ptid_equal (general_thread, minus_one_ptid)) + { + strcpy (own_buf, "E.Must select a single thread."); + return -1; + } + + thread = find_thread_ptid (general_thread); + if (thread == NULL) + { + strcpy (own_buf, "E.No such thread."); + return -1; + } + + err = NULL; + + if (strcmp (op, "bts") == 0) + err = handle_btrace_enable (thread); + else if (strcmp (op, "off") == 0) + err = handle_btrace_disable (thread); + else + err = "E.Bad Qbtrace operation. Use bts or off."; + + if (err != 0) + strcpy (own_buf, err); + else + write_ok (own_buf); + + return 1; +} + /* Handle all of the extended 'Q' packets. */ static void @@ -552,6 +635,9 @@ handle_general_set (char *own_buf) return; } + if (handle_btrace_general_set (own_buf)) + return; + /* Otherwise we didn't know what packet it was. Say we didn't understand it. */ own_buf[0] = 0; @@ -1251,9 +1337,77 @@ handle_qxfer_fdpic (const char *annex, gdb_byte *readbuf, return (*the_target->read_loadmap) (annex, offset, readbuf, len); } +/* Handle qXfer:btrace:read. */ + +static int +handle_qxfer_btrace (const char *annex, + gdb_byte *readbuf, const gdb_byte *writebuf, + ULONGEST offset, LONGEST len) +{ + static struct buffer cache; + struct thread_info *thread; + int type; + + if (the_target->read_btrace == NULL || writebuf != NULL) + return -2; + + if (!target_running ()) + return -1; + + if (ptid_equal (general_thread, null_ptid) + || ptid_equal (general_thread, minus_one_ptid)) + { + strcpy (own_buf, "E.Must select a single thread."); + return -3; + } + + thread = find_thread_ptid (general_thread); + if (thread == NULL) + { + strcpy (own_buf, "E.No such thread."); + return -3; + } + + if (thread->btrace == NULL) + { + strcpy (own_buf, "E.Btrace not enabled."); + return -3; + } + + if (strcmp (annex, "all") == 0) + type = btrace_read_all; + else if (strcmp (annex, "new") == 0) + type = btrace_read_new; + else + { + strcpy (own_buf, "E.Bad annex."); + return -3; + } + + if (offset == 0) + { + buffer_free (&cache); + + target_read_btrace (thread->btrace, &cache, type); + } + else if (offset > cache.used_size) + { + buffer_free (&cache); + return -3; + } + + if (len > cache.used_size - offset) + len = cache.used_size - offset; + + memcpy (readbuf, cache.buffer + offset, len); + + return len; +} + static const struct qxfer qxfer_packets[] = { { "auxv", handle_qxfer_auxv }, + { "btrace", handle_qxfer_btrace }, { "fdpic", handle_qxfer_fdpic}, { "features", handle_qxfer_features }, { "libraries", handle_qxfer_libraries }, @@ -1656,6 +1810,13 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) if (target_supports_agent ()) strcat (own_buf, ";QAgent+"); + if (target_supports_btrace ()) + { + strcat (own_buf, ";Qbtrace:bts+"); + strcat (own_buf, ";Qbtrace:off+"); + strcat (own_buf, ";qXfer:btrace:read+"); + } + return; } |