📄 main.c
字号:
char *p; change = 0; for (p = current_directory; *p;) { if (!strncmp (p, "/./", 2) && (p[2] == 0 || p[2] == '/')) strcpy (p, p + 2); else if (!strncmp (p, "/..", 3) && (p[3] == 0 || p[3] == '/') && p != current_directory) { char *q = p; while (q != current_directory && q[-1] != '/') q--; if (q != current_directory) { strcpy (q-1, p+3); p = q-1; } } else p++; } } forget_cached_source_info (); if (from_tty) pwd_command ((char *) 0, 1);}/* ARGSUSED */static voidsource_command (args, from_tty) char *args; int from_tty;{ FILE *stream; struct cleanup *cleanups; char *file = args; if (file == 0) /* Let source without arguments read .gdbinit. */ file = gdbinit; file = tilde_expand (file); make_cleanup (free, file); stream = fopen (file, "r"); if (stream == 0) { char *cp = xmalloc(strlen(file) + 5); sprintf(cp, "%s.gdb", file); make_cleanup (free, cp); stream = fopen(cp, "r"); if (stream == 0) perror_with_name (file); } cleanups = make_cleanup (fclose, stream); read_command_file (stream); do_cleanups (cleanups);}/* ARGSUSED */static voidecho_command (text, from_tty) char *text; int from_tty;{ char *p = text; register int c; if (text) while (c = *p++) { if (c == '\\') { /* \ at end of argument is used after spaces so they won't be lost. */ if (*p == 0) return; c = parse_escape (&p); if (c >= 0) printf_filtered ("%c", c); } else printf_filtered ("%c", c); } /* Force this output to appear now. */ wrap_here (""); fflush (stdout);}/* Functions to manipulate command line editing control variables. *//* Number of commands to print in each call to show_commands. */#define Hist_print 10static voidshow_commands (args, from_tty) char *args; int from_tty;{ /* Index for history commands. Relative to history_base. */ int offset; /* Number of the history entry which we are planning to display next. Relative to history_base. */ static int num = 0; /* The first command in the history which doesn't exist (i.e. one more than the number of the last command). Relative to history_base. */ int hist_len; extern struct _hist_entry *history_get PARAMS ((int)); extern int history_base; /* Print out some of the commands from the command history. */ /* First determine the length of the history list. */ hist_len = history_size; for (offset = 0; offset < history_size; offset++) { if (!history_get (history_base + offset)) { hist_len = offset; break; } } if (args) { if (args[0] == '+' && args[1] == '\0') /* "info editing +" should print from the stored position. */ ; else /* "info editing <exp>" should print around command number <exp>. */ num = (parse_and_eval_address (args) - history_base) - Hist_print / 2; } /* "show commands" means print the last Hist_print commands. */ else { num = hist_len - Hist_print; } if (num < 0) num = 0; /* If there are at least Hist_print commands, we want to display the last Hist_print rather than, say, the last 6. */ if (hist_len - num < Hist_print) { num = hist_len - Hist_print; if (num < 0) num = 0; } for (offset = num; offset < num + Hist_print && offset < hist_len; offset++) { printf_filtered ("%5d %s\n", history_base + offset, (history_get (history_base + offset))->line); } /* The next command we want to display is the next one that we haven't displayed yet. */ num += Hist_print; /* If the user repeats this command with return, it should do what "show commands +" does. This is unnecessary if arg is null, because "show commands +" is not useful after "show commands". */ if (from_tty && args) { args[0] = '+'; args[1] = '\0'; }}/* Called by do_setshow_command. *//* ARGSUSED */static voidset_history_size_command (args, from_tty, c) char *args; int from_tty; struct cmd_list_element *c;{ if (history_size == UINT_MAX) unstifle_history (); else if (history_size >= 0) stifle_history (history_size); else { history_size = UINT_MAX; error ("History size must be non-negative"); }}/* ARGSUSED */static voidset_history (args, from_tty) char *args; int from_tty;{ printf ("\"set history\" must be followed by the name of a history subcommand.\n"); help_list (sethistlist, "set history ", -1, stdout);}/* ARGSUSED */static voidshow_history (args, from_tty) char *args; int from_tty;{ cmd_show_list (showhistlist, from_tty, "");}int info_verbose = 0; /* Default verbose msgs off *//* Called by do_setshow_command. An elaborate joke. *//* ARGSUSED */static void set_verbose (args, from_tty, c) char *args; int from_tty; struct cmd_list_element *c;{ char *cmdname = "verbose"; struct cmd_list_element *showcmd; showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1); if (info_verbose) { c->doc = "Set verbose printing of informational messages."; showcmd->doc = "Show verbose printing of informational messages."; } else { c->doc = "Set verbosity."; showcmd->doc = "Show verbosity."; }}static voidfloat_handler (signo)int signo;{ /* This message is based on ANSI C, section 4.7. Note that integer divide by zero causes this, so "float" is a misnomer. */ error ("Erroneous arithmetic operation.");}/* Return whether we are running a batch file or from terminal. */intbatch_mode (){ return !(instream == stdin && ISATTY (stdin));}static voidinitialize_cmd_lists (){ cmdlist = NULL; infolist = NULL; enablelist = NULL; disablelist = NULL; deletelist = NULL; enablebreaklist = NULL; setlist = NULL; unsetlist = NULL; showlist = NULL; sethistlist = NULL; showhistlist = NULL; unsethistlist = NULL;#if MAINTENANCE_CMDS maintenancelist = NULL; maintenanceinfolist = NULL; maintenanceprintlist = NULL;#endif setprintlist = NULL; showprintlist = NULL; setchecklist = NULL; showchecklist = NULL;}/* Init the history buffer. Note that we are called after the init file(s) * have been read so that the user can change the history file via his * .gdbinit file (for instance). The GDBHISTFILE environment variable * overrides all of this. */static voidinitialize_history(){ char *tmpenv; tmpenv = getenv ("HISTSIZE"); if (tmpenv) history_size = atoi (tmpenv); else if (!history_size) history_size = 256; stifle_history (history_size); tmpenv = getenv ("GDBHISTFILE"); if (tmpenv) history_filename = savestring (tmpenv, strlen(tmpenv)); else if (!history_filename) { /* We include the current directory so that if the user changes directories the file written will be the same as the one that was read. */ history_filename = concat (current_directory, "/.gdb_history", NULL); } read_history (history_filename);}voidset_prompt(s) char *s;{ if (masterprompt != 0) free (masterprompt); masterprompt = strsave (s);}static voidinitialize_main (){ struct cmd_list_element *c; #ifdef DEFAULT_PROMPT set_prompt(DEFAULT_PROMPT);#else#ifdef KERNELDEBUG if (kernel_debugging) set_prompt ("(kgdb) "); else#endif set_prompt("(gdb) ");#endif /* Set the important stuff up for command editing. */ write_history_p = 0; /* Setup important stuff for command line editing. */ rl_completion_entry_function = (int (*)()) symbol_completion_function; rl_completer_word_break_characters = gdb_completer_word_break_characters; rl_completer_quote_characters = gdb_completer_quote_characters; rl_readline_name = "gdb"; /* Define the classes of commands. They will appear in the help list in the reverse of this order. */ add_cmd ("internals", class_maintenance, NO_FUNCTION, "Maintenance commands.\n\Some gdb commands are provided just for use by gdb maintainers.\n\These commands are subject to frequent change, and may not be as\n\well documented as user commands.", &cmdlist); add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist); add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist); add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\The commands in this class are those defined by the user.\n\Use the \"define\" command to define a command.", &cmdlist); add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist); add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist); add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist); add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist); add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist); add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\counting from zero for the innermost (currently executing) frame.\n\n\At any time gdb identifies one frame as the \"selected\" frame.\n\Variable lookups are done with respect to the selected frame.\n\When the program being debugged stops, gdb selects the innermost frame.\n\The commands below can be used to select other frames by number or address.", &cmdlist); add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist); add_com ("pwd", class_files, pwd_command, "Print working directory. This is used for your program as well."); add_com ("cd", class_files, cd_command, "Set working directory to DIR for debugger and program being debugged.\n\The change does not take effect for the program being debugged\n\until the next time it is started."); add_show_from_set (add_set_cmd ("prompt", class_support, var_string, (char *)&masterprompt, "Set gdb's prompt", &setlist), &showlist); add_com ("echo", class_support, echo_command, "Print a constant string. Give string as argument.\n\C escape sequences may be used in the argument.\n\No newline is added at the end of the argument;\n\use \"\\n\" if you want a newline to be printed.\n\Since leading and trailing whitespace are ignored in command arguments,\n\if you want to print some you must use \"\\\" before leading whitespace\n\to be printed or after trailing whitespace."); add_com ("document", class_support, document_command, "Document a user-defined command.\n\Give command name as argument. Give documentation on following lines.\n\End with a line of just \"end\"."); add_com ("define", class_support, define_command, "Define a new command name. Command name is argument.\n\Definition appears on following lines, one command per line.\n\End with a line of just \"end\".\n\Use the \"document\" command to give documentation for the new command.\n\Commands defined in this way do not take arguments.");#ifdef __STDC__ add_com ("source", class_support, source_command, "Read commands from a file named FILE.\n\Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\when gdb is started.");#else /* Punt file name, we can't help it easily. */ add_com ("source", class_support, source_command, "Read commands from a file named FILE.\n\Note that the file \".gdbinit\" is read automatically in this way\n\when gdb is started.");#endif add_com ("quit", class_support, quit_command, "Exit gdb."); add_com ("help", class_support, help_command, "Print list of commands."); add_com_alias ("q", "quit", class_support, 1); add_com_alias ("h", "help", class_support, 1); c = add_set_cmd ("verbose", class_support, var_boolean, (char *)&info_verbose, "Set ", &setlist), add_show_from_set (c, &showlist); c->function.sfunc = set_verbose; set_verbose (NULL, 0, c); add_prefix_cmd ("history", class_support, set_history, "Generic command for setting command history parameters.", &sethistlist, "set history ", 0, &setlist); add_prefix_cmd ("history", class_support, show_history, "Generic command for showing command history parameters.", &showhistlist, "show history ", 0, &showlist); add_show_from_set (add_set_cmd ("save", no_class, var_boolean, (char *)&write_history_p, "Set saving of the history record on exit.\n\Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\Without an argument, saving is enabled.", &sethistlist), &showhistlist); c = add_set_cmd ("size", no_class, var_uinteger, (char *)&history_size, "Set the size of the command history, \n\ie. the number of previous commands to keep a record of.", &sethistlist); add_show_from_set (c, &showhistlist); c->function.sfunc = set_history_size_command; add_show_from_set (add_set_cmd ("filename", no_class, var_filename, (char *)&history_filename, "Set the filename in which to record the command history\n\ (the list of previous commands of which a record is kept).", &sethistlist), &showhistlist); add_show_from_set (add_set_cmd ("confirm", class_support, var_boolean, (char *)&caution, "Set whether to confirm potentially dangerous operations.", &setlist), &showlist); add_prefix_cmd ("info", class_info, info_command, "Generic command for showing things about the program being debugged.", &infolist, "info ", 0, &cmdlist); add_com_alias ("i", "info", class_info, 1); add_prefix_cmd ("show", class_info, show_command, "Generic command for showing things about the debugger.", &showlist, "show ", 0, &cmdlist); /* Another way to get at the same thing. */ add_info ("set", show_command, "Show all GDB settings."); add_cmd ("commands", no_class, show_commands, "Show the the history of commands you typed.\n\You can supply a command number to start with, or a `+' to start after\n\the previous command number shown.", &showlist); add_cmd ("version", no_class, show_version, "Show what version of GDB this is.", &showlist);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -