aboutsummaryrefslogtreecommitdiff
path: root/gdb/darwin-nat.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-07-13 12:45:07 -0600
committerTom Tromey <tom@tromey.com>2018-08-02 15:08:44 -0600
commitb5bddbbbbcece5d52115bd3e1299cec2a3b362f0 (patch)
treec199bb0c240fe568d96dc21548bc618c31990912 /gdb/darwin-nat.c
parent8094f49a4dd9679c294e6254e928ea75c229aa95 (diff)
downloadgdb-b5bddbbbbcece5d52115bd3e1299cec2a3b362f0.zip
gdb-b5bddbbbbcece5d52115bd3e1299cec2a3b362f0.tar.gz
gdb-b5bddbbbbcece5d52115bd3e1299cec2a3b362f0.tar.bz2
Check results of get_darwin_inferior
I noticed that the existing kill-detach-inferiors-cmd.exp test was causing gdb to crash on macOS 10.13. The bug was that an inferior that hadn't yet been started would cause get_darwin_inferior to return NULL, and this was not checked. I went through the places calling get_darwin_inferior and added checks where appropriate. This makes the test get a bit further. Not all of these spots are exercised by the test, but they seem safe enough in any case. gdb/ChangeLog 2018-08-02 Tom Tromey <tom@tromey.com> * darwin-nat.c (find_inferior_task_it, darwin_find_thread) (darwin_suspend_inferior, darwin_resume_inferior) (darwin_decode_notify_message, darwin_resume_inferior_threads) (darwin_check_new_threads): Check result of get_darwin_inferior.
Diffstat (limited to 'gdb/darwin-nat.c')
-rw-r--r--gdb/darwin-nat.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index bb46cfb..6d7b80d 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -259,6 +259,9 @@ darwin_check_new_threads (struct inferior *inf)
darwin_inferior *darwin_inf = get_darwin_inferior (inf);
std::vector<darwin_thread_t *> new_thread_vec;
+ if (darwin_inf == nullptr)
+ return;
+
/* Get list of threads. */
kret = task_threads (darwin_inf->task, &thread_list, &new_nbr);
MACH_CHECK_ERROR (kret);
@@ -374,7 +377,7 @@ find_inferior_task_it (struct inferior *inf, void *port_ptr)
{
darwin_inferior *priv = get_darwin_inferior (inf);
- return priv->task == *(task_t *)port_ptr;
+ return priv != nullptr && priv->task == *(task_t *)port_ptr;
}
static int
@@ -403,11 +406,12 @@ darwin_find_thread (struct inferior *inf, thread_t thread)
{
darwin_inferior *priv = get_darwin_inferior (inf);
- for (darwin_thread_t *t : priv->threads)
- {
- if (t->gdb_port == thread)
- return t;
- }
+ if (priv != nullptr)
+ for (darwin_thread_t *t : priv->threads)
+ {
+ if (t->gdb_port == thread)
+ return t;
+ }
return NULL;
}
@@ -419,7 +423,7 @@ darwin_suspend_inferior (struct inferior *inf)
{
darwin_inferior *priv = get_darwin_inferior (inf);
- if (!priv->suspended)
+ if (priv != nullptr && !priv->suspended)
{
kern_return_t kret;
@@ -437,7 +441,7 @@ darwin_resume_inferior (struct inferior *inf)
{
darwin_inferior *priv = get_darwin_inferior (inf);
- if (priv->suspended)
+ if (priv != nullptr && priv->suspended)
{
kern_return_t kret;
@@ -766,11 +770,13 @@ darwin_decode_notify_message (mach_msg_header_t *hdr, struct inferior **pinf)
inf = darwin_find_inferior_by_task (task_port);
*pinf = inf;
- darwin_inferior *priv = get_darwin_inferior (inf);
-
/* Check message destination. */
- if (inf != NULL && hdr->msgh_local_port != priv->notify_port)
- return -4;
+ if (inf != NULL)
+ {
+ darwin_inferior *priv = get_darwin_inferior (inf);
+ if (hdr->msgh_local_port != priv->notify_port)
+ return -4;
+ }
return 0;
}
@@ -882,8 +888,9 @@ darwin_resume_inferior_threads (struct inferior *inf, int step, int nsignal)
{
darwin_inferior *priv = get_darwin_inferior (inf);
- for (darwin_thread_t *thread : priv->threads)
- darwin_resume_thread (inf, thread, step, nsignal);
+ if (priv != nullptr)
+ for (darwin_thread_t *thread : priv->threads)
+ darwin_resume_thread (inf, thread, step, nsignal);
}
struct resume_inferior_threads_param