Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v2 (w/ ChangeLog)] Fix disabling of solib probes when LD_AUDITing
@ 2019-12-15  0:12 George Barrett
  2019-12-15  2:30 ` Simon Marchi
  0 siblings, 1 reply; 6+ messages in thread
From: George Barrett @ 2019-12-15  0:12 UTC (permalink / raw)
  To: gdb-patches

The SVR4 solib event handler determines whether an event is related to a
non-base link namespace by comparing the event's debug struct address
to the debug struct address of the initial program image. However, this
can fail when using LD_AUDIT as audit libraries are loaded before the
loader has initialised the initial program image's debug struct. When
the event handler fails to find the debug struct, the probe-based
debugger interface is disabled and a warning is flagged to the user.

This commit adds a fallback test to help determine whether an event is
for a foreign link namespace when the debug struct isn't available.

gdb/ChangeLog:
2019-12-15  George Barrett  <bob@bob131.so>

	* solib-svr4.c (svr4_handle_solib_event): Add fallback link
	namespace test for when the debug struct isn't available.
---
 gdb/solib-svr4.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index de765576d0..f0c7769ac2 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1942,7 +1942,27 @@ svr4_handle_solib_event (void)
     /* Always locate the debug struct, in case it moved.  */
     info->debug_base = 0;
     if (locate_base (info) == 0)
-      return;
+      {
+	/* It's possible for the reloc_complete probe to be triggered before
+	   the linker has set the DT_DEBUG pointer (for example, when the
+	   linker has finished relocating an LD_AUDIT library or its
+	   dependencies).  Since we can't yet handle libraries from other link
+	   namespaces, we don't lose anything by ignoring them here.  */
+	struct value *link_map_id_val;
+	try
+	  {
+	    link_map_id_val = pa->prob->evaluate_argument (0, frame);
+	  }
+	catch (const gdb_exception_error)
+	  {
+	    link_map_id_val = NULL;
+	  }
+	/* glibc and illumos' libc both define LM_ID_BASE as zero.  */
+	if (link_map_id_val != NULL && value_as_long (link_map_id_val) != 0)
+	  action = DO_NOTHING;
+	else
+	  return;
+      }
 
     /* GDB does not currently support libraries loaded via dlmopen
        into namespaces other than the initial one.  We must ignore
-- 
2.23.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 (w/ ChangeLog)] Fix disabling of solib probes when LD_AUDITing
  2019-12-15  0:12 [PATCH v2 (w/ ChangeLog)] Fix disabling of solib probes when LD_AUDITing George Barrett
@ 2019-12-15  2:30 ` Simon Marchi
  2019-12-15  2:33   ` George Barrett
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2019-12-15  2:30 UTC (permalink / raw)
  To: George Barrett, gdb-patches

On 2019-12-14 7:12 p.m., George Barrett wrote:
> The SVR4 solib event handler determines whether an event is related to a
> non-base link namespace by comparing the event's debug struct address
> to the debug struct address of the initial program image. However, this
> can fail when using LD_AUDIT as audit libraries are loaded before the
> loader has initialised the initial program image's debug struct. When
> the event handler fails to find the debug struct, the probe-based
> debugger interface is disabled and a warning is flagged to the user.
> 
> This commit adds a fallback test to help determine whether an event is
> for a foreign link namespace when the debug struct isn't available.

Hi George,

The patch makes sense to me, as far as I understand it.

> gdb/ChangeLog:
> 2019-12-15  George Barrett  <bob@bob131.so>
> 
> 	* solib-svr4.c (svr4_handle_solib_event): Add fallback link
> 	namespace test for when the debug struct isn't available.
> ---
>  gdb/solib-svr4.c | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
> index de765576d0..f0c7769ac2 100644
> --- a/gdb/solib-svr4.c
> +++ b/gdb/solib-svr4.c
> @@ -1942,7 +1942,27 @@ svr4_handle_solib_event (void)
>      /* Always locate the debug struct, in case it moved.  */
>      info->debug_base = 0;
>      if (locate_base (info) == 0)
> -      return;
> +      {
> +	/* It's possible for the reloc_complete probe to be triggered before
> +	   the linker has set the DT_DEBUG pointer (for example, when the
> +	   linker has finished relocating an LD_AUDIT library or its
> +	   dependencies).  Since we can't yet handle libraries from other link
> +	   namespaces, we don't lose anything by ignoring them here.  */
> +	struct value *link_map_id_val;
> +	try
> +	  {
> +	    link_map_id_val = pa->prob->evaluate_argument (0, frame);
> +	  }
> +	catch (const gdb_exception_error)

Catch the exception by reference:

  catch (const gdb_exception_error &)

I can push your patch with this fixed, if you agree (and others think the patch is
fine too).

Simon


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 (w/ ChangeLog)] Fix disabling of solib probes when LD_AUDITing
  2019-12-15  2:30 ` Simon Marchi
@ 2019-12-15  2:33   ` George Barrett
  2019-12-15  2:34     ` Simon Marchi
  0 siblings, 1 reply; 6+ messages in thread
From: George Barrett @ 2019-12-15  2:33 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

On Sat, Dec 14, 2019 at 09:30:43PM -0500, Simon Marchi wrote:
> Catch the exception by reference:
>
>   catch (const gdb_exception_error &)
>
> I can push your patch with this fixed, if you agree (and others think the
> patch is fine too).

Yes, that's fine by me.

Thanks


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 (w/ ChangeLog)] Fix disabling of solib probes when LD_AUDITing
  2019-12-15  2:33   ` George Barrett
@ 2019-12-15  2:34     ` Simon Marchi
  2019-12-21 15:25       ` George Barrett
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2019-12-15  2:34 UTC (permalink / raw)
  To: George Barrett; +Cc: gdb-patches

On 2019-12-14 9:33 p.m., George Barrett wrote:
> On Sat, Dec 14, 2019 at 09:30:43PM -0500, Simon Marchi wrote:
>> Catch the exception by reference:
>>
>>   catch (const gdb_exception_error &)
>>
>> I can push your patch with this fixed, if you agree (and others think the
>> patch is fine too).
> 
> Yes, that's fine by me.
> 
> Thanks
> 

Ok, I'd like to leave a bit of time for others to comment, so please
ping in a week or so if there hasn't been any other activity, I'll merge
it then.

Simon


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 (w/ ChangeLog)] Fix disabling of solib probes when LD_AUDITing
  2019-12-15  2:34     ` Simon Marchi
@ 2019-12-21 15:25       ` George Barrett
  2019-12-21 21:03         ` Simon Marchi
  0 siblings, 1 reply; 6+ messages in thread
From: George Barrett @ 2019-12-21 15:25 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

On Sat, Dec 14, 2019 at 09:34:30PM -0500, Simon Marchi wrote:
> Ok, I'd like to leave a bit of time for others to comment, so please
> ping in a week or so if there hasn't been any other activity, I'll merge
> it then.

Pinging, as requested.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 (w/ ChangeLog)] Fix disabling of solib probes when LD_AUDITing
  2019-12-21 15:25       ` George Barrett
@ 2019-12-21 21:03         ` Simon Marchi
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2019-12-21 21:03 UTC (permalink / raw)
  To: George Barrett; +Cc: gdb-patches

On 2019-12-21 10:25 a.m., George Barrett wrote:
> On Sat, Dec 14, 2019 at 09:34:30PM -0500, Simon Marchi wrote:
>> Ok, I'd like to leave a bit of time for others to comment, so please
>> ping in a week or so if there hasn't been any other activity, I'll merge
>> it then.
> 
> Pinging, as requested.
> 

Thanks, I have pushed it.

Simon


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-12-21 21:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-15  0:12 [PATCH v2 (w/ ChangeLog)] Fix disabling of solib probes when LD_AUDITing George Barrett
2019-12-15  2:30 ` Simon Marchi
2019-12-15  2:33   ` George Barrett
2019-12-15  2:34     ` Simon Marchi
2019-12-21 15:25       ` George Barrett
2019-12-21 21:03         ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox