Changeset 9929 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Jul 27, 2005, 4:10:48 PM (20 years ago)
Author:
mjs
Message:

Changes by Michael Kahl, reviewed by me.

  • fixed <rdar://problem/4194278> Need better debugging support in JavaScriptCore
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/debugger.cpp: (KJS::AttachedInterpreter::AttachedInterpreter): (KJS::AttachedInterpreter::~AttachedInterpreter): (Debugger::~Debugger): (Debugger::attach): (Debugger::detach): (Debugger::sourceParsed):
  • kjs/debugger.h:
  • kjs/function.cpp: (KJS::FunctionImp::call): (KJS::GlobalFuncImp::call):
  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/grammar.y:
  • kjs/internal.cpp: (Parser::parse): (InterpreterImp::evaluate):
  • kjs/internal.h: (KJS::InterpreterImp::setDebugger):
  • kjs/interpreter.cpp:
  • kjs/interpreter.h: (KJS::Interpreter::imp):
  • kjs/nodes.cpp:
Location:
trunk/JavaScriptCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r9924 r9929  
     12005-07-27  Maciej Stachowiak  <[email protected]>
     2
     3        Changes by Michael Kahl, reviewed by me.
     4
     5        - fixed <rdar://problem/4194278> Need better debugging support in JavaScriptCore
     6       
     7        * JavaScriptCore.xcodeproj/project.pbxproj:
     8        * kjs/debugger.cpp:
     9        (KJS::AttachedInterpreter::AttachedInterpreter):
     10        (KJS::AttachedInterpreter::~AttachedInterpreter):
     11        (Debugger::~Debugger):
     12        (Debugger::attach):
     13        (Debugger::detach):
     14        (Debugger::sourceParsed):
     15        * kjs/debugger.h:
     16        * kjs/function.cpp:
     17        (KJS::FunctionImp::call):
     18        (KJS::GlobalFuncImp::call):
     19        * kjs/function_object.cpp:
     20        (FunctionObjectImp::construct):
     21        * kjs/grammar.y:
     22        * kjs/internal.cpp:
     23        (Parser::parse):
     24        (InterpreterImp::evaluate):
     25        * kjs/internal.h:
     26        (KJS::InterpreterImp::setDebugger):
     27        * kjs/interpreter.cpp:
     28        * kjs/interpreter.h:
     29        (KJS::Interpreter::imp):
     30        * kjs/nodes.cpp:
     31
    1322005-07-27  Geoffrey Garen  <[email protected]>
    233
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r9855 r9929  
    2929                932F5B420822A1C700736975 /* collector.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A8530255597D01FF60F7 /* collector.h */; settings = {ATTRIBUTES = (Private, ); }; };
    3030                932F5B430822A1C700736975 /* date_object.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A8560255597D01FF60F7 /* date_object.h */; settings = {ATTRIBUTES = (Private, ); }; };
    31                 932F5B450822A1C700736975 /* debugger.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A8590255597D01FF60F7 /* debugger.h */; };
     31                932F5B450822A1C700736975 /* debugger.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A8590255597D01FF60F7 /* debugger.h */; settings = {ATTRIBUTES = (Private, ); }; };
    3232                932F5B460822A1C700736975 /* error_object.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A85B0255597D01FF60F7 /* error_object.h */; settings = {ATTRIBUTES = (Private, ); }; };
    3333                932F5B470822A1C700736975 /* function_object.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A85D0255597D01FF60F7 /* function_object.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    5757                932F5B650822A1C700736975 /* completion.h in Headers */ = {isa = PBXBuildFile; fileRef = F5BB2BC5030F772101FCFE1D /* completion.h */; settings = {ATTRIBUTES = (Private, ); }; };
    5858                932F5B660822A1C700736975 /* identifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 933A349A038AE7C6008635CE /* identifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
    59                 932F5B670822A1C700736975 /* array_instance.h in Headers */ = {isa = PBXBuildFile; fileRef = 938772E5038BFE19008635CE /* array_instance.h */; };
     59                932F5B670822A1C700736975 /* array_instance.h in Headers */ = {isa = PBXBuildFile; fileRef = 938772E5038BFE19008635CE /* array_instance.h */; settings = {ATTRIBUTES = (Private, ); }; };
    6060                932F5B680822A1C700736975 /* scope_chain.h in Headers */ = {isa = PBXBuildFile; fileRef = 9374D3A7038D9D74008635CE /* scope_chain.h */; settings = {ATTRIBUTES = (Private, ); }; };
    6161                932F5B690822A1C700736975 /* context.h in Headers */ = {isa = PBXBuildFile; fileRef = 9373524E038DA8C2008635CE /* context.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    173173                A85D81F9087B2822006A9172 /* collector.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A8530255597D01FF60F7 /* collector.h */; settings = {ATTRIBUTES = (Private, ); }; };
    174174                A85D81FA087B2822006A9172 /* date_object.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A8560255597D01FF60F7 /* date_object.h */; settings = {ATTRIBUTES = (Private, ); }; };
    175                 A85D81FB087B2822006A9172 /* debugger.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A8590255597D01FF60F7 /* debugger.h */; };
     175                A85D81FB087B2822006A9172 /* debugger.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A8590255597D01FF60F7 /* debugger.h */; settings = {ATTRIBUTES = (Private, ); }; };
    176176                A85D81FC087B2822006A9172 /* error_object.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A85B0255597D01FF60F7 /* error_object.h */; settings = {ATTRIBUTES = (Private, ); }; };
    177177                A85D81FD087B2822006A9172 /* function_object.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A85D0255597D01FF60F7 /* function_object.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    201201                A85D8215087B2822006A9172 /* completion.h in Headers */ = {isa = PBXBuildFile; fileRef = F5BB2BC5030F772101FCFE1D /* completion.h */; settings = {ATTRIBUTES = (Private, ); }; };
    202202                A85D8216087B2822006A9172 /* identifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 933A349A038AE7C6008635CE /* identifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
    203                 A85D8217087B2822006A9172 /* array_instance.h in Headers */ = {isa = PBXBuildFile; fileRef = 938772E5038BFE19008635CE /* array_instance.h */; };
     203                A85D8217087B2822006A9172 /* array_instance.h in Headers */ = {isa = PBXBuildFile; fileRef = 938772E5038BFE19008635CE /* array_instance.h */; settings = {ATTRIBUTES = (Private, ); }; };
    204204                A85D8218087B2822006A9172 /* scope_chain.h in Headers */ = {isa = PBXBuildFile; fileRef = 9374D3A7038D9D74008635CE /* scope_chain.h */; settings = {ATTRIBUTES = (Private, ); }; };
    205205                A85D8219087B2822006A9172 /* context.h in Headers */ = {isa = PBXBuildFile; fileRef = 9373524E038DA8C2008635CE /* context.h */; settings = {ATTRIBUTES = (Private, ); }; };
  • trunk/JavaScriptCore/kjs/debugger.cpp

    r9768 r9929  
    3737  {
    3838  public:
    39     AttachedInterpreter(Interpreter *i) : interp(i) {}
     39    AttachedInterpreter(Interpreter *i, AttachedInterpreter *ai) : interp(i), next(ai) { ++Debugger::debuggersPresent; }
     40    ~AttachedInterpreter() { --Debugger::debuggersPresent; }
    4041    Interpreter *interp;
    4142    AttachedInterpreter *next;
     
    4344
    4445}
     46
     47int Debugger::debuggersPresent = 0;
    4548
    4649Debugger::Debugger()
     
    5154Debugger::~Debugger()
    5255{
    53   // detach from all interpreters
    54   while (rep->interps)
    55     detach(rep->interps->interp);
    56 
     56  detach(0);
    5757  delete rep;
    5858}
     
    6060void Debugger::attach(Interpreter *interp)
    6161{
    62   if (interp->imp()->debugger() != this)
    63     interp->imp()->setDebugger(this);
    64 
    65   // add to the list of attached interpreters
    66   if (!rep->interps)
    67     rep->interps = new AttachedInterpreter(interp);
    68   else {
    69     AttachedInterpreter *ai = rep->interps;
    70     while (ai->next)
    71       ai = ai->next;
    72     ai->next = new AttachedInterpreter(interp);;
    73   }
     62  Debugger *other = interp->imp()->debugger();
     63  if (other == this)
     64    return;
     65  if (other)
     66    other->detach(interp);
     67  interp->imp()->setDebugger(this);
     68  rep->interps = new AttachedInterpreter(interp, rep->interps);
    7469}
    7570
    7671void Debugger::detach(Interpreter *interp)
    7772{
    78   if (interp->imp()->debugger() == this)
    79     interp->imp()->setDebugger(this);
     73  if (interp && interp->imp()->debugger() == this)
     74    interp->imp()->setDebugger(0);
    8075
    81   // remove from the list of attached interpreters
    82   if (rep->interps->interp == interp) {
    83     AttachedInterpreter *old = rep->interps;
    84     rep->interps = rep->interps->next;
    85     delete old;
    86   }
    87 
    88   AttachedInterpreter *ai = rep->interps;
    89   while (ai->next && ai->next->interp != interp)
    90     ai = ai->next;
    91   if (ai->next) {
    92     AttachedInterpreter *old = ai->next;
    93     ai->next = ai->next->next;
    94     delete old;
     76  // iterate the addresses where AttachedInterpreter pointers are stored
     77  // so we can unlink items from the list
     78  AttachedInterpreter **p = &rep->interps;
     79  AttachedInterpreter *q;
     80  while ((q = *p)) {
     81    if (!interp || q->interp == interp) {
     82      *p = q->next;
     83      delete q;
     84    } else {
     85      p = &q->next;
     86    }
    9587  }
    9688}
    9789
    98 bool Debugger::sourceParsed(ExecState */*exec*/, int /*sourceId*/,
    99                             const UString &/*source*/, int /*errorLine*/)
     90bool Debugger::sourceParsed(ExecState */*exec*/, int /*sourceId*/, const UString &/*sourceURL*/,
     91                           const UString &/*source*/, int /*errorLine*/)
    10092{
    10193  return true;
  • trunk/JavaScriptCore/kjs/debugger.h

    r9768 r9929  
    102102     * @param sourceId The ID of the source code (corresponds to the
    103103     * sourceId supplied in other functions such as atStatement()
     104     * @param sourceURL Where the source code that was parsed came from
    104105     * @param source The source code that was parsed
    105106     * @param errorLine The line number at which parsing encountered an
     
    108109     * be aborted
    109110     */
    110     virtual bool sourceParsed(ExecState *exec, int sourceId,
     111    virtual bool sourceParsed(ExecState *exec, int sourceId, const UString &sourceURL,
    111112                              const UString &source, int errorLine);
    112113
     
    206207  private:
    207208    DebuggerImp *rep;
     209
     210  public:
     211    static int debuggersPresent;
    208212  };
    209213
  • trunk/JavaScriptCore/kjs/function.cpp

    r9889 r9929  
    7878  Object &globalObj = exec->dynamicInterpreter()->globalObject();
    7979
     80  // enter a new execution context
     81  ContextImp ctx(globalObj, exec->dynamicInterpreter()->imp(), thisObj, codeType(),
     82                 exec->context().imp(), this, &args);
     83  ExecState newExec(exec->dynamicInterpreter(), &ctx);
     84  newExec.setException(exec->exception()); // could be null
     85
     86  // assign user supplied arguments to parameters
     87  processParameters(&newExec, args);
     88  // add variable declarations (initialized to undefined)
     89  processVarDecls(&newExec);
     90
    8091  Debugger *dbg = exec->dynamicInterpreter()->imp()->debugger();
    8192  int sid = -1;
     
    8899
    89100    Object func(this);
    90     bool cont = dbg->callEvent(exec,sid,lineno,func,args);
     101    bool cont = dbg->callEvent(&newExec,sid,lineno,func,args);
    91102    if (!cont) {
    92103      dbg->imp()->abort();
     
    95106  }
    96107
    97   // enter a new execution context
    98   ContextImp ctx(globalObj, exec->dynamicInterpreter()->imp(), thisObj, codeType(),
    99                  exec->context().imp(), this, &args);
    100   ExecState newExec(exec->dynamicInterpreter(), &ctx);
    101   newExec.setException(exec->exception()); // could be null
    102 
    103   // assign user supplied arguments to parameters
    104   processParameters(&newExec, args);
    105   // add variable declarations (initialized to undefined)
    106   processVarDecls(&newExec);
    107 
    108108  Completion comp = execute(&newExec);
    109109
    110110  // if an exception occured, propogate it back to the previous execution object
    111111  if (newExec.hadException())
    112     exec->setException(newExec.exception());
     112    comp = Completion(Throw, newExec.exception());
    113113
    114114#ifdef KJS_VERBOSE
     
    122122
    123123  if (dbg) {
     124    if (inherits(&DeclaredFunctionImp::info))
     125      lineno = static_cast<DeclaredFunctionImp*>(this)->body->lastLine();
     126
     127    if (comp.complType() == Throw)
     128        newExec.setException(comp.value());
     129
    124130    Object func(this);
    125     int cont = dbg->returnEvent(exec,sid,lineno,func);
     131    int cont = dbg->returnEvent(&newExec,sid,lineno,func);
    126132    if (!cont) {
    127133      dbg->imp()->abort();
     
    790796        UString errMsg;
    791797        ProgramNode *progNode = Parser::parse(UString(), 0, s.data(),s.size(),&sid,&errLine,&errMsg);
    792        
     798
     799        Debugger *dbg = exec->dynamicInterpreter()->imp()->debugger();
     800        if (dbg) {
     801          bool cont = dbg->sourceParsed(exec, sid, UString(), s, errLine);
     802          if (!cont)
     803            return Undefined();
     804        }
     805
    793806        // no program node means a syntax occurred
    794807        if (!progNode) {
  • trunk/JavaScriptCore/kjs/function_object.cpp

    r9768 r9929  
    218218  Debugger *dbg = exec->dynamicInterpreter()->imp()->debugger();
    219219  if (dbg) {
    220     bool cont = dbg->sourceParsed(exec,sid,body,errLine);
     220    // send empty sourceURL to indicate constructed code
     221    bool cont = dbg->sourceParsed(exec,sid,UString(),body,errLine);
    221222    if (!cont) {
    222223      dbg->imp()->abort();
  • trunk/JavaScriptCore/kjs/grammar.y

    r9768 r9929  
    509509    CONTINUE ';'                   { $$ = new ContinueNode(); DBG($$,@1,@2); }
    510510  | CONTINUE error                 { if (automatic()) {
    511                                        $$ = new ContinueNode(); DBG($$,@1,@2);
     511                                       $$ = new ContinueNode(); DBG($$,@1,@1);
    512512                                     } else
    513513                                       YYABORT; }
     
    539539                                     } else
    540540                                       YYABORT; }
    541   | RETURN Expr ';'                { $$ = new ReturnNode($2); }
    542   | RETURN Expr error              { if (automatic())
    543                                        $$ = new ReturnNode($2);
    544                                      else
     541  | RETURN Expr ';'                { $$ = new ReturnNode($2); DBG($$,@1,@3); }
     542  | RETURN Expr error              { if (automatic()) {
     543                                       $$ = new ReturnNode($2); DBG($$,@1,@2);
     544                                     } else
    545545                                       YYABORT; }
    546546;
     
    588588
    589589ThrowStatement:
    590     THROW Expr ';'                 { $$ = new ThrowNode($2); }
    591   | THROW Expr error               { if (automatic()) $$ = new ThrowNode($2); else YYABORT; }
     590    THROW Expr ';'                 { $$ = new ThrowNode($2); DBG($$,@1,@3); }
     591  | THROW Expr error               { if (automatic()) { $$ = new ThrowNode($2); DBG($$,@1,@2); } else YYABORT; }
    592592;
    593593
    594594TryStatement:
    595     TRY Block Catch                { $$ = new TryNode($2, $3); }
    596   | TRY Block Finally              { $$ = new TryNode($2, $3); }
    597   | TRY Block Catch Finally        { $$ = new TryNode($2, $3, $4); }
     595    TRY Block Catch                { $$ = new TryNode($2, $3); DBG($$,@1,@2); }
     596  | TRY Block Finally              { $$ = new TryNode($2, $3); DBG($$,@1,@2); }
     597  | TRY Block Catch Finally        { $$ = new TryNode($2, $3, $4); DBG($$,@1,@2); }
    598598;
    599599
  • trunk/JavaScriptCore/kjs/internal.cpp

    r9768 r9929  
    453453  ProgramNode *prog = progNode;
    454454  progNode = 0;
    455   sid = -1;
     455//  sid = -1;
    456456
    457457  if (parseError || lexError) {
     
    762762  // notify debugger that source has been parsed
    763763  if (dbg) {
    764     bool cont = dbg->sourceParsed(globExec,sid,code,errLine);
     764    bool cont = dbg->sourceParsed(globExec,sid,sourceURL,code,errLine);
    765765    if (!cont)
    766766#if APPLE_CHANGES
     
    823823#endif
    824824  return res;
    825 }
    826 
    827 void InterpreterImp::setDebugger(Debugger *d)
    828 {
    829   if (d)
    830     d->detach(m_interpreter);
    831   dbg = d;
    832825}
    833826
  • trunk/JavaScriptCore/kjs/internal.h

    r9768 r9929  
    292292    Completion evaluate(const UString &code, const Value &thisV, const UString &sourceURL, int startingLineNumber);
    293293    Debugger *debugger() const { return dbg; }
    294     void setDebugger(Debugger *d);
     294    void setDebugger(Debugger *d) { dbg = d; }
    295295
    296296    Object builtinObject() const { return b_Object; }
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r9781 r9929  
    141141}
    142142
    143 InterpreterImp *Interpreter::imp()
    144 {
    145   return rep;
    146 }
    147 
    148143Object Interpreter::builtinObject() const
    149144{
  • trunk/JavaScriptCore/kjs/interpreter.h

    r9768 r9929  
    222222     * Only useful for internal KJS operations.
    223223     */
    224     InterpreterImp *imp();
     224    InterpreterImp *imp() const { return rep; }
    225225
    226226    /**
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r9889 r9929  
    4848using namespace KJS;
    4949
    50 // Disabled for now because it shows up on benchmark (0.5%).
    51 #if DEBUGGER_SUPPORT
    52 
    5350#define KJS_BREAKPOINT \
    54   if (!hitStatement(exec)) \
     51  if (Debugger::debuggersPresent > 0 && !hitStatement(exec)) \
    5552    return Completion(Normal);
    5653
    5754#define KJS_ABORTPOINT \
    58   if (exec->dynamicInterpreter()->imp()->debugger() && \
     55  if (Debugger::debuggersPresent > 0 && \
     56      exec->dynamicInterpreter()->imp()->debugger() && \
    5957      exec->dynamicInterpreter()->imp()->debugger()->imp()->aborted()) \
    6058    return Completion(Normal);
    61 
    62 #else
    63 
    64 #define KJS_BREAKPOINT
    65 #define KJS_ABORTPOINT
    66 
    67 #endif
    6859
    6960#define KJS_CHECKEXCEPTION \
Note: See TracChangeset for help on using the changeset viewer.