osabi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /* OS ABI variant handling for GDB.
  2. Copyright (C) 2001-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 "osabi.h"
  16. #include "arch-utils.h"
  17. #include "gdbcmd.h"
  18. #include "command.h"
  19. #include "gdb_bfd.h"
  20. #include "elf-bfd.h"
  21. #ifndef GDB_OSABI_DEFAULT
  22. #define GDB_OSABI_DEFAULT GDB_OSABI_UNKNOWN
  23. #endif
  24. /* State for the "set osabi" command. */
  25. static enum { osabi_auto, osabi_default, osabi_user } user_osabi_state;
  26. static enum gdb_osabi user_selected_osabi;
  27. static const char *gdb_osabi_available_names[GDB_OSABI_INVALID + 3] = {
  28. "auto",
  29. "default",
  30. "none",
  31. NULL
  32. };
  33. static const char *set_osabi_string;
  34. /* Names associated with each osabi. */
  35. struct osabi_names
  36. {
  37. /* The "pretty" name. */
  38. const char *pretty;
  39. /* The triplet regexp, or NULL if not known. */
  40. const char *regexp;
  41. };
  42. /* This table matches the indices assigned to enum gdb_osabi. Keep
  43. them in sync. */
  44. static const struct osabi_names gdb_osabi_names[] =
  45. {
  46. { "unknown", NULL },
  47. { "none", NULL },
  48. { "SVR4", NULL },
  49. { "GNU/Hurd", NULL },
  50. { "Solaris", NULL },
  51. { "GNU/Linux", "linux(-gnu[^-]*)?" },
  52. { "FreeBSD", NULL },
  53. { "NetBSD", NULL },
  54. { "OpenBSD", NULL },
  55. { "WindowsCE", NULL },
  56. { "DJGPP", NULL },
  57. { "QNX-Neutrino", NULL },
  58. { "Cygwin", NULL },
  59. { "Windows", NULL },
  60. { "AIX", NULL },
  61. { "DICOS", NULL },
  62. { "Darwin", NULL },
  63. { "OpenVMS", NULL },
  64. { "LynxOS178", NULL },
  65. { "Newlib", NULL },
  66. { "SDE", NULL },
  67. { "PikeOS", NULL },
  68. { "<invalid>", NULL }
  69. };
  70. const char *
  71. gdbarch_osabi_name (enum gdb_osabi osabi)
  72. {
  73. if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID)
  74. return gdb_osabi_names[osabi].pretty;
  75. return gdb_osabi_names[GDB_OSABI_INVALID].pretty;
  76. }
  77. /* See osabi.h. */
  78. const char *
  79. osabi_triplet_regexp (enum gdb_osabi osabi)
  80. {
  81. if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID)
  82. return gdb_osabi_names[osabi].regexp;
  83. return gdb_osabi_names[GDB_OSABI_INVALID].regexp;
  84. }
  85. /* Lookup the OS ABI corresponding to the specified target description
  86. string. */
  87. enum gdb_osabi
  88. osabi_from_tdesc_string (const char *name)
  89. {
  90. int i;
  91. for (i = 0; i < ARRAY_SIZE (gdb_osabi_names); i++)
  92. if (strcmp (name, gdb_osabi_names[i].pretty) == 0)
  93. {
  94. /* See note above: the name table matches the indices assigned
  95. to enum gdb_osabi. */
  96. enum gdb_osabi osabi = (enum gdb_osabi) i;
  97. if (osabi == GDB_OSABI_INVALID)
  98. return GDB_OSABI_UNKNOWN;
  99. else
  100. return osabi;
  101. }
  102. return GDB_OSABI_UNKNOWN;
  103. }
  104. /* Handler for a given architecture/OS ABI pair. There should be only
  105. one handler for a given OS ABI each architecture family. */
  106. struct gdb_osabi_handler
  107. {
  108. struct gdb_osabi_handler *next;
  109. const struct bfd_arch_info *arch_info;
  110. enum gdb_osabi osabi;
  111. void (*init_osabi)(struct gdbarch_info, struct gdbarch *);
  112. };
  113. static struct gdb_osabi_handler *gdb_osabi_handler_list;
  114. void
  115. gdbarch_register_osabi (enum bfd_architecture arch, unsigned long machine,
  116. enum gdb_osabi osabi,
  117. void (*init_osabi)(struct gdbarch_info,
  118. struct gdbarch *))
  119. {
  120. struct gdb_osabi_handler **handler_p;
  121. const struct bfd_arch_info *arch_info = bfd_lookup_arch (arch, machine);
  122. const char **name_ptr;
  123. /* Registering an OS ABI handler for "unknown" is not allowed. */
  124. if (osabi == GDB_OSABI_UNKNOWN)
  125. {
  126. internal_error
  127. (__FILE__, __LINE__,
  128. _("gdbarch_register_osabi: An attempt to register a handler for "
  129. "OS ABI \"%s\" for architecture %s was made. The handler will "
  130. "not be registered"),
  131. gdbarch_osabi_name (osabi),
  132. bfd_printable_arch_mach (arch, machine));
  133. return;
  134. }
  135. gdb_assert (arch_info);
  136. for (handler_p = &gdb_osabi_handler_list; *handler_p != NULL;
  137. handler_p = &(*handler_p)->next)
  138. {
  139. if ((*handler_p)->arch_info == arch_info
  140. && (*handler_p)->osabi == osabi)
  141. {
  142. internal_error
  143. (__FILE__, __LINE__,
  144. _("gdbarch_register_osabi: A handler for OS ABI \"%s\" "
  145. "has already been registered for architecture %s"),
  146. gdbarch_osabi_name (osabi),
  147. arch_info->printable_name);
  148. /* If user wants to continue, override previous definition. */
  149. (*handler_p)->init_osabi = init_osabi;
  150. return;
  151. }
  152. }
  153. (*handler_p) = XNEW (struct gdb_osabi_handler);
  154. (*handler_p)->next = NULL;
  155. (*handler_p)->arch_info = arch_info;
  156. (*handler_p)->osabi = osabi;
  157. (*handler_p)->init_osabi = init_osabi;
  158. /* Add this OS ABI to the list of enum values for "set osabi", if it isn't
  159. already there. */
  160. for (name_ptr = gdb_osabi_available_names; *name_ptr; name_ptr ++)
  161. {
  162. if (*name_ptr == gdbarch_osabi_name (osabi))
  163. return;
  164. }
  165. *name_ptr++ = gdbarch_osabi_name (osabi);
  166. *name_ptr = NULL;
  167. }
  168. /* Sniffer to find the OS ABI for a given file's architecture and flavour.
  169. It is legal to have multiple sniffers for each arch/flavour pair, to
  170. disambiguate one OS's a.out from another, for example. The first sniffer
  171. to return something other than GDB_OSABI_UNKNOWN wins, so a sniffer should
  172. be careful to claim a file only if it knows for sure what it is. */
  173. struct gdb_osabi_sniffer
  174. {
  175. struct gdb_osabi_sniffer *next;
  176. enum bfd_architecture arch; /* bfd_arch_unknown == wildcard */
  177. enum bfd_flavour flavour;
  178. enum gdb_osabi (*sniffer)(bfd *);
  179. };
  180. static struct gdb_osabi_sniffer *gdb_osabi_sniffer_list;
  181. void
  182. gdbarch_register_osabi_sniffer (enum bfd_architecture arch,
  183. enum bfd_flavour flavour,
  184. enum gdb_osabi (*sniffer_fn)(bfd *))
  185. {
  186. struct gdb_osabi_sniffer *sniffer;
  187. sniffer = XNEW (struct gdb_osabi_sniffer);
  188. sniffer->arch = arch;
  189. sniffer->flavour = flavour;
  190. sniffer->sniffer = sniffer_fn;
  191. sniffer->next = gdb_osabi_sniffer_list;
  192. gdb_osabi_sniffer_list = sniffer;
  193. }
  194. enum gdb_osabi
  195. gdbarch_lookup_osabi (bfd *abfd)
  196. {
  197. struct gdb_osabi_sniffer *sniffer;
  198. enum gdb_osabi osabi, match;
  199. int match_specific;
  200. /* If we aren't in "auto" mode, return the specified OS ABI. */
  201. if (user_osabi_state == osabi_user)
  202. return user_selected_osabi;
  203. /* If we don't have a binary, just return unknown. The caller may
  204. have other sources the OSABI can be extracted from, e.g., the
  205. target description. */
  206. if (abfd == NULL)
  207. return GDB_OSABI_UNKNOWN;
  208. match = GDB_OSABI_UNKNOWN;
  209. match_specific = 0;
  210. for (sniffer = gdb_osabi_sniffer_list; sniffer != NULL;
  211. sniffer = sniffer->next)
  212. {
  213. if ((sniffer->arch == bfd_arch_unknown /* wildcard */
  214. || sniffer->arch == bfd_get_arch (abfd))
  215. && sniffer->flavour == bfd_get_flavour (abfd))
  216. {
  217. osabi = (*sniffer->sniffer) (abfd);
  218. if (osabi < GDB_OSABI_UNKNOWN || osabi >= GDB_OSABI_INVALID)
  219. {
  220. internal_error
  221. (__FILE__, __LINE__,
  222. _("gdbarch_lookup_osabi: invalid OS ABI (%d) from sniffer "
  223. "for architecture %s flavour %d"),
  224. (int) osabi,
  225. bfd_printable_arch_mach (bfd_get_arch (abfd), 0),
  226. (int) bfd_get_flavour (abfd));
  227. }
  228. else if (osabi != GDB_OSABI_UNKNOWN)
  229. {
  230. /* A specific sniffer always overrides a generic sniffer.
  231. Croak on multiple match if the two matches are of the
  232. same class. If the user wishes to continue, we'll use
  233. the first match. */
  234. if (match != GDB_OSABI_UNKNOWN)
  235. {
  236. if ((match_specific && sniffer->arch != bfd_arch_unknown)
  237. || (!match_specific && sniffer->arch == bfd_arch_unknown))
  238. {
  239. internal_error
  240. (__FILE__, __LINE__,
  241. _("gdbarch_lookup_osabi: multiple %sspecific OS ABI "
  242. "match for architecture %s flavour %d: first "
  243. "match \"%s\", second match \"%s\""),
  244. match_specific ? "" : "non-",
  245. bfd_printable_arch_mach (bfd_get_arch (abfd), 0),
  246. (int) bfd_get_flavour (abfd),
  247. gdbarch_osabi_name (match),
  248. gdbarch_osabi_name (osabi));
  249. }
  250. else if (sniffer->arch != bfd_arch_unknown)
  251. {
  252. match = osabi;
  253. match_specific = 1;
  254. }
  255. }
  256. else
  257. {
  258. match = osabi;
  259. if (sniffer->arch != bfd_arch_unknown)
  260. match_specific = 1;
  261. }
  262. }
  263. }
  264. }
  265. return match;
  266. }
  267. /* Return non-zero if architecture A can run code written for
  268. architecture B. */
  269. static int
  270. can_run_code_for (const struct bfd_arch_info *a, const struct bfd_arch_info *b)
  271. {
  272. /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
  273. incompatible. But if they are compatible, it returns the 'more
  274. featureful' of the two arches. That is, if A can run code
  275. written for B, but B can't run code written for A, then it'll
  276. return A.
  277. struct bfd_arch_info objects are singletons: that is, there's
  278. supposed to be exactly one instance for a given machine. So you
  279. can tell whether two are equivalent by comparing pointers. */
  280. return (a == b || a->compatible (a, b) == a);
  281. }
  282. void
  283. gdbarch_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
  284. {
  285. struct gdb_osabi_handler *handler;
  286. gdb_assert (info.osabi != GDB_OSABI_UNKNOWN);
  287. for (handler = gdb_osabi_handler_list; handler != NULL;
  288. handler = handler->next)
  289. {
  290. if (handler->osabi != info.osabi)
  291. continue;
  292. /* If the architecture described by ARCH_INFO can run code for
  293. the architecture we registered the handler for, then the
  294. handler is applicable. Note, though, that if the handler is
  295. for an architecture that is a superset of ARCH_INFO, we can't
  296. use that --- it would be perfectly correct for it to install
  297. gdbarch methods that refer to registers / instructions /
  298. other facilities ARCH_INFO doesn't have.
  299. NOTE: kettenis/20021027: There may be more than one machine
  300. type that is compatible with the desired machine type. Right
  301. now we simply return the first match, which is fine for now.
  302. However, we might want to do something smarter in the future. */
  303. /* NOTE: cagney/2003-10-23: The code for "a can_run_code_for b"
  304. is implemented using BFD's compatible method (a->compatible
  305. (b) == a -- the lowest common denominator between a and b is
  306. a). That method's definition of compatible may not be as you
  307. expect. For instance the test "amd64 can run code for i386"
  308. (or more generally "64-bit ISA can run code for the 32-bit
  309. ISA"). BFD doesn't normally consider 32-bit and 64-bit
  310. "compatible" so it doesn't succeed. */
  311. if (can_run_code_for (info.bfd_arch_info, handler->arch_info))
  312. {
  313. (*handler->init_osabi) (info, gdbarch);
  314. return;
  315. }
  316. }
  317. if (info.osabi == GDB_OSABI_NONE)
  318. {
  319. /* Don't complain about no OSABI. Assume the user knows
  320. what they are doing. */
  321. return;
  322. }
  323. warning
  324. ("A handler for the OS ABI \"%s\" is not built into this configuration\n"
  325. "of GDB. Attempting to continue with the default %s settings.\n",
  326. gdbarch_osabi_name (info.osabi),
  327. info.bfd_arch_info->printable_name);
  328. }
  329. /* Limit on the amount of data to be read. */
  330. #define MAX_NOTESZ 128
  331. /* Return non-zero if NOTE matches NAME, DESCSZ and TYPE. If
  332. *SECTSIZE is non-zero, then this reads that many bytes from
  333. the start of the section and clears *SECTSIZE. */
  334. static int
  335. check_note (bfd *abfd, asection *sect, char *note, unsigned int *sectsize,
  336. const char *name, unsigned long descsz, unsigned long type)
  337. {
  338. unsigned long notesz;
  339. if (*sectsize)
  340. {
  341. if (!bfd_get_section_contents (abfd, sect, note, 0, *sectsize))
  342. return 0;
  343. *sectsize = 0;
  344. }
  345. /* Calculate the size of this note. */
  346. notesz = strlen (name) + 1;
  347. notesz = ((notesz + 3) & ~3);
  348. notesz += descsz;
  349. notesz = ((notesz + 3) & ~3);
  350. /* If this assertion triggers, increase MAX_NOTESZ. */
  351. gdb_assert (notesz <= MAX_NOTESZ);
  352. /* Check whether SECT is big enough to contain the complete note. */
  353. if (notesz > bfd_section_size (sect))
  354. return 0;
  355. /* Check the note name. */
  356. if (bfd_h_get_32 (abfd, note) != (strlen (name) + 1)
  357. || strcmp (note + 12, name) != 0)
  358. return 0;
  359. /* Check the descriptor size. */
  360. if (bfd_h_get_32 (abfd, note + 4) != descsz)
  361. return 0;
  362. /* Check the note type. */
  363. if (bfd_h_get_32 (abfd, note + 8) != type)
  364. return 0;
  365. return 1;
  366. }
  367. /* Generic sniffer for ELF flavoured files. */
  368. void
  369. generic_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
  370. enum gdb_osabi *osabi)
  371. {
  372. const char *name;
  373. unsigned int sectsize;
  374. char *note;
  375. name = bfd_section_name (sect);
  376. sectsize = bfd_section_size (sect);
  377. /* Limit the amount of data to read. */
  378. if (sectsize > MAX_NOTESZ)
  379. sectsize = MAX_NOTESZ;
  380. /* We lazily read the section data here. Since we use
  381. BFD_DECOMPRESS, we can't use bfd_get_section_contents on a
  382. compressed section. But, since note sections are not compressed,
  383. deferring the reading until we recognize the section avoids any
  384. error. */
  385. note = (char *) alloca (sectsize);
  386. /* .note.ABI-tag notes, used by GNU/Linux and FreeBSD. */
  387. if (strcmp (name, ".note.ABI-tag") == 0)
  388. {
  389. /* GNU. */
  390. if (check_note (abfd, sect, note, &sectsize, "GNU", 16, NT_GNU_ABI_TAG))
  391. {
  392. unsigned int abi_tag = bfd_h_get_32 (abfd, note + 16);
  393. switch (abi_tag)
  394. {
  395. case GNU_ABI_TAG_LINUX:
  396. *osabi = GDB_OSABI_LINUX;
  397. break;
  398. case GNU_ABI_TAG_HURD:
  399. *osabi = GDB_OSABI_HURD;
  400. break;
  401. case GNU_ABI_TAG_SOLARIS:
  402. *osabi = GDB_OSABI_SOLARIS;
  403. break;
  404. case GNU_ABI_TAG_FREEBSD:
  405. *osabi = GDB_OSABI_FREEBSD;
  406. break;
  407. case GNU_ABI_TAG_NETBSD:
  408. *osabi = GDB_OSABI_NETBSD;
  409. break;
  410. default:
  411. warning (_("GNU ABI tag value %u unrecognized."), abi_tag);
  412. break;
  413. }
  414. return;
  415. }
  416. /* FreeBSD. */
  417. if (check_note (abfd, sect, note, &sectsize, "FreeBSD", 4,
  418. NT_FREEBSD_ABI_TAG))
  419. {
  420. /* There is no need to check the version yet. */
  421. *osabi = GDB_OSABI_FREEBSD;
  422. return;
  423. }
  424. return;
  425. }
  426. /* .note.netbsd.ident notes, used by NetBSD. */
  427. if (strcmp (name, ".note.netbsd.ident") == 0
  428. && check_note (abfd, sect, note, &sectsize, "NetBSD", 4, NT_NETBSD_IDENT))
  429. {
  430. /* There is no need to check the version yet. */
  431. *osabi = GDB_OSABI_NETBSD;
  432. return;
  433. }
  434. /* .note.openbsd.ident notes, used by OpenBSD. */
  435. if (strcmp (name, ".note.openbsd.ident") == 0
  436. && check_note (abfd, sect, note, &sectsize, "OpenBSD", 4,
  437. NT_OPENBSD_IDENT))
  438. {
  439. /* There is no need to check the version yet. */
  440. *osabi = GDB_OSABI_OPENBSD;
  441. return;
  442. }
  443. /* .note.netbsdcore.procinfo notes, used by NetBSD. */
  444. if (strcmp (name, ".note.netbsdcore.procinfo") == 0)
  445. {
  446. *osabi = GDB_OSABI_NETBSD;
  447. return;
  448. }
  449. }
  450. static enum gdb_osabi
  451. generic_elf_osabi_sniffer (bfd *abfd)
  452. {
  453. unsigned int elfosabi;
  454. enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
  455. elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
  456. switch (elfosabi)
  457. {
  458. case ELFOSABI_NONE:
  459. case ELFOSABI_GNU:
  460. case ELFOSABI_HPUX:
  461. /* When the EI_OSABI field in the ELF header is ELFOSABI_NONE
  462. (0), then the ELF structures in the file are conforming to
  463. the base specification for that machine (there are no
  464. OS-specific extensions). In order to determine the real OS
  465. in use, we must look for OS-specific notes.
  466. The same applies for ELFOSABI_GNU: this can mean GNU/Hurd,
  467. GNU/Linux, and possibly more. */
  468. /* And likewise ELFOSABI_HPUX. For some reason the default
  469. value for the EI_OSABI field is ELFOSABI_HPUX for all PA-RISC
  470. targets (with the exception of GNU/Linux). */
  471. for (asection *sect : gdb_bfd_sections (abfd))
  472. generic_elf_osabi_sniff_abi_tag_sections (abfd, sect, &osabi);
  473. break;
  474. case ELFOSABI_FREEBSD:
  475. osabi = GDB_OSABI_FREEBSD;
  476. break;
  477. case ELFOSABI_NETBSD:
  478. osabi = GDB_OSABI_NETBSD;
  479. break;
  480. case ELFOSABI_SOLARIS:
  481. osabi = GDB_OSABI_SOLARIS;
  482. break;
  483. case ELFOSABI_OPENVMS:
  484. osabi = GDB_OSABI_OPENVMS;
  485. break;
  486. }
  487. if (osabi == GDB_OSABI_UNKNOWN)
  488. {
  489. /* The FreeBSD folks have been naughty; they stored the string
  490. "FreeBSD" in the padding of the e_ident field of the ELF
  491. header to "brand" their ELF binaries in FreeBSD 3.x. */
  492. if (memcmp (&elf_elfheader (abfd)->e_ident[8],
  493. "FreeBSD", sizeof ("FreeBSD")) == 0)
  494. osabi = GDB_OSABI_FREEBSD;
  495. }
  496. return osabi;
  497. }
  498. static void
  499. set_osabi (const char *args, int from_tty, struct cmd_list_element *c)
  500. {
  501. if (strcmp (set_osabi_string, "auto") == 0)
  502. user_osabi_state = osabi_auto;
  503. else if (strcmp (set_osabi_string, "default") == 0)
  504. {
  505. user_selected_osabi = GDB_OSABI_DEFAULT;
  506. user_osabi_state = osabi_user;
  507. }
  508. else
  509. {
  510. int i;
  511. for (i = 1; i < GDB_OSABI_INVALID; i++)
  512. {
  513. enum gdb_osabi osabi = (enum gdb_osabi) i;
  514. if (strcmp (set_osabi_string, gdbarch_osabi_name (osabi)) == 0)
  515. {
  516. user_selected_osabi = osabi;
  517. user_osabi_state = osabi_user;
  518. break;
  519. }
  520. }
  521. if (i == GDB_OSABI_INVALID)
  522. internal_error (__FILE__, __LINE__,
  523. _("Invalid OS ABI \"%s\" passed to command handler."),
  524. set_osabi_string);
  525. }
  526. /* NOTE: At some point (true multiple architectures) we'll need to be more
  527. graceful here. */
  528. gdbarch_info info;
  529. if (! gdbarch_update_p (info))
  530. internal_error (__FILE__, __LINE__, _("Updating OS ABI failed."));
  531. }
  532. static void
  533. show_osabi (struct ui_file *file, int from_tty, struct cmd_list_element *c,
  534. const char *value)
  535. {
  536. if (user_osabi_state == osabi_auto)
  537. gdb_printf (file,
  538. _("The current OS ABI is \"auto\" "
  539. "(currently \"%s\").\n"),
  540. gdbarch_osabi_name (gdbarch_osabi (get_current_arch ())));
  541. else
  542. gdb_printf (file, _("The current OS ABI is \"%s\".\n"),
  543. gdbarch_osabi_name (user_selected_osabi));
  544. if (GDB_OSABI_DEFAULT != GDB_OSABI_UNKNOWN)
  545. gdb_printf (file, _("The default OS ABI is \"%s\".\n"),
  546. gdbarch_osabi_name (GDB_OSABI_DEFAULT));
  547. }
  548. void _initialize_gdb_osabi ();
  549. void
  550. _initialize_gdb_osabi ()
  551. {
  552. if (strcmp (gdb_osabi_names[GDB_OSABI_INVALID].pretty, "<invalid>") != 0)
  553. internal_error
  554. (__FILE__, __LINE__,
  555. _("_initialize_gdb_osabi: gdb_osabi_names[] is inconsistent"));
  556. /* Register a generic sniffer for ELF flavoured files. */
  557. gdbarch_register_osabi_sniffer (bfd_arch_unknown,
  558. bfd_target_elf_flavour,
  559. generic_elf_osabi_sniffer);
  560. /* Register the "set osabi" command. */
  561. user_osabi_state = osabi_auto;
  562. set_osabi_string = gdb_osabi_available_names[0];
  563. gdb_assert (strcmp (set_osabi_string, "auto") == 0);
  564. add_setshow_enum_cmd ("osabi", class_support, gdb_osabi_available_names,
  565. &set_osabi_string,
  566. _("Set OS ABI of target."),
  567. _("Show OS ABI of target."),
  568. NULL, set_osabi, show_osabi,
  569. &setlist, &showlist);
  570. }