auxv.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /* Auxiliary vector support for GDB, the GNU debugger.
  2. Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "target.h"
  16. #include "gdbtypes.h"
  17. #include "command.h"
  18. #include "inferior.h"
  19. #include "valprint.h"
  20. #include "gdbcore.h"
  21. #include "observable.h"
  22. #include "gdbsupport/filestuff.h"
  23. #include "objfiles.h"
  24. #include "auxv.h"
  25. #include "elf/common.h"
  26. #include <unistd.h>
  27. #include <fcntl.h>
  28. /* Implement the to_xfer_partial target_ops method. This function
  29. handles access via /proc/PID/auxv, which is a common method for
  30. native targets. */
  31. static enum target_xfer_status
  32. procfs_xfer_auxv (gdb_byte *readbuf,
  33. const gdb_byte *writebuf,
  34. ULONGEST offset,
  35. ULONGEST len,
  36. ULONGEST *xfered_len)
  37. {
  38. ssize_t l;
  39. std::string pathname = string_printf ("/proc/%d/auxv", inferior_ptid.pid ());
  40. scoped_fd fd
  41. = gdb_open_cloexec (pathname, writebuf != NULL ? O_WRONLY : O_RDONLY, 0);
  42. if (fd.get () < 0)
  43. return TARGET_XFER_E_IO;
  44. if (offset != (ULONGEST) 0
  45. && lseek (fd.get (), (off_t) offset, SEEK_SET) != (off_t) offset)
  46. l = -1;
  47. else if (readbuf != NULL)
  48. l = read (fd.get (), readbuf, (size_t) len);
  49. else
  50. l = write (fd.get (), writebuf, (size_t) len);
  51. if (l < 0)
  52. return TARGET_XFER_E_IO;
  53. else if (l == 0)
  54. return TARGET_XFER_EOF;
  55. else
  56. {
  57. *xfered_len = (ULONGEST) l;
  58. return TARGET_XFER_OK;
  59. }
  60. }
  61. /* This function handles access via ld.so's symbol `_dl_auxv'. */
  62. static enum target_xfer_status
  63. ld_so_xfer_auxv (gdb_byte *readbuf,
  64. const gdb_byte *writebuf,
  65. ULONGEST offset,
  66. ULONGEST len, ULONGEST *xfered_len)
  67. {
  68. struct bound_minimal_symbol msym;
  69. CORE_ADDR data_address, pointer_address;
  70. struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
  71. size_t ptr_size = TYPE_LENGTH (ptr_type);
  72. size_t auxv_pair_size = 2 * ptr_size;
  73. gdb_byte *ptr_buf = (gdb_byte *) alloca (ptr_size);
  74. LONGEST retval;
  75. size_t block;
  76. msym = lookup_minimal_symbol ("_dl_auxv", NULL, NULL);
  77. if (msym.minsym == NULL)
  78. return TARGET_XFER_E_IO;
  79. if (MSYMBOL_SIZE (msym.minsym) != ptr_size)
  80. return TARGET_XFER_E_IO;
  81. /* POINTER_ADDRESS is a location where the `_dl_auxv' variable
  82. resides. DATA_ADDRESS is the inferior value present in
  83. `_dl_auxv', therefore the real inferior AUXV address. */
  84. pointer_address = BMSYMBOL_VALUE_ADDRESS (msym);
  85. /* The location of the _dl_auxv symbol may no longer be correct if
  86. ld.so runs at a different address than the one present in the
  87. file. This is very common case - for unprelinked ld.so or with a
  88. PIE executable. PIE executable forces random address even for
  89. libraries already being prelinked to some address. PIE
  90. executables themselves are never prelinked even on prelinked
  91. systems. Prelinking of a PIE executable would block their
  92. purpose of randomizing load of everything including the
  93. executable.
  94. If the memory read fails, return -1 to fallback on another
  95. mechanism for retrieving the AUXV.
  96. In most cases of a PIE running under valgrind there is no way to
  97. find out the base addresses of any of ld.so, executable or AUXV
  98. as everything is randomized and /proc information is not relevant
  99. for the virtual executable running under valgrind. We think that
  100. we might need a valgrind extension to make it work. This is PR
  101. 11440. */
  102. if (target_read_memory (pointer_address, ptr_buf, ptr_size) != 0)
  103. return TARGET_XFER_E_IO;
  104. data_address = extract_typed_address (ptr_buf, ptr_type);
  105. /* Possibly still not initialized such as during an inferior
  106. startup. */
  107. if (data_address == 0)
  108. return TARGET_XFER_E_IO;
  109. data_address += offset;
  110. if (writebuf != NULL)
  111. {
  112. if (target_write_memory (data_address, writebuf, len) == 0)
  113. {
  114. *xfered_len = (ULONGEST) len;
  115. return TARGET_XFER_OK;
  116. }
  117. else
  118. return TARGET_XFER_E_IO;
  119. }
  120. /* Stop if trying to read past the existing AUXV block. The final
  121. AT_NULL was already returned before. */
  122. if (offset >= auxv_pair_size)
  123. {
  124. if (target_read_memory (data_address - auxv_pair_size, ptr_buf,
  125. ptr_size) != 0)
  126. return TARGET_XFER_E_IO;
  127. if (extract_typed_address (ptr_buf, ptr_type) == AT_NULL)
  128. return TARGET_XFER_EOF;
  129. }
  130. retval = 0;
  131. block = 0x400;
  132. gdb_assert (block % auxv_pair_size == 0);
  133. while (len > 0)
  134. {
  135. if (block > len)
  136. block = len;
  137. /* Reading sizes smaller than AUXV_PAIR_SIZE is not supported.
  138. Tails unaligned to AUXV_PAIR_SIZE will not be read during a
  139. call (they should be completed during next read with
  140. new/extended buffer). */
  141. block &= -auxv_pair_size;
  142. if (block == 0)
  143. break;
  144. if (target_read_memory (data_address, readbuf, block) != 0)
  145. {
  146. if (block <= auxv_pair_size)
  147. break;
  148. block = auxv_pair_size;
  149. continue;
  150. }
  151. data_address += block;
  152. len -= block;
  153. /* Check terminal AT_NULL. This function is being called
  154. indefinitely being extended its READBUF until it returns EOF
  155. (0). */
  156. while (block >= auxv_pair_size)
  157. {
  158. retval += auxv_pair_size;
  159. if (extract_typed_address (readbuf, ptr_type) == AT_NULL)
  160. {
  161. *xfered_len = (ULONGEST) retval;
  162. return TARGET_XFER_OK;
  163. }
  164. readbuf += auxv_pair_size;
  165. block -= auxv_pair_size;
  166. }
  167. }
  168. *xfered_len = (ULONGEST) retval;
  169. return TARGET_XFER_OK;
  170. }
  171. /* Implement the to_xfer_partial target_ops method for
  172. TARGET_OBJECT_AUXV. It handles access to AUXV. */
  173. enum target_xfer_status
  174. memory_xfer_auxv (struct target_ops *ops,
  175. enum target_object object,
  176. const char *annex,
  177. gdb_byte *readbuf,
  178. const gdb_byte *writebuf,
  179. ULONGEST offset,
  180. ULONGEST len, ULONGEST *xfered_len)
  181. {
  182. gdb_assert (object == TARGET_OBJECT_AUXV);
  183. gdb_assert (readbuf || writebuf);
  184. /* ld_so_xfer_auxv is the only function safe for virtual
  185. executables being executed by valgrind's memcheck. Using
  186. ld_so_xfer_auxv during inferior startup is problematic, because
  187. ld.so symbol tables have not yet been relocated. So GDB uses
  188. this function only when attaching to a process.
  189. */
  190. if (current_inferior ()->attach_flag != 0)
  191. {
  192. enum target_xfer_status ret;
  193. ret = ld_so_xfer_auxv (readbuf, writebuf, offset, len, xfered_len);
  194. if (ret != TARGET_XFER_E_IO)
  195. return ret;
  196. }
  197. return procfs_xfer_auxv (readbuf, writebuf, offset, len, xfered_len);
  198. }
  199. /* This function compared to other auxv_parse functions: it takes the size of
  200. the auxv type field as a parameter. */
  201. static int
  202. generic_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr,
  203. gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp,
  204. int sizeof_auxv_type)
  205. {
  206. struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
  207. const int sizeof_auxv_val = TYPE_LENGTH (ptr_type);
  208. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  209. gdb_byte *ptr = *readptr;
  210. if (endptr == ptr)
  211. return 0;
  212. if (endptr - ptr < 2 * sizeof_auxv_val)
  213. return -1;
  214. *typep = extract_unsigned_integer (ptr, sizeof_auxv_type, byte_order);
  215. /* Even if the auxv type takes less space than an auxv value, there is
  216. padding after the type such that the value is aligned on a multiple of
  217. its size (and this is why we advance by `sizeof_auxv_val` and not
  218. `sizeof_auxv_type`). */
  219. ptr += sizeof_auxv_val;
  220. *valp = extract_unsigned_integer (ptr, sizeof_auxv_val, byte_order);
  221. ptr += sizeof_auxv_val;
  222. *readptr = ptr;
  223. return 1;
  224. }
  225. /* See auxv.h. */
  226. int
  227. default_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
  228. gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
  229. {
  230. struct gdbarch *gdbarch = target_gdbarch ();
  231. struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
  232. const int sizeof_auxv_type = TYPE_LENGTH (ptr_type);
  233. return generic_auxv_parse (gdbarch, readptr, endptr, typep, valp,
  234. sizeof_auxv_type);
  235. }
  236. /* See auxv.h. */
  237. int
  238. svr4_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr,
  239. gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
  240. {
  241. struct type *int_type = builtin_type (gdbarch)->builtin_int;
  242. const int sizeof_auxv_type = TYPE_LENGTH (int_type);
  243. return generic_auxv_parse (gdbarch, readptr, endptr, typep, valp,
  244. sizeof_auxv_type);
  245. }
  246. /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
  247. Return 0 if *READPTR is already at the end of the buffer.
  248. Return -1 if there is insufficient buffer for a whole entry.
  249. Return 1 if an entry was read into *TYPEP and *VALP. */
  250. int
  251. target_auxv_parse (gdb_byte **readptr,
  252. gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
  253. {
  254. struct gdbarch *gdbarch = target_gdbarch();
  255. if (gdbarch_auxv_parse_p (gdbarch))
  256. return gdbarch_auxv_parse (gdbarch, readptr, endptr, typep, valp);
  257. return current_inferior ()->top_target ()->auxv_parse (readptr, endptr,
  258. typep, valp);
  259. }
  260. /* Auxiliary Vector information structure. This is used by GDB
  261. for caching purposes for each inferior. This helps reduce the
  262. overhead of transfering data from a remote target to the local host. */
  263. struct auxv_info
  264. {
  265. gdb::optional<gdb::byte_vector> data;
  266. };
  267. /* Per-inferior data key for auxv. */
  268. static const struct inferior_key<auxv_info> auxv_inferior_data;
  269. /* Invalidate INF's auxv cache. */
  270. static void
  271. invalidate_auxv_cache_inf (struct inferior *inf)
  272. {
  273. auxv_inferior_data.clear (inf);
  274. }
  275. /* Invalidate current inferior's auxv cache. */
  276. static void
  277. invalidate_auxv_cache (void)
  278. {
  279. invalidate_auxv_cache_inf (current_inferior ());
  280. }
  281. /* Fetch the auxv object from inferior INF. If auxv is cached already,
  282. return a pointer to the cache. If not, fetch the auxv object from the
  283. target and cache it. This function always returns a valid INFO pointer. */
  284. static struct auxv_info *
  285. get_auxv_inferior_data (struct target_ops *ops)
  286. {
  287. struct auxv_info *info;
  288. struct inferior *inf = current_inferior ();
  289. info = auxv_inferior_data.get (inf);
  290. if (info == NULL)
  291. {
  292. info = auxv_inferior_data.emplace (inf);
  293. info->data = target_read_alloc (ops, TARGET_OBJECT_AUXV, NULL);
  294. }
  295. return info;
  296. }
  297. /* Extract the auxiliary vector entry with a_type matching MATCH.
  298. Return zero if no such entry was found, or -1 if there was
  299. an error getting the information. On success, return 1 after
  300. storing the entry's value field in *VALP. */
  301. int
  302. target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
  303. {
  304. CORE_ADDR type, val;
  305. auxv_info *info = get_auxv_inferior_data (ops);
  306. if (!info->data)
  307. return -1;
  308. gdb_byte *data = info->data->data ();
  309. gdb_byte *ptr = data;
  310. size_t len = info->data->size ();
  311. while (1)
  312. switch (target_auxv_parse (&ptr, data + len, &type, &val))
  313. {
  314. case 1: /* Here's an entry, check it. */
  315. if (type == match)
  316. {
  317. *valp = val;
  318. return 1;
  319. }
  320. break;
  321. case 0: /* End of the vector. */
  322. return 0;
  323. default: /* Bogosity. */
  324. return -1;
  325. }
  326. /*NOTREACHED*/
  327. }
  328. /* Print the description of a single AUXV entry on the specified file. */
  329. void
  330. fprint_auxv_entry (struct ui_file *file, const char *name,
  331. const char *description, enum auxv_format format,
  332. CORE_ADDR type, CORE_ADDR val)
  333. {
  334. gdb_printf (file, ("%-4s %-20s %-30s "),
  335. plongest (type), name, description);
  336. switch (format)
  337. {
  338. case AUXV_FORMAT_DEC:
  339. gdb_printf (file, ("%s\n"), plongest (val));
  340. break;
  341. case AUXV_FORMAT_HEX:
  342. gdb_printf (file, ("%s\n"), paddress (target_gdbarch (), val));
  343. break;
  344. case AUXV_FORMAT_STR:
  345. {
  346. struct value_print_options opts;
  347. get_user_print_options (&opts);
  348. if (opts.addressprint)
  349. gdb_printf (file, ("%s "), paddress (target_gdbarch (), val));
  350. val_print_string (builtin_type (target_gdbarch ())->builtin_char,
  351. NULL, val, -1, file, &opts);
  352. gdb_printf (file, ("\n"));
  353. }
  354. break;
  355. }
  356. }
  357. /* The default implementation of gdbarch_print_auxv_entry. */
  358. void
  359. default_print_auxv_entry (struct gdbarch *gdbarch, struct ui_file *file,
  360. CORE_ADDR type, CORE_ADDR val)
  361. {
  362. const char *name = "???";
  363. const char *description = "";
  364. enum auxv_format format = AUXV_FORMAT_HEX;
  365. switch (type)
  366. {
  367. #define TAG(tag, text, kind) \
  368. case tag: name = #tag; description = text; format = kind; break
  369. TAG (AT_NULL, _("End of vector"), AUXV_FORMAT_HEX);
  370. TAG (AT_IGNORE, _("Entry should be ignored"), AUXV_FORMAT_HEX);
  371. TAG (AT_EXECFD, _("File descriptor of program"), AUXV_FORMAT_DEC);
  372. TAG (AT_PHDR, _("Program headers for program"), AUXV_FORMAT_HEX);
  373. TAG (AT_PHENT, _("Size of program header entry"), AUXV_FORMAT_DEC);
  374. TAG (AT_PHNUM, _("Number of program headers"), AUXV_FORMAT_DEC);
  375. TAG (AT_PAGESZ, _("System page size"), AUXV_FORMAT_DEC);
  376. TAG (AT_BASE, _("Base address of interpreter"), AUXV_FORMAT_HEX);
  377. TAG (AT_FLAGS, _("Flags"), AUXV_FORMAT_HEX);
  378. TAG (AT_ENTRY, _("Entry point of program"), AUXV_FORMAT_HEX);
  379. TAG (AT_NOTELF, _("Program is not ELF"), AUXV_FORMAT_DEC);
  380. TAG (AT_UID, _("Real user ID"), AUXV_FORMAT_DEC);
  381. TAG (AT_EUID, _("Effective user ID"), AUXV_FORMAT_DEC);
  382. TAG (AT_GID, _("Real group ID"), AUXV_FORMAT_DEC);
  383. TAG (AT_EGID, _("Effective group ID"), AUXV_FORMAT_DEC);
  384. TAG (AT_CLKTCK, _("Frequency of times()"), AUXV_FORMAT_DEC);
  385. TAG (AT_PLATFORM, _("String identifying platform"), AUXV_FORMAT_STR);
  386. TAG (AT_HWCAP, _("Machine-dependent CPU capability hints"),
  387. AUXV_FORMAT_HEX);
  388. TAG (AT_FPUCW, _("Used FPU control word"), AUXV_FORMAT_DEC);
  389. TAG (AT_DCACHEBSIZE, _("Data cache block size"), AUXV_FORMAT_DEC);
  390. TAG (AT_ICACHEBSIZE, _("Instruction cache block size"), AUXV_FORMAT_DEC);
  391. TAG (AT_UCACHEBSIZE, _("Unified cache block size"), AUXV_FORMAT_DEC);
  392. TAG (AT_IGNOREPPC, _("Entry should be ignored"), AUXV_FORMAT_DEC);
  393. TAG (AT_BASE_PLATFORM, _("String identifying base platform"),
  394. AUXV_FORMAT_STR);
  395. TAG (AT_RANDOM, _("Address of 16 random bytes"), AUXV_FORMAT_HEX);
  396. TAG (AT_HWCAP2, _("Extension of AT_HWCAP"), AUXV_FORMAT_HEX);
  397. TAG (AT_EXECFN, _("File name of executable"), AUXV_FORMAT_STR);
  398. TAG (AT_SECURE, _("Boolean, was exec setuid-like?"), AUXV_FORMAT_DEC);
  399. TAG (AT_SYSINFO, _("Special system info/entry points"), AUXV_FORMAT_HEX);
  400. TAG (AT_SYSINFO_EHDR, _("System-supplied DSO's ELF header"),
  401. AUXV_FORMAT_HEX);
  402. TAG (AT_L1I_CACHESHAPE, _("L1 Instruction cache information"),
  403. AUXV_FORMAT_HEX);
  404. TAG (AT_L1I_CACHESIZE, _("L1 Instruction cache size"), AUXV_FORMAT_HEX);
  405. TAG (AT_L1I_CACHEGEOMETRY, _("L1 Instruction cache geometry"),
  406. AUXV_FORMAT_HEX);
  407. TAG (AT_L1D_CACHESHAPE, _("L1 Data cache information"), AUXV_FORMAT_HEX);
  408. TAG (AT_L1D_CACHESIZE, _("L1 Data cache size"), AUXV_FORMAT_HEX);
  409. TAG (AT_L1D_CACHEGEOMETRY, _("L1 Data cache geometry"),
  410. AUXV_FORMAT_HEX);
  411. TAG (AT_L2_CACHESHAPE, _("L2 cache information"), AUXV_FORMAT_HEX);
  412. TAG (AT_L2_CACHESIZE, _("L2 cache size"), AUXV_FORMAT_HEX);
  413. TAG (AT_L2_CACHEGEOMETRY, _("L2 cache geometry"), AUXV_FORMAT_HEX);
  414. TAG (AT_L3_CACHESHAPE, _("L3 cache information"), AUXV_FORMAT_HEX);
  415. TAG (AT_L3_CACHESIZE, _("L3 cache size"), AUXV_FORMAT_HEX);
  416. TAG (AT_L3_CACHEGEOMETRY, _("L3 cache geometry"), AUXV_FORMAT_HEX);
  417. TAG (AT_MINSIGSTKSZ, _("Minimum stack size for signal delivery"),
  418. AUXV_FORMAT_HEX);
  419. TAG (AT_SUN_UID, _("Effective user ID"), AUXV_FORMAT_DEC);
  420. TAG (AT_SUN_RUID, _("Real user ID"), AUXV_FORMAT_DEC);
  421. TAG (AT_SUN_GID, _("Effective group ID"), AUXV_FORMAT_DEC);
  422. TAG (AT_SUN_RGID, _("Real group ID"), AUXV_FORMAT_DEC);
  423. TAG (AT_SUN_LDELF, _("Dynamic linker's ELF header"), AUXV_FORMAT_HEX);
  424. TAG (AT_SUN_LDSHDR, _("Dynamic linker's section headers"),
  425. AUXV_FORMAT_HEX);
  426. TAG (AT_SUN_LDNAME, _("String giving name of dynamic linker"),
  427. AUXV_FORMAT_STR);
  428. TAG (AT_SUN_LPAGESZ, _("Large pagesize"), AUXV_FORMAT_DEC);
  429. TAG (AT_SUN_PLATFORM, _("Platform name string"), AUXV_FORMAT_STR);
  430. TAG (AT_SUN_CAP_HW1, _("Machine-dependent CPU capability hints"),
  431. AUXV_FORMAT_HEX);
  432. TAG (AT_SUN_IFLUSH, _("Should flush icache?"), AUXV_FORMAT_DEC);
  433. TAG (AT_SUN_CPU, _("CPU name string"), AUXV_FORMAT_STR);
  434. TAG (AT_SUN_EMUL_ENTRY, _("COFF entry point address"), AUXV_FORMAT_HEX);
  435. TAG (AT_SUN_EMUL_EXECFD, _("COFF executable file descriptor"),
  436. AUXV_FORMAT_DEC);
  437. TAG (AT_SUN_EXECNAME,
  438. _("Canonicalized file name given to execve"), AUXV_FORMAT_STR);
  439. TAG (AT_SUN_MMU, _("String for name of MMU module"), AUXV_FORMAT_STR);
  440. TAG (AT_SUN_LDDATA, _("Dynamic linker's data segment address"),
  441. AUXV_FORMAT_HEX);
  442. TAG (AT_SUN_AUXFLAGS,
  443. _("AF_SUN_ flags passed from the kernel"), AUXV_FORMAT_HEX);
  444. TAG (AT_SUN_EMULATOR, _("Name of emulation binary for runtime linker"),
  445. AUXV_FORMAT_STR);
  446. TAG (AT_SUN_BRANDNAME, _("Name of brand library"), AUXV_FORMAT_STR);
  447. TAG (AT_SUN_BRAND_AUX1, _("Aux vector for brand modules 1"),
  448. AUXV_FORMAT_HEX);
  449. TAG (AT_SUN_BRAND_AUX2, _("Aux vector for brand modules 2"),
  450. AUXV_FORMAT_HEX);
  451. TAG (AT_SUN_BRAND_AUX3, _("Aux vector for brand modules 3"),
  452. AUXV_FORMAT_HEX);
  453. TAG (AT_SUN_CAP_HW2, _("Machine-dependent CPU capability hints 2"),
  454. AUXV_FORMAT_HEX);
  455. }
  456. fprint_auxv_entry (file, name, description, format, type, val);
  457. }
  458. /* Print the contents of the target's AUXV on the specified file. */
  459. int
  460. fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
  461. {
  462. struct gdbarch *gdbarch = target_gdbarch ();
  463. CORE_ADDR type, val;
  464. int ents = 0;
  465. auxv_info *info = get_auxv_inferior_data (ops);
  466. if (!info->data)
  467. return -1;
  468. gdb_byte *data = info->data->data ();
  469. gdb_byte *ptr = data;
  470. size_t len = info->data->size ();
  471. while (target_auxv_parse (&ptr, data + len, &type, &val) > 0)
  472. {
  473. gdbarch_print_auxv_entry (gdbarch, file, type, val);
  474. ++ents;
  475. if (type == AT_NULL)
  476. break;
  477. }
  478. return ents;
  479. }
  480. static void
  481. info_auxv_command (const char *cmd, int from_tty)
  482. {
  483. if (! target_has_stack ())
  484. error (_("The program has no auxiliary information now."));
  485. else
  486. {
  487. int ents = fprint_target_auxv (gdb_stdout,
  488. current_inferior ()->top_target ());
  489. if (ents < 0)
  490. error (_("No auxiliary vector found, or failed reading it."));
  491. else if (ents == 0)
  492. error (_("Auxiliary vector is empty."));
  493. }
  494. }
  495. void _initialize_auxv ();
  496. void
  497. _initialize_auxv ()
  498. {
  499. add_info ("auxv", info_auxv_command,
  500. _("Display the inferior's auxiliary vector.\n\
  501. This is information provided by the operating system at program startup."));
  502. /* Observers used to invalidate the auxv cache when needed. */
  503. gdb::observers::inferior_exit.attach (invalidate_auxv_cache_inf, "auxv");
  504. gdb::observers::inferior_appeared.attach (invalidate_auxv_cache_inf, "auxv");
  505. gdb::observers::executable_changed.attach (invalidate_auxv_cache, "auxv");
  506. }