2005-01-17 Jeff Johnston * linux-nat.c (iterate_over_lwps): Add logic to handle non-threaded applications using this function for watchpoints. (linux_nat_inferior_created): New observer. (_initialize_linux_nat): Register new observer. --- gdb-6.3/gdb/linux-nat.c.fix Mon Jan 17 19:35:43 2005 +++ gdb-6.3/gdb/linux-nat.c Mon Jan 17 19:37:58 2005 @@ -1,6 +1,6 @@ /* GNU/Linux native-dependent code common to multiple platforms. - Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GDB. @@ -802,11 +802,23 @@ iterate_over_lwps (int (*callback) (stru { struct lwp_info *lp, *lpnext; - for (lp = lwp_list; lp; lp = lpnext) + if (lwp_list != NULL) { - lpnext = lp->next; + for (lp = lwp_list; lp; lp = lpnext) + { + lpnext = lp->next; + if ((*callback) (lp, data)) + return lp; + } + } + else + { + /* We are calling iterate_over_lwps for a non-threaded program. + Initialize the lwp list to the inferior's ptid. */ + lp = add_lwp (BUILD_LWP (GET_PID (inferior_ptid), + GET_PID (inferior_ptid))); if ((*callback) (lp, data)) - return lp; + return lp; } return NULL; @@ -3103,6 +3115,17 @@ linux_proc_pending_signals (int pid, sig fclose (procfile); } +/* Observer function for an inferior creation event. This is needed + because if iterate_over_lwps is called for a non-threaded program + to handle watchpoints, the lwp list gets initialized but there is + no corresponding clean-up if the program gets rerun or a new + program is run. */ +static void +linux_nat_inferior_created (struct target_ops *objfile, int from_tty) +{ + init_lwp_list (); +} + void _initialize_linux_nat (void) { @@ -3120,7 +3143,9 @@ Specify any of the following keywords fo stat -- list a bunch of random process info.\n\ status -- list a different bunch of random process info.\n\ all -- list all available /proc info."); - + + observer_attach_inferior_created (linux_nat_inferior_created); + init_linux_nat_ops (); add_target (&linux_nat_ops); thread_db_init (&linux_nat_ops);