• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revision5dc1a7047a77f86de7518a99805af64891d4e22a (tree)
Time2018-03-09 14:00:08
AuthorTom Tromey <tom@trom...>
CommiterTom Tromey

Log Message

Use scoped_fd in more places

This changes a few more places to use scoped_fd. This allows the
removal of some cleanups.

Regression tested by the buildbot, though note that I'm not sure
whether the buildbot actually builds anything using all of these
files.

gdb/ChangeLog
2018-03-08 Tom Tromey <tom@tromey.com>

* source.c (get_filename_and_charpos): Use scoped_fd.
* nto-procfs.c (procfs_open_1): Use scoped_fd.
(procfs_pidlist): Likewise.
* procfs.c (proc_get_LDT_entry): Use scoped_fd.
(iterate_over_mappings): Likewise.

Change Summary

Incremental Difference

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
11 2018-03-08 Tom Tromey <tom@tromey.com>
22
3+ * source.c (get_filename_and_charpos): Use scoped_fd.
4+ * nto-procfs.c (procfs_open_1): Use scoped_fd.
5+ (procfs_pidlist): Likewise.
6+ * procfs.c (proc_get_LDT_entry): Use scoped_fd.
7+ (iterate_over_mappings): Likewise.
8+
9+2018-03-08 Tom Tromey <tom@tromey.com>
10+
311 * infcall.c (struct call_return_meta_info)
412 <stack_temporaries_enabled>: Remove.
513 (get_call_return_value, call_function_by_hand_dummy): Update.
--- a/gdb/nto-procfs.c
+++ b/gdb/nto-procfs.c
@@ -43,6 +43,7 @@
4343 #include "solib.h"
4444 #include "inf-child.h"
4545 #include "common/filestuff.h"
46+#include "common/scoped_fd.h"
4647
4748 #define NULL_PID 0
4849 #define _DEBUG_FLAG_TRACE (_DEBUG_FLAG_TRACE_EXEC|_DEBUG_FLAG_TRACE_RD|\
@@ -113,9 +114,8 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
113114 {
114115 char *endstr;
115116 char buffer[50];
116- int fd, total_size;
117+ int total_size;
117118 procfs_sysinfo *sysinfo;
118- struct cleanup *cleanups;
119119 char nto_procfs_path[PATH_MAX];
120120
121121 /* Offer to kill previous inferiors before opening this target. */
@@ -158,17 +158,16 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
158158 snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s",
159159 (nodestr != NULL) ? nodestr : "", "/proc");
160160
161- fd = open (nto_procfs_path, O_RDONLY);
162- if (fd == -1)
161+ scoped_fd fd (open (nto_procfs_path, O_RDONLY));
162+ if (fd.get () == -1)
163163 {
164164 printf_filtered ("Error opening %s : %d (%s)\n", nto_procfs_path, errno,
165165 safe_strerror (errno));
166166 error (_("Invalid procfs arg"));
167167 }
168- cleanups = make_cleanup_close (fd);
169168
170169 sysinfo = (void *) buffer;
171- if (devctl (fd, DCMD_PROC_SYSINFO, sysinfo, sizeof buffer, 0) != EOK)
170+ if (devctl (fd.get (), DCMD_PROC_SYSINFO, sysinfo, sizeof buffer, 0) != EOK)
172171 {
173172 printf_filtered ("Error getting size: %d (%s)\n", errno,
174173 safe_strerror (errno));
@@ -186,7 +185,8 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
186185 }
187186 else
188187 {
189- if (devctl (fd, DCMD_PROC_SYSINFO, sysinfo, total_size, 0) != EOK)
188+ if (devctl (fd.get (), DCMD_PROC_SYSINFO, sysinfo, total_size, 0)
189+ != EOK)
190190 {
191191 printf_filtered ("Error getting sysinfo: %d (%s)\n", errno,
192192 safe_strerror (errno));
@@ -201,7 +201,6 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty)
201201 }
202202 }
203203 }
204- do_cleanups (cleanups);
205204
206205 inf_child_open_target (ops, arg, from_tty);
207206 printf_filtered ("Debugging using %s\n", nto_procfs_path);
@@ -377,9 +376,6 @@ procfs_pidlist (const char *args, int from_tty)
377376
378377 do
379378 {
380- int fd;
381- struct cleanup *inner_cleanup;
382-
383379 /* Get the right pid and procfs path for the pid. */
384380 do
385381 {
@@ -397,17 +393,16 @@ procfs_pidlist (const char *args, int from_tty)
397393 while (pid == 0);
398394
399395 /* Open the procfs path. */
400- fd = open (buf, O_RDONLY);
401- if (fd == -1)
396+ scoped_fd fd (open (buf, O_RDONLY));
397+ if (fd.get () == -1)
402398 {
403399 fprintf_unfiltered (gdb_stderr, "failed to open %s - %d (%s)\n",
404400 buf, errno, safe_strerror (errno));
405401 continue;
406402 }
407- inner_cleanup = make_cleanup_close (fd);
408403
409404 pidinfo = (procfs_info *) buf;
410- if (devctl (fd, DCMD_PROC_INFO, pidinfo, sizeof (buf), 0) != EOK)
405+ if (devctl (fd.get (), DCMD_PROC_INFO, pidinfo, sizeof (buf), 0) != EOK)
411406 {
412407 fprintf_unfiltered (gdb_stderr,
413408 "devctl DCMD_PROC_INFO failed - %d (%s)\n",
@@ -417,7 +412,8 @@ procfs_pidlist (const char *args, int from_tty)
417412 num_threads = pidinfo->num_threads;
418413
419414 info = (procfs_debuginfo *) buf;
420- if (devctl (fd, DCMD_PROC_MAPDEBUG_BASE, info, sizeof (buf), 0) != EOK)
415+ if (devctl (fd.get (), DCMD_PROC_MAPDEBUG_BASE, info, sizeof (buf), 0)
416+ != EOK)
421417 strcpy (name, "unavailable");
422418 else
423419 strcpy (name, info->path);
@@ -427,7 +423,7 @@ procfs_pidlist (const char *args, int from_tty)
427423 for (status->tid = 1; status->tid <= num_threads; status->tid++)
428424 {
429425 const int err
430- = devctl (fd, DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0);
426+ = devctl (fd.get (), DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0);
431427 printf_filtered ("%s - %d", name, pid);
432428 if (err == EOK && status->tid != 0)
433429 printf_filtered ("/%d\n", status->tid);
@@ -437,8 +433,6 @@ procfs_pidlist (const char *args, int from_tty)
437433 break;
438434 }
439435 }
440-
441- do_cleanups (inner_cleanup);
442436 }
443437 while (dirp != NULL);
444438
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -46,6 +46,7 @@
4646 #include "auxv.h"
4747 #include "procfs.h"
4848 #include "observer.h"
49+#include "common/scoped_fd.h"
4950
5051 /* This module provides the interface between GDB and the
5152 /proc file system, which is used on many versions of Unix
@@ -1593,8 +1594,6 @@ proc_get_LDT_entry (procinfo *pi, int key)
15931594 {
15941595 static struct ssd *ldt_entry = NULL;
15951596 char pathname[MAX_PROC_NAME_SIZE];
1596- struct cleanup *old_chain = NULL;
1597- int fd;
15981597
15991598 /* Allocate space for one LDT entry.
16001599 This alloc must persist, because we return a pointer to it. */
@@ -1603,16 +1602,16 @@ proc_get_LDT_entry (procinfo *pi, int key)
16031602
16041603 /* Open the file descriptor for the LDT table. */
16051604 sprintf (pathname, "/proc/%d/ldt", pi->pid);
1606- if ((fd = open_with_retry (pathname, O_RDONLY)) < 0)
1605+ scoped_fd fd (open_with_retry (pathname, O_RDONLY));
1606+ if (fd.get () < 0)
16071607 {
16081608 proc_warn (pi, "proc_get_LDT_entry (open)", __LINE__);
16091609 return NULL;
16101610 }
1611- /* Make sure it gets closed again! */
1612- old_chain = make_cleanup_close (fd);
16131611
16141612 /* Now 'read' thru the table, find a match and return it. */
1615- while (read (fd, ldt_entry, sizeof (struct ssd)) == sizeof (struct ssd))
1613+ while (read (fd.get (), ldt_entry, sizeof (struct ssd))
1614+ == sizeof (struct ssd))
16161615 {
16171616 if (ldt_entry->sel == 0 &&
16181617 ldt_entry->bo == 0 &&
@@ -1627,7 +1626,6 @@ proc_get_LDT_entry (procinfo *pi, int key)
16271626 }
16281627 }
16291628 /* Loop ended, match not found. */
1630- do_cleanups (old_chain);
16311629 return NULL;
16321630 }
16331631
@@ -3426,40 +3424,33 @@ iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func,
34263424 struct prmap *prmaps;
34273425 struct prmap *prmap;
34283426 int funcstat;
3429- int map_fd;
34303427 int nmap;
3431- struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
34323428 struct stat sbuf;
34333429
34343430 /* Get the number of mappings, allocate space,
34353431 and read the mappings into prmaps. */
34363432 /* Open map fd. */
34373433 sprintf (pathname, "/proc/%d/map", pi->pid);
3438- if ((map_fd = open (pathname, O_RDONLY)) < 0)
3439- proc_error (pi, "iterate_over_mappings (open)", __LINE__);
34403434
3441- /* Make sure it gets closed again. */
3442- make_cleanup_close (map_fd);
3435+ scoped_fd map_fd (open (pathname, O_RDONLY));
3436+ if (map_fd.get () < 0)
3437+ proc_error (pi, "iterate_over_mappings (open)", __LINE__);
34433438
34443439 /* Use stat to determine the file size, and compute
34453440 the number of prmap_t objects it contains. */
3446- if (fstat (map_fd, &sbuf) != 0)
3441+ if (fstat (map_fd.get (), &sbuf) != 0)
34473442 proc_error (pi, "iterate_over_mappings (fstat)", __LINE__);
34483443
34493444 nmap = sbuf.st_size / sizeof (prmap_t);
34503445 prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
3451- if (read (map_fd, (char *) prmaps, nmap * sizeof (*prmaps))
3446+ if (read (map_fd.get (), (char *) prmaps, nmap * sizeof (*prmaps))
34523447 != (nmap * sizeof (*prmaps)))
34533448 proc_error (pi, "iterate_over_mappings (read)", __LINE__);
34543449
34553450 for (prmap = prmaps; nmap > 0; prmap++, nmap--)
34563451 if ((funcstat = (*func) (prmap, child_func, data)) != 0)
3457- {
3458- do_cleanups (cleanups);
3459- return funcstat;
3460- }
3452+ return funcstat;
34613453
3462- do_cleanups (cleanups);
34633454 return 0;
34643455 }
34653456
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -42,6 +42,7 @@
4242 #include "ui-out.h"
4343 #include "readline/readline.h"
4444 #include "common/enum-flags.h"
45+#include "common/scoped_fd.h"
4546 #include <algorithm>
4647 #include "common/pathstuff.h"
4748
@@ -1215,24 +1216,21 @@ find_source_lines (struct symtab *s, int desc)
12151216 static int
12161217 get_filename_and_charpos (struct symtab *s, char **fullname)
12171218 {
1218- int desc, linenums_changed = 0;
1219- struct cleanup *cleanups;
1219+ int linenums_changed = 0;
12201220
1221- desc = open_source_file (s);
1222- if (desc < 0)
1221+ scoped_fd desc (open_source_file (s));
1222+ if (desc.get () < 0)
12231223 {
12241224 if (fullname)
12251225 *fullname = NULL;
12261226 return 0;
12271227 }
1228- cleanups = make_cleanup_close (desc);
12291228 if (fullname)
12301229 *fullname = s->fullname;
12311230 if (s->line_charpos == 0)
12321231 linenums_changed = 1;
12331232 if (linenums_changed)
1234- find_source_lines (s, desc);
1235- do_cleanups (cleanups);
1233+ find_source_lines (s, desc.get ());
12361234 return linenums_changed;
12371235 }
12381236