This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: Updated patch for Bug 13217 - thread apply all detach throws a SEGFAULT
- From: Tom Tromey <tromey at redhat dot com>
- To: ali_anwar <ali_anwar at codesourcery dot com>
- Cc: Pedro Alves <palves at redhat dot com>, <gdb-patches at sourceware dot org>
- Date: Wed, 10 Jul 2013 11:55:46 -0600
- Subject: Re: Updated patch for Bug 13217 - thread apply all detach throws a SEGFAULT
- References: <5062EA9B dot 1060505 at codesourcery dot com> <871uhnwkf3 dot fsf at fleche dot redhat dot com> <50C62BBB dot 6010404 at codesourcery dot com> <87hantek1p dot fsf at fleche dot redhat dot com> <50C75319 dot 9080903 at codesourcery dot com> <50C7628F dot 5080004 at redhat dot com> <51DD37FA dot 8010306 at codesourcery dot com>
>>>>> "Ali" == ali anwar <ali_anwar@codesourcery.com> writes:
Ali> + /* Save a copy of the thread_list in case we execute detach
Ali> + command. */
Ali> + tp_array = xmalloc (sizeof (struct thread_info*) * tc);
Extra space after the "=". Missing space before the "*" in the type
name.
Ali> + ta_cleanup.tp_array = tp_array;
Ali> + ta_cleanup.count = tc;
Ali> +
Ali> + ALL_THREADS (tp)
Ali> + {
Ali> + tp_array[i] = tp;
Ali> + tp->refcount++;
Ali> + i++;
Ali> + }
Ali> + for (k = 0; k != i; k++)
Ali> + if (thread_alive (tp_array[k]))
Ali> + {
Ali> + switch_to_thread (tp_array[k]->ptid);
Ali> + printf_filtered (_("\nThread %d (%s):\n"),
Ali> + tp_array[k]->num, target_pid_to_str (inferior_ptid));
Ali> + execute_command (cmd, from_tty);
Ali> + strcpy (cmd, saved_cmd); /* Restore exact command used
Ali> + previously. */
Ali> + }
Ali> +
Ali> + make_cleanup (xfree, tp_array);
Ali> + make_cleanup (make_cleanup_thread_refcount, &ta_cleanup);
This installs the cleanups at the wrong point.
They must be installed before any potential exception is thrown.
That is, the xfree cleanup ought to be created just after initialization;
and the refcount cleanup ought to be created after the refcounts are
incremented.
Also, make_cleanup_thread_refcount is misnamed.
By convention, a "make_cleanup_" function creates a new cleanup.
The function that does the work of cleaning up is given a different name.
Tom