agent/src/os/linux/ps_core.c

changeset 8719
f89cf87d867d
parent 5961
1bee3014cf2a
child 8856
ac27a9c85bea
child 9714
e49125a0c77c
equal deleted inserted replaced
8717:77d9c9da7188 8719:f89cf87d867d
640 640
641 if (notep->n_type == NT_PRSTATUS) { 641 if (notep->n_type == NT_PRSTATUS) {
642 if (core_handle_prstatus(ph, descdata, notep->n_descsz) != true) { 642 if (core_handle_prstatus(ph, descdata, notep->n_descsz) != true) {
643 return false; 643 return false;
644 } 644 }
645 } else if (notep->n_type == NT_AUXV) {
646 // Get first segment from entry point
647 ELF_AUXV *auxv = (ELF_AUXV *)descdata;
648 while (auxv->a_type != AT_NULL) {
649 if (auxv->a_type == AT_ENTRY) {
650 // Set entry point address to address of dynamic section.
651 // We will adjust it in read_exec_segments().
652 ph->core->dynamic_addr = auxv->a_un.a_val;
653 break;
654 }
655 auxv++;
656 }
645 } 657 }
646 p = descdata + ROUNDUP(notep->n_descsz, 4); 658 p = descdata + ROUNDUP(notep->n_descsz, 4);
647 } 659 }
648 660
649 free(buf); 661 free(buf);
824 break; 836 break;
825 } 837 }
826 838
827 // from PT_DYNAMIC we want to read address of first link_map addr 839 // from PT_DYNAMIC we want to read address of first link_map addr
828 case PT_DYNAMIC: { 840 case PT_DYNAMIC: {
829 ph->core->dynamic_addr = exec_php->p_vaddr; 841 if (exec_ehdr->e_type == ET_EXEC) {
842 ph->core->dynamic_addr = exec_php->p_vaddr;
843 } else { // ET_DYN
844 // dynamic_addr has entry point of executable.
845 // Thus we should substract it.
846 ph->core->dynamic_addr += exec_php->p_vaddr - exec_ehdr->e_entry;
847 }
830 print_debug("address of _DYNAMIC is 0x%lx\n", ph->core->dynamic_addr); 848 print_debug("address of _DYNAMIC is 0x%lx\n", ph->core->dynamic_addr);
831 break; 849 break;
832 } 850 }
833 851
834 } // switch 852 } // switch
1022 if ((ph->core->exec_fd = open(exec_file, O_RDONLY)) < 0) { 1040 if ((ph->core->exec_fd = open(exec_file, O_RDONLY)) < 0) {
1023 print_debug("can't open executable file\n"); 1041 print_debug("can't open executable file\n");
1024 goto err; 1042 goto err;
1025 } 1043 }
1026 1044
1027 if (read_elf_header(ph->core->exec_fd, &exec_ehdr) != true || exec_ehdr.e_type != ET_EXEC) { 1045 if (read_elf_header(ph->core->exec_fd, &exec_ehdr) != true ||
1028 print_debug("executable file is not a valid ELF ET_EXEC file\n"); 1046 ((exec_ehdr.e_type != ET_EXEC) && (exec_ehdr.e_type != ET_DYN))) {
1047 print_debug("executable file is not a valid ELF file\n");
1029 goto err; 1048 goto err;
1030 } 1049 }
1031 1050
1032 // process core file segments 1051 // process core file segments
1033 if (read_core_segments(ph, &core_ehdr) != true) { 1052 if (read_core_segments(ph, &core_ehdr) != true) {

mercurial