X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fsource.c;h=c1127656cbb2b6d7dabf606f78fd8119faa849b2;hb=2117c711ae07700adb57ea5b5ca61e4c32d7e3d2;hp=710b90c9eb9758d5c3ae7992abaf6347d724d093;hpb=40aea4772114f8c0b62595560e67b5e229b47ee6;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/source.c b/gdb/source.c index 710b90c9eb..c1127656cb 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1,5 +1,5 @@ /* List lines of source files for GDB, the GNU debugger. - Copyright (C) 1986-2013 Free Software Foundation, Inc. + Copyright (C) 1986-2014 Free Software Foundation, Inc. This file is part of GDB. @@ -30,8 +30,8 @@ #include "filestuff.h" #include -#include "gdb_string.h" -#include "gdb_stat.h" +#include +#include #include #include "gdbcore.h" #include "gdb_regex.h" @@ -45,9 +45,6 @@ #include "ui-out.h" #include "readline/readline.h" -#include "psymtab.h" - - #define OPEN_MODE (O_RDONLY | O_BINARY) #define FDOPEN_MODE FOPEN_RB @@ -577,17 +574,33 @@ add_path (char *dirname, char **which_path, int parse_separators) char tinybuf[2]; p = *which_path; - /* FIXME: we should use realpath() or its work-alike - before comparing. Then all the code above which - removes excess slashes and dots could simply go away. */ - if (!filename_cmp (p, name)) + while (1) { - /* Found it in the search path, remove old copy. */ - if (p > *which_path) - p--; /* Back over leading separator. */ - if (prefix > p - *which_path) - goto skip_dup; /* Same dir twice in one cmd. */ - memmove (p, &p[len + 1], strlen (&p[len + 1]) + 1); /* Copy from next \0 or : */ + /* FIXME: we should use realpath() or its work-alike + before comparing. Then all the code above which + removes excess slashes and dots could simply go away. */ + if (!filename_ncmp (p, name, len) + && (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR)) + { + /* Found it in the search path, remove old copy. */ + if (p > *which_path) + { + /* Back over leading separator. */ + p--; + } + if (prefix > p - *which_path) + { + /* Same dir twice in one cmd. */ + goto skip_dup; + } + /* Copy from next '\0' or ':'. */ + memmove (p, &p[len + 1], strlen (&p[len + 1]) + 1); + } + p = strchr (p, DIRNAME_SEPARATOR); + if (p != 0) + ++p; + else + break; } tinybuf[0] = DIRNAME_SEPARATOR; @@ -677,9 +690,10 @@ is_regular_file (const char *name) If OPF_TRY_CWD_FIRST, try to open ./STRING before searching PATH. (ie pretend the first element of PATH is "."). This also indicates - that a slash in STRING disables searching of the path (this is - so that "exec-file ./foo" or "symbol-file ./foo" insures that you - get that particular version of foo or an error message). + that, unless OPF_SEARCH_IN_PATH is also specified, a slash in STRING + disables searching of the path (this is so that "exec-file ./foo" or + "symbol-file ./foo" insures that you get that particular version of + foo or an error message). If OPTS has OPF_SEARCH_IN_PATH set, absolute names will also be searched in path (we usually want this for source files but not for @@ -691,6 +705,11 @@ is_regular_file (const char *name) and the file, sigh! Emacs gets confuzzed by this when we print the source file name!!! + If OPTS has OPF_RETURN_REALPATH set return FILENAME_OPENED resolved by + gdb_realpath. Even without OPF_RETURN_REALPATH this function still returns + filename starting with "/". If FILENAME_OPENED is NULL this option has no + effect. + If a file is found, return the descriptor. Otherwise, return -1, with errno set for the last name we tried to open. */ @@ -850,20 +869,10 @@ done: /* If a file was opened, canonicalize its filename. */ if (fd < 0) *filename_opened = NULL; - else if (IS_ABSOLUTE_PATH (filename)) + else if ((opts & OPF_RETURN_REALPATH) != 0) *filename_opened = gdb_realpath (filename); else - { - /* Beware the // my son, the Emacs barfs, the botch that catch... */ - - char *f = concat (current_directory, - IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]) - ? "" : SLASH_STRING, - filename, (char *)NULL); - - *filename_opened = gdb_realpath (f); - xfree (f); - } + *filename_opened = gdb_abspath (filename); } return fd; @@ -886,8 +895,9 @@ source_full_path_of (const char *filename, char **full_pathname) { int fd; - fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH, filename, - O_RDONLY, full_pathname); + fd = openp (source_path, + OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, + filename, O_RDONLY, full_pathname); if (fd < 0) { *full_pathname = NULL; @@ -985,6 +995,7 @@ find_and_open_source (const char *filename, char *path = source_path; const char *p; int result; + struct cleanup *cleanup; /* Quick way out if we already know its full name. */ @@ -1016,6 +1027,8 @@ find_and_open_source (const char *filename, *fullname = NULL; } + cleanup = make_cleanup (null_cleanup, NULL); + if (dirname != NULL) { /* If necessary, rewrite the compilation directory name according @@ -1063,15 +1076,18 @@ find_and_open_source (const char *filename, } } - result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, fullname); + result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, filename, + OPEN_MODE, fullname); if (result < 0) { /* Didn't work. Try using just the basename. */ p = lbasename (filename); if (p != filename) - result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, fullname); + result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, p, + OPEN_MODE, fullname); } + do_cleanups (cleanup); return result; } @@ -1840,9 +1856,10 @@ show_substitute_path_command (char *args, int from_tty) struct substitute_path_rule *rule = substitute_path_rules; char **argv; char *from = NULL; + struct cleanup *cleanup; argv = gdb_buildargv (args); - make_cleanup_freeargv (argv); + cleanup = make_cleanup_freeargv (argv); /* We expect zero or one argument. */ @@ -1866,6 +1883,8 @@ show_substitute_path_command (char *args, int from_tty) printf_filtered (" `%s' -> `%s'.\n", rule->from, rule->to); rule = rule->next; } + + do_cleanups (cleanup); } /* Implement the "unset substitute-path" command. */ @@ -1877,10 +1896,11 @@ unset_substitute_path_command (char *args, int from_tty) char **argv = gdb_buildargv (args); char *from = NULL; int rule_found = 0; + struct cleanup *cleanup; /* This function takes either 0 or 1 argument. */ - make_cleanup_freeargv (argv); + cleanup = make_cleanup_freeargv (argv); if (argv != NULL && argv[0] != NULL && argv[1] != NULL) error (_("Incorrect usage, too many arguments in command")); @@ -1918,6 +1938,8 @@ unset_substitute_path_command (char *args, int from_tty) error (_("No substitution rule defined for `%s'"), from); forget_cached_source_info (); + + do_cleanups (cleanup); } /* Add a new source path substitution rule. */ @@ -1927,9 +1949,10 @@ set_substitute_path_command (char *args, int from_tty) { char **argv; struct substitute_path_rule *rule; + struct cleanup *cleanup; argv = gdb_buildargv (args); - make_cleanup_freeargv (argv); + cleanup = make_cleanup_freeargv (argv); if (argv == NULL || argv[0] == NULL || argv [1] == NULL) error (_("Incorrect usage, too few arguments in command")); @@ -1956,6 +1979,8 @@ set_substitute_path_command (char *args, int from_tty) add_substitute_path_rule (argv[0], argv[1]); forget_cached_source_info (); + + do_cleanups (cleanup); }