Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 Oct 2012 21:50:34 +0000 (UTC)
From:      Raphael Kubo da Costa <rakuco@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r306581 - in head/devel/gdb: . files
Message-ID:  <201210282150.q9SLoYAI007166@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rakuco
Date: Sun Oct 28 21:50:34 2012
New Revision: 306581
URL: http://svn.freebsd.org/changeset/ports/306581

Log:
  - Show thread names, closing ports/172572. Thanks to Mark Lokowich.
  - It is now possible to choose which readline version to use, closing
    ports/172077. Thanks to Jan Beich.
  - Fix patches to remove compilation warnings.
  - Clean configure arguments to remove a compilation warning.
  - Fix file permissions when the PYTHON option is enabled.
  - Trim Makefile header.
  
  PR:		ports/172828
  Submitted by:	Luca Pizzammiglio <luca.pizzamiglio@gmail.com> (maintainer)
  Feature safe:	yes

Modified:
  head/devel/gdb/Makefile
  head/devel/gdb/files/fbsd-threads.c
  head/devel/gdb/files/patch-gdb-amd64fbsd-nat.c
  head/devel/gdb/files/patch-gdb-i386fbsd-nat.c

Modified: head/devel/gdb/Makefile
==============================================================================
--- head/devel/gdb/Makefile	Sun Oct 28 21:44:23 2012	(r306580)
+++ head/devel/gdb/Makefile	Sun Oct 28 21:50:34 2012	(r306581)
@@ -24,13 +24,12 @@ CONFIGURE_ENV=	CONFIGURED_M4=m4 CONFIGUR
 CONFIGURE_ARGS=	--program-suffix=${PORTVERSION:S/.//g} \
 		--with-gdb-datadir=${PREFIX}/share/gdb${PORTVERSION:S/.//g} \
 		--with-libiconv-prefix=${LOCALBASE} \
-		--with-system-readline \
-		--without-libunwind \
+		--without-libunwind-ia64 \
 		--enable-target=all \
 		--enable-tui
 CFLAGS:=	${CFLAGS:C/ +$//}	# blanks at EOL creep in sometimes
 CFLAGS+=	-DRL_NO_COMPAT
-EXCLUDE=	dejagnu expect readline sim texinfo intl
+EXCLUDE=	dejagnu expect sim texinfo intl
 EXTRACT_AFTER_ARGS=	| ${TAR} -xf - ${EXCLUDE:S/^/--exclude /} \
 			--no-same-owner --no-same-permissions
 VER=	${PORTVERSION:S/.//g}
@@ -39,13 +38,14 @@ MAN1=	gdb${VER}.1
 
 ONLY_FOR_ARCHS=	i386 amd64	# untested elsewhere, might work
 
-# Forcing to use readline.6 from ports (newer readline in FreeBSD world is not
-# compatible anymore).
-USE_READLINE=	port
-
 OPTIONS_DEFINE=	DEBUG EXPAT PYTHON THREADS GDB_LINK
+OPTIONS_SINGLE_READLINE=	BASE_READLINE BUNDLED_READLINE PORT_READLINE
+OPTIONS_SINGLE=	READLINE
+BASE_READLINE_DESC=	from base system (EXPERIMENTAL)
+BUNDLED_READLINE_DESC=	from gdb distfile
+PORT_READLINE_DESC=	from devel/readline port
 GDB_LINK_DESC=	Create the gdb link
-OPTIONS_DEFAULT=	THREADS GDB_LINK
+OPTIONS_DEFAULT=	THREADS GDB_LINK PORT_READLINE
 
 .include <bsd.port.options.mk>
 
@@ -59,6 +59,19 @@ PLIST_SUB+=	GDB_LINK="@comment "
 USE_PYTHON=	2.5-2.7
 .endif
 
+.if empty(PORT_OPTIONS:MBUNDLED_READLINE)
+EXCLUDE+=	readline
+CONFIGURE_ARGS+=	--with-system-readline
+.endif
+
+.if ${PORT_OPTIONS:MBASE_READLINE}
+CFLAGS+=	-D_rl_echoing_p=readline_echoing_p
+USE_READLINE=	base
+.endif
+
+.if ${PORT_OPTIONS:MPORT_READLINE}
+USE_READLINE=	port
+.endif
 .include <bsd.port.pre.mk>
 
 .if ${PORT_OPTIONS:MTHREADS}
@@ -97,7 +110,7 @@ post-patch:
 
 do-install:
 	${INSTALL_PROGRAM} ${WRKSRC}/gdb/gdb ${PREFIX}/bin/gdb${VER}
-	${LN} ${PREFIX}/bin/gdb${VER} ${PREFIX}/bin/gdbtui${VER}
+	${LN} -sf ${PREFIX}/bin/gdb${VER} ${PREFIX}/bin/gdbtui${VER}
 	${INSTALL_MAN} ${WRKSRC}/gdb/gdb.1 ${MAN1PREFIX}/man/man1/gdb${VER}.1
 .if ${PORT_OPTIONS:MGDB_LINK}
 	${LN} -sf gdb${VER} ${PREFIX}/bin/gdb
@@ -107,4 +120,10 @@ do-install:
 	(cd ${WRKSRC}/gdb/data-directory; ${GMAKE} install-python )
 .endif
 
+post-install:
+.if ${PORT_OPTIONS:MPYTHON}
+	${CHMOD} u+w ${PREFIX}/share/gdb${VER}/python/gdb/*.py*
+	${CHMOD} u+w ${PREFIX}/share/gdb${VER}/python/gdb/command/*.py*
+.endif
+
 .include <bsd.port.post.mk>

Modified: head/devel/gdb/files/fbsd-threads.c
==============================================================================
--- head/devel/gdb/files/fbsd-threads.c	Sun Oct 28 21:44:23 2012	(r306580)
+++ head/devel/gdb/files/fbsd-threads.c	Sun Oct 28 21:50:34 2012	(r306581)
@@ -18,6 +18,15 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <err.h>
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+#include <libutil.h>
 
 #include <dlfcn.h>
 #include <sys/types.h>
@@ -48,11 +57,19 @@
 
 #define LIBTHREAD_DB_SO "libthread_db.so"
 
+struct private_thread_info
+{
+  char *lwp_name;
+};
+
 struct ps_prochandle
 {
   pid_t pid;
 };
 
+/* Defining the prototype of _initialize_thread_db to remove warning */
+extern initialize_file_ftype _initialize_thread_db;
+
 /* This module's target vectors.  */
 static struct target_ops fbsd_thread_ops;
 
@@ -76,8 +93,8 @@ static td_thragent_t *thread_agent;
 /* The last thread we are single stepping */
 static ptid_t last_single_step_thread;
 
-/* Pointers to the libthread_db functions.  */
 
+/* Pointers to the libthread_db functions.  */
 static td_err_e (*td_init_p) (void);
 
 static td_err_e (*td_ta_new_p) (struct ps_prochandle *ps, td_thragent_t **ta);
@@ -133,6 +150,7 @@ static CORE_ADDR td_create_bp_addr;
 static CORE_ADDR td_death_bp_addr;
 
 /* Prototypes for local functions.  */
+static void fbsd_find_lwp_name(long lwpid, struct private_thread_info *info);
 static void fbsd_thread_find_new_threads (struct target_ops *ops);
 static int fbsd_thread_alive (struct target_ops *ops, ptid_t ptid);
 static void attach_thread (ptid_t ptid, const td_thrhandle_t *th_p,
@@ -140,6 +158,9 @@ static void attach_thread (ptid_t ptid, 
 static void fbsd_thread_detach (struct target_ops *ops, char *args,
 				int from_tty);
 
+CORE_ADDR fbsd_thread_get_local_address(struct target_ops *ops,
+		ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset);
+
 /* Building process ids.  */
 
 #define GET_PID(ptid)		ptid_get_pid (ptid)
@@ -152,6 +173,13 @@ static void fbsd_thread_detach (struct t
 #define BUILD_LWP(lwp, pid)	ptid_build (pid, lwp, 0)
 #define BUILD_THREAD(tid, pid)	ptid_build (pid, 0, tid)
 
+static void
+free_private_thread_info(struct private_thread_info *info)
+{
+  xfree(info->lwp_name);
+  xfree(info);
+}
+
 static char *
 thread_db_err_str (td_err_e err)
 {
@@ -237,7 +265,7 @@ static ptid_t
 thread_from_lwp (ptid_t ptid, td_thrhandle_t *th, td_thrinfo_t *ti)
 {
   td_err_e err;
- 
+
   gdb_assert (IS_LWP (ptid));
 
   if (fbsd_thread_active)
@@ -252,7 +280,7 @@ thread_from_lwp (ptid_t ptid, td_thrhand
         }
     }
 
-  /* the LWP is not mapped to user thread */  
+  /* the LWP is not mapped to user thread */
   return BUILD_LWP (GET_LWP (ptid), GET_PID (ptid));
 }
 
@@ -463,7 +491,7 @@ check_for_thread_db (void)
      that at this point there is no guarantee that we actually have a
      child process.  */
   proc_handle.pid = GET_PID (inferior_ptid);
-  
+
   /* Now attempt to open a connection to the thread library.  */
   err = td_ta_new_p (&proc_handle, &thread_agent);
   switch (err)
@@ -477,7 +505,7 @@ check_for_thread_db (void)
       push_target(&fbsd_thread_ops);
       fbsd_thread_present = 1;
       fbsd_thread_activate();
-	  
+
       break;
 
     default:
@@ -631,11 +659,24 @@ static void
 attach_thread (ptid_t ptid, const td_thrhandle_t *th_p,
                const td_thrinfo_t *ti_p, int verbose)
 {
+  struct private_thread_info *private;
+  struct thread_info *tp = NULL;
+  char *lwpstr = NULL;
   td_err_e err;
 
   /* Add the thread to GDB's thread list.  */
   if (!in_thread_list (ptid))
-    add_thread (ptid);
+  {
+    /* Add thread with info */
+    private = xmalloc(sizeof(struct private_thread_info));
+    gdb_assert(private != NULL);
+    // Thread name is assigned when printed
+    memset(private, 0, sizeof(struct private_thread_info));
+
+    tp = add_thread_with_info(ptid, private);
+    tp->private = private;
+    tp->private_dtor = free_private_thread_info;
+  }
 
   if (ti_p->ti_state == TD_THR_UNKNOWN || ti_p->ti_state == TD_THR_ZOMBIE)
     return;                     /* A zombie thread -- do not attach.  */
@@ -743,7 +784,7 @@ fbsd_thread_wait (struct target_ops *ops
          a non-existing thread to fbsd_thread_resume causes error. However,
          if the exiting thread is the currently selected thread,
          then that is handled later in handle_inferior_event(), and we must
-         not delete the currently selected thread. 
+         not delete the currently selected thread.
       */
       if (!fbsd_thread_alive (ops, inferior_ptid) && !ptid_equal(inferior_ptid, ret))
         {
@@ -781,7 +822,7 @@ fbsd_lwp_fetch_registers (struct target_
   if (ptrace (PT_GETREGS, lwp, (caddr_t) &gregs, 0) == -1)
     error ("Cannot get lwp %d registers: %s\n", lwp, safe_strerror (errno));
   supply_gregset (regcache, &gregs);
-  
+
 #ifdef PT_GETXMMREGS
   if (ptrace (PT_GETXMMREGS, lwp, xmmregs, 0) == 0)
     {
@@ -819,7 +860,7 @@ fbsd_thread_fetch_registers (struct targ
   err = td_ta_map_id2thr_p (thread_agent, GET_THREAD (inferior_ptid), &th);
   if (err != TD_OK)
     error ("Cannot find thread %d: Thread ID=%ld, %s",
-           pid_to_thread_id (inferior_ptid),           
+           pid_to_thread_id (inferior_ptid),
            GET_THREAD (inferior_ptid), thread_db_err_str (err));
 
   err = td_thr_getgregs_p (&th, gregset);
@@ -1051,7 +1092,7 @@ fbsd_thread_alive (struct target_ops *op
     {
       lwp = GET_LWP (ptid);
       bfd_map_over_sections (core_bfd, fbsd_core_check_lwp, &lwp);
-      return (lwp == 0); 
+      return (lwp == 0);
     }
 
   /* check lwp in kernel */
@@ -1091,10 +1132,74 @@ fbsd_thread_find_new_threads (struct tar
     error ("Cannot find new threads: %s", thread_db_err_str (err));
 }
 
+static void
+fbsd_find_lwp_name(long lwpid, struct private_thread_info *info)
+{
+  int error, name[4];
+  unsigned int i;
+  struct kinfo_proc *kipp, *kip;
+  char *lwpstr = info->lwp_name;
+  int pid = inferior_ptid.pid;
+  size_t len = 0;
+
+  name[0] = CTL_KERN;
+  name[1] = KERN_PROC;
+  name[2] = KERN_PROC_PID | KERN_PROC_INC_THREAD;
+  name[3] = pid;
+
+  error = sysctl(name, 4, NULL, &len, NULL, 0);
+  if (error < 0 && errno != ESRCH) {
+      warn("sysctl: kern.proc.pid: %d", pid);
+      return;
+  }
+  if (error < 0)
+    return;
+
+  kip = malloc(len);
+  if (kip == NULL)
+    err(-1, "malloc");
+
+  if (sysctl(name, 4, kip, &len, NULL, 0) < 0) {
+      warn("sysctl: kern.proc.pid: %d", pid);
+      free(kip);
+      return;
+  }
+
+  for (i = 0; i < len / sizeof(*kipp); i++) {
+      kipp = &kip[i];
+      if ((kipp->ki_tid == lwpid) && strlen(kipp->ki_ocomm) &&
+          (strcmp(kipp->ki_comm, kipp->ki_ocomm) != 0))
+        {
+          // Found the LWP, update the name field
+          if (lwpstr != NULL)
+            {
+              if (strcmp(lwpstr, kipp->ki_ocomm) != 0)
+                {
+                  xfree(lwpstr);
+                }
+              else
+                {
+                  // Name hasn't changed, just return
+                  break;
+                }
+            }
+
+          len = strlen(kipp->ki_ocomm);
+          lwpstr = xmalloc(len);
+          strcpy(lwpstr, kipp->ki_ocomm);
+          info->lwp_name = lwpstr;
+          break;
+        }
+  }
+
+  free(kip);
+}
+
 static char *
 fbsd_thread_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char buf[64];
+  struct thread_info *tinfo = NULL;
 
   if (IS_THREAD (ptid))
     {
@@ -1112,10 +1217,25 @@ fbsd_thread_pid_to_str (struct target_op
         error ("Cannot get thread info, Thread ID=%ld, %s",
                GET_THREAD (ptid), thread_db_err_str (err));
 
+      tinfo = find_thread_ptid(ptid);
+      gdb_assert(tinfo != NULL);
+
       if (ti.ti_lid != 0)
         {
-          snprintf (buf, sizeof (buf), "Thread %llx (LWP %d)",
-                    (unsigned long long)th.th_thread, ti.ti_lid);
+          // Need to find the name of this LWP, even though it shouldn't change
+          fbsd_find_lwp_name(ti.ti_lid, tinfo->private);
+
+          if (tinfo->private->lwp_name == NULL)
+            {
+              snprintf(buf, sizeof (buf), "Thread %llx (LWP %d)",
+                  (unsigned long long)th.th_thread, ti.ti_lid);
+            }
+          else
+            {
+              snprintf(buf, sizeof (buf), "Thread %llx (LWP %d %s)",
+                  (unsigned long long)th.th_thread, ti.ti_lid,
+                  tinfo->private->lwp_name);
+            }
         }
       else
         {
@@ -1170,7 +1290,7 @@ static int
 tsd_cb (thread_key_t key, void (*destructor)(void *), void *ignore)
 {
   struct minimal_symbol *ms;
-  char *name;
+  const char *name;
 
   ms = lookup_minimal_symbol_by_pc (extract_func_ptr (&destructor));
   if (!ms)
@@ -1333,7 +1453,7 @@ thread_db_load (void)
   td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg");
   td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable");
   td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr");
-  
+
   return 1;
 }
 
@@ -1514,7 +1634,7 @@ ps_lstop(struct ps_prochandle *ph, lwpid
 {
   if (ptrace (PT_SUSPEND, lwpid, 0, 0) == -1)
     return PS_ERR;
-  return PS_OK;  
+  return PS_OK;
 }
 
 ps_err_e
@@ -1522,7 +1642,7 @@ ps_lcontinue(struct ps_prochandle *ph, l
 {
   if (ptrace (PT_RESUME, lwpid, 0, 0) == -1)
     return PS_ERR;
-  return PS_OK;   
+  return PS_OK;
 }
 
 ps_err_e

Modified: head/devel/gdb/files/patch-gdb-amd64fbsd-nat.c
==============================================================================
--- head/devel/gdb/files/patch-gdb-amd64fbsd-nat.c	Sun Oct 28 21:44:23 2012	(r306580)
+++ head/devel/gdb/files/patch-gdb-amd64fbsd-nat.c	Sun Oct 28 21:50:34 2012	(r306581)
@@ -1,6 +1,12 @@
 --- gdb/amd64fbsd-nat.c.orig	2012-02-09 17:06:44.000000000 +0100
-+++ gdb/amd64fbsd-nat.c	2012-08-22 23:51:38.000000000 +0200
-@@ -26,6 +26,7 @@
++++ gdb/amd64fbsd-nat.c	2012-08-30 10:58:55.000000000 +0200
+@@ -21,11 +21,13 @@
+ #include "inferior.h"
+ #include "regcache.h"
+ #include "target.h"
++#include "gregset.h"
+ 
+ #include "gdb_assert.h"
  #include <signal.h>
  #include <stddef.h>
  #include <sys/types.h>
@@ -8,7 +14,7 @@
  #include <sys/ptrace.h>
  #include <sys/sysctl.h>
  #include <machine/reg.h>
-@@ -93,6 +94,47 @@
+@@ -93,6 +95,46 @@
  };
  
  
@@ -28,7 +34,7 @@
 +   do this for all registers.  */
 +
 +void
-+fill_gregset (struct regcache *regcache, gregset_t *gregsetp, int regnum)
++fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
 +{
 +  amd64_collect_native_gregset (regcache, gregsetp, regnum);
 +}
@@ -47,12 +53,11 @@
 +   do this for all registers.  */
 +
 +void
-+fill_fpregset (struct regcache *regcache, fpregset_t *fpregsetp, int regnum)
++fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
 +{
 +  amd64_collect_fxsave (regcache, regnum, fpregsetp);
 +}
 +
-+
  /* Support for debugging kernel virtual memory images.  */
  
  #include <sys/types.h>

Modified: head/devel/gdb/files/patch-gdb-i386fbsd-nat.c
==============================================================================
--- head/devel/gdb/files/patch-gdb-i386fbsd-nat.c	Sun Oct 28 21:44:23 2012	(r306580)
+++ head/devel/gdb/files/patch-gdb-i386fbsd-nat.c	Sun Oct 28 21:50:34 2012	(r306581)
@@ -1,14 +1,17 @@
---- gdb/i386fbsd-nat.c.orig	2010-01-01 02:31:36.000000000 -0500
-+++ gdb/i386fbsd-nat.c	2010-10-22 13:57:48.705926000 -0400
-@@ -24,6 +24,7 @@
+--- gdb/i386fbsd-nat.c.orig	2012-05-24 18:39:09.000000000 +0200
++++ gdb/i386fbsd-nat.c	2012-08-29 17:19:57.000000000 +0200
+@@ -21,8 +21,10 @@
+ #include "inferior.h"
+ #include "regcache.h"
  #include "target.h"
++#include "gregset.h"
  
  #include <sys/types.h>
 +#include <sys/procfs.h>
  #include <sys/ptrace.h>
  #include <sys/sysctl.h>
  
-@@ -81,6 +82,49 @@
+@@ -80,6 +82,49 @@
  }
  
  
@@ -28,7 +31,7 @@
 +   do this for all registers.  */
 +
 +void
-+fill_gregset (struct regcache *regcache, gregset_t *gregsetp, int regnum)
++fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
 +{
 +  i386bsd_collect_gregset (regcache, gregsetp, regnum);
 +}
@@ -49,7 +52,7 @@
 +   do this for all registers.  */
 +
 +void
-+fill_fpregset (struct regcache *regcache, fpregset_t *fpregsetp, int regnum)
++fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
 +{
 +  i387_collect_fsave (regcache, regnum, fpregsetp);
 +}
@@ -58,7 +61,7 @@
  /* Support for debugging kernel virtual memory images.  */
  
  #include <sys/types.h>
-@@ -141,7 +185,6 @@
+@@ -141,7 +186,6 @@
  #endif /* HAVE_PT_GETDBREGS */
  
  



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