31 #include <sys/types.h> 41 #include "filenames.h" 44 #include "readline/readline.h" 48 #define OPEN_MODE (O_RDONLY | O_BINARY) 49 #define FDOPEN_MODE FOPEN_RB 93 _(
"Number of source lines gdb " 94 "will list by default is %s.\n"),
196 error (
_(
"No symbol table is loaded. Use the \"file\" command."));
267 std::vector<symtab_and_line> sals
286 int len = strlen (
name);
288 if (!(len > 2 && (strcmp (&
name[len - 2],
".h") == 0
289 || strcmp (
name,
"<<C++-namespaces>>") == 0)))
309 error (
_(
"Can't find a default source file"));
329 if (*set_path !=
'\0')
421 if (!from_tty ||
query (
_(
"Reinitialize source path to empty? ")))
460 add_path (
const char *dirname,
char **which_path,
int parse_separators)
462 char *old = *which_path;
472 if (parse_separators)
495 while (!(IS_DIR_SEPARATOR (*
name) && p <=
name + 1)
496 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
498 && !(p ==
name + 3 &&
name[1] ==
':')
500 && IS_DIR_SEPARATOR (p[-1]))
505 while (p >
name && p[-1] ==
'.')
513 else if (p >
name + 1 && IS_DIR_SEPARATOR (p[-2]))
535 #ifdef HAVE_DOS_BASED_FILE_SYSTEM 536 else if (IS_ABSOLUTE_PATH (
name) && p ==
name + 2)
537 name = concat (
name,
".", (
char *)NULL);
539 else if (!IS_ABSOLUTE_PATH (
name) &&
name[0] !=
'$')
557 if (stat (
name, &st) < 0)
559 int save_errno = errno;
564 else if ((st.st_mode & S_IFMT) != S_IFDIR)
570 unsigned int len = strlen (
name);
579 if (!filename_ncmp (p,
name, len)
588 if (prefix > p - *which_path)
594 memmove (p, &p[len + 1], strlen (&p[len + 1]) + 1);
615 temp = concat (old, tinybuf,
name, (
char *)NULL);
617 *which_path = concat (temp,
"", &old[prefix], (
char *) NULL);
618 prefix = strlen (temp);
623 *which_path = concat (
name, (old[0] ? tinybuf : old),
625 prefix = strlen (
name);
658 s->
nlines == 1 ?
"" :
"s");
668 ?
"Includes" :
"Does not include");
695 if (S_ISREG (st.st_mode))
698 if (S_ISDIR (st.st_mode))
739 openp (
const char *path,
int opts,
const char *
string,
740 int mode,
char **filename_opened)
764 if (
string[0] ==
'\0')
777 int i, reg_file_errno;
781 filename = (
char *) alloca (strlen (
string) + 1);
782 strcpy (filename,
string);
792 last_errno = reg_file_errno;
796 for (i = 0;
string[i]; i++)
797 if (IS_DIR_SEPARATOR (
string[i]))
802 if (HAS_DRIVE_SPEC (
string))
803 string = STRIP_DRIVE_SPEC (
string);
806 while (IS_DIR_SEPARATOR(
string[0]))
810 while (
string[0] ==
'.' && IS_DIR_SEPARATOR (
string[1]))
813 alloclen = strlen (path) + strlen (
string) + 2;
814 filename = (
char *) alloca (alloclen);
818 dir_vec = dirnames_to_char_ptr_vec (path);
823 size_t len = strlen (dir);
826 if (strcmp (dir,
"$cwd") == 0)
833 newlen = len + strlen (
string) + 2;
834 if (newlen > alloclen)
837 filename = (
char *) alloca (alloclen);
841 else if (strchr(dir,
'~'))
849 len = strlen (tilde_expanded.get ());
850 newlen = len + strlen (
string) + 2;
851 if (newlen > alloclen)
854 filename = (
char *) alloca (alloclen);
856 strcpy (filename, tilde_expanded.get ());
861 strcpy (filename, dir);
870 if (strcmp (dir,
"$cdir") == 0)
875 while (len > 0 && IS_DIR_SEPARATOR (filename[len - 1]))
879 strcat (filename,
string);
889 last_errno = reg_file_errno;
899 *filename_opened = NULL;
903 *filename_opened =
gdb_abspath (filename).release ();
929 filename, O_RDONLY, full_pathname);
932 *full_pathname = NULL;
947 const int from_len = strlen (rule->
from);
948 const int path_len = strlen (path);
950 if (path_len < from_len)
956 if (filename_ncmp (path, rule->
from, from_len) != 0)
963 if (path[from_len] !=
'\0' && !IS_DIR_SEPARATOR (path[from_len]))
999 from_len = strlen (rule->
from);
1004 (
char *)
xmalloc (strlen (path) + 1 + strlen (rule->
to) - from_len);
1005 strcpy (new_path, rule->
to);
1006 strcat (new_path, path + from_len);
1013 const char *dirname,
1029 if (rewritten_fullname != NULL)
1032 *fullname = rewritten_fullname;
1051 if (dirname != NULL)
1058 if (rewritten_dirname != NULL)
1059 dirname = rewritten_dirname.get ();
1073 alloca (strlen (
source_path) + 1 + strlen (dirname) + 1);
1076 strcpy (path + len, dirname);
1083 if (IS_ABSOLUTE_PATH (filename))
1089 if (rewritten_filename != NULL)
1090 filename = rewritten_filename.get ();
1098 p = lbasename (filename);
1151 fullname.reset (xstrdup (s->
filename));
1177 internal_error (__FILE__, __LINE__,
_(
"invalid filename_display_string"));
1189 char *data, *p, *end;
1191 int lines_allocated = 1000;
1197 line_charpos =
XNEWVEC (
int, lines_allocated);
1198 if (fstat (desc, &st) < 0)
1206 if (mtime && mtime < st.st_mtime)
1207 warning (
_(
"Source file is more recent than executable."));
1214 size = (int) st.st_size;
1227 line_charpos[0] = 0;
1235 if (nlines == lines_allocated)
1237 lines_allocated *= 2;
1239 (
int *)
xrealloc ((
char *) line_charpos,
1240 sizeof (int) * lines_allocated);
1242 line_charpos[nlines++] = p - data;
1250 (
int *)
xrealloc ((
char *) line_charpos, nlines *
sizeof (int));
1264 int desc, linenums_changed = 0;
1278 linenums_changed = 1;
1279 if (linenums_changed)
1282 return linenums_changed;
1320 print_source_lines_flags
flags)
1325 int nlines = stopline - line;
1356 if (desc < 0 || noprint)
1363 int len = strlen (filename) + 100;
1364 char *
name = (
char *) alloca (len);
1372 uiout->
text (
"\tin ");
1383 char *local_fullname;
1388 local_fullname = (
char *) alloca (strlen (s_fullname) + 1);
1389 strcpy (local_fullname, s_fullname);
1405 if (line < 1 || line > s->
nlines)
1408 error (
_(
"Line number %d out of range; %s has %d lines."),
1419 clearerr (stream.get ());
1421 while (nlines-- > 0)
1425 c = fgetc (stream.get ());
1438 if (c < 040 && c !=
'\t' && c !=
'\n' && c !=
'\r')
1440 xsnprintf (buf,
sizeof (buf),
"^%c", c + 0100);
1448 int c1 = fgetc (stream.get ());
1453 ungetc (c1, stream.get ());
1461 while (c !=
'\n' && (c = fgetc (stream.get ())) >= 0);
1472 print_source_lines_flags
flags)
1484 std::vector<symtab_and_line> decoded_sals;
1503 sals = decoded_sals;
1510 for (
const auto &sal : sals)
1515 if (sal.symtab == 0)
1533 else if (sal.line > 0
1539 if (start_pc == end_pc)
1597 msg = (
char *)
re_comp (regex);
1599 error ((
"%s"), msg);
1613 error (
_(
"Expression not found"));
1620 clearerr (stream.get ());
1623 static char *buf = NULL;
1625 int cursize, newsize;
1628 buf = (
char *)
xmalloc (cursize);
1631 c = fgetc (stream.get ());
1637 if (p - buf == cursize)
1639 newsize = cursize + cursize / 2;
1640 buf = (
char *)
xrealloc (buf, newsize);
1645 while (c !=
'\n' && (c = fgetc (stream.get ())) >= 0);
1649 if (p - buf > 1 && p[-2] ==
'\r')
1657 if (re_exec (buf) > 0)
1682 msg = (
char *)
re_comp (regex);
1684 error ((
"%s"), msg);
1698 error (
_(
"Expression not found"));
1705 clearerr (stream.get ());
1712 c = fgetc (stream.get ());
1719 while (c !=
'\n' && (c = fgetc (stream.get ())) >= 0);
1723 if (p - buf > 1 && p[-2] ==
'\r')
1731 if (re_exec (buf) > 0)
1740 if (fseek (stream.get (),
1743 const char *filename;
1759 const int last = strlen (path) - 1;
1764 if (IS_DIR_SEPARATOR (path[last]))
1776 while (rule != NULL)
1778 if (FILENAME_CMP (rule->
from,
from) == 0)
1796 new_rule->
to = xstrdup (
to);
1797 new_rule->
next = NULL;
1812 while (rule->
next != NULL)
1815 rule->
next = new_rule;
1830 while (prev != NULL && prev->
next != rule)
1855 if (
argv != NULL &&
argv[0] != NULL &&
argv[1] != NULL)
1856 error (
_(
"Too many arguments in command"));
1858 if (
argv != NULL &&
argv[0] != NULL)
1865 (
_(
"Source path substitution rule matching `%s':\n"),
from);
1869 while (rule != NULL)
1889 if (
argv != NULL &&
argv[0] != NULL &&
argv[1] != NULL)
1890 error (
_(
"Incorrect usage, too many arguments in command"));
1892 if (
argv != NULL &&
argv[0] != NULL)
1900 && !
query (
_(
"Delete all source path substitution rules? ")))
1906 while (rule != NULL)
1910 if (
from == NULL || FILENAME_CMP (
from, rule->
from) == 0)
1922 if (
from != NULL && !rule_found)
1923 error (
_(
"No substitution rule defined for `%s'"),
from);
1937 if (
argv == NULL ||
argv[0] == NULL ||
argv [1] == NULL)
1938 error (
_(
"Incorrect usage, too few arguments in command"));
1940 if (
argv[2] != NULL)
1941 error (
_(
"Incorrect usage, too many arguments in command"));
1943 if (*(
argv[0]) ==
'\0')
1944 error (
_(
"First argument must be at least one character long"));
1977 re_set_syntax (RE_SYNTAX_GREP);
1980 Add directory DIR to beginning of search path for source files.\n\ 1981 Forget cached info on source file locations and line positions.\n\ 1982 DIR can also be $cwd for the current working directory, or $cdir for the\n\ 1983 directory in which the source file was compiled into object code.\n\ 1984 With no argument, reset the search path to $cdir:$cwd, the default."),
1996 Set the search path for finding source files."),
1998 Show the search path for finding source files."),
2000 $cwd in the path means the current working directory.\n\ 2001 $cdir in the path means the compilation directory of the source file.\n\ 2002 GDB ensures the search path always ends with $cdir:$cwd by\n\ 2003 appending these directories if necessary.\n\ 2004 Setting the value to an empty string sets it to $cdir:$cwd, the default."),
2010 _(
"Information about the current source file."));
2013 Core addresses of the code for a source line.\n\ 2014 Line can be specified as\n\ 2015 LINENUM, to list around that line in current file,\n\ 2016 FILE:LINENUM, to list around that line in that file,\n\ 2017 FUNCTION, to list around beginning of that function,\n\ 2018 FILE:FUNCTION, to distinguish among like-named static functions.\n\ 2019 Default is to describe the last source line that was listed.\n\n\ 2020 This sets the default address for \"x\" to the line's first instruction\n\ 2021 so that \"x/i\" suffices to start examining the machine code.\n\ 2022 The address is also stored as the value of \"$_\"."));
2025 Search for regular expression (see regex(3)) from last line listed.\n\ 2026 The matching line number is also stored as the value of \"$_\"."));
2031 Search backward for regular expression (see regex(3)) from last line listed.\n\ 2032 The matching line number is also stored as the value of \"$_\"."));
2036 Set number of source lines gdb will list by default."),
_(
"\ 2037 Show number of source lines gdb will list by default."),
_(
"\ 2038 Use this to choose how many source lines the \"list\" displays (unless\n\ 2039 the \"list\" argument explicitly specifies some other number).\n\ 2040 A value of \"unlimited\", or zero, means there's no limit."),
2047 Usage: set substitute-path FROM TO\n\ 2048 Add a substitution rule replacing FROM into TO in source file names.\n\ 2049 If a substitution rule was previously set for FROM, the old rule\n\ 2050 is replaced by the new one."),
2055 Usage: unset substitute-path [FROM]\n\ 2056 Delete the rule for substituting FROM in source file names. If FROM\n\ 2057 is not specified, all substituting rules are deleted.\n\ 2058 If the debugger cannot find a rule for FROM, it will display a warning."),
2063 Usage: show substitute-path [FROM]\n\ 2064 Print the rule for substituting FROM in source file names. If FROM\n\ 2065 is not specified, print all substitution rules."),
2071 Set how to display filenames."),
_(
"\ 2072 Show how to display filenames."),
_(
"\ 2073 filename-display can be:\n\ 2074 basename - display only basename of a filename\n\ 2075 relative - display a filename relative to the compilation directory\n\ 2076 absolute - display an absolute filename\n\ 2077 By default, relative filenames are displayed."),
void init_source_path(void)
const char * symtab_to_filename_for_display(struct symtab *symtab)
#define SYMTAB_COMPUNIT(symtab)
#define SYMTAB_DIRNAME(symtab)
void(* forget_cached_source_info)(struct objfile *objfile)
#define ALL_OBJFILE_FILETABS(objfile, cu, s)
#define COMPUNIT_DEBUGFORMAT(cust)
static int is_regular_file(const char *name, int *errno_ptr)
void field_string(const char *fldname, const char *string)
void print_address(struct gdbarch *, CORE_ADDR, struct ui_file *)
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_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
ui_out_flags test_flags(ui_out_flags mask)
int find_and_open_source(const char *filename, const char *dirname, char **fullname)
int open_source_file(struct symtab *s)
void set_default_source_symtab_and_line(void)
void warning(const char *fmt,...)
int query(const char *ctlstr,...)
struct program_space * pspace
static void set_substitute_path_command(const char *args, int from_tty)
struct symtab_and_line get_current_source_symtab_and_line(void)
struct cmd_list_element * add_info(const char *name, cmd_const_cfunc_ftype *fun, const char *doc)
void dirnames_to_char_ptr_vec_append(VEC(char_ptr) **vecp, const char *dirnames)
#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)
static void info_line_command(const char *arg, int from_tty)
int identify_source_line(struct symtab *s, int line, int mid_statement, CORE_ADDR pc)
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_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void mod_path(const char *dirname, char **which_path)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
void select_source_symtab(struct symtab *s)
#define DIRNAME_SEPARATOR
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
int have_partial_symbols(void)
#define VEC_safe_push(T, V, O)
struct cmd_list_element * cmdlist
void set_next_address(struct gdbarch *, CORE_ADDR)
struct block_symbol lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
struct internalvar * lookup_internalvar(const char *name)
gdb::unique_xmalloc_ptr< char > gdb_realpath(const char *filename)
#define OPF_SEARCH_IN_PATH
static struct program_space * current_source_pspace
static void directory_command(const char *dirname, int from_tty)
void annotate_source(char *filename, int line, int character, int mid, struct gdbarch *gdbarch, CORE_ADDR pc)
void text(const char *string)
int source_full_path_of(const char *filename, char **full_pathname)
void printf_filtered(const char *format,...)
void directory_switch(const char *dirname, int from_tty)
const char * symtab_to_fullname(struct symtab *s)
std::vector< symtab_and_line > decode_line_with_last_displayed(const char *string, int flags)
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
struct cmd_list_element * setlist
static const char filename_display_absolute[]
static const char filename_display_relative[]
#define VEC_iterate(T, V, I, P)
static void set_directories_command(const char *args, int from_tty, struct cmd_list_element *c)
void find_source_lines(struct symtab *s, int desc)
std::unique_ptr< FILE, gdb_file_deleter > gdb_file_up
#define OPF_TRY_CWD_FIRST
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
void clear_current_source_symtab_and_line(void)
objfile(bfd *, const char *, objfile_flags)
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,...)
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)
const struct sym_fns * sf
static struct substitute_path_rule * get_substitute_path_rule(const char *path)
static int first_line_listed
static void print_source_lines_base(struct symtab *s, int line, int stopline, print_source_lines_flags flags)
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)
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 gdbarch * get_current_arch(void)
static const char filename_display_basename[]
#define COMPUNIT_PRODUCER(cust)
struct symtab *(* find_last_source_symtab)(struct objfile *objfile)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
#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 add_path(const char *dirname, char **which_path, int parse_separators)
#define ALL_FILETABS(objfile, ps, s)
static void clear_lines_listed_range(void)
static void forward_search_command(const char *regex, int from_tty)
int myread(int desc, char *addr, int len)
void wrap_here(const char *indent)
gdb::unique_xmalloc_ptr< char > rewrite_source_path(const char *path)
PTR xrealloc(PTR ptr, size_t size)
int find_line_pc_range(struct symtab_and_line sal, CORE_ADDR *startptr, CORE_ADDR *endptr)
void discard_cleanups(struct cleanup *old_chain)
int get_lines_to_list(void)
gdb::unique_xmalloc_ptr< char > gdb_abspath(const char *path)
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)
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)
void field_int(const char *fldname, int value)
void print_source_lines(struct symtab *s, int line, int stopline, print_source_lines_flags flags)
void set_internalvar_integer(struct internalvar *var, LONGEST l)
static void reverse_search_command(const char *regex, int from_tty)
static struct substitute_path_rule * substitute_path_rules
std::vector< symtab_and_line > decode_line_with_current_source(const char *string, int flags)
struct program_space * pspace
#define OPF_RETURN_REALPATH
static struct symtab * last_source_visited
void forget_cached_source_info(void)
int have_full_symbols(void)
static int get_filename_and_charpos(struct symtab *, char **)
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
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)
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_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static const char * filename_display_string
struct symtab_and_line set_current_source_symtab_and_line(const symtab_and_line &sal)
struct cleanup * make_cleanup_free_char_ptr_vec(VEC(char_ptr) *char_ptr_vec)
#define ALL_OBJFILES(obj)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc)
const struct quick_symbol_functions * qf
static void info_source_command(const char *ignore, int from_tty)
#define ALL_PSPACE_OBJFILES(ss, obj)
static const char *const filename_display_kind_names[]
static void unset_substitute_path_command(const char *args, int from_tty)
void error(const char *fmt,...)
static void show_substitute_path_command(const char *args, int from_tty)
void do_cleanups(struct cleanup *old_chain)
static int last_source_error