1 /* FreeBSD-specific methods for using the /proc file system.
3 Copyright 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
27 #include <sys/procfs.h>
28 #include <sys/types.h>
35 child_pid_to_exec_file (int pid
)
40 xasprintf (&path
, "/proc/%d/file", pid
);
41 buf
= xcalloc (MAXPATHLEN
, sizeof (char));
42 make_cleanup (xfree
, path
);
43 make_cleanup (xfree
, buf
);
45 if (readlink (path
, buf
, MAXPATHLEN
) > 0)
52 read_mapping (FILE *mapfile
, unsigned long *start
, unsigned long *end
,
55 int resident
, privateresident
;
57 int ref_count
, shadow_count
;
59 char cow
[5], access
[4];
63 /* The layout is described in /usr/src/miscfs/procfs/procfs_map.c. */
64 ret
= fscanf (mapfile
, "%lx %lx %d %d %lx %s %d %d %x %s %s %s\n",
66 &resident
, &privateresident
, &obj
,
68 &ref_count
, &shadow_count
, &flags
, cow
, access
, type
);
70 return (ret
!= 0 && ret
!= EOF
);
74 fbsd_find_memory_regions (int (*func
) (CORE_ADDR
, unsigned long,
75 int, int, int, void *),
78 pid_t pid
= ptid_get_pid (inferior_ptid
);
81 unsigned long start
, end
, size
;
83 int read
, write
, exec
;
85 xasprintf (&mapfilename
, "/proc/%ld/map", (long) pid
);
86 mapfile
= fopen (mapfilename
, "r");
88 error ("Couldn't open %s\n", mapfilename
);
91 fprintf_filtered (gdb_stdout
,
92 "Reading memory regions from %s\n", mapfilename
);
94 /* Now iterate until end-of-file. */
95 while (read_mapping (mapfile
, &start
, &end
, &protection
[0]))
99 read
= (strchr (protection
, 'r') != 0);
100 write
= (strchr (protection
, 'w') != 0);
101 exec
= (strchr (protection
, 'x') != 0);
105 fprintf_filtered (gdb_stdout
,
106 "Save segment, %ld bytes at 0x%s (%c%c%c)\n",
107 size
, paddr_nz (start
),
113 /* Invoke the callback function to create the corefile segment. */
114 func (start
, size
, read
, write
, exec
, obfd
);
122 fbsd_make_corefile_notes (bfd
*obfd
, int *note_size
)
126 char *note_data
= NULL
;
127 Elf_Internal_Ehdr
*i_ehdrp
;
129 /* Put a "FreeBSD" label in the ELF header. */
130 i_ehdrp
= elf_elfheader (obfd
);
131 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_FREEBSD
;
133 fill_gregset (&gregs
, -1);
134 note_data
= elfcore_write_prstatus (obfd
, note_data
, note_size
,
135 ptid_get_pid (inferior_ptid
),
136 stop_signal
, &gregs
);
138 fill_fpregset (&fpregs
, -1);
139 note_data
= elfcore_write_prfpreg (obfd
, note_data
, note_size
,
140 &fpregs
, sizeof (fpregs
));
142 if (get_exec_file (0))
144 char *fname
= strrchr (get_exec_file (0), '/') + 1;
145 char *psargs
= xstrdup (fname
);
147 if (get_inferior_args ())
148 psargs
= reconcat (psargs
, psargs
, " ", get_inferior_args (), NULL
);
150 note_data
= elfcore_write_prpsinfo (obfd
, note_data
, note_size
,
154 make_cleanup (xfree
, note_data
);
160 _initialize_fbsd_proc (void)
162 extern void inftarg_set_find_memory_regions ();
163 extern void inftarg_set_make_corefile_notes ();
165 inftarg_set_find_memory_regions (fbsd_find_memory_regions
);
166 inftarg_set_make_corefile_notes (fbsd_make_corefile_notes
);
This page took 0.032621 seconds and 4 git commands to generate.