1 /* Auxiliary vector support for GDB, the GNU debugger.
3 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "gdb_assert.h"
30 #include "elf/common.h"
36 /* This function is called like a to_xfer_partial hook, but must be
37 called with TARGET_OBJECT_AUXV. It handles access via
38 /proc/PID/auxv, which is a common method for native targets. */
41 procfs_xfer_auxv (struct target_ops *ops,
42 enum target_object object,
45 const gdb_byte *writebuf,
53 gdb_assert (object == TARGET_OBJECT_AUXV);
54 gdb_assert (readbuf || writebuf);
56 pathname = xstrprintf ("/proc/%d/auxv", PIDGET (inferior_ptid));
57 fd = open (pathname, writebuf != NULL ? O_WRONLY : O_RDONLY);
62 if (offset != (ULONGEST) 0
63 && lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset)
65 else if (readbuf != NULL)
66 n = read (fd, readbuf, len);
68 n = write (fd, writebuf, len);
75 /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
76 Return 0 if *READPTR is already at the end of the buffer.
77 Return -1 if there is insufficient buffer for a whole entry.
78 Return 1 if an entry was read into *TYPEP and *VALP. */
80 default_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
81 gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
83 const int sizeof_auxv_field = gdbarch_ptr_bit (target_gdbarch)
85 gdb_byte *ptr = *readptr;
90 if (endptr - ptr < sizeof_auxv_field * 2)
93 *typep = extract_unsigned_integer (ptr, sizeof_auxv_field);
94 ptr += sizeof_auxv_field;
95 *valp = extract_unsigned_integer (ptr, sizeof_auxv_field);
96 ptr += sizeof_auxv_field;
102 /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
103 Return 0 if *READPTR is already at the end of the buffer.
104 Return -1 if there is insufficient buffer for a whole entry.
105 Return 1 if an entry was read into *TYPEP and *VALP. */
107 target_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
108 gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
110 struct target_ops *t;
111 for (t = ops; t != NULL; t = t->beneath)
112 if (t->to_auxv_parse != NULL)
113 return t->to_auxv_parse (t, readptr, endptr, typep, valp);
115 return default_auxv_parse (ops, readptr, endptr, typep, valp);
118 /* Extract the auxiliary vector entry with a_type matching MATCH.
119 Return zero if no such entry was found, or -1 if there was
120 an error getting the information. On success, return 1 after
121 storing the entry's value field in *VALP. */
123 target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
127 LONGEST n = target_read_alloc (ops, TARGET_OBJECT_AUXV, NULL, &data);
128 gdb_byte *ptr = data;
135 switch (target_auxv_parse (ops, &ptr, data + n, &type, &val))
137 case 1: /* Here's an entry, check it. */
145 case 0: /* End of the vector. */
148 default: /* Bogosity. */
157 /* Print the contents of the target's AUXV on the specified file. */
159 fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
163 LONGEST len = target_read_alloc (ops, TARGET_OBJECT_AUXV, NULL,
165 gdb_byte *ptr = data;
171 while (target_auxv_parse (ops, &ptr, data + len, &type, &val) > 0)
173 const char *name = "???";
174 const char *description = "";
175 enum { dec, hex, str } flavor = hex;
179 #define TAG(tag, text, kind) \
180 case tag: name = #tag; description = text; flavor = kind; break
181 TAG (AT_NULL, _("End of vector"), hex);
182 TAG (AT_IGNORE, _("Entry should be ignored"), hex);
183 TAG (AT_EXECFD, _("File descriptor of program"), dec);
184 TAG (AT_PHDR, _("Program headers for program"), hex);
185 TAG (AT_PHENT, _("Size of program header entry"), dec);
186 TAG (AT_PHNUM, _("Number of program headers"), dec);
187 TAG (AT_PAGESZ, _("System page size"), dec);
188 TAG (AT_BASE, _("Base address of interpreter"), hex);
189 TAG (AT_FLAGS, _("Flags"), hex);
190 TAG (AT_ENTRY, _("Entry point of program"), hex);
191 TAG (AT_NOTELF, _("Program is not ELF"), dec);
192 TAG (AT_UID, _("Real user ID"), dec);
193 TAG (AT_EUID, _("Effective user ID"), dec);
194 TAG (AT_GID, _("Real group ID"), dec);
195 TAG (AT_EGID, _("Effective group ID"), dec);
196 TAG (AT_CLKTCK, _("Frequency of times()"), dec);
197 TAG (AT_PLATFORM, _("String identifying platform"), str);
198 TAG (AT_HWCAP, _("Machine-dependent CPU capability hints"), hex);
199 TAG (AT_FPUCW, _("Used FPU control word"), dec);
200 TAG (AT_DCACHEBSIZE, _("Data cache block size"), dec);
201 TAG (AT_ICACHEBSIZE, _("Instruction cache block size"), dec);
202 TAG (AT_UCACHEBSIZE, _("Unified cache block size"), dec);
203 TAG (AT_IGNOREPPC, _("Entry should be ignored"), dec);
204 TAG (AT_BASE_PLATFORM, _("String identifying base platform"), str);
205 TAG (AT_RANDOM, _("Address of 16 random bytes"), hex);
206 TAG (AT_EXECFN, _("File name of executable"), str);
207 TAG (AT_SECURE, _("Boolean, was exec setuid-like?"), dec);
208 TAG (AT_SYSINFO, _("Special system info/entry points"), hex);
209 TAG (AT_SYSINFO_EHDR, _("System-supplied DSO's ELF header"), hex);
210 TAG (AT_SUN_UID, _("Effective user ID"), dec);
211 TAG (AT_SUN_RUID, _("Real user ID"), dec);
212 TAG (AT_SUN_GID, _("Effective group ID"), dec);
213 TAG (AT_SUN_RGID, _("Real group ID"), dec);
214 TAG (AT_SUN_LDELF, _("Dynamic linker's ELF header"), hex);
215 TAG (AT_SUN_LDSHDR, _("Dynamic linker's section headers"), hex);
216 TAG (AT_SUN_LDNAME, _("String giving name of dynamic linker"), str);
217 TAG (AT_SUN_LPAGESZ, _("Large pagesize"), dec);
218 TAG (AT_SUN_PLATFORM, _("Platform name string"), str);
219 TAG (AT_SUN_HWCAP, _("Machine-dependent CPU capability hints"), hex);
220 TAG (AT_SUN_IFLUSH, _("Should flush icache?"), dec);
221 TAG (AT_SUN_CPU, _("CPU name string"), str);
222 TAG (AT_SUN_EMUL_ENTRY, _("COFF entry point address"), hex);
223 TAG (AT_SUN_EMUL_EXECFD, _("COFF executable file descriptor"), dec);
224 TAG (AT_SUN_EXECNAME,
225 _("Canonicalized file name given to execve"), str);
226 TAG (AT_SUN_MMU, _("String for name of MMU module"), str);
227 TAG (AT_SUN_LDDATA, _("Dynamic linker's data segment address"), hex);
228 TAG (AT_SUN_AUXFLAGS,
229 _("AF_SUN_ flags passed from the kernel"), hex);
232 fprintf_filtered (file, "%-4s %-20s %-30s ",
233 plongest (type), name, description);
237 fprintf_filtered (file, "%s\n", plongest (val));
240 fprintf_filtered (file, "0x%s\n", paddr_nz (val));
244 struct value_print_options opts;
245 get_user_print_options (&opts);
246 if (opts.addressprint)
247 fprintf_filtered (file, "0x%s", paddr_nz (val));
248 val_print_string (builtin_type (target_gdbarch)->builtin_char,
249 val, -1, file, &opts);
250 fprintf_filtered (file, "\n");
265 info_auxv_command (char *cmd, int from_tty)
267 if (! target_has_stack)
268 error (_("The program has no auxiliary information now."));
271 int ents = fprint_target_auxv (gdb_stdout, ¤t_target);
273 error (_("No auxiliary vector found, or failed reading it."));
275 error (_("Auxiliary vector is empty."));
280 extern initialize_file_ftype _initialize_auxv; /* -Wmissing-prototypes; */
283 _initialize_auxv (void)
285 add_info ("auxv", info_auxv_command,
286 _("Display the inferior's auxiliary vector.\n\
287 This is information provided by the operating system at program startup."));