src/scripttools/debugging/scripts/commands/break.qs
changeset 0 1918ee327afb
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 name = "break";
       
     2 
       
     3 group = "breakpoints";
       
     4 
       
     5 shortDescription = "Set a breakpoint at specified location";
       
     6 
       
     7 longDescription = "break <file>:<line> : Sets a breakpoint at the given location.";
       
     8 longDescription += "\nbreak <line> : Sets a breakpoint at the given line of the current file.";
       
     9 
       
    10 argumentTypes = [ "script-filename" ];
       
    11 
       
    12 aliases = [ "b" ];
       
    13 
       
    14 seeAlso = [ "condition", "delete", "disable", "tbreak" ];
       
    15 
       
    16 function execute() {
       
    17     if (arguments.length == 0) {
       
    18         message("Missing argument.");
       
    19         return;
       
    20     }
       
    21     var arg = arguments[0];
       
    22     var colonIndex = arg.lastIndexOf(':');
       
    23     if (colonIndex == -1) {
       
    24         lineNumber = parseInt(arg);
       
    25         if (isNaN(lineNumber)) {
       
    26             message("Breakpoint location must be of the form <file>:<line> or <line>.");
       
    27             return;
       
    28         }
       
    29         var sid = getCurrentScriptId();
       
    30         if (sid == -1) {
       
    31             message("No script.");
       
    32             return;
       
    33         }
       
    34         scheduleGetScriptData(sid);
       
    35         scriptId = sid;
       
    36         state = 1;
       
    37     } else {
       
    38         fileName = arg.slice(0, colonIndex);
       
    39         lineNumber = parseInt(arg.slice(colonIndex+1));
       
    40         // ### resolve the script to see if it's loaded or not? (e.g. so we can issue a warning)
       
    41         scheduleSetBreakpoint({ fileName: fileName, lineNumber: lineNumber});
       
    42         state = 2;
       
    43     }
       
    44 }
       
    45 
       
    46 function handleResponse(resp) {
       
    47     if (state == 1) {
       
    48         fileName = resp.result.fileName;
       
    49         if (fileName.length == 0)
       
    50             fileName = "<anonymous script, id=" + scriptId + ">";
       
    51         scheduleSetBreakpoint({ scriptId: scriptId, lineNumber: lineNumber});
       
    52         state = 2;
       
    53     } else if (state == 2) {
       
    54         if (resp.error == 0) {
       
    55             var id = resp.result;
       
    56             message("Breakpoint " + id + ": " + fileName + ", line " + lineNumber + ".");
       
    57         }
       
    58     }
       
    59 }