Commit 2662aad7 authored by Russ Cox's avatar Russ Cox

libmach_amd64: refresh darwin thread list each time we get asked.

R=r
DELTA=1  (1 added, 0 deleted, 0 changed)
OCL=15982
CL=15993
parent 72154b04
...@@ -139,7 +139,7 @@ static int ...@@ -139,7 +139,7 @@ static int
me(kern_return_t r) me(kern_return_t r)
{ {
int i; int i;
if(r == 0) if(r == 0)
return 0; return 0;
...@@ -217,7 +217,7 @@ addpid(int pid, int force) ...@@ -217,7 +217,7 @@ addpid(int pid, int force)
pthread_cond_init(&cond, nil); pthread_cond_init(&cond, nil);
first = 0; first = 0;
} }
if(!force){ if(!force){
for(i=0; i<nthr; i++) for(i=0; i<nthr; i++)
if(thr[i].pid == pid) if(thr[i].pid == pid)
...@@ -269,7 +269,7 @@ idtotable(int id) ...@@ -269,7 +269,7 @@ idtotable(int id)
{ {
if(id >= 0) if(id >= 0)
return addpid(id, 1); return addpid(id, 1);
id = -(id+1); id = -(id+1);
if(id >= nthr) if(id >= nthr)
return nil; return nil;
...@@ -280,7 +280,7 @@ static int ...@@ -280,7 +280,7 @@ static int
idtopid(int id) idtopid(int id)
{ {
Thread *t; Thread *t;
if((t = idtotable(id)) == nil) if((t = idtotable(id)) == nil)
return -1; return -1;
return t->pid; return t->pid;
...@@ -290,7 +290,7 @@ static mach_port_t ...@@ -290,7 +290,7 @@ static mach_port_t
idtotask(int id) idtotask(int id)
{ {
Thread *t; Thread *t;
if((t = idtotable(id)) == nil) if((t = idtotable(id)) == nil)
return -1; return -1;
return t->task; return t->task;
...@@ -300,7 +300,7 @@ static mach_port_t ...@@ -300,7 +300,7 @@ static mach_port_t
idtothread(int id) idtothread(int id)
{ {
Thread *t; Thread *t;
if((t = idtotable(id)) == nil) if((t = idtotable(id)) == nil)
return -1; return -1;
return t->thread; return t->thread;
...@@ -338,11 +338,12 @@ procthreadpids(int id, int **thread) ...@@ -338,11 +338,12 @@ procthreadpids(int id, int **thread)
Thread *t; Thread *t;
int i, n, pid; int i, n, pid;
int *out; int *out;
t = idtotable(id); t = idtotable(id);
if(t == nil) if(t == nil)
return -1; return -1;
pid = t->pid; pid = t->pid;
addpid(pid, 1); // force refresh of thread list
n = 0; n = 0;
for(i=0; i<nthr; i++) for(i=0; i<nthr; i++)
if(thr[i].pid == pid) if(thr[i].pid == pid)
...@@ -390,7 +391,7 @@ machsegrw(Map *map, Seg *seg, uvlong addr, void *v, uint n, int isr) ...@@ -390,7 +391,7 @@ machsegrw(Map *map, Seg *seg, uvlong addr, void *v, uint n, int isr)
uintptr nn; uintptr nn;
mach_port_t task; mach_port_t task;
int r; int r;
task = idtotask(map->pid); task = idtotask(map->pid);
if(task == -1) if(task == -1)
return -1; return -1;
...@@ -493,7 +494,7 @@ machregrw(Map *map, Seg *seg, uvlong addr, void *v, uint n, int isr) ...@@ -493,7 +494,7 @@ machregrw(Map *map, Seg *seg, uvlong addr, void *v, uint n, int isr)
werrstr("no such id"); werrstr("no such id");
return -1; return -1;
} }
if((reg = go2darwin(addr)) < 0 || reg+n > sizeof u){ if((reg = go2darwin(addr)) < 0 || reg+n > sizeof u){
if(isr){ if(isr){
memset(v, 0, n); memset(v, 0, n);
...@@ -526,7 +527,7 @@ machregrw(Map *map, Seg *seg, uvlong addr, void *v, uint n, int isr) ...@@ -526,7 +527,7 @@ machregrw(Map *map, Seg *seg, uvlong addr, void *v, uint n, int isr)
werrstr("thread_set_state: %r"); werrstr("thread_set_state: %r");
return -1; return -1;
} }
if(me(thread_resume(thread)) < 0){ if(me(thread_resume(thread)) < 0){
werrstr("thread_resume: %r"); werrstr("thread_resume: %r");
return -1; return -1;
...@@ -583,7 +584,7 @@ threadstart(Thread *t, int singlestep) ...@@ -583,7 +584,7 @@ threadstart(Thread *t, int singlestep)
(thread_state_t)&regs, (thread_state_t)&regs,
x86_THREAD_STATE64_COUNT)) < 0) x86_THREAD_STATE64_COUNT)) < 0)
return -1; return -1;
// Run. // Run.
n = sizeof info; n = sizeof info;
if(me(thread_info(t->thread, THREAD_BASIC_INFO, (thread_info_t)&info, &n)) < 0) if(me(thread_info(t->thread, THREAD_BASIC_INFO, (thread_info_t)&info, &n)) < 0)
...@@ -630,12 +631,12 @@ havet: ...@@ -630,12 +631,12 @@ havet:
if(ncode > nelem(t->code)) if(ncode > nelem(t->code))
ncode = nelem(t->code); ncode = nelem(t->code);
memmove(t->code, code, ncode*sizeof t->code[0]); memmove(t->code, code, ncode*sizeof t->code[0]);
// Synchronize with waitstop below. // Synchronize with waitstop below.
pthread_mutex_lock(&mu); pthread_mutex_lock(&mu);
pthread_cond_broadcast(&cond); pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mu); pthread_mutex_unlock(&mu);
// Suspend thread, so that we can look at it & restart it later. // Suspend thread, so that we can look at it & restart it later.
if(me(thread_suspend(thread)) < 0) if(me(thread_suspend(thread)) < 0)
fprint(2, "catch_exception_raise thread_suspend: %r\n"); fprint(2, "catch_exception_raise thread_suspend: %r\n");
...@@ -732,10 +733,10 @@ ctlproc(int id, char *msg) ...@@ -732,10 +733,10 @@ ctlproc(int id, char *msg)
return -1; return -1;
return waitstop(t); return waitstop(t);
} }
if(strcmp(msg, "waitstop") == 0) if(strcmp(msg, "waitstop") == 0)
return waitstop(t); return waitstop(t);
// sysstop not available on OS X // sysstop not available on OS X
werrstr("unknown control message"); werrstr("unknown control message");
...@@ -746,13 +747,13 @@ char* ...@@ -746,13 +747,13 @@ char*
procstatus(int id) procstatus(int id)
{ {
Thread *t; Thread *t;
if((t = idtotable(id)) == nil) if((t = idtotable(id)) == nil)
return "gone!"; return "gone!";
if(threadstopped(t)) if(threadstopped(t))
return "Stopped"; return "Stopped";
return "Running"; return "Running";
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment