#include "backtrace.h"
#include "stdio.h"
+#include "stab.h"
#include "asm/x86.h"
// get next stack pointer - just does some math
-#define get_ra(cur_sp) (*((int *) (cur_sp) - 1))
+#define get_ra(cur_sp) (*((int *) (cur_sp) + 1))
#define MAGIC_RETURN_ADDR 0xF00
void backtrace() {
- int ebp;
+ int ebp, i;
+ struct stab_info si = {
+ NULL, 0, NULL, 0, 0, 0};
read_ebp(ebp);
- cprintf("Backtrace: %d\n", sizeof(int));
+ // asm ("movl %%ebp, %0" : "=r" (ebp) );
+ cprintf("Backtrace:\n");
+ char eip_fn_name[32];
+ char *unk = "<unknown>";
+ char *realstr;
+ /* should be really offset
+ * which is how many bytes away from fn start */
+ int lineno = 0;
while (ebp != MAGIC_RETURN_ADDR) {
- cprintf(" <0x%x> func1+offs1\n", get_ra(ebp));
+ if (stab_info(get_ra(ebp), &si) == 0) {
+ /* do a strcpy like thing since not null
+ * terminated */
+ for (i = 0; i < si.eip_fn_namelen; ++i) {
+ eip_fn_name[i] = si.eip_fn_name[i];
+ }
+ eip_fn_name[si.eip_fn_namelen] = '\0';
+ realstr = eip_fn_name;
+ lineno = get_ra(ebp)-si.eip_fn_addr;
+ } else {
+ /* set lineno to 0 and fn to unknown */
+ lineno = 0;
+ realstr = unk;
+ }
+
+ cprintf(" <0x%x> %s+%d\n", get_ra(ebp),
+ realstr, lineno);
ebp = *((int *) ebp);
}
}
#include "syscall.h"
#include "stdio.h"
+// FIXME
+#include "backtrace.h"
// User code makes a system call with INT T_SYSCALL.
// System call number in %eax.
// Arguments on the stack, from the user call to the C
int num;
struct proc *curproc = myproc();
+ //FIXME
+ backtrace();
+
num = curproc->tf->eax;
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
curproc->tf->eax = syscalls[num]();