Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2939 → Rev 2940

/branches/tracing/uspace/app/debug/main.c
59,8 → 59,6
int cmd_argc;
char *cmd_argv[MAX_ARGC + 1]; /* need one spare field for cmd_split() */
 
#define THBUF_SIZE 64
thash_t thread_hash_buf[THBUF_SIZE];
 
int next_thread_id;
 
142,9 → 140,11
static void thread_stop(void)
{
dthread_t *dt;
uintptr_t pc;
 
dt = dthread_get();
cons_printf("[thread %d] stopped\n", dt->id);
pc = dthread_get_pc(dt);
cons_printf("[thread %d] stopped at 0x%lx\n", dt->id, pc);
dthread_stop_me();
cons_printf("[thread %d] go\n", dt->id);
}
183,29 → 183,58
return 0;
}
 
static int get_thread_list(void)
#define THASH_BUF_INIT_LENGTH 32
 
static int get_thread_list(thash_t **thash_buf_ptr, int *n)
{
int rc;
int tb_copied;
int tb_needed;
int i;
int n;
size_t tb_size;
thash_t *thash_buf;
 
cons_printf("send IPC_M_DEBUG_THREAD_READ message\n");
rc = udebug_thread_read(app_phone, (unsigned)thread_hash_buf,
THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed);
cons_printf("-> %d\n", rc);
tb_size = THASH_BUF_INIT_LENGTH * sizeof(thash_t);
thash_buf = malloc(tb_size);
 
rc = udebug_thread_read(app_phone, (sysarg_t)thash_buf,
tb_size, &tb_copied, &tb_needed);
if (rc < 0) return rc;
 
n = tb_copied / sizeof(unsigned);
if (tb_needed > tb_size) {
/* Larger buffer needed */
 
cons_printf("thread IDs:");
for (i=0; i<n; i++) {
cons_printf(" %u", thread_hash_buf[i]);
free(thash_buf);
 
tb_size = tb_needed;
thash_buf = malloc(tb_size);
 
if (!thash_buf) {
printf("malloc failed\n");
exit(1);
}
 
/* Try again */
rc = udebug_thread_read(app_phone, (sysarg_t)thash_buf,
tb_size, &tb_copied, &tb_needed);
 
if (rc < 0) return rc;
}
cons_printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned));
 
return n;
*n = tb_copied / sizeof(thash_t);
 
cons_printf("thread hashes:");
 
for (i = 0; i < *n; ++i) {
cons_printf("0x%x\n", thash_buf[i]);
}
 
cons_printf("Total of %u threads\n", *n);
 
*thash_buf_ptr = thash_buf;
 
return 0;
}
 
void event_thread_b(unsigned hash)
295,6 → 324,9
int rc;
int c;
 
thash_t *thash_buffer;
int n_threads;
 
cons_printf("Breakpoint Debugger\n");
cons_printf("Press 'c' to connect\n");
while ((i = getchar()) != 'c')
309,16 → 341,16
 
cons_printf("Connected to task %d\n", taskid);
 
rc = get_thread_list();
rc = get_thread_list(&thash_buffer, &n_threads);
if (rc < 0) {
cons_printf("Failed to get thread list (error %d)\n", rc);
cons_printf("Failed to get thread list\n", rc);
return;
}
 
abort_debug = false;
 
for (i = 0; i < rc; i++) {
thread_debug_start(thread_hash_buf[i]);
for (i = 0; i < n_threads; i++) {
thread_debug_start(thash_buffer[i]);
}
 
while (!quit) {