1 /*
   2  * Copyright (c) 1997, 2010, 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 
  26 #ifndef __DECODER_HPP
  27 #define __DECODER_HPP
  28 
  29 #include "memory/allocation.hpp"
  30 #include "runtime/mutex.hpp"
  31 
  32 class Decoder: public CHeapObj {
  33 
  34 public:
  35   // status code for decoding native C frame
  36   enum decoder_status {
  37          not_available = -10,  // real decoder is not available
  38          no_error = 0,         // successfully decoded frames
  39          out_of_memory,        // out of memory
  40          file_invalid,         // invalid elf file
  41          file_not_found,       // could not found symbol file (on windows), such as jvm.pdb or jvm.map
  42          helper_not_found,     // could not load dbghelp.dll (Windows only)
  43          helper_func_error,    // decoding functions not found (Windows only)
  44          helper_init_error     // SymInitialize failed (Windows only)
  45   };
  46 
  47    static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL);
  48    static bool demangle(const char* symbol, char* buf, int buflen);
  49    static bool can_decode_C_frame_in_vm();
  50 
  51    static bool is_error(decoder_status status) { return (status > 0); }
  52    static decoder_status status();
  53 
  54    static void shutdown();
  55 protected:
  56   Decoder() {
  57     _decoder_status = not_available;
  58   };
  59 
  60   ~Decoder() {};
  61 
  62   static Decoder* get_decoder();
  63 
  64   virtual bool _decode(address pc, char* buf, int buflen, int* offset, 
  65     const char* modulepath = NULL) {
  66     return false;
  67   }
  68 
  69   virtual bool _demangle(const char* symbol, char* buf, int buflen) {
  70     return false;
  71   }
  72 
  73   virtual bool _can_decode_C_frame_in_vm() const { 
  74     return false; 
  75   }
  76 
  77   virtual decoder_status _status() const { return _decoder_status; }
  78   virtual bool has_error() const { return is_error(_decoder_status); }
  79  
  80 private:
  81   static Decoder*     _decoder;
  82   static Decoder      _do_nothing_decoder;
  83 
  84 protected:
  85   static Mutex*       _decoder_lock;
  86 
  87   decoder_status      _decoder_status;
  88 };
  89 
  90 #endif // __DECODER_HPP