Index: usr.bin/gcore/elfcore.c =================================================================== --- usr.bin/gcore/elfcore.c (revision 214921) +++ usr.bin/gcore/elfcore.c (working copy) @@ -284,6 +284,7 @@ static void elf_puthdr(pid_t pid, vm_map_entry_t map, void *dst, size_t *off, int numsegs) { + struct ptrace_lwpinfo lwpinfo; struct { prstatus_t status; prfpregset_t fpregset; @@ -356,6 +357,9 @@ ptrace(PT_GETREGS, tids[i], (void *)&status->pr_reg, 0); ptrace(PT_GETFPREGS, tids[i], (void *)fpregset, 0); + ptrace(PT_LWPINFO, tids[i], (void *)&lwpinfo, + sizeof(lwpinfo)); + strcpy(status->pr_tname, lwpinfo.pl_tdname); } elf_putnote(dst, off, "FreeBSD", NT_PRSTATUS, status, sizeof *status); Index: gnu/usr.bin/gdb/libgdb/fbsd-threads.c =================================================================== --- gnu/usr.bin/gdb/libgdb/fbsd-threads.c (revision 214921) +++ gnu/usr.bin/gdb/libgdb/fbsd-threads.c (working copy) @@ -426,6 +426,46 @@ init_thread_list (); } +static thrname_t * +fbsd_thread_get_name (lwpid_t lwpid) +{ + static thrname_t last_thr_name; + 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 (name[0] == '\0') + goto fail; + } + last_thr_name[sizeof (last_thr_name) - 1] = '\0'; + return &last_thr_name; +fail: + strcpy (&last_thr_name, ""); + return &last_thr_name; +} + static void fbsd_thread_new_objfile (struct objfile *objfile) { @@ -1158,7 +1198,7 @@ static char * fbsd_thread_pid_to_str (ptid_t ptid) { - static char buf[64]; + static char buf[64 + MAXCOMLEN]; if (IS_THREAD (ptid)) { @@ -1178,8 +1218,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 {