From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Fq+rK5M0cmlR4A8AWB0awg (envelope-from ) for ; Thu, 22 Jan 2026 09:30:43 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EkUq4UMu; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A248D1E0AD; Thu, 22 Jan 2026 09:30:43 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 ESMTPS id E7F691E08D for ; Thu, 22 Jan 2026 09:30:42 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id BA0014BBCDED for ; Thu, 22 Jan 2026 14:30:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA0014BBCDED Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EkUq4UMu Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 6BE824BA2E28 for ; Thu, 22 Jan 2026 14:30:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BE824BA2E28 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6BE824BA2E28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769092214; cv=none; b=D9F2sBF8gZDsQce2IlW9dbg7J7KeOYvggr9oWSbjMGkbxtnJVlyBIPypRztFd/FdopsfH20vEzySbUaoqXNYj6FcKXbGpcKFteRbvj7ee74iII74CQzl9+cuijc6++v8cBjg0+RvzsdorfQWek8TLfcXkXa9uX9Xg5Ikl+RKKCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769092214; c=relaxed/simple; bh=V9qIm+vKyknlUgPly4MORhYxbDip0h8gaP8JNrsqiL0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ej0Pn7cJqeG7O4BrtaKBZ2VbsX+xy8m4rrDtBee/SOIlOms0SLRNjKpRhhX1BVlIo3oMLCf3HRV2UOiK42QHmqSUhmqWSrO0Sp0FKRPX/dImGYFSVlXbBKSDJarzAtG9yRjSUfJ33ca1q/x+3Zcd/Q4ErLs9uTnMvKhfrmOutlE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BE824BA2E28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769092213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/AlapiDIUJA57x7dukmwNw7Tsz/Pddm15Kal4JE1rtA=; b=EkUq4UMuRq1iIkBWDvO+7pd6Al6Z7S20sZ2bksF+zoly6g2Pwd1yV530+fTjUmVt/GG3f+ kkMYkmShzz9cE9YFd3mWnftUA2o4UaDQiIedtJQBQ0KAsp4OrLlWXRBo3ExjIAJa5n6Ln7 IQLaAYaFx4WFMN8DOyOqWONefcxswmM= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-424-pseAS71QMFWBGemPg0ovsg-1; Thu, 22 Jan 2026 09:30:12 -0500 X-MC-Unique: pseAS71QMFWBGemPg0ovsg-1 X-Mimecast-MFC-AGG-ID: pseAS71QMFWBGemPg0ovsg_1769092211 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-43065ad16a8so693820f8f.1 for ; Thu, 22 Jan 2026 06:30:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769092210; x=1769697010; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/AlapiDIUJA57x7dukmwNw7Tsz/Pddm15Kal4JE1rtA=; b=RL7quKL0sMitzQykqaKYZGXbR3R0oFMHpF6o6d1upYRaasHBx6bYjWm7f1zYFd7aGm P31rfDXmCWQgs6nCecX6Pnn2bnS6R0KLaEQAKmgsOs1welEGWAzzbYzpQvWfWEzuHuXE WAQan2Yzi5RdNPL24cRnHlLkVevTXGSg8tUMpc+vp/jF8NaZl508yNYw6vbhdQwJzmWr B+QYES9kwpOpxAil6ywASu6wAu20G+iyTFPdC34Kn5Q9+UyzpCZLOiMogHFqrVVVqRzs pule8ApxkQqJGj1Rdbwvj0+c/FooypCHMW3ORg9IGCQGykxL/4pdWaIp++IgRj+cUg8o h1Nw== X-Gm-Message-State: AOJu0YwrJIRSr1NF/PFPdy/qNDhNZ2Hy0h9j8dHpa/nndMCvdLJscUPK 58ZoflVbSG195LWDk7u1c0rDcWLT2Y9YurEI0IoRdqmdjkLzcgUl9C7TjI0PF/o2ECVfP0Px742 xsILy6j5amDkkQYsgkEOguOCmGrkvNgsSSEdYSrKxcCdz+7ah40kcVbx9ODywQxTUg5vgxJBNqW QTR3/zhh2EftyZC+IVWkQyxOjH0Pn0guQQ9He4TCBc/amQcMs= X-Gm-Gg: AZuq6aIB8lx9Wf/K2xq/rgiP1QRTj5BjdvDf6H6xKBX2EfPE6V0qT3OFgzEf/6fQgmV wB18pcJzzKTBqL/NR98DesHI2a8fN8opn3ZsbF1yfrdbiWklleQBvf7sbiYqqV/Vvf+FFC4VLPx /oYZ04lFOtEBLjAmVoN/bQqEDXer9BjhIWVjngMgpQJvtvVAdVnEZUJ3ZXg606iKRzmiq06Z5Vs 9vnrt+zHhItF0RrNAzoBGFb343Eii3zhXCiAHunqRvU/cAvPS7yStnoQ0a7d3lMsonUgw0DWn2A 4ogHNHnTBVce101QPaVOW4MSuy8q/HiHE+W1wge1d5v8JwFPlIj4Oui5AbUU+HBiVG1HS75UBiV 96Vth X-Received: by 2002:a05:600c:3555:b0:47e:e20e:bb9c with SMTP id 5b1f17b1804b1-4801e2f8e63mr321912055e9.8.1769092210323; Thu, 22 Jan 2026 06:30:10 -0800 (PST) X-Received: by 2002:a05:600c:3555:b0:47e:e20e:bb9c with SMTP id 5b1f17b1804b1-4801e2f8e63mr321911485e9.8.1769092209795; Thu, 22 Jan 2026 06:30:09 -0800 (PST) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4358f12ee69sm22735862f8f.11.2026.01.22.06.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jan 2026 06:30:09 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb/tui: return std::string from tui_get_function_from_frame Date: Thu, 22 Jan 2026 14:30:07 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: <32f9ecb06cced368b9f6433e9b4f38bad2e61d86.1769092070.git.aburgess@redhat.com> References: <32f9ecb06cced368b9f6433e9b4f38bad2e61d86.1769092070.git.aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: PNwcxuaXXxna_WYB6xmdy85qFpQomXlDjb3LVLTuKKY_1769092211 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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~public-inbox=simark.ca@sourceware.org In v2: - Added a '!name.empty ()' check to tui_get_function_from_frame. I forgot to check this in prior to sending V1. Sorry about that. Thanks, Andrew --- Update tui_get_function_from_frame to return a std::string rather than a pointer into a static buffer. The value returned from tui_get_function_from_frame is passed to tui_location_tracker::set_location, which already stores the data in a std::string; this just moves the string creation earlier. I don't think there was anything particularly wrong with the old code, but I'm not a huge fan of returning data in static buffers unless there's a really good reason, and it doesn't feel like there's a really good reason in this case. The current approach in tui_get_function_from_frame is to call print_address_symbolic, and then to pull the function name from the result. There is an argument that this approach could be improved, but I've not done that in this commit, nor do I plan to do that any time soon. As such the new code should do exactly what the old code did. There should be no user visible changes after this commit. --- gdb/tui/tui-location.c | 6 ++---- gdb/tui/tui-location.h | 2 +- gdb/tui/tui-status.c | 33 ++++++++++++++++----------------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/gdb/tui/tui-location.c b/gdb/tui/tui-location.c index 9527ae50c60..003c022f1e8 100644 --- a/gdb/tui/tui-location.c +++ b/gdb/tui/tui-location.c @@ -29,17 +29,15 @@ tui_location_tracker tui_location; bool tui_location_tracker::set_location (struct gdbarch *gdbarch, const struct symtab_and_line &sal, - const char *procname) + std::string procname) { - gdb_assert (procname != nullptr); - bool location_changed_p = set_fullname (sal.symtab); location_changed_p |= procname != m_proc_name; location_changed_p |= sal.line != m_line_no; location_changed_p |= sal.pc != m_addr; location_changed_p |= gdbarch != m_gdbarch; - m_proc_name = procname; + m_proc_name = std::move (procname); m_line_no = sal.line; m_addr = sal.pc; m_gdbarch = gdbarch; diff --git a/gdb/tui/tui-location.h b/gdb/tui/tui-location.h index 6b663f1df9b..5cf29c3716b 100644 --- a/gdb/tui/tui-location.h +++ b/gdb/tui/tui-location.h @@ -32,7 +32,7 @@ struct tui_location_tracker and false otherwise. */ bool set_location (struct gdbarch *gdbarch, const struct symtab_and_line &sal, - const char *procname); + std::string procname); /* Update the current location with the with the provided argument. Return true if any of the fields actually changed, otherwise false. */ diff --git a/gdb/tui/tui-status.c b/gdb/tui/tui-status.c index b58bf9aa990..e80b0bb5da2 100644 --- a/gdb/tui/tui-status.c +++ b/gdb/tui/tui-status.c @@ -207,10 +207,9 @@ tui_status_window::make_status_line () const /* Get a printable name for the function at the address. The symbol name is demangled if demangling is turned on. Returns a pointer to a static area holding the result. */ -static char* +static std::string tui_get_function_from_frame (const frame_info_ptr &fi) { - static char name[256]; string_file stream; print_address_symbolic (get_frame_arch (fi), get_frame_pc (fi), @@ -219,20 +218,20 @@ tui_get_function_from_frame (const frame_info_ptr &fi) /* Use simple heuristics to isolate the function name. The symbol can be demangled and we can have function parameters. Remove them because the status line is too short to display them. */ - const char *d = stream.c_str (); - if (*d == '<') - d++; - strncpy (name, d, sizeof (name) - 1); - name[sizeof (name) - 1] = 0; + std::string name = stream.release (); + if (!name.empty () && name.front () == '<') + name = name.erase (0, 1); + + size_t pos = name.find('('); + if (pos == std::string::npos) + pos = name.find('>'); + if (pos != std::string::npos) + name.erase (pos); + + pos = name.find('+'); + if (pos != std::string::npos) + name.erase (pos); - char *p = strchr (name, '('); - if (!p) - p = strchr (name, '>'); - if (p) - *p = 0; - p = strchr (name, '+'); - if (p) - *p = 0; return name; } @@ -270,7 +269,7 @@ tui_show_frame_info (const frame_info_ptr &fi) { symtab_and_line sal = find_frame_sal (fi); - const char *func_name; + std::string func_name; std::optional tmp_pc = get_frame_pc_if_available (fi); /* find_frame_sal does not always set PC, but we want to ensure that it is available in the SAL. */ @@ -284,7 +283,7 @@ tui_show_frame_info (const frame_info_ptr &fi) struct gdbarch *gdbarch = get_frame_arch (fi); status_changed_p - = tui_location.set_location (gdbarch, sal, func_name); + = tui_location.set_location (gdbarch, sal, std::move (func_name)); /* If the status information has not changed, then frame information has not changed. If frame information has not changed, then the windows' base-commit: 93172549b7397c526b3622e16484909028d81e41 -- 2.25.4