Home | History | Annotate | Download | only in src
      1 // Copyright 2010 the V8 project authors. All rights reserved.
      2 // Redistribution and use in source and binary forms, with or without
      3 // modification, are permitted provided that the following conditions are
      4 // met:
      5 //
      6 //     * Redistributions of source code must retain the above copyright
      7 //       notice, this list of conditions and the following disclaimer.
      8 //     * Redistributions in binary form must reproduce the above
      9 //       copyright notice, this list of conditions and the following
     10 //       disclaimer in the documentation and/or other materials provided
     11 //       with the distribution.
     12 //     * Neither the name of Google Inc. nor the names of its
     13 //       contributors may be used to endorse or promote products derived
     14 //       from this software without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 
     28 #ifndef V8_GDB_JIT_H_
     29 #define V8_GDB_JIT_H_
     30 
     31 //
     32 // Basic implementation of GDB JIT Interface client.
     33 // GBD JIT Interface is supported in GDB 7.0 and above.
     34 // Currently on x64 and ia32 architectures and Linux OS are supported.
     35 //
     36 
     37 #ifdef ENABLE_GDB_JIT_INTERFACE
     38 #include "v8.h"
     39 #include "factory.h"
     40 
     41 namespace v8 {
     42 namespace internal {
     43 
     44 #define CODE_TAGS_LIST(V)                       \
     45   V(LOAD_IC)                                    \
     46   V(KEYED_LOAD_IC)                              \
     47   V(STORE_IC)                                   \
     48   V(KEYED_STORE_IC)                             \
     49   V(CALL_IC)                                    \
     50   V(CALL_INITIALIZE)                            \
     51   V(CALL_PRE_MONOMORPHIC)                       \
     52   V(CALL_NORMAL)                                \
     53   V(CALL_MEGAMORPHIC)                           \
     54   V(CALL_MISS)                                  \
     55   V(STUB)                                       \
     56   V(BUILTIN)                                    \
     57   V(SCRIPT)                                     \
     58   V(EVAL)                                       \
     59   V(FUNCTION)
     60 
     61 class GDBJITLineInfo : public Malloced {
     62  public:
     63   GDBJITLineInfo()
     64       : pc_info_(10) { }
     65 
     66   void SetPosition(intptr_t pc, int pos, bool is_statement) {
     67     AddPCInfo(PCInfo(pc, pos, is_statement));
     68   }
     69 
     70   struct PCInfo {
     71     PCInfo(intptr_t pc, int pos, bool is_statement)
     72         : pc_(pc), pos_(pos), is_statement_(is_statement) { }
     73 
     74     intptr_t pc_;
     75     int pos_;
     76     bool is_statement_;
     77   };
     78 
     79   List<PCInfo>* pc_info() {
     80     return &pc_info_;
     81   }
     82 
     83  private:
     84   void AddPCInfo(const PCInfo& pc_info) {
     85     pc_info_.Add(pc_info);
     86   }
     87 
     88   List<PCInfo> pc_info_;
     89 };
     90 
     91 
     92 class GDBJITInterface: public AllStatic {
     93  public:
     94   enum CodeTag {
     95 #define V(x) x,
     96     CODE_TAGS_LIST(V)
     97 #undef V
     98     TAG_COUNT
     99   };
    100 
    101   static const char* Tag2String(CodeTag tag) {
    102     switch (tag) {
    103 #define V(x) case x: return #x;
    104       CODE_TAGS_LIST(V)
    105 #undef V
    106       default:
    107         return NULL;
    108     }
    109   }
    110 
    111   static void AddCode(const char* name,
    112                       Code* code,
    113                       CodeTag tag,
    114                       Script* script = NULL);
    115 
    116   static void AddCode(Handle<String> name,
    117                       Handle<Script> script,
    118                       Handle<Code> code);
    119 
    120   static void AddCode(CodeTag tag, String* name, Code* code);
    121 
    122   static void AddCode(CodeTag tag, const char* name, Code* code);
    123 
    124   static void AddCode(CodeTag tag, Code* code);
    125 
    126   static void RemoveCode(Code* code);
    127 
    128   static void RegisterDetailedLineInfo(Code* code, GDBJITLineInfo* line_info);
    129 
    130  private:
    131   static Mutex* mutex_;
    132 };
    133 
    134 #define GDBJIT(action) GDBJITInterface::action
    135 
    136 } }   // namespace v8::internal
    137 #else
    138 #define GDBJIT(action) ((void) 0)
    139 #endif
    140 
    141 #endif
    142