static void find_address_in_section(bfd *abfd, asection *section, void *data) { bfd_vma pc, vma; bfd_size_type size; struct a2l_data *a2l = data; if (a2l->found) return; if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0) return; pc = a2l->addr; vma = bfd_get_section_vma(abfd, section); size = bfd_get_section_size(section); if (pc < vma || pc >= vma + size) return; a2l->found = bfd_find_nearest_line(abfd, section, a2l->syms, pc - vma, &a2l->filename, &a2l->funcname, &a2l->line); if (a2l->filename && !strlen(a2l->filename)) a2l->filename = NULL; }
void exec_set_section_offsets (bfd_signed_vma text_off, bfd_signed_vma data_off, bfd_signed_vma bss_off) { struct section_table *sect; for (sect = exec_ops.to_sections; sect < exec_ops.to_sections_end; sect++) { flagword flags; flags = bfd_get_section_flags (exec_bfd, sect->the_bfd_section); if (flags & SEC_CODE) { sect->addr += text_off; sect->endaddr += text_off; } else if (flags & (SEC_DATA | SEC_LOAD)) { sect->addr += data_off; sect->endaddr += data_off; } else if (flags & SEC_ALLOC) { sect->addr += bss_off; sect->endaddr += bss_off; } } }
void dwarf2_emit_label (symbolS *label) { struct dwarf2_line_info loc; if (!dwarf2_loc_mark_labels) return; if (S_GET_SEGMENT (label) != now_seg) return; if (!(bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)) return; if (debug_type == DEBUG_DWARF2) dwarf2_where (&loc); else { loc = current; loc_directive_seen = FALSE; } loc.flags |= DWARF2_FLAG_BASIC_BLOCK; current.flags &= ~(DWARF2_FLAG_BASIC_BLOCK | DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_EPILOGUE_BEGIN); dwarf2_gen_line_info_1 (label, &loc); }
static void debug_translateAddress(const char *symbol, bfd_vma address) { const char *file, *func; unsigned int line; asection *section; for (section = abfd->sections; section != NULL; section = section->next) { if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0) continue; bfd_vma vma = bfd_get_section_vma(abfd, section); bfd_size_type size = bfd_get_section_size(section); if (address < vma || address >= vma + size) continue; if (!bfd_find_nearest_line(abfd, section, syms, address - vma, &file, &func, &line)) continue; do { if (func == NULL || func[0] == '\0') func = "??"; if (file == NULL || file[0] == '\0') file = "??"; DEBUG("%s %s(...):%u %s", symbol, func, line, file); } while (bfd_find_inliner_info(abfd, &file, &func, &line)); return; } DEBUG("%s %s(...):%u %s", symbol, "??", 0, "??"); }
static segT make_debug_seg (segT cseg, char *name, int sflags) { segT save_seg = now_seg; int save_subseg = now_subseg; segT r; flagword flags; r = subseg_new (name, 0); /* Check if code segment is marked as linked once. */ if (!cseg) flags = 0; else flags = bfd_get_section_flags (stdoutput, cseg) & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE | SEC_LINK_DUPLICATES_SAME_CONTENTS); /* Add standard section flags. */ flags |= sflags; /* Apply possibly linked once flags to new generated segment, too. */ if (!bfd_set_section_flags (stdoutput, r, flags)) as_bad (_("bfd_set_section_flags: %s"), bfd_errmsg (bfd_get_error ())); /* Restore to previous segment. */ if (save_seg != NULL) subseg_set (save_seg, save_subseg); return r; }
/* Look for an address in a section. * This is called via bfd_map_over_sections. */ static void find_address_in_section (bfd *abfd, asection *section, void *data) { bfd_vma vma; bfd_size_type size; struct symbol *symbol = data; struct symtab *symtab = symbol->symtab; if (symbol->found) return; if ((bfd_get_section_flags (symtab->bfd, section) & SEC_ALLOC) == 0) return; vma = bfd_get_section_vma (symtab->bfd, section); if (symbol->pc < vma) return; size = bfd_section_size (symtab->bfd, section); if (symbol->pc >= vma + size) return; symbol->found = bfd_find_nearest_line (symtab->bfd, section, symtab->syms, symbol->pc - vma, &symbol->filename, &symbol->functionname, &symbol->line); }
void stacktrace::find_address_in_section (bfd* abfd, asection* section, void* data) { stacktrace* self = static_cast<stacktrace*> (data); bfd_vma vma; bfd_size_type size; if (self->found) return; if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0) return; vma = bfd_get_section_vma (abfd, section); if (self->pc < vma) return; size = bfd_section_size (abfd, section); if (self->pc >= vma + size) return; self->found = bfd_find_nearest_line (abfd, section, self->syms, self->pc - vma, &self->filename, &self->funcname, &self->line); }
static void bfdsec_to_vmap (struct bfd *abfd, struct bfd_section *sect, void *arg3) { struct vmap_and_bfd *vmap_bfd = (struct vmap_and_bfd *) arg3; struct vmap *vp; vp = vmap_bfd->pvmap; if ((bfd_get_section_flags (abfd, sect) & SEC_LOAD) == 0) return; if (strcmp (bfd_section_name (abfd, sect), ".text") == 0) { vp->tstart = bfd_section_vma (abfd, sect); vp->tend = vp->tstart + bfd_section_size (abfd, sect); vp->tvma = bfd_section_vma (abfd, sect); vp->toffs = sect->filepos; } else if (strcmp (bfd_section_name (abfd, sect), ".data") == 0) { vp->dstart = bfd_section_vma (abfd, sect); vp->dend = vp->dstart + bfd_section_size (abfd, sect); vp->dvma = bfd_section_vma (abfd, sect); } /* Silently ignore other types of sections. (FIXME?) */ }
/** Find_Address_In_Section * * Localitza la direccio (pc) dins de la seccio ".text" del binari * * @param abfd * @param section * @param data * * @return No return value. */ static void BFDmanager_findAddressInSection (bfd * abfd, asection * section, PTR data) { #if HAVE_BFD_GET_SECTION_SIZE || HAVE_BFD_GET_SECTION_SIZE_BEFORE_RELOC bfd_size_type size; #endif bfd_vma vma; BFDmanager_symbolInfo_t *symdata = (BFDmanager_symbolInfo_t*) data; if (symdata->found) return; if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0) return; vma = bfd_get_section_vma (abfd, section);; if (symdata->pc < vma) return; #if HAVE_BFD_GET_SECTION_SIZE size = bfd_get_section_size (section); if (symdata->pc >= vma + size) return; #elif HAVE_BFD_GET_SECTION_SIZE_BEFORE_RELOC size = bfd_get_section_size_before_reloc (section); if (symdata->pc >= vma + size) return; #else /* Do nothing? */ #endif symdata->found = bfd_find_nearest_line (abfd, section, symdata->symbols, symdata->pc - vma, &symdata->filename, &symdata->function, &symdata->line); }
/* Read inferior memory at ADDR to find the header of a loaded object file and read its in-core symbols out of inferior memory. TEMPL is a bfd representing the target's format. NAME is the name to use for this symbol file in messages; it can be NULL or a malloc-allocated string which will be attached to the BFD. */ static struct objfile * symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, char *name, int from_tty) { struct objfile *objf; struct bfd *nbfd; struct bfd_section *sec; bfd_vma loadbase; struct section_addr_info *sai; unsigned int i; struct cleanup *cleanup; if (bfd_get_flavour (templ) != bfd_target_elf_flavour) error (_("add-symbol-file-from-memory not supported for this target")); nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, &loadbase, target_read_memory_bfd); if (nbfd == NULL) error (_("Failed to read a valid object file image from memory.")); gdb_bfd_ref (nbfd); if (name == NULL) nbfd->filename = "shared object read from target memory"; else { nbfd->filename = name; gdb_bfd_stash_filename (nbfd); xfree (name); } cleanup = make_cleanup_bfd_unref (nbfd); if (!bfd_check_format (nbfd, bfd_object)) error (_("Got object file from memory but can't read symbols: %s."), bfd_errmsg (bfd_get_error ())); sai = alloc_section_addr_info (bfd_count_sections (nbfd)); make_cleanup (xfree, sai); i = 0; for (sec = nbfd->sections; sec != NULL; sec = sec->next) if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0) { sai->other[i].addr = bfd_get_section_vma (nbfd, sec) + loadbase; sai->other[i].name = (char *) bfd_get_section_name (nbfd, sec); sai->other[i].sectindex = sec->index; ++i; } sai->num_sections = i; objf = symbol_file_add_from_bfd (nbfd, bfd_get_filename (nbfd), from_tty ? SYMFILE_VERBOSE : 0, sai, OBJF_SHARED, NULL); /* This might change our ideas about frames already looked at. */ reinit_frame_cache (); do_cleanups (cleanup); return objf; }
static void process_section(bfd *bfdobj, asection *section, void *obj) { struct bfd_data *data = obj; const char *file, *func; unsigned int line; bfd_vma offset; bfd_vma vma; bfd_size_type size; bfd_boolean line_found = 0; char *fn; int inlined = 0; offset = data->pc - (data->dynamic ? (bfd_vma)(uintptr_t) data->dli.dli_fbase : 0); if (!(bfd_get_section_flags(bfdobj, section) & SEC_ALLOC)) { return; } vma = bfd_get_section_vma(bfdobj, section); size = bfd_get_section_size(section); if (offset < vma || offset >= vma + size) { /* Not in this section */ return; } line_found = bfd_find_nearest_line(bfdobj, section, data->syms, offset - vma, &file, &func, &line); if (!line_found) { return; } /* * If we find a line, we will want to continue calling bfd_find_inliner_info * to capture any inlined functions that don't have their own stack frames. */ do { data->found++; /* file can possibly be null even with a success result from bfd_find_nearest_line */ file = file ? file : ""; fn = strrchr(file, '/'); #define FMT_INLINED "[%s] %s %s:%u %s()" #define FMT_NOT_INLINED "[%p] %s %s:%u %s()" snprintf(data->msg, MSG_BUFF_LEN, inlined ? FMT_INLINED : FMT_NOT_INLINED, inlined ? "inlined" : (char *)(uintptr_t) data->pc, data->libname, fn ? fn + 1 : file, line, S_OR(func, "???")); if (AST_VECTOR_APPEND(data->return_strings, strdup(data->msg))) { return; } inlined++; /* Let's see if there are any inlined functions */ } while (bfd_find_inliner_info(bfdobj, &file, &func, &line)); }
static segT is_now_linkonce_segment (void) { if ((bfd_get_section_flags (stdoutput, now_seg) & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE | SEC_LINK_DUPLICATES_SAME_CONTENTS)) != 0) return now_seg; return NULL; }
static int derive_heap_segment (bfd *abfd, bfd_vma *bottom, bfd_vma *top) { bfd_vma top_of_data_memory = 0; bfd_vma top_of_heap = 0; bfd_size_type sec_size; bfd_vma sec_vaddr; asection *sec; gdb_assert (bottom); gdb_assert (top); /* This function depends on being able to call a function in the inferior. */ if (!target_has_execution) return 0; /* The following code assumes that the link map is arranged as follows (low to high addresses): --------------------------------- | text sections | --------------------------------- | data sections (including bss) | --------------------------------- | heap | --------------------------------- */ for (sec = abfd->sections; sec; sec = sec->next) { if (bfd_get_section_flags (abfd, sec) & SEC_DATA || strcmp (".bss", bfd_section_name (abfd, sec)) == 0) { sec_vaddr = bfd_get_section_vma (abfd, sec); sec_size = bfd_get_section_size (sec); if (sec_vaddr + sec_size > top_of_data_memory) top_of_data_memory = sec_vaddr + sec_size; } } top_of_heap = call_target_sbrk (0); if (top_of_heap == (bfd_vma) 0) return 0; /* Return results. */ if (top_of_heap > top_of_data_memory) { *bottom = top_of_data_memory; *top = top_of_heap; return 1; } /* No additional heap space needs to be saved. */ return 0; }
static enum target_xfer_status record_btrace_xfer_partial (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { struct target_ops *t; /* Filter out requests that don't make sense during replay. */ if (!record_btrace_allow_memory_access && record_btrace_is_replaying (ops)) { switch (object) { case TARGET_OBJECT_MEMORY: { struct target_section *section; /* We do not allow writing memory in general. */ if (writebuf != NULL) { *xfered_len = len; return TARGET_XFER_UNAVAILABLE; } /* We allow reading readonly memory. */ section = target_section_by_addr (ops, offset); if (section != NULL) { /* Check if the section we found is readonly. */ if ((bfd_get_section_flags (section->the_bfd_section->owner, section->the_bfd_section) & SEC_READONLY) != 0) { /* Truncate the request to fit into this section. */ len = min (len, section->endaddr - offset); break; } } *xfered_len = len; return TARGET_XFER_UNAVAILABLE; } } } /* Forward the request. */ for (ops = ops->beneath; ops != NULL; ops = ops->beneath) if (ops->to_xfer_partial != NULL) return ops->to_xfer_partial (ops, object, annex, readbuf, writebuf, offset, len, xfered_len); *xfered_len = len; return TARGET_XFER_UNAVAILABLE; }
/* Read inferior memory at ADDR to find the header of a loaded object file and read its in-core symbols out of inferior memory. TEMPL is a bfd representing the target's format. NAME is the name to use for this symbol file in messages; it can be NULL or a malloc-allocated string which will be attached to the BFD. */ static struct objfile * symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, char *name, int from_tty) { struct objfile *objf; struct bfd *nbfd; struct bfd_section *sec; bfd_vma loadbase; struct section_addr_info *sai; unsigned int i; if (bfd_get_flavour (templ) != bfd_target_elf_flavour) error (_("add-symbol-file-from-memory not supported for this target")); nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, &loadbase, target_read_memory); if (nbfd == NULL) error (_("Failed to read a valid object file image from memory.")); if (name == NULL) nbfd->filename = xstrdup ("shared object read from target memory"); else nbfd->filename = name; if (!bfd_check_format (nbfd, bfd_object)) { /* FIXME: should be checking for errors from bfd_close (for one thing, on error it does not free all the storage associated with the bfd). */ bfd_close (nbfd); error (_("Got object file from memory but can't read symbols: %s."), bfd_errmsg (bfd_get_error ())); } sai = alloc_section_addr_info (bfd_count_sections (nbfd)); make_cleanup (xfree, sai); i = 0; for (sec = nbfd->sections; sec != NULL; sec = sec->next) if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0) { sai->other[i].addr = bfd_get_section_vma (nbfd, sec) + loadbase; sai->other[i].name = (char *) bfd_get_section_name (nbfd, sec); sai->other[i].sectindex = sec->index; ++i; } objf = symbol_file_add_from_bfd (nbfd, from_tty ? SYMFILE_VERBOSE : 0, sai, OBJF_SHARED); /* This might change our ideas about frames already looked at. */ reinit_frame_cache (); return objf; }
static void make_output_phdrs (bfd *obfd, asection *osec, void *ignored) { int p_flags = 0; int p_type; /* FIXME: these constants may only be applicable for ELF. */ if (strncmp (bfd_section_name (obfd, osec), "load", 4) == 0) p_type = PT_LOAD; else p_type = PT_NOTE; p_flags |= PF_R; /* Segment is readable. */ if (!(bfd_get_section_flags (obfd, osec) & SEC_READONLY)) p_flags |= PF_W; /* Segment is writable. */ if (bfd_get_section_flags (obfd, osec) & SEC_CODE) p_flags |= PF_X; /* Segment is executable. */ bfd_record_phdr (obfd, p_type, 1, p_flags, 0, 0, 0, 0, 1, &osec); }
static symbolS * obj_coff_common_parse (int ignore ATTRIBUTE_UNUSED, symbolS *symbolP, addressT size) { addressT align = 0; if (*input_line_pointer == ',') { align = parse_align (0); if (align == (addressT) -1) return NULL; } S_SET_VALUE (symbolP, size); S_SET_EXTERNAL (symbolP); S_SET_SEGMENT (symbolP, bfd_com_section_ptr); symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT; /* There is no S_SET_ALIGN (symbolP, align) in COFF/PE. Instead we must add a note to the .drectve section. */ if (align) { segT current_seg = now_seg; subsegT current_subseg = now_subseg; flagword oldflags; asection *sec; size_t pfxlen, numlen; char *frag; char numbuff[20]; sec = subseg_new (".drectve", 0); oldflags = bfd_get_section_flags (stdoutput, sec); if (oldflags == SEC_NO_FLAGS) { if (!bfd_set_section_flags (stdoutput, sec, TC_COFF_SECTION_DEFAULT_ATTRIBUTES)) as_warn (_("error setting flags for \"%s\": %s"), bfd_section_name (stdoutput, sec), bfd_errmsg (bfd_get_error ())); } /* Emit a string. Note no NUL-termination. */ pfxlen = strlen (" -aligncomm:") + 2 + strlen (S_GET_NAME (symbolP)) + 1; numlen = snprintf (numbuff, sizeof (numbuff), "%d", (int) align); frag = frag_more (pfxlen + numlen); (void) sprintf (frag, " -aligncomm:\"%s\",", S_GET_NAME (symbolP)); memcpy (frag + pfxlen, numbuff, numlen); /* Restore original subseg. */ subseg_set (current_seg, current_subseg); } return symbolP; }
/* Read inferior memory at ADDR to find the header of a loaded object file and read its in-core symbols out of inferior memory. SIZE, if non-zero, is the known size of the object. TEMPL is a bfd representing the target's format. NAME is the name to use for this symbol file in messages; it can be NULL or a malloc-allocated string which will be attached to the BFD. */ static struct objfile * symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, size_t size, char *name, int from_tty) { struct objfile *objf; struct bfd *nbfd; struct bfd_section *sec; bfd_vma loadbase; symfile_add_flags add_flags = 0; if (bfd_get_flavour (templ) != bfd_target_elf_flavour) error (_("add-symbol-file-from-memory not supported for this target")); nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, size, &loadbase, target_read_memory_bfd); if (nbfd == NULL) error (_("Failed to read a valid object file image from memory.")); /* Manage the new reference for the duration of this function. */ gdb_bfd_ref_ptr nbfd_holder = gdb_bfd_ref_ptr::new_reference (nbfd); xfree (bfd_get_filename (nbfd)); if (name == NULL) nbfd->filename = xstrdup ("shared object read from target memory"); else nbfd->filename = name; if (!bfd_check_format (nbfd, bfd_object)) error (_("Got object file from memory but can't read symbols: %s."), bfd_errmsg (bfd_get_error ())); section_addr_info sai; for (sec = nbfd->sections; sec != NULL; sec = sec->next) if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0) sai.emplace_back (bfd_get_section_vma (nbfd, sec) + loadbase, bfd_get_section_name (nbfd, sec), sec->index); if (from_tty) add_flags |= SYMFILE_VERBOSE; objf = symbol_file_add_from_bfd (nbfd, bfd_get_filename (nbfd), add_flags, &sai, OBJF_SHARED, NULL); add_target_sections_of_objfile (objf); /* This might change our ideas about frames already looked at. */ reinit_frame_cache (); return objf; }
enum sh64_elf_cr_type sh64_get_contents_type (asection *sec, bfd_vma addr, sh64_elf_crange *rangep) { asection *cranges; /* Fill in the range with the boundaries of the section as a default. */ if (bfd_get_flavour (sec->owner) == bfd_target_elf_flavour && elf_elfheader (sec->owner)->e_type == ET_EXEC) { rangep->cr_addr = bfd_get_section_vma (sec->owner, sec); rangep->cr_size = sec->size; rangep->cr_type = CRT_NONE; } else return FALSE; /* If none of the pertinent bits are set, then it's a SHcompact (or at least not SHmedia). */ if ((elf_section_data (sec)->this_hdr.sh_flags & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED)) == 0) { enum sh64_elf_cr_type cr_type = ((bfd_get_section_flags (sec->owner, sec) & SEC_CODE) != 0 ? CRT_SH5_ISA16 : CRT_DATA); rangep->cr_type = cr_type; return cr_type; } /* If only the SHF_SH5_ISA32 bit is set, then we have SHmedia. */ if ((elf_section_data (sec)->this_hdr.sh_flags & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED)) == SHF_SH5_ISA32) { rangep->cr_type = CRT_SH5_ISA32; return CRT_SH5_ISA32; } /* Otherwise, we have to look up the .cranges section. */ cranges = bfd_get_section_by_name (sec->owner, SH64_CRANGES_SECTION_NAME); if (cranges == NULL) /* A mixed section but there's no .cranges section. This is probably bad input; it does not comply to specs. */ return CRT_NONE; /* If this call fails, we will still have CRT_NONE in rangep->cr_type and that will be suitable to return. */ sh64_address_in_cranges (cranges, addr, rangep); return rangep->cr_type; }
static void print_objfile_section_info(bfd *abfd, struct obj_section *asect, const char *string) { flagword flags = bfd_get_section_flags(abfd, asect->the_bfd_section); const char *name = bfd_section_name(abfd, asect->the_bfd_section); if ((string == NULL) || (*string == '\0') || match_substring(string, name) || match_bfd_flags(string, flags)) { maint_print_section_info(name, flags, asect->addr, asect->endaddr, (unsigned long)asect->the_bfd_section->filepos); } }
void lookup_section(bfd * abfd, asection * sec, void * opaque_data) { find_info * data = (find_info*)opaque_data; if (data->func) return; if (!(bfd_get_section_flags(abfd, sec) & SEC_ALLOC)) return; bfd_vma vma = bfd_get_section_vma(abfd, sec); if (data->counter < vma || vma + bfd_get_section_size(sec) <= data->counter) return; bfd_find_nearest_line(abfd, sec, data->symbol, data->counter - vma, &(data->file), &(data->func), &(data->line)); }
void traceback::Bfd::Context::lookup_section(bfd* abfd, asection* sec, void* opaque_data) { Bfd::Info* data = static_cast<Bfd::Info*>(opaque_data); if (data->func) return; if (!(bfd_get_section_flags(abfd, sec) & SEC_ALLOC)) return; bfd_vma vma = bfd_get_section_vma(abfd, sec); if (data->counter < vma || vma + bfd_get_section_size(sec) <= data->counter) return; data->displacement = data->counter - vma; bfd_find_nearest_line(abfd, sec, data->symbol, data->displacement, &(data->file), &(data->func), &(data->line)); }
static void add_to_section_table (bfd *abfd, struct bfd_section *asect, void *table_pp_char) { struct section_table **table_pp = (struct section_table **) table_pp_char; flagword aflag; aflag = bfd_get_section_flags (abfd, asect); if (!(aflag & SEC_ALLOC)) return; if (0 == bfd_section_size (abfd, asect)) return; (*table_pp)->bfd = abfd; (*table_pp)->the_bfd_section = asect; (*table_pp)->addr = bfd_section_vma (abfd, asect); (*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect); (*table_pp)++; }
static void print_bfd_section_info(bfd *abfd, asection *asect, void *arg) { flagword flags = bfd_get_section_flags(abfd, asect); const char *name = bfd_section_name(abfd, asect); if ((arg == NULL) || (*((char *)arg) == '\0') || match_substring((char *)arg, name) || match_bfd_flags((char *)arg, flags)) { CORE_ADDR addr, endaddr; addr = bfd_section_vma(abfd, asect); endaddr = (addr + bfd_section_size(abfd, asect)); maint_print_section_info(name, flags, addr, endaddr, (unsigned long)asect->filepos); } }
void deprecated_hpux_text_end (struct target_ops *exec_ops) { struct section_table *p; /* Set text_end to the highest address of the end of any readonly code section. */ /* FIXME: The comment above does not match the code. The code checks for sections with are either code *or* readonly. */ text_end = (CORE_ADDR) 0; for (p = exec_ops->to_sections; p < exec_ops->to_sections_end; p++) if (bfd_get_section_flags (p->bfd, p->the_bfd_section) & (SEC_CODE | SEC_READONLY)) { if (text_end < p->endaddr) text_end = p->endaddr; } }
static void add_to_section_table (struct bfd *abfd, struct bfd_section *asect, void *closure) { struct section_closure *pp = closure; flagword aflag; /* NOTE: cagney/2003-10-22: Is this pruning useful? */ aflag = bfd_get_section_flags (abfd, asect); if (!(aflag & SEC_ALLOC)) return; if (bfd_section_size (abfd, asect) == 0) return; pp->end->bfd = abfd; pp->end->the_bfd_section = asect; pp->end->addr = bfd_section_vma (abfd, asect); pp->end->endaddr = pp->end->addr + bfd_section_size (abfd, asect); pp->end++; }
static void som_relocate_section_addresses (struct so_list *so, struct target_section *sec) { flagword aflag = bfd_get_section_flags(so->abfd, sec->the_bfd_section); if (aflag & SEC_CODE) { sec->addr += so->lm_info->text_addr - so->lm_info->text_link_addr; sec->endaddr += so->lm_info->text_addr - so->lm_info->text_link_addr; } else if (aflag & SEC_DATA) { sec->addr += so->lm_info->data_start; sec->endaddr += so->lm_info->data_start; } else ; }
/** * Lookup callback. */ static void bfd_util_lookup_section(bfd *b, asection *sec, void *data) { struct symbol_ctx *sc = data; bfd_vma vma; if (sc->location.function != NULL) return; /* Already found */ if (0 == (bfd_get_section_flags(b, sec) & SEC_ALLOC)) return; vma = bfd_get_section_vma(b, sec); if (sc->addr < vma || sc->addr >= bfd_get_section_size(sec) + vma) return; bfd_find_nearest_line(b, sec, sc->symbols, sc->addr - vma, &sc->location.file, &sc->location.function, &sc->location.line); }
/// Examines the bfd in order to find the sections containing data to be loaded. /// Also fills the program_data array. void trap::ExecLoader::load_program_data() { bfd_section* p = NULL; std::map<unsigned long, unsigned char> mem_map; for (p = this->exec_image->sections; p != NULL; p = p->next) { flagword flags = bfd_get_section_flags(this->exec_image, p); if ((flags & SEC_ALLOC) != 0 && (flags & SEC_DEBUGGING) == 0 && (flags & SEC_THREAD_LOCAL) == 0) { //Ok, this is a section which must be in the final executable; //Lets see if it has content: if not I have to pad the section with zeros, //otherwise I load it bfd_size_type datasize = bfd_section_size(this->exec_image, p); bfd_vma vma = bfd_get_section_vma(this->exec_image, p); std::map<unsigned long, unsigned char>::iterator mem_it = mem_map.begin(); if ((flags & SEC_HAS_CONTENTS) != 0) { /*#ifndef NDEBUG std::cerr << "Loading data fom section " << p->name << " Start Address " << std::showbase << std::hex << vma << " Size " << std::hex << datasize << " End Address " << std::hex << datasize + vma << std::dec << " Swap Endianess " << swap_endianess << " flags " << std::hex << std::showbase << flags << std::dec << std::endl; #endif*/ bfd_byte* data = new bfd_byte[datasize]; bfd_get_section_contents (this->exec_image, p, data, 0, datasize); for (unsigned i = 0; i < datasize; i++) { mem_it = mem_map.insert(mem_it, std::pair<unsigned long, unsigned char>(vma + i, data[i])); } delete [] data; } else { /*#ifndef NDEBUG std::cerr << "Filling with 0s section " << p->name << " Start Address " << std::showbase << std::hex << vma << " Size " << std::hex << datasize << " End Address " << std::hex << datasize + vma << std::dec << std::endl; #endif*/ for (unsigned i = 0; i < datasize; i++) mem_it = mem_map.insert(mem_it, std::pair<unsigned long, unsigned char>(vma + i, 0)); } } } //ok, I now have all the map of the memory; I simply have to fill in the //this->program_data array this->data_start = mem_map.begin()->first; this->program_dim = mem_map.rbegin()->first - this->data_start + 1; this->program_data = new unsigned char[this->program_dim]; std::map<unsigned long, unsigned char>::iterator mem_it, mem_end; for (mem_it = mem_map.begin(), mem_end = mem_map.end(); mem_it != mem_end; mem_it++) { this->program_data[mem_it->first - this->data_start] = mem_it->second; } } // ExecLoader::load_program_data()
static void find_address_in_section(bfd *abfd, asection *section, void *data) { addr2line_data *adata = reinterpret_cast<addr2line_data*>(data); bfd_vma vma; bfd_size_type size; if (adata->found) { return; } if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0) { return; } vma = bfd_get_section_vma(abfd, section); if (adata->pc < vma) { return; } size = bfd_get_section_size(section); if (adata->pc >= vma + size) { return; } // libdwarf allocates its own unaligned memory so it doesn't play well with // valgrind #ifndef VALGRIND adata->found = bfd_find_nearest_line(abfd, section, adata->syms, adata->pc - vma, &adata->filename, &adata->functionname, &adata->line); #endif if (adata->found) { const char *file = adata->filename; unsigned int line = adata->line; bfd_boolean found = TRUE; while (found) { found = bfd_find_inliner_info(abfd, &file, &adata->functionname, &line); } } }