Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2941 → Rev 2942

/branches/tracing/uspace/app/debug/dthread.h
39,6 → 39,8
#include <fibril.h>
#include <libadt/list.h>
 
#include "include/arch/types.h"
 
typedef struct {
int id; /* human-friendly id */
thash_t hash; /* system hash */
47,6 → 49,8
 
/** Link to list of debugged threads */
link_t link;
 
dthread_arch_t arch;
} dthread_t;
 
extern link_t dthreads; /* List of application's threads */
/branches/tracing/uspace/app/debug/include/arch.h
39,11 → 39,13
#include <udebug.h>
 
#include "arch/types.h"
#include "../dthread.h"
 
void arch_breakpoint_add(uintptr_t addr);
void arch_event_breakpoint(thash_t thread_hash);
void arch_event_trap(thash_t thread_hash);
void arch_event_trap(dthread_t *dt);
void arch_dump_regs(thash_t thash);
void arch_set_singlestep(dthread_t *dt, int enable);
 
#endif
 
/branches/tracing/uspace/app/debug/cmd.c
121,6 → 121,7
dt = NULL;
for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
dt = list_get_instance(cur, dthread_t, link);
arch_set_singlestep(dt, 0);
dthread_resume(dt);
}
}
140,7 → 141,9
void cmd_istep(int argc, char *argv[])
{
(void)argc; (void)argv;
/*TODO*/
 
arch_set_singlestep(cwt, 1);
dthread_resume(cwt);
}
 
#define BYTES_PER_LINE 16
/branches/tracing/uspace/app/debug/main.c
158,6 → 158,16
thread_stop();
}
 
/*
* Called by a fibril (from arch code) when a single instruction
* in singlestep is executed
*/
void singlestep_hit(void)
{
cons_printf("singlestep hit\n");
thread_stop();
}
 
static int task_connect(int taskid)
{
int rc;
266,7 → 276,7
arch_event_breakpoint(thash);
break;
case UDEBUG_EVENT_TRAP:
arch_event_trap(thash);
arch_event_trap(dthread_get());
break;
default:
cons_printf("unknown event type %d\n", ev_type);
/branches/tracing/uspace/app/debug/main.h
54,6 → 54,7
extern fcv_t go_cv;
 
void breakpoint_hit(void);
void singlestep_hit(void);
 
 
#endif
/branches/tracing/uspace/app/debug/arch/mips32/include/types.h
42,6 → 42,10
} breakpoint_arch_t;
 
typedef struct {
int singlestep;
} dthread_arch_t;
 
typedef struct {
uint32_t at;
uint32_t v0;
uint32_t v1;
/branches/tracing/uspace/app/debug/arch/mips32/src/mips32.c
125,10 → 125,10
cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr);
}
 
void arch_event_trap(thash_t thread_hash)
void arch_event_trap(dthread_t *dt)
{
/* Unused */
(void)thread_hash;
(void)dt;
}
 
void arch_dump_regs(thash_t thash)
135,5 → 135,9
{
}
 
void arch_set_singlestep(dthread_t *dt, int enable)
{
}
 
/** @}
*/
/branches/tracing/uspace/app/debug/arch/ia32/include/types.h
40,6 → 40,10
} breakpoint_arch_t;
 
typedef struct {
int singlestep;
} dthread_arch_t;
 
typedef struct {
uint32_t eax;
uint32_t ecx;
uint32_t edx;
/branches/tracing/uspace/app/debug/arch/ia32/src/ia32.c
45,9 → 45,6
 
#define OPCODE_INT3 0xCC
 
#define ISTATE_OFF_EIP 12
#define ISTATE_OFF_EFLAGS 14
 
void arch_breakpoint_add(uintptr_t addr)
{
char brkp[1];
57,7 → 54,7
 
brk = NULL;
for (i = 0; i < MAX_BRKPTS; i++)
if (brk_list[i].set == 0) brk = brk_list+i;
if (brk_list[i].set == 0) { brk = brk_list+i; break; }
 
if (!brk) {
cons_printf("too many breakpoints\n");
74,16 → 71,16
brk->set = 1;
}
 
static istate_t istate;
static breakpoint_t *lifted_brkpt;
 
void arch_event_breakpoint(thash_t thread_hash)
{
static istate_t istate;
int rc;
 
rc = udebug_regs_read(app_phone, thread_hash, &istate);
cons_printf("udebug_regs_read -> %d\n", rc);
cons_printf("EIP was 0x%08x\n", istate.eip);
// cons_printf("udebug_regs_read -> %d\n", rc);
// cons_printf("EIP was 0x%08x\n", istate.eip);
int brk_addr = istate.eip - 1;
int bi;
for (bi = 0; bi < MAX_BRKPTS; bi++) {
93,40 → 90,53
 
if (bi < MAX_BRKPTS) {
cons_printf("breakpoint %d hit\n", bi);
breakpoint_hit();
 
istate.eip = brk_addr;
istate.eflags |= 0x0100; /* trap flag */
cons_printf("setting EIP to 0x%08x\n", istate.eip);
// cons_printf("setting EIP to 0x%08x\n", istate.eip);
rc = udebug_regs_write(app_phone, thread_hash, &istate);
if (rc < 0) { printf("error writing regs\n"); return; }
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);
if (rc < 0) { printf("error writing mem\n"); return; }
// cons_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];
 
breakpoint_hit();
} else {
cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr);
}
}
 
void arch_event_trap(thash_t thread_hash)
void arch_event_trap(dthread_t *dt)
{
static istate_t istate;
unsigned char brkinstr[1];
int rc;
 
cons_printf("trap event\n");
// cons_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);
if (lb) {
brkinstr[0] = OPCODE_INT3;
rc = udebug_mem_write(app_phone, brkinstr, lb->addr, 1);
// cons_printf("restore breakpoint -> %d\n", rc);
lifted_brkpt = NULL;
}
 
rc = udebug_regs_read(app_phone, thread_hash, &istate);
cons_printf("udebug_regs_read -> %d\n", rc);
istate.eflags &= ~0x0100; /* trap flag */
rc = udebug_regs_write(app_phone, thread_hash, &istate);
if (!dt->arch.singlestep) {
rc = udebug_regs_read(app_phone, dt->hash, &istate);
// cons_printf("udebug_regs_read -> %d\n", rc);
istate.eflags &= ~0x0100; /* trap flag */
rc = udebug_regs_write(app_phone, dt->hash, &istate);
} else {
// printf("ss-hit\n");
singlestep_hit();
}
}
 
void arch_dump_regs(thash_t thash)
{
static istate_t istate;
int rc;
 
printf("arch_dump_regs...\n");
142,5 → 152,22
istate.ds, istate.es, istate.fs, istate.gs);
}
 
void arch_set_singlestep(dthread_t *dt, int enable)
{
static istate_t istate;
int rc;
 
rc = udebug_regs_read(app_phone, dt->hash, &istate);
if (rc < 0) { printf("regs read failed\n"); return; }
 
if (enable) istate.eflags |= 0x0100; /* trap flag */
else istate.eflags &= ~0x0100; /* trap flag */
 
rc = udebug_regs_write(app_phone, dt->hash, &istate);
if (rc < 0) { printf("regs write failed\n"); return; }
 
dt->arch.singlestep = enable;
}
 
/** @}
*/