diff --git a/hotspot/agent/src/os/linux/ps_core.c b/hotspot/agent/src/os/linux/ps_core.c index b7fe4c095d1..6fb8c940445 100644 --- a/hotspot/agent/src/os/linux/ps_core.c +++ b/hotspot/agent/src/os/linux/ps_core.c @@ -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 @@ -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) { @@ -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); @@ -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; } @@ -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; } diff --git a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxCDebugger.java b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxCDebugger.java index 3bf324506bd..f178d6a6e7f 100644 --- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxCDebugger.java +++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxCDebugger.java @@ -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. * @@ -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; } }