From nobody@FreeBSD.org  Wed Oct 10 11:54:15 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id BB7AE70F
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Oct 2012 11:54:15 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 891A38FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Oct 2012 11:54:15 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q9ABsEab091307
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Oct 2012 11:54:14 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q9ABsEwS091306;
	Wed, 10 Oct 2012 11:54:14 GMT
	(envelope-from nobody)
Message-Id: <201210101154.q9ABsEwS091306@red.freebsd.org>
Date: Wed, 10 Oct 2012 11:54:14 GMT
From: Norbert Koch <nkoch@demig.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] devel/gdb: add missing thread names
X-Send-Pr-Version: www-3.1
X-GNATS-Notify: luca.pizzamiglio@gmail.com

>Number:         172572
>Category:       ports
>Synopsis:       [patch] devel/gdb: add missing thread names
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 10 12:00:01 UTC 2012
>Closed-Date:    Sun Oct 28 21:42:49 UTC 2012
>Last-Modified:  Sun Oct 28 21:42:49 UTC 2012
>Originator:     Norbert Koch
>Release:        9.0-RELEASE
>Organization:
>Environment:
>Description:
I have an application that sets thread names using pthread_set_name_np().
Those names are visible using FreeBSD's gdb 6.1.1, but not using
the latest gdb 7.5 from ports.
The required function and its use in fbsd-threads.c are missing
in the port's fbsd-threads.c.patch.

I simply added the function without changes and it seems to work.

Any reason why this is missing in the port? Any known problems?
>How-To-Repeat:

>Fix:
--- gdb.org/Makefile	2012-10-02 08:40:29.000000000 +0200
+++ gdb/Makefile	2012-10-10 13:34:42.000000000 +0200
@@ -7,7 +7,7 @@
 
 PORTNAME=	gdb
 PORTVERSION=	7.5
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	devel
 MASTER_SITES=	GNU
 
--- gdb.org/files/fbsd-threads.c	2012-08-28 09:24:15.000000000 +0200
+++ gdb/files/fbsd-threads.c	2012-10-10 13:34:18.000000000 +0200
@@ -431,6 +431,46 @@
   fbsd_thread_present = 0;
 }
 
+static char * 
+fbsd_thread_get_name (lwpid_t lwpid)
+{
+  static char last_thr_name[MAXCOMLEN + 1];
+  char section_name[32];
+  struct ptrace_lwpinfo lwpinfo;
+  bfd_size_type size;
+  struct bfd_section *section;
+
+  if (target_has_execution)
+    {
+      if (ptrace (PT_LWPINFO, lwpid, (caddr_t)&lwpinfo, sizeof (lwpinfo)) == -1)
+        goto fail;
+      strncpy (last_thr_name, lwpinfo.pl_tdname, sizeof (last_thr_name) - 1);
+    }
+  else
+    {
+      snprintf (section_name, sizeof (section_name), ".tname/%u", lwpid);
+      section = bfd_get_section_by_name (core_bfd, section_name);
+      if (! section)
+        goto fail;
+
+      /* Section size fix-up. */
+      size = bfd_section_size (core_bfd, section);
+      if (size > sizeof (last_thr_name))
+        size = sizeof (last_thr_name);
+
+      if (! bfd_get_section_contents (core_bfd, section, last_thr_name,
+	       (file_ptr)0, size))
+        goto fail;
+      if (last_thr_name[0] == '\0')
+        goto fail;
+    }
+    last_thr_name[sizeof (last_thr_name) - 1] = '\0';
+    return last_thr_name;
+fail:
+     strcpy (last_thr_name, "<unknown>");
+     return last_thr_name;
+}
+
 static void
 check_for_thread_db (void)
 {
@@ -1114,8 +1154,9 @@
 
       if (ti.ti_lid != 0)
         {
-          snprintf (buf, sizeof (buf), "Thread %llx (LWP %d)",
-                    (unsigned long long)th.th_thread, ti.ti_lid);
+          snprintf (buf, sizeof (buf), "Thread %llx (LWP %d/%s)",
+                    (unsigned long long)th.th_thread, ti.ti_lid,
+                    fbsd_thread_get_name (ti.ti_lid));
         }
       else
         {


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: edwin 
State-Changed-When: Wed Oct 10 12:00:14 UTC 2012 
State-Changed-Why:  
Awaiting maintainers feedback (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172572 

From: Edwin Groothuis <edwin@FreeBSD.org>
To: luca.pizzamiglio@gmail.com
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/172572: [patch] devel/gdb: add missing thread names
Date: Wed, 10 Oct 2012 12:00:13 UT

 Maintainer of devel/gdb,
 
 Please note that PR ports/172572 has just been submitted.
 
 If it contains a patch for an upgrade, an enhancement or a bug fix
 you agree on, reply to this email stating that you approve the patch
 and a committer will take care of it.
 
 The full text of the PR can be found at:
     http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/172572
 
 -- 
 Edwin Groothuis via the GNATS Auto Assign Tool
 edwin@FreeBSD.org

From: Luca Pizzamiglio <luca.pizzamiglio@gmail.com>
To: bug-followup@freebsd.org, nkoch@demig.de
Cc:  
Subject: Re: ports/172572: [patch] devel/gdb: add missing thread names
Date: Tue, 16 Oct 2012 17:17:55 +0200

 Hi all!
 
 thread's names will be added in the next patch I'll submit, merging
 other modifications
 I've received another approach to manage thread's names, parsing the
 kinfo_proc structure.
 
 There're some advantages using the ptrace approach?
 
 Thanks for the support
 
 Best regards
 Luca

From: Norbert Koch <nkoch@demig.de>
To: luca.pizzamiglio@gmail.com
Cc: bug-followup@freebsd.org
Subject: Re: ports/172572: [patch] devel/gdb: add missing thread names
Date: Tue, 16 Oct 2012 17:31:21 +0200

 Am 16.10.2012 17:17, schrieb Luca Pizzamiglio:
 > Hi all!
 >
 > thread's names will be added in the next patch I'll submit, merging
 > other modifications
 > I've received another approach to manage thread's names, parsing the
 > kinfo_proc structure.
 >
 > There're some advantages using the ptrace approach?
 >
 > Thanks for the support
 >
 > Best regards
 > Luca
 
 Hi,
 it was a quick&dirty hack to see threads' names.
 I just diff'ed system gdb sources and port gdb sources.
 
 I will appreciate any patch that improves my
 debug experience;-)
 
 Best regards,
 Norbert Koch

From: Luca Pizzamiglio <luca.pizzamiglio@gmail.com>
To: Norbert Koch <nkoch@demig.de>
Cc: bug-followup@freebsd.org
Subject: Re: ports/172572: [patch] devel/gdb: add missing thread names
Date: Tue, 16 Oct 2012 17:47:12 +0200

 In a week or less I should commit a cumulative patch that includes
 several small improves and thread names support.
 Thanks for the clarification and the support
 
 Best regards,
 Luca
 
 On Tue, Oct 16, 2012 at 5:31 PM, Norbert Koch <nkoch@demig.de> wrote:
 > Am 16.10.2012 17:17, schrieb Luca Pizzamiglio:
 >> Hi all!
 >>
 >> thread's names will be added in the next patch I'll submit, merging
 >> other modifications
 >> I've received another approach to manage thread's names, parsing the
 >> kinfo_proc structure.
 >>
 >> There're some advantages using the ptrace approach?
 >>
 >> Thanks for the support
 >>
 >> Best regards
 >> Luca
 >
 > Hi,
 > it was a quick&dirty hack to see threads' names.
 > I just diff'ed system gdb sources and port gdb sources.
 >
 > I will appreciate any patch that improves my
 > debug experience;-)
 >
 > Best regards,
 > Norbert Koch

From: Luca Pizzamiglio <luca.pizzamiglio@gmail.com>
To: bug-followup@freebsd.org, nkoch@demig.de
Cc:  
Subject: Re: ports/172572: [patch] devel/gdb: add missing thread names
Date: Wed, 17 Oct 2012 17:22:35 +0200

 Thread names and some other improvements are added on this PR ports/172828
 that also close this current one.
 
 Best regards
State-Changed-From-To: feedback->closed 
State-Changed-By: rakuco 
State-Changed-When: Sun Oct 28 21:42:45 UTC 2012 
State-Changed-Why:  
Closing since this is part of ports/172828. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172572 
>Unformatted:
