Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions hotspot/agent/src/os/linux/ps_core.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -802,13 +802,15 @@ static bool read_interp_segments(struct ps_prochandle* ph) {
}

// process segments of a a.out
static bool read_exec_segments(struct ps_prochandle* ph, ELF_EHDR* exec_ehdr) {
// returns base address of executable.
static uintptr_t read_exec_segments(struct ps_prochandle* ph, ELF_EHDR* exec_ehdr) {
int i = 0;
ELF_PHDR* phbuf = NULL;
ELF_PHDR* exec_php = NULL;
uintptr_t result = 0L;

if ((phbuf = read_program_header_table(ph->core->exec_fd, exec_ehdr)) == NULL)
return false;
return 0L;

for (exec_php = phbuf, i = 0; i < exec_ehdr->e_phnum; i++) {
switch (exec_php->p_type) {
Expand Down Expand Up @@ -839,10 +841,10 @@ static bool read_exec_segments(struct ps_prochandle* ph, ELF_EHDR* exec_ehdr) {
// from PT_DYNAMIC we want to read address of first link_map addr
case PT_DYNAMIC: {
if (exec_ehdr->e_type == ET_EXEC) {
result = exec_php->p_vaddr;
ph->core->dynamic_addr = exec_php->p_vaddr;
} else { // ET_DYN
// dynamic_addr has entry point of executable.
// Thus we should substract it.
result = ph->core->dynamic_addr - exec_ehdr->e_entry;
ph->core->dynamic_addr += exec_php->p_vaddr - exec_ehdr->e_entry;
}
print_debug("address of _DYNAMIC is 0x%lx\n", ph->core->dynamic_addr);
Expand All @@ -854,10 +856,10 @@ static bool read_exec_segments(struct ps_prochandle* ph, ELF_EHDR* exec_ehdr) {
} // for

free(phbuf);
return true;
return result;
err:
free(phbuf);
return false;
return 0L;
}


Expand Down Expand Up @@ -1108,13 +1110,12 @@ struct ps_prochandle* Pgrab_core(const char* exec_file, const char* core_file) {
}

// process exec file segments
if (read_exec_segments(ph, &exec_ehdr) != true) {
uintptr_t exec_base_addr = read_exec_segments(ph, &exec_ehdr);
if (exec_base_addr == 0L) {
goto err;
}

// exec file is also treated like a shared object for symbol search
if (add_lib_info_fd(ph, exec_file, ph->core->exec_fd,
(uintptr_t)0 + find_base_address(ph->core->exec_fd, &exec_ehdr)) == NULL) {
print_debug("exec_base_addr = 0x%lx\n", exec_base_addr);
if (add_lib_info_fd(ph, exec_file, ph->core->exec_fd, exec_base_addr) == NULL) {
goto err;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, Red Hat Inc.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -68,7 +68,7 @@ public LoadObject loadObjectContainingPC(Address pc) throws DebuggerException {
LoadObject ob = (LoadObject) objs.get(i);
Address base = ob.getBase();
long size = ob.getSize();
if ( pc.greaterThanOrEqual(base) && pc.lessThan(base.addOffsetTo(size))) {
if (pc.greaterThanOrEqual(base) && pc.lessThan(base.addOffsetTo(size))) {
return ob;
}
}
Expand Down