]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Improve correctness of backtrace library.
authorJoshua Wise <joshua@ainfvec.fac.cs.cmu.edu>
Sat, 3 Oct 2009 06:45:03 +0000 (02:45 -0400)
committerJoshua Wise <joshua@ainfvec.fac.cs.cmu.edu>
Sat, 3 Oct 2009 06:45:03 +0000 (02:45 -0400)
net/http/fs.c

index 832d3dddddf1672f47942df24f343f78f29f848a..2a63b4d7c777a7b95505571b4f05bf102f95765f 100644 (file)
@@ -51,7 +51,7 @@ void handle_regs(struct fs_file *file)
 
   len = snprintf(http_output_buffer, sizeof(http_output_buffer), "<html><pre>");
 
-  for (i = 0; i < NUM_REGISTERS; i++) {
+  for (i = 0; i < state_num_regs(); i++) {
     len += state_dump_reg(http_output_buffer + len, sizeof(http_output_buffer) - len, i);
   }
 
@@ -75,33 +75,35 @@ void handle_backtrace(struct fs_file *file)
   strcpy(buf, "<html><head><title>Backtrace</title></head><body><tt><pre>");
   len = strlen(buf);
 
-  bp = state_get_reg(STATE_REG_RIP);
+  bp = state_get_reg(longmode ? STATE_REG_RIP : STATE_REG_EIP);
 
   if (longmode)
     len += snprintf(buf + len, LEFT, "0x%08x%08x, from\n", (uint32_t)(bp >> 32), (uint32_t)bp);
   else
     len += snprintf(buf + len, LEFT, "0x%08x, from\n", (uint32_t)bp);
   
-  bp = state_get_reg(STATE_REG_RBP);
+  bp = state_get_reg(longmode ? STATE_REG_RBP : STATE_REG_EBP);
   
-  /* I never thought I'd do this again. */
+
+  outputf("Backtrace:");
   while ((peip = demap(bp+(longmode?8:4))) != 0x0 && i--)
   {
     if (longmode) {
-      next = *(uint64_t *)peip;
-      len += snprintf(buf + len, LEFT, "0x%08x%08x, from\n", (uint32_t)(next >> 32), (uint32_t)next);
+      uint64_t rip;
+      rip = *(uint64_t *)peip;
+      len += snprintf(buf + len, LEFT, "0x%08x%08x, from\n", (uint32_t)(rip >> 32), (uint32_t)rip);
     } else {
-      next = *(uint32_t *)peip;
-      len += snprintf(buf + len, LEFT, "0x%08x, from\n", (uint32_t)next);
+      len += snprintf(buf + len, LEFT, "0x%08x, from\n", *(uint32_t *)peip);
     }
+    outputf("   EIP: %08x", *(uint32_t *)peip);
 
     pebp = demap(bp);
-
-    if (!pebp)
+    if (!pebp || (bp & 3))
     {
       len += snprintf(buf + len, LEFT, "&lt;unreadable frame&gt;\n");
       break;
     }
+    outputf("   *EBP: %08x", *(uint32_t *)pebp);
 
     if (longmode)
       next = *(uint64_t *)pebp;
@@ -119,6 +121,8 @@ void handle_backtrace(struct fs_file *file)
 
   if (i == -1)
     len += snprintf(buf + len, LEFT, "...\n");
+  else if (bp && !peip)
+    len += snprintf(buf + len, LEFT, "&lt;unreadable fp @ %08x&gt;\n", (uint32_t) bp);
   else
     len += snprintf(buf + len, LEFT, "&lt;root&gt;");
 
This page took 0.027224 seconds and 4 git commands to generate.