home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / gdb / source.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-04  |  37.2 KB  |  1,451 lines

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