Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 May 2014 03:26:25 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r265629 - head/lib/librtld_db
Message-ID:  <201405080326.s483QPOC054185@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Thu May  8 03:26:25 2014
New Revision: 265629
URL: http://svnweb.freebsd.org/changeset/base/265629

Log:
  Handle the different event types properly in rd_event_addr(). In particular,
  with r265456 _r_debug_postinit can be used for RD_POSTINIT events. rtld(1)
  uses r_debug_state for dl state transitions, so we use its address for
  RD_DLACTIVITY events.
  
  MFC after:	2 weeks

Modified:
  head/lib/librtld_db/rtld_db.c
  head/lib/librtld_db/rtld_db.h

Modified: head/lib/librtld_db/rtld_db.c
==============================================================================
--- head/lib/librtld_db/rtld_db.c	Thu May  8 02:24:30 2014	(r265628)
+++ head/lib/librtld_db/rtld_db.c	Thu May  8 03:26:25 2014	(r265629)
@@ -81,20 +81,40 @@ rd_errstr(rd_err_e rderr)
 }
 
 rd_err_e
-rd_event_addr(rd_agent_t *rdap, rd_event_e event __unused, rd_notify_t *notify)
+rd_event_addr(rd_agent_t *rdap, rd_event_e event, rd_notify_t *notify)
 {
-	DPRINTF("%s rdap %p notify %p\n", __func__, rdap, notify);	
+	rd_err_e ret;
 
-	notify->type = RD_NOTIFY_BPT;
-	notify->u.bptaddr = rdap->rda_addr;
+	DPRINTF("%s rdap %p event %d notify %p\n", __func__, rdap, event,
+	    notify);
 
-	return (RD_OK);
+	ret = RD_OK;
+	switch (event) {
+	case RD_NONE:
+		break;
+	case RD_PREINIT:
+		notify->type = RD_NOTIFY_BPT;
+		notify->u.bptaddr = rdap->rda_preinit_addr;
+		break;
+	case RD_POSTINIT:
+		notify->type = RD_NOTIFY_BPT;
+		notify->u.bptaddr = rdap->rda_postinit_addr;
+		break;
+	case RD_DLACTIVITY:
+		notify->type = RD_NOTIFY_BPT;
+		notify->u.bptaddr = rdap->rda_dlactivity_addr;
+		break;
+	default:
+		ret = RD_ERR;
+		break;
+	}
+	return (ret);
 }
 
 rd_err_e
 rd_event_enable(rd_agent_t *rdap __unused, int onoff)
 {
-	DPRINTF("%s onoff %d\n", __func__, onoff);	
+	DPRINTF("%s onoff %d\n", __func__, onoff);
 
 	return (RD_OK);
 }
@@ -220,7 +240,15 @@ rd_reset(rd_agent_t *rdap)
 	    &sym) < 0)
 		return (RD_ERR);
 	DPRINTF("found r_debug_state at 0x%lx\n", (unsigned long)sym.st_value);
-	rdap->rda_addr = sym.st_value;
+	rdap->rda_preinit_addr = sym.st_value;
+	rdap->rda_dlactivity_addr = sym.st_value;
+
+	if (proc_name2sym(rdap->rda_php, "ld-elf.so.1", "_r_debug_postinit",
+	    &sym) < 0)
+		return (RD_ERR);
+	DPRINTF("found _r_debug_postinit at 0x%lx\n",
+	    (unsigned long)sym.st_value);
+	rdap->rda_postinit_addr = sym.st_value;
 
 	return (RD_OK);
 }

Modified: head/lib/librtld_db/rtld_db.h
==============================================================================
--- head/lib/librtld_db/rtld_db.h	Thu May  8 02:24:30 2014	(r265628)
+++ head/lib/librtld_db/rtld_db.h	Thu May  8 03:26:25 2014	(r265629)
@@ -51,7 +51,9 @@ typedef enum {
 
 typedef struct rd_agent {
 	struct proc_handle *rda_php;
-	uintptr_t rda_addr;		/* address of r_debug_state */
+	uintptr_t rda_dlactivity_addr;
+	uintptr_t rda_preinit_addr;
+	uintptr_t rda_postinit_addr;
 } rd_agent_t;
 
 typedef struct rd_loadobj {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405080326.s483QPOC054185>