Lines Matching refs:tgt

133 tgt_scn_init(dis_tgt_t *tgt, dis_scn_t *scn, void *data)
139 tgt->dt_shnmap[*index].dm_name = scn->ds_name;
140 tgt->dt_shnmap[*index].dm_start = scn->ds_shdr.sh_addr;
141 tgt->dt_shnmap[*index].dm_length = scn->ds_shdr.sh_size;
142 tgt->dt_shnmap[*index].dm_mapped = B_FALSE;
147 if (scn->ds_shdr.sh_type == SHT_DYNSYM && tgt->dt_symidx == 0)
148 tgt->dt_symidx = *index;
150 tgt->dt_symidx = *index;
237 construct_symtab(dis_tgt_t *tgt)
252 for (scn = elf_nextscn(tgt->dt_elf, NULL); scn != NULL;
253 scn = elf_nextscn(tgt->dt_elf, scn)) {
257 shdr.sh_link == tgt->dt_symidx) {
269 if ((scn = elf_getscn(tgt->dt_elf, tgt->dt_symidx)) == NULL)
270 die("%s: failed to get section information", tgt->dt_filename);
272 die("%s: failed to get section header", tgt->dt_filename);
274 die("%s: symbol table has zero size", tgt->dt_filename);
277 die("%s: failed to get symbol table", tgt->dt_filename);
279 tgt->dt_symcount = symdata->d_size / gelf_fsize(tgt->dt_elf, ELF_T_SYM,
282 p_symtab = safe_malloc(tgt->dt_symcount * sizeof (sym_entry_t));
284 for (i = 0, sym = p_symtab; i < tgt->dt_symcount; i++) {
287 tgt->dt_filename, i);
303 tgt->dt_filename, i);
353 if ((sym->se_name = elf_strptr(tgt->dt_elf, shdr.sh_link,
356 tgt->dt_filename, i);
365 if (tgt->dt_shnmap[sym->se_shndx].dm_mapped)
367 tgt->dt_shnmap[sym->se_shndx].dm_start;
372 tgt->dt_symcount -= nsym;
373 tgt->dt_symtab = realloc(p_symtab, tgt->dt_symcount *
376 qsort(tgt->dt_symtab, tgt->dt_symcount, sizeof (sym_entry_t),
384 create_addrmap(dis_tgt_t *tgt)
389 if (tgt->dt_shnmap == NULL)
393 for (addr = 0, i = 1; i < tgt->dt_shncount; i++)
394 if (tgt->dt_shnmap[i].dm_start > addr)
395 addr = tgt->dt_shnmap[i].dm_start +
396 tgt->dt_shnmap[i].dm_length;
404 for (i = 1; i < tgt->dt_shncount; i++) {
405 if (tgt->dt_shnmap[i].dm_start != 0)
408 tgt->dt_shnmap[i].dm_start = addr;
409 tgt->dt_shnmap[i].dm_mapped = B_TRUE;
410 addr = P2ROUNDUP(addr + tgt->dt_shnmap[i].dm_length, 0x1000);
420 dis_tgt_t *tgt, *current;
430 tgt = safe_malloc(sizeof (dis_tgt_t));
432 if ((tgt->dt_fd = open(file, O_RDONLY)) < 0) {
435 free(tgt);
439 if ((tgt->dt_elf_root =
440 elf_begin(tgt->dt_fd, ELF_C_READ, NULL)) == NULL) {
442 dis_tgt_destroy(tgt);
446 current = tgt;
448 while ((elf = elf_begin(tgt->dt_fd, cmd, tgt->dt_elf_root)) != NULL) {
451 if (elf_kind(tgt->dt_elf_root) == ELF_K_AR &&
454 dis_tgt_destroy(tgt);
478 dis_tgt_destroy(tgt);
490 next->dt_elf_root = tgt->dt_elf_root;
501 dis_tgt_destroy(tgt);
508 dis_tgt_destroy(tgt);
531 if (tgt->dt_elf == NULL) {
533 dis_tgt_destroy(tgt);
537 return (tgt);
544 dis_tgt_name(dis_tgt_t *tgt)
546 return (tgt->dt_filename);
553 dis_tgt_member(dis_tgt_t *tgt)
555 if (tgt->dt_arhdr)
556 return (tgt->dt_arhdr->ar_name);
566 dis_tgt_ehdr(dis_tgt_t *tgt, GElf_Ehdr *ehdr)
568 (void) gelf_getehdr(tgt->dt_elf, ehdr);
575 dis_tgt_next(dis_tgt_t *tgt)
577 return (tgt->dt_next);
584 dis_tgt_destroy(dis_tgt_t *tgt)
588 current = tgt->dt_next;
599 if (tgt->dt_elf)
600 (void) elf_end(tgt->dt_elf);
601 if (tgt->dt_elf_root)
602 (void) elf_end(tgt->dt_elf_root);
604 if (tgt->dt_symtab)
605 free(tgt->dt_symtab);
607 free(tgt);
615 dis_find_section(dis_tgt_t *tgt, uint64_t addr, off_t *offset)
619 for (i = 1; i < tgt->dt_shncount; i++) {
620 if ((addr >= tgt->dt_shnmap[i].dm_start) &&
621 (addr < tgt->dt_shnmap[i].dm_start +
622 tgt->dt_shnmap[i].dm_length)) {
623 *offset = addr - tgt->dt_shnmap[i].dm_start;
624 return (tgt->dt_shnmap[i].dm_name);
643 dis_tgt_lookup(dis_tgt_t *tgt, uint64_t addr, off_t *offset, int cache_result,
655 if (tgt->dt_symcache != NULL &&
656 addr >= tgt->dt_symcache->se_sym.st_value &&
657 addr < tgt->dt_symcache->se_sym.st_value +
658 tgt->dt_symcache->se_sym.st_size) {
659 sym = tgt->dt_symcache;
669 hi = (tgt->dt_symcount - 1);
675 sym = &tgt->dt_symtab[mid];
710 if (osym == tgt->dt_symtab)
719 tgt->dt_symcache = sym;
734 dis_tgt_next_symbol(dis_tgt_t *tgt, uint64_t addr)
738 sym = (tgt->dt_symcache != NULL) ? tgt->dt_symcache : tgt->dt_symtab;
740 while (sym != (tgt->dt_symtab + tgt->dt_symcount)) {
754 dis_tgt_section_iter(dis_tgt_t *tgt, section_iter_f func, void *data)
760 for (scn = elf_nextscn(tgt->dt_elf, NULL), idx = 1; scn != NULL;
761 scn = elf_nextscn(tgt->dt_elf, scn), idx++) {
765 tgt->dt_filename, idx);
769 if ((sdata.ds_name = elf_strptr(tgt->dt_elf, tgt->dt_shstrndx,
772 tgt->dt_filename, idx);
778 tgt->dt_filename, sdata.ds_name);
789 sdata.ds_shdr.sh_addr = tgt->dt_shnmap[idx].dm_start;
791 func(tgt, &sdata, data);
869 dis_tgt_function_iter(dis_tgt_t *tgt, function_iter_f func, void *data)
877 for (i = 0, sym = tgt->dt_symtab; i < tgt->dt_symcount; i++, sym++) {
887 if ((scn = elf_getscn(tgt->dt_elf, sym->se_shndx)) == NULL ||
892 tgt->dt_filename, sym->se_shndx);
896 if (tgt->dt_shnmap[sym->se_shndx].dm_mapped)
897 shdr.sh_addr = tgt->dt_shnmap[sym->se_shndx].dm_start;
907 tgt->dt_filename, sym->se_sym.st_shndx,
915 func(tgt, &df, data);