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

📄 infcmd.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
  dont_repeat ();  exec_path = strsave (get_in_environ (inferior_environ, path_var_name));  mod_path (dirname, &exec_path);  set_in_environ (inferior_environ, path_var_name, exec_path);  free (exec_path);  if (from_tty)    path_info ((char *)NULL, from_tty);}CORE_ADDRread_pc (){  return ADDR_BITS_REMOVE ((CORE_ADDR) read_register (PC_REGNUM));}voidwrite_pc (val)     CORE_ADDR val;{  write_register (PC_REGNUM, (long) val);#ifdef NPC_REGNUM  write_register (NPC_REGNUM, (long) val+4);#endif  pc_changed = 0;}const char * const reg_names[] = REGISTER_NAMES;/* Print out the machine register regnum. If regnum is -1,   print all registers (fpregs == 1) or all non-float registers   (fpregs == 0).   For most machines, having all_registers_info() print the   register(s) one per line is good enough. If a different format   is required, (eg, for MIPS or Pyramid 90x, which both have   lots of regs), or there is an existing convention for showing   all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)   to provide that format.  */  #if !defined (DO_REGISTERS_INFO)#define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)static voiddo_registers_info (regnum, fpregs)     int regnum;     int fpregs;{  register int i;  for (i = 0; i < NUM_REGS; i++)    {      char raw_buffer[MAX_REGISTER_RAW_SIZE];      char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];      /* Decide between printing all regs, nonfloat regs, or specific reg.  */      if (regnum == -1) {	if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)	  continue;      } else {        if (i != regnum)	  continue;      }      fputs_filtered (reg_names[i], stdout);      print_spaces_filtered (15 - strlen (reg_names[i]), stdout);      /* Get the data in raw format, then convert also to virtual format.  */      if (read_relative_register_raw_bytes (i, raw_buffer))	{	  printf_filtered ("Invalid register contents\n");	  continue;	}            REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer);      /* If virtual format is floating, print it that way, and in raw hex.  */      if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT	  && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))	{	  register int j;	  val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0,		     stdout, 0, 1, 0, Val_pretty_default);	  printf_filtered ("\t(raw 0x");	  for (j = 0; j < REGISTER_RAW_SIZE (i); j++)	    printf_filtered ("%02x", (unsigned char)raw_buffer[j]);	  printf_filtered (")");	}/* FIXME!  val_print probably can handle all of these cases now...  */      /* Else if virtual format is too long for printf,	 print in hex a byte at a time.  */      else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long))	{	  register int j;	  printf_filtered ("0x");	  for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)	    printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);	}      /* Else print as integer in hex and in decimal.  */      else	{	  val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,		     stdout, 'x', 1, 0, Val_pretty_default);	  printf_filtered ("\t");	  val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,		     stdout,   0, 1, 0, Val_pretty_default);	}      /* The SPARC wants to print even-numbered float regs as doubles	 in addition to printing them as floats.  */#ifdef PRINT_REGISTER_HOOK      PRINT_REGISTER_HOOK (i);#endif      printf_filtered ("\n");    }}#endif /* no DO_REGISTERS_INFO.  */static voidregisters_info (addr_exp, fpregs)     char *addr_exp;     int fpregs;{  int regnum;  register char *end;  if (!target_has_registers)    error ("The program has no registers now.");  if (!addr_exp)    {      DO_REGISTERS_INFO(-1, fpregs);      return;    }  do    {            if (addr_exp[0] == '$')	addr_exp++;      end = addr_exp;      while (*end != '\0' && *end != ' ' && *end != '\t')	++end;      for (regnum = 0; regnum < NUM_REGS; regnum++)	if (!strncmp (addr_exp, reg_names[regnum], end - addr_exp)	    && strlen (reg_names[regnum]) == end - addr_exp)	  goto found;      if (*addr_exp >= '0' && *addr_exp <= '9')	regnum = atoi (addr_exp);		/* Take a number */      if (regnum >= NUM_REGS)		/* Bad name, or bad number */	error ("%.*s: invalid register", end - addr_exp, addr_exp);found:      DO_REGISTERS_INFO(regnum, fpregs);      addr_exp = end;      while (*addr_exp == ' ' || *addr_exp == '\t')	++addr_exp;    } while (*addr_exp != '\0');}static voidall_registers_info (addr_exp, from_tty)     char *addr_exp;     int from_tty;{  registers_info (addr_exp, 1);}static voidnofp_registers_info (addr_exp, from_tty)     char *addr_exp;     int from_tty;{  registers_info (addr_exp, 0);}/* * TODO: * Should save/restore the tty state since it might be that the * program to be debugged was started on this tty and it wants * the tty in some state other than what we want.  If it's running * on another terminal or without a terminal, then saving and * restoring the tty state is a harmless no-op. * This only needs to be done if we are attaching to a process. *//*   attach_command --   takes a program started up outside of gdb and ``attaches'' to it.   This stops it cold in its tracks and allows us to start debugging it.   and wait for the trace-trap that results from attaching.  */voidattach_command (args, from_tty)     char *args;     int from_tty;{  dont_repeat ();			/* Not for the faint of heart */  if (target_has_execution)    {      if (query ("A program is being debugged already.  Kill it? "))	target_kill ();      else	error ("Inferior not killed.");    }  target_attach (args, from_tty);  /* Set up the "saved terminal modes" of the inferior     based on what modes we are starting it with.  */  target_terminal_init ();  /* Install inferior's terminal modes.  */  target_terminal_inferior ();  /* Set up execution context to know that we should return from     wait_for_inferior as soon as the target reports a stop.  */  init_wait_for_inferior ();  clear_proceed_status ();  stop_soon_quietly = 1;  wait_for_inferior ();#ifdef SOLIB_ADD  /* Add shared library symbols from the newly attached process, if any.  */  SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);#endif  normal_stop ();}/* * detach_command -- * takes a program previously attached to and detaches it. * The program resumes execution and will no longer stop * on signals, etc.  We call clear_breakpoints() to make sure * all the breakpoints are out when we let it go.  Otherwise, * the program will die when it hits one.  For this to work, * it may be necessary for the process to have been * previously attached.  It *might* work if the program was * started via the normal ptrace (PTRACE_TRACEME). */static voiddetach_command (args, from_tty)     char *args;     int from_tty;{  dont_repeat ();			/* Not for the faint of heart */  clear_breakpoints();  target_detach (args, from_tty);}/* ARGSUSED */static voidfloat_info (addr_exp, from_tty)     char *addr_exp;     int from_tty;{#ifdef FLOAT_INFO	FLOAT_INFO;#else	printf_filtered ("No floating point info available for this processor.\n");#endif}/* ARGSUSED */static voidunset_command (args, from_tty)     char *args;     int from_tty;{  printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");  help_list (unsetlist, "unset ", -1, stdout);}void_initialize_infcmd (){  struct cmd_list_element *c;    add_com ("tty", class_run, tty_command,	   "Set terminal for future runs of program being debugged.");  add_show_from_set    (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,		  "Set arguments to give program being debugged when it is started.\n\Follow this command with any number of args, to be passed to the program.",		  &setlist),     &showlist);  c = add_cmd    ("environment", no_class, environment_info,     "The environment to give the program, or one variable's value.\n\With an argument VAR, prints the value of environment variable VAR to\n\give the program being debugged.  With no arguments, prints the entire\n\environment to be given to the program.", &showlist);  c->completer = noop_completer;  add_prefix_cmd ("unset", no_class, unset_command,		  "Complement to certain \"set\" commands",		  &unsetlist, "unset ", 0, &cmdlist);    c = add_cmd ("environment", class_run, unset_environment_command,	      "Cancel environment variable VAR for the program.\n\This does not affect the program until the next \"run\" command.",	   &unsetlist);  c->completer = noop_completer;  c = add_cmd ("environment", class_run, set_environment_command,	       "Set environment variable value to give the program.\n\Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\VALUES of environment variables are uninterpreted strings.\n\This does not affect the program until the next \"run\" command.",	   &setlist);  c->completer = noop_completer;   add_com ("path", class_files, path_command,       "Add directory DIR(s) to beginning of search path for object files.\n\$cwd in the path means the current working directory.\n\This path is equivalent to the $PATH shell variable.  It is a list of\n\directories, separated by colons.  These directories are searched to find\n\fully linked executable files and separately compiled object files as needed.");  c = add_cmd ("paths", no_class, path_info,	    "Current search path for finding object files.\n\$cwd in the path means the current working directory.\n\This path is equivalent to the $PATH shell variable.  It is a list of\n\directories, separated by colons.  These directories are searched to find\n\fully linked executable files and separately compiled object files as needed.", &showlist);  c->completer = noop_completer; add_com ("attach", class_run, attach_command, 	   "Attach to a process or file outside of GDB.\n\This command attaches to another target, of the same type as your last\n\`target' command (`info files' will show your target stack).\n\The command may take as argument a process id or a device file.\n\For a process id, you must have permission to send the process a signal,\n\and it must have the same effective uid as the debugger.\n\When using \"attach\", you should use the \"file\" command to specify\n\the program running in the process, and to load its symbol table.");  add_com ("detach", class_run, detach_command,	   "Detach a process or file previously attached.\n\If a process, it is no longer traced, and it continues its execution.  If you\n\were debugging a file, the file is closed and gdb no longer accesses it.");  add_com ("signal", class_run, signal_command,	   "Continue program giving it signal number SIGNUMBER.");  add_com ("stepi", class_run, stepi_command,	   "Step one instruction exactly.\n\Argument N means do this N times (or till program stops for another reason).");  add_com_alias ("si", "stepi", class_alias, 0);  add_com ("nexti", class_run, nexti_command,	   "Step one instruction, but proceed through subroutine calls.\n\Argument N means do this N times (or till program stops for another reason).");  add_com_alias ("ni", "nexti", class_alias, 0);  add_com ("finish", class_run, finish_command,	   "Execute until selected stack frame returns.\n\Upon return, the value returned is printed and put in the value history.");  add_com ("next", class_run, next_command,	   "Step program, proceeding through subroutine calls.\n\Like the \"step\" command as long as subroutine calls do not happen;\n\when they do, the call is treated as one instruction.\n\Argument N means do this N times (or till program stops for another reason).");  add_com_alias ("n", "next", class_run, 1);  add_com ("step", class_run, step_command,	   "Step program until it reaches a different source line.\n\Argument N means do this N times (or till program stops for another reason).");  add_com_alias ("s", "step", class_run, 1);  add_com ("until", class_run, until_command,	   "Execute until the program reaches a source line greater than the current\n\or a specified line or address or function (same args as break command).\n\Execution will also stop upon exit from the current stack frame.");  add_com_alias ("u", "until", class_run, 1);    add_com ("jump", class_run, jump_command,	   "Continue program being debugged at specified line or address.\n\Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\for an address to start at.");  add_com ("continue", class_run, continue_command,	   "Continue program being debugged, after signal or breakpoint.\n\If proceeding from breakpoint, a number N may be used as an argument:\n\then the same breakpoint won't break until the Nth time it is reached.");  add_com_alias ("c", "cont", class_run, 1);  add_com_alias ("fg", "cont", class_run, 1);  add_com ("run", class_run, run_command,	   "Start debugged program.  You may specify arguments to give it.\n\Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\To cancel previous arguments and run with no arguments,\n\use \"set args\" without arguments.");  add_com_alias ("r", "run", class_run, 1);  add_info ("registers", nofp_registers_info,    "List of integer registers and their contents, for selected stack frame.\n\Register name as argument means describe only that register.");  add_info ("all-registers", all_registers_info,"List of all registers and their contents, for selected stack frame.\n\Register name as argument means describe only that register.");  add_info ("program", program_info,	    "Execution status of the program.");  add_info ("float", float_info,	    "Print the status of the floating point unit\n");  inferior_args = savestring ("", 1);	/* Initially no args */  inferior_environ = make_environ ();  init_environ (inferior_environ);}

⌨️ 快捷键说明

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