Browse Source

gdbsupport: constify some return values in print-utils.{h,cc}

There is no reason the callers of these functions need to change the
returned string, so change the `char *` return types to `const char *`.

Update a few callers to also use `const char *`.

Change-Id: I94adff574d5e1b326e8cc688cf1817a15b408b96
Approved-By: Tom Tromey <tom@tromey.com>
master
Simon Marchi 2 years ago
parent
commit
523e454fab
  1. 2
      gdb/dwarf2/types.h
  2. 2
      gdb/symtab.c
  3. 2
      gdbserver/utils.cc
  4. 2
      gdbserver/utils.h
  5. 20
      gdbsupport/print-utils.cc
  6. 16
      gdbsupport/print-utils.h

2
gdb/dwarf2/types.h

@ -31,7 +31,7 @@ DEFINE_OFFSET_TYPE (cu_offset, unsigned int);
section. */ section. */
DEFINE_OFFSET_TYPE (sect_offset, uint64_t); DEFINE_OFFSET_TYPE (sect_offset, uint64_t);
static inline char * static inline const char *
sect_offset_str (sect_offset offset) sect_offset_str (sect_offset offset)
{ {
return hex_string (to_underlying (offset)); return hex_string (to_underlying (offset));

2
gdb/symtab.c

@ -5177,7 +5177,7 @@ static void
print_msymbol_info (struct bound_minimal_symbol msymbol) print_msymbol_info (struct bound_minimal_symbol msymbol)
{ {
struct gdbarch *gdbarch = msymbol.objfile->arch (); struct gdbarch *gdbarch = msymbol.objfile->arch ();
char *tmp; const char *tmp;
if (gdbarch_addr_bit (gdbarch) <= 32) if (gdbarch_addr_bit (gdbarch) <= 32)
tmp = hex_string_custom (msymbol.value_address () tmp = hex_string_custom (msymbol.value_address ()

2
gdbserver/utils.cc

@ -99,7 +99,7 @@ internal_vwarning (const char *file, int line, const char *fmt, va_list args)
/* Convert a CORE_ADDR into a HEX string, like %lx. /* Convert a CORE_ADDR into a HEX string, like %lx.
The result is stored in a circular static buffer, NUMCELLS deep. */ The result is stored in a circular static buffer, NUMCELLS deep. */
char * const char *
paddress (CORE_ADDR addr) paddress (CORE_ADDR addr)
{ {
return phex_nz (addr, sizeof (CORE_ADDR)); return phex_nz (addr, sizeof (CORE_ADDR));

2
gdbserver/utils.h

@ -19,6 +19,6 @@
#ifndef GDBSERVER_UTILS_H #ifndef GDBSERVER_UTILS_H
#define GDBSERVER_UTILS_H #define GDBSERVER_UTILS_H
char *paddress (CORE_ADDR addr); const char *paddress (CORE_ADDR addr);
#endif /* GDBSERVER_UTILS_H */ #endif /* GDBSERVER_UTILS_H */

20
gdbsupport/print-utils.cc

@ -122,7 +122,7 @@ octal2str (ULONGEST addr, int width)
/* See print-utils.h. */ /* See print-utils.h. */
char * const char *
pulongest (ULONGEST u) pulongest (ULONGEST u)
{ {
return decimal2str ("", u, 0); return decimal2str ("", u, 0);
@ -130,7 +130,7 @@ pulongest (ULONGEST u)
/* See print-utils.h. */ /* See print-utils.h. */
char * const char *
plongest (LONGEST l) plongest (LONGEST l)
{ {
if (l < 0) if (l < 0)
@ -144,7 +144,7 @@ static int thirty_two = 32;
/* See print-utils.h. */ /* See print-utils.h. */
char * const char *
phex (ULONGEST l, int sizeof_l) phex (ULONGEST l, int sizeof_l)
{ {
char *str; char *str;
@ -170,7 +170,7 @@ phex (ULONGEST l, int sizeof_l)
xsnprintf (str, PRINT_CELL_SIZE, "%02x", (unsigned short) (l & 0xff)); xsnprintf (str, PRINT_CELL_SIZE, "%02x", (unsigned short) (l & 0xff));
break; break;
default: default:
str = phex (l, sizeof (l)); return phex (l, sizeof (l));
break; break;
} }
@ -179,7 +179,7 @@ phex (ULONGEST l, int sizeof_l)
/* See print-utils.h. */ /* See print-utils.h. */
char * const char *
phex_nz (ULONGEST l, int sizeof_l) phex_nz (ULONGEST l, int sizeof_l)
{ {
char *str; char *str;
@ -212,7 +212,7 @@ phex_nz (ULONGEST l, int sizeof_l)
xsnprintf (str, PRINT_CELL_SIZE, "%x", (unsigned short) (l & 0xff)); xsnprintf (str, PRINT_CELL_SIZE, "%x", (unsigned short) (l & 0xff));
break; break;
default: default:
str = phex_nz (l, sizeof (l)); return phex_nz (l, sizeof (l));
break; break;
} }
@ -221,7 +221,7 @@ phex_nz (ULONGEST l, int sizeof_l)
/* See print-utils.h. */ /* See print-utils.h. */
char * const char *
hex_string (LONGEST num) hex_string (LONGEST num)
{ {
char *result = get_print_cell (); char *result = get_print_cell ();
@ -232,7 +232,7 @@ hex_string (LONGEST num)
/* See print-utils.h. */ /* See print-utils.h. */
char * const char *
hex_string_custom (LONGEST num, int width) hex_string_custom (LONGEST num, int width)
{ {
char *result = get_print_cell (); char *result = get_print_cell ();
@ -254,7 +254,7 @@ hex_string_custom: insufficient space to store result"));
/* See print-utils.h. */ /* See print-utils.h. */
char * const char *
int_string (LONGEST val, int radix, int is_signed, int width, int_string (LONGEST val, int radix, int is_signed, int width,
int use_c_format) int use_c_format)
{ {
@ -262,7 +262,7 @@ int_string (LONGEST val, int radix, int is_signed, int width,
{ {
case 16: case 16:
{ {
char *result; const char *result;
if (width == 0) if (width == 0)
result = hex_string (val); result = hex_string (val);

16
gdbsupport/print-utils.h

@ -27,34 +27,34 @@
/* %u for ULONGEST. The result is stored in a circular static buffer, /* %u for ULONGEST. The result is stored in a circular static buffer,
NUMCELLS deep. */ NUMCELLS deep. */
extern char *pulongest (ULONGEST u); extern const char *pulongest (ULONGEST u);
/* %d for LONGEST. The result is stored in a circular static buffer, /* %d for LONGEST. The result is stored in a circular static buffer,
NUMCELLS deep. */ NUMCELLS deep. */
extern char *plongest (LONGEST l); extern const char *plongest (LONGEST l);
/* Convert a ULONGEST into a HEX string, like %lx, with leading zeros. /* Convert a ULONGEST into a HEX string, like %lx, with leading zeros.
The result is stored in a circular static buffer, NUMCELLS deep. */ The result is stored in a circular static buffer, NUMCELLS deep. */
extern char *phex (ULONGEST l, int sizeof_l); extern const char *phex (ULONGEST l, int sizeof_l);
/* Convert a ULONGEST into a HEX string, like %lx, without leading zeros. /* Convert a ULONGEST into a HEX string, like %lx, without leading zeros.
The result is stored in a circular static buffer, NUMCELLS deep. */ The result is stored in a circular static buffer, NUMCELLS deep. */
extern char *phex_nz (ULONGEST l, int sizeof_l); extern const char *phex_nz (ULONGEST l, int sizeof_l);
/* Converts a LONGEST to a C-format hexadecimal literal and stores it /* Converts a LONGEST to a C-format hexadecimal literal and stores it
in a static string. Returns a pointer to this string. */ in a static string. Returns a pointer to this string. */
extern char *hex_string (LONGEST num); extern const char *hex_string (LONGEST num);
/* Converts a LONGEST number to a C-format hexadecimal literal and /* Converts a LONGEST number to a C-format hexadecimal literal and
stores it in a static string. Returns a pointer to this string stores it in a static string. Returns a pointer to this string
that is valid until the next call. The number is padded on the that is valid until the next call. The number is padded on the
left with 0s to at least WIDTH characters. */ left with 0s to at least WIDTH characters. */
extern char *hex_string_custom (LONGEST num, int width); extern const char *hex_string_custom (LONGEST num, int width);
/* Convert VAL to a numeral in the given radix. For /* Convert VAL to a numeral in the given radix. For
* radix 10, IS_SIGNED may be true, indicating a signed quantity; * radix 10, IS_SIGNED may be true, indicating a signed quantity;
@ -63,8 +63,8 @@ extern char *hex_string_custom (LONGEST num, int width);
* to use C format in all cases. If it is false, then 'x' * to use C format in all cases. If it is false, then 'x'
* and 'o' formats do not include a prefix (0x or leading 0). */ * and 'o' formats do not include a prefix (0x or leading 0). */
extern char *int_string (LONGEST val, int radix, int is_signed, int width, extern const char *int_string (LONGEST val, int radix, int is_signed, int width,
int use_c_format); int use_c_format);
/* Convert a CORE_ADDR into a string. */ /* Convert a CORE_ADDR into a string. */

Loading…
Cancel
Save