Debugger should not lookup units
[hiphop-php.git] / hphp / test / slow / ext_vsdebug / context.php
blob0bf20b0e20d9d65bbdb3e76ff1599481d9096703
1 <?hh
3 <<__EntryPoint>> function main() {
4 require(__DIR__ . '/common.inc');
6 $path = __FILE__ . ".test";
7 $breakpoints = varray[
8 darray[
9 "path" => $path,
10 "breakpoints" => varray[
11 darray["line" => 20, "calibratedLine" => 20, "condition" => ""],
12 darray["line" => 21, "calibratedLine" => 21, "condition" => ""],
13 darray["line" => 23, "calibratedLine" => 24, "condition" => ""],
14 darray["line" => 28, "calibratedLine" => 28, "condition" => ""],
18 $testProcess = vsDebugLaunch(__FILE__ . ".test", true, $breakpoints);
20 // Skip breakpoint resolution messages.
21 skipMessages(count($breakpoints[0]{'breakpoints'}));
23 // Verify we hit breakpoint 1.
24 verifyBpHit($breakpoints[0]{'path'}, $breakpoints[0]{'breakpoints'}[0]);
26 // Check thread stacks.
27 $seq = sendVsCommand(darray[
28 "command" => "stackTrace",
29 "type" => "request",
30 "arguments" => darray[
31 "threadId" => 1
32 ]]);
34 $msg = json_decode(getNextVsDebugMessage(), true);
35 checkObjEqualRecursively($msg, darray[
36 "type" => "response",
37 "command" => "stackTrace",
38 "request_seq" => $seq,
39 "success" => true,
40 "body" => darray[
41 "totalFrames" => 2,
42 "stackFrames" => varray[
43 darray[
44 "source" => darray["path" => $path, "name" => str_replace(".test", "", basename($path))],
45 "id" => 1,
46 "line" => 20,
47 "name" => "innerFunc"
49 darray[
50 "source" => darray["path" => $path, "name" => str_replace(".test", "", basename($path))],
51 "id" => 2,
52 "line" => 31,
53 "name" => "main"
57 ]);
59 // Check threads.
60 $seq = sendVsCommand(darray[
61 "command" => "threads",
62 "type" => "request"]);
63 $msg = json_decode(getNextVsDebugMessage(), true);
64 checkObjEqualRecursively($msg, darray[
65 "type" => "response",
66 "command" => "threads",
67 "request_seq" => $seq,
68 "success" => true,
69 "body" => darray[
70 "threads" => varray[darray["name" => "Request 1", "id" => 1]]
72 ]);
75 // Get scopes.
76 $seq = sendVsCommand(darray[
77 "command" => "scopes",
78 "type" => "request",
79 "arguments" => darray["frameId" => 1]]);
80 $msg = json_decode(getNextVsDebugMessage(), true);
81 checkObjEqualRecursively($msg, darray[
82 "type" => "response",
83 "command" => "scopes",
84 "request_seq" => $seq,
85 "success" => true,
86 "body" => darray[
87 "scopes" => varray[
88 darray[
89 "namedVariables" => 1,
90 "name" => "Locals",
92 darray[
93 "namedVariables" => 7,
94 "name" => "Superglobals",
96 darray[
97 "namedVariables" => 2,
98 "name" => "Constants",
103 // Get locals, only $a should be visible right here.
104 $seq = sendVsCommand(darray[
105 "command" => "variables",
106 "type" => "request",
107 "arguments" => darray["variablesReference" => 3]]);
108 $msg = json_decode(getNextVsDebugMessage(), true);
109 checkObjEqualRecursively($msg, darray[
110 "type" => "response",
111 "command" => "variables",
112 "request_seq" => $seq,
113 "success" => true,
114 "body" => darray[
115 "variables" => varray[
116 darray[
117 "type" => "int",
118 "name" => "\$a",
119 "value" => "1",
124 if (count($msg{"body"}{"variables"}) != 1) {
125 throw new UnexpectedValueException("Unexpected variable count");
128 resumeTarget();
130 // Verify we hit breakpoint 2.
131 verifyBpHit($breakpoints[0]{'path'}, $breakpoints[0]{'breakpoints'}[1]);
132 resumeTarget();
134 // Verify we hit breakpoint 3.
135 verifyBpHit($breakpoints[0]{'path'}, $breakpoints[0]{'breakpoints'}[2]);
136 resumeTarget();
138 // Verify we hit breakpoint 4.
139 verifyBpHit($breakpoints[0]{'path'}, $breakpoints[0]{'breakpoints'}[3]);
141 $seq = sendVsCommand(darray[
142 "command" => "stackTrace",
143 "type" => "request",
144 "arguments" => darray[
145 "threadId" => 1
146 ]]);
147 $msg = json_decode(getNextVsDebugMessage(), true);
149 $seq = sendVsCommand(darray[
150 "command" => "scopes",
151 "type" => "request",
152 "arguments" => darray["frameId" => 8]]);
153 $msg = json_decode(getNextVsDebugMessage(), true);
155 $seq = sendVsCommand(darray[
156 "command" => "variables",
157 "type" => "request",
158 "arguments" => darray["variablesReference" => 3]]);
159 $msg = json_decode(getNextVsDebugMessage(), true);
160 checkObjEqualRecursively($msg, darray[
161 "type" => "response",
162 "command" => "variables",
163 "request_seq" => $seq,
164 "success" => true,
165 "body" => darray[
166 "variables" => varray[
167 darray[
168 "type" => "int",
169 "name" => "\$a",
170 "value" => "1",
172 darray[
173 "type" => "string",
174 "name" => "\$b",
175 "value" => "Hello world",
177 darray[
178 "type" => "B",
179 "name" => "\$bObj",
180 "value" => "B",
182 darray[
183 "type" => "vec",
184 "name" => "\$c",
185 "value" => "vec[3]",
186 "indexedVariables" => 3,
188 darray[
189 "type" => "vec",
190 "name" => "\$d",
191 "value" => "vec[2]",
192 "indexedVariables" => 2,
194 darray[
195 "type" => "vec",
196 "name" => "\$e",
197 "value" => "vec[2]",
198 "indexedVariables" => 2,
203 if (count($msg{"body"}{"variables"}) != 6) {
204 throw new UnexpectedValueException("Unexpected variable count");
207 $seq = sendVsCommand(darray[
208 "command" => "variables",
209 "type" => "request",
210 "arguments" => darray["variablesReference" => 14]]);
212 $msg = json_decode(getNextVsDebugMessage(), true);
213 checkObjEqualRecursively($msg, darray[
214 "type" => "response",
215 "command" => "variables",
216 "request_seq" => $seq,
217 "success" => true,
218 "body" => darray[
219 "variables" => varray[
220 darray[
221 "type" => "A",
222 "name" => "aObj",
223 "value" => "A",
224 "namedVariables" => 2,
225 "variablesReference" => 16,
226 "presentationHint" => darray[
227 "visibility" => "public"
230 darray[
231 "type" => "int",
232 "name" => "b",
233 "value" => "2",
234 "presentationHint" => darray[
235 "visibility" => "protected"
238 darray[
239 "type" => "int",
240 "name" => "c",
241 "value" => "3",
242 "presentationHint" => darray[
243 "visibility" => "public"
247 // The private props should contain the base class's copy of $a, only.
248 darray[
249 "variablesReference" => 17,
250 "name" => "Private props",
251 "value" => "class A",
252 "namedVariables" => 1,
253 "presentationHint" => darray[
254 "attributes" => varray["constant", "readOnly"]
258 // Two constants should be visible on A, HELLOA and HELLOB, and one
259 // on class B.
260 darray[
261 "variablesReference" => 18,
262 "name" => "Class Constants",
263 "value" => "class B",
264 "namedVariables" => 3,
265 "presentationHint" => darray[
266 "attributes" => varray["constant", "readOnly"]
270 darray[
271 "variablesReference" => 19,
272 "name" => "Static Props",
273 "value" => "class B",
274 "namedVariables" => 1,
275 "presentationHint" => darray[
276 "attributes" => varray["constant", "readOnly"]
282 // Check that we can see the correct properties of $aObj
283 $seq = sendVsCommand(darray[
284 "command" => "variables",
285 "type" => "request",
286 "arguments" => darray["variablesReference" => 16]]);
288 $msg = json_decode(getNextVsDebugMessage(), true);
289 checkObjEqualRecursively($msg, darray[
290 "type" => "response",
291 "command" => "variables",
292 "request_seq" => $seq,
293 "success" => true,
294 "body" => darray[
295 "variables" => varray[
296 darray[
297 "type" => "int",
298 "name" => "a",
299 "value" => "0",
300 "presentationHint" => darray[
301 "visibility" => "private"
304 darray[
305 "type" => "int",
306 "name" => "b",
307 "value" => "1",
308 "presentationHint" => darray[
309 "visibility" => "protected"
312 darray[
313 "name" => "Class Constants",
314 "value" => "class A",
315 "namedVariables" => 2,
316 "presentationHint" => darray[
317 "attributes" => varray["constant", "readOnly"]
321 darray[
322 "name" => "Static Props",
323 "value" => "class A",
324 "namedVariables" => 1,
325 "presentationHint" => darray[
326 "attributes" => varray["constant", "readOnly"]
330 ]]);
332 if (count($msg{"body"}{"variables"}) != 4) {
333 throw new UnexpectedValueException("Unexpected variable count");
336 // Correct private props of $bObj from base class A
337 $seq = sendVsCommand(darray[
338 "command" => "variables",
339 "type" => "request",
340 "arguments" => darray["variablesReference" => 17]]);
341 $msg = json_decode(getNextVsDebugMessage(), true);
342 checkObjEqualRecursively($msg, darray[
343 "type" => "response",
344 "command" => "variables",
345 "request_seq" => $seq,
346 "success" => true,
347 "body" => darray[
348 "variables" => varray[
349 darray[
350 "type" => "int",
351 "name" => "a",
352 "value" => "0",
353 "presentationHint" => darray[
354 "visibility" => "private"
358 ]]);
360 if (count($msg{"body"}{"variables"}) != 1) {
361 throw new UnexpectedValueException("Unexpected variable count");
364 // Correct statics, $bObj should see statics inherited from class A
365 $seq = sendVsCommand(darray[
366 "command" => "variables",
367 "type" => "request",
368 "arguments" => darray["variablesReference" => 19]]);
369 $msg = json_decode(getNextVsDebugMessage(), true);
370 checkObjEqualRecursively($msg, darray[
371 "type" => "response",
372 "command" => "variables",
373 "request_seq" => $seq,
374 "success" => true,
375 "body" => darray[
376 "variables" => varray[
377 darray[
378 "type" => "int",
379 "name" => "B::\$S",
380 "value" => "100",
381 "presentationHint" => darray[
382 "visibility" => "public"
386 ]]);
388 if (count($msg{"body"}{"variables"}) != 1) {
389 throw new UnexpectedValueException("Unexpected variable count");
392 // Correct class constants. Should inclide consts from A and B, sorted by name.
393 $seq = sendVsCommand(darray[
394 "command" => "variables",
395 "type" => "request",
396 "arguments" => darray["variablesReference" => 18]]);
397 $msg = json_decode(getNextVsDebugMessage(), true);
398 checkObjEqualRecursively($msg, darray[
399 "type" => "response",
400 "command" => "variables",
401 "request_seq" => $seq,
402 "success" => true,
403 "body" => darray[
404 "variables" => varray[
405 darray[
406 "type" => "string",
407 "name" => "A::HELLOA",
408 "value" => "hello0",
409 "presentationHint" => darray[
410 "attributes" => varray["constant", "readOnly"]
413 darray[
414 "type" => "string",
415 "name" => "A::HELLOB",
416 "value" => "hello0",
417 "presentationHint" => darray[
418 "attributes" => varray["constant", "readOnly"]
421 darray[
422 "type" => "string",
423 "name" => "B::HELLOB",
424 "value" => "hello1",
425 "presentationHint" => darray[
426 "attributes" => varray["constant", "readOnly"]
430 ]]);
432 if (count($msg{"body"}{"variables"}) != 3) {
433 throw new UnexpectedValueException("Unexpected variable count");
436 // Check $c, a regular array of ints.
437 $seq = sendVsCommand(darray[
438 "command" => "variables",
439 "type" => "request",
440 "arguments" => darray["variablesReference" => 12]]);
441 $msg = json_decode(getNextVsDebugMessage(), true);
442 checkObjEqualRecursively($msg, darray[
443 "type" => "response",
444 "command" => "variables",
445 "request_seq" => $seq,
446 "success" => true,
447 "body" => darray[
448 "variables" => varray[
449 darray[
450 "type" => "int",
451 "name" => "0",
452 "value" => "1"
454 darray[
455 "type" => "int",
456 "name" => "1",
457 "value" => "2"
459 darray[
460 "type" => "int",
461 "name" => "2",
462 "value" => "3"
465 ]]);
467 if (count($msg{"body"}{"variables"}) != 3) {
468 throw new UnexpectedValueException("Unexpected variable count");
471 // Ask for a subset of the array.
472 $seq = sendVsCommand(darray[
473 "command" => "variables",
474 "type" => "request",
475 "arguments" =>darray["variablesReference" => 12, "count" => 2]]);
476 $msg = json_decode(getNextVsDebugMessage(), true);
477 checkObjEqualRecursively($msg, darray[
478 "type" => "response",
479 "command" => "variables",
480 "request_seq" => $seq,
481 "success" => true,
482 "body" => darray[
483 "variables" => varray[
484 darray[
485 "type" => "int",
486 "name" => "0",
487 "value" => "1"
489 darray[
490 "type" => "int",
491 "name" => "1",
492 "value" => "2"
495 ]]);
497 if (count($msg{"body"}{"variables"}) != 2) {
498 throw new UnexpectedValueException("Unexpected variable count");
501 // Check $d, a array of arrays.
502 $seq = sendVsCommand(darray[
503 "command" => "variables",
504 "type" => "request",
505 "arguments" => darray["variablesReference" => 13]]);
506 $msg = json_decode(getNextVsDebugMessage(), true);
507 checkObjEqualRecursively($msg, darray[
508 "type" => "response",
509 "command" => "variables",
510 "request_seq" => $seq,
511 "success" => true,
512 "body" => darray[
513 "variables" => varray[
514 darray[
515 "type" => "int",
516 "name" => "0",
517 "value" => "1"
519 darray[
520 "type" => "vec",
521 "name" => "1",
522 "value" => "vec[2]",
523 "variablesReference" => 22
526 ]]);
528 if (count($msg{"body"}{"variables"}) != 2) {
529 throw new UnexpectedValueException("Unexpected variable count");
532 // check $d[1], sub array of ints.
533 $seq = sendVsCommand(darray[
534 "command" => "variables",
535 "type" => "request",
536 "arguments" => darray["variablesReference" => 22]]);
537 $msg = json_decode(getNextVsDebugMessage(), true);
538 checkObjEqualRecursively($msg, darray[
539 "type" => "response",
540 "command" => "variables",
541 "request_seq" => $seq,
542 "success" => true,
543 "body" => darray[
544 "variables" => varray[
545 darray[
546 "type" => "int",
547 "name" => "0",
548 "value" => "2"
550 darray[
551 "type" => "int",
552 "name" => "1",
553 "value" => "3"
556 ]]);
558 if (count($msg{"body"}{"variables"}) != 2) {
559 throw new UnexpectedValueException("Unexpected variable count");
562 // Check $e, array of objects
563 $seq = sendVsCommand(darray[
564 "command" => "variables",
565 "type" => "request",
566 "arguments" => darray["variablesReference" => 15]]);
567 $msg = json_decode(getNextVsDebugMessage(), true);
568 checkObjEqualRecursively($msg, darray[
569 "type" => "response",
570 "command" => "variables",
571 "request_seq" => $seq,
572 "success" => true,
573 "body" => darray[
574 "variables" => varray[
575 darray[
576 "type" => "B",
577 "name" => "0",
578 "value" => "B",
579 "variablesReference" => 14
581 darray[
582 "type" => "B",
583 "name" => "1",
584 "value" => "B",
585 "variablesReference" => 14
588 ]]);
590 if (count($msg{"body"}{"variables"}) != 2) {
591 throw new UnexpectedValueException("Unexpected variable count");
594 $seq = sendVsCommand(darray[
595 "command" => "variables",
596 "type" => "request",
597 "arguments" => darray["variablesReference" => 14]]);
599 $msg = json_decode(getNextVsDebugMessage(), true);
600 checkObjEqualRecursively($msg, darray[
601 "type" => "response",
602 "command" => "variables",
603 "request_seq" => $seq,
604 "success" => true,
605 "body" => darray[
606 "variables" => varray[
607 darray[
608 "type" => "A",
609 "name" => "aObj",
610 "value" => "A",
611 "namedVariables" => 2,
612 "variablesReference" => 16,
613 "presentationHint" => darray[
614 "visibility" => "public"
617 darray[
618 "type" => "int",
619 "name" => "b",
620 "value" => "2",
621 "presentationHint" => darray[
622 "visibility" => "protected"
625 darray[
626 "type" => "int",
627 "name" => "c",
628 "value" => "3",
629 "presentationHint" => darray[
630 "visibility" => "public"
634 // The private props should contain the base class's copy of $a, only.
635 darray[
636 "variablesReference" => 23,
637 "name" => "Private props",
638 "value" => "class A",
639 "namedVariables" => 1,
640 "presentationHint" => darray[
641 "attributes" => varray["constant", "readOnly"]
645 // Two constants should be visible on A, HELLOA and HELLOB, and one
646 // on class B.
647 darray[
648 "variablesReference" => 24,
649 "name" => "Class Constants",
650 "value" => "class B",
651 "namedVariables" => 3,
652 "presentationHint" => darray[
653 "attributes" => varray["constant", "readOnly"]
657 darray[
658 "variablesReference" => 25,
659 "name" => "Static Props",
660 "value" => "class B",
661 "namedVariables" => 1,
662 "presentationHint" => darray[
663 "attributes" => varray["constant", "readOnly"]
669 // Ask for a subset of the array. Give me index 1 only.
670 $seq = sendVsCommand(darray[
671 "command" => "variables",
672 "type" => "request",
673 "seq" => 27,
674 "arguments" => darray[
675 "variablesReference" => 12,
676 "start" => 1,
677 "count" => 1
678 ]]);
679 $msg = json_decode(getNextVsDebugMessage(), true);
680 checkObjEqualRecursively($msg, darray[
681 "type" => "response",
682 "command" => "variables",
683 "request_seq" => $seq,
684 "success" => true,
685 "body" => darray[
686 "variables" => varray[
687 darray[
688 "type" => "int",
689 "name" => "1",
690 "value" => "2"
693 ]]);
695 if (count($msg{"body"}{"variables"}) != 1) {
696 throw new UnexpectedValueException("Unexpected variable count");
699 // Subset of class constants.
700 $seq = sendVsCommand(darray[
701 "command" => "variables",
702 "type" => "request",
703 "arguments" =>
704 darray[
705 "variablesReference" => 24,
706 "start" => 1,
707 "count" => 2
708 ]]);
709 $msg = json_decode(getNextVsDebugMessage(), true);
710 checkObjEqualRecursively($msg, darray[
711 "type" => "response",
712 "command" => "variables",
713 "request_seq" => $seq,
714 "success" => true,
715 "body" => darray[
716 "variables" => varray[
717 darray[
718 "type" => "string",
719 "name" => "A::HELLOB",
720 "value" => "hello0",
721 "presentationHint" => darray[
722 "attributes" => varray["constant", "readOnly"]
725 darray[
726 "type" => "string",
727 "name" => "B::HELLOB",
728 "value" => "hello1",
729 "presentationHint" => darray[
730 "attributes" => varray["constant", "readOnly"]
734 ]]);
736 if (count($msg{"body"}{"variables"}) != 2) {
737 throw new UnexpectedValueException("Unexpected variable count");
740 // Invalid subsets.
741 $seq = sendVsCommand(darray[
742 "command" => "variables",
743 "type" => "request",
744 "arguments" =>
745 darray[
746 "variablesReference" => 24,
747 "start" => 100,
748 "count" => 1
749 ]]);
750 $msg = json_decode(getNextVsDebugMessage(), true);
751 checkObjEqualRecursively($msg, darray[
752 "type" => "response",
753 "command" => "variables",
754 "request_seq" => $seq,
755 "success" => true,
756 "body" => darray[
757 "variables" => varray[
758 darray[
759 "type" => "string",
760 "name" => "A::HELLOA",
761 "value" => "hello0",
762 "presentationHint" => darray[
763 "attributes" => varray["constant", "readOnly"]
767 ]]);
768 if (count($msg{"body"}{"variables"}) != 1) {
769 throw new UnexpectedValueException("Unexpected variable count");
772 $seq = sendVsCommand(darray[
773 "command" => "variables",
774 "type" => "request",
775 "arguments" =>
776 darray[
777 "variablesReference" => 24,
778 "start" => 1,
779 "count" => 100
780 ]]);
781 $msg = json_decode(getNextVsDebugMessage(), true);
782 checkObjEqualRecursively($msg, darray[
783 "type" => "response",
784 "command" => "variables",
785 "request_seq" => $seq,
786 "success" => true,
787 "body" => darray[
788 "variables" => varray[
789 darray[
790 "type" => "string",
791 "name" => "A::HELLOB",
792 "value" => "hello0",
793 "presentationHint" => darray[
794 "attributes" => varray["constant", "readOnly"]
797 darray[
798 "type" => "string",
799 "name" => "B::HELLOB",
800 "value" => "hello1",
801 "presentationHint" => darray[
802 "attributes" => varray["constant", "readOnly"]
806 ]]);
807 if (count($msg{"body"}{"variables"}) != 2) {
808 throw new UnexpectedValueException("Unexpected variable count");
811 resumeTarget();
813 checkForOutput($testProcess, "hello world 1\n", "stdout");
814 checkForOutput($testProcess, "hello world 2\n", "stdout");
815 vsDebugCleanup($testProcess);
817 echo "OK!\n";