* getenv always return NULL in GDB/DDD
@ 2018-10-26 9:35 Luo, Ginger
2018-10-26 14:21 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Luo, Ginger @ 2018-10-26 9:35 UTC (permalink / raw)
To: gdb
Hello, GDB experts
I try to call getenv in my C code, this can return correct env string in terminal, while it returns NULL in GDB/DDD.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
void main() {
char * a = getenv("ANCHOR"); // ANCHOR exists in the terminal
if (strlen(a)>0)
printf("%s\n", a);
}
The GDB/DDD is started from the same terminal. Even I "show environment", this env exists.
Anyone any idea?
OS/Tools version info: RHEL Linux hostname1 2.6.32-754.3.5.el6.x86_64 #1 SMP Thu Aug 9 11:56:22 EDT 2018 x86_64 GNU/Linux
GNU gdb (GDB) 7.12
gcc (GCC) 6.3.0
SHELL is tcsh, DDD/GDB is using default settings.
Let me know if you need any further info.
Thanks!
G
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: getenv always return NULL in GDB/DDD
2018-10-26 9:35 getenv always return NULL in GDB/DDD Luo, Ginger
@ 2018-10-26 14:21 ` Simon Marchi
2018-10-29 5:05 ` Luo, Ginger
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2018-10-26 14:21 UTC (permalink / raw)
To: Luo, Ginger; +Cc: gdb
On 2018-10-26 05:35, Luo, Ginger wrote:
> Hello, GDB experts
>
>
> I try to call getenv in my C code, this can return correct env string
> in terminal, while it returns NULL in GDB/DDD.
>
>
> #include <stdlib.h>
>
> #include <string.h>
>
> #include <stdio.h>
>
> void main() {
> char * a = getenv("ANCHOR"); // ANCHOR exists in the terminal
> if (strlen(a)>0)
> printf("%s\n", a);
> }
>
>
> The GDB/DDD is started from the same terminal. Even I "show
> environment", this env exists.
>
> Anyone any idea?
>
> OS/Tools version info: RHEL Linux hostname1 2.6.32-754.3.5.el6.x86_64
> #1 SMP Thu Aug 9 11:56:22 EDT 2018 x86_64 GNU/Linux
>
> GNU gdb (GDB) 7.12
>
> gcc (GCC) 6.3.0
> SHELL is tcsh, DDD/GDB is using default settings.
>
> Let me know if you need any further info.
I don't see off-hand why this would happen. One thing to try would be
"set startup-with-shell off". If, for some reason, your shell (through
which the debugged program is ran) messes up with the environment, this
would bypass it entirely.
Otherwise, as usual, I would recommend trying the latest version of GDB.
I don't have anything specific in mind that changed recently, but it's
good to try.
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread* RE: getenv always return NULL in GDB/DDD
2018-10-26 14:21 ` Simon Marchi
@ 2018-10-29 5:05 ` Luo, Ginger
0 siblings, 0 replies; 3+ messages in thread
From: Luo, Ginger @ 2018-10-29 5:05 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb
Simon,
Thanks, It's awesomely working.
-----Original Message-----
From: Simon Marchi <simon.marchi@polymtl.ca>
Sent: Friday, October 26, 2018 10:21 PM
To: Luo, Ginger <Ginger.Luo@amd.com>
Cc: gdb@sourceware.org
Subject: Re: getenv always return NULL in GDB/DDD
On 2018-10-26 05:35, Luo, Ginger wrote:
> Hello, GDB experts
>
>
> I try to call getenv in my C code, this can return correct env string
> in terminal, while it returns NULL in GDB/DDD.
>
>
> #include <stdlib.h>
>
> #include <string.h>
>
> #include <stdio.h>
>
> void main() {
> char * a = getenv("ANCHOR"); // ANCHOR exists in the terminal
> if (strlen(a)>0)
> printf("%s\n", a);
> }
>
>
> The GDB/DDD is started from the same terminal. Even I "show
> environment", this env exists.
>
> Anyone any idea?
>
> OS/Tools version info: RHEL Linux hostname1 2.6.32-754.3.5.el6.x86_64
> #1 SMP Thu Aug 9 11:56:22 EDT 2018 x86_64 GNU/Linux
>
> GNU gdb (GDB) 7.12
>
> gcc (GCC) 6.3.0
> SHELL is tcsh, DDD/GDB is using default settings.
>
> Let me know if you need any further info.
I don't see off-hand why this would happen. One thing to try would be "set startup-with-shell off". If, for some reason, your shell (through which the debugged program is ran) messes up with the environment, this would bypass it entirely.
Otherwise, as usual, I would recommend trying the latest version of GDB.
I don't have anything specific in mind that changed recently, but it's good to try.
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-10-29 5:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-26 9:35 getenv always return NULL in GDB/DDD Luo, Ginger
2018-10-26 14:21 ` Simon Marchi
2018-10-29 5:05 ` Luo, Ginger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox