From: Andrew Burgess <aburgess@redhat.com>
To: "Tom Tromey" <tom@tromey.com>, "Alexandra Hájková" <ahajkova@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] remote.c: Make packet_check_result return a structure
Date: Fri, 05 Jan 2024 14:36:32 +0000 [thread overview]
Message-ID: <87y1d3979r.fsf@redhat.com> (raw)
In-Reply-To: <87il4q2qy4.fsf@tromey.com>
Tom Tromey <tom@tromey.com> writes:
>>>>>> "Alexandra" == Alexandra Hájková <ahajkova@redhat.com> writes:
>
> Alexandra> packet_check_result currently returns an packet_result enum.
> Alexandra> If GDB will recieve an error in a format E.errtext, which
> Alexandra> is possible for some q packets, such errtext is lost if
> Alexandra> treated by packet_check_result.
>
> Thank you for the patch. I think the general idea makes sense.
>
> Alexandra> There's no infrastructure to test this with a test case so
> Alexandra> I tested this by modifying store_registers_using_G function
> Alexandra> to get an error message:
>
> packet_check_result is isolated enough that, if you wanted, you could
> write unit tests for it.
>
> Alexandra> +/* Keeps packet's return value. If packet's return value is PACKET_ERROR,
> Alexandra> + err_msg contains an error message string from E.string or the number
> Alexandra> + stored as a string from E.num. */
> Alexandra> +struct packet_result
> Alexandra> +{
> Alexandra> + packet_result (enum packet_status status, std::string err_msg)
> Alexandra> + : m_status (status),
> Alexandra> + m_err_msg (std::move (err_msg))
>
> This is formatted strangely.
>
> Alexandra> + packet_result (enum packet_status status)
> Alexandra> + : m_status (status)
> Alexandra> + {
> Alexandra> + gdb_assert (status != PACKET_ERROR);
>
> Here and elsewhere the "{" is indented too far.
> Also, single-argument constructors should ordinarily be "explicit".
OOI, wondering why you specifically call out single-argument
constructors here? I was re-reading this page to refresh my knowledge
of 'explicit':
https://en.cppreference.com/w/cpp/language/explicit
And it seems that marking multi-argument constructors would place the
same restrictions on the constructor as for single-argument
constructors...
Though I guess there's more chance of accidentally assigning a scalar
into a non-scalar object (e.g. packet_result in this case). Maybe
that's why the single-argument case is being called out?
Anyway, not disagreeing with you, just trying to educate myself.
Thanks,
Andrew
>
> Alexandra> + }
> Alexandra> +
> Alexandra> +private:
> Alexandra> + enum packet_status m_status;
> Alexandra> + std::string m_err_msg;
> Alexandra> +
> Alexandra> +public:
>
> Better IMO to put all the private stuff at the end.
>
> Alexandra> + enum packet_status
> Alexandra> + status () const
>
> For methods this all goes on one line.
>
> Alexandra> -static enum packet_result
> Alexandra> +static struct packet_result
>
> Since you're touching this anyway you might as well leave out the
> 'struct' keyword.
>
> Tom
next prev parent reply other threads:[~2024-01-05 14:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-22 11:33 Alexandra Hájková
2023-12-22 15:32 ` Tom Tromey
2024-01-05 14:36 ` Andrew Burgess [this message]
2024-01-09 14:54 ` Tom Tromey
2023-12-26 15:39 ` Thiago Jung Bauermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y1d3979r.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=ahajkova@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).