From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id xUthEhU0cmmx3w8AWB0awg (envelope-from ) for ; Thu, 22 Jan 2026 09:28:37 -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=cUEW40yE; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3A8EB1E08D; Thu, 22 Jan 2026 09:28:37 -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 3FF121E08D for ; Thu, 22 Jan 2026 09:28:36 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id DD7DA4BA23CA for ; Thu, 22 Jan 2026 14:28:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD7DA4BA23CA 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=cUEW40yE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 58E604BA2E32 for ; Thu, 22 Jan 2026 14:28:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58E604BA2E32 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 58E604BA2E32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769092087; cv=none; b=euLhX3cWdL3Of+uzzjhFuYG8ImuCka5Trvtg3zyD3inX9YpVZ7dQI5HtHc5zB4OZwwS0Vjqbau0THEgd0NNntB3qe3P4RYEZy+Pg3a/HXL0luIc3mAaZi+BHNl59cyle2f87O9BeTB6RbPIh51vix61G4dzxx0Mq0br/F9pZt+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769092087; c=relaxed/simple; bh=qnafi/i2hGB/6JJiiUVmXoRJtSOQbthqItCvSqC8fN0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=jqxPEqY8DlMYLGoUlX3Y7hPEaYnufEs6ryISS9mSLdFN9aXBTZpIOUxxTf9iLgBYKUOXh4vwYJLbpA5liyuvJUoubav8BpqPLnzQAnZiIynvssjyLRqi7gAeNkCvJk5tCH+37pGzLxTq5KCWGhI+tOBgnfSfLcrDo0DmhTC4tk8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58E604BA2E32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769092086; 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; bh=l9+YlTRN/dAu3WTQIl+T8RYTYzc+GOJuSS4De2Z6PvM=; b=cUEW40yEV+mcsxyxQJJCvRxwRwCFH71KEMrZoZbSdNJeBQ1byyuWrDZniA3tQ9xL/E37dv BVqQF5RC4R2Swr7Yf6e+shRXI5+bQyRT0Z7d0pGsGMyWUkKRCqUDb//WZGzelxpyQuK6qr Nx+3SRt6fNkgX9aKgWRKiBo3wbTachI= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-209-ih6vk9_HOy60aTZYtzXVYg-1; Thu, 22 Jan 2026 09:28:05 -0500 X-MC-Unique: ih6vk9_HOy60aTZYtzXVYg-1 X-Mimecast-MFC-AGG-ID: ih6vk9_HOy60aTZYtzXVYg_1769092084 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-47ee1fe7b24so8877975e9.1 for ; Thu, 22 Jan 2026 06:28:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769092083; x=1769696883; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=l9+YlTRN/dAu3WTQIl+T8RYTYzc+GOJuSS4De2Z6PvM=; b=v7utJXiF+4kdwfhWB++4SKiKJPie4p/hGf8a4Ty9iTttsptOGAmCrXOHbR9UmUkuvI ePsy7U6F61+jaJPag3tZeazPrwr+C7ArKF7froE+eMI9/Q5KiefDHsVlxVgdp0QMq63f j+MdEkivrXWX3wI5Ati3zeFacRQarFhXzfRMgUqKgyrIupjOvBalLzhNuC8rb6t4+JDI QShHRGr3P4C3udtwMvfbhRRUX2V4+woFEB3bKSMi11OYNxTTjz6ATUm07maj8ZjOUVdL +ECa12xMxqW+2CLMLgSdorSdRjjInKiXwNP54b/s/UTMX7WImt+ec0669RaCdXjXudYk TGlg== X-Gm-Message-State: AOJu0YxKSTDi9gGiP9AuadmdRRuM6cxzZ9puHzf7RPzaL9QbhNVHLrF0 QRgcwUnD/JkWL2LvvvRQoOoh4SrWAJnsIJ8sUsTVJjlKKEOh4i26UW7rYHMs/6qK7cc/53UG2hS SnptID+FeSh2kUMy/hYLaSaYYccwt+0QmuTKC62H3Vu4fTJRtVTLg2iMq/C0tMhlHxSjGOUW8WV 78mL5EPsY8BrtGiWl+6Ih8jnaZttxCtr8Eo8Ro4P8B65crB58= X-Gm-Gg: AZuq6aIttvlZw/ZwayMScd5QGWWQ9OB/ImUpcH13aI+t6zsDp5peOjzVWPjwGAgfXvv 8dsvpLDDIhcFgCH3C/m+sHS9mqsnPW9OJzO6nocXDLQL0Kp7o0KUFBKUfy80cA+8zT2RFtHf3Al G0gupfPJYz4hVA1iIsSDR18fo6BjKSGytCZfrsitXW5uoA9PATTkI+NqcGuU1m/eYKUrGZ3/738 hBG5hvJsAhIUTePYUvTODEN1kU9JPu+5dqftQwWFehfpCPfFlPNEP46vdhRiDOvffd2qCa1Ks/+ 5V/kQ6F7Ay2n52CuY106GsAYFk4yG/6tE3wU8P6MalE3EBIybnyJjzAv84OIRz6+h74LKJV7aY1 G9662 X-Received: by 2002:a05:600c:458c:b0:47d:6856:9bd9 with SMTP id 5b1f17b1804b1-4801e3342bamr244929965e9.23.1769092083442; Thu, 22 Jan 2026 06:28:03 -0800 (PST) X-Received: by 2002:a05:600c:458c:b0:47d:6856:9bd9 with SMTP id 5b1f17b1804b1-4801e3342bamr244929425e9.23.1769092082786; Thu, 22 Jan 2026 06:28:02 -0800 (PST) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4804702fb04sm68928345e9.3.2026.01.22.06.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jan 2026 06:28:02 -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:28:00 +0000 Message-Id: <32f9ecb06cced368b9f6433e9b4f38bad2e61d86.1769092070.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: RRmIdPApxParMQ4yw5E3fiNoIDpbOEYFtj_Z3C4Y0-o_1769092084 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 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..3d252503da0 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.front () == '<') + name = name.substr (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