Debian Codegraph @

src/scripttools/debugging/scripts/commands/tbreak.qs

raw
1 name = "tbreak";
2
3 group = "breakpoints";
4
5 shortDescription = "Set a temporary breakpoint";
6
7 longDescription = "The same as the \"break\" command, except that the breakpoint is automatically deleted as soon as it is triggered.";
8
9 seeAlso = [ "break", "ignore" ];
10
11 argumentTypes = [ "script-filename" ];
12
13 // ### merge with break.qs: only difference is the "singleShot: true" in call to scheduleSetBreakpoint()
14 // ### maybe an include() function so commands can share code?
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, singleShot: true });
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, singleShot: true });
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 }