< prev index next >

src/hotspot/os/aix/porting_aix.cpp

Print this page
rev 51015 : 8207342: error occurred during error reporting (printing register info)
Summary: os::print_location misses a check if the pointer is readable.
Reviewed-by:


 125   // weed out obvious bogus states
 126   if (pc < (codeptr_t)0x1000) {
 127     trcVerbose("invalid program counter");
 128     return false;
 129   }
 130 
 131   // We see random but frequent crashes in this function since some months mainly on shutdown
 132   // (-XX:+DumpInfoAtExit). It appears the page we are reading is randomly disappearing while
 133   // we read it (?).
 134   // As the pc cannot be trusted to be anything sensible lets make all reads via SafeFetch. Also
 135   // bail if this is not a text address right now.
 136   if (!LoadedLibraries::find_for_text_address(pc, NULL)) {
 137     trcVerbose("not a text address");
 138     return false;
 139   }
 140 
 141   // .. (Note that is_readable_pointer returns true if safefetch stubs are not there yet;
 142   // in that case I try reading the traceback table unsafe - I rather risk secondary crashes in
 143   // error files than not having a callstack.)
 144 #define CHECK_POINTER_READABLE(p) \
 145   if (!MiscUtils::is_readable_pointer(p)) { \
 146     trcVerbose("pc not readable"); \
 147     return false; \
 148   }
 149 
 150   codeptr_t pc2 = (codeptr_t) pc;
 151 
 152   // Make sure the pointer is word aligned.
 153   pc2 = (codeptr_t) align_up((char*)pc2, 4);
 154   CHECK_POINTER_READABLE(pc2)
 155 
 156   // Find start of traceback table.
 157   // (starts after code, is marked by word-aligned (32bit) zeros)
 158   while ((*pc2 != NULL) && (searchcount++ < MAX_FUNC_SEARCH_LEN)) {
 159     CHECK_POINTER_READABLE(pc2)
 160     pc2++;
 161   }
 162   if (*pc2 != 0) {
 163     trcVerbose("no traceback table found");
 164     return false;
 165   }


 213     }
 214   }
 215 
 216   if (tb->tb.int_hndl == TRUE)
 217     pc2++;
 218 
 219   if (tb->tb.has_ctl == TRUE)
 220     pc2 += (*pc2) + 1; // don't care
 221 
 222   CHECK_POINTER_READABLE(pc2)
 223 
 224   //
 225   // return function name if it exists.
 226   //
 227   if (p_name && namelen > 0) {
 228     if (tb->tb.name_present) {
 229       // Copy name from text because it may not be zero terminated.
 230       const short l = MIN2<short>(*((short*)pc2), namelen - 1);
 231       // Be very careful.
 232       int i = 0; char* const p = (char*)pc2 + sizeof(short);
 233       while (i < l && MiscUtils::is_readable_pointer(p + i)) {
 234         p_name[i] = p[i];
 235         i++;
 236       }
 237       p_name[i] = '\0';
 238 
 239       // If it is a C++ name, try and demangle it using the Demangle interface (see demangle.h).
 240       if (demangle) {
 241         char* rest;
 242         Name* const name = Demangle(p_name, rest);
 243         if (name) {
 244           const char* const demangled_name = name->Text();
 245           if (demangled_name) {
 246             strncpy(p_name, demangled_name, namelen-1);
 247             p_name[namelen-1] = '\0';
 248           }
 249           delete name;
 250         }
 251       }
 252     } else {
 253       strncpy(p_name, "<nameless function>", namelen-1);


 472     st->print("gpr_saved:%d ", p_tb->tb.gpr_saved);
 473   }
 474   if (p_tb->tb.fixedparms > 0) {
 475     st->print("fixedparms:%d ", p_tb->tb.fixedparms);
 476   }
 477   if (p_tb->tb.floatparms > 0) {
 478     st->print("floatparms:%d ", p_tb->tb.floatparms);
 479   }
 480   if (p_tb->tb.parmsonstk > 0) {
 481     st->print("parmsonstk:%d", p_tb->tb.parmsonstk);
 482   }
 483 }
 484 
 485 // Print information for pc (module, function, displacement, traceback table)
 486 // on one line.
 487 static void print_info_for_pc (outputStream* st, codeptr_t pc, char* buf,
 488                                size_t buf_size, bool demangle) {
 489   const struct tbtable* tb = NULL;
 490   int displacement = -1;
 491 
 492   if (!MiscUtils::is_readable_pointer(pc)) {
 493     st->print("(invalid)");
 494     return;
 495   }
 496 
 497   if (AixSymbols::get_module_name((address)pc, buf, buf_size)) {
 498     st->print("%s", buf);
 499   } else {
 500     st->print("(unknown module)");
 501   }
 502   st->print("::");
 503   if (AixSymbols::get_function_name((address)pc, buf, buf_size,
 504                                      &displacement, &tb, demangle)) {
 505     st->print("%s", buf);
 506   } else {
 507     st->print("(unknown function)");
 508   }
 509   if (displacement == -1) {
 510     st->print("+?");
 511   } else {
 512     st->print("+0x%x", displacement);


 680 
 681   // Retrieve current stack base, size from the current thread. If there is none,
 682   // retrieve it from the OS.
 683   stackptr_t stack_base = NULL;
 684   size_t stack_size = NULL;
 685   {
 686     AixMisc::stackbounds_t stackbounds;
 687     if (!AixMisc::query_stack_bounds_for_current_thread(&stackbounds)) {
 688       st->print_cr("Cannot retrieve stack bounds.");
 689       return;
 690     }
 691     stack_base = (stackptr_t)stackbounds.base;
 692     stack_size = stackbounds.size;
 693   }
 694 
 695   st->print_cr("------ current frame:");
 696   st->print("iar:  " PTR64_FORMAT " ", p2i(cur_iar));
 697   print_info_for_pc(st, cur_iar, buf, buf_size, demangle);
 698   st->cr();
 699 
 700   if (cur_iar && MiscUtils::is_readable_pointer(cur_iar)) {
 701     decode_instructions_at_pc(
 702       "Decoded instructions at iar:",
 703       cur_iar, 32, 16, st);
 704   }
 705 
 706   // Print out lr too, which may be interesting if we did jump to some bogus location;
 707   // in those cases the new frame is not built up yet and the caller location is only
 708   // preserved via lr register.
 709   st->print("lr:   " PTR64_FORMAT " ", p2i(cur_lr));
 710   print_info_for_pc(st, cur_lr, buf, buf_size, demangle);
 711   st->cr();
 712 
 713   if (cur_lr && MiscUtils::is_readable_pointer(cur_lr)) {
 714     decode_instructions_at_pc(
 715       "Decoded instructions at lr:",
 716       cur_lr, 32, 16, st);
 717   }
 718 
 719   // Check and print sp.
 720   st->print("sp:   " PTR64_FORMAT " ", p2i(cur_sp));
 721   if (!is_valid_stackpointer(cur_sp, stack_base, stack_size)) {
 722     st->print("(invalid) ");
 723     goto cleanup;
 724   } else {
 725     st->print("(base - 0x%X) ", PTRDIFF_BYTES(stack_base, cur_sp));
 726   }
 727   st->cr();
 728 
 729   // Check and print rtoc.
 730   st->print("rtoc: "  PTR64_FORMAT " ", p2i(cur_rtoc));
 731   if (cur_rtoc == NULL || cur_rtoc == (codeptr_t)-1 ||
 732       !MiscUtils::is_readable_pointer(cur_rtoc)) {
 733     st->print("(invalid)");
 734   } else if (((uintptr_t)cur_rtoc) & 0x7) {
 735     st->print("(unaligned)");
 736   }
 737   st->cr();
 738 
 739   st->print_cr("|---stackaddr----|   |----lrsave------|:   <function name>");
 740 
 741   ///
 742   // Walk callstack.
 743   //
 744   // (if no context was given, use the current stack)
 745   sp = (unsigned long*)(*(unsigned long*)cur_sp); // Stack pointer
 746   sp_last = cur_sp;
 747 
 748   frame = 0;
 749 
 750   while (frame < MAX_CALLSTACK_DEPTH) {
 751 
 752     // Check sp.




 125   // weed out obvious bogus states
 126   if (pc < (codeptr_t)0x1000) {
 127     trcVerbose("invalid program counter");
 128     return false;
 129   }
 130 
 131   // We see random but frequent crashes in this function since some months mainly on shutdown
 132   // (-XX:+DumpInfoAtExit). It appears the page we are reading is randomly disappearing while
 133   // we read it (?).
 134   // As the pc cannot be trusted to be anything sensible lets make all reads via SafeFetch. Also
 135   // bail if this is not a text address right now.
 136   if (!LoadedLibraries::find_for_text_address(pc, NULL)) {
 137     trcVerbose("not a text address");
 138     return false;
 139   }
 140 
 141   // .. (Note that is_readable_pointer returns true if safefetch stubs are not there yet;
 142   // in that case I try reading the traceback table unsafe - I rather risk secondary crashes in
 143   // error files than not having a callstack.)
 144 #define CHECK_POINTER_READABLE(p) \
 145   if (!os::is_readable_pointer(p)) { \
 146     trcVerbose("pc not readable"); \
 147     return false; \
 148   }
 149 
 150   codeptr_t pc2 = (codeptr_t) pc;
 151 
 152   // Make sure the pointer is word aligned.
 153   pc2 = (codeptr_t) align_up((char*)pc2, 4);
 154   CHECK_POINTER_READABLE(pc2)
 155 
 156   // Find start of traceback table.
 157   // (starts after code, is marked by word-aligned (32bit) zeros)
 158   while ((*pc2 != NULL) && (searchcount++ < MAX_FUNC_SEARCH_LEN)) {
 159     CHECK_POINTER_READABLE(pc2)
 160     pc2++;
 161   }
 162   if (*pc2 != 0) {
 163     trcVerbose("no traceback table found");
 164     return false;
 165   }


 213     }
 214   }
 215 
 216   if (tb->tb.int_hndl == TRUE)
 217     pc2++;
 218 
 219   if (tb->tb.has_ctl == TRUE)
 220     pc2 += (*pc2) + 1; // don't care
 221 
 222   CHECK_POINTER_READABLE(pc2)
 223 
 224   //
 225   // return function name if it exists.
 226   //
 227   if (p_name && namelen > 0) {
 228     if (tb->tb.name_present) {
 229       // Copy name from text because it may not be zero terminated.
 230       const short l = MIN2<short>(*((short*)pc2), namelen - 1);
 231       // Be very careful.
 232       int i = 0; char* const p = (char*)pc2 + sizeof(short);
 233       while (i < l && os::is_readable_pointer(p + i)) {
 234         p_name[i] = p[i];
 235         i++;
 236       }
 237       p_name[i] = '\0';
 238 
 239       // If it is a C++ name, try and demangle it using the Demangle interface (see demangle.h).
 240       if (demangle) {
 241         char* rest;
 242         Name* const name = Demangle(p_name, rest);
 243         if (name) {
 244           const char* const demangled_name = name->Text();
 245           if (demangled_name) {
 246             strncpy(p_name, demangled_name, namelen-1);
 247             p_name[namelen-1] = '\0';
 248           }
 249           delete name;
 250         }
 251       }
 252     } else {
 253       strncpy(p_name, "<nameless function>", namelen-1);


 472     st->print("gpr_saved:%d ", p_tb->tb.gpr_saved);
 473   }
 474   if (p_tb->tb.fixedparms > 0) {
 475     st->print("fixedparms:%d ", p_tb->tb.fixedparms);
 476   }
 477   if (p_tb->tb.floatparms > 0) {
 478     st->print("floatparms:%d ", p_tb->tb.floatparms);
 479   }
 480   if (p_tb->tb.parmsonstk > 0) {
 481     st->print("parmsonstk:%d", p_tb->tb.parmsonstk);
 482   }
 483 }
 484 
 485 // Print information for pc (module, function, displacement, traceback table)
 486 // on one line.
 487 static void print_info_for_pc (outputStream* st, codeptr_t pc, char* buf,
 488                                size_t buf_size, bool demangle) {
 489   const struct tbtable* tb = NULL;
 490   int displacement = -1;
 491 
 492   if (!os::is_readable_pointer(pc)) {
 493     st->print("(invalid)");
 494     return;
 495   }
 496 
 497   if (AixSymbols::get_module_name((address)pc, buf, buf_size)) {
 498     st->print("%s", buf);
 499   } else {
 500     st->print("(unknown module)");
 501   }
 502   st->print("::");
 503   if (AixSymbols::get_function_name((address)pc, buf, buf_size,
 504                                      &displacement, &tb, demangle)) {
 505     st->print("%s", buf);
 506   } else {
 507     st->print("(unknown function)");
 508   }
 509   if (displacement == -1) {
 510     st->print("+?");
 511   } else {
 512     st->print("+0x%x", displacement);


 680 
 681   // Retrieve current stack base, size from the current thread. If there is none,
 682   // retrieve it from the OS.
 683   stackptr_t stack_base = NULL;
 684   size_t stack_size = NULL;
 685   {
 686     AixMisc::stackbounds_t stackbounds;
 687     if (!AixMisc::query_stack_bounds_for_current_thread(&stackbounds)) {
 688       st->print_cr("Cannot retrieve stack bounds.");
 689       return;
 690     }
 691     stack_base = (stackptr_t)stackbounds.base;
 692     stack_size = stackbounds.size;
 693   }
 694 
 695   st->print_cr("------ current frame:");
 696   st->print("iar:  " PTR64_FORMAT " ", p2i(cur_iar));
 697   print_info_for_pc(st, cur_iar, buf, buf_size, demangle);
 698   st->cr();
 699 
 700   if (cur_iar && os::is_readable_pointer(cur_iar)) {
 701     decode_instructions_at_pc(
 702       "Decoded instructions at iar:",
 703       cur_iar, 32, 16, st);
 704   }
 705 
 706   // Print out lr too, which may be interesting if we did jump to some bogus location;
 707   // in those cases the new frame is not built up yet and the caller location is only
 708   // preserved via lr register.
 709   st->print("lr:   " PTR64_FORMAT " ", p2i(cur_lr));
 710   print_info_for_pc(st, cur_lr, buf, buf_size, demangle);
 711   st->cr();
 712 
 713   if (cur_lr && os::is_readable_pointer(cur_lr)) {
 714     decode_instructions_at_pc(
 715       "Decoded instructions at lr:",
 716       cur_lr, 32, 16, st);
 717   }
 718 
 719   // Check and print sp.
 720   st->print("sp:   " PTR64_FORMAT " ", p2i(cur_sp));
 721   if (!is_valid_stackpointer(cur_sp, stack_base, stack_size)) {
 722     st->print("(invalid) ");
 723     goto cleanup;
 724   } else {
 725     st->print("(base - 0x%X) ", PTRDIFF_BYTES(stack_base, cur_sp));
 726   }
 727   st->cr();
 728 
 729   // Check and print rtoc.
 730   st->print("rtoc: "  PTR64_FORMAT " ", p2i(cur_rtoc));
 731   if (cur_rtoc == NULL || cur_rtoc == (codeptr_t)-1 ||
 732       !os::is_readable_pointer(cur_rtoc)) {
 733     st->print("(invalid)");
 734   } else if (((uintptr_t)cur_rtoc) & 0x7) {
 735     st->print("(unaligned)");
 736   }
 737   st->cr();
 738 
 739   st->print_cr("|---stackaddr----|   |----lrsave------|:   <function name>");
 740 
 741   ///
 742   // Walk callstack.
 743   //
 744   // (if no context was given, use the current stack)
 745   sp = (unsigned long*)(*(unsigned long*)cur_sp); // Stack pointer
 746   sp_last = cur_sp;
 747 
 748   frame = 0;
 749 
 750   while (frame < MAX_CALLSTACK_DEPTH) {
 751 
 752     // Check sp.


< prev index next >