From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13976 invoked by alias); 26 Oct 2018 14:21:23 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 13966 invoked by uid 89); 26 Oct 2018 14:21:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=luo, sk:startup, offhand X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 Oct 2018 14:21:21 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id w9QELEnc013396 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 26 Oct 2018 10:21:19 -0400 Received: by simark.ca (Postfix, from userid 112) id C630C1EA6F; Fri, 26 Oct 2018 10:21:14 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id B346C1E514; Fri, 26 Oct 2018 10:21:12 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 26 Oct 2018 14:21:00 -0000 From: Simon Marchi To: "Luo, Ginger" Cc: gdb@sourceware.org Subject: Re: getenv always return NULL in GDB/DDD In-Reply-To: References: Message-ID: <4db04642c19ebdf220c6022d2ff5f5b8@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-IsSubscribed: yes X-SW-Source: 2018-10/txt/msg00052.txt.bz2 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 > > #include > > #include > > 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