aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbserver/utils.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2010-04-09 03:40:00 +0000
committerPedro Alves <palves@redhat.com>2010-04-09 03:40:00 +0000
commit219f2f2398a678322264121a25214b3046180dec (patch)
treec9cb248482f190db5039f4c3a6aec0c96b3b3d3d /gdb/gdbserver/utils.c
parent33da3f1cb51cb8851ab5b12d1f5fa61e45232276 (diff)
downloadgdb-219f2f2398a678322264121a25214b3046180dec.zip
gdb-219f2f2398a678322264121a25214b3046180dec.tar.gz
gdb-219f2f2398a678322264121a25214b3046180dec.tar.bz2
gdb/gdbserver/
* server.h (LONGEST): New. (struct thread_info) <while_stepping>: New field. (unpack_varlen_hex, xrealloc, pulongest, plongest, phex_nz): Declare. (initialize_tracepoint, handle_tracepoint_general_set) (handle_tracepoint_query, tracepoint_finished_step) (tracepoint_was_hit, release_while_stepping_state_list): (current_traceframe): Declare. * server.c (handle_general_set): Handle tracepoint packets. (read_memory): New. (write_memory): New. (handle_search_memory_1): Use read_memory. (handle_query): Report support for conditional tracepoints, trace state variables, and tracepoint sources. Handle tracepoint queries. (main): Initialize the tracepoints module. (process_serial_event): Handle traceframe reads/writes. * linux-low.c (handle_tracepoints): New. (linux_wait_1): Call it. (linux_resume_one_lwp): Handle while-stepping. (linux_supports_tracepoints, linux_read_pc, linux_write_pc): New. (linux_target_ops): Install them. * linux-low.h (struct linux_target_ops) <supports_tracepoints>: New field. * linux-x86-low.c (x86_supports_tracepoints): New. (the_low_target). Install it. * mem-break.h (delete_breakpoint): Declare. * mem-break.c (delete_breakpoint): Make external. * target.h (struct target_ops): Add `supports_tracepoints', `read_pc', and `write_pc' fields. (target_supports_tracepoints): Define. * utils.c (xrealloc, decimal2str, pulongest, plongest, thirty_two) (phex_nz): New. * regcache.h (struct regcache) <registers_owned>: New field. (init_register_cache, regcache_cpy): Declare. (regcache_read_pc, regcache_write_pc): Declare. (register_cache_size): Declare. (supply_regblock): Declare. * regcache.c (init_register_cache): New. (new_register_cache): Use it. (regcache_cpy): New. (register_cache_size): New. (supply_regblock): New. (regcache_read_pc, regcache_write_pc): New. * tracepoint.c: New. * Makefile.in (OBS): Add tracepoint.o. (tracepoint.o): New rule. gdb/ * regformats/regdat.sh: Include server.h. Don't include regcache.h.
Diffstat (limited to 'gdb/gdbserver/utils.c')
-rw-r--r--gdb/gdbserver/utils.c125
1 files changed, 125 insertions, 0 deletions
diff --git a/gdb/gdbserver/utils.c b/gdb/gdbserver/utils.c
index 78c6f66..33671e5 100644
--- a/gdb/gdbserver/utils.c
+++ b/gdb/gdbserver/utils.c
@@ -57,6 +57,26 @@ xmalloc (size_t size)
return newmem;
}
+/* Reallocate memory without fail. This works like xmalloc. */
+
+void *
+xrealloc (void *ptr, size_t size)
+{
+ void *val;
+
+ if (size == 0)
+ size = 1;
+
+ if (ptr != NULL)
+ val = realloc (ptr, size); /* OK: realloc */
+ else
+ val = malloc (size); /* OK: malloc */
+ if (val == NULL)
+ malloc_failure (size);
+
+ return val;
+}
+
/* Allocate memory without fail and set it to zero.
If malloc fails, this will print a message to stderr and exit. */
@@ -229,3 +249,108 @@ paddress (CORE_ADDR addr)
xsnprintf (str, CELLSIZE, "%lx", (long) addr);
return str;
}
+
+static char *
+decimal2str (char *sign, ULONGEST addr, int width)
+{
+ /* Steal code from valprint.c:print_decimal(). Should this worry
+ about the real size of addr as the above does? */
+ unsigned long temp[3];
+ char *str = get_cell ();
+
+ int i = 0;
+ do
+ {
+ temp[i] = addr % (1000 * 1000 * 1000);
+ addr /= (1000 * 1000 * 1000);
+ i++;
+ width -= 9;
+ }
+ while (addr != 0 && i < (sizeof (temp) / sizeof (temp[0])));
+
+ width = 9;
+ if (width < 0)
+ width = 0;
+
+ switch (i)
+ {
+ case 1:
+ xsnprintf (str, CELLSIZE, "%s%0*lu", sign, width, temp[0]);
+ break;
+ case 2:
+ xsnprintf (str, CELLSIZE, "%s%0*lu%09lu", sign, width,
+ temp[1], temp[0]);
+ break;
+ case 3:
+ xsnprintf (str, CELLSIZE, "%s%0*lu%09lu%09lu", sign, width,
+ temp[2], temp[1], temp[0]);
+ break;
+ default:
+ internal_error (__FILE__, __LINE__,
+ "failed internal consistency check");
+ }
+
+ return str;
+}
+
+/* %u for ULONGEST. The result is stored in a circular static buffer,
+ NUMCELLS deep. */
+
+char *
+pulongest (ULONGEST u)
+{
+ return decimal2str ("", u, 0);
+}
+
+/* %d for LONGEST. The result is stored in a circular static buffer,
+ NUMCELLS deep. */
+
+char *
+plongest (LONGEST l)
+{
+ if (l < 0)
+ return decimal2str ("-", -l, 0);
+ else
+ return decimal2str ("", l, 0);
+}
+
+/* Eliminate warning from compiler on 32-bit systems. */
+static int thirty_two = 32;
+
+/* Convert a ULONGEST into a HEX string, like %lx. The result is
+ stored in a circular static buffer, NUMCELLS deep. */
+
+char *
+phex_nz (ULONGEST l, int sizeof_l)
+{
+ char *str;
+
+ switch (sizeof_l)
+ {
+ case 8:
+ {
+ unsigned long high = (unsigned long) (l >> thirty_two);
+ str = get_cell ();
+ if (high == 0)
+ xsnprintf (str, CELLSIZE, "%lx",
+ (unsigned long) (l & 0xffffffff));
+ else
+ xsnprintf (str, CELLSIZE, "%lx%08lx", high,
+ (unsigned long) (l & 0xffffffff));
+ break;
+ }
+ case 4:
+ str = get_cell ();
+ xsnprintf (str, CELLSIZE, "%lx", (unsigned long) l);
+ break;
+ case 2:
+ str = get_cell ();
+ xsnprintf (str, CELLSIZE, "%x", (unsigned short) (l & 0xffff));
+ break;
+ default:
+ str = phex_nz (l, sizeof (l));
+ break;
+ }
+
+ return str;
+}