⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dmp_kernel.c

📁 Minix3.11的源码。[MINIX 3是一个为高可靠性应用而设计的自由且简洁的类UNIX系统。]
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Debugging dump procedures for the kernel. */#include "inc.h"#include <timers.h>#include <ibm/interrupt.h>#include "../../kernel/const.h"#include "../../kernel/config.h"#include "../../kernel/debug.h"#include "../../kernel/type.h"#include "../../kernel/proc.h"#include "../../kernel/ipc.h"#define click_to_round_k(n) \	((unsigned) ((((unsigned long) (n) << CLICK_SHIFT) + 512) / 1024))/* Declare some local dump procedures. */FORWARD _PROTOTYPE( char *proc_name, (int proc_nr)		);FORWARD _PROTOTYPE( char *s_traps_str, (int flags)		);FORWARD _PROTOTYPE( char *s_flags_str, (int flags)		);FORWARD _PROTOTYPE( char *p_rts_flags_str, (int flags)		);/* Some global data that is shared among several dumping procedures.  * Note that the process table copy has the same name as in the kernel * so that most macros and definitions from proc.h also apply here. */PUBLIC struct proc proc[NR_TASKS + NR_PROCS];PUBLIC struct priv priv[NR_SYS_PROCS];PUBLIC struct boot_image image[NR_BOOT_PROCS];/*===========================================================================* *				timing_dmp				     * *===========================================================================*/PUBLIC void timing_dmp(){#if ! DEBUG_TIME_LOCKS  printf("Enable the DEBUG_TIME_LOCKS definition in src/kernel/config.h\n");#else  static struct lock_timingdata timingdata[TIMING_CATEGORIES];  int r, c, f, skipped = 0, printed = 0, maxlines = 23, x = 0;  static int offsetlines = 0;  if ((r = sys_getlocktimings(&timingdata[0])) != OK) {      report("IS","warning: couldn't get copy of lock timings", r);      return;  }   for(c = 0; c < TIMING_CATEGORIES; c++) {	int b;	if (!timingdata[c].lock_timings_range[0] || !timingdata[c].binsize)		continue;	x = printf("%-*s: misses %lu, resets %lu, measurements %lu: ",	TIMING_NAME, timingdata[c].names,		timingdata[c].misses,		timingdata[c].resets,		timingdata[c].measurements);	for(b = 0; b < TIMING_POINTS; b++) {		int w;		if (!timingdata[c].lock_timings[b])			continue;		x += (w = printf(" %5d: %5d", timingdata[c].lock_timings_range[0] +			b*timingdata[c].binsize,			timingdata[c].lock_timings[b]));	 	if (x + w >= 80) { printf("\n"); x = 0; }	}  	if (x > 0) printf("\n");  }#endif}/*===========================================================================* *				kmessages_dmp				     * *===========================================================================*/PUBLIC void kmessages_dmp(){  struct kmessages kmess;		/* get copy of kernel messages */  char print_buf[KMESS_BUF_SIZE+1];	/* this one is used to print */  int start;				/* calculate start of messages */  int r;  /* Try to get a copy of the kernel messages. */  if ((r = sys_getkmessages(&kmess)) != OK) {      report("IS","warning: couldn't get copy of kmessages", r);      return;  }  /* Try to print the kernel messages. First determine start and copy the   * buffer into a print-buffer. This is done because the messages in the   * copy may wrap (the kernel buffer is circular).   */  start = ((kmess.km_next + KMESS_BUF_SIZE) - kmess.km_size) % KMESS_BUF_SIZE;  r = 0;  while (kmess.km_size > 0) {  	print_buf[r] = kmess.km_buf[(start+r) % KMESS_BUF_SIZE];  	r ++;  	kmess.km_size --;  }  print_buf[r] = 0;		/* make sure it terminates */  printf("Dump of all messages generated by the kernel.\n\n");   printf("%s", print_buf);		/* print the messages */}/*===========================================================================* *				monparams_dmp				     * *===========================================================================*/PUBLIC void monparams_dmp(){  char val[1024];  char *e;  int r;  /* Try to get a copy of the boot monitor parameters. */  if ((r = sys_getmonparams(val, sizeof(val))) != OK) {      report("IS","warning: couldn't get copy of monitor params", r);      return;  }  /* Append new lines to the result. */  e = val;  do {	e += strlen(e);	*e++ = '\n';  } while (*e != 0);   /* Finally, print the result. */  printf("Dump of kernel environment strings set by boot monitor.\n");  printf("\n%s\n", val);}/*===========================================================================* *				irqtab_dmp				     * *===========================================================================*/PUBLIC void irqtab_dmp(){  int i,r;  struct irq_hook irq_hooks[NR_IRQ_HOOKS];  struct irq_hook *e;	/* irq tab entry */  char *irq[] = {  	"clock",	/* 00 */  	"keyboard",	/* 01 */  	"cascade",	/* 02 */  	"rs232",	/* 03 */  	"rs232",	/* 04 */  	"NIC(eth)",	/* 05 */  	"floppy",	/* 06 */  	"printer",	/* 07 */  	"",	/* 08 */  	"",	/* 09 */  	"",	/* 10 */  	"",	/* 11 */  	"",	/* 12 */  	"",	/* 13 */  	"at_wini_0",	/* 14 */  	"at_wini_1",	/* 15 */  };  if ((r = sys_getirqhooks(irq_hooks)) != OK) {      report("IS","warning: couldn't get copy of irq hooks", r);      return;  }  printf("IRQ policies dump shows use of kernel's IRQ hooks.\n");  printf("-h.id- -proc.nr- -IRQ vector (nr.)- -policy- -notify id-\n");  for (i=0; i<NR_IRQ_HOOKS; i++) {  	e = &irq_hooks[i];  	printf("%3d", i);  	if (e->proc_nr==NONE) {  	    printf("    <unused>\n");  	    continue;  	}  	printf("%10d  ", e->proc_nr);   	printf("    %9.9s (%02d) ", irq[e->irq], e->irq);   	printf("  %s", (e->policy & IRQ_REENABLE) ? "reenable" : "    -   ");  	printf("   %d\n", e->notify_id);  }  printf("\n");}/*===========================================================================* *				image_dmp				     * *===========================================================================*/PUBLIC void image_dmp(){  int m, i,j,r;  struct boot_image *ip;  static char ipc_to[BITCHUNK_BITS*2];	  if ((r = sys_getimage(image)) != OK) {      report("IS","warning: couldn't get copy of image table", r);      return;  }  printf("Image table dump showing all processes included in system image.\n");  printf("---name-- -nr- -flags- -traps- -sq- ----pc- -stack- -ipc_to[0]--------\n");  for (m=0; m<NR_BOOT_PROCS; m++) {       ip = &image[m];        for (i=j=0; i < BITCHUNK_BITS; i++, j++) {       	    ipc_to[j] = (ip->ipc_to & (1<<i)) ? '1' : '0';       	    if (i % 8 == 7) ipc_to[++j] = ' ';       	}        ipc_to[j] = '\0';      printf("%8s %4d   %s   %s  %3d %7lu %7lu   %s\n",          ip->proc_name, ip->proc_nr, 	       s_flags_str(ip->flags), s_traps_str(ip->trap_mask), 	ip->priority, (long)ip->initial_pc, ip->stksize, ipc_to);   }  printf("\n");}/*===========================================================================* *				sched_dmp    				     * *===========================================================================*/PUBLIC void sched_dmp(){  struct proc *rdy_head[NR_SCHED_QUEUES];  struct kinfo kinfo;  register struct proc *rp;  vir_bytes ptr_diff;  int r;  /* First obtain a scheduling information. */  if ((r = sys_getschedinfo(proc, rdy_head)) != OK) {      report("IS","warning: couldn't get copy of process table", r);      return;  }  /* Then obtain kernel addresses to correct pointer information. */  if ((r = sys_getkinfo(&kinfo)) != OK) {      report("IS","warning: couldn't get kernel addresses", r);      return;  }  /* Update all pointers. Nasty pointer algorithmic ... */  ptr_diff = (vir_bytes) proc - (vir_bytes) kinfo.proc_addr;  for (r=0;r<NR_SCHED_QUEUES; r++)      if (rdy_head[r] != NIL_PROC)          rdy_head[r] =               (struct proc *)((vir_bytes) rdy_head[r] + ptr_diff);  for (rp=BEG_PROC_ADDR; rp < END_PROC_ADDR; rp++)      if (rp->p_nextready != NIL_PROC)          rp->p_nextready =               (struct proc *)((vir_bytes) rp->p_nextready + ptr_diff);  /* Now show scheduling queues. */  printf("Dumping scheduling queues.\n");  for (r=0;r<NR_SCHED_QUEUES; r++) {      rp = rdy_head[r];      if (!rp) continue;      printf("%2d: ", r);      while (rp != NIL_PROC) {          printf("%3d ", rp->p_nr);          rp = rp->p_nextready;      }      printf("\n");  }  printf("\n");}/*===========================================================================* *				kenv_dmp				     * *===========================================================================*/PUBLIC void kenv_dmp(){    struct kinfo kinfo;    struct machine machine;    int r;    if ((r = sys_getkinfo(&kinfo)) != OK) {    	report("IS","warning: couldn't get copy of kernel info struct", r);    	return;    }    if ((r = sys_getmachine(&machine)) != OK) {    	report("IS","warning: couldn't get copy of kernel machine struct", r);    	return;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -