The following is the first of a set of proposed patches for gdb to support the new nptl threading model for linux. In the old linuxthreads model, the lwp was equal to the pid. In the new nptl model, the lwp is unique for each thread and the pid value is common among sibling threads. A side-effect of this difference is that with linuxthreads, you could see individual threads externally on the ps list. With the new nptl kernel, you will not be able to see child thread lwps on the list. Another key difference is how a tid is represented. In the linuxthreads model, a tid was an index into a table and was restricted to 16-bits. In the new nptl model, there is no such restriction on the number of threads and the tid is in fact an address (i.e. not 16 bits). In the current linux-proc.c logic, when performing a gcore command, pr_status note information is created by taking the pid and concatenating this to the tid to form a 32-bit construct. Obviously, in the new nptl model this won't work as the tid itself is either 32-bits or 64-bits. It should also be mentioned that this logic does not match what the kernel spits out in a corefile. For linuxthreads, the kernel is just putting the lwp = pid in the pr_status notes. Logic that works for either model and matches what the kernel is doing is to use the lwp and only the lwp in the pr_status notes. This creates a slight problem because linux-proc.c uses the thread_info list to run through all the threads. Unfortunately, the thread_info list contains ptid_t structs that contain the pid and the tid, but no lwp. In the old linuxthreads model, this isn't a problem because the pid is in fact equal to the lwp. In the nptl model, we can't simply convert a pid/tid combination into its associated lwp because this logic is hidden in libthread_db. At present, the libthread_db library is only loaded by the thread-db layer. While there are routines to convert a tid to lwp and vice-versa, these routines are not externally exposed in the target vector. The only externalized method that could do such a job is to_pid_to_str() which converts to character. Usage of this interface would require parsing the output for the characters "LWP". This patch proposes adding a secondary list of thread_info structs that keeps track of the lwps. This list is kept distinct from the regular thread list. Since manipulating either list involves common operations, some base operations are added for generic thread_info list manipulation. The lin-lwp.c layer is changed to add and delete lwp thread_info structs to the lwp list when lwps are added or deleted. The linux-proc.c code is changed to iterate through the lwp thread_info list rather than the thread list when creating the pr_status notes. I had brought up this idea on the gdb mailing list and there was some discussion about how the thread_info struct should be renamed to something more generic. That issue was not resolved, but I feel that it can be performed distinct from this patch as it will require a global change to many pieces of code. To keep some new names at a reasonable length, I chose to use the name tinfo_list rather than thread_info_list. This would obviously also be renamed. Ok to commit? I have reindented and checked in the three C files involved prior to building this patch. -- Jeff J. 2003-03-28 Jeff Johnston * gdbthread.h (tinfo_list): New struct to represent list of thread_info structs. (get_thread_tinfo_list, get_lwp_tinfo_list): New prototypes. (add_thread_info, delete_thread_info): Ditto. (thread_info_id_to_pid, pid_to_thread_info_id): Ditto. (in_tinfo_list, valid_thread_info_id, find_thread_info_pid): Ditto. (iterate_over_tinfo_list): Ditto. * thread.c (init_thread_list): Clear lwp list as well as thread list. (get_thread_tinfo_list, get_lwp_tinfo_list): New functions to get either the thread or lwp lists respectively. (add_thread_info, delete_thread_info): New generic thread_info functions. (thread_info_id_to_pid, pid_to_thread_info_id): Ditto. (in_tinfo_list, valid_thread_info_id, find_thread_info_pid): Ditto. (iterate_over_tinfo_list): Ditto. * linux-proc.c (linux_do_thread_registers): Store lwp for prstatus note rather than a merge of pid and tid. (linux_make_note_section): Iterate over list of lwps rather than threads to create note data. * lin-lwp.c (add_lwp): Call add_thread_info() to add new lwp ptid to lwp list. (delete_lwp): Call delete_thread_info() to delete lwp ptid from lwp list.