ports/172572: [patch] devel/gdb: add missing thread names

Norbert Koch nkoch at demig.de
Wed Oct 10 12:00:02 UTC 2012


>Number:         172572
>Category:       ports
>Synopsis:       [patch] devel/gdb: add missing thread names
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 10 12:00:01 UTC 2012
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:


More information about the freebsd-ports-bugs mailing list