static int fbsd_find_memory_regions (struct target_ops *self, find_memory_region_ftype func, void *obfd) { pid_t pid = ptid_get_pid (inferior_ptid); char *mapfilename; FILE *mapfile; unsigned long start, end, size; char protection[4]; int read, write, exec; struct cleanup *cleanup; mapfilename = xstrprintf ("/proc/%ld/map", (long) pid); cleanup = make_cleanup (xfree, mapfilename); mapfile = fopen (mapfilename, "r"); if (mapfile == NULL) error (_("Couldn't open %s."), mapfilename); make_cleanup_fclose (mapfile); if (info_verbose) fprintf_filtered (gdb_stdout, "Reading memory regions from %s\n", mapfilename); /* Now iterate until end-of-file. */ while (fbsd_read_mapping (mapfile, &start, &end, &protection[0])) { size = end - start; read = (strchr (protection, 'r') != 0); write = (strchr (protection, 'w') != 0); exec = (strchr (protection, 'x') != 0); if (info_verbose) { fprintf_filtered (gdb_stdout, "Save segment, %ld bytes at %s (%c%c%c)\n", size, paddress (target_gdbarch (), start), read ? 'r' : '-', write ? 'w' : '-', exec ? 'x' : '-'); } /* Invoke the callback function to create the corefile segment. Pass MODIFIED as true, we do not know the real modification state. */ func (start, size, read, write, exec, 1, obfd); } do_cleanups (cleanup); return 0; }
int fbsd_nat_target::find_memory_regions (find_memory_region_ftype func, void *obfd) { pid_t pid = inferior_ptid.pid (); unsigned long start, end, size; char protection[4]; int read, write, exec; std::string mapfilename = string_printf ("/proc/%ld/map", (long) pid); gdb_file_up mapfile (fopen (mapfilename.c_str (), "r")); if (mapfile == NULL) error (_("Couldn't open %s."), mapfilename.c_str ()); if (info_verbose) fprintf_filtered (gdb_stdout, "Reading memory regions from %s\n", mapfilename.c_str ()); /* Now iterate until end-of-file. */ while (fbsd_read_mapping (mapfile.get (), &start, &end, &protection[0])) { size = end - start; read = (strchr (protection, 'r') != 0); write = (strchr (protection, 'w') != 0); exec = (strchr (protection, 'x') != 0); if (info_verbose) { fprintf_filtered (gdb_stdout, "Save segment, %ld bytes at %s (%c%c%c)\n", size, paddress (target_gdbarch (), start), read ? 'r' : '-', write ? 'w' : '-', exec ? 'x' : '-'); } /* Invoke the callback function to create the corefile segment. Pass MODIFIED as true, we do not know the real modification state. */ func (start, size, read, write, exec, 1, obfd); } return 0; }