From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 892AA3858D33; Thu, 18 Apr 2024 14:32:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 892AA3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1713450745; bh=Wi1d0q3UI9V2U1ktMbhMxhHbKzEpeTmEIGtL3cZGOsU=; h=From:To:Subject:Date:From; b=yAi12Aw0uPbki8Iair4M/uyiKd4F/d8pNEHe9+ntEier6DyJTuqqJ1j99Tfz3JRX0 DSDWWrmr83VWNXtDfrALVD9443PRSBlBpFQe4Gt8PBKZAuyTTtam3BZLk9loW9Cwfn hjb/nbwQjMr0/Fb62UadF4AliH+qn0aWBL1WENR4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdbsupport: constify some return values in print-utils.{h,cc} X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 31d5afc19d98869aa13c3197f55b8a208fd19da2 X-Git-Newrev: 523e454fab831e07c83a648c5d07370375a1c376 Message-Id: <20240418143225.892AA3858D33@sourceware.org> Date: Thu, 18 Apr 2024 14:32:24 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D523e454fab83= 1e07c83a648c5d07370375a1c376 commit 523e454fab831e07c83a648c5d07370375a1c376 Author: Simon Marchi Date: Wed Apr 17 16:55:28 2024 -0400 gdbsupport: constify some return values in print-utils.{h,cc} =20 There is no reason the callers of these functions need to change the returned string, so change the `char *` return types to `const char *`. =20 Update a few callers to also use `const char *`. =20 Change-Id: I94adff574d5e1b326e8cc688cf1817a15b408b96 Approved-By: Tom Tromey Diff: --- gdb/dwarf2/types.h | 2 +- gdb/symtab.c | 2 +- gdbserver/utils.cc | 2 +- gdbserver/utils.h | 2 +- gdbsupport/print-utils.cc | 20 ++++++++++---------- gdbsupport/print-utils.h | 16 ++++++++-------- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/gdb/dwarf2/types.h b/gdb/dwarf2/types.h index 9db5c635704..f0b9febba15 100644 --- a/gdb/dwarf2/types.h +++ b/gdb/dwarf2/types.h @@ -31,7 +31,7 @@ DEFINE_OFFSET_TYPE (cu_offset, unsigned int); section. */ DEFINE_OFFSET_TYPE (sect_offset, uint64_t); =20 -static inline char * +static inline const char * sect_offset_str (sect_offset offset) { return hex_string (to_underlying (offset)); diff --git a/gdb/symtab.c b/gdb/symtab.c index 86603dfebc3..d931b3a694b 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -5177,7 +5177,7 @@ static void print_msymbol_info (struct bound_minimal_symbol msymbol) { struct gdbarch *gdbarch =3D msymbol.objfile->arch (); - char *tmp; + const char *tmp; =20 if (gdbarch_addr_bit (gdbarch) <=3D 32) tmp =3D hex_string_custom (msymbol.value_address () diff --git a/gdbserver/utils.cc b/gdbserver/utils.cc index 3d3144e33da..302300770e8 100644 --- a/gdbserver/utils.cc +++ b/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. The result is stored in a circular static buffer, NUMCELLS deep. */ =20 -char * +const char * paddress (CORE_ADDR addr) { return phex_nz (addr, sizeof (CORE_ADDR)); diff --git a/gdbserver/utils.h b/gdbserver/utils.h index 7a6d0fd1d37..ad1f82ccb9f 100644 --- a/gdbserver/utils.h +++ b/gdbserver/utils.h @@ -19,6 +19,6 @@ #ifndef GDBSERVER_UTILS_H #define GDBSERVER_UTILS_H =20 -char *paddress (CORE_ADDR addr); +const char *paddress (CORE_ADDR addr); =20 #endif /* GDBSERVER_UTILS_H */ diff --git a/gdbsupport/print-utils.cc b/gdbsupport/print-utils.cc index 565a4791675..a2e43576a7c 100644 --- a/gdbsupport/print-utils.cc +++ b/gdbsupport/print-utils.cc @@ -122,7 +122,7 @@ octal2str (ULONGEST addr, int width) =20 /* See print-utils.h. */ =20 -char * +const char * pulongest (ULONGEST u) { return decimal2str ("", u, 0); @@ -130,7 +130,7 @@ pulongest (ULONGEST u) =20 /* See print-utils.h. */ =20 -char * +const char * plongest (LONGEST l) { if (l < 0) @@ -144,7 +144,7 @@ static int thirty_two =3D 32; =20 /* See print-utils.h. */ =20 -char * +const char * phex (ULONGEST l, int sizeof_l) { char *str; @@ -170,7 +170,7 @@ phex (ULONGEST l, int sizeof_l) xsnprintf (str, PRINT_CELL_SIZE, "%02x", (unsigned short) (l & 0xff)= ); break; default: - str =3D phex (l, sizeof (l)); + return phex (l, sizeof (l)); break; } =20 @@ -179,7 +179,7 @@ phex (ULONGEST l, int sizeof_l) =20 /* See print-utils.h. */ =20 -char * +const char * phex_nz (ULONGEST l, int sizeof_l) { char *str; @@ -212,7 +212,7 @@ phex_nz (ULONGEST l, int sizeof_l) xsnprintf (str, PRINT_CELL_SIZE, "%x", (unsigned short) (l & 0xff)); break; default: - str =3D phex_nz (l, sizeof (l)); + return phex_nz (l, sizeof (l)); break; } =20 @@ -221,7 +221,7 @@ phex_nz (ULONGEST l, int sizeof_l) =20 /* See print-utils.h. */ =20 -char * +const char * hex_string (LONGEST num) { char *result =3D get_print_cell (); @@ -232,7 +232,7 @@ hex_string (LONGEST num) =20 /* See print-utils.h. */ =20 -char * +const char * hex_string_custom (LONGEST num, int width) { char *result =3D get_print_cell (); @@ -254,7 +254,7 @@ hex_string_custom: insufficient space to store result")= ); =20 /* See print-utils.h. */ =20 -char * +const char * int_string (LONGEST val, int radix, int is_signed, int width, int use_c_format) { @@ -262,7 +262,7 @@ int_string (LONGEST val, int radix, int is_signed, int = width, { case 16: { - char *result; + const char *result; =20 if (width =3D=3D 0) result =3D hex_string (val); diff --git a/gdbsupport/print-utils.h b/gdbsupport/print-utils.h index 510cc63bc89..5c5869ec1ae 100644 --- a/gdbsupport/print-utils.h +++ b/gdbsupport/print-utils.h @@ -27,34 +27,34 @@ /* %u for ULONGEST. The result is stored in a circular static buffer, NUMCELLS deep. */ =20 -extern char *pulongest (ULONGEST u); +extern const char *pulongest (ULONGEST u); =20 /* %d for LONGEST. The result is stored in a circular static buffer, NUMCELLS deep. */ =20 -extern char *plongest (LONGEST l); +extern const char *plongest (LONGEST l); =20 /* Convert a ULONGEST into a HEX string, like %lx, with leading zeros. The result is stored in a circular static buffer, NUMCELLS deep. */ =20 -extern char *phex (ULONGEST l, int sizeof_l); +extern const char *phex (ULONGEST l, int sizeof_l); =20 /* Convert a ULONGEST into a HEX string, like %lx, without leading zeros. The result is stored in a circular static buffer, NUMCELLS deep. */ =20 -extern char *phex_nz (ULONGEST l, int sizeof_l); +extern const char *phex_nz (ULONGEST l, int sizeof_l); =20 /* Converts a LONGEST to a C-format hexadecimal literal and stores it in a static string. Returns a pointer to this string. */ =20 -extern char *hex_string (LONGEST num); +extern const char *hex_string (LONGEST num); =20 /* Converts a LONGEST number to a C-format hexadecimal literal and 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 left with 0s to at least WIDTH characters. */ =20 -extern char *hex_string_custom (LONGEST num, int width); +extern const char *hex_string_custom (LONGEST num, int width); =20 /* Convert VAL to a numeral in the given radix. For * 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'=20 * and 'o' formats do not include a prefix (0x or leading 0). */ =20 -extern char *int_string (LONGEST val, int radix, int is_signed, int width,= =20 - int use_c_format);=09 +extern const char *int_string (LONGEST val, int radix, int is_signed, int = width, + int use_c_format); =20 /* Convert a CORE_ADDR into a string. */