ports/172828: [MAINTAINER] Name thread patch, warning remove and readline option for gdb 7.5
Luca Pizzammiglio
luca.pizzamiglio at gmail.com
Wed Oct 17 15:20:01 UTC 2012
>Number: 172828
>Category: ports
>Synopsis: [MAINTAINER] Name thread patch, warning remove and readline option for gdb 7.5
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: maintainer-update
>Submitter-Id: current-users
>Arrival-Date: Wed Oct 17 15:20:00 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator: Luca Pizzammiglio
>Release: FreeBSD 8.3-STABLE
>Organization:
>Environment:
FreeBSD pizzamig.bally.de 8.3-STABLE FreeBSD 8.3-STABLE #9: Thu Aug 23 16:22:24 CEST 2012 root at pizzamig.xxx.xx:/usr/obj/usr/src/sys/PIZZAMIG i386
>Description:
This is a cumulative update that add and fix several stuff.
* Showing thread names, closing the PR ports/172572. Thanks to Mark Lokowich.
* readline library to use is now an option, closing the PR ports/172077. Thanks to Jan Beich.
* fixed patches to remove compile warning
* cleaned configure arguments to remove compile warning
* cleaned file permission installation when python option is active
* adopting the new Makefile header standard
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
diff -uNr devel/gdb.orig/Makefile devel/gdb/Makefile
--- devel/gdb.orig/Makefile 2012-09-09 15:56:00.000000000 +0200
+++ devel/gdb/Makefile 2012-10-17 16:18:10.000000000 +0200
@@ -1,13 +1,9 @@
-# Ports collection makefile for: GDB
-# Date created: 16 November 2010
-# Whom: Steven Kreuzer <skreuzer at FreeBSD.org>
-#
-# $FreeBSD: ports/devel/gdb/Makefile,v 1.25 2012/09/09 13:56:00 bdrewery Exp $
-#
+# Created by: Steven Kreuzer <skreuzer at FreeBSD.org>
+# $FreeBSD$
PORTNAME= gdb
PORTVERSION= 7.5
-PORTREVISION= 1
+PORTREVISION= 2
CATEGORIES= devel
MASTER_SITES= GNU
@@ -24,13 +20,12 @@
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 +34,14 @@
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 +55,19 @@
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 +106,7 @@
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 +116,10 @@
(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>
diff -uNr devel/gdb.orig/files/fbsd-threads.c devel/gdb/files/fbsd-threads.c
--- devel/gdb.orig/files/fbsd-threads.c 2012-08-24 04:54:50.000000000 +0200
+++ devel/gdb/files/fbsd-threads.c 2012-08-29 17:00:41.000000000 +0200
@@ -1,4 +1,4 @@
-/* $FreeBSD: ports/devel/gdb/files/fbsd-threads.c,v 1.6 2012/08/24 02:54:50 bdrewery Exp $ */
+/* $FreeBSD: ports/devel/gdb/files/fbsd-threads.c,v 1.5 2012/08/03 02:00:58 wxs Exp $ */
/* FreeBSD libthread_db assisted debugging support.
Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
@@ -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 @@
/* 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_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 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 @@
#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 @@
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 @@
}
}
- /* 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 @@
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 @@
push_target(&fbsd_thread_ops);
fbsd_thread_present = 1;
fbsd_thread_activate();
-
+
break;
default:
@@ -631,11 +659,24 @@
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 @@
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 @@
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 @@
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 @@
{
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 @@
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 @@
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 @@
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 @@
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 @@
{
if (ptrace (PT_SUSPEND, lwpid, 0, 0) == -1)
return PS_ERR;
- return PS_OK;
+ return PS_OK;
}
ps_err_e
@@ -1522,7 +1642,7 @@
{
if (ptrace (PT_RESUME, lwpid, 0, 0) == -1)
return PS_ERR;
- return PS_OK;
+ return PS_OK;
}
ps_err_e
diff -uNr devel/gdb.orig/files/patch-gdb-amd64fbsd-nat.c devel/gdb/files/patch-gdb-amd64fbsd-nat.c
--- devel/gdb.orig/files/patch-gdb-amd64fbsd-nat.c 2012-08-24 04:54:50.000000000 +0200
+++ devel/gdb/files/patch-gdb-amd64fbsd-nat.c 2012-08-30 10:59:26.000000000 +0200
@@ -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>
diff -uNr devel/gdb.orig/files/patch-gdb-i386fbsd-nat.c devel/gdb/files/patch-gdb-i386fbsd-nat.c
--- devel/gdb.orig/files/patch-gdb-i386fbsd-nat.c 2010-11-16 21:39:48.000000000 +0100
+++ devel/gdb/files/patch-gdb-i386fbsd-nat.c 2012-08-29 17:22:40.000000000 +0200
@@ -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 */
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list