GNU Binutils with patches for OS216
Revision | 5dc1a7047a77f86de7518a99805af64891d4e22a (tree) |
---|---|
Time | 2018-03-09 14:00:08 |
Author | Tom Tromey <tom@trom...> |
Commiter | Tom Tromey |
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.
@@ -1,5 +1,13 @@ | ||
1 | 1 | 2018-03-08 Tom Tromey <tom@tromey.com> |
2 | 2 | |
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 | + | |
3 | 11 | * infcall.c (struct call_return_meta_info) |
4 | 12 | <stack_temporaries_enabled>: Remove. |
5 | 13 | (get_call_return_value, call_function_by_hand_dummy): Update. |
@@ -43,6 +43,7 @@ | ||
43 | 43 | #include "solib.h" |
44 | 44 | #include "inf-child.h" |
45 | 45 | #include "common/filestuff.h" |
46 | +#include "common/scoped_fd.h" | |
46 | 47 | |
47 | 48 | #define NULL_PID 0 |
48 | 49 | #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) | ||
113 | 114 | { |
114 | 115 | char *endstr; |
115 | 116 | char buffer[50]; |
116 | - int fd, total_size; | |
117 | + int total_size; | |
117 | 118 | procfs_sysinfo *sysinfo; |
118 | - struct cleanup *cleanups; | |
119 | 119 | char nto_procfs_path[PATH_MAX]; |
120 | 120 | |
121 | 121 | /* 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) | ||
158 | 158 | snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s", |
159 | 159 | (nodestr != NULL) ? nodestr : "", "/proc"); |
160 | 160 | |
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) | |
163 | 163 | { |
164 | 164 | printf_filtered ("Error opening %s : %d (%s)\n", nto_procfs_path, errno, |
165 | 165 | safe_strerror (errno)); |
166 | 166 | error (_("Invalid procfs arg")); |
167 | 167 | } |
168 | - cleanups = make_cleanup_close (fd); | |
169 | 168 | |
170 | 169 | 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) | |
172 | 171 | { |
173 | 172 | printf_filtered ("Error getting size: %d (%s)\n", errno, |
174 | 173 | safe_strerror (errno)); |
@@ -186,7 +185,8 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty) | ||
186 | 185 | } |
187 | 186 | else |
188 | 187 | { |
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) | |
190 | 190 | { |
191 | 191 | printf_filtered ("Error getting sysinfo: %d (%s)\n", errno, |
192 | 192 | safe_strerror (errno)); |
@@ -201,7 +201,6 @@ procfs_open_1 (struct target_ops *ops, const char *arg, int from_tty) | ||
201 | 201 | } |
202 | 202 | } |
203 | 203 | } |
204 | - do_cleanups (cleanups); | |
205 | 204 | |
206 | 205 | inf_child_open_target (ops, arg, from_tty); |
207 | 206 | printf_filtered ("Debugging using %s\n", nto_procfs_path); |
@@ -377,9 +376,6 @@ procfs_pidlist (const char *args, int from_tty) | ||
377 | 376 | |
378 | 377 | do |
379 | 378 | { |
380 | - int fd; | |
381 | - struct cleanup *inner_cleanup; | |
382 | - | |
383 | 379 | /* Get the right pid and procfs path for the pid. */ |
384 | 380 | do |
385 | 381 | { |
@@ -397,17 +393,16 @@ procfs_pidlist (const char *args, int from_tty) | ||
397 | 393 | while (pid == 0); |
398 | 394 | |
399 | 395 | /* 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) | |
402 | 398 | { |
403 | 399 | fprintf_unfiltered (gdb_stderr, "failed to open %s - %d (%s)\n", |
404 | 400 | buf, errno, safe_strerror (errno)); |
405 | 401 | continue; |
406 | 402 | } |
407 | - inner_cleanup = make_cleanup_close (fd); | |
408 | 403 | |
409 | 404 | 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) | |
411 | 406 | { |
412 | 407 | fprintf_unfiltered (gdb_stderr, |
413 | 408 | "devctl DCMD_PROC_INFO failed - %d (%s)\n", |
@@ -417,7 +412,8 @@ procfs_pidlist (const char *args, int from_tty) | ||
417 | 412 | num_threads = pidinfo->num_threads; |
418 | 413 | |
419 | 414 | 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) | |
421 | 417 | strcpy (name, "unavailable"); |
422 | 418 | else |
423 | 419 | strcpy (name, info->path); |
@@ -427,7 +423,7 @@ procfs_pidlist (const char *args, int from_tty) | ||
427 | 423 | for (status->tid = 1; status->tid <= num_threads; status->tid++) |
428 | 424 | { |
429 | 425 | const int err |
430 | - = devctl (fd, DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0); | |
426 | + = devctl (fd.get (), DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0); | |
431 | 427 | printf_filtered ("%s - %d", name, pid); |
432 | 428 | if (err == EOK && status->tid != 0) |
433 | 429 | printf_filtered ("/%d\n", status->tid); |
@@ -437,8 +433,6 @@ procfs_pidlist (const char *args, int from_tty) | ||
437 | 433 | break; |
438 | 434 | } |
439 | 435 | } |
440 | - | |
441 | - do_cleanups (inner_cleanup); | |
442 | 436 | } |
443 | 437 | while (dirp != NULL); |
444 | 438 |
@@ -46,6 +46,7 @@ | ||
46 | 46 | #include "auxv.h" |
47 | 47 | #include "procfs.h" |
48 | 48 | #include "observer.h" |
49 | +#include "common/scoped_fd.h" | |
49 | 50 | |
50 | 51 | /* This module provides the interface between GDB and the |
51 | 52 | /proc file system, which is used on many versions of Unix |
@@ -1593,8 +1594,6 @@ proc_get_LDT_entry (procinfo *pi, int key) | ||
1593 | 1594 | { |
1594 | 1595 | static struct ssd *ldt_entry = NULL; |
1595 | 1596 | char pathname[MAX_PROC_NAME_SIZE]; |
1596 | - struct cleanup *old_chain = NULL; | |
1597 | - int fd; | |
1598 | 1597 | |
1599 | 1598 | /* Allocate space for one LDT entry. |
1600 | 1599 | This alloc must persist, because we return a pointer to it. */ |
@@ -1603,16 +1602,16 @@ proc_get_LDT_entry (procinfo *pi, int key) | ||
1603 | 1602 | |
1604 | 1603 | /* Open the file descriptor for the LDT table. */ |
1605 | 1604 | 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) | |
1607 | 1607 | { |
1608 | 1608 | proc_warn (pi, "proc_get_LDT_entry (open)", __LINE__); |
1609 | 1609 | return NULL; |
1610 | 1610 | } |
1611 | - /* Make sure it gets closed again! */ | |
1612 | - old_chain = make_cleanup_close (fd); | |
1613 | 1611 | |
1614 | 1612 | /* 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)) | |
1616 | 1615 | { |
1617 | 1616 | if (ldt_entry->sel == 0 && |
1618 | 1617 | ldt_entry->bo == 0 && |
@@ -1627,7 +1626,6 @@ proc_get_LDT_entry (procinfo *pi, int key) | ||
1627 | 1626 | } |
1628 | 1627 | } |
1629 | 1628 | /* Loop ended, match not found. */ |
1630 | - do_cleanups (old_chain); | |
1631 | 1629 | return NULL; |
1632 | 1630 | } |
1633 | 1631 |
@@ -3426,40 +3424,33 @@ iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func, | ||
3426 | 3424 | struct prmap *prmaps; |
3427 | 3425 | struct prmap *prmap; |
3428 | 3426 | int funcstat; |
3429 | - int map_fd; | |
3430 | 3427 | int nmap; |
3431 | - struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); | |
3432 | 3428 | struct stat sbuf; |
3433 | 3429 | |
3434 | 3430 | /* Get the number of mappings, allocate space, |
3435 | 3431 | and read the mappings into prmaps. */ |
3436 | 3432 | /* Open map fd. */ |
3437 | 3433 | 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__); | |
3440 | 3434 | |
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__); | |
3443 | 3438 | |
3444 | 3439 | /* Use stat to determine the file size, and compute |
3445 | 3440 | the number of prmap_t objects it contains. */ |
3446 | - if (fstat (map_fd, &sbuf) != 0) | |
3441 | + if (fstat (map_fd.get (), &sbuf) != 0) | |
3447 | 3442 | proc_error (pi, "iterate_over_mappings (fstat)", __LINE__); |
3448 | 3443 | |
3449 | 3444 | nmap = sbuf.st_size / sizeof (prmap_t); |
3450 | 3445 | 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)) | |
3452 | 3447 | != (nmap * sizeof (*prmaps))) |
3453 | 3448 | proc_error (pi, "iterate_over_mappings (read)", __LINE__); |
3454 | 3449 | |
3455 | 3450 | for (prmap = prmaps; nmap > 0; prmap++, nmap--) |
3456 | 3451 | if ((funcstat = (*func) (prmap, child_func, data)) != 0) |
3457 | - { | |
3458 | - do_cleanups (cleanups); | |
3459 | - return funcstat; | |
3460 | - } | |
3452 | + return funcstat; | |
3461 | 3453 | |
3462 | - do_cleanups (cleanups); | |
3463 | 3454 | return 0; |
3464 | 3455 | } |
3465 | 3456 |
@@ -42,6 +42,7 @@ | ||
42 | 42 | #include "ui-out.h" |
43 | 43 | #include "readline/readline.h" |
44 | 44 | #include "common/enum-flags.h" |
45 | +#include "common/scoped_fd.h" | |
45 | 46 | #include <algorithm> |
46 | 47 | #include "common/pathstuff.h" |
47 | 48 |
@@ -1215,24 +1216,21 @@ find_source_lines (struct symtab *s, int desc) | ||
1215 | 1216 | static int |
1216 | 1217 | get_filename_and_charpos (struct symtab *s, char **fullname) |
1217 | 1218 | { |
1218 | - int desc, linenums_changed = 0; | |
1219 | - struct cleanup *cleanups; | |
1219 | + int linenums_changed = 0; | |
1220 | 1220 | |
1221 | - desc = open_source_file (s); | |
1222 | - if (desc < 0) | |
1221 | + scoped_fd desc (open_source_file (s)); | |
1222 | + if (desc.get () < 0) | |
1223 | 1223 | { |
1224 | 1224 | if (fullname) |
1225 | 1225 | *fullname = NULL; |
1226 | 1226 | return 0; |
1227 | 1227 | } |
1228 | - cleanups = make_cleanup_close (desc); | |
1229 | 1228 | if (fullname) |
1230 | 1229 | *fullname = s->fullname; |
1231 | 1230 | if (s->line_charpos == 0) |
1232 | 1231 | linenums_changed = 1; |
1233 | 1232 | if (linenums_changed) |
1234 | - find_source_lines (s, desc); | |
1235 | - do_cleanups (cleanups); | |
1233 | + find_source_lines (s, desc.get ()); | |
1236 | 1234 | return linenums_changed; |
1237 | 1235 | } |
1238 | 1236 |