aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-10-27 12:23:44 -0600
committerTom Tromey <tom@tromey.com>2018-11-09 15:47:45 -0700
commit2179fbc36d23f29a83fb3dfcac0fc7d1fb31b8e8 (patch)
tree25112de3c1340c90ca19cefb2dbf5ab5877b6a96 /gdb/tui
parent9c122c7f9c8260d2cceb1e8f29d69607531f43ba (diff)
downloadgdb-2179fbc36d23f29a83fb3dfcac0fc7d1fb31b8e8.zip
gdb-2179fbc36d23f29a83fb3dfcac0fc7d1fb31b8e8.tar.gz
gdb-2179fbc36d23f29a83fb3dfcac0fc7d1fb31b8e8.tar.bz2
Return scoped_fd from open_source_file and find_and_open_source
This changes open_source_file and find_and_open_source to return scoped_fd, then updates the callers as appropriate, including using scoped_fd::to_file. Tested by the buildbot. gdb/ChangeLog 2018-11-09 Tom Tromey <tom@tromey.com> * common/scoped_fd.h (class scoped_fd): Add move constructor and move assignment operator. * psymtab.c (psymtab_to_fullname): Update. * source.h (open_source_file): Return scoped_fd. (find_and_open_source): Likewise. * source.c (open_source_file): Return scoped_fd. (get_filename_and_charpos): Update. (print_source_lines_base): Update. Use scoped_fd::to_file. (forward_search_command): Likewise. (reverse_search_command): Likewise. (find_and_open_source): Return scoped_fd. * tui/tui-source.c (tui_set_source_content): Update. Use gdb_file_up.
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-source.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index a26b7b0..3c4f06b 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -46,8 +46,7 @@ tui_set_source_content (struct symtab *s,
if (s != (struct symtab *) NULL)
{
- FILE *stream;
- int i, desc, c, line_width, nlines;
+ int i, c, line_width, nlines;
char *src_line = 0;
if ((ret = tui_alloc_source_buffer (TUI_SRC_WIN)) == TUI_SUCCESS)
@@ -56,8 +55,8 @@ tui_set_source_content (struct symtab *s,
/* Take hilite (window border) into account, when
calculating the number of lines. */
nlines = (line_no + (TUI_SRC_WIN->generic.height - 2)) - line_no;
- desc = open_source_file (s);
- if (desc < 0)
+ scoped_fd desc = open_source_file (s);
+ if (desc.get () < 0)
{
if (!noerror)
{
@@ -72,22 +71,17 @@ tui_set_source_content (struct symtab *s,
else
{
if (s->line_charpos == 0)
- find_source_lines (s, desc);
+ find_source_lines (s, desc.get ());
if (line_no < 1 || line_no > s->nlines)
- {
- close (desc);
- printf_unfiltered ("Line number %d out of range; "
- "%s has %d lines.\n",
- line_no,
- symtab_to_filename_for_display (s),
- s->nlines);
- }
- else if (lseek (desc, s->line_charpos[line_no - 1], 0) < 0)
- {
- close (desc);
- perror_with_name (symtab_to_filename_for_display (s));
- }
+ printf_unfiltered ("Line number %d out of range; "
+ "%s has %d lines.\n",
+ line_no,
+ symtab_to_filename_for_display (s),
+ s->nlines);
+ else if (lseek (desc.get (), s->line_charpos[line_no - 1], 0)
+ < 0)
+ perror_with_name (symtab_to_filename_for_display (s));
else
{
int offset, cur_line_no, cur_line, cur_len, threshold;
@@ -108,8 +102,8 @@ tui_set_source_content (struct symtab *s,
line and the offset to start the display. */
offset = src->horizontal_offset;
threshold = (line_width - 1) + offset;
- stream = fdopen (desc, FOPEN_RT);
- clearerr (stream);
+ gdb_file_up stream = desc.to_file (FOPEN_RT);
+ clearerr (stream.get ());
cur_line = 0;
src->gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
src->start_line_or_addr.loa = LOA_LINE;
@@ -123,7 +117,7 @@ tui_set_source_content (struct symtab *s,
= TUI_SRC_WIN->generic.content[cur_line];
/* Get the first character in the line. */
- c = fgetc (stream);
+ c = fgetc (stream.get ());
if (offset == 0)
src_line = TUI_SRC_WIN->generic.content[cur_line]
@@ -200,21 +194,21 @@ tui_set_source_content (struct symtab *s,
{ /* If we have not reached EOL, then
eat chars until we do. */
while (c != EOF && c != '\n' && c != '\r')
- c = fgetc (stream);
+ c = fgetc (stream.get ());
/* Handle non-'\n' end-of-line. */
if (c == '\r'
- && (c = fgetc (stream)) != '\n'
+ && (c = fgetc (stream.get ())) != '\n'
&& c != EOF)
{
- ungetc (c, stream);
- c = '\r';
+ ungetc (c, stream.get ());
+ c = '\r';
}
}
}
while (c != EOF && c != '\n' && c != '\r'
&& i < threshold
- && (c = fgetc (stream)));
+ && (c = fgetc (stream.get ())));
}
/* Now copy the line taking the offset into
account. */
@@ -232,7 +226,6 @@ tui_set_source_content (struct symtab *s,
}
if (offset > 0)
xfree (src_line);
- fclose (stream);
TUI_SRC_WIN->generic.content_size = nlines;
ret = TUI_SUCCESS;
}