Bug 8210 - Linux core files should use linux-thread-db.c
Summary: Linux core files should use linux-thread-db.c
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: corefiles (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: 7.3
Assignee: Pedro Alves
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-02 03:18 UTC by ac131313
Modified: 2017-11-07 21:48 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ac131313 2003-03-02 03:18:00 UTC
[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
Comment 1 Jan Kratochvil 2010-04-25 13:59:04 UTC
Discussed now at:
pthread_t ids of threads not showed by "thread info"
http://sourceware.org/ml/gdb/2010-04/msg00079.html
Comment 2 Pedro Alves 2010-08-06 14:34:10 UTC
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.
Comment 4 Sourceware Commits 2010-08-18 12:24:33 UTC
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

Comment 5 Sourceware Commits 2010-08-18 12:26:01 UTC
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

Comment 6 Pedro Alves 2010-08-18 12:34:32 UTC
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.
Comment 7 Pedro Alves 2010-08-18 12:37:42 UTC
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.  :-)
Comment 8 Maciej W. Rozycki 2017-11-07 21:48:15 UTC
And the cross debug case is now PR threads/22381.