* [PUSHED] gdb: make more use of make_target_connection_string
@ 2022-12-15 12:53 Andrew Burgess
2022-12-15 12:58 ` Simon Marchi
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2022-12-15 12:53 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
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 noticed that we have a function make_target_connection_string which
wraps all the logic for creating a string that describes a target
connection - but in some places we are not calling this function,
instead we duplicate the function's logic.
This commit cleans this up, and calls make_target_connection_string
where possible.
There should be no user visible changes after this commit.
---
gdb/inferior.c | 34 ++++++++++------------------------
gdb/target-connection.c | 5 +----
2 files changed, 11 insertions(+), 28 deletions(-)
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 ();
+ return string_printf ("%d (%s)", proc_target->connection_number,
+ conn_str.c_str ());
}
}
@@ -823,17 +816,10 @@ switch_to_inferior_and_push_target (inferior *new_inf,
if (!no_connection && proc_target != NULL)
{
new_inf->push_target (proc_target);
- if (proc_target->connection_string () != NULL)
- gdb_printf (_("Added inferior %d on connection %d (%s %s)\n"),
- new_inf->num,
- proc_target->connection_number,
- proc_target->shortname (),
- proc_target->connection_string ());
- else
- gdb_printf (_("Added inferior %d on connection %d (%s)\n"),
- new_inf->num,
- proc_target->connection_number,
- proc_target->shortname ());
+ gdb_printf (_("Added inferior %d on connection %d (%s)\n"),
+ new_inf->num,
+ proc_target->connection_number,
+ make_target_connection_string (proc_target).c_str ());
}
else
gdb_printf (_("Added inferior %d\n"), new_inf->num);
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 ());
if (l > what_len)
what_len = l;
}
base-commit: c91a13e4e6790324e2177fa4b98e4637e3b03f97
--
2.25.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PUSHED] gdb: make more use of make_target_connection_string
2022-12-15 12:53 [PUSHED] gdb: make more use of make_target_connection_string Andrew Burgess
@ 2022-12-15 12:58 ` Simon Marchi
2022-12-15 16:54 ` Andrew Burgess
0 siblings, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2022-12-15 12:58 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches
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.
Simon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PUSHED] gdb: make more use of make_target_connection_string
2022-12-15 12:58 ` Simon Marchi
@ 2022-12-15 16:54 ` Andrew Burgess
2022-12-15 17:04 ` Simon Marchi
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2022-12-15 16:54 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
Simon Marchi <simark@simark.ca> 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 <aburgess@redhat.com>
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;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PUSHED] gdb: make more use of make_target_connection_string
2022-12-15 16:54 ` Andrew Burgess
@ 2022-12-15 17:04 ` Simon Marchi
2022-12-16 13:31 ` Andrew Burgess
0 siblings, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2022-12-15 17:04 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches
> 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 :)
Hehe :). The patch LGTM, you can add my:
Approved-By: Simon Marchi <simon.marchi@efficios.com>
... such that if the patch ends up incorrect, you can shift the blame on
me.
Simon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PUSHED] gdb: make more use of make_target_connection_string
2022-12-15 17:04 ` Simon Marchi
@ 2022-12-16 13:31 ` Andrew Burgess
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2022-12-16 13:31 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
Simon Marchi <simark@simark.ca> writes:
>> 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 :)
>
> Hehe :). The patch LGTM, you can add my:
>
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
>
Thanks, pushed.
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-12-16 13:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-15 12:53 [PUSHED] gdb: make more use of make_target_connection_string Andrew Burgess
2022-12-15 12:58 ` Simon Marchi
2022-12-15 16:54 ` Andrew Burgess
2022-12-15 17:04 ` Simon Marchi
2022-12-16 13:31 ` Andrew Burgess
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).