From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tom@tromey.com>,
Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org>
Cc: Andreas Schwab <schwab@suse.de>
Subject: Re: [PATCHv2 4/5] gdbserver: cleanup in handle_v_run
Date: Wed, 04 Oct 2023 15:40:33 +0100 [thread overview]
Message-ID: <87v8bmwivy.fsf@redhat.com> (raw)
In-Reply-To: <87y1gjy0xq.fsf@tromey.com>
Tom Tromey <tom@tromey.com> writes:
>>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Andrew> After the previous commit there is now a redundant string copy in
> Andrew> handle_v_run, this commit cleans that up.
>
> Andrew> + /* Buffer to decode the argument into. */
> Andrew> char *arg = (char *) xmalloc (len + 1);
> ...
> Andrew> hex2bin (p, (gdb_byte *) arg, len);
> Andrew> arg[len] = '\0';
>
> Not really your problem, but since you're changing it anyway, using the
> byte_vector form of hex2bin would remove some manual memory management
> here.
I see two problems with that plan. First, we currently run hex2bin on a
slice of a larger string buffer, the slice is not null-terminated. The
current hex2bin that returns a gdb::byte_vector expects a
null-terminated string (it uses strlen internally). We can easily solve
this by adding an overload of hex2bin that takes a gdb::string_view,
except...
... for the second problem, which is the result of calling hex2bin is
passed off to either new_program_name or the new_argv vector. There's
no way to "release" the memory from a gdb::byte_vector, so we'd end up
copying the contents into a malloc'd buffer anyway, like:
gdb::byte_vector vec = hex2bin (gdb::string_view (p, (next_p - p)));
const char *arg = xstrdup ((const char *) vec.data ());
Which I'm not sure is really any better than we have right now?
Did you have something else in mind? Let me know and I'm happy to have
a look at an alternative approach.
Thanks,
Andrew
next prev parent reply other threads:[~2023-10-04 14:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 12:21 [PATCH] gdbserver: fix handling of single quote arguments Andrew Burgess
2023-09-27 13:01 ` Andreas Schwab
2023-09-27 17:27 ` [PATCHv2 0/5] Fixes for passing arguments to gdbserver Andrew Burgess
2023-09-27 17:27 ` [PATCHv2 1/5] gdbserver: fix handling of single quote arguments Andrew Burgess
2023-09-27 17:27 ` [PATCHv2 2/5] gdbserver: fix handling of trailing empty argument Andrew Burgess
2023-09-27 17:27 ` [PATCHv2 3/5] gdbserver: handle newlines in inferior arguments Andrew Burgess
2023-09-27 17:27 ` [PATCHv2 4/5] gdbserver: cleanup in handle_v_run Andrew Burgess
2023-10-03 19:13 ` Tom Tromey
2023-10-04 14:40 ` Andrew Burgess [this message]
2023-10-04 19:35 ` Tom Tromey
2023-09-27 17:27 ` [PATCHv2 5/5] gdb/testsuite: cleanup in gdb.base/args.exp Andrew Burgess
2023-10-05 16:17 ` Tom Tromey
2023-10-05 16:18 ` [PATCHv2 0/5] Fixes for passing arguments to gdbserver Tom Tromey
2023-10-06 12:15 ` Andrew Burgess
2023-10-06 12:56 ` Tom Tromey
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=87v8bmwivy.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=schwab@suse.de \
--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).