]> Devi Nivas Git - cs3210-lab0.git/commitdiff
save process name for debugging
authorrsc <rsc>
Wed, 8 Aug 2007 08:38:11 +0000 (08:38 +0000)
committerrsc <rsc>
Wed, 8 Aug 2007 08:38:11 +0000 (08:38 +0000)
proc.h
sysfile.c
trap.c

diff --git a/proc.h b/proc.h
index 3f0c0068aee5f6198f14d5f21883a5e33e20cbf8..2848ecdf038146a9d0001b7bdfef6746b74ab77b 100644 (file)
--- a/proc.h
+++ b/proc.h
@@ -40,6 +40,7 @@ struct proc {
   struct inode *cwd;        // Current directory
   struct jmpbuf jmpbuf;     // Jump here to run process
   struct trapframe *tf;     // Trap frame for current interrupt
+  char name[16];            // Process name (debugging)
 };
 
 // Process memory is laid out contiguously:
index 45731f91d99dc93d8ce08f709deaf2dcbc3c688e..475c907a4e36e0ad11c3de37bd21d37a58dfb220 100644 (file)
--- a/sysfile.c
+++ b/sysfile.c
@@ -322,7 +322,7 @@ sys_exec(void)
   struct elfhdr elf;
   struct proghdr ph;
   char *mem = 0;
-  char *path, *s;
+  char *path, *s, *last;
   uint argv;
   
   if(argstr(0, &path) < 0 || argint(1, (int*)&argv) < 0)
@@ -399,6 +399,12 @@ sys_exec(void)
   }
   *(uint*)(mem + p1) = 0;
 
+  // Save name for debugging.
+  for(last=s=path; *s; s++)
+    if(*s == '/')
+      last = s+1;
+  safestrcpy(cp->name, last, sizeof cp->name);
+
   // commit to the new image.
   kfree(cp->mem, cp->sz);
   cp->sz = sz;
@@ -419,7 +425,7 @@ sys_exec(void)
   }
 
   iput(ip);
-
+  
   cp->tf->eip = elf.entry;
   cp->tf->esp = sp;
   setupsegs(cp);
diff --git a/trap.c b/trap.c
index aafaadf788fa8fb3ad2da001b54979cfc6114388..0625e5609822928feb787b52564b84652d99fba9 100644 (file)
--- a/trap.c
+++ b/trap.c
@@ -80,10 +80,10 @@ trap(struct trapframe *tf)
     break;
     
   default:
-    if(curproc[cpu()]) {
+    if(cp) {
       // Assume process divided by zero or dereferenced null, etc.
-      cprintf("pid %d: unhandled trap %d on cpu %d eip %x -- kill proc\n",
-              curproc[cpu()]->pid, v, cpu(), tf->eip);
+      cprintf("pid %d %s: unhandled trap %d on cpu %d eip %x -- kill proc\n",
+              cp->pid, cp->name, v, cpu(), tf->eip);
       proc_exit();
     }