From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 104744 invoked by alias); 7 Oct 2016 12:09:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 104724 invoked by uid 89); 7 Oct 2016 12:09:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS,URIBL_RED autolearn=ham version=3.3.2 spammy=bare, metal, luis X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Oct 2016 12:09:02 +0000 Received: from svr-orw-mbx-03.mgc.mentorg.com ([147.34.90.203]) by relay1.mentorg.com with esmtp id 1bsTxV-0003mE-Fa from Luis_Gustavo@mentor.com ; Fri, 07 Oct 2016 05:09:01 -0700 Received: from [172.30.8.200] (147.34.91.1) by svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Fri, 7 Oct 2016 05:08:58 -0700 Reply-To: Luis Machado Subject: Re: [PATCH] Fixup gdb.python/py-value.exp for bare-metal aarch64-elf References: <1475771231-1739-1-git-send-email-lgustavo@codesourcery.com> To: Yao Qi CC: "gdb-patches@sourceware.org" From: Luis Machado Message-ID: Date: Fri, 07 Oct 2016 12:09:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00161.txt.bz2 On 10/07/2016 05:23 AM, Yao Qi wrote: > On Thu, Oct 6, 2016 at 5:27 PM, Luis Machado wrote: >> I noticed that testing aarch64-elf gdb with a physical board >> ran into issues with gdb.python/py-value.exp. Further investigation showed >> that we were actually trying to dereference a NULL pointer (argv) when trying >> to access argv[0]. >> >> Being bare-metal, argv is not guaranteed to be there. So we need to make sure >> argv is sane before accessing argv[0]. >> >> After fixing that, i noticed we were assuming a value of 1 for argc, which is >> also not true, as i see 0 in my tests. > > If I understand C standard > http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf correctly, > "argv" can't be NULL. > > 5.1.2.2.1 Program startup > ... > The value of argc shall be nonnegative. > argv[argc] shall be a null pointer. > > The first one implies that argc can be zero, and the second one implies > argv can't be NULL. In this case, argc is zero, so argv[0] can be > dereferenced. > I went back and read the standard and we're dealing with a freestanding environment for bare metal here. The descriptions above seem to make sense for a hosted environment, but not for a freestanding one, correct?