X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fsource.c;h=7a71cbd2eeed0efb21ad4046dc062cf21f0c2738;hb=112e8700a6fd2fed65ca70132c9cbed4132e8bd4;hp=894531adb142e5b564a04d8a28f60507fbe44968;hpb=eb822aa6d0f2cdc1a3125da084b96c5bbe32cb86;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/source.c b/gdb/source.c index 894531adb1..7a71cbd2ee 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-2014 Free Software Foundation, Inc. + Copyright (C) 1986-2016 Free Software Foundation, Inc. This file is part of GDB. @@ -42,6 +42,8 @@ #include "completer.h" #include "ui-out.h" #include "readline/readline.h" +#include "common/enum-flags.h" +#include #define OPEN_MODE (O_RDONLY | O_BINARY) #define FDOPEN_MODE FOPEN_RB @@ -94,7 +96,7 @@ static struct program_space *current_source_pspace; and friends should be rewritten to count characters and see where things are wrapping, but that would be a fair amount of work. */ -int lines_to_list = 10; +static int lines_to_list = 10; static void show_lines_to_list (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -259,6 +261,7 @@ select_source_symtab (struct symtab *s) struct symtabs_and_lines sals; struct symtab_and_line sal; struct objfile *ofp; + struct compunit_symtab *cu; if (s) { @@ -273,7 +276,7 @@ select_source_symtab (struct symtab *s) /* Make the default place to list be the function `main' if one exists. */ - if (lookup_symbol (main_name (), 0, VAR_DOMAIN, 0)) + if (lookup_symbol (main_name (), 0, VAR_DOMAIN, 0).symbol) { sals = decode_line_with_current_source (main_name (), DECODE_LINE_FUNFIRSTLINE); @@ -281,7 +284,7 @@ select_source_symtab (struct symtab *s) xfree (sals.sals); current_source_pspace = sal.pspace; current_source_symtab = sal.symtab; - current_source_line = max (sal.line - (lines_to_list - 1), 1); + current_source_line = std::max (sal.line - (lines_to_list - 1), 1); if (current_source_symtab) return; } @@ -291,7 +294,7 @@ select_source_symtab (struct symtab *s) current_source_line = 1; - ALL_SYMTABS (ofp, s) + ALL_FILETABS (ofp, cu, s) { const char *name = s->filename; int len = strlen (name); @@ -369,9 +372,10 @@ show_directories_command (struct ui_file *file, int from_tty, void forget_cached_source_info_for_objfile (struct objfile *objfile) { + struct compunit_symtab *cu; struct symtab *s; - ALL_OBJFILE_SYMTABS (objfile, s) + ALL_OBJFILE_FILETABS (objfile, cu, s) { if (s->line_charpos != NULL) { @@ -652,15 +656,18 @@ static void source_info (char *ignore, int from_tty) { struct symtab *s = current_source_symtab; + struct compunit_symtab *cust; if (!s) { printf_filtered (_("No current source file.\n")); return; } + + cust = SYMTAB_COMPUNIT (s); printf_filtered (_("Current source file is %s\n"), s->filename); - if (s->dirname) - printf_filtered (_("Compilation directory is %s\n"), s->dirname); + if (SYMTAB_DIRNAME (s) != NULL) + printf_filtered (_("Compilation directory is %s\n"), SYMTAB_DIRNAME (s)); if (s->fullname) printf_filtered (_("Located in %s\n"), s->fullname); if (s->nlines) @@ -668,15 +675,23 @@ source_info (char *ignore, int from_tty) s->nlines == 1 ? "" : "s"); printf_filtered (_("Source language is %s.\n"), language_str (s->language)); - printf_filtered (_("Compiled with %s debugging format.\n"), s->debugformat); + printf_filtered (_("Producer is %s.\n"), + COMPUNIT_PRODUCER (cust) != NULL + ? COMPUNIT_PRODUCER (cust) : _("unknown")); + printf_filtered (_("Compiled with %s debugging format.\n"), + COMPUNIT_DEBUGFORMAT (cust)); printf_filtered (_("%s preprocessor macro info.\n"), - s->macro_table ? "Includes" : "Does not include"); + COMPUNIT_MACRO_TABLE (cust) != NULL + ? "Includes" : "Does not include"); } -/* Return True if the file NAME exists and is a regular file. */ +/* Return True if the file NAME exists and is a regular file. + If the result is false then *ERRNO_PTR is set to a useful value assuming + we're expecting a regular file. */ + static int -is_regular_file (const char *name) +is_regular_file (const char *name, int *errno_ptr) { struct stat st; const int status = stat (name, &st); @@ -687,9 +702,21 @@ is_regular_file (const char *name) on obscure systems where stat does not work as expected. */ if (status != 0) - return (errno != ENOENT); + { + if (errno != ENOENT) + return 1; + *errno_ptr = ENOENT; + return 0; + } - return S_ISREG (st.st_mode); + if (S_ISREG (st.st_mode)) + return 1; + + if (S_ISDIR (st.st_mode)) + *errno_ptr = EISDIR; + else + *errno_ptr = EINVAL; + return 0; } /* Open a file named STRING, searching path PATH (dir names sep by some char) @@ -736,6 +763,9 @@ openp (const char *path, int opts, const char *string, struct cleanup *back_to; int ix; char *dir; + /* The errno set for the last name we tried to open (and + failed). */ + int last_errno = 0; /* The open syscall MODE parameter is not specified. */ gdb_assert ((mode & O_CREAT) == 0); @@ -761,20 +791,22 @@ openp (const char *path, int opts, const char *string, if ((opts & OPF_TRY_CWD_FIRST) || IS_ABSOLUTE_PATH (string)) { - int i; + int i, reg_file_errno; - if (is_regular_file (string)) + if (is_regular_file (string, ®_file_errno)) { - filename = alloca (strlen (string) + 1); + filename = (char *) alloca (strlen (string) + 1); strcpy (filename, string); fd = gdb_open_cloexec (filename, mode, 0); if (fd >= 0) goto done; + last_errno = errno; } else { filename = NULL; fd = -1; + last_errno = reg_file_errno; } if (!(opts & OPF_SEARCH_IN_PATH)) @@ -796,8 +828,9 @@ openp (const char *path, int opts, const char *string, string += 2; alloclen = strlen (path) + strlen (string) + 2; - filename = alloca (alloclen); + filename = (char *) alloca (alloclen); fd = -1; + last_errno = ENOENT; dir_vec = dirnames_to_char_ptr_vec (path); back_to = make_cleanup_free_char_ptr_vec (dir_vec); @@ -805,6 +838,7 @@ openp (const char *path, int opts, const char *string, for (ix = 0; VEC_iterate (char_ptr, dir_vec, ix, dir); ++ix) { size_t len = strlen (dir); + int reg_file_errno; if (strcmp (dir, "$cwd") == 0) { @@ -817,7 +851,7 @@ openp (const char *path, int opts, const char *string, if (newlen > alloclen) { alloclen = newlen; - filename = alloca (alloclen); + filename = (char *) alloca (alloclen); } strcpy (filename, current_directory); } @@ -835,7 +869,7 @@ openp (const char *path, int opts, const char *string, if (newlen > alloclen) { alloclen = newlen; - filename = alloca (alloclen); + filename = (char *) alloca (alloclen); } strcpy (filename, tilde_expanded); xfree (tilde_expanded); @@ -863,12 +897,15 @@ openp (const char *path, int opts, const char *string, strcat (filename + len, SLASH_STRING); strcat (filename, string); - if (is_regular_file (filename)) + if (is_regular_file (filename, ®_file_errno)) { fd = gdb_open_cloexec (filename, mode, 0); if (fd >= 0) break; + last_errno = errno; } + else + last_errno = reg_file_errno; } do_cleanups (back_to); @@ -885,6 +922,7 @@ done: *filename_opened = gdb_abspath (filename); } + errno = last_errno; return fd; } @@ -1105,7 +1143,7 @@ open_source_file (struct symtab *s) if (!s) return -1; - return find_and_open_source (s->filename, s->dirname, &s->fullname); + return find_and_open_source (s->filename, SYMTAB_DIRNAME (s), &s->fullname); } /* Finds the fullname that a symtab represents. @@ -1125,7 +1163,8 @@ symtab_to_fullname (struct symtab *s) to handle cases like the file being moved. */ if (s->fullname == NULL) { - int fd = find_and_open_source (s->filename, s->dirname, &s->fullname); + int fd = find_and_open_source (s->filename, SYMTAB_DIRNAME (s), + &s->fullname); if (fd >= 0) close (fd); @@ -1137,10 +1176,11 @@ symtab_to_fullname (struct symtab *s) /* rewrite_source_path would be applied by find_and_open_source, we should report the pathname where GDB tried to find the file. */ - if (s->dirname == NULL || IS_ABSOLUTE_PATH (s->filename)) + if (SYMTAB_DIRNAME (s) == NULL || IS_ABSOLUTE_PATH (s->filename)) fullname = xstrdup (s->filename); else - fullname = concat (s->dirname, SLASH_STRING, s->filename, NULL); + fullname = concat (SYMTAB_DIRNAME (s), SLASH_STRING, + s->filename, (char *) NULL); back_to = make_cleanup (xfree, fullname); s->fullname = rewrite_source_path (fullname); @@ -1185,7 +1225,7 @@ find_source_lines (struct symtab *s, int desc) int size; gdb_assert (s); - line_charpos = (int *) xmalloc (lines_allocated * sizeof (int)); + line_charpos = XNEWVEC (int, lines_allocated); if (fstat (desc, &st) < 0) perror_with_name (symtab_to_filename_for_display (s)); @@ -1308,7 +1348,7 @@ identify_source_line (struct symtab *s, int line, int mid_statement, static void print_source_lines_base (struct symtab *s, int line, int stopline, - enum print_source_lines_flags flags) + print_source_lines_flags flags) { int c; int desc; @@ -1325,7 +1365,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, /* If printing of source lines is disabled, just print file and line number. */ - if (ui_out_test_flags (uiout, ui_source_list)) + if (uiout->test_flags (ui_source_list)) { /* Only prints "No such file or directory" once. */ if ((s != last_source_visited) || (!last_source_error)) @@ -1342,7 +1382,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, else { desc = last_source_error; - flags |= PRINT_SOURCE_LINES_NOERROR; + flags |= PRINT_SOURCE_LINES_NOERROR; noprint = 1; } @@ -1354,26 +1394,23 @@ print_source_lines_base (struct symtab *s, int line, int stopline, { const char *filename = symtab_to_filename_for_display (s); int len = strlen (filename) + 100; - char *name = alloca (len); + char *name = (char *) alloca (len); xsnprintf (name, len, "%d\t%s", line, filename); print_sys_errmsg (name, errno); } else { - ui_out_field_int (uiout, "line", line); - ui_out_text (uiout, "\tin "); + uiout->field_int ("line", line); + uiout->text ("\tin "); /* CLI expects only the "file" field. TUI expects only the "fullname" field (and TUI does break if "file" is printed). MI expects both fields. ui_source_list is set only for CLI, not for TUI. */ - if (ui_out_is_mi_like_p (uiout) - || ui_out_test_flags (uiout, ui_source_list)) - ui_out_field_string (uiout, "file", - symtab_to_filename_for_display (s)); - if (ui_out_is_mi_like_p (uiout) - || !ui_out_test_flags (uiout, ui_source_list)) + if (uiout->is_mi_like_p () || uiout->test_flags (ui_source_list)) + uiout->field_string ("file", symtab_to_filename_for_display (s)); + if (uiout->is_mi_like_p () || !uiout->test_flags (ui_source_list)) { const char *s_fullname = symtab_to_fullname (s); char *local_fullname; @@ -1381,13 +1418,13 @@ print_source_lines_base (struct symtab *s, int line, int stopline, /* ui_out_field_string may free S_FULLNAME by calling open_source_file for it again. See e.g., tui_field_string->tui_show_source. */ - local_fullname = alloca (strlen (s_fullname) + 1); + local_fullname = (char *) alloca (strlen (s_fullname) + 1); strcpy (local_fullname, s_fullname); - ui_out_field_string (uiout, "fullname", local_fullname); + uiout->field_string ("fullname", local_fullname); } - ui_out_text (uiout, "\n"); + uiout->text ("\n"); } return; @@ -1425,20 +1462,20 @@ print_source_lines_base (struct symtab *s, int line, int stopline, last_line_listed = current_source_line; if (flags & PRINT_SOURCE_LINES_FILENAME) { - ui_out_text (uiout, symtab_to_filename_for_display (s)); - ui_out_text (uiout, ":"); + uiout->text (symtab_to_filename_for_display (s)); + uiout->text (":"); } xsnprintf (buf, sizeof (buf), "%d\t", current_source_line++); - ui_out_text (uiout, buf); + uiout->text (buf); do { if (c < 040 && c != '\t' && c != '\n' && c != '\r') { xsnprintf (buf, sizeof (buf), "^%c", c + 0100); - ui_out_text (uiout, buf); + uiout->text (buf); } else if (c == 0177) - ui_out_text (uiout, "^?"); + uiout->text ("^?"); else if (c == '\r') { /* Skip a \r character, but only before a \n. */ @@ -1452,7 +1489,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, else { xsnprintf (buf, sizeof (buf), "%c", c); - ui_out_text (uiout, buf); + uiout->text (buf); } } while (c != '\n' && (c = fgetc (stream)) >= 0); @@ -1468,7 +1505,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, void print_source_lines (struct symtab *s, int line, int stopline, - enum print_source_lines_flags flags) + print_source_lines_flags flags) { print_source_lines_base (s, line, stopline, flags); } @@ -1496,8 +1533,7 @@ line_info (char *arg, int from_tty) sal.line = current_source_line; sals.nelts = 1; - sals.sals = (struct symtab_and_line *) - xmalloc (sizeof (struct symtab_and_line)); + sals.sals = XNEW (struct symtab_and_line); sals.sals[0] = sal; } else @@ -1633,7 +1669,7 @@ forward_search_command (char *regex, int from_tty) int cursize, newsize; cursize = 256; - buf = xmalloc (cursize); + buf = (char *) xmalloc (cursize); p = buf; c = fgetc (stream); @@ -1645,7 +1681,7 @@ forward_search_command (char *regex, int from_tty) if (p - buf == cursize) { newsize = cursize + cursize / 2; - buf = xrealloc (buf, newsize); + buf = (char *) xrealloc (buf, newsize); p = buf + cursize; cursize = newsize; } @@ -1668,7 +1704,7 @@ forward_search_command (char *regex, int from_tty) do_cleanups (cleanups); print_source_lines (current_source_symtab, line, line + 1, 0); set_internalvar_integer (lookup_internalvar ("_"), line); - current_source_line = max (line - lines_to_list / 2, 1); + current_source_line = std::max (line - lines_to_list / 2, 1); return; } line++; @@ -1746,7 +1782,7 @@ reverse_search_command (char *regex, int from_tty) do_cleanups (cleanups); print_source_lines (current_source_symtab, line, line + 1, 0); set_internalvar_integer (lookup_internalvar ("_"), line); - current_source_line = max (line - lines_to_list / 2, 1); + current_source_line = std::max (line - lines_to_list / 2, 1); return; } line--; @@ -1804,9 +1840,8 @@ void add_substitute_path_rule (char *from, char *to) { struct substitute_path_rule *rule; - struct substitute_path_rule *new_rule; + struct substitute_path_rule *new_rule = XNEW (struct substitute_path_rule); - new_rule = xmalloc (sizeof (struct substitute_path_rule)); new_rule->from = xstrdup (from); new_rule->to = xstrdup (to); new_rule->next = NULL; @@ -2035,16 +2070,6 @@ Setting the value to an empty string sets it to $cdir:$cwd, the default."), show_directories_command, &setlist, &showlist); - if (xdb_commands) - { - add_com_alias ("D", "directory", class_files, 0); - add_cmd ("ld", no_class, show_directories_1, _("\ -Current search path for finding source files.\n\ -$cwd in the path means the current working directory.\n\ -$cdir in the path means the compilation directory of the source file."), - &cmdlist); - } - add_info ("source", source_info, _("Information about the current source file.")); @@ -2071,12 +2096,6 @@ Search backward for regular expression (see regex(3)) from last line listed.\n\ The matching line number is also stored as the value of \"$_\".")); add_com_alias ("rev", "reverse-search", class_files, 1); - if (xdb_commands) - { - add_com_alias ("/", "forward-search", class_files, 0); - add_com_alias ("?", "reverse-search", class_files, 0); - } - add_setshow_integer_cmd ("listsize", class_support, &lines_to_list, _("\ Set number of source lines gdb will list by default."), _("\ Show number of source lines gdb will list by default."), _("\