Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org, roirand@adacore.com
Subject: Re: [RFC] Make "run" work on macOS 10.13
Date: Thu, 23 Aug 2018 16:01:00 -0000	[thread overview]
Message-ID: <d4d3994e73220253b058babb07c995fc@polymtl.ca> (raw)
In-Reply-To: <20180629205532.25377-1-tom@tromey.com>

On 2018-06-29 16:55, Tom Tromey wrote:
> I would like some feedback on this patch.
> 
> On macOS 10.13.5, "run" does not work in gdb.  There are two cases:
> 
> 1. If I forget to "set startup-with-shell off", then gdb will fail due
>    to the system integrity protection feature.  I believe this happens
>    because gdb is not allowed to debug the shell.
> 
>    You can find many sites advocating "set startup-with-shell off",
>    but it seems to me that it is friendlier for gdb to simply do it by
>    default.
> 
>    One option here might be to do this conditionally based on the
>    version of the OS.
> 
> 2. I found that gdb was setting the solib breakpoint incorrectly,
>    causing a failure.  Adding the load address to the notifier address
>    makes this work for me.  I suspect this would regress earlier
>    versions of macOS, but I have no way to test that; one idea might
>    be to only do this when gdb_dyld_all_image_infos::version == 15.
> 
> gdb/ChangeLog
> 2018-06-29  Tom Tromey  <tom@tromey.com>
> 
> 	* solib-darwin.c (darwin_solib_create_inferior_hook): Create solib
> 	breakpoint later.  Add load_addr to the notifier address.
> 	* darwin-nat.c (darwin_nat_target::create_inferior): Bind
> 	startup_with_shell to 0.
> ---
>  gdb/ChangeLog      | 7 +++++++
>  gdb/darwin-nat.c   | 5 +++++
>  gdb/solib-darwin.c | 9 +++++----
>  3 files changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 4c04d0ba728..c6462259fe0 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,10 @@
> +2018-06-29  Tom Tromey  <tom@tromey.com>
> +
> +	* solib-darwin.c (darwin_solib_create_inferior_hook): Create solib
> +	breakpoint later.  Add load_addr to the notifier address.
> +	* darwin-nat.c (darwin_nat_target::create_inferior): Bind
> +	startup_with_shell to 0.
> +
>  2018-06-28  Tom Tromey  <tom@tromey.com>
> 
>  	* NEWS: Mention --enable-codesign.
> diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
> index 7dccce73926..542c8389ef0 100644
> --- a/gdb/darwin-nat.c
> +++ b/gdb/darwin-nat.c
> @@ -1809,6 +1809,11 @@ darwin_nat_target::create_inferior (const char
> *exec_file,
>  				    const std::string &allargs,
>  				    char **env, int from_tty)
>  {
> +  /* Starting with Sierra, SIP prevents gdb from attaching to the
> +     shell, so users have to disable startup-with-shell.  */
> +  scoped_restore save_startup
> +    = make_scoped_restore (&startup_with_shell, 0);
> +
>    /* Do the hard work.  */
>    fork_inferior (exec_file, allargs, env, darwin_ptrace_me,

I think this part is good.  I would suggest printing a message/warnings 
to indicate that we are disabling startup-with-shell (only if 
startup_with_shell is 1 in the first place).

>  		 darwin_ptrace_him, darwin_pre_ptrace, NULL,
> diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
> index ed8e0c13365..a4e15dc6b5b 100644
> --- a/gdb/solib-darwin.c
> +++ b/gdb/solib-darwin.c
> @@ -528,10 +528,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).  */
> @@ -547,6 +543,11 @@ darwin_solib_create_inferior_hook (int from_tty)
>        load_addr = darwin_read_exec_load_addr_at_init (info);
>      }
> 
> +  /* 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 + load_addr);
> +
>    if (load_addr != 0 && symfile_objfile != NULL)
>      {
>        CORE_ADDR vmaddr;

About the dynamic loader relocation, I am trying to compare your 
approach with Xavier's approach here:

https://sourceware.org/ml/gdb-patches/2018-08/msg00519.html

If I print the resulting notifier address, I get two different values:

With Tom's patch: 0x10000f782
With Xavier's patch: 0x100012782

The unrelocated value of the symbol is 0xf782.  That breakpoint is used 
for "set stop-on-solib-events", it seems, so I tried to enable that with 
both of your patches.  I got a stop with Xavier's patch and none with 
Tom's, which leads me to think that Xavier's patch gets it right.  I 
think you may be using the executable base address, while we actually 
want to use dyld's base address?  This is not very clear to me yet.

Simon


  parent reply	other threads:[~2018-08-23 16:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-29 20:55 Tom Tromey
2018-06-29 21:01 ` Tom Tromey
2018-06-29 23:04 ` Joel Brobecker
2018-06-30 17:41 ` Pedro Alves
2018-08-23 16:01 ` Simon Marchi [this message]
2018-08-23 20:04   ` Tom Tromey
2018-08-23 20:42     ` Simon Marchi

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=d4d3994e73220253b058babb07c995fc@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --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