/branches/tracing/uspace/app/debug/dthread.h |
---|
0,0 → 1,58 |
/* |
* Copyright (c) 2008 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup debug |
* @{ |
*/ |
/** @file |
*/ |
#ifndef DTHREAD_H_ |
#define DTHREAD_H_ |
#include <udebug.h> |
#include <libadt/list.h> |
typedef struct { |
int id; /* human-friendly id */ |
thash_t hash; /* system hash */ |
/** Link to list of debugged threads */ |
link_t link; |
} dthread_t; |
extern link_t dthreads; /* List of application's threads */ |
extern dthread_t *cwt; |
dthread_t *dthread_new(thash_t hash); |
void dthread_delete(dthread_t *dthread); |
#endif |
/** @} |
*/ |
/branches/tracing/uspace/app/debug/cmd.c |
---|
41,6 → 41,7 |
#include "main.h" |
#include "cons.h" |
#include "dthread.h" |
#include "include/arch.h" |
#include "cmd.h" |
81,19 → 82,24 |
static void cmd_ct(int argc, char *argv[]) |
{ |
int i; |
int tid; |
link_t *cur; |
dthread_t *dt; |
(void)argc; |
tid = strtoul(argv[1], NULL, 0); |
for (i = 0; i < n_threads; ++i) { |
if (thread_id[i] == tid) break; |
dt = NULL; |
for (cur = dthreads.next; cur != &dthreads; cur = cur->next) { |
dt = list_get_instance(cur, dthread_t, link); |
if (dt->id == tid) break; |
} |
if (thread_id[i] == tid) { |
if (dt->id == tid) { |
cwt = dt; |
cons_printf("changed working thread to: %d [hash 0x%x]\n", |
thread_id[cwt], thread_hash[cwt]); |
cwt->id, cwt->hash); |
} else { |
cons_printf("no such thread\n"); |
} |
171,18 → 177,22 |
void cmd_pwt(int argc, char *argv[]) |
{ |
(void)argc; (void)argv; |
cons_printf("working thread: %d [hash 0x%x]\n", thread_id[cwt], |
thread_hash[cwt]); |
cons_printf("working thread: %d [hash 0x%x]\n", cwt->id, cwt->hash); |
} |
void cmd_threads(int argc, char *argv[]) |
{ |
int i; |
link_t *cur; |
dthread_t *dt; |
(void)argc; (void)argv; |
for (i = 0; i < n_threads; ++i) { |
cons_printf("%d [hash 0x%x]\n", thread_id[i], thread_hash[i]); |
} |
(void)argc; |
dt = NULL; |
for (cur = dthreads.next; cur != &dthreads; cur = cur->next) { |
dt = list_get_instance(cur, dthread_t, link); |
cons_printf("%d [hash 0x%x]\n", dt->id, dt->hash); |
} |
} |
/branches/tracing/uspace/app/debug/main.c |
---|
45,6 → 45,7 |
#include "cmd.h" |
#include "cons.h" |
#include "dthread.h" |
#include "include/arch.h" |
#include "fib_synch.h" |
#include "main.h" |
61,12 → 62,6 |
#define THBUF_SIZE 64 |
thash_t thread_hash_buf[THBUF_SIZE]; |
#define MAX_THREADS 64 |
thash_t thread_hash[MAX_THREADS]; |
int thread_id[MAX_THREADS]; |
unsigned n_threads; |
int cwt; /* index into thread_hash/thread_id */ |
int next_thread_id; |
int app_phone; |
80,7 → 75,7 |
fcv_t go_cv; |
void command_split(char *cmd_str) |
static void command_split(char *cmd_str) |
{ |
char *p = cmd_str; |
101,7 → 96,7 |
} |
} |
void command_run(void) |
static void command_run(void) |
{ |
int i; |
int cmp_len; |
145,7 → 140,7 |
(*cmd_table[idx_found].proc)(cmd_argc, cmd_argv); |
} |
void thread_stop(void) |
static void thread_stop(void) |
{ |
cons_printf("[t] stopped\n"); |
fcv_wait(&go_cv); |
161,7 → 156,7 |
thread_stop(); |
} |
int task_connect(int taskid) |
static int task_connect(int taskid) |
{ |
int rc; |
unsigned evmask; |
186,7 → 181,7 |
return 0; |
} |
int get_thread_list(void) |
static int get_thread_list(void) |
{ |
int rc; |
int tb_copied; |
254,46 → 249,41 |
} |
} |
void debug_loop(void *thread_buf_idx_arg) |
void debug_loop(void *dt_arg) |
{ |
int rc; |
udebug_event_t ev_type; |
unsigned thread_buf_idx; |
thash_t thash; |
int tid; |
unsigned val0, val1; |
dthread_t *dt; |
thread_buf_idx = (unsigned)thread_buf_idx_arg; |
dt = (dthread_t *)dt_arg; |
thash = thread_hash[thread_buf_idx]; |
tid = thread_id[thread_buf_idx]; |
cons_printf("debug_loop(%d)\n", dt->id); |
cons_printf("debug_loop(%d)\n", tid); |
while (!abort_debug) { |
/* Run thread until an event occurs */ |
rc = udebug_go(app_phone, thash, |
&ev_type, &val0, &val1); |
rc = udebug_go(app_phone, dt->hash, &ev_type, &val0, &val1); |
if (ev_type == UDEBUG_EVENT_FINISHED) { |
cons_printf("thread %u debugging finished\n", tid); |
cons_printf("thread %u debugging finished\n", dt->id); |
break; |
} |
if (rc >= 0) debug_event(thash, ev_type, val0); |
} |
cons_printf("debug_loop(%d) exiting\n", thread_id); |
cons_printf("debug_loop(%d) exiting\n", dt->id); |
} |
void thread_debug_start(unsigned thash) |
{ |
fid_t fid; |
dthread_t *dt; |
thread_hash[n_threads] = thash; |
thread_id[n_threads] = next_thread_id++; |
dt = dthread_new(thash); |
fid = fibril_create(debug_loop, (void *)n_threads++); |
fid = fibril_create(debug_loop, (void *)dt); |
if (fid == 0) { |
cons_printf("Warning: Failed creating fibril\n"); |
} |
354,6 → 344,9 |
{ |
next_thread_id = 1; |
paused = 0; |
list_initialize(&dthreads); |
cwt = NULL; |
fcv_init(&go_cv); |
} |
/branches/tracing/uspace/app/debug/main.h |
---|
36,6 → 36,7 |
#define MAIN_H_ |
#include <udebug.h> |
#include <libadt/list.h> |
#include "include/arch/types.h" |
#include "fib_synch.h" |
52,11 → 53,6 |
extern int app_phone; |
extern fcv_t go_cv; |
extern thash_t thread_hash[]; |
extern int thread_id[]; |
extern unsigned n_threads; |
extern int cwt; |
void breakpoint_hit(void); |
/branches/tracing/uspace/app/debug/dthread.c |
---|
0,0 → 1,72 |
/* |
* Copyright (c) 2008 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup debug |
* @{ |
*/ |
/** @file |
*/ |
#include <stdlib.h> |
#include <libadt/list.h> |
#include "dthread.h" |
static int last_thread_id = 0; |
link_t dthreads; /* List of application's threads */ |
dthread_t *cwt; /* Current working thread */ |
dthread_t *dthread_new(thash_t hash) |
{ |
dthread_t *dt; |
dt = malloc(sizeof(dthread_t)); |
if (!dt) { |
exit(1); |
} |
dt->id = ++last_thread_id; |
dt->hash = hash; |
if (!cwt) cwt = dt; |
list_append(&dt->link, &dthreads); |
return dt; |
} |
void dthread_delete(dthread_t *dt) |
{ |
list_remove(&dt->link); |
free(dt); |
} |
/** @} |
*/ |
/branches/tracing/uspace/app/debug/Makefile |
---|
46,6 → 46,7 |
GENERIC_SOURCES = cmd.c \ |
fib_synch.c \ |
cons.c \ |
dthread.c \ |
main.c |
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES))) |