|
|
1.1 ! root 1: /* Top level for GDB, the GNU debugger. ! 2: Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc. ! 3: ! 4: GDB is distributed in the hope that it will be useful, but WITHOUT ANY ! 5: WARRANTY. No author or distributor accepts responsibility to anyone ! 6: for the consequences of using it or for whether it serves any ! 7: particular purpose or works at all, unless he says so in writing. ! 8: Refer to the GDB General Public License for full details. ! 9: ! 10: Everyone is granted permission to copy, modify and redistribute GDB, ! 11: but only under the conditions described in the GDB General Public ! 12: License. A copy of this license is supposed to have been given to you ! 13: along with GDB so you can know your rights and responsibilities. It ! 14: should be in a file named COPYING. Among other things, the copyright ! 15: notice and this notice must be preserved on all copies. ! 16: ! 17: In other words, go ahead and share GDB, but don't try to stop ! 18: anyone else from sharing it farther. Help stamp out software hoarding! ! 19: */ ! 20: ! 21: #include <sys/file.h> ! 22: #include <stdio.h> ! 23: #include <setjmp.h> ! 24: #include <signal.h> ! 25: #include <sys/param.h> ! 26: #include "defs.h" ! 27: #include "command.h" ! 28: #include "param.h" ! 29: ! 30: #ifdef SET_STACK_LIMIT_HUGE ! 31: #include <sys/time.h> ! 32: #include <sys/resource.h> ! 33: #endif ! 34: ! 35: /* Version number of GDB, as a string. */ ! 36: ! 37: extern char *version; ! 38: ! 39: /* Chain containing all defined commands. */ ! 40: ! 41: struct cmd_list_element *cmdlist; ! 42: ! 43: /* Chain containing all defined info subcommands. */ ! 44: ! 45: struct cmd_list_element *infolist; ! 46: ! 47: /* stdio stream that command input is being read from. */ ! 48: ! 49: FILE *instream; ! 50: ! 51: /* Current working directory. */ ! 52: ! 53: char *current_directory; ! 54: ! 55: /* The directory name is actually stored here (usually). */ ! 56: static char dirbuf[MAXPATHLEN]; ! 57: ! 58: /* Nonzero if we should refrain from using an X window. */ ! 59: ! 60: int inhibit_windows = 0; ! 61: ! 62: /* Hook for window manager argument parsing. */ ! 63: ! 64: int *win_argc; ! 65: char **win_argv; ! 66: char *win_prgm; ! 67: ! 68: /* Function to call before reading a command, if nonzero. ! 69: The function receives two args: an input stream, ! 70: and a prompt string. */ ! 71: ! 72: void (*window_hook) (); ! 73: ! 74: extern int frame_file_full_name; ! 75: ! 76: void free_command_lines (); ! 77: char *read_line (); ! 78: static void initialize_main (); ! 79: void command_loop (); ! 80: static void source_command (); ! 81: void print_gdb_version (); ! 82: ! 83: /* gdb prints this when reading a command interactively */ ! 84: static char *prompt; ! 85: ! 86: /* Buffer used for reading command lines, and the size ! 87: allocated for it so far. */ ! 88: ! 89: char *line; ! 90: int linesize; ! 91: ! 92: /* This is how `error' returns to command level. */ ! 93: ! 94: jmp_buf to_top_level; ! 95: ! 96: return_to_top_level () ! 97: { ! 98: quit_flag = 0; ! 99: immediate_quit = 0; ! 100: clear_breakpoint_commands (); ! 101: clear_momentary_breakpoints (); ! 102: delete_current_display (); ! 103: do_cleanups (0); ! 104: longjmp (to_top_level, 1); ! 105: } ! 106: ! 107: /* Call FUNC with arg ARG, catching any errors. ! 108: If there is no error, return the value returned by FUNC. ! 109: If there is an error, return zero after printing ERRSTRING ! 110: (which is in addition to the specific error message already printed). */ ! 111: ! 112: int ! 113: catch_errors (func, arg, errstring) ! 114: int (*func) (); ! 115: int arg; ! 116: char *errstring; ! 117: { ! 118: jmp_buf saved; ! 119: int val; ! 120: ! 121: bcopy (to_top_level, saved, sizeof (jmp_buf)); ! 122: ! 123: if (setjmp (to_top_level) == 0) ! 124: val = (*func) (arg); ! 125: else ! 126: { ! 127: fprintf (stderr, "%s\n", errstring); ! 128: val = 0; ! 129: } ! 130: ! 131: bcopy (saved, to_top_level, sizeof (jmp_buf)); ! 132: return val; ! 133: } ! 134: ! 135: /* Handler for SIGHUP. */ ! 136: ! 137: static void ! 138: disconnect () ! 139: { ! 140: kill_inferior_fast (); ! 141: signal (SIGHUP, SIG_DFL); ! 142: kill (getpid (), SIGHUP); ! 143: } ! 144: ! 145: main (argc, argv, envp) ! 146: int argc; ! 147: char **argv; ! 148: char **envp; ! 149: { ! 150: extern void request_quit (); ! 151: int count; ! 152: int inhibit_gdbinit = 0; ! 153: int quiet = 0; ! 154: int batch = 0; ! 155: register int i; ! 156: ! 157: quit_flag = 0; ! 158: linesize = 100; ! 159: line = (char *) xmalloc (linesize); ! 160: instream = stdin; ! 161: ! 162: getwd (dirbuf); ! 163: current_directory = dirbuf; ! 164: ! 165: win_argc = &argc; ! 166: win_argv = argv; ! 167: win_prgm = argv[0]; ! 168: ! 169: #ifdef SET_STACK_LIMIT_HUGE ! 170: { ! 171: struct rlimit rlim; ! 172: ! 173: /* Set the stack limit huge so that alloca (particularly stringtab ! 174: * in dbxread.c) does not fail. */ ! 175: getrlimit (RLIMIT_STACK, &rlim); ! 176: rlim.rlim_cur = rlim.rlim_max; ! 177: setrlimit (RLIMIT_STACK, &rlim); ! 178: } ! 179: #endif /* SET_STACK_LIMIT_HUGE */ ! 180: ! 181: /* Look for flag arguments. */ ! 182: ! 183: for (i = 1; i < argc; i++) ! 184: { ! 185: if (!strcmp (argv[i], "-q") || !strcmp (argv[i], "-quiet")) ! 186: quiet = 1; ! 187: else if (!strcmp (argv[i], "-nx")) ! 188: inhibit_gdbinit = 1; ! 189: else if (!strcmp (argv[i], "-nw")) ! 190: inhibit_windows = 1; ! 191: else if (!strcmp (argv[i], "-batch")) ! 192: batch = 1, quiet = 1; ! 193: else if (!strcmp (argv[i], "-fullname")) ! 194: frame_file_full_name = 1; ! 195: else if (argv[i][0] == '-') ! 196: i++; ! 197: } ! 198: ! 199: /* Run the init function of each source file */ ! 200: ! 201: initialize_all_files (); ! 202: initialize_main (); /* But that omits this file! Do it now */ ! 203: ! 204: signal (SIGINT, request_quit); ! 205: signal (SIGQUIT, SIG_IGN); ! 206: if (signal (SIGHUP, SIG_IGN) != SIG_IGN) ! 207: signal (SIGHUP, disconnect); ! 208: ! 209: if (!quiet) ! 210: print_gdb_version (); ! 211: ! 212: /* Process the command line arguments. */ ! 213: ! 214: count = 0; ! 215: for (i = 1; i < argc; i++) ! 216: { ! 217: register char *arg = argv[i]; ! 218: /* Args starting with - say what to do with the following arg ! 219: as a filename. */ ! 220: if (arg[0] == '-') ! 221: { ! 222: extern void exec_file_command (), symbol_file_command (); ! 223: extern void core_file_command (), directory_command (); ! 224: extern void tty_command (); ! 225: ! 226: if (!strcmp (arg, "-q") || !strcmp (arg, "-nx") ! 227: || !strcmp (arg, "-quiet") || !strcmp (arg, "-batch") ! 228: || !strcmp (arg, "-fullname")) ! 229: /* Already processed above */ ! 230: continue; ! 231: ! 232: if (++i == argc) ! 233: fprintf (stderr, "No argument follows \"%s\".\n", arg); ! 234: if (!setjmp (to_top_level)) ! 235: { ! 236: /* -s foo: get syms from foo. -e foo: execute foo. ! 237: -se foo: do both with foo. -c foo: use foo as core dump. */ ! 238: if (!strcmp (arg, "-se")) ! 239: { ! 240: exec_file_command (argv[i], !batch); ! 241: symbol_file_command (argv[i], !batch); ! 242: } ! 243: else if (!strcmp (arg, "-s") || !strcmp (arg, "-symbols")) ! 244: symbol_file_command (argv[i], !batch); ! 245: else if (!strcmp (arg, "-e") || !strcmp (arg, "-exec")) ! 246: exec_file_command (argv[i], !batch); ! 247: else if (!strcmp (arg, "-c") || !strcmp (arg, "-core")) ! 248: core_file_command (argv[i], !batch); ! 249: /* -x foo: execute commands from foo. */ ! 250: else if (!strcmp (arg, "-x") || !strcmp (arg, "-command") ! 251: || !strcmp (arg, "-commands")) ! 252: source_command (argv[i]); ! 253: /* -d foo: add directory `foo' to source-file directory ! 254: search-list */ ! 255: else if (!strcmp (arg, "-d") || !strcmp (arg, "-dir") ! 256: || !strcmp (arg, "-directory")) ! 257: directory_command (argv[i], 0); ! 258: /* -cd FOO: specify current directory as FOO. ! 259: GDB remembers the precise string FOO as the dirname. */ ! 260: else if (!strcmp (arg, "-cd")) ! 261: { ! 262: int len = strlen (argv[i]); ! 263: current_directory = argv[i]; ! 264: if (len > 1 && current_directory[len - 1] == '/') ! 265: current_directory = savestring (current_directory, len-1); ! 266: chdir (current_directory); ! 267: init_source_path (); ! 268: } ! 269: /* -t /def/ttyp1: use /dev/ttyp1 for inferior I/O. */ ! 270: else if (!strcmp (arg, "-t") || !strcmp (arg, "-tty")) ! 271: tty_command (argv[i], 0); ! 272: else ! 273: error ("Unknown command-line switch: \"%s\"\n", arg); ! 274: } ! 275: } ! 276: else ! 277: { ! 278: /* Args not thus accounted for ! 279: are treated as, first, the symbol/executable file ! 280: and, second, the core dump file. */ ! 281: count++; ! 282: if (!setjmp (to_top_level)) ! 283: switch (count) ! 284: { ! 285: case 1: ! 286: exec_file_command (arg, !batch); ! 287: symbol_file_command (arg, !batch); ! 288: break; ! 289: ! 290: case 2: ! 291: core_file_command (arg, !batch); ! 292: break; ! 293: ! 294: case 3: ! 295: fprintf (stderr, "Excess command line args ignored. (%s%s)\n", ! 296: arg, (i == argc - 1) ? "" : " ..."); ! 297: } ! 298: } ! 299: } ! 300: ! 301: /* Read init file, if it exists in home directory */ ! 302: if (getenv ("HOME")) ! 303: { ! 304: char *s; ! 305: s = (char *) xmalloc (strlen (getenv ("HOME")) + 10); ! 306: strcpy (s, getenv ("HOME")); ! 307: strcat (s, "/.gdbinit"); ! 308: if (!inhibit_gdbinit && access (s, R_OK) == 0) ! 309: if (!setjmp (to_top_level)) ! 310: source_command (s); ! 311: } ! 312: ! 313: /* Read init file, if it exists in current directory. */ ! 314: if (!inhibit_gdbinit && access (".gdbinit", R_OK) == 0) ! 315: if (!setjmp (to_top_level)) ! 316: source_command (".gdbinit"); ! 317: ! 318: if (batch) ! 319: fatal ("Attempt to read commands from stdin in batch mode."); ! 320: ! 321: if (!quiet) ! 322: printf ("Type \"help\" for a list of commands.\n"); ! 323: ! 324: /* The command loop. */ ! 325: ! 326: while (1) ! 327: { ! 328: if (!setjmp (to_top_level)) ! 329: command_loop (); ! 330: clearerr (stdin); /* Don't get hung if C-d is typed. */ ! 331: } ! 332: } ! 333: ! 334: /* Execute the line P as a command. ! 335: Pass FROM_TTY as second argument to the defining function. */ ! 336: ! 337: void ! 338: execute_command (p, from_tty) ! 339: char *p; ! 340: int from_tty; ! 341: { ! 342: register struct cmd_list_element *c; ! 343: register struct command_line *cmdlines; ! 344: ! 345: free_all_values (); ! 346: while (*p == ' ' || *p == '\t') p++; ! 347: if (*p) ! 348: { ! 349: c = lookup_cmd (&p, cmdlist, "", 0); ! 350: if (c->function == 0) ! 351: error ("That is not a command, just a help topic."); ! 352: else if (c->class == (int) class_user) ! 353: { ! 354: if (*p) ! 355: error ("User-defined commands cannot take arguments."); ! 356: cmdlines = (struct command_line *) c->function; ! 357: if (cmdlines == (struct command_line *) 0) ! 358: /* Null command */ ! 359: return; ! 360: while (cmdlines) ! 361: { ! 362: execute_command (cmdlines->line, 0); ! 363: cmdlines = cmdlines->next; ! 364: } ! 365: } ! 366: else ! 367: /* Pass null arg rather than an empty one. */ ! 368: (*c->function) (*p ? p : 0, from_tty); ! 369: } ! 370: } ! 371: ! 372: static void ! 373: do_nothing () ! 374: { ! 375: } ! 376: ! 377: /* Read commands from `instream' and execute them ! 378: until end of file. */ ! 379: void ! 380: command_loop () ! 381: { ! 382: struct cleanup *old_chain; ! 383: while (!feof (instream)) ! 384: { ! 385: if (instream == stdin) ! 386: printf ("%s", prompt); ! 387: fflush (stdout); ! 388: ! 389: if (window_hook && instream == stdin) ! 390: (*window_hook) (instream, prompt); ! 391: ! 392: quit_flag = 0; ! 393: old_chain = make_cleanup (do_nothing, 0); ! 394: execute_command (read_line (instream == stdin), instream == stdin); ! 395: /* Do any commands attached to breakpoint we stopped at. */ ! 396: do_breakpoint_commands (); ! 397: do_cleanups (old_chain); ! 398: } ! 399: } ! 400: ! 401: #ifdef SIGTSTP ! 402: static void ! 403: stop_sig () ! 404: { ! 405: signal (SIGTSTP, SIG_DFL); ! 406: sigsetmask (0); ! 407: kill (getpid (), SIGTSTP); ! 408: signal (SIGTSTP, stop_sig); ! 409: printf ("%s", prompt); ! 410: fflush (stdout); ! 411: ! 412: /* Forget about any previous command -- null line now will do nothing. */ ! 413: *line = 0; ! 414: } ! 415: #endif /* SIGTSTP */ ! 416: ! 417: /* Commands call this if they do not want to be repeated by null lines. */ ! 418: ! 419: void ! 420: dont_repeat () ! 421: { ! 422: *line = 0; ! 423: } ! 424: ! 425: /* Read one line from the command input stream `instream' ! 426: into the buffer `line' (whose current length is `linesize'). ! 427: The buffer is made bigger as necessary. ! 428: Returns the address of the start of the line. */ ! 429: ! 430: char * ! 431: read_line (repeat) ! 432: int repeat; ! 433: { ! 434: register char *p = line; ! 435: register char *p1; ! 436: register int c; ! 437: char *nline; ! 438: ! 439: /* Control-C quits instantly if typed while in this loop ! 440: since it should not wait until the user types a newline. */ ! 441: immediate_quit++; ! 442: #ifdef SIGTSTP ! 443: signal (SIGTSTP, stop_sig); ! 444: #endif ! 445: ! 446: while (1) ! 447: { ! 448: c = fgetc (instream); ! 449: if (c == -1 || c == '\n') ! 450: break; ! 451: /* Ignore backslash-newline; keep adding to the same line. */ ! 452: else if (c == '\\') ! 453: { ! 454: int c1 = fgetc (instream); ! 455: if (c1 == '\n') ! 456: continue; ! 457: else ! 458: ungetc (c1, instream); ! 459: } ! 460: ! 461: if (p - line == linesize - 1) ! 462: { ! 463: linesize *= 2; ! 464: nline = (char *) xrealloc (line, linesize); ! 465: p += nline - line; ! 466: line = nline; ! 467: } ! 468: *p++ = c; ! 469: } ! 470: ! 471: #ifdef SIGTSTP ! 472: signal (SIGTSTP, SIG_DFL); ! 473: #endif ! 474: immediate_quit--; ! 475: ! 476: /* If we just got an empty line, and that is supposed ! 477: to repeat the previous command, leave the last input unchanged. */ ! 478: if (p == line && repeat) ! 479: return line; ! 480: ! 481: /* If line is a comment, clear it out. */ ! 482: p1 = line; ! 483: while ((c = *p1) == ' ' || c == '\t') p1++; ! 484: if (c == '#') ! 485: p = line; ! 486: ! 487: *p = 0; ! 488: ! 489: return line; ! 490: } ! 491: ! 492: /* Read lines from the input stream ! 493: and accumulate them in a chain of struct command_line's ! 494: which is then returned. */ ! 495: ! 496: struct command_line * ! 497: read_command_lines () ! 498: { ! 499: struct command_line *first = 0; ! 500: register struct command_line *next, *tail = 0; ! 501: register char *p, *p1; ! 502: struct cleanup *old_chain = 0; ! 503: ! 504: while (1) ! 505: { ! 506: dont_repeat (); ! 507: p = read_line (1); ! 508: /* Remove leading and trailing blanks. */ ! 509: while (*p == ' ' || *p == '\t') p++; ! 510: p1 = p + strlen (p); ! 511: while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t')) p1--; ! 512: ! 513: /* Is this "end"? */ ! 514: if (p1 - p == 3 && !strncmp (p, "end", 3)) ! 515: break; ! 516: ! 517: /* No => add this line to the chain of command lines. */ ! 518: next = (struct command_line *) xmalloc (sizeof (struct command_line)); ! 519: next->line = savestring (p, p1 - p); ! 520: next->next = 0; ! 521: if (tail) ! 522: { ! 523: tail->next = next; ! 524: } ! 525: else ! 526: { ! 527: /* We just read the first line. ! 528: From now on, arrange to throw away the lines we have ! 529: if we quit or get an error while inside this function. */ ! 530: first = next; ! 531: old_chain = make_cleanup (free_command_lines, &first); ! 532: } ! 533: tail = next; ! 534: } ! 535: ! 536: dont_repeat (); ! 537: ! 538: /* Now we are about to return the chain to our caller, ! 539: so freeing it becomes his responsibility. */ ! 540: if (first) ! 541: discard_cleanups (old_chain); ! 542: return first; ! 543: } ! 544: ! 545: /* Free a chain of struct command_line's. */ ! 546: ! 547: void ! 548: free_command_lines (lptr) ! 549: struct command_line **lptr; ! 550: { ! 551: register struct command_line *l = *lptr; ! 552: register struct command_line *next; ! 553: ! 554: while (l) ! 555: { ! 556: next = l->next; ! 557: free (l->line); ! 558: free (l); ! 559: l = next; ! 560: } ! 561: } ! 562: ! 563: /* Add an element to the list of info subcommands. */ ! 564: ! 565: void ! 566: add_info (name, fun, doc) ! 567: char *name; ! 568: void (*fun) (); ! 569: char *doc; ! 570: { ! 571: add_cmd (name, 0, fun, doc, &infolist); ! 572: } ! 573: ! 574: /* Add an alias to the list of info subcommands. */ ! 575: ! 576: void ! 577: add_info_alias (name, oldname, abbrev_flag) ! 578: char *name; ! 579: char *oldname; ! 580: int abbrev_flag; ! 581: { ! 582: add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist); ! 583: } ! 584: ! 585: /* The "info" command is defined as a prefix, with allow_unknown = 0. ! 586: Therefore, its own definition is called only for "info" with no args. */ ! 587: ! 588: static void ! 589: info_command () ! 590: { ! 591: printf ("\"info\" must be followed by the name of an info command.\n"); ! 592: help_cmd (0, infolist, "info ", -1, stdout); ! 593: } ! 594: ! 595: /* Add an element to the list of commands. */ ! 596: ! 597: void ! 598: add_com (name, class, fun, doc) ! 599: char *name; ! 600: int class; ! 601: void (*fun) (); ! 602: char *doc; ! 603: { ! 604: add_cmd (name, class, fun, doc, &cmdlist); ! 605: } ! 606: ! 607: /* Add an alias or abbreviation command to the list of commands. */ ! 608: ! 609: void ! 610: add_com_alias (name, oldname, class, abbrev_flag) ! 611: char *name; ! 612: char *oldname; ! 613: int class; ! 614: int abbrev_flag; ! 615: { ! 616: add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist); ! 617: } ! 618: ! 619: void ! 620: error_no_arg (why) ! 621: char *why; ! 622: { ! 623: error ("Argument required (%s).", why); ! 624: } ! 625: ! 626: static void ! 627: help_command (command, from_tty) ! 628: char *command; ! 629: int from_tty; /* Ignored */ ! 630: { ! 631: help_cmd (command, cmdlist, "", -2, stdout); ! 632: } ! 633: ! 634: static void ! 635: validate_comname (comname) ! 636: char *comname; ! 637: { ! 638: register char *p; ! 639: ! 640: if (comname == 0) ! 641: error_no_arg ("name of command to define"); ! 642: ! 643: p = comname; ! 644: while (*p) ! 645: { ! 646: if (!(*p >= 'A' && *p <= 'Z') ! 647: && !(*p >= 'a' && *p <= 'z') ! 648: && !(*p >= '0' && *p <= '9') ! 649: && *p != '-') ! 650: error ("Junk in argument list: \"%s\"", p); ! 651: p++; ! 652: } ! 653: } ! 654: ! 655: static void ! 656: define_command (comname, from_tty) ! 657: char *comname; ! 658: int from_tty; ! 659: { ! 660: register struct command_line *cmds; ! 661: register struct cmd_list_element *c; ! 662: char *tem = comname; ! 663: ! 664: validate_comname (comname); ! 665: ! 666: c = lookup_cmd (&tem, cmdlist, "", -1); ! 667: if (c) ! 668: { ! 669: if (c->class == (int) class_user || c->class == (int) class_alias) ! 670: tem = "Redefine command \"%s\"? "; ! 671: else ! 672: tem = "Really redefine built-in command \"%s\"? "; ! 673: if (!query (tem, comname)) ! 674: error ("Command \"%s\" not redefined.", comname); ! 675: } ! 676: ! 677: if (from_tty) ! 678: printf ("Type commands for definition of \"%s\".\n\ ! 679: End with a line saying just \"end\".\n", comname); ! 680: ! 681: comname = savestring (comname, strlen (comname)); ! 682: ! 683: cmds = read_command_lines (); ! 684: ! 685: if (c && c->class == (int) class_user) ! 686: free_command_lines (&c->function); ! 687: ! 688: add_com (comname, class_user, cmds, ! 689: (c && c->class == (int) class_user) ! 690: ? c->doc : savestring ("User-defined.", 13)); ! 691: } ! 692: ! 693: static void ! 694: document_command (comname, from_tty) ! 695: char *comname; ! 696: int from_tty; ! 697: { ! 698: struct command_line *doclines; ! 699: register struct cmd_list_element *c; ! 700: char *tem = comname; ! 701: ! 702: validate_comname (comname); ! 703: ! 704: c = lookup_cmd (&tem, cmdlist, "", 0); ! 705: ! 706: if (c->class != (int) class_user) ! 707: error ("Command \"%s\" is built-in.", comname); ! 708: ! 709: if (from_tty) ! 710: printf ("Type documentation for \"%s\".\n\ ! 711: End with a line saying just \"end\".\n", comname); ! 712: ! 713: doclines = read_command_lines (); ! 714: ! 715: if (c->doc) free (c->doc); ! 716: ! 717: { ! 718: register struct command_line *cl1; ! 719: register int len = 0; ! 720: ! 721: for (cl1 = doclines; cl1; cl1 = cl1->next) ! 722: len += strlen (cl1->line) + 1; ! 723: ! 724: c->doc = (char *) xmalloc (len + 1); ! 725: *c->doc = 0; ! 726: ! 727: for (cl1 = doclines; cl1; cl1 = cl1->next) ! 728: { ! 729: strcat (c->doc, cl1->line); ! 730: if (cl1->next) ! 731: strcat (c->doc, "\n"); ! 732: } ! 733: } ! 734: ! 735: free_command_lines (&doclines); ! 736: } ! 737: ! 738: static void ! 739: copying_info () ! 740: { ! 741: immediate_quit++; ! 742: printf (" GDB GENERAL PUBLIC LICENSE\n\ ! 743: (Clarified 11 Feb 1988)\n\ ! 744: \n\ ! 745: Copyright (C) 1988 Richard M. Stallman\n\ ! 746: Everyone is permitted to copy and distribute verbatim copies\n\ ! 747: of this license, but changing it is not allowed.\n\ ! 748: You can also use this wording to make the terms for other programs.\n\ ! 749: \n\ ! 750: The license agreements of most software companies keep you at the\n\ ! 751: mercy of those companies. By contrast, our general public license is\n\ ! 752: intended to give everyone the right to share GDB. To make sure that\n\ ! 753: you get the rights we want you to have, we need to make restrictions\n\ ! 754: that forbid anyone to deny you these rights or to ask you to surrender\n\ ! 755: the rights. Hence this license agreement.\n\ ! 756: \n\ ! 757: Specifically, we want to make sure that you have the right to give\n\ ! 758: away copies of GDB, that you receive source code or else can get it\n\ ! 759: if you want it, that you can change GDB or use pieces of it in new\n\ ! 760: free programs, and that you know you can do these things.\n\ ! 761: --Type Return to print more--"); ! 762: fflush (stdout); ! 763: read_line (); ! 764: ! 765: printf ("\ ! 766: To make sure that everyone has such rights, we have to forbid you to\n\ ! 767: deprive anyone else of these rights. For example, if you distribute\n\ ! 768: copies of GDB, you must give the recipients all the rights that you\n\ ! 769: have. You must make sure that they, too, receive or can get the\n\ ! 770: source code. And you must tell them their rights.\n\ ! 771: \n\ ! 772: Also, for our own protection, we must make certain that everyone\n\ ! 773: finds out that there is no warranty for GDB. If GDB is modified by\n\ ! 774: someone else and passed on, we want its recipients to know that what\n\ ! 775: they have is not what we distributed, so that any problems introduced\n\ ! 776: by others will not reflect on our reputation.\n\ ! 777: \n\ ! 778: Therefore we (Richard Stallman and the Free Software Foundation,\n\ ! 779: Inc.) make the following terms which say what you must do to be\n\ ! 780: allowed to distribute or change GDB.\n\ ! 781: --Type Return to print more--"); ! 782: fflush (stdout); ! 783: read_line (); ! 784: ! 785: printf ("\ ! 786: COPYING POLICIES\n\ ! 787: \n\ ! 788: 1. You may copy and distribute verbatim copies of GDB source code as\n\ ! 789: you receive it, in any medium, provided that you conspicuously and\n\ ! 790: appropriately publish on each copy a valid copyright notice \"Copyright\n\ ! 791: \(C) 1988 Free Software Foundation, Inc.\" (or with whatever year is\n\ ! 792: appropriate); keep intact the notices on all files that refer\n\ ! 793: to this License Agreement and to the absence of any warranty; and give\n\ ! 794: any other recipients of the GDB program a copy of this License\n\ ! 795: Agreement along with the program. You may charge a distribution fee\n\ ! 796: for the physical act of transferring a copy.\n\ ! 797: \n\ ! 798: 2. You may modify your copy or copies of GDB or any portion of it,\n\ ! 799: and copy and distribute such modifications under the terms of\n\ ! 800: Paragraph 1 above, provided that you also do the following:\n\ ! 801: \n\ ! 802: a) cause the modified files to carry prominent notices stating\n\ ! 803: that you changed the files and the date of any change; and\n\ ! 804: --Type Return to print more--"); ! 805: fflush (stdout); ! 806: read_line (); ! 807: ! 808: printf ("\ ! 809: b) cause the whole of any work that you distribute or publish,\n\ ! 810: that in whole or in part contains or is a derivative of GDB\n\ ! 811: or any part thereof, to be licensed to all third parties on terms\n\ ! 812: identical to those contained in this License Agreement (except that\n\ ! 813: you may choose to grant more extensive warranty protection to some\n\ ! 814: or all third parties, at your option).\n\ ! 815: \n"); ! 816: printf ("\ ! 817: c) if the modified program serves as a debugger, cause it\n\ ! 818: when started running in the simplest and usual way, to print\n\ ! 819: an announcement including a valid copyright notice\n\ ! 820: \"Copyright (C) 1988 Free Software Foundation, Inc.\" (or with\n\ ! 821: the year that is appropriate), saying that there is no warranty\n\ ! 822: (or else, saying that you provide a warranty) and that users may\n\ ! 823: redistribute the program under these conditions, and telling the user\n\ ! 824: how to view a copy of this License Agreement.\n\ ! 825: \n\ ! 826: d) You may charge a distribution fee for the physical act of\n\ ! 827: transferring a copy, and you may at your option offer warranty\n\ ! 828: protection in exchange for a fee.\n\ ! 829: \n\ ! 830: Mere aggregation of another unrelated program with this program (or its\n\ ! 831: derivative) on a volume of a storage or distribution medium does not bring\n\ ! 832: the other program under the scope of these terms.\n\ ! 833: --Type Return to print more--"); ! 834: fflush (stdout); ! 835: read_line (); ! 836: ! 837: printf ("\ ! 838: 3. You may copy and distribute GDB (or a portion or derivative of it,\n\ ! 839: under Paragraph 2) in object code or executable form under the terms of\n\ ! 840: Paragraphs 1 and 2 above provided that you also do one of the following:\n\ ! 841: \n\ ! 842: a) accompany it with the complete corresponding machine-readable\n\ ! 843: source code, which must be distributed under the terms of\n\ ! 844: Paragraphs 1 and 2 above; or,\n\ ! 845: \n\ ! 846: b) accompany it with a written offer, valid for at least three\n\ ! 847: years, to give any third party free (except for a nominal\n\ ! 848: shipping charge) a complete machine-readable copy of the\n\ ! 849: corresponding source code, to be distributed under the terms of\n\ ! 850: Paragraphs 1 and 2 above; or,\n\n"); ! 851: ! 852: printf ("\ ! 853: c) accompany it with the information you received as to where the\n\ ! 854: corresponding source code may be obtained. (This alternative is\n\ ! 855: allowed only for noncommercial distribution and only if you\n\ ! 856: received the program in object code or executable form alone.)\n\ ! 857: \n\ ! 858: For an executable file, complete source code means all the source code for\n\ ! 859: all modules it contains; but, as a special exception, it need not include\n\ ! 860: source code for modules which are standard libraries that accompany the\n\ ! 861: operating system on which the executable file runs.\n\ ! 862: --Type Return to print more--"); ! 863: fflush (stdout); ! 864: read_line (); ! 865: ! 866: printf ("\ ! 867: 4. You may not copy, sublicense, distribute or transfer GDB\n\ ! 868: except as expressly provided under this License Agreement. Any attempt\n\ ! 869: otherwise to copy, sublicense, distribute or transfer GDB is void and\n\ ! 870: your rights to use the program under this License agreement shall be\n\ ! 871: automatically terminated. However, parties who have received computer\n\ ! 872: software programs from you with this License Agreement will not have\n\ ! 873: their licenses terminated so long as such parties remain in full compliance.\n\ ! 874: \n\ ! 875: 5. If you wish to incorporate parts of GDB into other free\n\ ! 876: programs whose distribution conditions are different, write to the Free\n\ ! 877: Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet\n\ ! 878: worked out a simple rule that can be stated here, but we will often permit\n\ ! 879: this. We will be guided by the two goals of preserving the free status of\n\ ! 880: all derivatives of our free software and of promoting the sharing and reuse\n\ ! 881: of software.\n\ ! 882: \n\ ! 883: In other words, go ahead and share GDB, but don't try to stop\n\ ! 884: anyone else from sharing it farther. Help stamp out software hoarding!\n\ ! 885: "); ! 886: immediate_quit--; ! 887: } ! 888: ! 889: static void ! 890: warranty_info () ! 891: { ! 892: immediate_quit++; ! 893: printf (" NO WARRANTY\n\ ! 894: \n\ ! 895: BECAUSE GDB IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY NO\n\ ! 896: WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT\n\ ! 897: WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,\n\ ! 898: RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE GDB \"AS IS\" WITHOUT\n\ ! 899: WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT\n\ ! 900: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n\ ! 901: A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND\n\ ! 902: PERFORMANCE OF GDB IS WITH YOU. SHOULD GDB PROVE DEFECTIVE, YOU\n\ ! 903: ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n"); ! 904: ! 905: printf ("\ ! 906: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.\n\ ! 907: STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY\n\ ! 908: WHO MAY MODIFY AND REDISTRIBUTE GDB, BE LIABLE TO\n\ ! 909: YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER\n\ ! 910: SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR\n\ ! 911: INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA\n\ ! 912: BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A\n\ ! 913: FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GDB, EVEN\n\ ! 914: IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR\n\ ! 915: ANY CLAIM BY ANY OTHER PARTY.\n"); ! 916: immediate_quit--; ! 917: } ! 918: ! 919: static void ! 920: print_gdb_version () ! 921: { ! 922: printf ("GDB %s, Copyright (C) 1988 Free Software Foundation, Inc.\n\ ! 923: There is ABSOLUTELY NO WARRANTY for GDB; type \"info warranty\" for details.\n\ ! 924: GDB is free software and you are welcome to distribute copies of it\n\ ! 925: under certain conditions; type \"info copying\" to see the conditions.\n", ! 926: version); ! 927: } ! 928: ! 929: static void ! 930: version_info () ! 931: { ! 932: immediate_quit++; ! 933: print_gdb_version (); ! 934: immediate_quit--; ! 935: } ! 936: ! 937: /* xgdb calls this to reprint the usual GDB prompt. */ ! 938: ! 939: void ! 940: print_prompt () ! 941: { ! 942: printf ("%s", prompt); ! 943: fflush (stdout); ! 944: } ! 945: ! 946: /* Command to specify a prompt string instead of "(gdb) ". */ ! 947: ! 948: static void ! 949: set_prompt_command (text) ! 950: char *text; ! 951: { ! 952: char *p, *q; ! 953: register int c; ! 954: char *new; ! 955: ! 956: if (text == 0) ! 957: error_no_arg ("string to which to set prompt"); ! 958: ! 959: new = (char *) xmalloc (strlen (text) + 2); ! 960: p = text; q = new; ! 961: while (c = *p++) ! 962: { ! 963: if (c == '\\') ! 964: { ! 965: /* \ at end of argument is used after spaces ! 966: so they won't be lost. */ ! 967: if (*p == 0) ! 968: break; ! 969: c = parse_escape (&p); ! 970: if (c == 0) ! 971: break; /* C loses */ ! 972: else if (c > 0) ! 973: *q++ = c; ! 974: } ! 975: else ! 976: *q++ = c; ! 977: } ! 978: if (*(p - 1) != '\\') ! 979: *q++ = ' '; ! 980: *q++ = '\0'; ! 981: new = (char *) xrealloc (new, q - new); ! 982: free (prompt); ! 983: prompt = new; ! 984: } ! 985: ! 986: static void ! 987: quit_command () ! 988: { ! 989: if (have_inferior_p ()) ! 990: { ! 991: if (query ("The program is running. Quit anyway? ")) ! 992: { ! 993: /* Prevent any warning message from reopen_exec_file, in case ! 994: we have a core file that's inconsistent with the exec file. */ ! 995: exec_file_command (0, 0); ! 996: kill_inferior (); ! 997: } ! 998: else ! 999: error ("Not confirmed."); ! 1000: } ! 1001: exit (0); ! 1002: } ! 1003: ! 1004: int ! 1005: input_from_terminal_p () ! 1006: { ! 1007: return instream == stdin; ! 1008: } ! 1009: ! 1010: static void ! 1011: pwd_command (arg, from_tty) ! 1012: char *arg; ! 1013: int from_tty; ! 1014: { ! 1015: if (arg) error ("The \"pwd\" command does not take an argument: %s", arg); ! 1016: getwd (dirbuf); ! 1017: ! 1018: if (strcmp (dirbuf, current_directory)) ! 1019: printf ("Working directory %s\n (canonically %s).\n", ! 1020: current_directory, dirbuf); ! 1021: else ! 1022: printf ("Working directory %s.\n", current_directory); ! 1023: } ! 1024: ! 1025: static void ! 1026: cd_command (dir, from_tty) ! 1027: char *dir; ! 1028: int from_tty; ! 1029: { ! 1030: int len; ! 1031: int change; ! 1032: ! 1033: if (dir == 0) ! 1034: error_no_arg ("new working directory"); ! 1035: ! 1036: len = strlen (dir); ! 1037: dir = savestring (dir, len - (len > 1 && dir[len-1] == '/')); ! 1038: if (dir[0] == '/') ! 1039: current_directory = dir; ! 1040: else ! 1041: { ! 1042: current_directory = concat (current_directory, "/", dir); ! 1043: free (dir); ! 1044: } ! 1045: ! 1046: /* Now simplify any occurrences of `.' and `..' in the pathname. */ ! 1047: ! 1048: change = 1; ! 1049: while (change) ! 1050: { ! 1051: char *p; ! 1052: change = 0; ! 1053: ! 1054: for (p = current_directory; *p;) ! 1055: { ! 1056: if (!strncmp (p, "/./", 2) ! 1057: && (p[2] == 0 || p[2] == '/')) ! 1058: strcpy (p, p + 2); ! 1059: else if (!strncmp (p, "/..", 3) ! 1060: && (p[3] == 0 || p[3] == '/') ! 1061: && p != current_directory) ! 1062: { ! 1063: char *q = p; ! 1064: while (q != current_directory && q[-1] != '/') q--; ! 1065: if (q != current_directory) ! 1066: { ! 1067: strcpy (q-1, p+3); ! 1068: p = q-1; ! 1069: } ! 1070: } ! 1071: else p++; ! 1072: } ! 1073: } ! 1074: ! 1075: if (chdir (dir) < 0) ! 1076: perror_with_name (dir); ! 1077: ! 1078: if (from_tty) ! 1079: pwd_command ((char *) 0, 1); ! 1080: } ! 1081: ! 1082: /* Clean up on error during a "source" command. ! 1083: Close the file opened by the command ! 1084: and restore the previous input stream. */ ! 1085: ! 1086: static void ! 1087: source_cleanup (stream) ! 1088: FILE *stream; ! 1089: { ! 1090: fclose (instream); ! 1091: instream = stream; ! 1092: } ! 1093: ! 1094: static void ! 1095: source_command (file) ! 1096: char *file; ! 1097: { ! 1098: FILE *stream; ! 1099: struct cleanup *cleanups; ! 1100: ! 1101: if (file == 0) ! 1102: error_no_arg ("file to read commands from"); ! 1103: ! 1104: stream = fopen (file, "r"); ! 1105: if (stream == 0) ! 1106: perror_with_name (file); ! 1107: ! 1108: cleanups = make_cleanup (source_cleanup, instream); ! 1109: ! 1110: instream = stream; ! 1111: ! 1112: command_loop (); ! 1113: ! 1114: do_cleanups (cleanups); ! 1115: } ! 1116: ! 1117: static void ! 1118: echo_command (text) ! 1119: char *text; ! 1120: { ! 1121: char *p = text; ! 1122: register int c; ! 1123: ! 1124: if (text) ! 1125: while (c = *p++) ! 1126: { ! 1127: if (c == '\\') ! 1128: { ! 1129: /* \ at end of argument is used after spaces ! 1130: so they won't be lost. */ ! 1131: if (*p == 0) ! 1132: return; ! 1133: ! 1134: c = parse_escape (&p); ! 1135: if (c >= 0) ! 1136: fputc (c, stdout); ! 1137: } ! 1138: else ! 1139: fputc (c, stdout); ! 1140: } ! 1141: } ! 1142: ! 1143: static void ! 1144: dump_me_command () ! 1145: { ! 1146: if (query ("Should GDB dump core? ")) ! 1147: { ! 1148: signal (SIGQUIT, SIG_DFL); ! 1149: kill (getpid (), SIGQUIT); ! 1150: } ! 1151: } ! 1152: ! 1153: static void ! 1154: initialize_main () ! 1155: { ! 1156: prompt = savestring ("(gdb) ", 6); ! 1157: ! 1158: /* Define the classes of commands. ! 1159: They will appear in the help list in the reverse of this order. */ ! 1160: ! 1161: add_cmd ("obscure", class_obscure, 0, "Obscure features.", &cmdlist); ! 1162: add_cmd ("alias", class_alias, 0, "Aliases of other commands.", &cmdlist); ! 1163: add_cmd ("user", class_user, 0, "User-defined commands.\n\ ! 1164: The commands in this class are those defined by the user.\n\ ! 1165: Use the \"define\" command to define a command.", &cmdlist); ! 1166: add_cmd ("support", class_support, 0, "Support facilities.", &cmdlist); ! 1167: add_cmd ("status", class_info, 0, "Status inquiries.", &cmdlist); ! 1168: add_cmd ("files", class_files, 0, "Specifying and examining files.", &cmdlist); ! 1169: add_cmd ("breakpoints", class_breakpoint, 0, "Making program stop at certain points.", &cmdlist); ! 1170: add_cmd ("data", class_vars, 0, "Examining data.", &cmdlist); ! 1171: add_cmd ("stack", class_stack, 0, "Examining the stack.\n\ ! 1172: The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\ ! 1173: counting from zero for the innermost (currently executing) frame.\n\n\ ! 1174: At any time gdb identifies one frame as the \"selected\" frame.\n\ ! 1175: Variable lookups are done with respect to the selected frame.\n\ ! 1176: When the program being debugged stops, gdb selects the innermost frame.\n\ ! 1177: The commands below can be used to select other frames by number or address.", ! 1178: &cmdlist); ! 1179: add_cmd ("running", class_run, 0, "Running the program.", &cmdlist); ! 1180: ! 1181: add_com ("pwd", class_files, pwd_command, ! 1182: "Print working directory. This is used for your program as well."); ! 1183: add_com ("cd", class_files, cd_command, ! 1184: "Set working directory to DIR for debugger and program being debugged.\n\ ! 1185: The change does not take effect for the program being debugged\n\ ! 1186: until the next time it is started."); ! 1187: ! 1188: add_com ("set-prompt", class_support, set_prompt_command, ! 1189: "Change gdb's prompt from the default of \"(gdb)\""); ! 1190: add_com ("echo", class_support, echo_command, ! 1191: "Print a constant string. Give string as argument.\n\ ! 1192: C escape sequences may be used in the argument.\n\ ! 1193: No newline is added at the end of the argument;\n\ ! 1194: use \"\\n\" if you want a newline to be printed.\n\ ! 1195: Since leading and trailing whitespace are ignored in command arguments,\n\ ! 1196: if you want to print some you must use \"\\\" before leading whitespace\n\ ! 1197: to be printed or after trailing whitespace."); ! 1198: add_com ("document", class_support, document_command, ! 1199: "Document a user-defined command.\n\ ! 1200: Give command name as argument. Give documentation on following lines.\n\ ! 1201: End with a line of just \"end\"."); ! 1202: add_com ("define", class_support, define_command, ! 1203: "Define a new command name. Command name is argument.\n\ ! 1204: Definition appears on following lines, one command per line.\n\ ! 1205: End with a line of just \"end\".\n\ ! 1206: Use the \"document\" command to give documentation for the new command.\n\ ! 1207: Commands defined in this way do not take arguments."); ! 1208: ! 1209: add_com ("source", class_support, source_command, ! 1210: "Read commands from a file named FILE.\n\ ! 1211: Note that the file \".gdbinit\" is read automatically in this way\n\ ! 1212: when gdb is started."); ! 1213: add_com ("quit", class_support, quit_command, "Exit gdb."); ! 1214: add_com ("help", class_support, help_command, "Print list of commands."); ! 1215: add_com_alias ("q", "quit", class_support, 1); ! 1216: add_com_alias ("h", "help", class_support, 1); ! 1217: ! 1218: add_com ("dump-me", class_obscure, dump_me_command, ! 1219: "Get fatal error; make debugger dump its core."); ! 1220: ! 1221: add_prefix_cmd ("info", class_info, info_command, ! 1222: "Generic command for printing status.", ! 1223: &infolist, "info ", 0, &cmdlist); ! 1224: add_com_alias ("i", "info", class_info, 1); ! 1225: ! 1226: add_info ("copying", copying_info, "Conditions for redistributing copies of GDB."); ! 1227: add_info ("warranty", warranty_info, "Various kinds of warranty you do not have."); ! 1228: add_info ("version", version_info, "Report what version of GDB this is."); ! 1229: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.