From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 5C6733856B53 for ; Thu, 15 Dec 2022 16:56:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5C6733856B53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671123362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KXgXS54tXEy8iQxLsoSVlmXafVsRN9VGKJbl+JLUQQE=; b=bTwwN7ebJJbrhoQIjeYTqc9RasIna++SMbDZHGtGYTzmhgo5KbpN1fLNlw2c2S8H41kyhC BxvapRxqvUn2J7dBOXZ8kQYI/WcQRAyH88IZ72cn/AFMBPsapZpdX1PS/HidSBgKr7i8QZ r5g6G4WZZ981x7cU7eNXXvRkexXaL6Y= Received: from mail-qk1-f199.google.com (209.85.222.199 [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-277-JldD26vjPl2Z-KVMLhKYvg-1; Thu, 15 Dec 2022 11:54:34 -0500 X-MC-Unique: JldD26vjPl2Z-KVMLhKYvg-1 Received: by mail-qk1-f199.google.com with SMTP id w14-20020a05620a424e00b006fc46116f7dso6272369qko.12 for ; Thu, 15 Dec 2022 08:54:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KXgXS54tXEy8iQxLsoSVlmXafVsRN9VGKJbl+JLUQQE=; b=o0S5SmAzQQXZVHRnBcz9UVYxhKhB1g/jo9LbSFrdaeH0EK6UKycb7FCbK4A0iuFJ90 G0p3+Jmeg9Ev+ozfRl1pOW84Jg+tiV7T1olUmTEKwCXr4PD4M7io+YiWdnpmoKNjNPKY JtMpwn76udOq0pGRuuKOXXlsinAVkzy3NGZnM/pX6+BrfF43bb/vzuYPxB+8Pu8OOXvo K9DFKSVLrqKnWu97qty/0E12KbHrFEWRIms65J0dFSgTXqDc7RhEp70RKIVpDr2MQH4G bnR4dvgfhTfd7eoXPW6fuJ9Ar2Z9lh/dALkx9v7TxOhj5EWu2YqXY28wlaQfplJAZIfI TRKQ== X-Gm-Message-State: ANoB5pnaPONuTTQaIUuHYmXHtsYrQjOcV40fHWGVXaXTKfAHqd89kjnh OYEWBU1n367EUXqM0/a3tfST14XfIBrdz3o+Nh7pJ/IqbP8Dx3BKI+Muoy4BUnyZ7bAGrXfqNOU Lp5Wh88oGeatrzR71w/TuIg== X-Received: by 2002:a05:6214:e6c:b0:4c7:7257:68a2 with SMTP id jz12-20020a0562140e6c00b004c7725768a2mr51350083qvb.15.1671123252292; Thu, 15 Dec 2022 08:54:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf5NE+4QdJ0xpy72UARnDLIwQtjbPEmptuQylFTVyQlgvbxbyt2vuJp5rWlWg9KG70gy5530iw== X-Received: by 2002:a05:6214:e6c:b0:4c7:7257:68a2 with SMTP id jz12-20020a0562140e6c00b004c7725768a2mr51350051qvb.15.1671123251986; Thu, 15 Dec 2022 08:54:11 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id h19-20020a05620a13f300b006fcab4da037sm12074835qkl.39.2022.12.15.08.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 08:54:11 -0800 (PST) From: Andrew Burgess To: Simon Marchi , gdb-patches@sourceware.org Subject: Re: [PUSHED] gdb: make more use of make_target_connection_string In-Reply-To: <2d9e0814-b4a8-fba8-9422-a1c746a15ebf@simark.ca> References: <53cf95c3389a3ecd97276d322e4a60fe3396a201.1671108652.git.aburgess@redhat.com> <2d9e0814-b4a8-fba8-9422-a1c746a15ebf@simark.ca> Date: Thu, 15 Dec 2022 16:54:05 +0000 Message-ID: <87o7s4zjyq.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 List-Id: Simon Marchi writes: > On 12/15/22 07:53, Andrew Burgess via Gdb-patches wrote: >> Oops! I accidentally pushed this patch to master. >> >> I haven't immediately reverted it because I think it is a pretty >> obvious cleanup, but I would normally have posted this for review. >> >> If anyone has any issues with the patch then please reply, I can >> either fix any problems, or fully revert the patch if requeted. >> >> Sorry for the carelessness. >> >> Thanks, >> Andrew > > I just spotted some nits, if you want to fix them up. > >> diff --git a/gdb/inferior.c b/gdb/inferior.c >> index ec63e0491e5..3d2bce9df7b 100644 >> --- a/gdb/inferior.c >> +++ b/gdb/inferior.c >> @@ -33,6 +33,7 @@ >> #include "cli/cli-utils.h" >> #include "arch-utils.h" >> #include "target-descriptions.h" >> +#include "target-connection.h" >> #include "readline/tilde.h" >> #include "progspace-and-thread.h" >> #include "gdbsupport/buildargv.h" >> @@ -482,21 +483,13 @@ static std::string >> uiout_field_connection (process_stratum_target *proc_target) >> { >> if (proc_target == NULL) >> - { >> - return {}; >> - } >> - else if (proc_target->connection_string () != NULL) >> - { >> - return string_printf ("%d (%s %s)", >> - proc_target->connection_number, >> - proc_target->shortname (), >> - proc_target->connection_string ()); >> - } >> + return {}; >> else >> { >> - return string_printf ("%d (%s)", >> - proc_target->connection_number, >> - proc_target->shortname ()); >> + std::string conn_str >> + = make_target_connection_string (proc_target).c_str (); > > I think you can remove the .c_str here. > >> diff --git a/gdb/target-connection.c b/gdb/target-connection.c >> index d1da6a2d7b9..d88b9c8f563 100644 >> --- a/gdb/target-connection.c >> +++ b/gdb/target-connection.c >> @@ -91,10 +91,7 @@ print_connection (struct ui_out *uiout, const char *requested_connections) >> >> process_stratum_target *t = it.second; >> >> - size_t l = strlen (t->shortname ()); >> - if (t->connection_string () != NULL) >> - l += 1 + strlen (t->connection_string ()); >> - >> + size_t l = strlen (make_target_connection_string (t).c_str ()); > > I think you can use std::string::length here. Thanks. Normally I'd just push the fixes for this as obvious. But as that's what got me into this mess in the first place, I figure I should post the fixes here first :) I'll merge these tomorrow unless I hear any complaints. Thanks, Andrew --- commit c06914cdbc40a30919df4efc9c0135c0694b5bc0 Author: Andrew Burgess Date: Thu Dec 15 16:50:57 2022 +0000 gdb: clean up some inefficient std::string usage This commit: commit 53cf95c3389a3ecd97276d322e4a60fe3396a201 Date: Wed Dec 14 14:17:44 2022 +0000 gdb: make more use of make_target_connection_string Introduced a couple of inefficient uses of std::string, both of which are fixed in this commit. There should be no user visible changes after this commit. diff --git a/gdb/inferior.c b/gdb/inferior.c index 3d2bce9df7b..928305fc79d 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -486,8 +486,7 @@ uiout_field_connection (process_stratum_target *proc_target) return {}; else { - std::string conn_str - = make_target_connection_string (proc_target).c_str (); + std::string conn_str = make_target_connection_string (proc_target); return string_printf ("%d (%s)", proc_target->connection_number, conn_str.c_str ()); } diff --git a/gdb/target-connection.c b/gdb/target-connection.c index d88b9c8f563..55818cf28dc 100644 --- a/gdb/target-connection.c +++ b/gdb/target-connection.c @@ -91,7 +91,7 @@ print_connection (struct ui_out *uiout, const char *requested_connections) process_stratum_target *t = it.second; - size_t l = strlen (make_target_connection_string (t).c_str ()); + size_t l = make_target_connection_string (t).length (); if (l > what_len) what_len = l; }