home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / gdb / gdb_18s.zoo / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-27  |  37.8 KB  |  1,457 lines

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