From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 74335 invoked by alias); 19 Sep 2018 19:50:43 -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 73996 invoked by uid 89); 19 Sep 2018 19:50:43 -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= 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; Wed, 19 Sep 2018 19:50:41 +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 w8JJoZHL031512 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 19 Sep 2018 15:50:39 -0400 Received: by simark.ca (Postfix, from userid 112) id E657B1E76F; Wed, 19 Sep 2018 15:50:34 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id DE9631E175; Wed, 19 Sep 2018 15:50:31 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 19 Sep 2018 19:50:00 -0000 From: Simon Marchi To: Tom Tromey Cc: Joel Brobecker , Xavier Roirand , gdb-patches@sourceware.org Subject: Re: [RFA 2/5] Darwin: Handle unrelocated dyld. In-Reply-To: <87worhpadh.fsf@tromey.com> References: <1534932677-9496-1-git-send-email-roirand@adacore.com> <1534932677-9496-3-git-send-email-roirand@adacore.com> <18e995c1bee8c82df212dd431136d259@polymtl.ca> <87lg7ysdpb.fsf@tromey.com> <20180919134057.GN19172@adacore.com> <87fty5r1ud.fsf@tromey.com> <8f17f90607d350f19c4a36346c4e1acb@polymtl.ca> <87worhpadh.fsf@tromey.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00712.txt.bz2 On 2018-09-19 15:15, Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi writes: > > Simon> I would vote for only checking in the code you know is necessary > for > Simon> now, otherwise it will just be more confusing in the future, > trying to > Simon> figure out what is needed and what isn't. > > Here is a more minimal version of the patch. This one seems to work > for > me on High Sierra. I tried running a "hello world" program -- this > previously failed, but now works. It's good enough that I could run > gdb.cp/*.exp -- lots of fails but no crashes or mystery problems. > > Tom > > commit 114a1aae792443d72f1438dbc979b42a39c5b780 > Author: Xavier Roirand > Date: Wed Aug 22 12:11:14 2018 +0200 > > Darwin: Handle unrelocated dyld. > > On Darwin, debugging an helloworld program with GDB does > not work and ends with: > > (gdb) set startup-with-shell off > (gdb) start > Temporary breakpoint 1 at 0x100000fb4: file /tmp/helloworld.c, > line 1. > Starting program: /private/tmp/helloworld > [New Thread 0x2703 of process 18906] > [New Thread 0x2603 of process 18906] > > [1]+ Stopped ./gdb/gdb /tmp/helloworld > > When debugging with lldb, instead of having the STOP signal, we can > see that a breakpoint is not set to a proper location: > > Warning: > Cannot insert breakpoint -1. > Cannot access memory at address 0xf726 > > Command aborted. > > The inserted breakpoint is the one used when GDB has to stop the > target > when a shared library is loaded or unloaded. The notifier address > used > for adding the breakpoint is wrong thus the above failure. > This notifier address is an offset relative to dyld base address, > so > the value calculation has to be updated to reflect this. > > This was tested on High Sierra by trying to run a simple "hello > world" > program. Works for me, thanks! I just noted some nits. > @@ -459,6 +457,18 @@ darwin_solib_get_all_image_info_addr_at_init > (struct darwin_info *info) > else > dyld_bfd.release (); > } > + return dyld_bfd; > +} > + > +/* Extract dyld_all_image_addr when the process was just created, > assuming the > + current PC is at the entry of the dynamic linker. */ > + > +static void > +darwin_solib_get_all_image_info_addr_at_init (struct darwin_info > *info) > +{ > + CORE_ADDR load_addr = 0; > + gdb_bfd_ref_ptr dyld_bfd (darwin_get_dyld_bfd ()); Use =. > + > if (dyld_bfd == NULL) > return; > > @@ -528,10 +538,6 @@ darwin_solib_create_inferior_hook (int from_tty) > return; > } > > - /* Add the breakpoint which is hit by dyld when the list of solib is > - modified. */ > - create_solib_event_breakpoint (target_gdbarch (), > info->all_image.notifier); > - > if (info->all_image.count != 0) > { > /* Possible relocate the main executable (PIE). */ > @@ -558,6 +564,49 @@ darwin_solib_create_inferior_hook (int from_tty) > if (vmaddr != load_addr) > objfile_rebase (symfile_objfile, load_addr - vmaddr); > } > + > + /* Set solib notifier (to reload list of shared libraries). */ > + CORE_ADDR notifier = info->all_image.notifier; > + > + if (info->all_image.count == 0) > + { > + /* Dyld hasn't yet relocated itself, so the notifier address may > + be incorrect (as it has to be relocated). */ > + CORE_ADDR start = bfd_get_start_address (exec_bfd); > + if (start == 0) > + notifier = 0; > + else > + { > + gdb_bfd_ref_ptr dyld_bfd (darwin_get_dyld_bfd ()); Here too. Simon