From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17133 invoked by alias); 7 Nov 2012 11:24:26 -0000 Received: (qmail 17125 invoked by uid 22791); 7 Nov 2012 11:24:26 -0000 X-SWARE-Spam-Status: No, hits=-4.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 07 Nov 2012 11:24:20 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1TW3k3-0006Sr-ED from Luis_Gustavo@mentor.com ; Wed, 07 Nov 2012 03:24:19 -0800 Received: from NA1-MAIL.mgc.mentorg.com ([147.34.98.181]) by svr-orw-fem-01.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 7 Nov 2012 03:24:19 -0800 Received: from [0.0.0.0] ([172.16.63.104]) by NA1-MAIL.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 7 Nov 2012 03:24:18 -0800 Message-ID: <509A44E3.9030209@codesourcery.com> Date: Wed, 07 Nov 2012 11:24:00 -0000 From: Luis Machado Reply-To: lgustavo@codesourcery.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.28) Gecko/20120313 Lightning/1.0b2 Thunderbird/3.1.20 MIME-Version: 1.0 To: Joel Brobecker CC: gdb-patches@sourceware.org Subject: Re: [PATCH,tests] Run to main before doing any tests in structs3.exp References: <50994431.1040405@codesourcery.com> <20121106173029.GC5103@adacore.com> <50995C16.2060507@codesourcery.com> <20121107002611.GD5103@adacore.com> In-Reply-To: <20121107002611.GD5103@adacore.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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 X-SW-Source: 2012-11/txt/msg00137.txt.bz2 Joe, On 11/06/2012 10:26 PM, Joel Brobecker wrote: >> Consider, for example, a target that runs on QEMU. QEMU won't start >> the binary in exactly the same way as gdbserver running on linux. >> Thus, global variable initialization procedures may not have >> happened at that point yet. Consider that we start even before the >> dynamic loader had a chance to run and do all the relocation magic. > > The part I don't get is why this even enters the picture. If it was > a C++ program, with elaboration code that's run when the binary is > loaded in memory, I would understand. But this is a plain C program, > where I imagine the variables are simply located in data, with their > default value provided there. So, even if the program hasn't started > at all, GDB should be able to fetch it from the binary. > > That being said, I don't want to hold your patch. I think it's fine > to run the program till main. I was just curious as to why this was > sometimes necessary. Still can't get it :-). > I find the discussion and in-depth view really important, so i appreciate your comments. There is, of course, an explanation. :-) The real issue arises from two points: 1 - As Pedro mentioned, the testsuite does not start the inferior for native debugging, but does so for remote targets. 2 - On startup, some targets relocate the binary's sections during inferior execution. When this happens, data is shifted from location X to location Y. In the specific case of structs3, we have "two", the structure, and "twop", a pointer to the structure. The whole structure is properly relocated, so attempting to print "two" will yield the correct result. When gdb tries to print the contents of "twop", that's where the problem shows up. Though "two" and "twop" have been properly relocated, the value of "twop" is still pointing at the location before relocation, thus the printed values are wrong. The contents of "twop" will eventually be fixed up by a dynamic relocation during ld.so's execution (which, in my case, did not start yet). Pedro's suggestion of simply loading the binary via gdb_file_cmd works for me though. So there is no need to effectively start the inferior. Luis