From patchwork Wed Apr 17 20:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 88622 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9AD473858C60 for ; Wed, 17 Apr 2024 20:56:03 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 80EB33858C52 for ; Wed, 17 Apr 2024 20:55:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80EB33858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 80EB33858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713387341; cv=none; b=xJe/bq5h3tthk3gLBcauHgJElvtDUH3A/MSpFvT0AsBbtH5GHxOnI8TGSrcMtqn+q1gyadS/N2m1NTiL20qkyoOkDNJSlNt7C9biPXt4XYFYQF8qg934BT2L4dHJCnSoqbWJCnQZ4rpPFdt2V14xUMvVwS9E4wSATEXLVbBl+0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713387341; c=relaxed/simple; bh=TzIUJznKd1EjGXJjPrpy3mjXmWeTIzSotsOMWQy71oM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iYArQSL0mMQN6wK+4gXWJ7eBck64HJNdfoi//3kgqLjcn1ykgRg/L2lyjy62jaEOse8y1SisMrUdipKUjRmhzZEu+0jDYzplZpemeAfQveDG9tkQdXVIR64TT0XdwmyYpG7pzjLDYP/yjWpU5y9e7rRARkfBqefx2QteUmymwSw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 43HKtVZA036941 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Apr 2024 16:55:36 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 43HKtVZA036941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1713387337; bh=ILGv5VGI9XQnCxI6q2sYwVLi4TyZAERvdjXw2bX5mVE=; h=From:To:Cc:Subject:Date:From; b=bfkBmQ6S8raNAEN2N/eXppg8Oo8z3xwXKAc67n0NgMbfU28FLrlG1HPgJ+wHfWOtm g0KJs7VbVPm8nKbkFi1+4FtsMM2XWlxO/hBLjm7Y/z8gHLnsOR/yPCrtuHrsDK1A1Q dZyzBMbXtJMc7iWnv6nsHs3eo2+1kO8AiTgX7o7k= Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 9756B1E030; Wed, 17 Apr 2024 16:55:31 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdbsupport: constify some return values in print-utils.{h, cc} Date: Wed, 17 Apr 2024 16:55:28 -0400 Message-ID: <20240417205530.2033347-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 17 Apr 2024 20:55:31 +0000 X-Spam-Status: No, score=-3188.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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 --- 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(-) base-commit: 56f4dea207d690fff70a3ccb6fe10ebe1e4697c0 diff --git a/gdb/dwarf2/types.h b/gdb/dwarf2/types.h index 9db5c6357046..f0b9febba151 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); -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 86603dfebc31..d931b3a694b3 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 = msymbol.objfile->arch (); - char *tmp; + const char *tmp; if (gdbarch_addr_bit (gdbarch) <= 32) tmp = hex_string_custom (msymbol.value_address () diff --git a/gdbserver/utils.cc b/gdbserver/utils.cc index 3d3144e33da3..302300770e84 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. */ -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 7a6d0fd1d37b..ad1f82ccb9f6 100644 --- a/gdbserver/utils.h +++ b/gdbserver/utils.h @@ -19,6 +19,6 @@ #ifndef GDBSERVER_UTILS_H #define GDBSERVER_UTILS_H -char *paddress (CORE_ADDR addr); +const char *paddress (CORE_ADDR addr); #endif /* GDBSERVER_UTILS_H */ diff --git a/gdbsupport/print-utils.cc b/gdbsupport/print-utils.cc index 565a4791675f..a2e43576a7cd 100644 --- a/gdbsupport/print-utils.cc +++ b/gdbsupport/print-utils.cc @@ -122,7 +122,7 @@ octal2str (ULONGEST addr, int width) /* See print-utils.h. */ -char * +const char * pulongest (ULONGEST u) { return decimal2str ("", u, 0); @@ -130,7 +130,7 @@ pulongest (ULONGEST u) /* See print-utils.h. */ -char * +const char * plongest (LONGEST l) { if (l < 0) @@ -144,7 +144,7 @@ static int thirty_two = 32; /* See print-utils.h. */ -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 = phex (l, sizeof (l)); + return phex (l, sizeof (l)); break; } @@ -179,7 +179,7 @@ phex (ULONGEST l, int sizeof_l) /* See print-utils.h. */ -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 = phex_nz (l, sizeof (l)); + return phex_nz (l, sizeof (l)); break; } @@ -221,7 +221,7 @@ phex_nz (ULONGEST l, int sizeof_l) /* See print-utils.h. */ -char * +const char * hex_string (LONGEST num) { char *result = get_print_cell (); @@ -232,7 +232,7 @@ hex_string (LONGEST num) /* See print-utils.h. */ -char * +const char * hex_string_custom (LONGEST num, int width) { char *result = get_print_cell (); @@ -254,7 +254,7 @@ hex_string_custom: insufficient space to store result")); /* See print-utils.h. */ -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; if (width == 0) result = hex_string (val); diff --git a/gdbsupport/print-utils.h b/gdbsupport/print-utils.h index 510cc63bc895..5c5869ec1ae6 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. */ -extern char *pulongest (ULONGEST u); +extern const char *pulongest (ULONGEST u); /* %d for LONGEST. The result is stored in a circular static buffer, 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. 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. 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 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 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. */ -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 * 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' * 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, - int use_c_format); +extern const char *int_string (LONGEST val, int radix, int is_signed, int width, + int use_c_format); /* Convert a CORE_ADDR into a string. */