1 /* Auxiliary vector support for GDB, the GNU debugger.
3 Copyright 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, 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
,
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
, char **data
)
86 size_t auxv_alloc
= 512, auxv_pos
= 0;
87 char *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
, char **readptr
, char *endptr
,
122 CORE_ADDR
*typep
, CORE_ADDR
*valp
)
124 const int sizeof_auxv_field
= TYPE_LENGTH (builtin_type_void_data_ptr
);
125 char *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
);
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
);
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.");