/branches/tracing/uspace/app/debug/dthread.h |
---|
36,11 → 36,14 |
#define DTHREAD_H_ |
#include <udebug.h> |
#include <fibril.h> |
#include <libadt/list.h> |
typedef struct { |
int id; /* human-friendly id */ |
thash_t hash; /* system hash */ |
fid_t fid; /* id of servicing fibril */ |
int stopped; |
/** Link to list of debugged threads */ |
link_t link; |
51,7 → 54,12 |
dthread_t *dthread_new(thash_t hash); |
void dthread_delete(dthread_t *dthread); |
dthread_t *dthread_get_by_fid(fid_t fid); |
dthread_t *dthread_get(void); |
void dthread_stop_me(void); |
void dthread_resume(dthread_t *dt); |
#endif |
/** @} |
/branches/tracing/uspace/app/debug/cmd.c |
---|
48,10 → 48,11 |
static void cmd_break(int argc, char *argv[]); |
static void cmd_ct(int argc, char *argv[]); |
static void cmd_go(int argc, char *argv[]); |
static void cmd_istep(int argc, char *argv[]); |
void cmd_help(int argc, char *argv[]); |
static void cmd_pwt(int argc, char *argv[]); |
static void cmd_read(int argc, char *argv[]); |
static void cmd_step(int argc, char *argv[]); |
static void cmd_stop(int argc, char *argv[]); |
static void cmd_threads(int argc, char *argv[]); |
static void cmd_quit(int argc, char *argv[]); |
64,6 → 65,8 |
{ 0, "help", cmd_help }, |
{ 0, "pwt", cmd_pwt }, |
{ 2, "read", cmd_read }, |
{ 0 , "stop", cmd_stop }, |
{ 0, "istep", cmd_istep }, |
{ 0, "threads", cmd_threads }, |
{ 0, "quit", cmd_quit }, |
{ -1, NULL, NULL } |
108,7 → 111,16 |
void cmd_go(int argc, char *argv[]) |
{ |
fcv_broadcast(&go_cv); |
link_t *cur; |
dthread_t *dt; |
(void)argc; (void)argv; |
dt = NULL; |
for (cur = dthreads.next; cur != &dthreads; cur = cur->next) { |
dt = list_get_instance(cur, dthread_t, link); |
dthread_resume(dt); |
} |
} |
void cmd_help(int argc, char *argv[]) |
123,6 → 135,19 |
} |
} |
void cmd_istep(int argc, char *argv[]) |
{ |
(void)argc; (void)argv; |
/*TODO*/ |
} |
void cmd_pwt(int argc, char *argv[]) |
{ |
(void)argc; (void)argv; |
cons_printf("working thread: %d [hash 0x%x]\n", cwt->id, cwt->hash); |
} |
#define BYTES_PER_LINE 16 |
static void cmd_read(int argc, char *argv[]) |
169,18 → 194,29 |
} |
} |
void cmd_step(int argc, char *argv[]) |
void cmd_stop(int argc, char *argv[]) |
{ |
fcv_broadcast(&go_cv); |
} |
link_t *cur; |
dthread_t *dt; |
int rc; |
void cmd_pwt(int argc, char *argv[]) |
{ |
(void)argc; (void)argv; |
cons_printf("working thread: %d [hash 0x%x]\n", cwt->id, cwt->hash); |
dt = NULL; |
for (cur = dthreads.next; cur != &dthreads; cur = cur->next) { |
dt = list_get_instance(cur, dthread_t, link); |
if (!dt->stopped) { |
rc = udebug_stop(app_phone, dt->hash); |
if (rc < 0) { |
printf("failed halting thread %d\n", dt->id); |
} |
} |
} |
} |
void cmd_threads(int argc, char *argv[]) |
{ |
link_t *cur; |
/branches/tracing/uspace/app/debug/main.c |
---|
67,7 → 67,6 |
int app_phone; |
volatile bool abort_debug; |
thash_t thash; |
volatile int paused; |
breakpoint_t brk_list[MAX_BRKPTS]; |
142,9 → 141,12 |
static void thread_stop(void) |
{ |
cons_printf("[t] stopped\n"); |
fcv_wait(&go_cv); |
cons_printf("[t] go\n"); |
dthread_t *dt; |
dt = dthread_get(); |
cons_printf("[thread %d] stopped\n", dt->id); |
dthread_stop_me(); |
cons_printf("[thread %d] go\n", dt->id); |
} |
/* |
222,13 → 224,7 |
switch (ev_type) { |
case UDEBUG_EVENT_STOP: |
cons_printf("stop event\n"); |
cons_printf("waiting for resume\n"); |
while (paused) { |
usleep(1000000); |
fibril_yield(); |
cons_printf("."); |
} |
cons_printf("resumed\n"); |
thread_stop(); |
break; |
case UDEBUG_EVENT_THREAD_B: |
event_thread_b(val0); |
270,7 → 266,7 |
cons_printf("thread %u debugging finished\n", dt->id); |
break; |
} |
if (rc >= 0) debug_event(thash, ev_type, val0); |
if (rc >= 0) debug_event(dt->hash, ev_type, val0); |
} |
cons_printf("debug_loop(%d) exiting\n", dt->id); |
287,6 → 283,8 |
if (fid == 0) { |
cons_printf("Warning: Failed creating fibril\n"); |
} |
dt->fid = fid; |
fibril_add_ready(fid); |
} |
/branches/tracing/uspace/app/debug/dthread.c |
---|
34,6 → 34,9 |
#include <stdlib.h> |
#include <libadt/list.h> |
#include <assert.h> |
#include <futex.h> |
#include <async.h> |
#include "dthread.h" |
53,6 → 56,8 |
dt->id = ++last_thread_id; |
dt->hash = hash; |
dt->fid = 0; |
dt->stopped = 0; |
if (!cwt) cwt = dt; |
67,6 → 72,59 |
free(dt); |
} |
/* |
* Get dthread struct serviced by fibril fid. |
*/ |
dthread_t *dthread_get_by_fid(fid_t fid) |
{ |
link_t *cur; |
dthread_t *dt; |
dt = NULL; |
for (cur = dthreads.next; cur != &dthreads; cur = cur->next) { |
dt = list_get_instance(cur, dthread_t, link); |
if (dt->fid == fid) return dt; |
} |
return NULL; |
} |
/* |
* Get dthread struct for dthread serviced by the current fibril. |
*/ |
dthread_t *dthread_get(void) |
{ |
return dthread_get_by_fid(fibril_get_id()); |
} |
void dthread_stop_me(void) |
{ |
dthread_t *dt; |
int i; |
dt = dthread_get(); |
assert(dt); |
futex_down(&async_futex); |
dt->stopped = 1; |
fibril_switch(FIBRIL_TO_MANAGER); |
futex_up(&async_futex); |
} |
void dthread_resume(dthread_t *dt) |
{ |
if (!dt->stopped) return; |
futex_down(&async_futex); |
fibril_add_ready(dt->fid); |
dt->stopped = 0; |
futex_up(&async_futex); |
} |
/** @} |
*/ |