< prev index next >

src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2016, 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  *


 962   return (bottom + size);
 963 }
 964 
 965 size_t os::current_stack_size() {
 966   // stack size includes normal stack and HotSpot guard pages
 967   address bottom;
 968   size_t size;
 969   current_stack_region(&bottom, &size);
 970   return size;
 971 }
 972 
 973 /////////////////////////////////////////////////////////////////////////////
 974 // helper functions for fatal error handler
 975 
 976 void os::print_context(outputStream *st, const void *context) {
 977   if (context == NULL) return;
 978 
 979   const ucontext_t *uc = (const ucontext_t*)context;
 980   st->print_cr("Registers:");
 981 #ifdef AMD64
 982   st->print(  "RAX=" INTPTR_FORMAT, uc->context_rax);
 983   st->print(", RBX=" INTPTR_FORMAT, uc->context_rbx);
 984   st->print(", RCX=" INTPTR_FORMAT, uc->context_rcx);
 985   st->print(", RDX=" INTPTR_FORMAT, uc->context_rdx);
 986   st->cr();
 987   st->print(  "RSP=" INTPTR_FORMAT, uc->context_rsp);
 988   st->print(", RBP=" INTPTR_FORMAT, uc->context_rbp);
 989   st->print(", RSI=" INTPTR_FORMAT, uc->context_rsi);
 990   st->print(", RDI=" INTPTR_FORMAT, uc->context_rdi);
 991   st->cr();
 992   st->print(  "R8 =" INTPTR_FORMAT, uc->context_r8);
 993   st->print(", R9 =" INTPTR_FORMAT, uc->context_r9);
 994   st->print(", R10=" INTPTR_FORMAT, uc->context_r10);
 995   st->print(", R11=" INTPTR_FORMAT, uc->context_r11);
 996   st->cr();
 997   st->print(  "R12=" INTPTR_FORMAT, uc->context_r12);
 998   st->print(", R13=" INTPTR_FORMAT, uc->context_r13);
 999   st->print(", R14=" INTPTR_FORMAT, uc->context_r14);
1000   st->print(", R15=" INTPTR_FORMAT, uc->context_r15);
1001   st->cr();
1002   st->print(  "RIP=" INTPTR_FORMAT, uc->context_rip);
1003   st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_flags);
1004   st->print(", ERR=" INTPTR_FORMAT, uc->context_err);
1005   st->cr();
1006   st->print("  TRAPNO=" INTPTR_FORMAT, uc->context_trapno);
1007 #else
1008   st->print(  "EAX=" INTPTR_FORMAT, uc->context_eax);
1009   st->print(", EBX=" INTPTR_FORMAT, uc->context_ebx);
1010   st->print(", ECX=" INTPTR_FORMAT, uc->context_ecx);
1011   st->print(", EDX=" INTPTR_FORMAT, uc->context_edx);
1012   st->cr();
1013   st->print(  "ESP=" INTPTR_FORMAT, uc->context_esp);
1014   st->print(", EBP=" INTPTR_FORMAT, uc->context_ebp);
1015   st->print(", ESI=" INTPTR_FORMAT, uc->context_esi);
1016   st->print(", EDI=" INTPTR_FORMAT, uc->context_edi);
1017   st->cr();
1018   st->print(  "EIP=" INTPTR_FORMAT, uc->context_eip);
1019   st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_eflags);
1020 #endif // AMD64
1021   st->cr();
1022   st->cr();
1023 
1024   intptr_t *sp = (intptr_t *)os::Bsd::ucontext_get_sp(uc);
1025   st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
1026   print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
1027   st->cr();
1028 
1029   // Note: it may be unsafe to inspect memory near pc. For example, pc may
1030   // point to garbage if entry point in an nmethod is corrupted. Leave
1031   // this at the end, and hope for the best.
1032   address pc = os::Bsd::ucontext_get_pc(uc);
1033   st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
1034   print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
1035 }
1036 
1037 void os::print_register_info(outputStream *st, const void *context) {
1038   if (context == NULL) return;
1039 
1040   const ucontext_t *uc = (const ucontext_t*)context;
1041 
1042   st->print_cr("Register to memory mapping:");
1043   st->cr();
1044 
1045   // this is horrendously verbose but the layout of the registers in the
1046   // context does not match how we defined our abstract Register set, so
1047   // we can't just iterate through the gregs area
1048 
1049   // this is only for the "general purpose" registers
1050 
1051 #ifdef AMD64
1052   st->print("RAX="); print_location(st, uc->context_rax);
1053   st->print("RBX="); print_location(st, uc->context_rbx);


   1 /*
   2  * Copyright (c) 1999, 2017, 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  *


 962   return (bottom + size);
 963 }
 964 
 965 size_t os::current_stack_size() {
 966   // stack size includes normal stack and HotSpot guard pages
 967   address bottom;
 968   size_t size;
 969   current_stack_region(&bottom, &size);
 970   return size;
 971 }
 972 
 973 /////////////////////////////////////////////////////////////////////////////
 974 // helper functions for fatal error handler
 975 
 976 void os::print_context(outputStream *st, const void *context) {
 977   if (context == NULL) return;
 978 
 979   const ucontext_t *uc = (const ucontext_t*)context;
 980   st->print_cr("Registers:");
 981 #ifdef AMD64
 982   st->print(  "RAX=" INTPTR_FORMAT, (intptr_t)uc->context_rax);
 983   st->print(", RBX=" INTPTR_FORMAT, (intptr_t)uc->context_rbx);
 984   st->print(", RCX=" INTPTR_FORMAT, (intptr_t)uc->context_rcx);
 985   st->print(", RDX=" INTPTR_FORMAT, (intptr_t)uc->context_rdx);
 986   st->cr();
 987   st->print(  "RSP=" INTPTR_FORMAT, (intptr_t)uc->context_rsp);
 988   st->print(", RBP=" INTPTR_FORMAT, (intptr_t)uc->context_rbp);
 989   st->print(", RSI=" INTPTR_FORMAT, (intptr_t)uc->context_rsi);
 990   st->print(", RDI=" INTPTR_FORMAT, (intptr_t)uc->context_rdi);
 991   st->cr();
 992   st->print(  "R8 =" INTPTR_FORMAT, (intptr_t)uc->context_r8);
 993   st->print(", R9 =" INTPTR_FORMAT, (intptr_t)uc->context_r9);
 994   st->print(", R10=" INTPTR_FORMAT, (intptr_t)uc->context_r10);
 995   st->print(", R11=" INTPTR_FORMAT, (intptr_t)uc->context_r11);
 996   st->cr();
 997   st->print(  "R12=" INTPTR_FORMAT, (intptr_t)uc->context_r12);
 998   st->print(", R13=" INTPTR_FORMAT, (intptr_t)uc->context_r13);
 999   st->print(", R14=" INTPTR_FORMAT, (intptr_t)uc->context_r14);
1000   st->print(", R15=" INTPTR_FORMAT, (intptr_t)uc->context_r15);
1001   st->cr();
1002   st->print(  "RIP=" INTPTR_FORMAT, (intptr_t)uc->context_rip);
1003   st->print(", EFLAGS=" INTPTR_FORMAT, (intptr_t)uc->context_flags);
1004   st->print(", ERR=" INTPTR_FORMAT, (intptr_t)uc->context_err);
1005   st->cr();
1006   st->print("  TRAPNO=" INTPTR_FORMAT, (intptr_t)uc->context_trapno);
1007 #else
1008   st->print(  "EAX=" INTPTR_FORMAT, (intptr_t)uc->context_eax);
1009   st->print(", EBX=" INTPTR_FORMAT, (intptr_t)uc->context_ebx);
1010   st->print(", ECX=" INTPTR_FORMAT, (intptr_t)uc->context_ecx);
1011   st->print(", EDX=" INTPTR_FORMAT, (intptr_t)uc->context_edx);
1012   st->cr();
1013   st->print(  "ESP=" INTPTR_FORMAT, (intptr_t)uc->context_esp);
1014   st->print(", EBP=" INTPTR_FORMAT, (intptr_t)uc->context_ebp);
1015   st->print(", ESI=" INTPTR_FORMAT, (intptr_t)uc->context_esi);
1016   st->print(", EDI=" INTPTR_FORMAT, (intptr_t)uc->context_edi);
1017   st->cr();
1018   st->print(  "EIP=" INTPTR_FORMAT, (intptr_t)uc->context_eip);
1019   st->print(", EFLAGS=" INTPTR_FORMAT, (intptr_t)uc->context_eflags);
1020 #endif // AMD64
1021   st->cr();
1022   st->cr();
1023 
1024   intptr_t *sp = (intptr_t *)os::Bsd::ucontext_get_sp(uc);
1025   st->print_cr("Top of Stack: (sp=" INTPTR_FORMAT ")", (intptr_t)sp);
1026   print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
1027   st->cr();
1028 
1029   // Note: it may be unsafe to inspect memory near pc. For example, pc may
1030   // point to garbage if entry point in an nmethod is corrupted. Leave
1031   // this at the end, and hope for the best.
1032   address pc = os::Bsd::ucontext_get_pc(uc);
1033   st->print_cr("Instructions: (pc=" INTPTR_FORMAT ")", (intptr_t)pc);
1034   print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
1035 }
1036 
1037 void os::print_register_info(outputStream *st, const void *context) {
1038   if (context == NULL) return;
1039 
1040   const ucontext_t *uc = (const ucontext_t*)context;
1041 
1042   st->print_cr("Register to memory mapping:");
1043   st->cr();
1044 
1045   // this is horrendously verbose but the layout of the registers in the
1046   // context does not match how we defined our abstract Register set, so
1047   // we can't just iterate through the gregs area
1048 
1049   // this is only for the "general purpose" registers
1050 
1051 #ifdef AMD64
1052   st->print("RAX="); print_location(st, uc->context_rax);
1053   st->print("RBX="); print_location(st, uc->context_rbx);


< prev index next >