From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tom@tromey.com>
Cc: Joel Brobecker <brobecker@adacore.com>,
Xavier Roirand <roirand@adacore.com>,
gdb-patches@sourceware.org
Subject: Re: [RFA 2/5] Darwin: Handle unrelocated dyld.
Date: Wed, 19 Sep 2018 19:50:00 -0000 [thread overview]
Message-ID: <d2b9ec24e9252780f9c61dd2bf674ac9@polymtl.ca> (raw)
In-Reply-To: <87worhpadh.fsf@tromey.com>
On 2018-09-19 15:15, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> 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 <roirand@adacore.com>
> 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
next prev parent reply other threads:[~2018-09-19 19:50 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-22 10:11 [RFA 0/5] Fix some bugs on macOS Xavier Roirand
2018-08-22 10:11 ` [RFA 4/5] Darwin: fix thread ptid started by fork_inferior Xavier Roirand
2018-08-22 14:30 ` Simon Marchi
2018-08-22 16:10 ` Pedro Alves
2018-08-22 18:14 ` Simon Marchi
2018-08-22 10:11 ` [RFA 5/5] Darwin: fix SIGTRAP when debugging Xavier Roirand
2018-08-22 14:34 ` Simon Marchi
2018-08-22 10:11 ` [RFA 1/5] Darwin: fix bad loop incrementation Xavier Roirand
2018-08-22 13:14 ` Simon Marchi
2018-08-23 15:21 ` Simon Marchi
2018-08-22 10:11 ` [RFA 3/5] Darwin: set startup-with-shell to off on Sierra and later Xavier Roirand
2018-08-22 14:20 ` Simon Marchi
2018-08-22 14:37 ` Pedro Alves
2018-09-03 13:23 ` Xavier Roirand
2018-09-17 19:31 ` Tom Tromey
2018-08-22 10:11 ` [RFA 2/5] Darwin: Handle unrelocated dyld Xavier Roirand
2018-08-22 13:55 ` Simon Marchi
2018-09-18 21:22 ` Tom Tromey
2018-09-19 13:41 ` Joel Brobecker
2018-09-19 14:16 ` Simon Marchi
2018-09-19 14:28 ` Joel Brobecker
2018-09-19 14:36 ` Tom Tromey
2018-09-19 14:44 ` Simon Marchi
2018-09-19 15:32 ` Joel Brobecker
2018-09-19 19:15 ` Tom Tromey
2018-09-19 19:50 ` Simon Marchi [this message]
2018-09-28 13:31 ` Xavier Roirand
2018-09-28 17:22 ` Tom Tromey
2018-08-22 13:59 ` Simon Marchi
2018-09-18 21:23 ` Tom Tromey
2018-09-17 20:57 ` [RFA 0/5] Fix some bugs on macOS Tom Tromey
2018-09-17 21:25 ` Joel Brobecker
2018-09-17 23:03 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d2b9ec24e9252780f9c61dd2bf674ac9@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=roirand@adacore.com \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox