From patchwork Tue Jul 25 17:20:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 21763 Received: (qmail 72854 invoked by alias); 25 Jul 2017 17:22:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 72752 invoked by uid 89); 25 Jul 2017 17:22:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy8-pub.mail.unifiedlayer.com Received: from gproxy8-pub.mail.unifiedlayer.com (HELO gproxy8-pub.mail.unifiedlayer.com) (67.222.33.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Jul 2017 17:22:12 +0000 Received: from cmgw4 (unknown [10.0.90.85]) by gproxy8.mail.unifiedlayer.com (Postfix) with ESMTP id 773171AB479 for ; Tue, 25 Jul 2017 11:21:18 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id p5MF1v00b2f2jeq015MJMH; Tue, 25 Jul 2017 11:21:18 -0600 X-Authority-Analysis: v=2.2 cv=G/hsK5s5 c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=G3gG6ho9WtcA:10 a=zstS-IiYAAAA:8 a=7FIms0H3mJcsxGTjBMEA:9 a=6JuhWrEk9uxBkoqX:21 a=Vs7x1NMydiofnI1Z:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-29-39-24.hlrn.qwest.net ([174.29.39.24]:55470 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1da3WF-0015gW-6R; Tue, 25 Jul 2017 11:21:15 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 05/24] Use gdb_file_up in source.c Date: Tue, 25 Jul 2017 11:20:48 -0600 Message-Id: <20170725172107.9799-6-tom@tromey.com> In-Reply-To: <20170725172107.9799-1-tom@tromey.com> References: <20170725172107.9799-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1da3WF-0015gW-6R X-Source-Sender: 174-29-39-24.hlrn.qwest.net (bapiya.Home) [174.29.39.24]:55470 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes some functions in source.c to use gdb_file_up. ChangeLog 2017-07-25 Tom Tromey * source.c (print_source_lines_base, forward_search_command) (reverse_search_command): Use gdb_file_up. --- gdb/ChangeLog | 5 +++++ gdb/source.c | 45 ++++++++++++++++----------------------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ab0a51f..4c23f79 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2017-07-25 Tom Tromey + * source.c (print_source_lines_base, forward_search_command) + (reverse_search_command): Use gdb_file_up. + +2017-07-25 Tom Tromey + * fbsd-nat.c (fbsd_find_memory_regions): Update. 2017-07-25 Tom Tromey diff --git a/gdb/source.c b/gdb/source.c index 8926e54..4cc862c 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1353,9 +1353,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, int c; int desc; int noprint = 0; - FILE *stream; int nlines = stopline - line; - struct cleanup *cleanup; struct ui_out *uiout = current_uiout; /* Regardless of whether we can open the file, set current_source_symtab. */ @@ -1448,15 +1446,14 @@ print_source_lines_base (struct symtab *s, int line, int stopline, perror_with_name (symtab_to_filename_for_display (s)); } - stream = fdopen (desc, FDOPEN_MODE); - clearerr (stream); - cleanup = make_cleanup_fclose (stream); + gdb_file_up stream (fdopen (desc, FDOPEN_MODE)); + clearerr (stream.get ()); while (nlines-- > 0) { char buf[20]; - c = fgetc (stream); + c = fgetc (stream.get ()); if (c == EOF) break; last_line_listed = current_source_line; @@ -1479,12 +1476,12 @@ print_source_lines_base (struct symtab *s, int line, int stopline, else if (c == '\r') { /* Skip a \r character, but only before a \n. */ - int c1 = fgetc (stream); + int c1 = fgetc (stream.get ()); if (c1 != '\n') printf_filtered ("^%c", c + 0100); if (c1 != EOF) - ungetc (c1, stream); + ungetc (c1, stream.get ()); } else { @@ -1492,10 +1489,8 @@ print_source_lines_base (struct symtab *s, int line, int stopline, uiout->text (buf); } } - while (c != '\n' && (c = fgetc (stream)) >= 0); + while (c != '\n' && (c = fgetc (stream.get ())) >= 0); } - - do_cleanups (cleanup); } /* Show source lines from the file of symtab S, starting with line @@ -1630,7 +1625,6 @@ forward_search_command (char *regex, int from_tty) { int c; int desc; - FILE *stream; int line; char *msg; struct cleanup *cleanups; @@ -1659,9 +1653,8 @@ forward_search_command (char *regex, int from_tty) perror_with_name (symtab_to_filename_for_display (current_source_symtab)); discard_cleanups (cleanups); - stream = fdopen (desc, FDOPEN_MODE); - clearerr (stream); - cleanups = make_cleanup_fclose (stream); + gdb_file_up stream (fdopen (desc, FDOPEN_MODE)); + clearerr (stream.get ()); while (1) { static char *buf = NULL; @@ -1672,7 +1665,7 @@ forward_search_command (char *regex, int from_tty) buf = (char *) xmalloc (cursize); p = buf; - c = fgetc (stream); + c = fgetc (stream.get ()); if (c == EOF) break; do @@ -1686,7 +1679,7 @@ forward_search_command (char *regex, int from_tty) cursize = newsize; } } - while (c != '\n' && (c = fgetc (stream)) >= 0); + while (c != '\n' && (c = fgetc (stream.get ())) >= 0); /* Remove the \r, if any, at the end of the line, otherwise regular expressions that end with $ or \n won't work. */ @@ -1701,7 +1694,6 @@ forward_search_command (char *regex, int from_tty) if (re_exec (buf) > 0) { /* Match! */ - do_cleanups (cleanups); print_source_lines (current_source_symtab, line, line + 1, 0); set_internalvar_integer (lookup_internalvar ("_"), line); current_source_line = std::max (line - lines_to_list / 2, 1); @@ -1711,7 +1703,6 @@ forward_search_command (char *regex, int from_tty) } printf_filtered (_("Expression not found\n")); - do_cleanups (cleanups); } static void @@ -1719,7 +1710,6 @@ reverse_search_command (char *regex, int from_tty) { int c; int desc; - FILE *stream; int line; char *msg; struct cleanup *cleanups; @@ -1748,23 +1738,22 @@ reverse_search_command (char *regex, int from_tty) perror_with_name (symtab_to_filename_for_display (current_source_symtab)); discard_cleanups (cleanups); - stream = fdopen (desc, FDOPEN_MODE); - clearerr (stream); - cleanups = make_cleanup_fclose (stream); + gdb_file_up stream (fdopen (desc, FDOPEN_MODE)); + clearerr (stream.get ()); while (line > 1) { /* FIXME!!! We walk right off the end of buf if we get a long line!!! */ char buf[4096]; /* Should be reasonable??? */ char *p = buf; - c = fgetc (stream); + c = fgetc (stream.get ()); if (c == EOF) break; do { *p++ = c; } - while (c != '\n' && (c = fgetc (stream)) >= 0); + while (c != '\n' && (c = fgetc (stream.get ())) >= 0); /* Remove the \r, if any, at the end of the line, otherwise regular expressions that end with $ or \n won't work. */ @@ -1779,25 +1768,23 @@ reverse_search_command (char *regex, int from_tty) if (re_exec (buf) > 0) { /* Match! */ - do_cleanups (cleanups); print_source_lines (current_source_symtab, line, line + 1, 0); set_internalvar_integer (lookup_internalvar ("_"), line); current_source_line = std::max (line - lines_to_list / 2, 1); return; } line--; - if (fseek (stream, current_source_symtab->line_charpos[line - 1], 0) < 0) + if (fseek (stream.get (), + current_source_symtab->line_charpos[line - 1], 0) < 0) { const char *filename; - do_cleanups (cleanups); filename = symtab_to_filename_for_display (current_source_symtab); perror_with_name (filename); } } printf_filtered (_("Expression not found\n")); - do_cleanups (cleanups); return; }