From b08d16f61d0022cb908f35a27efa100caf27dcf6 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Wed, 22 Aug 2012 20:07:04 -0400 Subject: [PATCH 01/10] Fix from Peter Froehlich --- wc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wc.c b/wc.c index b728d27..d6a54df 100644 --- a/wc.c +++ b/wc.c @@ -44,7 +44,7 @@ main(int argc, char *argv[]) for(i = 1; i < argc; i++){ if((fd = open(argv[i], 0)) < 0){ - printf(1, "cat: cannot open %s\n", argv[i]); + printf(1, "wc: cannot open %s\n", argv[i]); exit(); } wc(fd, argv[i]); From 70c555574a140b2696d6f1a5aa524902ef4c820c Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Wed, 22 Aug 2012 20:13:43 -0400 Subject: [PATCH 02/10] Remove unused argument from lapicinit (thanks to Peter Froehlich) --- defs.h | 2 +- lapic.c | 2 +- main.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/defs.h b/defs.h index efbbe3d..90b5572 100644 --- a/defs.h +++ b/defs.h @@ -74,7 +74,7 @@ void kbdintr(void); int cpunum(void); extern volatile uint* lapic; void lapiceoi(void); -void lapicinit(int); +void lapicinit(void); void lapicstartap(uchar, uint); void microdelay(int); diff --git a/lapic.c b/lapic.c index effceb1..94b484f 100644 --- a/lapic.c +++ b/lapic.c @@ -50,7 +50,7 @@ lapicw(int index, int value) //PAGEBREAK! void -lapicinit(int c) +lapicinit(void) { if(!lapic) return; diff --git a/main.c b/main.c index c0c3a91..712958f 100644 --- a/main.c +++ b/main.c @@ -20,7 +20,7 @@ main(void) kinit1(end, P2V(4*1024*1024)); // phys page allocator kvmalloc(); // kernel page table mpinit(); // collect info about this machine - lapicinit(mpbcpu()); + lapicinit(); seginit(); // set up segments cprintf("\ncpu%d: starting xv6\n\n", cpu->id); picinit(); // interrupt controller @@ -48,7 +48,7 @@ mpenter(void) { switchkvm(); seginit(); - lapicinit(cpunum()); + lapicinit(); mpmain(); } From 4ce832ddd280a4cea36e16115ddeaea74213314e Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Wed, 22 Aug 2012 20:19:37 -0400 Subject: [PATCH 03/10] Remove unused argument to setupkvm (thanks to Peter Froehlich) --- defs.h | 2 +- exec.c | 2 +- proc.c | 2 +- vm.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/defs.h b/defs.h index 90b5572..12f021b 100644 --- a/defs.h +++ b/defs.h @@ -164,7 +164,7 @@ void uartputc(int); void seginit(void); void kvmalloc(void); void vmenable(void); -pde_t* setupkvm(); +pde_t* setupkvm(void); char* uva2ka(pde_t*, char*); int allocuvm(pde_t*, uint, uint); int deallocuvm(pde_t*, uint, uint); diff --git a/exec.c b/exec.c index 312a5c3..a85e203 100644 --- a/exec.c +++ b/exec.c @@ -29,7 +29,7 @@ exec(char *path, char **argv) if(elf.magic != ELF_MAGIC) goto bad; - if((pgdir = setupkvm(kalloc)) == 0) + if((pgdir = setupkvm()) == 0) goto bad; // Load program into memory. diff --git a/proc.c b/proc.c index 05cb85f..bcdbfea 100644 --- a/proc.c +++ b/proc.c @@ -83,7 +83,7 @@ userinit(void) p = allocproc(); initproc = p; - if((p->pgdir = setupkvm(kalloc)) == 0) + if((p->pgdir = setupkvm()) == 0) panic("userinit: out of memory?"); inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size); p->sz = PGSIZE; diff --git a/vm.c b/vm.c index fa7b706..da3ea3c 100644 --- a/vm.c +++ b/vm.c @@ -126,7 +126,7 @@ static struct kmap { // Set up kernel part of a page table. pde_t* -setupkvm() +setupkvm(void) { pde_t *pgdir; struct kmap *k; From 95692c4a8cf38765bac15b05d7a898e4ac8946e8 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Wed, 22 Aug 2012 20:28:58 -0400 Subject: [PATCH 04/10] Remove left-over from some logging plan making complete syscalls atomic 0 is not a system call (thanks to Peter Froehlich) --- syscall.c | 4 +--- syscall.h | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/syscall.c b/syscall.c index 45f758e..799ebc2 100644 --- a/syscall.c +++ b/syscall.c @@ -129,9 +129,7 @@ syscall(void) int num; num = proc->tf->eax; - if(num >= 0 && num < SYS_open && syscalls[num]) { - proc->tf->eax = syscalls[num](); - } else if (num >= SYS_open && num < NELEM(syscalls) && syscalls[num]) { + if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { proc->tf->eax = syscalls[num](); } else { cprintf("%d %s: unknown sys call %d\n", diff --git a/syscall.h b/syscall.h index 59a4576..bc5f356 100644 --- a/syscall.h +++ b/syscall.h @@ -13,7 +13,6 @@ #define SYS_sbrk 12 #define SYS_sleep 13 #define SYS_uptime 14 - #define SYS_open 15 #define SYS_write 16 #define SYS_mknod 17 From c2d393df13cd14762af650c78a7c960b820c4660 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Wed, 22 Aug 2012 20:51:29 -0400 Subject: [PATCH 05/10] Decode getcallerpcs() (thanks to Peter Froehlich) --- depcs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 depcs diff --git a/depcs b/depcs new file mode 100644 index 0000000..6dfb888 --- /dev/null +++ b/depcs @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +# Decode a stack trace from getcallerpcs() to kernel symbols. +# Peter H. Froehlich , 600.318/418, Spring 2011 +# +# $ ./depcs 1072fa 1073c4 106d4a 103024 102fdd 0 0 0 0 0 +# 1078010 ['mappages'] +# 1078212 ['setupkvm'] +# 1076554 ['kvmalloc'] +# 1060900 ['mainc'] +# 1060829 ['jmpkstack'] + +import sys + +# read the symbols, mapping each address to all known names + +raw = {} +with open("kernel.sym") as f: + for s in f: + adr, sym = s.strip().split() + adr = int(adr, 16) + if adr in raw: + raw[adr].append(sym) + else: + raw[adr] = [sym] + +# for a given address, we need to determine what range it +# lies in; there are fancy data structures or this, which +# we ignore; let's just sort the keys instead + +sort = sorted(raw.keys()) + +# now we can find the least key greater than an address; +# if there's none, we use the last address we know; doh! + +def least(x): + for i in range(len(sort)-1): + if sort[i] <= x < sort[i+1]: + return sort[i] + return sort[-1] + +# therefore we can decode a backtrace (ignoring address +# 0 since it's useless for xv6) + +for adr in sys.argv[1:]: + adr = int(adr, 16) + if adr != 0: + print adr, raw[least(adr)] From f3f4b0fd88fd06df515a332ec68b34efa8616e12 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Wed, 22 Aug 2012 20:54:47 -0400 Subject: [PATCH 06/10] chmod +x --- depcs | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 depcs diff --git a/depcs b/depcs old mode 100644 new mode 100755 From 3fb7eceea7fb967d6d4567559f544f5742edae49 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Wed, 22 Aug 2012 21:24:13 -0400 Subject: [PATCH 07/10] Runoff still complaints these lines are too long, but it is now ok on printout --- vm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vm.c b/vm.c index da3ea3c..7cfdc4e 100644 --- a/vm.c +++ b/vm.c @@ -118,10 +118,10 @@ static struct kmap { uint phys_end; int perm; } kmap[] = { - { (void*) KERNBASE, 0, EXTMEM, PTE_W}, // I/O space - { (void*) KERNLINK, V2P(KERNLINK), V2P(data), 0}, // kernel text+rodata - { (void*) data, V2P(data), PHYSTOP, PTE_W}, // kernel data, memory - { (void*) DEVSPACE, DEVSPACE, 0, PTE_W}, // more devices + { (void*)KERNBASE, 0, EXTMEM, PTE_W}, // I/O space + { (void*)KERNLINK, V2P(KERNLINK), V2P(data), 0}, // kernel text+rodata + { (void*)data, V2P(data), PHYSTOP, PTE_W}, // kernel data+memory + { (void*)DEVSPACE, DEVSPACE, 0, PTE_W}, // more devices }; // Set up kernel part of a page table. From 6650cc934afa222bb729f63fbfe85aa15ebbd778 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Wed, 22 Aug 2012 21:25:19 -0400 Subject: [PATCH 08/10] Use addr2line (or i386-jos-elf-addr2line, if you cross compile) --- depcs | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100755 depcs diff --git a/depcs b/depcs deleted file mode 100755 index 6dfb888..0000000 --- a/depcs +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python - -# Decode a stack trace from getcallerpcs() to kernel symbols. -# Peter H. Froehlich , 600.318/418, Spring 2011 -# -# $ ./depcs 1072fa 1073c4 106d4a 103024 102fdd 0 0 0 0 0 -# 1078010 ['mappages'] -# 1078212 ['setupkvm'] -# 1076554 ['kvmalloc'] -# 1060900 ['mainc'] -# 1060829 ['jmpkstack'] - -import sys - -# read the symbols, mapping each address to all known names - -raw = {} -with open("kernel.sym") as f: - for s in f: - adr, sym = s.strip().split() - adr = int(adr, 16) - if adr in raw: - raw[adr].append(sym) - else: - raw[adr] = [sym] - -# for a given address, we need to determine what range it -# lies in; there are fancy data structures or this, which -# we ignore; let's just sort the keys instead - -sort = sorted(raw.keys()) - -# now we can find the least key greater than an address; -# if there's none, we use the last address we know; doh! - -def least(x): - for i in range(len(sort)-1): - if sort[i] <= x < sort[i+1]: - return sort[i] - return sort[-1] - -# therefore we can decode a backtrace (ignoring address -# 0 since it's useless for xv6) - -for adr in sys.argv[1:]: - adr = int(adr, 16) - if adr != 0: - print adr, raw[least(adr)] From 020acb4f10832d0c003f24272b75a95859d4188f Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Thu, 23 Aug 2012 09:35:00 -0400 Subject: [PATCH 09/10] For the convenience of students --- printpcs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 printpcs diff --git a/printpcs b/printpcs new file mode 100755 index 0000000..32b33cc --- /dev/null +++ b/printpcs @@ -0,0 +1,11 @@ +#!/bin/sh + +# Decode the symbols from a panic stack trace on stdin + +if which addr2line +then + p="addr2line" +else + p="i386-jos-elf-addr2line" +fi +echo grep '^ ' | $p -e kernel $* From 951b77f7eced2165312d5c12d6256e874dba10f8 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 24 Aug 2012 14:51:52 -0400 Subject: [PATCH 10/10] Various fixes and improvements to printpcs Search for an addr2line that supports elf32-i386. Don't print the path of addr2line as a side-effect of which. Don't uselessly pipe "grep '^ '" to addr2line's stdin. Enable as many pretty-printing and otherwise helpful options as possible (this makes the output *much* more pleasant on modern addr2lines). --- printpcs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/printpcs b/printpcs index 32b33cc..81d039b 100755 --- a/printpcs +++ b/printpcs @@ -1,11 +1,14 @@ #!/bin/sh -# Decode the symbols from a panic stack trace on stdin +# Decode the symbols from a panic EIP list -if which addr2line -then - p="addr2line" -else - p="i386-jos-elf-addr2line" -fi -echo grep '^ ' | $p -e kernel $* +# Find a working addr2line +for p in i386-jos-elf-addr2line addr2line; do + if which $p 2>&1 >/dev/null && \ + $p -h 2>&1 | grep -q '\belf32-i386\b'; then + break + fi +done + +# Enable as much pretty-printing as this addr2line can do +$p $($p -h | grep ' -[aipsf] ' | awk '{print $1}') -e kernel "$@"