1 /*
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include <jni.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <stddef.h>
31 #include <elf.h>
32 #include <link.h>
33 #include "libproc_impl.h"
34 #include "salibelf.h"
35 #include "cds.h"
36
37 // This file has the libproc implementation to read core files.
38 // For live processes, refer to ps_proc.c. Portions of this is adapted
39 // /modelled after Solaris libproc.so (in particular Pcore.c)
40
41 //----------------------------------------------------------------------
42 // ps_prochandle cleanup helper functions
43
44 // close all file descriptors
45 static void close_files(struct ps_prochandle* ph) {
46 lib_info* lib = NULL;
47
48 // close core file descriptor
49 if (ph->core->core_fd >= 0)
50 close(ph->core->core_fd);
51
52 // close exec file descriptor
53 if (ph->core->exec_fd >= 0)
493 }
494 thr = thr->next;
495 }
496 return false;
497 }
498
499 static ps_prochandle_ops core_ops = {
500 .release= core_release,
501 .p_pread= core_read_data,
502 .p_pwrite= core_write_data,
503 .get_lwp_regs= core_get_lwp_regs
504 };
505
506 // read regs and create thread from NT_PRSTATUS entries from core file
507 static bool core_handle_prstatus(struct ps_prochandle* ph, const char* buf, size_t nbytes) {
508 // we have to read prstatus_t from buf
509 // assert(nbytes == sizeof(prstaus_t), "size mismatch on prstatus_t");
510 prstatus_t* prstat = (prstatus_t*) buf;
511 thread_info* newthr;
512 print_debug("got integer regset for lwp %d\n", prstat->pr_pid);
513 // we set pthread_t to -1 for core dump
514 if((newthr = add_thread_info(ph, (pthread_t) -1, prstat->pr_pid)) == NULL)
515 return false;
516
517 // copy regs
518 memcpy(&newthr->regs, prstat->pr_reg, sizeof(struct user_regs_struct));
519
520 if (is_debug()) {
521 print_debug("integer regset\n");
522 #ifdef i386
523 // print the regset
524 print_debug("\teax = 0x%x\n", newthr->regs.eax);
525 print_debug("\tebx = 0x%x\n", newthr->regs.ebx);
526 print_debug("\tecx = 0x%x\n", newthr->regs.ecx);
527 print_debug("\tedx = 0x%x\n", newthr->regs.edx);
528 print_debug("\tesp = 0x%x\n", newthr->regs.esp);
529 print_debug("\tebp = 0x%x\n", newthr->regs.ebp);
530 print_debug("\tesi = 0x%x\n", newthr->regs.esi);
531 print_debug("\tedi = 0x%x\n", newthr->regs.edi);
532 print_debug("\teip = 0x%x\n", newthr->regs.eip);
533 #endif
534
|
1 /*
2 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include <jni.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <stddef.h>
31 #include <elf.h>
32 #include <link.h>
33 #include "libproc_impl.h"
34 #include "proc_service.h"
35 #include "salibelf.h"
36 #include "cds.h"
37
38 // This file has the libproc implementation to read core files.
39 // For live processes, refer to ps_proc.c. Portions of this is adapted
40 // /modelled after Solaris libproc.so (in particular Pcore.c)
41
42 //----------------------------------------------------------------------
43 // ps_prochandle cleanup helper functions
44
45 // close all file descriptors
46 static void close_files(struct ps_prochandle* ph) {
47 lib_info* lib = NULL;
48
49 // close core file descriptor
50 if (ph->core->core_fd >= 0)
51 close(ph->core->core_fd);
52
53 // close exec file descriptor
54 if (ph->core->exec_fd >= 0)
494 }
495 thr = thr->next;
496 }
497 return false;
498 }
499
500 static ps_prochandle_ops core_ops = {
501 .release= core_release,
502 .p_pread= core_read_data,
503 .p_pwrite= core_write_data,
504 .get_lwp_regs= core_get_lwp_regs
505 };
506
507 // read regs and create thread from NT_PRSTATUS entries from core file
508 static bool core_handle_prstatus(struct ps_prochandle* ph, const char* buf, size_t nbytes) {
509 // we have to read prstatus_t from buf
510 // assert(nbytes == sizeof(prstaus_t), "size mismatch on prstatus_t");
511 prstatus_t* prstat = (prstatus_t*) buf;
512 thread_info* newthr;
513 print_debug("got integer regset for lwp %d\n", prstat->pr_pid);
514 if((newthr = add_thread_info(ph, prstat->pr_pid)) == NULL)
515 return false;
516
517 // copy regs
518 memcpy(&newthr->regs, prstat->pr_reg, sizeof(struct user_regs_struct));
519
520 if (is_debug()) {
521 print_debug("integer regset\n");
522 #ifdef i386
523 // print the regset
524 print_debug("\teax = 0x%x\n", newthr->regs.eax);
525 print_debug("\tebx = 0x%x\n", newthr->regs.ebx);
526 print_debug("\tecx = 0x%x\n", newthr->regs.ecx);
527 print_debug("\tedx = 0x%x\n", newthr->regs.edx);
528 print_debug("\tesp = 0x%x\n", newthr->regs.esp);
529 print_debug("\tebp = 0x%x\n", newthr->regs.ebp);
530 print_debug("\tesi = 0x%x\n", newthr->regs.esi);
531 print_debug("\tedi = 0x%x\n", newthr->regs.edi);
532 print_debug("\teip = 0x%x\n", newthr->regs.eip);
533 #endif
534
|