/branches/tracing/uspace/app/debug/genarch/idec/bstore.c |
---|
0,0 → 1,111 |
/* |
* 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 <stdio.h> |
#include <assert.h> |
#include <errno.h> |
#include <sys/types.h> |
#include <udebug.h> |
#include "../../main.h" |
#include "../../cons.h" |
#include "bstore.h" |
void bstore_initialize(bstore_t *bs) |
{ |
bs->valid = false; |
} |
int bstore_save(bstore_t *bs, uintptr_t addr) |
{ |
uint32_t v; |
int rc; |
assert(bs->valid == false); |
rc = udebug_mem_read(app_phone, &v, addr, sizeof(uint32_t)); |
if (rc == EOK) { |
bs->valid = true; |
bs->address = addr; |
bs->value = v; |
} else { |
cons_printf("Error reading memory address 0x%zx\n", addr); |
} |
return rc; |
} |
int bstore_push(bstore_t *bs, uintptr_t addr, uint32_t value) |
{ |
int rc; |
rc = bstore_save(bs, addr); |
if (rc != EOK) return rc; |
rc = udebug_mem_write(app_phone, &value, addr, sizeof(uint32_t)); |
if (rc != EOK) { |
cons_printf("Error writing memory address 0x%zx\n", addr); |
bstore_empty(bs); |
return rc; |
} |
return EOK; |
} |
int bstore_pop(bstore_t *bs) |
{ |
int rc; |
assert(bs->valid == true); |
rc = udebug_mem_write(app_phone, &bs->value, bs->address, |
sizeof(uint32_t)); |
if (rc == EOK) { |
bs->valid = false; |
} else { |
cons_printf("Error writing memory address 0x%zx\n", |
bs->address); |
} |
return rc; |
} |
void bstore_empty(bstore_t *bs) |
{ |
assert(bs->valid == true); |
bs->valid = false; |
} |
/** @} |
*/ |
/branches/tracing/uspace/app/debug/genarch/idec/bstore.h |
---|
0,0 → 1,55 |
/* |
* 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 BSTORE_H_ |
#define BSTORE_H_ |
#include <bool.h> |
typedef struct { |
bool valid; |
uintptr_t address; |
uint32_t value; |
} bstore_t; |
void bstore_initialize(bstore_t *bs); |
int bstore_save(bstore_t *bs, uintptr_t addr); |
int bstore_push(bstore_t *bs, uintptr_t addr, uint32_t value); |
int bstore_pop(bstore_t *bs); |
void bstore_empty(bstore_t *bs); |
#endif |
/** @} |
*/ |
/branches/tracing/uspace/app/debug/genarch/idec/idec.c |
---|
0,0 → 1,235 |
/* |
* 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 <stdio.h> |
#include <stdlib.h> |
#include <assert.h> |
#include <sys/types.h> |
#include <errno.h> |
#include <udebug.h> |
#include "../../cons.h" |
#include "../../main.h" |
#include "../../breakpoint.h" |
#include "../../include/arch.h" |
#include "../../include/arch/arch.h" |
#include "idec.h" |
static istate_t istate; |
int idec_breakpoint_set(breakpoint_t *b) |
{ |
bstore_initialize(&b->arch.bs); |
bstore_initialize(&b->arch.next_bs[0]); |
bstore_initialize(&b->arch.next_bs[1]); |
return bstore_push(&b->arch.bs, b->addr, OPCODE_BREAK); |
} |
int idec_breakpoint_remove(breakpoint_t *b) |
{ |
return bstore_pop(&b->arch.bs); |
} |
static void _ev_breakpoint(thash_t thread_hash) |
{ |
breakpoint_t *b; |
dthread_t *dt; |
int rc, n_next, i; |
uint32_t epc; |
uintptr_t brk_addr; |
uintptr_t next_addr[2]; |
uint32_t brkp; |
brkp = OPCODE_BREAK; |
cons_printf("arch_event_breakpoint\n"); |
rc = udebug_regs_read(app_phone, thread_hash, &istate); |
cons_printf("udebug_regs_read -> %d\n", rc); |
epc = istate_get_pc(&istate); |
cons_printf("EPC was 0x%08x\n", epc); |
brk_addr = epc; |
dt = dthread_get(); |
if (active_bkpt != NULL) { |
assert(active_bkpt->arch.bs.address == brk_addr); |
b = active_bkpt; |
/* A breakpoint-restoring BRK has been hit */ |
cons_printf("restoring breakpoint %d\n", b->id); |
for (i = 0; i < b->arch.n_next; ++i) { |
rc = bstore_pop(&b->arch.next_bs[i]); |
if (rc != 0) return; |
} |
rc = bstore_push(&b->arch.bs, b->addr, OPCODE_BREAK); |
if (rc != 0) return; |
active_bkpt = NULL; |
return; |
} |
b = breakpoint_find_by_addr(brk_addr); |
if (b == NULL) { |
cons_printf("Unrecognized breakpoint at 0x%lx\n", brk_addr); |
} |
/* A breakpoint has been hit */ |
cons_printf("breakpoint_hit...\n"); |
breakpoint_hit(b); |
/* While in breakpoint_hit(), singlestep was activated */ |
if (dt->arch.singlestep) return; |
cons_printf("move breakpoint\b"); |
rc = bstore_pop(&b->arch.bs); |
if (rc != 0) return; |
n_next = get_next_addr(dt, brk_addr, next_addr); |
if (n_next < 0) return; |
/* |
* There could be another breakpoint at next_addr, |
* but that's okay. We'll pop the active breakpoint bs |
* before doing anything else. |
*/ |
for (i = 0; i < n_next; ++i) { |
rc = bstore_push(&b->arch.next_bs[i], next_addr[i], |
OPCODE_BREAK); |
if (rc != 0) return; |
} |
b->arch.n_next = n_next; |
active_bkpt = b; |
b->active = true; |
cons_printf("end_hit...\n"); |
} |
static void _ev_singlestep(thash_t thread_hash) |
{ |
dthread_t *dt; |
int rc, i; |
uint32_t epc; |
int brk_addr; |
uint32_t brkp; |
dt = dthread_get(); |
assert(active_bkpt == NULL); |
assert(dt->arch.singlestep); |
brkp = OPCODE_BREAK; |
cons_printf("arch_event_breakpoint\n"); |
rc = udebug_regs_read(app_phone, thread_hash, &istate); |
cons_printf("udebug_regs_read -> %d\n", rc); |
epc = istate_get_pc(&istate); |
cons_printf("EPC was 0x%08x\n", epc); |
brk_addr = epc; |
if (dt->arch.cur.valid) { |
cons_printf("restore breakpoint BREAK\n"); |
rc = bstore_pop(&dt->arch.cur); |
} |
cons_printf("\nclear singlestep BREAKs\n"); |
for (i = 0; i < dt->arch.n_next; ++i) { |
rc = bstore_pop(&dt->arch.next[i]); |
if (rc != 0) return; |
} |
dt->arch.singlestep = false; |
singlestep_hit(); |
} |
void idec_event_breakpoint(thash_t thread_hash) |
{ |
dthread_t *dt; |
dt = dthread_get(); |
if (dt->arch.singlestep) { |
_ev_singlestep(thread_hash); |
} else { |
_ev_breakpoint(thread_hash); |
} |
} |
void idec_singlestep(dthread_t *dt) |
{ |
int rc, i; |
uint32_t epc; |
breakpoint_t *b; |
uint32_t old_instr; |
uintptr_t next_addr[2]; |
int n_next; |
assert(active_bkpt == NULL); |
assert(dt->arch.singlestep == false); |
cons_printf("idec_singlestep(dt)\n"); |
rc = udebug_regs_read(app_phone, dt->hash, &istate); |
cons_printf("udebug_regs_read -> %d\n", rc); |
epc = istate_get_pc(&istate); |
cons_printf("EPC was 0x%08x\n", epc); |
cons_printf("initial set singlestep\n"); |
b = breakpoint_find_by_addr(epc); |
if (b != NULL) { |
/* Cover breakpoint with old instruction */ |
old_instr = b->arch.bs.value; |
rc = bstore_push(&dt->arch.cur, epc, old_instr); |
if (rc < 0) return; |
} |
n_next = get_next_addr(dt, epc, next_addr); |
if (n_next < 0) return; |
/* Cover next instruction(s) with BREAK */ |
for (i = 0; i < n_next; ++i) { |
rc = bstore_push(&dt->arch.next[i], next_addr[i], OPCODE_BREAK); |
if (rc != 0) return; |
} |
dt->arch.n_next = n_next; |
dt->arch.singlestep = true; |
dthread_resume(dt); |
} |
/** @} |
*/ |
/branches/tracing/uspace/app/debug/genarch/idec/idec.h |
---|
0,0 → 1,48 |
/* |
* 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 IDEC_H_ |
#define IDEC_H_ |
#include "../../breakpoint.h" |
int idec_breakpoint_set(breakpoint_t *b); |
int idec_breakpoint_remove(breakpoint_t *b); |
void idec_event_breakpoint(thash_t thread_hash); |
void idec_singlestep(dthread_t *dt); |
#endif |
/** @} |
*/ |
/branches/tracing/uspace/app/debug/Makefile |
---|
34,8 → 34,9 |
SOFTINT_PREFIX = ../../lib/softint |
include $(LIBC_PREFIX)/Makefile.toolchain |
include arch/$(ARCH)/Makefile.inc |
include genarch/Makefile.inc |
CFLAGS += -I../../srv/kbd/include |
CFLAGS += -I../../srv/kbd/include -Igenarch/idec |
LIBS = $(LIBC_PREFIX)/libc.a |
49,8 → 50,8 |
breakpoint.c \ |
main.c |
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES))) |
ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES))) |
SOURCES := $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) |
OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) |
.PHONY: all clean depend disasm inc |
66,10 → 67,10 |
find . -name '*.o' -follow -exec rm \{\} \; |
depend: |
$(CC) $(DEFS) $(CFLAGS) -M $(ARCH_SOURCES) $(GENERIC_SOURCES) > Makefile.depend |
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend |
$(OUTPUT): $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS) |
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map |
$(OUTPUT): $(OBJECTS) $(LIBS) |
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map |
disasm: |
$(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm |
/branches/tracing/uspace/app/debug/arch/mips32/include/bstore.h |
---|
File deleted |
/branches/tracing/uspace/app/debug/arch/mips32/include/arch.h |
---|
0,0 → 1,48 |
/* |
* 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 mips32_ARCH_H_ |
#define mips32_ARCH_H_ |
#include <sys/types.h> |
#include "../../../dthread.h" |
#define OPCODE_BREAK 0x0000000d |
int get_next_addr(dthread_t *dt, uintptr_t addr, uintptr_t *buffer); |
#endif |
/** @} |
*/ |
/branches/tracing/uspace/app/debug/arch/mips32/include/types.h |
---|
32,12 → 32,13 |
/** @file |
*/ |
#ifndef TYPES_H_ |
#define TYPES_H_ |
#ifndef mips32_TYPES_H_ |
#define mips32_TYPES_H_ |
#include <sys/types.h> |
#include "bstore.h" |
#include <bstore.h> |
typedef struct { |
bstore_t bs; |
/branches/tracing/uspace/app/debug/arch/mips32/Makefile.inc |
---|
27,5 → 27,6 |
# |
ARCH_SOURCES := \ |
arch/$(ARCH)/src/mips32.c \ |
arch/$(ARCH)/src/bstore.c |
arch/$(ARCH)/src/mips32.c |
CONFIG_IDEC = y |
/branches/tracing/uspace/app/debug/arch/mips32/src/bstore.c |
---|
File deleted |
/branches/tracing/uspace/app/debug/arch/mips32/src/mips32.c |
---|
43,6 → 43,7 |
#include "../../../main.h" |
#include "../../../breakpoint.h" |
#include "../../../include/arch.h" |
#include "../../../genarch/idec/idec.h" |
#define OPCODE_BREAK 0x0000000d |
125,16 → 126,12 |
int arch_breakpoint_set(breakpoint_t *b) |
{ |
bstore_initialize(&b->arch.bs); |
bstore_initialize(&b->arch.next_bs[0]); |
bstore_initialize(&b->arch.next_bs[1]); |
return bstore_push(&b->arch.bs, b->addr, OPCODE_BREAK); |
return idec_breakpoint_set(b); |
} |
int arch_breakpoint_remove(breakpoint_t *b) |
{ |
return bstore_pop(&b->arch.bs); |
return idec_breakpoint_remove(b); |
} |
static int islot_read(uintptr_t addr, uint32_t *instr) |
163,8 → 160,10 |
return -1; |
} |
static int get_reg(int reg_no, uint32_t *value) |
static int get_reg(dthread_t *dt, int reg_no, uint32_t *value) |
{ |
int rc; |
cons_printf("get_reg...\n"); |
if (reg_no == 0) { |
172,6 → 171,9 |
return 0; |
} |
rc = udebug_regs_read(app_phone, dt->hash, &istate); |
if (rc < 0) return rc; |
/* FIXME: ugly */ |
*value = ((uint32_t *)&istate)[reg_no - 1]; |
printf("get_reg ok (0x%08x)\n", *value); |
183,11 → 185,12 |
* |
* Assumptions: addr == PC, *addr is not covered by a BREAK. |
* |
* @param dt Dthread on which to operate. |
* @param addr Address of an instruction. |
* @param buffer Buffer for storing up to 2 addresses. |
* @return Number of stored addresses or negative error code. |
*/ |
static int get_next_addr(uintptr_t addr, uintptr_t *buffer) |
int get_next_addr(dthread_t *dt, uintptr_t addr, uintptr_t *buffer) |
{ |
/* TODO: J[AL]R, branches and delay slots */ |
uint32_t instr; |
239,7 → 242,7 |
case OP_JR: |
case OP_JALR: |
/* Register jump */ |
rc = get_reg((instr >> 21) & 0x1f, &buffer[0]); |
rc = get_reg(dt, (instr >> 21) & 0x1f, &buffer[0]); |
n = 1; |
break; |
default: |
252,132 → 255,9 |
return n; |
} |
static void _ev_breakpoint(thash_t thread_hash) |
{ |
breakpoint_t *b; |
dthread_t *dt; |
int rc, n_next, i; |
uint32_t epc; |
uintptr_t brk_addr; |
uintptr_t next_addr[2]; |
uint32_t brkp; |
brkp = OPCODE_BREAK; |
cons_printf("arch_event_breakpoint\n"); |
rc = udebug_regs_read(app_phone, thread_hash, &istate); |
cons_printf("udebug_regs_read -> %d\n", rc); |
epc = istate_get_pc(&istate); |
cons_printf("EPC was 0x%08x\n", epc); |
brk_addr = epc; |
dt = dthread_get(); |
if (active_bkpt != NULL) { |
assert(active_bkpt->arch.bs.address == brk_addr); |
b = active_bkpt; |
/* A breakpoint-restoring BRK has been hit */ |
cons_printf("restoring breakpoint %d\n", b->id); |
for (i = 0; i < b->arch.n_next; ++i) { |
rc = bstore_pop(&b->arch.next_bs[i]); |
if (rc != 0) return; |
} |
rc = bstore_push(&b->arch.bs, b->addr, OPCODE_BREAK); |
if (rc != 0) return; |
active_bkpt = NULL; |
return; |
} |
b = breakpoint_find_by_addr(brk_addr); |
if (b == NULL) { |
cons_printf("Unrecognized breakpoint at 0x%lx\n", brk_addr); |
} |
/* A breakpoint has been hit */ |
cons_printf("breakpoint_hit...\n"); |
breakpoint_hit(b); |
/* While in breakpoint_hit(), singlestep was activated */ |
if (dt->arch.singlestep) return; |
cons_printf("move breakpoint\b"); |
rc = bstore_pop(&b->arch.bs); |
if (rc != 0) return; |
n_next = get_next_addr(brk_addr, next_addr); |
if (n_next < 0) return; |
/* |
* There could be another breakpoint at next_addr, |
* but that's okay. We'll pop the active breakpoint bs |
* before doing anything else. |
*/ |
for (i = 0; i < n_next; ++i) { |
rc = bstore_push(&b->arch.next_bs[i], next_addr[i], |
OPCODE_BREAK); |
if (rc != 0) return; |
} |
b->arch.n_next = n_next; |
active_bkpt = b; |
b->active = true; |
cons_printf("end_hit...\n"); |
} |
static void _ev_singlestep(thash_t thread_hash) |
{ |
dthread_t *dt; |
int rc, i; |
uint32_t epc; |
int brk_addr; |
uint32_t brkp; |
dt = dthread_get(); |
assert(active_bkpt == NULL); |
assert(dt->arch.singlestep); |
brkp = OPCODE_BREAK; |
cons_printf("arch_event_breakpoint\n"); |
rc = udebug_regs_read(app_phone, thread_hash, &istate); |
cons_printf("udebug_regs_read -> %d\n", rc); |
epc = istate_get_pc(&istate); |
cons_printf("EPC was 0x%08x\n", epc); |
brk_addr = epc; |
if (dt->arch.cur.valid) { |
cons_printf("restore breakpoint BREAK\n"); |
rc = bstore_pop(&dt->arch.cur); |
} |
cons_printf("\nclear singlestep BREAKs\n"); |
for (i = 0; i < dt->arch.n_next; ++i) { |
rc = bstore_pop(&dt->arch.next[i]); |
if (rc != 0) return; |
} |
dt->arch.singlestep = false; |
singlestep_hit(); |
} |
void arch_event_breakpoint(thash_t thread_hash) |
{ |
dthread_t *dt; |
dt = dthread_get(); |
if (dt->arch.singlestep) { |
_ev_singlestep(thread_hash); |
} else { |
_ev_breakpoint(thread_hash); |
} |
idec_event_breakpoint(thread_hash); |
} |
void arch_event_trap(dthread_t *dt) |
393,43 → 273,7 |
void arch_singlestep(dthread_t *dt) |
{ |
int rc, i; |
uint32_t epc; |
breakpoint_t *b; |
uint32_t old_instr; |
uintptr_t next_addr[2]; |
int n_next; |
assert(active_bkpt == NULL); |
assert(dt->arch.singlestep == false); |
cons_printf("arch_singlestep(dt)\n"); |
rc = udebug_regs_read(app_phone, dt->hash, &istate); |
cons_printf("udebug_regs_read -> %d\n", rc); |
epc = istate_get_pc(&istate); |
cons_printf("EPC was 0x%08x\n", epc); |
cons_printf("initial set singlestep\n"); |
b = breakpoint_find_by_addr(epc); |
if (b != NULL) { |
/* Cover breakpoint with old instruction */ |
old_instr = b->arch.bs.value; |
rc = bstore_push(&dt->arch.cur, epc, old_instr); |
if (rc < 0) return; |
} |
n_next = get_next_addr(epc, next_addr); |
if (n_next < 0) return; |
/* Cover next instruction(s) with BREAK */ |
for (i = 0; i < n_next; ++i) { |
rc = bstore_push(&dt->arch.next[i], next_addr[i], OPCODE_BREAK); |
if (rc != 0) return; |
} |
dt->arch.n_next = n_next; |
dt->arch.singlestep = true; |
dthread_resume(dt); |
idec_singlestep(dt); |
} |
/** @} |
/branches/tracing/uspace/app/debug/arch/ia32/include/types.h |
---|
32,8 → 32,8 |
/** @file |
*/ |
#ifndef TYPES_H_ |
#define TYPES_H_ |
#ifndef ia32_TYPES_H_ |
#define ia32_TYPES_H_ |
typedef struct { |
unsigned char back; |
/branches/tracing/uspace/app/debug/arch/ia32/src/ia32.c |
---|
46,6 → 46,11 |
#define OPCODE_INT3 0xCC |
void arch_dthread_initialize(dthread_t *dt) |
{ |
dt->arch.singlestep = false; |
} |
static int _set_trap_flag(dthread_t *dt, bool enable) |
{ |
static istate_t istate; |
52,13 → 57,13 |
int rc; |
rc = udebug_regs_read(app_phone, dt->hash, &istate); |
if (rc < 0) { printf("regs read failed\n"); return; } |
if (rc < 0) { printf("regs read failed\n"); return -1; } |
if (enable) istate.eflags |= 0x0100; /* trap flag */ |
else if (!active_bkpt) istate.eflags &= ~0x0100; /* trap flag */ |
rc = udebug_regs_write(app_phone, dt->hash, &istate); |
if (rc < 0) { printf("regs write failed\n"); return; } |
if (rc < 0) { printf("regs write failed\n"); return -1; } |
return 0; |
} |