code_junkie

How do you get a pointer to the .text section?

Nov 11th, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. __FlashStart = .;
  2.  
  3. extern unsigned long int _FlashStart;
  4. unsigned long int address = (unsigned long int)&_FlashStart;
  5.  
  6. #include <bfd.h>
  7.  
  8. bfd *abfd;
  9. asection *p;
  10. char *filename = "/path/to/my/file";
  11.  
  12. if ((abfd = bfd_openr(filename, NULL)) == NULL) {
  13. /* ... error handling */
  14. }
  15.  
  16. if (!bfd_check_format (abfd, bfd_object)) {
  17. /* ... error handling */
  18. }
  19.  
  20. for (p = abfd->sections; p != NULL; p = p->next) {
  21. bfd_vma base_addr = bfd_section_vma(abfd, p);
  22. bfd_size_type size = bfd_section_size (abfd, p);
  23. const char *name = bfd_section_name(abfd, p);
  24. flagword flags = bfd_get_section_flags(abfd, p);
  25.  
  26. if (flags & SEC_CODE) {
  27. printf("%s: addr=%p size=%dn", name, base_addr, size);
  28. }
  29. }
Add Comment
Please, Sign In to add comment