31 #include <sys/types.h>
41 #include "filenames.h"
44 #include "readline/readline.h"
46 #define OPEN_MODE (O_RDONLY | O_BINARY)
47 #define FDOPEN_MODE FOPEN_RB
103 _(
"Number of source lines gdb "
104 "will list by default is %s.\n"),
143 static struct symtab *last_source_visited = NULL;
206 error (
_(
"No symbol table is loaded. Use the \"file\" command."));
209 if (current_source_symtab == 0)
229 current_source_pspace = sal->pspace;
230 current_source_symtab = sal->symtab;
244 current_source_symtab = 0;
266 current_source_symtab = s;
272 if (current_source_symtab)
283 current_source_pspace = sal.
pspace;
284 current_source_symtab = sal.
symtab;
286 if (current_source_symtab)
298 int len = strlen (name);
300 if (!(len > 2 && (strcmp (&name[len - 2],
".h") == 0
301 || strcmp (name,
"<<C++-namespaces>>") == 0)))
304 current_source_symtab = s;
308 if (current_source_symtab)
316 current_source_symtab = s;
318 if (current_source_symtab)
321 error (
_(
"Can't find a default source file"));
340 if (*set_path !=
'\0')
410 last_source_visited = NULL;
432 if (!from_tty ||
query (
_(
"Reinitialize source path to empty? ")))
471 add_path (
char *dirname,
char **which_path,
int parse_separators)
473 char *old = *which_path;
483 if (parse_separators)
485 char **argv, **argvp;
491 for (argvp = argv; *argvp; argvp++)
508 p = name + strlen (name);
510 while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1)
511 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
513 && !(p == name + 3 && name[1] ==
':')
515 && IS_DIR_SEPARATOR (p[-1]))
520 while (p > name && p[-1] ==
'.')
528 else if (p > name + 1 && IS_DIR_SEPARATOR (p[-2]))
549 name = tilde_expand (name);
550 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
551 else if (IS_ABSOLUTE_PATH (name) && p == name + 2)
552 name = concat (name,
".", (
char *)NULL);
554 else if (!IS_ABSOLUTE_PATH (name) && name[0] !=
'$')
572 if (stat (name, &st) < 0)
574 int save_errno = errno;
579 else if ((st.st_mode & S_IFMT) != S_IFDIR)
580 warning (
_(
"%s is not a directory."), name);
585 unsigned int len = strlen (name);
594 if (!filename_ncmp (p, name, len)
603 if (prefix > p - *which_path)
609 memmove (p, &p[len + 1], strlen (&p[len + 1]) + 1);
630 temp = concat (old, tinybuf, name, (
char *)NULL);
632 *which_path = concat (temp,
"", &old[prefix], (
char *) NULL);
633 prefix = strlen (temp);
638 *which_path = concat (name, (old[0] ? tinybuf : old),
640 prefix = strlen (name);
673 s->
nlines == 1 ?
"" :
"s");
683 ?
"Includes" :
"Does not include");
692 const int status = stat (name, &st);
700 return (errno != ENOENT);
702 return S_ISREG (st.st_mode);
739 openp (
const char *path,
int opts,
const char *
string,
740 int mode,
char **filename_opened)
761 if (
string[0] ==
'\0')
778 filename = alloca (strlen (
string) + 1);
779 strcpy (filename,
string);
791 for (i = 0;
string[i]; i++)
792 if (IS_DIR_SEPARATOR (
string[i]))
797 if (HAS_DRIVE_SPEC (
string))
798 string = STRIP_DRIVE_SPEC (
string);
801 while (IS_DIR_SEPARATOR(
string[0]))
805 while (
string[0] ==
'.' && IS_DIR_SEPARATOR (
string[1]))
808 alloclen = strlen (path) + strlen (
string) + 2;
809 filename = alloca (alloclen);
812 dir_vec = dirnames_to_char_ptr_vec (path);
817 size_t len = strlen (dir);
819 if (strcmp (dir,
"$cwd") == 0)
826 newlen = len + strlen (
string) + 2;
827 if (newlen > alloclen)
830 filename = alloca (alloclen);
834 else if (strchr(dir,
'~'))
838 char *tilde_expanded;
840 tilde_expanded = tilde_expand (dir);
843 len = strlen (tilde_expanded);
844 newlen = len + strlen (
string) + 2;
845 if (newlen > alloclen)
848 filename = alloca (alloclen);
850 strcpy (filename, tilde_expanded);
851 xfree (tilde_expanded);
856 strcpy (filename, dir);
865 if (strcmp (dir,
"$cdir") == 0)
870 while (len > 0 && IS_DIR_SEPARATOR (filename[len - 1]))
874 strcat (filename,
string);
891 *filename_opened = NULL;
920 filename, O_RDONLY, full_pathname);
923 *full_pathname = NULL;
938 const int from_len = strlen (rule->
from);
939 const int path_len = strlen (path);
941 if (path_len < from_len)
947 if (filename_ncmp (path, rule->
from, from_len) != 0)
954 if (path[from_len] !=
'\0' && !IS_DIR_SEPARATOR (path[from_len]))
991 from_len = strlen (rule->
from);
996 (
char *)
xmalloc (strlen (path) + 1 + strlen (rule->
to) - from_len);
997 strcpy (new_path, rule->
to);
998 strcat (new_path, path + from_len);
1005 const char *dirname,
1022 if (rewritten_fullname != NULL)
1025 *fullname = rewritten_fullname;
1045 if (dirname != NULL)
1052 if (rewritten_dirname != NULL)
1055 dirname = rewritten_dirname;
1070 alloca (strlen (
source_path) + 1 + strlen (dirname) + 1);
1072 strncpy (path, source_path, len);
1073 strcpy (path + len, dirname);
1074 strcat (path + len, source_path + len +
cdir_len);
1079 if (IS_ABSOLUTE_PATH (filename))
1085 if (rewritten_filename != NULL)
1088 filename = rewritten_filename;
1097 p = lbasename (filename);
1174 return lbasename (symtab->
filename);
1180 internal_error (__FILE__, __LINE__,
_(
"invalid filename_display_string"));
1192 char *data, *p, *end;
1194 int lines_allocated = 1000;
1200 line_charpos = (
int *)
xmalloc (lines_allocated *
sizeof (
int));
1201 if (fstat (desc, &st) < 0)
1209 if (mtime && mtime < st.st_mtime)
1210 warning (
_(
"Source file is more recent than executable."));
1217 size = (
int) st.st_size;
1221 data = (
char *)
xmalloc (size);
1225 size =
myread (desc, data, size);
1230 line_charpos[0] = 0;
1238 if (nlines == lines_allocated)
1240 lines_allocated *= 2;
1242 (
int *)
xrealloc ((
char *) line_charpos,
1243 sizeof (
int) * lines_allocated);
1245 line_charpos[nlines++] = p - data;
1253 (
int *)
xrealloc ((
char *) line_charpos, nlines *
sizeof (
int));
1267 int desc, linenums_changed = 0;
1281 linenums_changed = 1;
1282 if (linenums_changed)
1285 return linenums_changed;
1312 current_source_symtab = s;
1329 int nlines = stopline -
line;
1334 current_source_symtab = s;
1345 last_source_visited = s;
1361 if (desc < 0 || noprint)
1368 int len = strlen (filename) + 100;
1369 char *
name = alloca (len);
1371 xsnprintf (name, len,
"%d\t%s", line, filename);
1391 char *local_fullname;
1396 local_fullname = alloca (strlen (s_fullname) + 1);
1397 strcpy (local_fullname, s_fullname);
1413 if (line < 1 || line > s->
nlines)
1416 error (
_(
"Line number %d out of range; %s has %d lines."),
1430 while (nlines-- > 0)
1447 if (c < 040 && c !=
'\t' && c !=
'\n' && c !=
'\r')
1449 xsnprintf (buf,
sizeof (buf),
"^%c", c + 0100);
1457 int c1 = fgetc (stream);
1462 ungetc (c1, stream);
1470 while (c !=
'\n' && (c = fgetc (stream)) >= 0);
1526 for (i = 0; i < sals.
nelts; i++)
1550 else if (sal.
line > 0
1556 if (start_pc == end_pc)
1616 msg = (
char *)
re_comp (regex);
1618 error ((
"%s"), msg);
1620 if (current_source_symtab == 0)
1631 if (line < 1 || line > current_source_symtab->
nlines)
1632 error (
_(
"Expression not found"));
1634 if (lseek (desc, current_source_symtab->
line_charpos[line - 1], 0) < 0)
1643 static char *buf = NULL;
1645 int cursize, newsize;
1657 if (p - buf == cursize)
1659 newsize = cursize + cursize / 2;
1665 while (c !=
'\n' && (c = fgetc (stream)) >= 0);
1669 if (p - buf > 1 && p[-2] ==
'\r')
1677 if (re_exec (buf) > 0)
1705 msg = (
char *)
re_comp (regex);
1707 error ((
"%s"), msg);
1709 if (current_source_symtab == 0)
1720 if (line < 1 || line > current_source_symtab->
nlines)
1721 error (
_(
"Expression not found"));
1723 if (lseek (desc, current_source_symtab->
line_charpos[line - 1], 0) < 0)
1743 while (c !=
'\n' && (c = fgetc (stream)) >= 0);
1747 if (p - buf > 1 && p[-2] ==
'\r')
1755 if (re_exec (buf) > 0)
1765 if (fseek (stream, current_source_symtab->
line_charpos[line - 1], 0) < 0)
1767 const char *filename;
1785 const int last = strlen (path) - 1;
1790 if (IS_DIR_SEPARATOR (path[last]))
1802 while (rule != NULL)
1804 if (FILENAME_CMP (rule->
from, from) == 0)
1822 new_rule->
from = xstrdup (from);
1823 new_rule->
to = xstrdup (to);
1824 new_rule->
next = NULL;
1829 if (substitute_path_rules == NULL)
1831 substitute_path_rules = new_rule;
1839 while (rule->
next != NULL)
1842 rule->
next = new_rule;
1851 if (rule == substitute_path_rules)
1852 substitute_path_rules = rule->
next;
1857 while (prev != NULL && prev->
next != rule)
1885 if (argv != NULL && argv[0] != NULL && argv[1] != NULL)
1886 error (
_(
"Too many arguments in command"));
1888 if (argv != NULL && argv[0] != NULL)
1895 (
_(
"Source path substitution rule matching `%s':\n"), from);
1899 while (rule != NULL)
1923 if (argv != NULL && argv[0] != NULL && argv[1] != NULL)
1924 error (
_(
"Incorrect usage, too many arguments in command"));
1926 if (argv != NULL && argv[0] != NULL)
1934 && !
query (
_(
"Delete all source path substitution rules? ")))
1940 while (rule != NULL)
1944 if (from == NULL || FILENAME_CMP (from, rule->
from) == 0)
1956 if (from != NULL && !rule_found)
1957 error (
_(
"No substitution rule defined for `%s'"), from);
1976 if (argv == NULL || argv[0] == NULL || argv [1] == NULL)
1977 error (
_(
"Incorrect usage, too few arguments in command"));
1979 if (argv[2] != NULL)
1980 error (
_(
"Incorrect usage, too many arguments in command"));
1982 if (*(argv[0]) ==
'\0')
1983 error (
_(
"First argument must be at least one character long"));
2011 current_source_symtab = 0;
2018 re_set_syntax (RE_SYNTAX_GREP);
2021 Add directory DIR to beginning of search path for source files.\n\
2022 Forget cached info on source file locations and line positions.\n\
2023 DIR can also be $cwd for the current working directory, or $cdir for the\n\
2024 directory in which the source file was compiled into object code.\n\
2025 With no argument, reset the search path to $cdir:$cwd, the default."),
2037 Set the search path for finding source files."),
2039 Show the search path for finding source files."),
2041 $cwd in the path means the current working directory.\n\
2042 $cdir in the path means the compilation directory of the source file.\n\
2043 GDB ensures the search path always ends with $cdir:$cwd by\n\
2044 appending these directories if necessary.\n\
2045 Setting the value to an empty string sets it to $cdir:$cwd, the default."),
2051 _(
"Information about the current source file."));
2054 Core addresses of the code for a source line.\n\
2055 Line can be specified as\n\
2056 LINENUM, to list around that line in current file,\n\
2057 FILE:LINENUM, to list around that line in that file,\n\
2058 FUNCTION, to list around beginning of that function,\n\
2059 FILE:FUNCTION, to distinguish among like-named static functions.\n\
2060 Default is to describe the last source line that was listed.\n\n\
2061 This sets the default address for \"x\" to the line's first instruction\n\
2062 so that \"x/i\" suffices to start examining the machine code.\n\
2063 The address is also stored as the value of \"$_\"."));
2066 Search for regular expression (see regex(3)) from last line listed.\n\
2067 The matching line number is also stored as the value of \"$_\"."));
2072 Search backward for regular expression (see regex(3)) from last line listed.\n\
2073 The matching line number is also stored as the value of \"$_\"."));
2077 Set number of source lines gdb will list by default."),
_(
"\
2078 Show number of source lines gdb will list by default."),
_(
"\
2079 Use this to choose how many source lines the \"list\" displays (unless\n\
2080 the \"list\" argument explicitly specifies some other number).\n\
2081 A value of \"unlimited\", or zero, means there's no limit."),
2088 Usage: set substitute-path FROM TO\n\
2089 Add a substitution rule replacing FROM into TO in source file names.\n\
2090 If a substitution rule was previously set for FROM, the old rule\n\
2091 is replaced by the new one."),
2096 Usage: unset substitute-path [FROM]\n\
2097 Delete the rule for substituting FROM in source file names. If FROM\n\
2098 is not specified, all substituting rules are deleted.\n\
2099 If the debugger cannot find a rule for FROM, it will display a warning."),
2104 Usage: show substitute-path [FROM]\n\
2105 Print the rule for substituting FROM in source file names. If FROM\n\
2106 is not specified, print all substitution rules."),
2112 Set how to display filenames."),
_(
"\
2113 Show how to display filenames."),
_(
"\
2114 filename-display can be:\n\
2115 basename - display only basename of a filename\n\
2116 relative - display a filename relative to the compilation directory\n\
2117 absolute - display an absolute filename\n\
2118 By default, relative filenames are displayed."),
void init_source_path(void)
struct cleanup * make_cleanup_freeargv(char **arg)
void mod_path(char *dirname, char **which_path)
const char * symtab_to_filename_for_display(struct symtab *symtab)
#define SYMTAB_COMPUNIT(symtab)
#define SYMTAB_DIRNAME(symtab)
char * gdb_realpath(const char *filename)
void(* forget_cached_source_info)(struct objfile *objfile)
#define ALL_OBJFILE_FILETABS(objfile, cu, s)
char * gdb_abspath(const char *path)
#define COMPUNIT_DEBUGFORMAT(cust)
void ui_out_field_int(struct ui_out *uiout, const char *fldname, int value)
void print_address(struct gdbarch *, CORE_ADDR, struct ui_file *)
int find_and_open_source(const char *filename, const char *dirname, char **fullname)
char * rewrite_source_path(const char *path)
void add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int open_source_file(struct symtab *s)
void set_default_source_symtab_and_line(void)
void warning(const char *fmt,...)
struct type ** const(pascal_builtin_types[])
int query(const char *ctlstr,...)
struct symtab_and_line get_current_source_symtab_and_line(void)
struct ui_file * gdb_stdout
#define COMPUNIT_MACRO_TABLE(cust)
void _initialize_source(void)
void internal_error(const char *file, int line, const char *fmt,...)
void print_sys_errmsg(const char *string, int errcode)
void init_sal(struct symtab_and_line *sal)
int ui_out_is_mi_like_p(struct ui_out *uiout)
int identify_source_line(struct symtab *s, int line, int mid_statement, CORE_ADDR pc)
void select_source_symtab(struct symtab *s)
#define DIRNAME_SEPARATOR
int have_partial_symbols(void)
int ui_out_test_flags(struct ui_out *uiout, int mask)
#define VEC_safe_push(T, V, O)
struct cmd_list_element * cmdlist
void set_next_address(struct gdbarch *, CORE_ADDR)
struct internalvar * lookup_internalvar(const char *name)
#define OPF_SEARCH_IN_PATH
static void line_info(char *, int)
static struct program_space * current_source_pspace
void annotate_source(char *filename, int line, int character, int mid, struct gdbarch *gdbarch, CORE_ADDR pc)
static void print_source_lines_base(struct symtab *s, int line, int stopline, enum print_source_lines_flags flags)
void ui_out_text(struct ui_out *uiout, const char *string)
int source_full_path_of(const char *filename, char **full_pathname)
void printf_filtered(const char *format,...)
const char * symtab_to_fullname(struct symtab *s)
static struct substitute_path_rule * find_substitute_path_rule(const char *from)
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
void null_cleanup(void *arg)
struct cmd_list_element * setlist
static const char filename_display_absolute[]
#define ALL_OBJFILES(obj)
static const char filename_display_relative[]
#define VEC_iterate(T, V, I, P)
static void unset_substitute_path_command(char *args, int from_tty)
void find_source_lines(struct symtab *s, int desc)
#define OPF_TRY_CWD_FIRST
void clear_current_source_symtab_and_line(void)
static void source_info(char *, int)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
#define SYMTAB_OBJFILE(symtab)
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
static struct symtab * current_source_symtab
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
int get_first_line_listed(void)
struct cmd_list_element * showlist
static int last_line_listed
struct cmd_list_element * add_com_alias(const char *name, const char *oldname, enum command_class theclass, int abbrev_flag)
void puts_filtered(const char *string)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **list)
const struct sym_fns * sf
static struct substitute_path_rule * get_substitute_path_rule(const char *path)
static int first_line_listed
static void set_substitute_path_command(char *args, int from_tty)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
struct cmd_list_element * unsetlist
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
static void show_directories_1(char *ignore, int from_tty)
const char * language_str(enum language lang)
static int current_source_line
struct cleanup * make_cleanup_close(int fd)
struct cleanup * make_cleanup_free_char_ptr_vec(VEC(char_ptr)*char_ptr_vec)
static void set_directories_command(char *args, int from_tty, struct cmd_list_element *c)
void forget_cached_source_info_for_objfile(struct objfile *objfile)
void add_substitute_path_rule(char *from, char *to)
static int substitute_path_rule_matches(const struct substitute_path_rule *rule, const char *path)
struct cmd_list_element * add_info(const char *name, cmd_cfunc_ftype *fun, const char *doc)
struct gdbarch * get_current_arch(void)
static const char filename_display_basename[]
#define COMPUNIT_PRODUCER(cust)
void print_source_lines(struct symtab *s, int line, int stopline, enum print_source_lines_flags flags)
struct symtab *(* find_last_source_symtab)(struct objfile *objfile)
void dirnames_to_char_ptr_vec_append(VEC(char_ptr)**vecp, const char *dirnames)
#define SYMTAB_PSPACE(symtab)
static void show_directories_command(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
void wrap_here(char *indent)
#define ALL_FILETABS(objfile, ps, s)
static void clear_lines_listed_range(void)
static void forward_search_command(char *, int)
int myread(int desc, char *addr, int len)
PTR xrealloc(PTR ptr, size_t size)
struct cleanup * make_cleanup_fclose(FILE *file)
const char const char int
int find_line_pc_range(struct symtab_and_line sal, CORE_ADDR *startptr, CORE_ADDR *endptr)
void directory_switch(char *dirname, int from_tty)
void discard_cleanups(struct cleanup *old_chain)
int get_lines_to_list(void)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
struct substitute_path_rule * next
int openp(const char *path, int opts, const char *string, int mode, char **filename_opened)
#define ALL_PSPACES(pspace)
void add_setshow_integer_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static void strip_trailing_directory_separator(char *path)
int xsnprintf(char *str, size_t size, const char *format,...)
static void show_filename_display_string(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
struct ui_file * gdb_stderr
void set_internalvar_integer(struct internalvar *var, LONGEST l)
static struct substitute_path_rule * substitute_path_rules
static int is_regular_file(const char *name)
struct symbol * lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
struct program_space * pspace
#define OPF_RETURN_REALPATH
void forget_cached_source_info(void)
struct symtab_and_line set_current_source_symtab_and_line(const struct symtab_and_line *sal)
char ** gdb_buildargv(const char *s)
void add_path(char *dirname, char **which_path, int parse_separators)
int have_full_symbols(void)
static int get_filename_and_charpos(struct symtab *, char **)
static void directory_command(char *dirname, int from_tty)
int gdb_open_cloexec(const char *filename, int flags, unsigned long mode)
EXTERN_C char * re_comp(const char *)
struct program_space * current_program_space
struct symtabs_and_lines decode_line_with_current_source(char *string, int flags)
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
char * savestring(const char *ptr, size_t len)
static void show_lines_to_list(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static void delete_substitute_path_rule(struct substitute_path_rule *rule)
static const char * filename_display_string
void ui_out_field_string(struct ui_out *uiout, const char *fldname, const char *string)
struct symtab_and_line * sals
struct symtabs_and_lines decode_line_with_last_displayed(char *string, int flags)
struct ui_out * current_uiout
static void reverse_search_command(char *, int)
const struct quick_symbol_functions * qf
#define ALL_PSPACE_OBJFILES(ss, obj)
static const char *const filename_display_kind_names[]
static void show_substitute_path_command(char *args, int from_tty)
void error(const char *fmt,...)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
void add_setshow_optional_filename_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void do_cleanups(struct cleanup *old_chain)
static int last_source_error
const ULONGEST const LONGEST len