1 /* Auxiliary vector support for GDB, the GNU debugger.
3 Copyright (C) 2004 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
28 #include "gdb_assert.h"
31 #include "elf/common.h"
37 /* This function is called like a to_xfer_partial hook,
38 but must be called with TARGET_OBJECT_AUXV.
39 It handles access via /proc/PID/auxv, which is the common method.
40 This function is appropriate for doing:
41 #define NATIVE_XFER_AUXV procfs_xfer_auxv
42 for a native target that uses inftarg.c's child_xfer_partial hook. */
45 procfs_xfer_auxv (struct target_ops *ops,
46 int /* enum target_object */ object,
49 const gdb_byte *writebuf,
57 gdb_assert (object == TARGET_OBJECT_AUXV);
58 gdb_assert (readbuf || writebuf);
60 pathname = xstrprintf ("/proc/%d/auxv", PIDGET (inferior_ptid));
61 fd = open (pathname, writebuf != NULL ? O_WRONLY : O_RDONLY);
66 if (offset != (ULONGEST) 0
67 && lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset)
69 else if (readbuf != NULL)
70 n = read (fd, readbuf, len);
72 n = write (fd, writebuf, len);
79 /* Read all the auxv data into a contiguous xmalloc'd buffer,
80 stored in *DATA. Return the size in bytes of this data.
81 If zero, there is no data and *DATA is null.
82 if < 0, there was an error and *DATA is null. */
84 target_auxv_read (struct target_ops *ops, gdb_byte **data)
86 size_t auxv_alloc = 512, auxv_pos = 0;
87 gdb_byte *auxv = xmalloc (auxv_alloc);
92 n = target_read_partial (ops, TARGET_OBJECT_AUXV,
93 NULL, &auxv[auxv_pos], 0,
94 auxv_alloc - auxv_pos);
98 if (auxv_pos < auxv_alloc) /* Read all there was. */
100 gdb_assert (auxv_pos == auxv_alloc);
102 auxv = xrealloc (auxv, auxv_alloc);
116 /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
117 Return 0 if *READPTR is already at the end of the buffer.
118 Return -1 if there is insufficient buffer for a whole entry.
119 Return 1 if an entry was read into *TYPEP and *VALP. */
121 target_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
122 gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
124 const int sizeof_auxv_field = TYPE_LENGTH (builtin_type_void_data_ptr);
125 gdb_byte *ptr = *readptr;
130 if (endptr - ptr < sizeof_auxv_field * 2)
133 *typep = extract_unsigned_integer (ptr, sizeof_auxv_field);
134 ptr += sizeof_auxv_field;
135 *valp = extract_unsigned_integer (ptr, sizeof_auxv_field);
136 ptr += sizeof_auxv_field;
142 /* Extract the auxiliary vector entry with a_type matching MATCH.
143 Return zero if no such entry was found, or -1 if there was
144 an error getting the information. On success, return 1 after
145 storing the entry's value field in *VALP. */
147 target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
151 int n = target_auxv_read (ops, &data);
152 gdb_byte *ptr = data;
159 switch (target_auxv_parse (ops, &ptr, data + n, &type, &val))
161 case 1: /* Here's an entry, check it. */
169 case 0: /* End of the vector. */
172 default: /* Bogosity. */
181 /* Print the contents of the target's AUXV on the specified file. */
183 fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
187 int len = target_auxv_read (ops, &data);
188 gdb_byte *ptr = data;
194 while (target_auxv_parse (ops, &ptr, data + len, &type, &val) > 0)
196 extern int addressprint;
197 const char *name = "???";
198 const char *description = "";
199 enum { dec, hex, str } flavor = hex;
203 #define TAG(tag, text, kind) \
204 case tag: name = #tag; description = text; flavor = kind; break
205 TAG (AT_NULL, _("End of vector"), hex);
206 TAG (AT_IGNORE, _("Entry should be ignored"), hex);
207 TAG (AT_EXECFD, _("File descriptor of program"), dec);
208 TAG (AT_PHDR, _("Program headers for program"), hex);
209 TAG (AT_PHENT, _("Size of program header entry"), dec);
210 TAG (AT_PHNUM, _("Number of program headers"), dec);
211 TAG (AT_PAGESZ, _("System page size"), dec);
212 TAG (AT_BASE, _("Base address of interpreter"), hex);
213 TAG (AT_FLAGS, _("Flags"), hex);
214 TAG (AT_ENTRY, _("Entry point of program"), hex);
215 TAG (AT_NOTELF, _("Program is not ELF"), dec);
216 TAG (AT_UID, _("Real user ID"), dec);
217 TAG (AT_EUID, _("Effective user ID"), dec);
218 TAG (AT_GID, _("Real group ID"), dec);
219 TAG (AT_EGID, _("Effective group ID"), dec);
220 TAG (AT_CLKTCK, _("Frequency of times()"), dec);
221 TAG (AT_PLATFORM, _("String identifying platform"), str);
222 TAG (AT_HWCAP, _("Machine-dependent CPU capability hints"), hex);
223 TAG (AT_FPUCW, _("Used FPU control word"), dec);
224 TAG (AT_DCACHEBSIZE, _("Data cache block size"), dec);
225 TAG (AT_ICACHEBSIZE, _("Instruction cache block size"), dec);
226 TAG (AT_UCACHEBSIZE, _("Unified cache block size"), dec);
227 TAG (AT_IGNOREPPC, _("Entry should be ignored"), dec);
228 TAG (AT_SYSINFO, _("Special system info/entry points"), hex);
229 TAG (AT_SYSINFO_EHDR, _("System-supplied DSO's ELF header"), hex);
230 TAG (AT_SECURE, _("Boolean, was exec setuid-like?"), dec);
231 TAG (AT_SUN_UID, _("Effective user ID"), dec);
232 TAG (AT_SUN_RUID, _("Real user ID"), dec);
233 TAG (AT_SUN_GID, _("Effective group ID"), dec);
234 TAG (AT_SUN_RGID, _("Real group ID"), dec);
235 TAG (AT_SUN_LDELF, _("Dynamic linker's ELF header"), hex);
236 TAG (AT_SUN_LDSHDR, _("Dynamic linker's section headers"), hex);
237 TAG (AT_SUN_LDNAME, _("String giving name of dynamic linker"), str);
238 TAG (AT_SUN_LPAGESZ, _("Large pagesize"), dec);
239 TAG (AT_SUN_PLATFORM, _("Platform name string"), str);
240 TAG (AT_SUN_HWCAP, _("Machine-dependent CPU capability hints"), hex);
241 TAG (AT_SUN_IFLUSH, _("Should flush icache?"), dec);
242 TAG (AT_SUN_CPU, _("CPU name string"), str);
243 TAG (AT_SUN_EMUL_ENTRY, _("COFF entry point address"), hex);
244 TAG (AT_SUN_EMUL_EXECFD, _("COFF executable file descriptor"), dec);
245 TAG (AT_SUN_EXECNAME,
246 _("Canonicalized file name given to execve"), str);
247 TAG (AT_SUN_MMU, _("String for name of MMU module"), str);
248 TAG (AT_SUN_LDDATA, _("Dynamic linker's data segment address"), hex);
251 fprintf_filtered (file, "%-4s %-20s %-30s ",
252 paddr_d (type), name, description);
256 fprintf_filtered (file, "%s\n", paddr_d (val));
259 fprintf_filtered (file, "0x%s\n", paddr_nz (val));
263 fprintf_filtered (file, "0x%s", paddr_nz (val));
264 val_print_string (val, -1, 1, file);
265 fprintf_filtered (file, "\n");
277 info_auxv_command (char *cmd, int from_tty)
279 if (! target_has_stack)
280 error (_("The program has no auxiliary information now."));
283 int ents = fprint_target_auxv (gdb_stdout, ¤t_target);
285 error (_("No auxiliary vector found, or failed reading it."));
287 error (_("Auxiliary vector is empty."));
292 extern initialize_file_ftype _initialize_auxv; /* -Wmissing-prototypes; */
295 _initialize_auxv (void)
297 add_info ("auxv", info_auxv_command,
298 _("Display the inferior's auxiliary vector.\n\
299 This is information provided by the operating system at program startup."));