public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use getenv instead of gdb_environ on mi-cmd-env.c
@ 2017-06-16 22:12 Sergio Durigan Junior
  2017-06-17  8:03 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Sergio Durigan Junior @ 2017-06-16 22:12 UTC (permalink / raw)
  To: GDB Patches; +Cc: Pedro Alves, Sergio Durigan Junior

This is a spinoff of
<https://sourceware.org/ml/gdb-patches/2017-06/msg00437.html>.
mi-cmd-env.c is using the whole gdb_environ machinery in order to
access just one variable, which can be easily replaced by a simple
call to getenv.  This patch does that, and doesn't cause regressions.

gdb/ChangeLog:
2017-06-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* mi/mi-cm-env.c (_initialize_mi_cmd_env): Use getenv instead of
	gdb_environ to access an environment variable.
---
 gdb/ChangeLog       |  5 +++++
 gdb/mi/mi-cmd-env.c | 12 ++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9062067..f5bf474 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-06-16  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* mi/mi-cm-env.c (_initialize_mi_cmd_env): Use getenv instead of
+	gdb_environ to access an environment variable.
+
 2017-06-16  Alan Hayward  <alan.hayward@arm.com>
 	    Pedro Alves  <palves@redhat.com>
 	    Yao Qi  <yao.qi@linaro.org>
diff --git a/gdb/mi/mi-cmd-env.c b/gdb/mi/mi-cmd-env.c
index 4093178..97be139 100644
--- a/gdb/mi/mi-cmd-env.c
+++ b/gdb/mi/mi-cmd-env.c
@@ -270,21 +270,17 @@ mi_cmd_inferior_tty_show (const char *command, char **argv, int argc)
 void 
 _initialize_mi_cmd_env (void)
 {
-  struct gdb_environ *environment;
   const char *env;
 
   /* We want original execution path to reset to, if desired later.
      At this point, current inferior is not created, so cannot use
-     current_inferior ()->environment.  Also, there's no obvious
-     place where this code can be moved such that it surely run
-     before any code possibly mangles original PATH.  */
-  environment = make_environ ();
-  init_environ (environment);
-  env = get_in_environ (environment, path_var_name);
+     current_inferior ()->environment.  We use getenv here because it
+     is not necessary to create a whole new gdb_environ just for one
+     variable.  */
+  env = getenv (path_var_name);
 
   /* Can be null if path is not set.  */
   if (!env)
     env = "";
   orig_path = xstrdup (env);
-  free_environ (environment);
 }
-- 
2.9.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Use getenv instead of gdb_environ on mi-cmd-env.c
  2017-06-16 22:12 [PATCH] Use getenv instead of gdb_environ on mi-cmd-env.c Sergio Durigan Junior
@ 2017-06-17  8:03 ` Simon Marchi
  2017-06-19  4:15   ` Sergio Durigan Junior
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2017-06-17  8:03 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches, Pedro Alves

On 2017-06-17 00:12, Sergio Durigan Junior wrote:
> This is a spinoff of
> <https://sourceware.org/ml/gdb-patches/2017-06/msg00437.html>.
> mi-cmd-env.c is using the whole gdb_environ machinery in order to
> access just one variable, which can be easily replaced by a simple
> call to getenv.  This patch does that, and doesn't cause regressions.
> 
> gdb/ChangeLog:
> 2017-06-16  Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* mi/mi-cm-env.c (_initialize_mi_cmd_env): Use getenv instead of
> 	gdb_environ to access an environment variable.
> ---
>  gdb/ChangeLog       |  5 +++++
>  gdb/mi/mi-cmd-env.c | 12 ++++--------
>  2 files changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 9062067..f5bf474 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,8 @@
> +2017-06-16  Sergio Durigan Junior  <sergiodj@redhat.com>
> +
> +	* mi/mi-cm-env.c (_initialize_mi_cmd_env): Use getenv instead of
> +	gdb_environ to access an environment variable.
> +
>  2017-06-16  Alan Hayward  <alan.hayward@arm.com>
>  	    Pedro Alves  <palves@redhat.com>
>  	    Yao Qi  <yao.qi@linaro.org>
> diff --git a/gdb/mi/mi-cmd-env.c b/gdb/mi/mi-cmd-env.c
> index 4093178..97be139 100644
> --- a/gdb/mi/mi-cmd-env.c
> +++ b/gdb/mi/mi-cmd-env.c
> @@ -270,21 +270,17 @@ mi_cmd_inferior_tty_show (const char *command,
> char **argv, int argc)
>  void
>  _initialize_mi_cmd_env (void)
>  {
> -  struct gdb_environ *environment;
>    const char *env;
> 
>    /* We want original execution path to reset to, if desired later.
>       At this point, current inferior is not created, so cannot use
> -     current_inferior ()->environment.  Also, there's no obvious
> -     place where this code can be moved such that it surely run
> -     before any code possibly mangles original PATH.  */
> -  environment = make_environ ();
> -  init_environ (environment);
> -  env = get_in_environ (environment, path_var_name);
> +     current_inferior ()->environment.  We use getenv here because it
> +     is not necessary to create a whole new gdb_environ just for one
> +     variable.  */
> +  env = getenv (path_var_name);
> 
>    /* Can be null if path is not set.  */
>    if (!env)
>      env = "";
>    orig_path = xstrdup (env);
> -  free_environ (environment);
>  }

LGTM.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Use getenv instead of gdb_environ on mi-cmd-env.c
  2017-06-17  8:03 ` Simon Marchi
@ 2017-06-19  4:15   ` Sergio Durigan Junior
  0 siblings, 0 replies; 3+ messages in thread
From: Sergio Durigan Junior @ 2017-06-19  4:15 UTC (permalink / raw)
  To: Simon Marchi; +Cc: GDB Patches, Pedro Alves

On Saturday, June 17 2017, Simon Marchi wrote:

> On 2017-06-17 00:12, Sergio Durigan Junior wrote:
>> This is a spinoff of
>> <https://sourceware.org/ml/gdb-patches/2017-06/msg00437.html>.
>> mi-cmd-env.c is using the whole gdb_environ machinery in order to
>> access just one variable, which can be easily replaced by a simple
>> call to getenv.  This patch does that, and doesn't cause regressions.
>>
>> gdb/ChangeLog:
>> 2017-06-16  Sergio Durigan Junior  <sergiodj@redhat.com>
>>
>> 	* mi/mi-cm-env.c (_initialize_mi_cmd_env): Use getenv instead of
>> 	gdb_environ to access an environment variable.
>> ---
>>  gdb/ChangeLog       |  5 +++++
>>  gdb/mi/mi-cmd-env.c | 12 ++++--------
>>  2 files changed, 9 insertions(+), 8 deletions(-)
>>
>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>> index 9062067..f5bf474 100644
>> --- a/gdb/ChangeLog
>> +++ b/gdb/ChangeLog
>> @@ -1,3 +1,8 @@
>> +2017-06-16  Sergio Durigan Junior  <sergiodj@redhat.com>
>> +
>> +	* mi/mi-cm-env.c (_initialize_mi_cmd_env): Use getenv instead of
>> +	gdb_environ to access an environment variable.
>> +
>>  2017-06-16  Alan Hayward  <alan.hayward@arm.com>
>>  	    Pedro Alves  <palves@redhat.com>
>>  	    Yao Qi  <yao.qi@linaro.org>
>> diff --git a/gdb/mi/mi-cmd-env.c b/gdb/mi/mi-cmd-env.c
>> index 4093178..97be139 100644
>> --- a/gdb/mi/mi-cmd-env.c
>> +++ b/gdb/mi/mi-cmd-env.c
>> @@ -270,21 +270,17 @@ mi_cmd_inferior_tty_show (const char *command,
>> char **argv, int argc)
>>  void
>>  _initialize_mi_cmd_env (void)
>>  {
>> -  struct gdb_environ *environment;
>>    const char *env;
>>
>>    /* We want original execution path to reset to, if desired later.
>>       At this point, current inferior is not created, so cannot use
>> -     current_inferior ()->environment.  Also, there's no obvious
>> -     place where this code can be moved such that it surely run
>> -     before any code possibly mangles original PATH.  */
>> -  environment = make_environ ();
>> -  init_environ (environment);
>> -  env = get_in_environ (environment, path_var_name);
>> +     current_inferior ()->environment.  We use getenv here because it
>> +     is not necessary to create a whole new gdb_environ just for one
>> +     variable.  */
>> +  env = getenv (path_var_name);
>>
>>    /* Can be null if path is not set.  */
>>    if (!env)
>>      env = "";
>>    orig_path = xstrdup (env);
>> -  free_environ (environment);
>>  }
>
> LGTM.
>

Thanks, pushed.

1c8e01c96054973c50ec1dec2f220af4734e1de5

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-19  4:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-16 22:12 [PATCH] Use getenv instead of gdb_environ on mi-cmd-env.c Sergio Durigan Junior
2017-06-17  8:03 ` Simon Marchi
2017-06-19  4:15   ` Sergio Durigan Junior

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).