1 /* Auxiliary vector support for GDB, the GNU debugger.
3 Copyright (C) 2004, 2005, 2006, 2007, 2008 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 3 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, see <http://www.gnu.org/licenses/>. */
26 #include "gdb_assert.h"
29 #include "elf/common.h"
35 /* This function is called like a to_xfer_partial hook,
36 but must be called with TARGET_OBJECT_AUXV.
37 It handles access via /proc/PID/auxv, which is the common method.
38 This function is appropriate for doing:
39 #define NATIVE_XFER_AUXV procfs_xfer_auxv
40 for a native target that uses inftarg.c's child_xfer_partial hook. */
43 procfs_xfer_auxv (struct target_ops *ops,
44 int /* enum target_object */ object,
47 const gdb_byte *writebuf,
55 gdb_assert (object == TARGET_OBJECT_AUXV);
56 gdb_assert (readbuf || writebuf);
58 pathname = xstrprintf ("/proc/%d/auxv", PIDGET (inferior_ptid));
59 fd = open (pathname, writebuf != NULL ? O_WRONLY : O_RDONLY);
64 if (offset != (ULONGEST) 0
65 && lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset)
67 else if (readbuf != NULL)
68 n = read (fd, readbuf, len);
70 n = write (fd, writebuf, len);
77 /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
78 Return 0 if *READPTR is already at the end of the buffer.
79 Return -1 if there is insufficient buffer for a whole entry.
80 Return 1 if an entry was read into *TYPEP and *VALP. */
82 target_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
83 gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
85 const int sizeof_auxv_field = TYPE_LENGTH (builtin_type_void_data_ptr);
86 gdb_byte *ptr = *readptr;
91 if (endptr - ptr < sizeof_auxv_field * 2)
94 *typep = extract_unsigned_integer (ptr, sizeof_auxv_field);
95 ptr += sizeof_auxv_field;
96 *valp = extract_unsigned_integer (ptr, sizeof_auxv_field);
97 ptr += sizeof_auxv_field;
103 /* Extract the auxiliary vector entry with a_type matching MATCH.
104 Return zero if no such entry was found, or -1 if there was
105 an error getting the information. On success, return 1 after
106 storing the entry's value field in *VALP. */
108 target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
112 LONGEST n = target_read_alloc (ops, TARGET_OBJECT_AUXV, NULL, &data);
113 gdb_byte *ptr = data;
120 switch (target_auxv_parse (ops, &ptr, data + n, &type, &val))
122 case 1: /* Here's an entry, check it. */
130 case 0: /* End of the vector. */
133 default: /* Bogosity. */
142 /* Print the contents of the target's AUXV on the specified file. */
144 fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
148 LONGEST len = target_read_alloc (ops, TARGET_OBJECT_AUXV, NULL,
150 gdb_byte *ptr = data;
156 while (target_auxv_parse (ops, &ptr, data + len, &type, &val) > 0)
158 extern int addressprint;
159 const char *name = "???";
160 const char *description = "";
161 enum { dec, hex, str } flavor = hex;
165 #define TAG(tag, text, kind) \
166 case tag: name = #tag; description = text; flavor = kind; break
167 TAG (AT_NULL, _("End of vector"), hex);
168 TAG (AT_IGNORE, _("Entry should be ignored"), hex);
169 TAG (AT_EXECFD, _("File descriptor of program"), dec);
170 TAG (AT_PHDR, _("Program headers for program"), hex);
171 TAG (AT_PHENT, _("Size of program header entry"), dec);
172 TAG (AT_PHNUM, _("Number of program headers"), dec);
173 TAG (AT_PAGESZ, _("System page size"), dec);
174 TAG (AT_BASE, _("Base address of interpreter"), hex);
175 TAG (AT_FLAGS, _("Flags"), hex);
176 TAG (AT_ENTRY, _("Entry point of program"), hex);
177 TAG (AT_NOTELF, _("Program is not ELF"), dec);
178 TAG (AT_UID, _("Real user ID"), dec);
179 TAG (AT_EUID, _("Effective user ID"), dec);
180 TAG (AT_GID, _("Real group ID"), dec);
181 TAG (AT_EGID, _("Effective group ID"), dec);
182 TAG (AT_CLKTCK, _("Frequency of times()"), dec);
183 TAG (AT_PLATFORM, _("String identifying platform"), str);
184 TAG (AT_HWCAP, _("Machine-dependent CPU capability hints"), hex);
185 TAG (AT_FPUCW, _("Used FPU control word"), dec);
186 TAG (AT_DCACHEBSIZE, _("Data cache block size"), dec);
187 TAG (AT_ICACHEBSIZE, _("Instruction cache block size"), dec);
188 TAG (AT_UCACHEBSIZE, _("Unified cache block size"), dec);
189 TAG (AT_IGNOREPPC, _("Entry should be ignored"), dec);
190 TAG (AT_SYSINFO, _("Special system info/entry points"), hex);
191 TAG (AT_SYSINFO_EHDR, _("System-supplied DSO's ELF header"), hex);
192 TAG (AT_SECURE, _("Boolean, was exec setuid-like?"), dec);
193 TAG (AT_SUN_UID, _("Effective user ID"), dec);
194 TAG (AT_SUN_RUID, _("Real user ID"), dec);
195 TAG (AT_SUN_GID, _("Effective group ID"), dec);
196 TAG (AT_SUN_RGID, _("Real group ID"), dec);
197 TAG (AT_SUN_LDELF, _("Dynamic linker's ELF header"), hex);
198 TAG (AT_SUN_LDSHDR, _("Dynamic linker's section headers"), hex);
199 TAG (AT_SUN_LDNAME, _("String giving name of dynamic linker"), str);
200 TAG (AT_SUN_LPAGESZ, _("Large pagesize"), dec);
201 TAG (AT_SUN_PLATFORM, _("Platform name string"), str);
202 TAG (AT_SUN_HWCAP, _("Machine-dependent CPU capability hints"), hex);
203 TAG (AT_SUN_IFLUSH, _("Should flush icache?"), dec);
204 TAG (AT_SUN_CPU, _("CPU name string"), str);
205 TAG (AT_SUN_EMUL_ENTRY, _("COFF entry point address"), hex);
206 TAG (AT_SUN_EMUL_EXECFD, _("COFF executable file descriptor"), dec);
207 TAG (AT_SUN_EXECNAME,
208 _("Canonicalized file name given to execve"), str);
209 TAG (AT_SUN_MMU, _("String for name of MMU module"), str);
210 TAG (AT_SUN_LDDATA, _("Dynamic linker's data segment address"), hex);
213 fprintf_filtered (file, "%-4s %-20s %-30s ",
214 paddr_d (type), name, description);
218 fprintf_filtered (file, "%s\n", paddr_d (val));
221 fprintf_filtered (file, "0x%s\n", paddr_nz (val));
225 fprintf_filtered (file, "0x%s", paddr_nz (val));
226 val_print_string (val, -1, 1, file);
227 fprintf_filtered (file, "\n");
239 info_auxv_command (char *cmd, int from_tty)
241 if (! target_has_stack)
242 error (_("The program has no auxiliary information now."));
245 int ents = fprint_target_auxv (gdb_stdout, ¤t_target);
247 error (_("No auxiliary vector found, or failed reading it."));
249 error (_("Auxiliary vector is empty."));
254 extern initialize_file_ftype _initialize_auxv; /* -Wmissing-prototypes; */
257 _initialize_auxv (void)
259 add_info ("auxv", info_auxv_command,
260 _("Display the inferior's auxiliary vector.\n\
261 This is information provided by the operating system at program startup."));