astest.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * (C) Copyright 2000
  3. * Murray Jensen <Murray.Jensen@csiro.au>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  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.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <unistd.h>
  27. #include <fcntl.h>
  28. #include <bfd.h>
  29. #include "error.h"
  30. int verbose = 0;
  31. void
  32. process_section(bfd *abfd, asection *sect, PTR obj)
  33. {
  34. printf("Section '%s':\n", sect->name);
  35. printf("\tindex=%d, flags=%x\n", sect->index, sect->flags);
  36. #if 0
  37. printf("\tuser_set_vma=%u, reloc_done=%u, linker_mark=%u, gc_mark=%u\n",
  38. (unsigned long)sect->user_set_vma, (unsigned long)sect->reloc_done,
  39. (unsigned long)sect->linker_mark, (unsigned long)sect->gc_mark);
  40. #else
  41. printf("\tuser_set_vma=%u, reloc_done=%u\n",
  42. (unsigned int)sect->user_set_vma, (unsigned int)sect->reloc_done);
  43. #endif
  44. printf("\tvma=%08lx, lma=%08lx\n",
  45. (unsigned long)sect->vma, (unsigned long)sect->lma);
  46. printf("\tcooked_size=%ld, raw_size=%ld, output_offset=%ld\n",
  47. (long)sect->_cooked_size, (long)sect->_raw_size,
  48. (long)sect->output_offset);
  49. printf("\talignment_power=%d, reloc_count=%d, filepos=%ld\n",
  50. sect->alignment_power, sect->reloc_count, sect->filepos);
  51. printf("\trel_filepos=%ld, line_filepos=%ld, lineno_count=%d\n",
  52. sect->rel_filepos, sect->line_filepos, sect->lineno_count);
  53. printf("\tmoving_line_filepos=%ld, target_index=%d\n",
  54. sect->moving_line_filepos, sect->target_index);
  55. }
  56. int
  57. main(int ac, char **av)
  58. {
  59. int c, ifd;
  60. char *ifn;
  61. bfd *bfdp;
  62. if ((pname = strrchr(av[0], '/')) == NULL)
  63. pname = av[0];
  64. else
  65. pname++;
  66. while ((c = getopt(ac, av, "v")) != EOF)
  67. switch (c) {
  68. case 'v':
  69. verbose = 1;
  70. break;
  71. default:
  72. usage:
  73. fprintf(stderr, "Usage: %s [-v] imagefile\n", pname);
  74. exit(1);
  75. }
  76. if (optind != ac - 1)
  77. goto usage;
  78. ifn = av[optind];
  79. if (verbose)
  80. fprintf(stderr, "Opening file...\n");
  81. if ((ifd = open(ifn, O_RDONLY)) < 0)
  82. Perror("can't open image file '%s'", ifn);
  83. if ((bfdp = bfd_fdopenr(ifn, "elf32-powerpc", ifd)) == NULL) {
  84. bfd_perror(ifn);
  85. close(ifd);
  86. Error("bfd_fdopenr of file '%s' failed", ifn);
  87. }
  88. bfdp->cacheable = 1;
  89. if (!bfd_check_format(bfdp, bfd_object) ||
  90. (bfd_get_file_flags(bfdp) & EXEC_P) == 0) {
  91. bfd_close(bfdp);
  92. Error("file '%s' is not an executable object file (%s,0x%x)", ifn,
  93. bfd_format_string(bfd_get_format(bfdp)), bfd_get_file_flags(bfdp));
  94. }
  95. printf("file '%s' is type '%s'...\n", ifn, bfd_get_target(bfdp));
  96. bfd_map_over_sections(bfdp, process_section, NULL);;
  97. bfd_close(bfdp);
  98. if (verbose)
  99. fprintf(stderr, "Done.\n");
  100. return (0);
  101. }