From: Simon Marchi <simon.marchi@polymtl.ca>
To: Sergio Durigan Junior <sergiodj@redhat.com>
Cc: GDB Patches <gdb-patches@sourceware.org>,
Pedro Alves <palves@redhat.com>,
Eli Zaretskii <eliz@gnu.org>
Subject: Re: [PATCH v2] Implement the ability to set/unset environment variables to GDBserver when starting the inferior
Date: Tue, 01 Aug 2017 09:35:00 -0000 [thread overview]
Message-ID: <4ad3e00be2b381fa85367f963ced1950@polymtl.ca> (raw)
In-Reply-To: <87wp6o9fv8.fsf@redhat.com>
Hi Sergio,
On 2017-08-01 04:33, Sergio Durigan Junior wrote:
>> There is this use case for which the behavior is different between
>> native and remote, related to unset
>>
>> native:
>>
>> (gdb inf1) file /usr/bin/env
>> (gdb inf1) unset environment DISPLAY
>> (gdb inf1) r # DISPLAY is not there
>> (gdb inf1) add-inferior -exec /usr/bin/env
>> (gdb inf1) inferior 2
>> (gdb inf2) r # DISPLAY is there
>>
>> remote:
>>
>> (gdb inf1) tar ext :1234
>> (gdb inf1) file /usr/bin/env
>> (gdb inf1) set remote exec-file /usr/bin/env
>> (gdb inf1) unset environment DISPLAY
>> (gdb inf1) r # DISPLAY is not there
>> (gdb inf1) add-inferior -exec /usr/bin/env
>> (gdb inf1) inferior 2
>> (gdb inf2) set remote exec-file /usr/bin/env
>> (gdb inf2) r # DISPLAY is not there
>>
>> I think that's because in GDB, we make a new pristine copy of the host
>> environment for every inferior, which we don't in gdbserver.
>
> Thanks for the review, Simon.
>
> Yes, you're right, these cases are currently different because of the
> way we handle the environment on GDB and gdbserver. On gdbserver we
> have 'our_environ', which is a global declared at server.c and that is
> passed to all inferiors being started.
>
>> The way I understand the QEnvironmentReset is that the remote agent
>> (gdbserver) should forget any previous modification to the environment
>> made using QEnvironmentHexEncoded and QEnvironmentUnset and return the
>> environment to its original state, when it was launched. This should
>> allow supporting the use case above. To implement that properly, we
>> would need to keep a copy of gdbserver's initial environment, which we
>> could revert to when receiving a QEnvironmentReset.
>
> Yes, and we already do that on gdbserver; see the 'our_environ' global.
Maybe I'm reading the code wrong, but that's not what I understand.
gdb_environ is never reset to gdbserver's original state. So if the
DISPLAY env var is present in the original environment and is unset with
a QEnvironmentUnset, a QEnvironmentReset won't make it reappear with the
current implementation. But we would want it to be back, to support the
scenario illustrated above, wouldn't we?
I originally talked about keeping a copy of the initial environment, but
actually when receiving a QEnvironmentReset, I think gdbserver should
simply do
our_environ = gdb_environ::from_host_environ ();
>> In any case, I just want to make sure that the packets we introduce
>> are not the things that limit us.
>
> Sorry, I'm not sure I understood what you have in mind. Could you
> explain in what ways we'd be limited by the new packets?
Oh, I just wanted to say that if the gdbserver implementation is not
perfect yet, it's not the end of the world because that can always
change. But the behavior of the RSP packets is more difficult to change
once it becomes a published interface, so we need to be careful that
their documented behavior covers all the use cases we want to support.
But I know you already know that, so I don't know why I said it in the
first place :).
>>> +
>>> + /* Iterate through M_USER_UNSET_ENV_LIST and unset all variables.
>>> */
>>> + void clear_user_set_env ();
>>
>> I wouldn't put the "Iterate through M_USER_UNSET_ENV_LIST" in the
>> comment, since that's implementation details. The function
>> documentation should focus on the visible effects or goals of the
>> function (i.e. remove the user set/unset variables in that
>> environment).
>
> Good point. I've updated the comment to:
>
> /* Unset all variables that were previously set by the user, i.e.,
> that were added by calling the SET method. */
> void clear_user_set_env ();
Sounds good.
>> Similar thing here, what we pass to str is a const char*, so it leads
>> to an unnecessary std::string construction. Also, the interface of
>> the function is not well-suited to encode arbitrary binary data, which
>> could any byte. One could use
>>
>> str2hex (std::string (p, count), hex);
>>
>> but again why copy the data in the first place? So what about this:
>>
>> extern std::string bin2hex (const char *bin, int count);
>
> Not sure if it was a typo or if you really meant to propose overloading
> the bin2hex method and have another version of it that returns a
> std::string, but I like the idea. I don't think we need to treat the
> first parameter as a 'const char *'; TBH, treating it like a 'const
> gdb_byte *' (just like the original version does) is more clear. So I
> went ahead and implemented it this way.
Sorry, I should have been more explicit. I really meant to overload
bin2hex, since there's no point in limiting this function's scope to
hex-encoding text strings, it can handle any binary data (of which a
text strings are a subset). But you are right, it should be const
gdb_byte *.
>>> --- a/gdb/gdbserver/server.c
>>> +++ b/gdb/gdbserver/server.c
>>> @@ -631,6 +631,75 @@ handle_general_set (char *own_buf)
>>> return;
>>> }
>>>
>>> + if (startswith (own_buf, "QEnvironmentReset"))
>>> + {
>>> + our_environ.clear_user_set_env ();
>>> +
>>> + write_ok (own_buf);
>>> + return;
>>> + }
>>> +
>>> + if (startswith (own_buf, "QEnvironmentHexEncoded:"))
>>> + {
>>> + const char *p = own_buf + sizeof ("QEnvironmentHexEncoded:")
>>> -
>>> 1;
>>
>> You can also use strlen to avoid having to do -1, but either is fine
>> with me.
>
> I personally like using sizeof here and avoiding the call to strlen.
Ok, but remember that the compilers optimize those calls to strlen
("literal") away to a constant.
Thanks,
Simon
next prev parent reply other threads:[~2017-08-01 9:35 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-29 19:41 [PATCH] Implement the ability to transmit " Sergio Durigan Junior
2017-07-10 21:32 ` Sergio Durigan Junior
2017-07-13 21:47 ` Simon Marchi
2017-07-14 17:34 ` Sergio Durigan Junior
2017-07-27 3:36 ` [PATCH v2] Implement the ability to set/unset " Sergio Durigan Junior
2017-07-27 17:10 ` Eli Zaretskii
2017-07-27 22:05 ` Simon Marchi
2017-08-01 2:33 ` Sergio Durigan Junior
2017-08-01 9:35 ` Simon Marchi [this message]
2017-08-04 22:56 ` Sergio Durigan Junior
2017-07-29 22:36 ` Simon Marchi
2017-08-01 2:43 ` Sergio Durigan Junior
2017-08-01 9:54 ` Simon Marchi
2017-08-04 23:03 ` Sergio Durigan Junior
2017-08-05 18:14 ` Simon Marchi
2017-08-12 4:34 ` Sergio Durigan Junior
2017-08-12 8:11 ` Simon Marchi
[not found] ` <256083325d9f9c4cc4f5518fe6e5292d@polymtl.ca>
2017-08-12 4:19 ` Sergio Durigan Junior
2017-08-13 6:19 ` [PATCH v3] " Sergio Durigan Junior
2017-08-21 19:11 ` Sergio Durigan Junior
2017-08-24 19:25 ` Simon Marchi
2017-08-28 21:25 ` Sergio Durigan Junior
2017-08-28 23:13 ` [PATCH v4] " Sergio Durigan Junior
2017-08-31 19:37 ` Simon Marchi
2017-08-31 20:34 ` Sergio Durigan Junior
2017-08-31 20:39 ` Simon Marchi
2017-08-31 20:49 ` [PATCH v5] " Sergio Durigan Junior
2017-08-31 21:03 ` Simon Marchi
2017-08-31 21:26 ` Sergio Durigan Junior
2017-09-05 15:33 ` Thomas Preudhomme
2017-09-05 16:26 ` Simon Marchi
2017-09-05 17:09 ` Thomas Preudhomme
2017-09-05 18:41 ` Simon Marchi
2017-09-06 8:36 ` Thomas Preudhomme
2017-09-01 6:19 ` Eli Zaretskii
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=4ad3e00be2b381fa85367f963ced1950@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=sergiodj@redhat.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