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

📄 printcmd.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
/* TYPENAME is either the name of a type, or an expression.  *//* ARGSUSED */static voidptype_command (typename, from_tty)     char *typename;     int from_tty;{  register struct type *type;  struct expression *expr;  register struct cleanup *old_chain;  if (typename)  {     expr = parse_expression (typename);     old_chain = make_cleanup (free_current_contents, &expr);     type = ptype_eval (expr);     if(type)     {	printf_filtered ("type = ");	type_print (type, "", stdout, 1);	printf_filtered ("\n");	do_cleanups (old_chain);     }     else     {	do_cleanups (old_chain);	whatis_exp (typename, 1);     }  }  else     whatis_exp (typename, 1);}#if MAINTENANCE_CMDS/* Dump details of a type specified either directly or indirectly.   Uses the same sort of type lookup mechanism as ptype_command()   and whatis_command(). */voidmaintenance_print_type (typename, from_tty)     char *typename;     int from_tty;{  register value val;  register struct type *type;  register struct cleanup *old_chain;  struct expression *expr;  if (typename != NULL)  {    expr = parse_expression (typename);    old_chain = make_cleanup (free_current_contents, &expr);    if (expr -> elts[0].opcode == OP_TYPE)      {	/* The user expression names a type directly, just use that type. */	type = expr -> elts[1].type;      }    else      {	/* The user expression may name a type indirectly by naming an	   object of that type.  Find that indirectly named type. */	val = evaluate_type (expr);	type = VALUE_TYPE (val);      }    if (type != NULL)      {	recursive_dump_type (type, 0);      }    do_cleanups (old_chain);  }}#endif	/* MAINTENANCE_CMDS *//* Add an expression to the auto-display chain.   Specify the expression.  */static voiddisplay_command (exp, from_tty)     char *exp;     int from_tty;{  struct format_data fmt;  register struct expression *expr;  register struct display *new;  if (exp == 0)    {      do_displays ();      return;    }  if (*exp == '/')    {      exp++;      fmt = decode_format (&exp, 0, 0);      if (fmt.size && fmt.format == 0)	fmt.format = 'x';      if (fmt.format == 'i' || fmt.format == 's')	fmt.size = 'b';    }  else    {      fmt.format = 0;      fmt.size = 0;      fmt.count = 0;    }  innermost_block = 0;  expr = parse_expression (exp);  new = (struct display *) xmalloc (sizeof (struct display));  new->exp = expr;  new->block = innermost_block;  new->next = display_chain;  new->number = ++display_number;  new->format = fmt;  new->status = enabled;  display_chain = new;  if (from_tty && target_has_execution)    do_one_display (new);  dont_repeat ();}static voidfree_display (d)     struct display *d;{  free ((PTR)d->exp);  free ((PTR)d);}/* Clear out the display_chain.   Done when new symtabs are loaded, since this invalidates   the types stored in many expressions.  */voidclear_displays (){  register struct display *d;  while (d = display_chain)    {      free ((PTR)d->exp);      display_chain = d->next;      free ((PTR)d);    }}/* Delete the auto-display number NUM.  */static voiddelete_display (num)     int num;{  register struct display *d1, *d;  if (!display_chain)    error ("No display number %d.", num);  if (display_chain->number == num)    {      d1 = display_chain;      display_chain = d1->next;      free_display (d1);    }  else    for (d = display_chain; ; d = d->next)      {	if (d->next == 0)	  error ("No display number %d.", num);	if (d->next->number == num)	  {	    d1 = d->next;	    d->next = d1->next;	    free_display (d1);	    break;	  }      }}/* Delete some values from the auto-display chain.   Specify the element numbers.  */static voidundisplay_command (args, from_tty)     char *args;     int from_tty;{  register char *p = args;  register char *p1;  register int num;  if (args == 0)    {      if (query ("Delete all auto-display expressions? "))	clear_displays ();      dont_repeat ();      return;    }  while (*p)    {      p1 = p;      while (*p1 >= '0' && *p1 <= '9') p1++;      if (*p1 && *p1 != ' ' && *p1 != '\t')	error ("Arguments must be display numbers.");      num = atoi (p);      delete_display (num);      p = p1;      while (*p == ' ' || *p == '\t') p++;    }  dont_repeat ();}/* Display a single auto-display.     Do nothing if the display cannot be printed in the current context,   or if the display is disabled. */static voiddo_one_display (d)     struct display *d;{  int within_current_scope;  if (d->status == disabled)    return;  if (d->block)    within_current_scope = contained_in (get_selected_block (), d->block);  else    within_current_scope = 1;  if (!within_current_scope)    return;  current_display_number = d->number;  printf_filtered ("%d: ", d->number);  if (d->format.size)    {      CORE_ADDR addr;            printf_filtered ("x/");      if (d->format.count != 1)	printf_filtered ("%d", d->format.count);      printf_filtered ("%c", d->format.format);      if (d->format.format != 'i' && d->format.format != 's')	printf_filtered ("%c", d->format.size);      printf_filtered (" ");      print_expression (d->exp, stdout);      if (d->format.count != 1)	printf_filtered ("\n");      else	printf_filtered ("  ");            addr = value_as_pointer (evaluate_expression (d->exp));      if (d->format.format == 'i')	addr = ADDR_BITS_REMOVE (addr);            do_examine (d->format, addr);    }  else    {      if (d->format.format)	printf_filtered ("/%c ", d->format.format);      print_expression (d->exp, stdout);      printf_filtered (" = ");      print_formatted (evaluate_expression (d->exp),		       d->format.format, d->format.size);      printf_filtered ("\n");    }  fflush (stdout);  current_display_number = -1;}/* Display all of the values on the auto-display chain which can be   evaluated in the current scope.  */voiddo_displays (){  register struct display *d;  for (d = display_chain; d; d = d->next)    do_one_display (d);}/* Delete the auto-display which we were in the process of displaying.   This is done when there is an error or a signal.  */voiddisable_display (num)     int num;{  register struct display *d;  for (d = display_chain; d; d = d->next)    if (d->number == num)      {	d->status = disabled;	return;      }  printf ("No display number %d.\n", num);}  voiddisable_current_display (){  if (current_display_number >= 0)    {      disable_display (current_display_number);      fprintf (stderr, "Disabling display %d to avoid infinite recursion.\n",	       current_display_number);    }  current_display_number = -1;}static voiddisplay_info (ignore, from_tty)     char *ignore;     int from_tty;{  register struct display *d;  if (!display_chain)    printf ("There are no auto-display expressions now.\n");  else      printf_filtered ("Auto-display expressions now in effect:\n\Num Enb Expression\n");  for (d = display_chain; d; d = d->next)    {      printf_filtered ("%d:   %c  ", d->number, "ny"[(int)d->status]);      if (d->format.size)	printf_filtered ("/%d%c%c ", d->format.count, d->format.size,		d->format.format);      else if (d->format.format)	printf_filtered ("/%c ", d->format.format);      print_expression (d->exp, stdout);      if (d->block && !contained_in (get_selected_block (), d->block))	printf_filtered (" (cannot be evaluated in the current context)");      printf_filtered ("\n");      fflush (stdout);    }}static voidenable_display (args, from_tty)     char *args;     int from_tty;{  register char *p = args;  register char *p1;  register int num;  register struct display *d;  if (p == 0)    {      for (d = display_chain; d; d = d->next)	d->status = enabled;    }  else    while (*p)      {	p1 = p;	while (*p1 >= '0' && *p1 <= '9')	  p1++;	if (*p1 && *p1 != ' ' && *p1 != '\t')	  error ("Arguments must be display numbers.");		num = atoi (p);		for (d = display_chain; d; d = d->next)	  if (d->number == num)	    {	      d->status = enabled;	      goto win;	    }	printf ("No display number %d.\n", num);      win:	p = p1;	while (*p == ' ' || *p == '\t')	  p++;      }}/* ARGSUSED */static voiddisable_display_command (args, from_tty)     char *args;     int from_tty;{  register char *p = args;  register char *p1;  register struct display *d;  if (p == 0)    {      for (d = display_chain; d; d = d->next)	d->status = disabled;    }  else    while (*p)      {	p1 = p;	while (*p1 >= '0' && *p1 <= '9')	  p1++;	if (*p1 && *p1 != ' ' && *p1 != '\t')	  error ("Arguments must be display numbers.");		disable_display (atoi (p));	p = p1;	while (*p == ' ' || *p == '\t')	  p++;      }}/* Print the value in stack frame FRAME of a variable   specified by a struct symbol.  */voidprint_variable_value (var, frame, stream)     struct symbol *var;     FRAME frame;     FILE *stream;{  value val = read_var_value (var, frame);  value_print (val, stream, 0, Val_pretty_default);}/* Print the arguments of a stack frame, given the function FUNC   running in that frame (as a symbol), the info on the frame,   and the number of args according to the stack frame (or -1 if unknown).  *//* References here and elsewhere to "number of args according to the   stack frame" appear in all cases to refer to "number of ints of args   according to the stack frame".  At least for VAX, i386, isi.  *//* Print arguments of a stack frame that have debugging symbols. */static intprint_frame_named_args(func, fi, offp, stream)  struct symbol *func;  struct frame_info *fi;  long *offp;  FILE *stream;{  struct block *b = SYMBOL_BLOCK_VALUE (func);  int nsyms = BLOCK_NSYMS (b);  int first = 1;  register int i;  register struct symbol *sym;  register value val;  int arg_size;  /* Number of ints of arguments that we have printed so far.  */  int args_printed = 0;  for (i = 0; i < nsyms; i++)    {      QUIT;      sym = BLOCK_SYM (b, i);      /* Keep track of the highest stack argument offset seen, and	 skip over any kinds of symbols we don't care about.  */      switch (SYMBOL_CLASS (sym)) {      case LOC_ARG:      case LOC_REF_ARG:	{	  long current_offset = SYMBOL_VALUE (sym);	  arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));	  	  /* Compute address of next argument by adding the size of	     this argument and rounding to an int boundary.  */	  current_offset	    = ((current_offset + arg_size + sizeof (int) - 1)	       & ~(sizeof (int) - 1));	  /* If this is the highest offset seen yet, remember it.  */	  if (current_offset > *offp)	    *offp = current_offset;	  /* Add the number of ints we're about to print to args_printed.  */	  args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);	}      /* We care about types of symbols, but don't need to keep track of	 stack offsets in them.  */      case LOC_REGPARM:      case LOC_LOCAL_ARG:	break;      /* Other types of symbols we just skip over.  */      default:	continue;      }      /* We have to re-look-up the symbol because arguments often have	 two entries (one a parameter, one a register or local), and the one	 we want is the non-parm, which lookup_symbol will find for	 us.  After this, sym could be any SYMBOL_CLASS...  */#ifdef IBM6000_TARGET      /* AIX/RS6000 implements a concept of traceback tables, in which case         it creates nameless parameters. Looking for those parameter symbols         will result in an error. */      if ( *SYMBOL_NAME (sym))#endif      sym = lookup_symbol (SYMBOL_NAME (sym),		    b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);      /* Print the current arg.  */      if (! first)	fprintf_filtered (stream, ", ");      wrap_here ("    ");      fprint_symbol (stream, SYMBOL_NAME (sym));      fputs_filtered ("=", stream);      /* Avoid value_print because it will deref ref parameters.  We just	 want to print their addresses.  Print ??? for args whose address	 we do not know.  We pass 2 as "recurse" to val_print because our	 standard indentation here is 4 spaces, and val_print indents	 2 for each recurse.  */      val = read_var_value (sym, FRAME_INFO_ID (fi));      if (val)        val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),		   stream, 0, 0, 2, Val_no_prettyprint);      else	fputs_filtered ("???", stream);      first = 0;    }  return args_printed;}/* Print the arguments of a stack frame, given the function FUNC   running in that frame (as a symbol), the info on the frame,   and the number of args according to the stack frame (or -1 if unknown).  *//* References here and elsewhere to "number of args according to the   stack frame" appear in all cases to refer to "number of ints of args   according to the stack frame".  At least for VAX, i386, isi.  */static int default_funargs = 4;voidprint_frame_args (func, fi, num, stream)     struct symbol *func;     struct frame_info *fi;     int num;     FILE *stream;{  long offset = FRAME_ARGS_SKIP;  if (func)

⌨️ 快捷键说明

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