Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2917 → Rev 2918

/branches/tracing/kernel/generic/include/udebug/udebug.h
157,6 → 157,7
UDEBUG_EVENT_SYSCALL_E, /**< After finishing syscall execution */
UDEBUG_EVENT_THREAD_B, /**< The task created a new thread */
UDEBUG_EVENT_THREAD_E, /**< A thread exited */
UDEBUG_EVENT_BREAKPOINT /**< Breakpoint instruction executed */
} udebug_event_t;
 
#define UDEBUG_EVMASK(event) (1 << ((event) - 1))
168,6 → 169,7
UDEBUG_EM_SYSCALL_E = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E),
UDEBUG_EM_THREAD_B = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B),
UDEBUG_EM_THREAD_E = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E),
UDEBUG_EM_BREAKPOINT = UDEBUG_EVMASK(UDEBUG_EVENT_BREAKPOINT),
UDEBUG_EM_ALL =
UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED) |
UDEBUG_EVMASK(UDEBUG_EVENT_STOP) |
174,7 → 176,8
UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B) |
UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E) |
UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B) |
UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E)
UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E) |
UDEBUG_EVMASK(UDEBUG_EVENT_BREAKPOINT)
} udebug_evmask_t;
 
#ifdef KERNEL
203,6 → 206,8
void udebug_stoppable_begin(void);
void udebug_stoppable_end(void);
 
void udebug_breakpoint_event(uintptr_t addr);
 
int udebug_task_cleanup(struct task *ta);
 
#endif
/branches/tracing/kernel/generic/src/udebug/udebug.c
329,7 → 329,52
/* This event does not sleep - debugging has finished in this thread */
}
 
void udebug_breakpoint_event(uintptr_t addr)
{
call_t *call;
ipl_t ipl;
udebug_event_t etype;
 
etype = UDEBUG_EVENT_BREAKPOINT;
 
ipl = interrupts_disable();
spinlock_lock(&THREAD->debug_lock);
 
/* Must only generate events when in debugging session and have go */
if (THREAD->debug_active != true ||
THREAD->debug_stop == true ||
(TASK->debug_evmask & UDEBUG_EVMASK(etype)) == 0) {
spinlock_unlock(&THREAD->debug_lock);
interrupts_restore(ipl);
return;
}
 
klog_printf("udebug_breakpoint_event");
call = THREAD->debug_go_call;
IPC_SET_RETVAL(call->data, 0);
IPC_SET_ARG1(call->data, etype);
IPC_SET_ARG2(call->data, addr);
 
/*
* Make sure debug_stop is true when going to sleep
* in case we get woken up by DEBUG_END. (At which
* point it must be back to the initial true value).
*/
THREAD->debug_stop = true;
 
THREAD->cur_event = etype;
spinlock_unlock(&THREAD->debug_lock);
klog_printf("- send answer");
 
spinlock_lock(&TASK->lock);
ipc_answer(&TASK->answerbox, THREAD->debug_go_call);
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
 
udebug_wait_for_go(&THREAD->go_wq);
}
 
 
/**
* Terminate task debugging session.
*
/branches/tracing/kernel/arch/ia32/include/interrupt.h
62,6 → 62,7
#endif
 
#define VECTOR_DEBUG 1
#define VECTOR_BREAKPOINT 3
#define VECTOR_CLK (IVT_IRQBASE + IRQ_CLK)
#define VECTOR_PIC_SPUR (IVT_IRQBASE + IRQ_PIC_SPUR)
#define VECTOR_SYSCALL IVT_FREEBASE
/branches/tracing/kernel/arch/ia32/include/breakpoint.h
0,0 → 1,43
/*
* 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 ia32
* @{
*/
/** @file
*/
 
#ifndef KERN_ia32_BREAKPOINT_H_
#define KERN_ia32_BREAKPOINT_H_
 
extern void breakpoint_init(void);
 
#endif
 
/** @}
*/
/branches/tracing/kernel/arch/ia32/Makefile.inc
151,4 → 151,5
arch/$(ARCH)/src/boot/boot.S \
arch/$(ARCH)/src/boot/memmap.c \
arch/$(ARCH)/src/fpu_context.c \
arch/$(ARCH)/src/debugger.c
arch/$(ARCH)/src/debugger.c \
arch/$(ARCH)/src/breakpoint.c
/branches/tracing/kernel/arch/ia32/src/ia32.c
57,6 → 57,7
#include <interrupt.h>
#include <ddi/irq.h>
#include <arch/debugger.h>
#include <arch/breakpoint.h>
#include <proc/thread.h>
#include <syscall/syscall.h>
#include <console/console.h>
97,6 → 98,8
/* Enable debugger */
debugger_init();
/* Enable INT3 breakpoint handler */
breakpoint_init();
/* Merge all memory zones to 1 big zone */
zone_merge_all();
}
/branches/tracing/kernel/arch/ia32/src/breakpoint.c
0,0 → 1,60
/*
* 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 ia32
* @{
*/
/** @file
*/
 
#include <arch/breakpoint.h>
#include <panic.h>
#include <console/klog.h>
#include <interrupt.h>
#include <func.h>
 
static void breakpoint_exception(int n __attribute__((unused)), istate_t *istate)
{
ASSERT(THREAD);
ASSERT(istate_from_uspace(istate));
 
(void)istate;
klog_printf("breakpoint exception\n");
interrupts_enable();
udebug_breakpoint_event(istate->eip);
}
 
/** Initialize breakpoint handling */
void breakpoint_init()
{
exc_register(VECTOR_BREAKPOINT, "breakpoint",
breakpoint_exception);
}
 
/** @}
*/
/branches/tracing/kernel/arch/ia32/src/pm.c
131,10 → 131,10
 
d->access = AR_PRESENT | AR_INTERRUPT; /* masking interrupt */
 
if (i == VECTOR_SYSCALL) {
if (i == VECTOR_SYSCALL || i == VECTOR_BREAKPOINT) {
/*
* The syscall interrupt gate must be calleable from
* userland.
* userland. The same for breakpoint gate.
*/
d->access |= DPL_USER;
}
/branches/tracing/uspace/app/debug/main.c
161,6 → 161,7
int task_connect(int taskid)
{
int rc;
unsigned evmask;
 
printf("ipc_connect_kbox(%d)... ", taskid);
rc = ipc_connect_kbox(taskid);
173,8 → 174,9
printf("-> %d\n", rc);
if (rc < 0) return rc;
 
printf("udebug_set_evmask(0x%x)... ", UDEBUG_EM_ALL);
rc = udebug_set_evmask(app_phone, UDEBUG_EM_ALL);
evmask = UDEBUG_EM_ALL & ~(UDEBUG_EM_SYSCALL_B | UDEBUG_EM_SYSCALL_E);
printf("udebug_set_evmask(0x%x)... ", evmask);
rc = udebug_set_evmask(app_phone, evmask);
printf("-> %d\n", rc);
if (rc < 0) return rc;
 
229,10 → 231,13
 
while (!abort_debug) {
 
printf("go\n");
/* Run thread until an event occurs */
rc = udebug_go(app_phone, thread_hash,
&ev_type, &val0, &val1);
 
printf("..ev type %d\n", ev_type);
 
// printf("rc = %d, ev_type=%d\n", rc, ev_type);
if (ev_type == UDEBUG_EVENT_FINISHED) {
printf("thread %u debugging finished\n", thread_id);
258,6 → 263,10
printf("thread 0x%x exited\n", val0);
abort_debug = true;
break;
case UDEBUG_EVENT_BREAKPOINT:
printf("breakpoint reached\n");
usleep(2000*2000);
break;
default:
printf("unknown event type %d\n", ev_type);
break;