[Converted from Gnats 1105] (notes from a hallway conversation, this needs to be tested) When using GDB on a live threaded program that puts all threads into tight infinite loops (while (1);), I'll do something like: $ ./a.out & Pid 1234 $ gdb ./a.out 1234 (gdb) info threads .... (gdb) quit As a user I'd also expect sequences such as: $ kill -QUIT 1234 $ gdb ./a.out core (gdb) info threads .... (gdb) quit and: $ gcore 1234 $ gdb ./a.out core (gdb) info threads .... (gdb) quit and: $ gdb ./a.out 1234 (gdb) gcore (gdb) quit $ gdb ./a.out core (gdb) info threads to all come back with effectively the same output. Further, on both live and corefile targets, I'd expect to be able to select/examine each thread vis: (gdb) thread 5 11 i = i + 1; (gdb) list 10 __thread__ i = 1; 11 i = i + 1; (gdb) print i $1 = 1 (which would involve thread local storage). Release: unknown
Discussed now at: pthread_t ids of threads not showed by "thread info" http://sourceware.org/ml/gdb/2010-04/msg00079.html
I played with this last weekend, wrote couple of patches, and got it working. I needed to tweak bfd to make it possible to get at the pid of the core (well, the pid of the process core was dumped from), as libthread_db nowadays ignores threads whose process id doesn't match ps_getpid, and gdb is currently using the fake pid of 1 on linux cores, which obviously doesn't match. I'll post the patches soon.
Patches posted: bfd: <http://sourceware.org/ml/binutils/2010-08/msg00164.html> gdb: <http://sourceware.org/ml/gdb-patches/2010-08/msg00207.html> gdb: <http://sourceware.org/ml/gdb-patches/2010-08/msg00208.html>
Subject: Bug 8210 CVSROOT: /cvs/src Module name: src Changes by: palves@sourceware.org 2010-08-18 12:24:13 Modified files: gdb : ChangeLog amd64-sol2-tdep.c corelow.c gdbarch.c gdbarch.h gdbarch.sh i386-sol2-tdep.c sparc-sol2-tdep.c sparc64-sol2-tdep.c Log message: 2010-08-18 Pedro Alves <pedro@codesourcery.com> PR corefile/8210 bfd/ * bfd-in2.h: Regenerate. * corefile.c (bfd_core_file_pid): New. * targets.c (BFD_JUMP_TABLE_CORE): Add NAME##_core_file_pid. (struct bfd_target) <_core_file_pid>: New. * libbfd-in.h (_bfd_nocore_core_file_pid): Declare. * libbfd.c (_bfd_nocore_core_file_pid): New. * elf-bfd.h (bfd_elf32_core_file_pid, bfd_elf64_core_file_pid): Declare. * elfcode.h (elf_core_file_pid): New define. * elfcore.h (elf_core_file_pid): New function. * elf.c (elfcore_make_pid): Rewrite. (elfcore_grok_prstatus): Only set core_pid if not set yet. (elfcore_grok_prstatus) [!HAVE_PRSTATUS_T_PR_WHO]: Fallback to getting the lwpid from prstat.pr_pid. * elf64-x86-64.c (elf64_x86_64_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. (elf64_x86_64_grok_psinfo): Extract the the main process's PID, and store it in elf_tdata's core_pid field. * elf32-i386.c (elf_i386_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. (elf_i386_grok_psinfo): Extract the the main process's PID, and store it in elf_tdata's core_pid field. * elf32-am33lin.c (elf32_am33lin_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-arm.c (elf32_arm_nabi_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-cris.c (cris_elf_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-frv.c (elf32_frv_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-hppa.c (elf32_hppa_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-mips.c (elf32_mips_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-ppc.c (ppc_elf_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-s390.c (elf_s390_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-score.c (s3_bfd_score_elf_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-score7.c (s7_bfd_score_elf_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-sh.c (elf32_shlin_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf32-xtensa.c (elf_xtensa_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf64-hppa.c (elf64_hppa_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf64-mips.c (elf64_mips_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elf64-ppc.c (ppc64_elf_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * elfn32-mips.c (elf32_mips_grok_prstatus): Write the LWPID to elf_tdata's core_lwpid instead of to core_pid. * plugin.c (bfd_plugin_core_file_pid): New function. * aout-target.h (MY_core_file_pid): Define. * aout-tic30.c (MY_core_file_pid, MY_core_file_p): New defines. * coff-rs6000.c (coff_core_file_pid): New define. (rs6000coff_vec, pmac_xcoff_vec): Use BFD_JUMP_TABLE_CORE. * coff64-rs6000.c (coff_core_file_pid): New define. (rs6000coff64_vec): Use BFD_JUMP_TABLE_CORE. (xcoff64_core_file_pid): New define. (aix5coff64_vec): Use BFD_JUMP_TABLE_CORE. * mach-o-target.c (bfd_mach_o_core_file_pid): New define. * aix386-core.c (aix386_core_file_pid): New define. * hppabsd-core.c (hppabsd_core_core_file_pid): New define. * hpux-core.c (hpux_core_core_file_pid): New define. * irix-core.c (irix_core_core_file_pid): New define. * lynx-core.c (lynx_core_file_pid): New define. * osf-core.c (osf_core_core_file_pid): New define. * ptrace-core.c (ptrace_unix_core_file_pid): New define. * sco5-core.c (sco5_core_file_pid): New define. * xcoff-target.h (coff_core_file_pid): New define. * netbsd-core.c (netbsd_core_core_file_pid): New define. gdb/ 2010-08-18 Pedro Alves <pedro@codesourcery.com> PR corefile/8210 gdb/ * corelow.c (add_to_thread_list): Don't use gdbarch_core_reg_section_encodes_pid. Use bfd_core_file_pid. (get_core_register_section): Don't use gdbarch_core_reg_section_encodes_pid. * gdbarch.sh (core_reg_section_encodes_pid): Delete. * gdbarch.h, gdbarch.c: Regenerate. * amd64-sol2-tdep.c (amd64_sol2_init_abi): Don't set gdbarch_core_reg_section_encodes_pid. * i386-sol2-tdep.c (i386_sol2_init_abi): Ditto. * sparc-sol2-tdep.c (sparc32_sol2_init_abi): Ditto. * sparc64-sol2-tdep.c (sparc64_sol2_init_abi): Ditto. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.12092&r2=1.12093 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/amd64-sol2-tdep.c.diff?cvsroot=src&r1=1.11&r2=1.12 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/corelow.c.diff?cvsroot=src&r1=1.102&r2=1.103 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbarch.c.diff?cvsroot=src&r1=1.470&r2=1.471 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbarch.h.diff?cvsroot=src&r1=1.419&r2=1.420 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbarch.sh.diff?cvsroot=src&r1=1.515&r2=1.516 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/i386-sol2-tdep.c.diff?cvsroot=src&r1=1.29&r2=1.30 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/sparc-sol2-tdep.c.diff?cvsroot=src&r1=1.21&r2=1.22 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/sparc64-sol2-tdep.c.diff?cvsroot=src&r1=1.20&r2=1.21
Subject: Bug 8210 CVSROOT: /cvs/src Module name: src Changes by: palves@sourceware.org 2010-08-18 12:25:49 Modified files: gdb : ChangeLog linux-thread-db.c Log message: PR corefile/8210 * linux-thread-db.c (add_thread_db_info): Skip glibc/BZ5983 workaround on core files. (try_thread_db_load_1): Don't try enabling thread event reporting on core files. (thread_db_load): Allow thread_db on core files. (attach_thread): Don't check thread signals on core files, nor try really attaching to the thread, nor enabling thread event event reporting. (thread_db_detach): Don't try disabing thread event reporting or removing thread event breakpoints when debugging a core file. (find_new_threads_callback): Don't try enabling thread event reporting on core files. (thread_db_find_new_threads_2): Don't look for a stopped lwp when debugging a core file. (thread_db_find_new_threads): Don't update thread cores (processors) when debugging a core (dump). Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.12093&r2=1.12094 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/linux-thread-db.c.diff?cvsroot=src&r1=1.76&r2=1.77
Patches applied. Note that this will only work on native linux GDBs. Getting this to work on cross linux builds will be harder to fix, as linux-thread-db.c is only built native, due to its entanglement with linux-nat.c. I think that can be considered a separate PR, so I'm closing this one.
Oh, dear me, I almost forgot: continuing on the comment above, supporting thread_db for cross debugging would also mean that we'd need to have available a libthread_db.so that is built for the host architecture so that GDB can load it, but that understands the _target_ architecture's glibc. (This is also the reason why we have gdbserver itself load libthread_db, not gdb, when remote debugging). So, I'm definitely closing this harder. :-)
And the cross debug case is now PR threads/22381.