git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
4-virtual_memory.md (#24)
[lunaix-os.git]
/
lunaix-os
/
kernel
/
debug
/
trace.c
diff --git
a/lunaix-os/kernel/debug/trace.c
b/lunaix-os/kernel/debug/trace.c
index 1235884c68704417f821f36501fa8249133fd2de..1e5c44ade8af440b76383681fb6dd7b670d0b893 100644
(file)
--- a/
lunaix-os/kernel/debug/trace.c
+++ b/
lunaix-os/kernel/debug/trace.c
@@
-5,8
+5,8
@@
#include <lunaix/syslog.h>
#include <lunaix/trace.h>
#include <lunaix/syslog.h>
#include <lunaix/trace.h>
-#include <sys/
cpu
.h>
-#include <sys/mm/m
empart
.h>
+#include <sys/
abi
.h>
+#include <sys/mm/m
m_defs
.h>
#include <klibc/string.h>
#include <klibc/string.h>
@@
-77,6
+77,11
@@
ksym_getstr(struct ksym_entry* sym)
trace_ctx.ksym_table->ksym_label_off + sym->label_off);
}
trace_ctx.ksym_table->ksym_label_off + sym->label_off);
}
+static inline bool valid_fp(ptr_t ptr) {
+ ptr_t start = ROUNDUP(current_thread->kstack - KSTACK_SIZE, MEM_PAGE);
+ return start < ptr && ptr < current_thread->kstack;
+}
+
int
trace_walkback(struct trace_record* tb_buffer,
ptr_t fp,
int
trace_walkback(struct trace_record* tb_buffer,
ptr_t fp,
@@
-87,8
+92,8
@@
trace_walkback(struct trace_record* tb_buffer,
struct ksym_entry* current = NULL;
int i = 0;
struct ksym_entry* current = NULL;
int i = 0;
- while (
frame
&& i < limit) {
- ptr_t pc =
*(frame + 1
);
+ while (
valid_fp((ptr_t)frame)
&& i < limit) {
+ ptr_t pc =
abi_get_retaddrat((ptr_t)frame
);
current = trace_sym_lookup(pc);
tb_buffer[i] =
current = trace_sym_lookup(pc);
tb_buffer[i] =
@@
-100,6
+105,10
@@
trace_walkback(struct trace_record* tb_buffer,
i++;
}
i++;
}
+ if (!valid_fp((ptr_t)frame)) {
+ frame = NULL;
+ }
+
if (last_fp) {
*last_fp = (ptr_t)frame;
}
if (last_fp) {
*last_fp = (ptr_t)frame;
}
@@
-110,7
+119,11
@@
trace_walkback(struct trace_record* tb_buffer,
static inline void
trace_print_code_entry(ptr_t sym_pc, ptr_t inst_pc, char* sym)
{
static inline void
trace_print_code_entry(ptr_t sym_pc, ptr_t inst_pc, char* sym)
{
- DEBUG("%p+%p: %s", sym_pc, inst_pc - sym_pc, sym);
+ if (sym_pc) {
+ DEBUG("%p+%p: %s", sym_pc, inst_pc - sym_pc, sym);
+ } else {
+ DEBUG("%p+%p: %s", inst_pc, sym_pc, sym);
+ }
}
void
}
void
@@
-134,49
+147,56
@@
trace_printstack_of(ptr_t fp)
void
trace_printstack()
{
void
trace_printstack()
{
- trace_printstack_of(
cpu_get_fp
());
+ trace_printstack_of(
abi_get_callframe
());
}
static void
}
static void
-trace_printswctx(const isr_param* p,
char* direction
)
+trace_printswctx(const isr_param* p,
bool from_usr, bool to_usr
)
{
struct ksym_entry* sym = trace_sym_lookup(p->execp->eip);
{
struct ksym_entry* sym = trace_sym_lookup(p->execp->eip);
- DEBUG("
>> (sw:%s) iv:%d, errno:%p <<",
-
direction
,
+ DEBUG("
^^^^^ --- %s", to_usr ? "user" : "kernel");
+
DEBUG(" interrupted on #%d, ecode=%p"
,
p->execp->vector,
p->execp->err_code);
p->execp->vector,
p->execp->err_code);
+ DEBUG("vvvvv --- %s", from_usr ? "user" : "kernel");
- trace_print_code_entry(sym->pc, p->execp->eip, ksym_getstr(sym));
+ ptr_t sym_pc = sym ? sym->pc : p->execp->eip;
+ trace_print_code_entry(sym_pc, p->execp->eip, ksym_getstr(sym));
}
void
trace_printstack_isr(const isr_param* isrm)
{
isr_param* p = isrm;
}
void
trace_printstack_isr(const isr_param* isrm)
{
isr_param* p = isrm;
- ptr_t fp =
cpu_get_fp
();
- int prev_
fromusr
= 0;
+ ptr_t fp =
abi_get_callframe
();
+ int prev_
usrctx
= 0;
DEBUG("stack trace (pid=%d)\n", __current->pid);
trace_printstack_of(fp);
while (p) {
DEBUG("stack trace (pid=%d)\n", __current->pid);
trace_printstack_of(fp);
while (p) {
- if (!prev_
fromusr
) {
- if (
uspace
_context(p)) {
- trace_printswctx(p,
"s/u"
);
+ if (!prev_
usrctx
) {
+ if (
!kernel
_context(p)) {
+ trace_printswctx(p,
true, false
);
} else {
} else {
- trace_printswctx(p,
"s/s"
);
+ trace_printswctx(p,
false, false
);
}
} else {
}
} else {
- trace_printswctx(p,
"u/s"
);
+ trace_printswctx(p,
false, true
);
}
fp = saved_fp(p);
}
fp = saved_fp(p);
+ if (!valid_fp(fp)) {
+ DEBUG("??? invalid frame: %p", fp);
+ break;
+ }
+
trace_printstack_of(fp);
trace_printstack_of(fp);
- prev_
fromusr = uspace
_context(p);
+ prev_
usrctx = !kernel
_context(p);
p = p->execp->saved_prev_ctx;
}
p = p->execp->saved_prev_ctx;
}