aboutsummaryrefslogtreecommitdiff
path: root/gdb/common
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-01-13 10:56:06 +0000
committerPedro Alves <palves@redhat.com>2016-01-13 10:59:14 +0000
commit43792cf0de3a49fb871d432343672bdf16270e99 (patch)
treea0c0937a8ca20d3bbfd466ebf2e1f65f5aabcb24 /gdb/common
parent8465445732dc04c3fb6cf954274e12d06b274f08 (diff)
downloadgdb-43792cf0de3a49fb871d432343672bdf16270e99.zip
gdb-43792cf0de3a49fb871d432343672bdf16270e99.tar.gz
gdb-43792cf0de3a49fb871d432343672bdf16270e99.tar.bz2
Centralize thread ID printing
Add a new function to print a thread ID, in the style of paddress, plongest, etc. and adjust all CLI-reachable paths to use it. This gives us a single place to tweak to print inferior-qualified thread IDs later: - [Switching to thread 1 (Thread 0x7ffff7fc2740 (LWP 8155))] + [Switching to thread 1.1 (Thread 0x7ffff7fc2740 (LWP 8155))] etc., though for now, this has no user-visible change. No regressions on x86_64 Fedora 20. gdb/ChangeLog: 2016-01-13 Pedro Alves <palves@redhat.com> * breakpoint.c (remove_threaded_breakpoints) (print_one_breakpoint_location): Use print_thread_id. * btrace.c (btrace_enable, btrace_disable, btrace_teardown) (btrace_fetch, btrace_clear): Use print_thread_id. * common/print-utils.c (CELLSIZE): Delete. (get_cell): Rename to ... (get_print_cell): ... this and made extern. Adjust call callers. Adjust to use PRINT_CELL_SIZE. * common/print-utils.h (get_print_cell): Declare. (PRINT_CELL_SIZE): New. * gdbthread.h (print_thread_id): Declare. * infcmd.c (signal_command): Use print_thread_id. * inferior.c (print_inferior): Use print_thread_id. * infrun.c (handle_signal_stop) (insert_exception_resume_breakpoint) (insert_exception_resume_from_probe) (print_signal_received_reason): Use print_thread_id. * record-btrace.c (record_btrace_info) (record_btrace_resume_thread, record_btrace_cancel_resume) (record_btrace_step_thread, record_btrace_wait): Use print_thread_id. * thread.c (thread_apply_all_command): Use print_thread_id. (print_thread_id): New function. (thread_apply_command): Use print_thread_id. (thread_command, thread_find_command, do_captured_thread_select): Use print_thread_id.
Diffstat (limited to 'gdb/common')
-rw-r--r--gdb/common/print-utils.c71
-rw-r--r--gdb/common/print-utils.h8
2 files changed, 44 insertions, 35 deletions
diff --git a/gdb/common/print-utils.c b/gdb/common/print-utils.c
index 5bb83b5..1a21404 100644
--- a/gdb/common/print-utils.c
+++ b/gdb/common/print-utils.c
@@ -21,15 +21,15 @@
#include "print-utils.h"
/* Temporary storage using circular buffer. */
+/* Number of cells in the circular buffer. */
#define NUMCELLS 16
-#define CELLSIZE 50
/* Return the next entry in the circular buffer. */
-static char *
-get_cell (void)
+char *
+get_print_cell (void)
{
- static char buf[NUMCELLS][CELLSIZE];
+ static char buf[NUMCELLS][PRINT_CELL_SIZE];
static int cell = 0;
if (++cell >= NUMCELLS)
@@ -43,7 +43,7 @@ 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 ();
+ char *str = get_print_cell ();
int i = 0;
do
@@ -62,14 +62,14 @@ decimal2str (char *sign, ULONGEST addr, int width)
switch (i)
{
case 1:
- xsnprintf (str, CELLSIZE, "%s%0*lu", sign, width, temp[0]);
+ xsnprintf (str, PRINT_CELL_SIZE, "%s%0*lu", sign, width, temp[0]);
break;
case 2:
- xsnprintf (str, CELLSIZE, "%s%0*lu%09lu", sign, width,
+ xsnprintf (str, PRINT_CELL_SIZE, "%s%0*lu%09lu", sign, width,
temp[1], temp[0]);
break;
case 3:
- xsnprintf (str, CELLSIZE, "%s%0*lu%09lu%09lu", sign, width,
+ xsnprintf (str, PRINT_CELL_SIZE, "%s%0*lu%09lu%09lu", sign, width,
temp[2], temp[1], temp[0]);
break;
default:
@@ -84,7 +84,7 @@ static char *
octal2str (ULONGEST addr, int width)
{
unsigned long temp[3];
- char *str = get_cell ();
+ char *str = get_print_cell ();
int i = 0;
do
@@ -104,15 +104,15 @@ octal2str (ULONGEST addr, int width)
{
case 1:
if (temp[0] == 0)
- xsnprintf (str, CELLSIZE, "%*o", width, 0);
+ xsnprintf (str, PRINT_CELL_SIZE, "%*o", width, 0);
else
- xsnprintf (str, CELLSIZE, "0%0*lo", width, temp[0]);
+ xsnprintf (str, PRINT_CELL_SIZE, "0%0*lo", width, temp[0]);
break;
case 2:
- xsnprintf (str, CELLSIZE, "0%0*lo%010lo", width, temp[1], temp[0]);
+ xsnprintf (str, PRINT_CELL_SIZE, "0%0*lo%010lo", width, temp[1], temp[0]);
break;
case 3:
- xsnprintf (str, CELLSIZE, "0%0*lo%010lo%010lo", width,
+ xsnprintf (str, PRINT_CELL_SIZE, "0%0*lo%010lo%010lo", width,
temp[2], temp[1], temp[0]);
break;
default:
@@ -155,18 +155,18 @@ phex (ULONGEST l, int sizeof_l)
switch (sizeof_l)
{
case 8:
- str = get_cell ();
- xsnprintf (str, CELLSIZE, "%08lx%08lx",
+ str = get_print_cell ();
+ xsnprintf (str, PRINT_CELL_SIZE, "%08lx%08lx",
(unsigned long) (l >> thirty_two),
(unsigned long) (l & 0xffffffff));
break;
case 4:
- str = get_cell ();
- xsnprintf (str, CELLSIZE, "%08lx", (unsigned long) l);
+ str = get_print_cell ();
+ xsnprintf (str, PRINT_CELL_SIZE, "%08lx", (unsigned long) l);
break;
case 2:
- str = get_cell ();
- xsnprintf (str, CELLSIZE, "%04x", (unsigned short) (l & 0xffff));
+ str = get_print_cell ();
+ xsnprintf (str, PRINT_CELL_SIZE, "%04x", (unsigned short) (l & 0xffff));
break;
default:
str = phex (l, sizeof (l));
@@ -189,22 +189,22 @@ phex_nz (ULONGEST l, int sizeof_l)
{
unsigned long high = (unsigned long) (l >> thirty_two);
- str = get_cell ();
+ str = get_print_cell ();
if (high == 0)
- xsnprintf (str, CELLSIZE, "%lx",
+ xsnprintf (str, PRINT_CELL_SIZE, "%lx",
(unsigned long) (l & 0xffffffff));
else
- xsnprintf (str, CELLSIZE, "%lx%08lx", high,
+ xsnprintf (str, PRINT_CELL_SIZE, "%lx%08lx", high,
(unsigned long) (l & 0xffffffff));
break;
}
case 4:
- str = get_cell ();
- xsnprintf (str, CELLSIZE, "%lx", (unsigned long) l);
+ str = get_print_cell ();
+ xsnprintf (str, PRINT_CELL_SIZE, "%lx", (unsigned long) l);
break;
case 2:
- str = get_cell ();
- xsnprintf (str, CELLSIZE, "%x", (unsigned short) (l & 0xffff));
+ str = get_print_cell ();
+ xsnprintf (str, PRINT_CELL_SIZE, "%x", (unsigned short) (l & 0xffff));
break;
default:
str = phex_nz (l, sizeof (l));
@@ -219,9 +219,9 @@ phex_nz (ULONGEST l, int sizeof_l)
char *
hex_string (LONGEST num)
{
- char *result = get_cell ();
+ char *result = get_print_cell ();
- xsnprintf (result, CELLSIZE, "0x%s", phex_nz (num, sizeof (num)));
+ xsnprintf (result, PRINT_CELL_SIZE, "0x%s", phex_nz (num, sizeof (num)));
return result;
}
@@ -230,14 +230,14 @@ hex_string (LONGEST num)
char *
hex_string_custom (LONGEST num, int width)
{
- char *result = get_cell ();
- char *result_end = result + CELLSIZE - 1;
+ char *result = get_print_cell ();
+ char *result_end = result + PRINT_CELL_SIZE - 1;
const char *hex = phex_nz (num, sizeof (num));
int hex_len = strlen (hex);
if (hex_len > width)
width = hex_len;
- if (width + 2 >= CELLSIZE)
+ if (width + 2 >= PRINT_CELL_SIZE)
internal_error (__FILE__, __LINE__, _("\
hex_string_custom: insufficient space to store result"));
@@ -294,7 +294,7 @@ int_string (LONGEST val, int radix, int is_signed, int width,
const char *
core_addr_to_string (const CORE_ADDR addr)
{
- char *str = get_cell ();
+ char *str = get_print_cell ();
strcpy (str, "0x");
strcat (str, phex (addr, sizeof (addr)));
@@ -306,7 +306,7 @@ core_addr_to_string (const CORE_ADDR addr)
const char *
core_addr_to_string_nz (const CORE_ADDR addr)
{
- char *str = get_cell ();
+ char *str = get_print_cell ();
strcpy (str, "0x");
strcat (str, phex_nz (addr, sizeof (addr)));
@@ -318,8 +318,9 @@ core_addr_to_string_nz (const CORE_ADDR addr)
const char *
host_address_to_string_1 (const void *addr)
{
- char *str = get_cell ();
+ char *str = get_print_cell ();
- xsnprintf (str, CELLSIZE, "0x%s", phex_nz ((uintptr_t) addr, sizeof (addr)));
+ xsnprintf (str, PRINT_CELL_SIZE, "0x%s",
+ phex_nz ((uintptr_t) addr, sizeof (addr)));
return str;
}
diff --git a/gdb/common/print-utils.h b/gdb/common/print-utils.h
index 706877b..8790d0b 100644
--- a/gdb/common/print-utils.h
+++ b/gdb/common/print-utils.h
@@ -20,6 +20,10 @@
#ifndef COMMON_CELLS_H
#define COMMON_CELLS_H
+/* How many characters (including the terminating null byte) fit in a
+ cell. */
+#define PRINT_CELL_SIZE 50
+
/* %d for LONGEST. The result is stored in a circular static buffer,
NUMCELLS deep. */
@@ -71,4 +75,8 @@ extern const char *host_address_to_string_1 (const void *addr);
#define host_address_to_string(ADDR) \
host_address_to_string_1 ((const void *) (ADDR))
+/* Return the next entry in the circular print buffer. */
+
+extern char *get_print_cell (void);
+
#endif /* COMMON_CELLS_H */