Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2936 → Rev 2935

/branches/tracing/uspace/app/debug/cons.h
File deleted
/branches/tracing/uspace/app/debug/cons.c
File deleted
/branches/tracing/uspace/app/debug/cmd.c
40,7 → 40,6
#include <sys/types.h>
 
#include "main.h"
#include "cons.h"
#include "include/arch.h"
#include "cmd.h"
 
68,7 → 67,7
(void)argc;
addr = strtoul(argv[1], NULL, 0);
 
cons_printf("You requested a breakpoint at 0x%x\n", addr);
printf("You requested a breakpoint at 0x%x\n", addr);
arch_breakpoint_add(addr);
}
 
84,7 → 83,7
(void)argc; (void)argv;
i = 0;
while (cmd_table[i].name != NULL) {
cons_printf("%s\n", cmd_table[i].name);
printf("%s\n", cmd_table[i].name);
++i;
}
}
108,16 → 107,16
 
rc = udebug_mem_read(app_phone, buf, addr, to_read);
if (rc < 0) {
cons_printf("error %d\n", rc);
printf("error %d\n", rc);
return;
}
 
cons_printf("0x%x:", addr);
printf("0x%x:", addr);
for (i = 0; i < to_read; ++i) {
cons_printf(" %02x", buf[i]);
printf(" %02x", buf[i]);
}
for (i = to_read; i < BYTES_PER_LINE; ++i) {
cons_printf(" ");
printf(" ");
}
 
putchar ('\t');
128,7 → 127,7
else
putchar('.');
}
cons_printf("\n");
printf("\n");
 
addr += to_read;
length -= to_read;
/branches/tracing/uspace/app/debug/main.c
44,7 → 44,6
#include <string.h>
 
#include "cmd.h"
#include "cons.h"
#include "include/arch.h"
#include "fib_synch.h"
#include "main.h"
51,8 → 50,8
 
void thread_debug_start(unsigned thread_hash);
 
#define IN_BUF_SIZE 64
static char in_buf[IN_BUF_SIZE];
#define INBUF_SIZE 64
char in_buf[INBUF_SIZE];
 
#define MAX_ARGC 10
int cmd_argc;
75,6 → 74,31
 
fcv_t go_cv;
 
void read_line(char *buffer, int n)
{
char c;
int i;
 
i = 0;
while (i < n - 1) {
c = getchar();
if (c == '\n') break;
if (c == '\b') {
if (i > 0) {
putchar('\b');
--i;
}
continue;
}
putchar(c);
buffer[i++] = c;
}
 
putchar('\n');
buffer[i] = '\0';
}
 
void command_split(char *cmd_str)
{
char *p = cmd_str;
126,13 → 150,13
}
 
if (num_found == 0) {
cons_printf("Unknown command. Try one of:\n");
printf("Unknown command. Try one of:\n");
cmd_help(0, NULL);
return;
}
 
if (cmd_argc - 1 != cmd_table[idx_found].argc) {
cons_printf("Command '%s' expects %d arguments\n",
printf("Command '%s' expects %d arguments\n",
cmd_table[idx_found].name, cmd_table[idx_found].argc);
return;
}
140,20 → 164,12
(*cmd_table[idx_found].proc)(cmd_argc, cmd_argv);
}
 
void thread_stop(void)
{
cons_printf("[t] stopped\n");
fcv_wait(&go_cv);
cons_printf("[t] go\n");
}
 
/*
* Called by a fibril (from arch code) when a breakpoint is hit.
*/
void breakpoint_hit(void)
{
cons_printf("breakpoint hit\n");
thread_stop();
fcv_wait(&go_cv);
}
 
int task_connect(int taskid)
161,21 → 177,21
int rc;
unsigned evmask;
 
cons_printf("ipc_connect_kbox(%d)... ", taskid);
printf("ipc_connect_kbox(%d)... ", taskid);
rc = ipc_connect_kbox(taskid);
cons_printf("-> %d\n", rc);
printf("-> %d\n", rc);
app_phone = rc;
if (rc < 0) return rc;
 
cons_printf("udebug_begin()... ");
printf("udebug_begin()... ");
rc = udebug_begin(app_phone);
cons_printf("-> %d\n", rc);
printf("-> %d\n", rc);
if (rc < 0) return rc;
 
evmask = UDEBUG_EM_ALL & ~(UDEBUG_EM_SYSCALL_B | UDEBUG_EM_SYSCALL_E);
cons_printf("udebug_set_evmask(0x%x)... ", evmask);
printf("udebug_set_evmask(0x%x)... ", evmask);
rc = udebug_set_evmask(app_phone, evmask);
cons_printf("-> %d\n", rc);
printf("-> %d\n", rc);
if (rc < 0) return rc;
 
return 0;
188,19 → 204,19
int tb_needed;
int i;
 
cons_printf("send IPC_M_DEBUG_THREAD_READ message\n");
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);
printf("-> %d\n", rc);
if (rc < 0) return rc;
 
n_threads = tb_copied / sizeof(unsigned);
 
cons_printf("thread IDs:");
printf("thread IDs:");
for (i=0; i<n_threads; i++) {
cons_printf(" %u", thread_hash_buf[i]);
printf(" %u", thread_hash_buf[i]);
}
cons_printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned));
printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned));
 
return 0;
}
208,7 → 224,7
void event_thread_b(unsigned hash)
{
async_serialize_start();
cons_printf("new thread, hash 0x%x\n", hash);
printf("new thread, hash 0x%x\n", hash);
async_serialize_end();
 
thread_debug_start(hash);
220,20 → 236,20
{
switch (ev_type) {
case UDEBUG_EVENT_STOP:
cons_printf("stop event\n");
cons_printf("waiting for resume\n");
printf("stop event\n");
printf("waiting for resume\n");
while (paused) {
usleep(1000000);
fibril_yield();
cons_printf(".");
printf(".");
}
cons_printf("resumed\n");
printf("resumed\n");
break;
case UDEBUG_EVENT_THREAD_B:
event_thread_b(val0);
break;
case UDEBUG_EVENT_THREAD_E:
cons_printf("thread 0x%x exited\n", val0);
printf("thread 0x%x exited\n", val0);
abort_debug = true;
break;
case UDEBUG_EVENT_BREAKPOINT:
243,7 → 259,7
arch_event_trap(thash);
break;
default:
cons_printf("unknown event type %d\n", ev_type);
printf("unknown event type %d\n", ev_type);
break;
}
}
259,22 → 275,24
thread_hash = (unsigned)thread_hash_arg;
thread_id = next_thread_id++;
 
cons_printf("debug_loop(%d)\n", thread_id);
printf("debug_loop(%d)\n", thread_id);
 
while (!abort_debug) {
 
printf("[t%d] go...\n", thread_id);
/* Run thread until an event occurs */
rc = udebug_go(app_phone, thread_hash,
&ev_type, &val0, &val1);
printf("[t%d] stopped\n", thread_id);
 
if (ev_type == UDEBUG_EVENT_FINISHED) {
cons_printf("thread %u debugging finished\n", thread_id);
printf("thread %u debugging finished\n", thread_id);
break;
}
if (rc >= 0) debug_event(thread_hash, ev_type, val0);
}
 
cons_printf("debug_loop(%d) exiting\n", thread_id);
printf("debug_loop(%d) exiting\n", thread_id);
}
 
void thread_debug_start(unsigned thread_hash)
285,7 → 303,7
 
fid = fibril_create(debug_loop, (void *)thread_hash);
if (fid == 0) {
cons_printf("Warning: Failed creating fibril\n");
printf("Warning: Failed creating fibril\n");
}
fibril_add_ready(fid);
}
297,8 → 315,8
int rc;
int c;
 
cons_printf("Breakpoint Debugger\n");
cons_printf("Press 'c' to connect\n");
printf("Breakpoint Debugger\n");
printf("Press 'c' to connect\n");
while ((i = getchar()) != 'c')
putchar(i);
 
305,15 → 323,15
taskid = 14;
rc = task_connect(taskid);
if (rc < 0) {
cons_printf("Failed to connect to task %d\n", taskid);
printf("Failed to connect to task %d\n", taskid);
return;
}
 
cons_printf("Connected to task %d\n", taskid);
printf("Connected to task %d\n", taskid);
 
rc = get_thread_list();
if (rc < 0) {
cons_printf("Failed to get thread list (error %d)\n", rc);
printf("Failed to get thread list (error %d)\n", rc);
return;
}
 
324,7 → 342,8
}
 
while (!quit) {
cons_read_line(in_buf, IN_BUF_SIZE);
printf("> ");
read_line(in_buf, INBUF_SIZE);
command_split(in_buf);
if (cmd_argc == 0) continue;
 
331,12 → 350,12
command_run();
}
 
cons_printf("terminate debugging session...\n");
printf("terminate debugging session...\n");
abort_debug = true;
udebug_end(app_phone);
ipc_hangup(app_phone);
 
cons_printf("done\n");
printf("done\n");
return;
}
 
/branches/tracing/uspace/app/debug/Makefile
45,7 → 45,6
OUTPUT = debug
GENERIC_SOURCES = cmd.c \
fib_synch.c \
cons.c \
main.c
 
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
/branches/tracing/uspace/app/debug/arch/mips32/src/mips32.c
38,7 → 38,6
#include <udebug.h>
#include <kernel/arch/context_offset.h>
 
#include "../../../cons.h"
#include "../../../main.h"
#include "../../../include/arch.h"
 
59,16 → 58,16
}
 
if (!brk) {
cons_printf("too many breakpoints\n");
printf("too many breakpoints\n");
return;
}
 
rc = udebug_mem_read(app_phone, &brk->arch.back, addr, sizeof(&brk->arch.back));
cons_printf("udebug_mem_read() -> %d\n", rc);
printf("udebug_mem_read() -> %d\n", rc);
brkp = OPCODE_BREAK;
rc = udebug_mem_write(app_phone, &brkp, addr, sizeof(brkp));
// for (i=0; i<256; i++) rc = udebug_mem_write(app_phone, &brkp, addr+4*i, sizeof(brkp));
cons_printf("udebug_mem_write() -> %d\n", rc);
printf("udebug_mem_write() -> %d\n", rc);
 
brk->addr = addr;
brk->set = 1;
87,9 → 86,9
brkp = OPCODE_BREAK;
 
rc = udebug_regs_read(app_phone, thread_hash, buffer);
cons_printf("udebug_regs_read -> %d\n", rc);
printf("udebug_regs_read -> %d\n", rc);
epc = buffer[EOFFSET_EPC/sizeof(unsigned)];
cons_printf("EPC was 0x%08x\n", epc);
printf("EPC was 0x%08x\n", epc);
brk_addr = epc;
 
int bi;
98,11 → 97,11
break;
}
if (bi < MAX_BRKPTS) {
cons_printf("breakpoint %d hit\n", bi);
printf("breakpoint %d hit\n", bi);
breakpoint_hit();
 
rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 4);
cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc);
printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc);
rc = udebug_mem_read(app_phone, &brk_list[bi].arch.back, brk_addr+4, 4);
rc = udebug_mem_write(app_phone, &brkp, brk_addr+4, 4);
lifted_brkpt = &brk_list[bi];
114,7 → 113,7
break;
}
if (bi < MAX_BRKPTS) {
cons_printf("restoring breakpoint %d\n", bi);
printf("restoring breakpoint %d\n", bi);
rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 4);
rc = udebug_mem_read(app_phone, &brk_list[bi].arch.back, brk_addr-4, 4);
rc = udebug_mem_write(app_phone, &brkp, brk_addr-4, 4);
122,7 → 121,7
return;
}
 
cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr);
printf("unrecognized breakpoint at 0x%x\n", brk_addr);
}
 
void arch_event_trap(thash_t thread_hash)
/branches/tracing/uspace/app/debug/arch/ia32/src/ia32.c
37,7 → 37,6
#include <sys/types.h>
#include <udebug.h>
 
#include "../../../cons.h"
#include "../../../main.h"
#include "../../../include/arch.h"
 
58,15 → 57,15
if (brk_list[i].set == 0) brk = brk_list+i;
 
if (!brk) {
cons_printf("too many breakpoints\n");
printf("too many breakpoints\n");
return;
}
 
rc = udebug_mem_read(app_phone, &brk->arch.back, addr, 1);
cons_printf("udebug_mem_read() -> %d\n", rc);
printf("udebug_mem_read() -> %d\n", rc);
brkp[0] = OPCODE_INT3;
rc = udebug_mem_write(app_phone, brkp, addr, 1);
cons_printf("udebug_mem_write() -> %d\n", rc);
printf("udebug_mem_write() -> %d\n", rc);
 
brk->addr = addr;
brk->set = 1;
80,8 → 79,8
int rc;
 
rc = udebug_regs_read(app_phone, thread_hash, buffer);
cons_printf("udebug_regs_read -> %d\n", rc);
cons_printf("EIP was 0x%08x\n", buffer[ISTATE_OFF_EIP]);
printf("udebug_regs_read -> %d\n", rc);
printf("EIP was 0x%08x\n", buffer[ISTATE_OFF_EIP]);
int brk_addr = buffer[ISTATE_OFF_EIP] - 1;
int bi;
for (bi = 0; bi < MAX_BRKPTS; bi++) {
90,18 → 89,18
}
 
if (bi < MAX_BRKPTS) {
cons_printf("breakpoint %d hit\n", bi);
printf("breakpoint %d hit\n", bi);
breakpoint_hit();
 
buffer[ISTATE_OFF_EIP] = brk_addr;
buffer[ISTATE_OFF_EFLAGS] |= 0x0100; /* trap flag */
cons_printf("setting EIP to 0x%08x\n", buffer[ISTATE_OFF_EIP]);
printf("setting EIP to 0x%08x\n", buffer[ISTATE_OFF_EIP]);
rc = udebug_regs_write(app_phone, thread_hash, buffer);
rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 1);
cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc);
printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc);
lifted_brkpt = &brk_list[bi];
} else {
cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr);
printf("unrecognized breakpoint at 0x%x\n", brk_addr);
}
}
 
110,15 → 109,15
unsigned char brkinstr[1];
int rc;
 
cons_printf("trap event\n");
printf("trap event\n");
 
breakpoint_t *lb = lifted_brkpt;
brkinstr[0] = OPCODE_INT3;
rc = udebug_mem_write(app_phone, brkinstr, lb->addr, 1);
cons_printf("restore breakpoint -> %d\n", rc);
printf("restore breakpoint -> %d\n", rc);
 
rc = udebug_regs_read(app_phone, thread_hash, buffer);
cons_printf("udebug_regs_read -> %d\n", rc);
printf("udebug_regs_read -> %d\n", rc);
buffer[ISTATE_OFF_EFLAGS] &= ~0x0100; /* trap flag */
rc = udebug_regs_write(app_phone, thread_hash, buffer);
}