This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] linux-proc: use lwp instead of merged_pid in gcore files.


Jeff, here's a patch that accomplishes the same thing as yours,
using mostly existing code and data.  I have tested it on old
linux threads, but not on nptl threads.

Daniel, I went with your suggestion for "linux-nat.h", and I
moved one declaration from config/nm-linux.h to the new file.

Michael

2003-06-18  Michael Snyder  <msnyder@redhat.com>

	* linux-nat.h: New file.  Export several definitions.
	* lin-lwp.c: Move struct lin_lwp to linux-nat.h and include it.
	* linux-proc.c: Include linux-nat.h.  
	(linux_make_note_section): Use iterate_over_lwps instead of 
	iterate_over_threads (get lwp ids instead of thread ids).
	(linux_do_thread_registers): Use ptid_get_lwp instead of
	ptid_get_pid and ptid_get_tid.

Index: lin-lwp.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/lin-lwp.c,v
retrieving revision 2.30
diff -p -r2.30 lin-lwp.c
*** lin-lwp.c	2003/06/05 22:08:34	2.30
--- lin-lwp.c	2003/06/19 00:02:16
***************
*** 40,45 ****
--- 40,47 ----
  static int debug_lin_lwp;
  extern char *strsignal (int sig);
  
+ #include "linux-nat.h"
+ 
  /* On GNU/Linux there are no real LWP's.  The closest thing to LWP's
     are processes sharing the same VM space.  A multi-threaded process
     is basically a group of such processes.  However, such a grouping
*************** extern char *strsignal (int sig);
*** 72,114 ****
       When debugged a multi-threaded process that spawns a lot of
       threads will run out of processes, even if the threads exit,
       because the "zombies" stay around.  */
- 
- /* Structure describing a LWP.  */
- struct lwp_info
- {
-   /* The process id of the LWP.  This is a combination of the LWP id
-      and overall process id.  */
-   ptid_t ptid;
- 
-   /* Non-zero if this LWP is cloned.  In this context "cloned" means
-      that the LWP is reporting to its parent using a signal other than
-      SIGCHLD.  */
-   int cloned;
- 
-   /* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report
-      it back yet).  */
-   int signalled;
- 
-   /* Non-zero if this LWP is stopped.  */
-   int stopped;
- 
-   /* Non-zero if this LWP will be/has been resumed.  Note that an LWP
-      can be marked both as stopped and resumed at the same time.  This
-      happens if we try to resume an LWP that has a wait status
-      pending.  We shouldn't let the LWP run until that wait status has
-      been processed, but we should not report that wait status if GDB
-      didn't try to let the LWP run.  */
-   int resumed;
- 
-   /* If non-zero, a pending wait status.  */
-   int status;
- 
-   /* Non-zero if we were stepping this LWP.  */
-   int step;
- 
-   /* Next LWP in list.  */
-   struct lwp_info *next;
- };
  
  /* List of known LWPs.  */
  static struct lwp_info *lwp_list;
--- 74,79 ----
Index: linux-proc.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/linux-proc.c,v
retrieving revision 2.12
diff -p -r2.12 linux-proc.c
*** linux-proc.c	2003/04/16 21:18:47	2.12
--- linux-proc.c	2003/06/19 00:02:16
***************
*** 35,40 ****
--- 35,42 ----
  #include "cli/cli-decode.h"	/* for add_info */
  #include "gdb_string.h"
  
+ #include "linux-nat.h"
+ 
  #ifndef O_LARGEFILE
  #define O_LARGEFILE 0
  #endif
*************** linux_do_thread_registers (bfd *obfd, pt
*** 171,183 ****
  #ifdef FILL_FPXREGSET
    gdb_fpxregset_t fpxregs;
  #endif
!   unsigned long merged_pid = ptid_get_tid (ptid) << 16 | ptid_get_pid (ptid);
  
    fill_gregset (&gregs, -1);
    note_data = (char *) elfcore_write_prstatus (obfd,
  					       note_data,
  					       note_size,
! 					       merged_pid,
  					       stop_signal, &gregs);
  
    fill_fpregset (&fpregs, -1);
--- 173,185 ----
  #ifdef FILL_FPXREGSET
    gdb_fpxregset_t fpxregs;
  #endif
!   unsigned long lwp = ptid_get_lwp (ptid);
  
    fill_gregset (&gregs, -1);
    note_data = (char *) elfcore_write_prstatus (obfd,
  					       note_data,
  					       note_size,
! 					       lwp,
  					       stop_signal, &gregs);
  
    fill_fpregset (&fpregs, -1);
*************** struct linux_corefile_thread_data
*** 210,216 ****
   */
  
  static int
! linux_corefile_thread_callback (struct thread_info *ti, void *data)
  {
    struct linux_corefile_thread_data *args = data;
    ptid_t saved_ptid = inferior_ptid;
--- 212,218 ----
   */
  
  static int
! linux_corefile_thread_callback (struct lwp_info *ti, void *data)
  {
    struct linux_corefile_thread_data *args = data;
    ptid_t saved_ptid = inferior_ptid;
*************** linux_make_note_section (bfd *obfd, int 
*** 268,274 ****
    thread_args.note_data = note_data;
    thread_args.note_size = note_size;
    thread_args.num_notes = 0;
!   iterate_over_threads (linux_corefile_thread_callback, &thread_args);
    if (thread_args.num_notes == 0)
      {
        /* iterate_over_threads didn't come up with any threads;
--- 270,276 ----
    thread_args.note_data = note_data;
    thread_args.note_size = note_size;
    thread_args.num_notes = 0;
!   iterate_over_lwps (linux_corefile_thread_callback, &thread_args);
    if (thread_args.num_notes == 0)
      {
        /* iterate_over_threads didn't come up with any threads;
Index: Makefile.in
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/Makefile.in,v
retrieving revision 1.933
diff -p -r1.933 Makefile.in
*** Makefile.in	2003/06/06 20:57:04	1.933
--- Makefile.in	2003/06/19 00:02:16
*************** kod.o: kod.c $(defs_h) $(command_h) $(gd
*** 1924,1936 ****
  language.o: language.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
  	$(value_h) $(gdbcmd_h) $(expression_h) $(language_h) $(target_h) \
  	$(parser_defs_h) $(jv_lang_h) $(demangle_h)
! lin-lwp.o: lin-lwp.c $(defs_h) $(gdb_assert_h) $(gdb_string_h) $(gdb_wait_h) \
! 	$(gdbthread_h) $(inferior_h) $(target_h) $(regcache_h) $(gdbcmd_h)
  linespec.o: linespec.c $(defs_h) $(symtab_h) $(frame_h) $(command_h) \
  	$(symfile_h) $(objfiles_h) $(demangle_h) $(value_h) $(completer_h) \
  	$(cp_abi_h) $(source_h) $(parser_defs_h) $(block_h) $(objc_lang_h)
  linux-proc.o: linux-proc.c $(defs_h) $(inferior_h) $(regcache_h) \
! 	$(gregset_h) $(gdbcore_h) $(gdbthread_h) $(elf_bfd_h) \
  	$(cli_decode_h) $(gdb_string_h)
  lynx-nat.o: lynx-nat.c $(defs_h) $(frame_h) $(inferior_h) $(target_h) \
  	$(gdbcore_h) $(regcache_h)
--- 1924,1937 ----
  language.o: language.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
  	$(value_h) $(gdbcmd_h) $(expression_h) $(language_h) $(target_h) \
  	$(parser_defs_h) $(jv_lang_h) $(demangle_h)
! lin-lwp.o: lin-lwp.c linux-nat.h $(defs_h) $(gdb_assert_h) $(gdb_string_h) \
! 	$(gdb_wait_h) $(gdbthread_h) $(inferior_h) $(target_h) $(regcache_h) \
! 	$(gdbcmd_h)
  linespec.o: linespec.c $(defs_h) $(symtab_h) $(frame_h) $(command_h) \
  	$(symfile_h) $(objfiles_h) $(demangle_h) $(value_h) $(completer_h) \
  	$(cp_abi_h) $(source_h) $(parser_defs_h) $(block_h) $(objc_lang_h)
  linux-proc.o: linux-proc.c $(defs_h) $(inferior_h) $(regcache_h) \
! 	$(gregset_h) $(gdbcore_h) $(gdbthread_h) $(elf_bfd_h) linux-nat.h \
  	$(cli_decode_h) $(gdb_string_h)
  lynx-nat.o: lynx-nat.c $(defs_h) $(frame_h) $(inferior_h) $(target_h) \
  	$(gdbcore_h) $(regcache_h)
Index: config/nm-linux.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/config/nm-linux.h,v
retrieving revision 1.14
diff -p -r1.14 nm-linux.h
*** nm-linux.h	2003/04/16 21:18:51	1.14
--- nm-linux.h	2003/06/19 00:02:16
*************** extern void lin_thread_get_thread_signal
*** 72,79 ****
  
  /* Override child_pid_to_exec_file in 'inftarg.c'.  */
  #define CHILD_PID_TO_EXEC_FILE
- 
- struct mem_attrib;
- extern int linux_proc_xfer_memory (CORE_ADDR addr, char *myaddr, int len,
- 				   int write, struct mem_attrib *attrib,
- 				   struct target_ops *target);
--- 72,74 ----
Index: linux-nat.h
===================================================================
RCS file: linux-nat.h
diff -N linux-nat.h
0a1,68
> /* Native debugging support for GNU/Linux (LWP layer).
>    Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
> 
>    This file is part of GDB.
> 
>    This program is free software; you can redistribute it and/or modify
>    it under the terms of the GNU General Public License as published by
>    the Free Software Foundation; either version 2 of the License, or
>    (at your option) any later version.
> 
>    This program is distributed in the hope that it will be useful,
>    but WITHOUT ANY WARRANTY; without even the implied warranty of
>    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>    GNU General Public License for more details.
> 
>    You should have received a copy of the GNU General Public License
>    along with this program; if not, write to the Free Software
>    Foundation, Inc., 59 Temple Place - Suite 330,
>    Boston, MA 02111-1307, USA.  */
> 
> /* Structure describing an LWP.  */
> 
> struct lwp_info
> {
>   /* The process id of the LWP.  This is a combination of the LWP id
>      and overall process id.  */
>   ptid_t ptid;
> 
>   /* Non-zero if this LWP is cloned.  In this context "cloned" means
>      that the LWP is reporting to its parent using a signal other than
>      SIGCHLD.  */
>   int cloned;
> 
>   /* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report
>      it back yet).  */
>   int signalled;
> 
>   /* Non-zero if this LWP is stopped.  */
>   int stopped;
> 
>   /* Non-zero if this LWP will be/has been resumed.  Note that an LWP
>      can be marked both as stopped and resumed at the same time.  This
>      happens if we try to resume an LWP that has a wait status
>      pending.  We shouldn't let the LWP run until that wait status has
>      been processed, but we should not report that wait status if GDB
>      didn't try to let the LWP run.  */
>   int resumed;
> 
>   /* If non-zero, a pending wait status.  */
>   int status;
> 
>   /* Non-zero if we were stepping this LWP.  */
>   int step;
> 
>   /* Next LWP in list.  */
>   struct lwp_info *next;
> };
> 
> /* Read/write to target memory via Linux's "proc file system".  */
> struct mem_attrib;
> extern int linux_proc_xfer_memory (CORE_ADDR addr, char *myaddr, int len,
> 				   int write, struct mem_attrib *attrib,
> 				   struct target_ops *target);
> 
> /* Iterator function for lin-lwp's lwp list.  */
> struct lwp_info *iterate_over_lwps (int (*callback) (struct lwp_info *, 
> 						     void *), 
> 				    void *data);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]