home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / GDB / GDB-4.13 / GDB-4 / gdb-4.13 / gdb / source.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-13  |  36.5 KB  |  1,416 lines

  1. /* List lines of source files for GDB, the GNU debugger.
  2.    Copyright (C) 1986, 1987, 1988, 1989, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include "symtab.h"
  22. #include "expression.h"
  23. #include "language.h"
  24. #include "command.h"
  25. #include "gdbcmd.h"
  26. #include "frame.h"
  27.  
  28. #include <sys/types.h>
  29. #include <string.h>
  30. #include <sys/param.h>
  31. #include <sys/stat.h>
  32. #include <fcntl.h>
  33. #include "gdbcore.h"
  34. #include "regex.h"
  35. #include "symfile.h"
  36. #include "objfiles.h"
  37. #include "annotate.h"
  38.  
  39. #ifndef DIRNAME_SEPARATOR
  40. #define DIRNAME_SEPARATOR ':'
  41. #endif
  42.  
  43. /* Prototypes for local functions. */
  44.  
  45. static int
  46. open_source_file PARAMS ((struct symtab *));
  47.  
  48. static int
  49. get_filename_and_charpos PARAMS ((struct symtab *, char **));
  50.  
  51. static void
  52. reverse_search_command PARAMS ((char *, int));
  53.  
  54. static void
  55. forward_search_command PARAMS ((char *, int));
  56.  
  57. static void
  58. line_info PARAMS ((char *, int));
  59.  
  60. static void
  61. list_command PARAMS ((char *, int));
  62.  
  63. static void
  64. ambiguous_line_spec PARAMS ((struct symtabs_and_lines *));
  65.  
  66. static void
  67. source_info PARAMS ((char *, int));
  68.  
  69. static void
  70. show_directories PARAMS ((char *, int));
  71.  
  72. static void
  73. find_source_lines PARAMS ((struct symtab *, int));
  74.  
  75. /* If we use this declaration, it breaks because of fucking ANSI "const" stuff
  76.    on some systems.  We just have to not declare it at all, have it default
  77.    to int, and possibly botch on a few systems.  Thanks, ANSIholes... */
  78. /* extern char *strstr(); */
  79.  
  80. /* Path of directories to search for source files.
  81.    Same format as the PATH environment variable's value.  */
  82.  
  83. char *source_path;
  84.  
  85. /* Symtab of default file for listing lines of.  */
  86.  
  87. struct symtab *current_source_symtab;
  88.  
  89. /* Default next line to list.  */
  90.  
  91. int current_source_line;
  92.  
  93. /* Default number of lines to print with commands like "list".
  94.    This is based on guessing how many long (i.e. more than chars_per_line
  95.    characters) lines there will be.  To be completely correct, "list"
  96.    and friends should be rewritten to count characters and see where
  97.    things are wrapping, but that would be a fair amount of work.  */
  98.  
  99. int lines_to_list = 10;
  100.  
  101. /* Line number of last line printed.  Default for various commands.
  102.    current_source_line is usually, but not always, the same as this.  */
  103.  
  104. static int last_line_listed;
  105.  
  106. /* First line number listed by last listing command.  */
  107.  
  108. static int first_line_listed;
  109.  
  110.  
  111. /* Set the source file default for the "list" command to be S.
  112.  
  113.    If S is NULL, and we don't have a default, find one.  This
  114.    should only be called when the user actually tries to use the
  115.    default, since we produce an error if we can't find a reasonable
  116.    default.  Also, since this can cause symbols to be read, doing it
  117.    before we need to would make things slower than necessary.  */
  118.  
  119. void
  120. select_source_symtab (s)
  121.      register struct symtab *s;
  122. {
  123.   struct symtabs_and_lines sals;
  124.   struct symtab_and_line sal;
  125.   struct partial_symtab *ps;
  126.   struct partial_symtab *cs_pst = 0;
  127.   struct objfile *ofp;
  128.   
  129.   if (s)
  130.     {
  131.       current_source_symtab = s;
  132.       current_source_line = 1;
  133.       return;
  134.     }
  135.  
  136.   if (current_source_symtab)
  137.     return;
  138.  
  139.   /* Make the default place to list be the function `main'
  140.      if one exists.  */
  141.   if (lookup_symbol ("main", 0, VAR_NAMESPACE, 0, NULL))
  142.     {
  143.       sals = decode_line_spec ("main", 1);
  144.       sal = sals.sals[0];
  145.       free (sals.sals);
  146.       current_source_symtab = sal.symtab;
  147.       current_source_line = max (sal.line - (lines_to_list - 1), 1);
  148.       if (current_source_symtab)
  149.         return;
  150.     }
  151.   
  152.   /* All right; find the last file in the symtab list (ignoring .h's).  */
  153.  
  154.   current_source_line = 1;
  155.  
  156.   for (ofp = object_files; ofp != NULL; ofp = ofp -> next)
  157.     {
  158.       for (s = ofp -> symtabs; s; s = s->next)
  159.     {
  160.       char *name = s -> filename;
  161.       int len = strlen (name);
  162.       if (! (len > 2 && (STREQ (&name[len - 2], ".h"))))
  163.         {
  164.           current_source_symtab = s;
  165.         }
  166.     }
  167.     }
  168.   if (current_source_symtab)
  169.     return;
  170.  
  171.   /* Howabout the partial symbol tables? */
  172.  
  173.   for (ofp = object_files; ofp != NULL; ofp = ofp -> next)
  174.     {
  175.       for (ps = ofp -> psymtabs; ps != NULL; ps = ps -> next)
  176.     {
  177.       char *name = ps -> filename;
  178.       int len = strlen (name);
  179.       if (! (len > 2 && (STREQ (&name[len - 2], ".h"))))
  180.         {
  181.           cs_pst = ps;
  182.         }
  183.     }
  184.     }
  185.   if (cs_pst)
  186.     {
  187.       if (cs_pst -> readin)
  188.     {
  189.       fatal ("Internal: select_source_symtab: readin pst found and no symtabs.");
  190.     }
  191.       else
  192.     {
  193.       current_source_symtab = PSYMTAB_TO_SYMTAB (cs_pst);
  194.     }
  195.     }
  196.  
  197.   error ("Can't find a default source file");
  198. }
  199.  
  200. static void
  201. show_directories (ignore, from_tty)
  202.      char *ignore;
  203.      int from_tty;
  204. {
  205.   puts_filtered ("Source directories searched: ");
  206.   puts_filtered (source_path);
  207.   puts_filtered ("\n");
  208. }
  209.  
  210. /* Forget what we learned about line positions in source files,
  211.    and which directories contain them;
  212.    must check again now since files may be found in
  213.    a different directory now.  */
  214.  
  215. void
  216. forget_cached_source_info ()
  217. {
  218.   register struct symtab *s;
  219.   register struct objfile *objfile;
  220.  
  221.   for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
  222.     {
  223.       for (s = objfile -> symtabs; s != NULL; s = s -> next)
  224.     {
  225.       if (s -> line_charpos != NULL)
  226.         {
  227.           mfree (objfile -> md, s -> line_charpos);
  228.           s -> line_charpos = NULL;
  229.         }
  230.       if (s -> fullname != NULL)
  231.         {
  232.           mfree (objfile -> md, s -> fullname);
  233.           s -> fullname = NULL;
  234.         }
  235.     }
  236.     }
  237. }
  238.  
  239. void
  240. init_source_path ()
  241. {
  242.   char buf[20];
  243.  
  244.   sprintf (buf, "$cdir%c$cwd", DIRNAME_SEPARATOR);
  245.   source_path = strsave (buf);
  246.   forget_cached_source_info ();
  247. }
  248.  
  249. /* Add zero or more directories to the front of the source path.  */
  250.  
  251. void
  252. directory_command (dirname, from_tty)
  253.      char *dirname;
  254.      int from_tty;
  255. {
  256.   dont_repeat ();
  257.   /* FIXME, this goes to "delete dir"... */
  258.   if (dirname == 0)
  259.     {
  260.       if (query ("Reinitialize source path to empty? ", ""))
  261.     {
  262.       free (source_path);
  263.       init_source_path ();
  264.     }
  265.     }
  266.   else
  267.     mod_path (dirname, &source_path);
  268.   if (from_tty)
  269.     show_directories ((char *)0, from_tty);
  270.   forget_cached_source_info ();
  271. }
  272.  
  273. /* Add zero or more directories to the front of an arbitrary path.  */
  274.  
  275. void
  276. mod_path (dirname, which_path)
  277.      char *dirname;
  278.      char **which_path;
  279. {
  280.   char *old = *which_path;
  281.   int prefix = 0;
  282.  
  283.   if (dirname == 0)
  284.     return;
  285.  
  286.   dirname = strsave (dirname);
  287.   make_cleanup (free, dirname);
  288.  
  289.   do
  290.     {
  291.       char *name = dirname;
  292.       register char *p;
  293.       struct stat st;
  294.  
  295.       {
  296.     char *colon = strchr (name, DIRNAME_SEPARATOR);
  297.     char *space = strchr (name, ' ');
  298.     char *tab = strchr (name, '\t');
  299.     if (colon == 0 && space == 0 && tab ==  0)
  300.       p = dirname = name + strlen (name);
  301.     else
  302.       {
  303.         p = 0;
  304.         if (colon != 0 && (p == 0 || colon < p))
  305.           p = colon;
  306.         if (space != 0 && (p == 0 || space < p))
  307.           p = space;
  308.         if (tab != 0 && (p == 0 || tab < p))
  309.           p = tab;
  310.         dirname = p + 1;
  311.         while (*dirname == DIRNAME_SEPARATOR || *dirname == ' ' || *dirname == '\t')
  312.           ++dirname;
  313.       }
  314.       }
  315.  
  316.       if (p[-1] == '/')
  317.     /* Sigh. "foo/" => "foo" */
  318.     --p;
  319.       *p = '\0';
  320.  
  321.       while (p[-1] == '.')
  322.     {
  323.       if (p - name == 1)
  324.         {
  325.           /* "." => getwd ().  */
  326.           name = current_directory;
  327.           goto append;
  328.         }
  329.       else if (p[-2] == '/')
  330.         {
  331.           if (p - name == 2)
  332.         {
  333.           /* "/." => "/".  */
  334.           *--p = '\0';
  335.           goto append;
  336.         }
  337.           else
  338.         {
  339.           /* "...foo/." => "...foo".  */
  340.           p -= 2;
  341.           *p = '\0';
  342.           continue;
  343.         }
  344.         }
  345.       else
  346.         break;
  347.     }
  348.  
  349.       if (name[0] == '~')
  350.     name = tilde_expand (name);
  351.       else if (name[0] != '/' && name[0] != '$')
  352.     name = concat (current_directory, "/", name, NULL);
  353.       else
  354.     name = savestring (name, p - name);
  355.       make_cleanup (free, name);
  356.  
  357.       /* Unless it's a variable, check existence.  */
  358.       if (name[0] != '$') {
  359.     /* These are warnings, not errors, since we don't want a
  360.        non-existent directory in a .gdbinit file to stop processing
  361.        of the .gdbinit file.
  362.  
  363.        Whether they get added to the path is more debatable.  Current
  364.        answer is yes, in case the user wants to go make the directory
  365.        or whatever.  If the directory continues to not exist/not be
  366.        a directory/etc, then having them in the path should be
  367.        harmless.  */
  368.     if (stat (name, &st) < 0)
  369.       {
  370.         int save_errno = errno;
  371.         fprintf_unfiltered (gdb_stderr, "Warning: ");
  372.         print_sys_errmsg (name, save_errno);
  373.       }
  374.     else if ((st.st_mode & S_IFMT) != S_IFDIR)
  375.       warning ("%s is not a directory.", name);
  376.       }
  377.  
  378.     append:
  379.       {
  380.     register unsigned int len = strlen (name);
  381.  
  382.     p = *which_path;
  383.     while (1)
  384.       {
  385.         if (!strncmp (p, name, len)
  386.         && (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
  387.           {
  388.         /* Found it in the search path, remove old copy */
  389.         if (p > *which_path)
  390.           p--;            /* Back over leading colon */
  391.         if (prefix > p - *which_path)
  392.           goto skip_dup;    /* Same dir twice in one cmd */
  393.         strcpy (p, &p[len+1]);    /* Copy from next \0 or  : */
  394.           }
  395.         p = strchr (p, DIRNAME_SEPARATOR);
  396.         if (p != 0)
  397.           ++p;
  398.         else
  399.           break;
  400.       }
  401.     if (p == 0)
  402.       {
  403.         char tinybuf[2];
  404.  
  405.         tinybuf[0] = DIRNAME_SEPARATOR;
  406.         tinybuf[1] = '\0';
  407.  
  408.         /* If we have already tacked on a name(s) in this command,               be sure they stay on the front as we tack on some more.  */
  409.         if (prefix)
  410.           {
  411.         char *temp, c;
  412.  
  413.         c = old[prefix];
  414.         old[prefix] = '\0';
  415.         temp = concat (old, tinybuf, name, NULL);
  416.         old[prefix] = c;
  417.         *which_path = concat (temp, "", &old[prefix], NULL);
  418.         prefix = strlen (temp);
  419.         free (temp);
  420.           }
  421.         else
  422.           {
  423.         *which_path = concat (name, (old[0] ? tinybuf : old), old, NULL);
  424.         prefix = strlen (name);
  425.           }
  426.         free (old);
  427.         old = *which_path;
  428.       }
  429.       }
  430.   skip_dup: ;
  431.     } while (*dirname != '\0');
  432. }
  433.  
  434.  
  435. static void
  436. source_info (ignore, from_tty)
  437.      char *ignore;
  438.      int from_tty;
  439. {
  440.   register struct symtab *s = current_source_symtab;
  441.  
  442.   if (!s)
  443.     {
  444.       printf_filtered("No current source file.\n");
  445.       return;
  446.     }
  447.   printf_filtered ("Current source file is %s\n", s->filename);
  448.   if (s->dirname)
  449.     printf_filtered ("Compilation directory is %s\n", s->dirname);
  450.   if (s->fullname)
  451.     printf_filtered ("Located in %s\n", s->fullname);
  452.   if (s->nlines)
  453.     printf_filtered ("Contains %d line%s.\n", s->nlines,
  454.              s->nlines == 1 ? "" : "s");
  455.  
  456.   printf_filtered("Source language is %s.\n", language_str (s->language));
  457. }
  458.  
  459.  
  460.  
  461. /* Open a file named STRING, searching path PATH (dir names sep by some char)
  462.    using mode MODE and protection bits PROT in the calls to open.
  463.  
  464.    If TRY_CWD_FIRST, try to open ./STRING before searching PATH.
  465.    (ie pretend the first element of PATH is ".").  This also indicates
  466.    that a slash in STRING disables searching of the path (this is
  467.    so that "exec-file ./foo" or "symbol-file ./foo" insures that you
  468.    get that particular version of foo or an error message).
  469.  
  470.    If FILENAMED_OPENED is non-null, set it to a newly allocated string naming
  471.    the actual file opened (this string will always start with a "/".  We
  472.    have to take special pains to avoid doubling the "/" between the directory
  473.    and the file, sigh!  Emacs gets confuzzed by this when we print the
  474.    source file name!!! 
  475.  
  476.    If a file is found, return the descriptor.
  477.    Otherwise, return -1, with errno set for the last name we tried to open.  */
  478.  
  479. /*  >>>> This should only allow files of certain types,
  480.     >>>>  eg executable, non-directory */
  481. int
  482. openp (path, try_cwd_first, string, mode, prot, filename_opened)
  483.      char *path;
  484.      int try_cwd_first;
  485.      char *string;
  486.      int mode;
  487.      int prot;
  488.      char **filename_opened;
  489. {
  490.   register int fd;
  491.   register char *filename;
  492.   register char *p, *p1;
  493.   register int len;
  494.   int alloclen;
  495.  
  496.   if (!path)
  497.     path = ".";
  498.  
  499.   if (try_cwd_first || string[0] == '/')
  500.     {
  501.       filename = string;
  502.       fd = open (filename, mode, prot);
  503.       if (fd >= 0 || string[0] == '/' || strchr (string, '/'))
  504.     goto done;
  505.     }
  506.  
  507.   /* ./foo => foo */
  508.   while (string[0] == '.' && string[1] == '/')
  509.     string += 2;
  510.  
  511.   alloclen = strlen (path) + strlen (string) + 2;
  512.   filename = (char *) alloca (alloclen);
  513.   fd = -1;
  514.   for (p = path; p; p = p1 ? p1 + 1 : 0)
  515.     {
  516.       p1 = (char *) strchr (p, DIRNAME_SEPARATOR);
  517.       if (p1)
  518.     len = p1 - p;
  519.       else
  520.     len = strlen (p);
  521.  
  522.       if (len == 4 && p[0] == '$' && p[1] == 'c'
  523.                && p[2] == 'w' && p[3] == 'd') {
  524.     /* Name is $cwd -- insert current directory name instead.  */
  525.     int newlen;
  526.  
  527.     /* First, realloc the filename buffer if too short. */
  528.     len = strlen (current_directory);
  529.     newlen = len + strlen (string) + 2;
  530.     if (newlen > alloclen) {
  531.       alloclen = newlen;
  532.       filename = (char *) alloca (alloclen);
  533.     }
  534.     strcpy (filename, current_directory);
  535.       } else {
  536.     /* Normal file name in path -- just use it.  */
  537.     strncpy (filename, p, len);
  538.     filename[len] = 0;
  539.       }
  540.  
  541.       /* Remove trailing slashes */
  542.       while (len > 0 && filename[len-1] == '/')
  543.        filename[--len] = 0;
  544.  
  545.       strcat (filename+len, "/");
  546.       strcat (filename, string);
  547.  
  548.       fd = open (filename, mode);
  549.       if (fd >= 0) break;
  550.     }
  551.  
  552.  done:
  553.   if (filename_opened)
  554.     if (fd < 0)
  555.       *filename_opened = (char *) 0;
  556.     else if (filename[0] == '/')
  557.       *filename_opened = savestring (filename, strlen (filename));
  558.     else
  559.       {
  560.     /* Beware the // my son, the Emacs barfs, the botch that catch... */
  561.        
  562.     *filename_opened = concat (current_directory, 
  563.        '/' == current_directory[strlen(current_directory)-1]? "": "/",
  564.                    filename, NULL);
  565.       }
  566.  
  567.   return fd;
  568. }
  569.  
  570. /* Open a source file given a symtab S.  Returns a file descriptor
  571.    or negative number for error.  */
  572.  
  573. static int
  574. open_source_file (s)
  575.      struct symtab *s;
  576. {
  577.   char *path = source_path;
  578.   char *p;
  579.   int result;
  580.   char *fullname;
  581.  
  582.   /* Quick way out if we already know its full name */
  583.   if (s->fullname) 
  584.     {
  585.       result = open (s->fullname, O_RDONLY);
  586.       if (result >= 0)
  587.         return result;
  588.       /* Didn't work -- free old one, try again. */
  589.       mfree (s->objfile->md, s->fullname);
  590.       s->fullname = NULL;
  591.     }
  592.  
  593.   if (s->dirname != NULL)
  594.     {
  595.       /* Replace a path entry of  $cdir  with the compilation directory name */
  596. #define    cdir_len    5
  597.       /* We cast strstr's result in case an ANSIhole has made it const,
  598.      which produces a "required warning" when assigned to a nonconst. */
  599.       p = (char *)strstr (source_path, "$cdir");
  600.       if (p && (p == path || p[-1] == DIRNAME_SEPARATOR)
  601.         && (p[cdir_len] == DIRNAME_SEPARATOR || p[cdir_len] == '\0')) {
  602.     int len;
  603.  
  604.     path = (char *)
  605.            alloca (strlen (source_path) + 1 + strlen (s->dirname) + 1);
  606.     len = p - source_path;
  607.     strncpy (path, source_path, len);        /* Before $cdir */
  608.     strcpy (path + len, s->dirname);        /* new stuff */
  609.     strcat (path + len, source_path + len + cdir_len); /* After $cdir */
  610.       }
  611.     }
  612.  
  613.   result = openp (path, 0, s->filename, O_RDONLY, 0, &s->fullname);
  614.   if (result < 0)
  615.     {
  616.       /* Didn't work.  Try using just the basename. */
  617.       p = basename (s->filename);
  618.       if (p != s->filename)
  619.     result = openp (path, 0, p, O_RDONLY, 0, &s->fullname);
  620.     }
  621.   if (result >= 0)
  622.     {
  623.       fullname = s->fullname;
  624.       s->fullname = mstrsave (s->objfile->md, s->fullname);
  625.       free (fullname);
  626.     }
  627.   return result;
  628. }
  629.  
  630.  
  631. /* Create and initialize the table S->line_charpos that records
  632.    the positions of the lines in the source file, which is assumed
  633.    to be open on descriptor DESC.
  634.    All set S->nlines to the number of such lines.  */
  635.  
  636. static void
  637. find_source_lines (s, desc)
  638.      struct symtab *s;
  639.      int desc;
  640. {
  641.   struct stat st;
  642.   register char *data, *p, *end;
  643.   int nlines = 0;
  644.   int lines_allocated = 1000;
  645.   int *line_charpos;
  646.   long exec_mtime;
  647.   int size;
  648.  
  649.   line_charpos = (int *) xmmalloc (s -> objfile -> md,
  650.                    lines_allocated * sizeof (int));
  651.   if (fstat (desc, &st) < 0)
  652.     perror_with_name (s->filename);
  653.  
  654.   if (exec_bfd)
  655.     {
  656.       exec_mtime = bfd_get_mtime(exec_bfd);
  657.       if (exec_mtime && exec_mtime < st.st_mtime)
  658.     printf_filtered ("Source file is more recent than executable.\n");
  659.     }
  660.  
  661. #ifdef LSEEK_NOT_LINEAR
  662.   {
  663.     char c;
  664.  
  665.     /* Have to read it byte by byte to find out where the chars live */
  666.  
  667.     line_charpos[0] = tell(desc);
  668.     nlines = 1;
  669.     while (myread(desc, &c, 1)>0) 
  670.       {
  671.     if (c == '\n') 
  672.       {
  673.         if (nlines == lines_allocated) 
  674.           {
  675.         lines_allocated *= 2;
  676.         line_charpos =
  677.           (int *) xmrealloc (s -> objfile -> md, (char *) line_charpos,
  678.                      sizeof (int) * lines_allocated);
  679.           }
  680.         line_charpos[nlines++] = tell(desc);
  681.       }
  682.       }
  683.   }
  684. #else /* lseek linear.  */
  685.   {
  686.     struct cleanup *old_cleanups;
  687.  
  688.     /* st_size might be a large type, but we only support source files whose 
  689.        size fits in an int.  */
  690.     size = (int) st.st_size;
  691.  
  692.     /* Use malloc, not alloca, because this may be pretty large, and we may
  693.        run into various kinds of limits on stack size.  */
  694.     data = (char *) xmalloc (size);
  695.     old_cleanups = make_cleanup (free, data);
  696.  
  697.     if (myread (desc, data, size) < 0)
  698.       perror_with_name (s->filename);
  699.     end = data + size;
  700.     p = data;
  701.     line_charpos[0] = 0;
  702.     nlines = 1;
  703.     while (p != end)
  704.       {
  705.     if (*p++ == '\n'
  706.         /* A newline at the end does not start a new line.  */
  707.         && p != end)
  708.       {
  709.         if (nlines == lines_allocated)
  710.           {
  711.         lines_allocated *= 2;
  712.         line_charpos =
  713.           (int *) xmrealloc (s -> objfile -> md, (char *) line_charpos,
  714.                      sizeof (int) * lines_allocated);
  715.           }
  716.         line_charpos[nlines++] = p - data;
  717.       }
  718.       }
  719.     do_cleanups (old_cleanups);
  720.   }
  721. #endif /* lseek linear.  */
  722.   s->nlines = nlines;
  723.   s->line_charpos =
  724.    (int *) xmrealloc (s -> objfile -> md, (char *) line_charpos,
  725.               nlines * sizeof (int));
  726.  
  727. }
  728.  
  729. /* Return the character position of a line LINE in symtab S.
  730.    Return 0 if anything is invalid.  */
  731.  
  732. #if 0    /* Currently unused */
  733.  
  734. int
  735. source_line_charpos (s, line)
  736.      struct symtab *s;
  737.      int line;
  738. {
  739.   if (!s) return 0;
  740.   if (!s->line_charpos || line <= 0) return 0;
  741.   if (line > s->nlines)
  742.     line = s->nlines;
  743.   return s->line_charpos[line - 1];
  744. }
  745.  
  746. /* Return the line number of character position POS in symtab S.  */
  747.  
  748. int
  749. source_charpos_line (s, chr)
  750.     register struct symtab *s;
  751.     register int chr;
  752. {
  753.   register int line = 0;
  754.   register int *lnp;
  755.     
  756.   if (s == 0 || s->line_charpos == 0) return 0;
  757.   lnp = s->line_charpos;
  758.   /* Files are usually short, so sequential search is Ok */
  759.   while (line < s->nlines  && *lnp <= chr)
  760.     {
  761.       line++;
  762.       lnp++;
  763.     }
  764.   if (line >= s->nlines)
  765.     line = s->nlines;
  766.   return line;
  767. }
  768.  
  769. #endif    /* 0 */
  770.  
  771.  
  772. /* Get full pathname and line number positions for a symtab.
  773.    Return nonzero if line numbers may have changed.
  774.    Set *FULLNAME to actual name of the file as found by `openp',
  775.    or to 0 if the file is not found.  */
  776.  
  777. static int
  778. get_filename_and_charpos (s, fullname)
  779.      struct symtab *s;
  780.      char **fullname;
  781. {
  782.   register int desc, linenums_changed = 0;
  783.   
  784.   desc = open_source_file (s);
  785.   if (desc < 0)
  786.     {
  787.       if (fullname)
  788.     *fullname = NULL;
  789.       return 0;
  790.     }  
  791.   if (fullname)
  792.     *fullname = s->fullname;
  793.   if (s->line_charpos == 0) linenums_changed = 1;
  794.   if (linenums_changed) find_source_lines (s, desc);
  795.   close (desc);
  796.   return linenums_changed;
  797. }
  798.  
  799. /* Print text describing the full name of the source file S
  800.    and the line number LINE and its corresponding character position.
  801.    The text starts with two Ctrl-z so that the Emacs-GDB interface
  802.    can easily find it.
  803.  
  804.    MID_STATEMENT is nonzero if the PC is not at the beginning of that line.
  805.  
  806.    Return 1 if successful, 0 if could not find the file.  */
  807.  
  808. int
  809. identify_source_line (s, line, mid_statement, pc)
  810.      struct symtab *s;
  811.      int line;
  812.      int mid_statement;
  813.      CORE_ADDR pc;
  814. {
  815.   if (s->line_charpos == 0)
  816.     get_filename_and_charpos (s, (char **)NULL);
  817.   if (s->fullname == 0)
  818.     return 0;
  819.   if (line > s->nlines)
  820.     /* Don't index off the end of the line_charpos array.  */
  821.     return 0;
  822.   annotate_source (s->fullname, line, s->line_charpos[line - 1],
  823.            mid_statement, pc);
  824.  
  825.   current_source_line = line;
  826.   first_line_listed = line;
  827.   last_line_listed = line;
  828.   current_source_symtab = s;
  829.   return 1;
  830. }
  831.  
  832. /* Print source lines from the file of symtab S,
  833.    starting with line number LINE and stopping before line number STOPLINE.  */
  834.  
  835. void
  836. print_source_lines (s, line, stopline, noerror)
  837.      struct symtab *s;
  838.      int line, stopline;
  839.      int noerror;
  840. {
  841.   register int c;
  842.   register int desc;
  843.   register FILE *stream;
  844.   int nlines = stopline - line;
  845.  
  846.   /* Regardless of whether we can open the file, set current_source_symtab. */
  847.   current_source_symtab = s;
  848.   current_source_line = line;
  849.   first_line_listed = line;
  850.  
  851.   desc = open_source_file (s);
  852.   if (desc < 0)
  853.     {
  854.       if (! noerror) {
  855.     char *name = alloca (strlen (s->filename) + 100);
  856.     sprintf (name, "%s:%d", s->filename, line);
  857.         print_sys_errmsg (name, errno);
  858.       }
  859.       return;
  860.     }
  861.  
  862.   if (s->line_charpos == 0)
  863.     find_source_lines (s, desc);
  864.  
  865.   if (line < 1 || line > s->nlines)
  866.     {
  867.       close (desc);
  868.       error ("Line number %d out of range; %s has %d lines.",
  869.          line, s->filename, s->nlines);
  870.     }
  871.  
  872.   if (lseek (desc, s->line_charpos[line - 1], 0) < 0)
  873.     {
  874.       close (desc);
  875.       perror_with_name (s->filename);
  876.     }
  877.  
  878.   stream = fdopen (desc, FOPEN_RT);
  879.   clearerr (stream);
  880.  
  881.   while (nlines-- > 0)
  882.     {
  883.       c = fgetc (stream);
  884.       if (c == EOF) break;
  885.       last_line_listed = current_source_line;
  886.       printf_filtered ("%d\t", current_source_line++);
  887.       do
  888.     {
  889.       if (c < 040 && c != '\t' && c != '\n' && c != '\r')
  890.           printf_filtered ("^%c", c + 0100);
  891.       else if (c == 0177)
  892.         printf_filtered ("^?");
  893.       else
  894.         printf_filtered ("%c", c);
  895.     } while (c != '\n' && (c = fgetc (stream)) >= 0);
  896.     }
  897.  
  898.   fclose (stream);
  899. }
  900.  
  901.  
  902.  
  903. /* 
  904.   C++
  905.   Print a list of files and line numbers which a user may choose from
  906.   in order to list a function which was specified ambiguously
  907.   (as with `list classname::overloadedfuncname', for example).
  908.   The vector in SALS provides the filenames and line numbers.
  909.   */
  910. static void
  911. ambiguous_line_spec (sals)
  912.      struct symtabs_and_lines *sals;
  913. {
  914.   int i;
  915.  
  916.   for (i = 0; i < sals->nelts; ++i)
  917.     printf_filtered("file: \"%s\", line number: %d\n",
  918.             sals->sals[i].symtab->filename, sals->sals[i].line);
  919. }
  920.  
  921.  
  922. static void
  923. list_command (arg, from_tty)
  924.      char *arg;
  925.      int from_tty;
  926. {
  927.   struct symtabs_and_lines sals, sals_end;
  928.   struct symtab_and_line sal, sal_end;
  929.   struct symbol *sym;
  930.   char *arg1;
  931.   int no_end = 1;
  932.   int dummy_end = 0;
  933.   int dummy_beg = 0;
  934.   int linenum_beg = 0;
  935.   char *p;
  936.  
  937.   if (!have_full_symbols () && !have_partial_symbols())
  938.     error ("No symbol table is loaded.  Use the \"file\" command.");
  939.  
  940.   /* Pull in a current source symtab if necessary */
  941.   if (current_source_symtab == 0 &&
  942.       (arg == 0 || arg[0] == '+' || arg[0] == '-'))
  943.     select_source_symtab (0);
  944.  
  945.   /* "l" or "l +" lists next ten lines.  */
  946.  
  947.   if (arg == 0 || STREQ (arg, "+"))
  948.     {
  949.       if (current_source_symtab == 0)
  950.     error ("No default source file yet.  Do \"help list\".");
  951.       print_source_lines (current_source_symtab, current_source_line,
  952.               current_source_line + lines_to_list, 0);
  953.       return;
  954.     }
  955.  
  956.   /* "l -" lists previous ten lines, the ones before the ten just listed.  */
  957.   if (STREQ (arg, "-"))
  958.     {
  959.       if (current_source_symtab == 0)
  960.     error ("No default source file yet.  Do \"help list\".");
  961.       print_source_lines (current_source_symtab,
  962.               max (first_line_listed - lines_to_list, 1),
  963.               first_line_listed, 0);
  964.       return;
  965.     }
  966.  
  967.   /* Now if there is only one argument, decode it in SAL
  968.      and set NO_END.
  969.      If there are two arguments, decode them in SAL and SAL_END
  970.      and clear NO_END; however, if one of the arguments is blank,
  971.      set DUMMY_BEG or DUMMY_END to record that fact.  */
  972.  
  973.   arg1 = arg;
  974.   if (*arg1 == ',')
  975.     dummy_beg = 1;
  976.   else
  977.     {
  978.       sals = decode_line_1 (&arg1, 0, 0, 0, 0);
  979.  
  980.       if (! sals.nelts) return;  /*  C++  */
  981.       if (sals.nelts > 1)
  982.     {
  983.       ambiguous_line_spec (&sals);
  984.       free (sals.sals);
  985.       return;
  986.     }
  987.  
  988.       sal = sals.sals[0];
  989.       free (sals.sals);
  990.     }
  991.  
  992.   /* Record whether the BEG arg is all digits.  */
  993.  
  994.   for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; p++);
  995.   linenum_beg = (p == arg1);
  996.  
  997.   while (*arg1 == ' ' || *arg1 == '\t')
  998.     arg1++;
  999.   if (*arg1 == ',')
  1000.     {
  1001.       no_end = 0;
  1002.       arg1++;
  1003.       while (*arg1 == ' ' || *arg1 == '\t')
  1004.     arg1++;
  1005.       if (*arg1 == 0)
  1006.     dummy_end = 1;
  1007.       else
  1008.     {
  1009.       if (dummy_beg)
  1010.         sals_end = decode_line_1 (&arg1, 0, 0, 0, 0);
  1011.       else
  1012.         sals_end = decode_line_1 (&arg1, 0, sal.symtab, sal.line, 0);
  1013.       if (sals_end.nelts == 0) 
  1014.         return;
  1015.       if (sals_end.nelts > 1)
  1016.         {
  1017.           ambiguous_line_spec (&sals_end);
  1018.           free (sals_end.sals);
  1019.           return;
  1020.         }
  1021.       sal_end = sals_end.sals[0];
  1022.       free (sals_end.sals);
  1023.     }
  1024.     }
  1025.  
  1026.   if (*arg1)
  1027.     error ("Junk at end of line specification.");
  1028.  
  1029.   if (!no_end && !dummy_beg && !dummy_end
  1030.       && sal.symtab != sal_end.symtab)
  1031.     error ("Specified start and end are in different files.");
  1032.   if (dummy_beg && dummy_end)
  1033.     error ("Two empty args do not say what lines to list.");
  1034.  
  1035.   /* if line was specified by address,
  1036.      first print exactly which line, and which file.
  1037.      In this case, sal.symtab == 0 means address is outside
  1038.      of all known source files, not that user failed to give a filename.  */
  1039.   if (*arg == '*')
  1040.     {
  1041.       if (sal.symtab == 0)
  1042.     /* FIXME-32x64--assumes sal.pc fits in long.  */
  1043.     error ("No source file for address %s.",
  1044.         local_hex_string((unsigned long) sal.pc));
  1045.       sym = find_pc_function (sal.pc);
  1046.       if (sym)
  1047.     {
  1048.       print_address_numeric (sal.pc, 1, gdb_stdout);
  1049.       printf_filtered (" is in ");
  1050.       fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
  1051.       printf_filtered (" (%s:%d).\n", sal.symtab->filename, sal.line);
  1052.     }
  1053.       else
  1054.     {
  1055.       print_address_numeric (sal.pc, 1, gdb_stdout);
  1056.       printf_filtered (" is at %s:%d.\n",
  1057.                sal.symtab->filename, sal.line);
  1058.     }
  1059.     }
  1060.  
  1061.   /* If line was not specified by just a line number,
  1062.      and it does not imply a symtab, it must be an undebuggable symbol
  1063.      which means no source code.  */
  1064.  
  1065.   if (! linenum_beg && sal.symtab == 0)
  1066.     error ("No line number known for %s.", arg);
  1067.  
  1068.   /* If this command is repeated with RET,
  1069.      turn it into the no-arg variant.  */
  1070.  
  1071.   if (from_tty)
  1072.     *arg = 0;
  1073.  
  1074.   if (dummy_beg && sal_end.symtab == 0)
  1075.     error ("No default source file yet.  Do \"help list\".");
  1076.   if (dummy_beg)
  1077.     print_source_lines (sal_end.symtab,
  1078.             max (sal_end.line - (lines_to_list - 1), 1),
  1079.             sal_end.line + 1, 0);
  1080.   else if (sal.symtab == 0)
  1081.     error ("No default source file yet.  Do \"help list\".");
  1082.   else if (no_end)
  1083.     print_source_lines (sal.symtab,
  1084.             max (sal.line - (lines_to_list / 2), 1),
  1085.             sal.line + (lines_to_list / 2), 0);
  1086.   else
  1087.     print_source_lines (sal.symtab, sal.line,
  1088.             (dummy_end
  1089.              ? sal.line + lines_to_list
  1090.              : sal_end.line + 1),
  1091.             0);
  1092. }
  1093.  
  1094. /* Print info on range of pc's in a specified line.  */
  1095.  
  1096. static void
  1097. line_info (arg, from_tty)
  1098.      char *arg;
  1099.      int from_tty;
  1100. {
  1101.   struct symtabs_and_lines sals;
  1102.   struct symtab_and_line sal;
  1103.   CORE_ADDR start_pc, end_pc;
  1104.   int i;
  1105.  
  1106.   if (arg == 0)
  1107.     {
  1108.       sal.symtab = current_source_symtab;
  1109.       sal.line = last_line_listed;
  1110.       sals.nelts = 1;
  1111.       sals.sals = (struct symtab_and_line *)
  1112.     xmalloc (sizeof (struct symtab_and_line));
  1113.       sals.sals[0] = sal;
  1114.     }
  1115.   else
  1116.     {
  1117.       sals = decode_line_spec_1 (arg, 0);
  1118.       
  1119.       dont_repeat ();
  1120.     }
  1121.  
  1122.   /* C++  More than one line may have been specified, as when the user
  1123.      specifies an overloaded function name. Print info on them all. */
  1124.   for (i = 0; i < sals.nelts; i++)
  1125.     {
  1126.       sal = sals.sals[i];
  1127.       
  1128.       if (sal.symtab == 0)
  1129.     {
  1130.       printf_filtered ("No line number information available");
  1131.       if (sal.pc != 0)
  1132.         {
  1133.           /* This is useful for "info line *0x7f34".  If we can't tell the
  1134.          user about a source line, at least let them have the symbolic
  1135.          address.  */
  1136.           printf_filtered (" for address ");
  1137.           wrap_here ("  ");
  1138.           print_address (sal.pc, gdb_stdout);
  1139.         }
  1140.       else
  1141.         printf_filtered (".");
  1142.       printf_filtered ("\n");
  1143.     }
  1144.       else if (sal.line > 0
  1145.            && find_line_pc_range (sal, &start_pc, &end_pc))
  1146.     {
  1147.       if (start_pc == end_pc)
  1148.         {
  1149.           printf_filtered ("Line %d of \"%s\"",
  1150.                    sal.line, sal.symtab->filename);
  1151.           wrap_here ("  ");
  1152.           printf_filtered (" is at address ");
  1153.           print_address (start_pc, gdb_stdout);
  1154.           wrap_here ("  ");
  1155.           printf_filtered (" but contains no code.\n");
  1156.         }
  1157.       else
  1158.         {
  1159.           printf_filtered ("Line %d of \"%s\"",
  1160.                    sal.line, sal.symtab->filename);
  1161.           wrap_here ("  ");
  1162.           printf_filtered (" starts at address ");
  1163.           print_address (start_pc, gdb_stdout);
  1164.           wrap_here ("  ");
  1165.           printf_filtered (" and ends at ");
  1166.           print_address (end_pc, gdb_stdout);
  1167.           printf_filtered (".\n");
  1168.         }
  1169.  
  1170.       /* x/i should display this line's code.  */
  1171.       set_next_address (start_pc);
  1172.  
  1173.       /* Repeating "info line" should do the following line.  */
  1174.       last_line_listed = sal.line + 1;
  1175.  
  1176.       /* If this is the only line, show the source code.  If it could
  1177.          not find the file, don't do anything special.  */
  1178.       if (annotation_level && sals.nelts == 1)
  1179.         identify_source_line (sal.symtab, sal.line, 0, start_pc);
  1180.     }
  1181.       else
  1182.     /* Is there any case in which we get here, and have an address
  1183.        which the user would want to see?  If we have debugging symbols
  1184.        and no line numbers?  */
  1185.     printf_filtered ("Line number %d is out of range for \"%s\".\n",
  1186.              sal.line, sal.symtab->filename);
  1187.     }
  1188.   free (sals.sals);
  1189. }
  1190.  
  1191. /* Commands to search the source file for a regexp.  */
  1192.  
  1193. /* ARGSUSED */
  1194. static void
  1195. forward_search_command (regex, from_tty)
  1196.      char *regex;
  1197.      int from_tty;
  1198. {
  1199.   register int c;
  1200.   register int desc;
  1201.   register FILE *stream;
  1202.   int line = last_line_listed + 1;
  1203.   char *msg;
  1204.  
  1205.   msg = (char *) re_comp (regex);
  1206.   if (msg)
  1207.     error (msg);
  1208.  
  1209.   if (current_source_symtab == 0)
  1210.     select_source_symtab (0);
  1211.  
  1212.   /* Search from last_line_listed+1 in current_source_symtab */
  1213.  
  1214.   desc = open_source_file (current_source_symtab);
  1215.   if (desc < 0)
  1216.     perror_with_name (current_source_symtab->filename);
  1217.  
  1218.   if (current_source_symtab->line_charpos == 0)
  1219.     find_source_lines (current_source_symtab, desc);
  1220.  
  1221.   if (line < 1 || line > current_source_symtab->nlines)
  1222.     {
  1223.       close (desc);
  1224.       error ("Expression not found");
  1225.     }
  1226.  
  1227.   if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
  1228.     {
  1229.       close (desc);
  1230.       perror_with_name (current_source_symtab->filename);
  1231.     }
  1232.  
  1233.   stream = fdopen (desc, FOPEN_RT);
  1234.   clearerr (stream);
  1235.   while (1) {
  1236. /* FIXME!!!  We walk right off the end of buf if we get a long line!!! */
  1237.     char buf[4096];        /* Should be reasonable??? */
  1238.     register char *p = buf;
  1239.  
  1240.     c = getc (stream);
  1241.     if (c == EOF)
  1242.       break;
  1243.     do {
  1244.       *p++ = c;
  1245.     } while (c != '\n' && (c = getc (stream)) >= 0);
  1246.  
  1247.     /* we now have a source line in buf, null terminate and match */
  1248.     *p = 0;
  1249.     if (re_exec (buf) > 0)
  1250.       {
  1251.     /* Match! */
  1252.     fclose (stream);
  1253.     print_source_lines (current_source_symtab,
  1254.                line, line+1, 0);
  1255.     current_source_line = max (line - lines_to_list / 2, 1);
  1256.     return;
  1257.       }
  1258.     line++;
  1259.   }
  1260.  
  1261.   printf_filtered ("Expression not found\n");
  1262.   fclose (stream);
  1263. }
  1264.  
  1265. /* ARGSUSED */
  1266. static void
  1267. reverse_search_command (regex, from_tty)
  1268.      char *regex;
  1269.      int from_tty;
  1270. {
  1271.   register int c;
  1272.   register int desc;
  1273.   register FILE *stream;
  1274.   int line = last_line_listed - 1;
  1275.   char *msg;
  1276.  
  1277.   msg = (char *) re_comp (regex);
  1278.   if (msg)
  1279.     error (msg);
  1280.  
  1281.   if (current_source_symtab == 0)
  1282.     select_source_symtab (0);
  1283.  
  1284.   /* Search from last_line_listed-1 in current_source_symtab */
  1285.  
  1286.   desc = open_source_file (current_source_symtab);
  1287.   if (desc < 0)
  1288.     perror_with_name (current_source_symtab->filename);
  1289.  
  1290.   if (current_source_symtab->line_charpos == 0)
  1291.     find_source_lines (current_source_symtab, desc);
  1292.  
  1293.   if (line < 1 || line > current_source_symtab->nlines)
  1294.     {
  1295.       close (desc);
  1296.       error ("Expression not found");
  1297.     }
  1298.  
  1299.   if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
  1300.     {
  1301.       close (desc);
  1302.       perror_with_name (current_source_symtab->filename);
  1303.     }
  1304.  
  1305.   stream = fdopen (desc, FOPEN_RT);
  1306.   clearerr (stream);
  1307.   while (line > 1)
  1308.     {
  1309. /* FIXME!!!  We walk right off the end of buf if we get a long line!!! */
  1310.       char buf[4096];        /* Should be reasonable??? */
  1311.       register char *p = buf;
  1312.  
  1313.       c = getc (stream);
  1314.       if (c == EOF)
  1315.     break;
  1316.       do {
  1317.     *p++ = c;
  1318.       } while (c != '\n' && (c = getc (stream)) >= 0);
  1319.  
  1320.       /* We now have a source line in buf; null terminate and match.  */
  1321.       *p = 0;
  1322.       if (re_exec (buf) > 0)
  1323.     {
  1324.       /* Match! */
  1325.       fclose (stream);
  1326.       print_source_lines (current_source_symtab,
  1327.                   line, line+1, 0);
  1328.       current_source_line = max (line - lines_to_list / 2, 1);
  1329.       return;
  1330.     }
  1331.       line--;
  1332.       if (fseek (stream, current_source_symtab->line_charpos[line - 1], 0) < 0)
  1333.     {
  1334.       fclose (stream);
  1335.       perror_with_name (current_source_symtab->filename);
  1336.     }
  1337.     }
  1338.  
  1339.   printf_filtered ("Expression not found\n");
  1340.   fclose (stream);
  1341.   return;
  1342. }
  1343.  
  1344. void
  1345. _initialize_source ()
  1346. {
  1347.   struct cmd_list_element *c;
  1348.   current_source_symtab = 0;
  1349.   init_source_path ();
  1350.  
  1351.   /* The intention is to use POSIX Basic Regular Expressions.
  1352.      Always use the GNU regex routine for consistency across all hosts.
  1353.      Our current GNU regex.c does not have all the POSIX features, so this is
  1354.      just an approximation.  */
  1355.   re_set_syntax (RE_SYNTAX_GREP);
  1356.  
  1357.   c = add_cmd ("directory", class_files, directory_command,
  1358.        "Add directory DIR to beginning of search path for source files.\n\
  1359. Forget cached info on source file locations and line positions.\n\
  1360. DIR can also be $cwd for the current working directory, or $cdir for the\n\
  1361. directory in which the source file was compiled into object code.\n\
  1362. With no argument, reset the search path to $cdir:$cwd, the default.",
  1363.            &cmdlist);
  1364.   c->completer = filename_completer;
  1365.  
  1366.   add_cmd ("directories", no_class, show_directories,
  1367.        "Current search path for finding source files.\n\
  1368. $cwd in the path means the current working directory.\n\
  1369. $cdir in the path means the compilation directory of the source file.",
  1370.        &showlist);
  1371.  
  1372.   add_info ("source", source_info,
  1373.         "Information about the current source file.");
  1374.  
  1375.   add_info ("line", line_info,
  1376.         "Core addresses of the code for a source line.\n\
  1377. Line can be specified as\n\
  1378.   LINENUM, to list around that line in current file,\n\
  1379.   FILE:LINENUM, to list around that line in that file,\n\
  1380.   FUNCTION, to list around beginning of that function,\n\
  1381.   FILE:FUNCTION, to distinguish among like-named static functions.\n\
  1382. Default is to describe the last source line that was listed.\n\n\
  1383. This sets the default address for \"x\" to the line's first instruction\n\
  1384. so that \"x/i\" suffices to start examining the machine code.\n\
  1385. The address is also stored as the value of \"$_\".");
  1386.  
  1387.   add_com ("forward-search", class_files, forward_search_command,
  1388.        "Search for regular expression (see regex(3)) from last line listed.");
  1389.   add_com_alias ("search", "forward-search", class_files, 0);
  1390.  
  1391.   add_com ("reverse-search", class_files, reverse_search_command,
  1392.        "Search backward for regular expression (see regex(3)) from last line listed.");
  1393.  
  1394.   add_com ("list", class_files, list_command,
  1395.        "List specified function or line.\n\
  1396. With no argument, lists ten more lines after or around previous listing.\n\
  1397. \"list -\" lists the ten lines before a previous ten-line listing.\n\
  1398. One argument specifies a line, and ten lines are listed around that line.\n\
  1399. Two arguments with comma between specify starting and ending lines to list.\n\
  1400. Lines can be specified in these ways:\n\
  1401.   LINENUM, to list around that line in current file,\n\
  1402.   FILE:LINENUM, to list around that line in that file,\n\
  1403.   FUNCTION, to list around beginning of that function,\n\
  1404.   FILE:FUNCTION, to distinguish among like-named static functions.\n\
  1405.   *ADDRESS, to list around the line containing that address.\n\
  1406. With two args if one is empty it stands for ten lines away from the other arg.");
  1407.   add_com_alias ("l", "list", class_files, 1);
  1408.  
  1409.   add_show_from_set
  1410.     (add_set_cmd ("listsize", class_support, var_uinteger,
  1411.           (char *)&lines_to_list,
  1412.     "Set number of source lines gdb will list by default.",
  1413.           &setlist),
  1414.      &showlist);
  1415. }
  1416.