-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Expand file tree
/
Copy pathTests.cs
More file actions
865 lines (746 loc) · 39.7 KB
/
Copy pathTests.cs
File metadata and controls
865 lines (746 loc) · 39.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.WebAssembly.Diagnostics;
using Newtonsoft.Json.Linq;
using Xunit;
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)]
namespace DebuggerTests
{
public class SourceList : DebuggerTestBase
{
[Fact]
public void CheckThatAllSourcesAreSent()
{
Assert.Contains("dotnet://debugger-test.dll/debugger-test.cs", scripts.Values);
Assert.Contains("dotnet://debugger-test.dll/debugger-test2.cs", scripts.Values);
Assert.Contains("dotnet://debugger-test.dll/dependency.cs", scripts.Values);
}
[Fact]
public async Task ExceptionThrownInJS()
{
var eval_req = JObject.FromObject(new
{
expression = "invoke_bad_js_test();"
});
var eval_res = await cli.SendCommand("Runtime.evaluate", eval_req, token);
Assert.True(eval_res.IsErr);
Assert.Equal("Uncaught", eval_res.Error["exceptionDetails"]?["text"]?.Value<string>());
}
[Fact]
public async Task ExceptionThrownInJSOutOfBand()
{
await SetBreakpoint("/debugger-driver.html", 27, 2);
var eval_req = JObject.FromObject(new
{
expression = "window.setTimeout(function() { invoke_bad_js_test(); }, 1);",
});
var task = insp.WaitFor("Runtime.exceptionThrown");
var eval_res = await cli.SendCommand("Runtime.evaluate", eval_req, token);
// Response here will be the id for the timer from JS!
Assert.True(eval_res.IsOk);
var ex = await Assert.ThrowsAsync<ArgumentException>(async () => await task);
var ex_json = JObject.Parse(ex.Message);
Assert.Equal(dicFileToUrl["/debugger-driver.html"], ex_json["exceptionDetails"]?["url"]?.Value<string>());
}
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task InspectLocalsAtBreakpointSite(bool use_cfo) =>
await CheckInspectLocalsAtBreakpointSite(
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8, "IntAdd",
"window.setTimeout(function() { invoke_add(); }, 1);",
use_cfo: use_cfo,
test_fn: (locals) =>
{
CheckNumber(locals, "a", 10);
CheckNumber(locals, "b", 20);
CheckNumber(locals, "c", 30);
CheckNumber(locals, "d", 0);
CheckNumber(locals, "e", 0);
}
);
[Fact]
public async Task InspectPrimitiveTypeLocalsAtBreakpointSite() =>
await CheckInspectLocalsAtBreakpointSite(
"dotnet://debugger-test.dll/debugger-test.cs", 154, 8, "PrimitiveTypesTest",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] Math:PrimitiveTypesTest'); }, 1);",
test_fn: (locals) =>
{
CheckSymbol(locals, "c0", "8364 '€'");
CheckSymbol(locals, "c1", "65 'A'");
}
);
[Fact]
public async Task InspectLocalsTypesAtBreakpointSite() =>
await CheckInspectLocalsAtBreakpointSite(
"dotnet://debugger-test.dll/debugger-test2.cs", 50, 8, "Types",
"window.setTimeout(function() { invoke_static_method (\"[debugger-test] Fancy:Types\")(); }, 1);",
use_cfo: false,
test_fn: (locals) =>
{
CheckNumber(locals, "dPI", Math.PI);
CheckNumber(locals, "fPI", (float)Math.PI);
CheckNumber(locals, "iMax", int.MaxValue);
CheckNumber(locals, "iMin", int.MinValue);
CheckNumber(locals, "uiMax", uint.MaxValue);
CheckNumber(locals, "uiMin", uint.MinValue);
CheckNumber(locals, "l", uint.MaxValue * (long)2);
//CheckNumber (locals, "lMax", long.MaxValue); // cannot be represented as double
//CheckNumber (locals, "lMin", long.MinValue); // cannot be represented as double
CheckNumber(locals, "sbMax", sbyte.MaxValue);
CheckNumber(locals, "sbMin", sbyte.MinValue);
CheckNumber(locals, "bMax", byte.MaxValue);
CheckNumber(locals, "bMin", byte.MinValue);
CheckNumber(locals, "sMax", short.MaxValue);
CheckNumber(locals, "sMin", short.MinValue);
CheckNumber(locals, "usMin", ushort.MinValue);
CheckNumber(locals, "usMax", ushort.MaxValue);
}
);
[Fact]
public async Task InspectSimpleStringLocals() =>
await CheckInspectLocalsAtBreakpointSite(
"Math", "TestSimpleStrings", 13, "TestSimpleStrings",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] Math:TestSimpleStrings')(); }, 1);",
wait_for_event_fn: async (pause_location) =>
{
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
var str_null = TString(null);
var str_empty = TString(String.Empty);
var str_spaces = TString(" ");
var str_esc = TString("\\");
await CheckProps(locals, new
{
str_null,
str_empty,
str_spaces,
str_esc,
strings = TArray("string[]", 4)
}, "locals");
var strings_arr = await GetObjectOnLocals(locals, "strings");
await CheckProps(strings_arr, new[]
{
str_null,
str_empty,
str_spaces,
str_esc
}, "locals#strings");
}
);
[Theory]
[InlineData("TestNullableLocal", false)]
[InlineData("TestNullableLocalAsync", true)]
public async Task InspectNullableLocals(string method_name, bool is_async) => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.NullableTests",
method_name,
10,
is_async ? "MoveNext" : method_name,
$"window.setTimeout(function() {{ invoke_static_method_async('[debugger-test] DebuggerTests.NullableTests:{method_name}'); }}, 1);",
wait_for_event_fn: async (pause_location) =>
{
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
var dt = new DateTime(2310, 1, 2, 3, 4, 5);
await CheckProps(locals, new
{
n_int = TNumber(5),
n_int_null = TObject("System.Nullable<int>", null),
n_dt = TDateTime(dt),
n_dt_null = TObject("System.Nullable<System.DateTime>", null),
n_gs = TValueType("DebuggerTests.ValueTypesTest.GenericStruct<int>"),
n_gs_null = TObject("System.Nullable<DebuggerTests.ValueTypesTest.GenericStruct<int>>", null),
}, "locals");
// check gs
var n_gs = GetAndAssertObjectWithName(locals, "n_gs");
var n_gs_props = await GetProperties(n_gs["value"]?["objectId"]?.Value<string>());
await CheckProps(n_gs_props, new
{
List = TObject("System.Collections.Generic.List<int>", is_null: true),
StringField = TString("n_gs#StringField"),
Options = TEnum("DebuggerTests.Options", "None")
}, nameof(n_gs));
});
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task InspectLocalsWithGenericTypesAtBreakpointSite(bool use_cfo) =>
await CheckInspectLocalsAtBreakpointSite(
"dotnet://debugger-test.dll/debugger-test.cs", 74, 8, "GenericTypesTest",
"window.setTimeout(function() { invoke_generic_types_test (); }, 1);",
use_cfo: use_cfo,
test_fn: (locals) =>
{
CheckObject(locals, "list", "System.Collections.Generic.Dictionary<Math[], Math.IsMathNull>", description: "Count = 0");
CheckObject(locals, "list_null", "System.Collections.Generic.Dictionary<Math[], Math.IsMathNull>", is_null: true);
CheckArray(locals, "list_arr", "System.Collections.Generic.Dictionary<Math[], Math.IsMathNull>[]", 1);
CheckObject(locals, "list_arr_null", "System.Collections.Generic.Dictionary<Math[], Math.IsMathNull>[]", is_null: true);
// Unused locals
CheckObject(locals, "list_unused", "System.Collections.Generic.Dictionary<Math[], Math.IsMathNull>", description: "Count = 0");
CheckObject(locals, "list_null_unused", "System.Collections.Generic.Dictionary<Math[], Math.IsMathNull>", is_null: true);
CheckArray(locals, "list_arr_unused", "System.Collections.Generic.Dictionary<Math[], Math.IsMathNull>[]", 1);
CheckObject(locals, "list_arr_null_unused", "System.Collections.Generic.Dictionary<Math[], Math.IsMathNull>[]", is_null: true);
}
);
[Fact]
public async Task RuntimeGetPropertiesWithInvalidScopeIdTest()
{
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 49, 8);
await EvaluateAndCheck(
"window.setTimeout(function() { invoke_delegates_test (); }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", 49, 8,
"DelegatesTest",
wait_for_event_fn: async (pause_location) =>
{
//make sure we're on the right bp
Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
var top_frame = pause_location["callFrames"][0];
var scope = top_frame["scopeChain"][0];
// Try to get an invalid scope!
var get_prop_req = JObject.FromObject(new
{
objectId = "dotnet:scope:23490871",
});
var frame_props = await cli.SendCommand("Runtime.getProperties", get_prop_req, token);
Assert.True(frame_props.IsErr);
}
);
}
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task InspectLocalsWithStructs(bool use_cfo)
{
UseCallFunctionOnBeforeGetProperties = use_cfo;
var debugger_test_loc = "dotnet://debugger-test.dll/debugger-valuetypes-test.cs";
await SetBreakpoint(debugger_test_loc, 24, 8);
var pause_location = await EvaluateAndCheck(
"window.setTimeout(function() { invoke_method_with_structs(); }, 1);",
debugger_test_loc, 24, 8, "MethodWithLocalStructs");
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
await CheckProps(locals, new
{
ss_local = TValueType("DebuggerTests.ValueTypesTest.SimpleStruct"),
gs_local = TValueType("DebuggerTests.ValueTypesTest.GenericStruct<DebuggerTests.ValueTypesTest>"),
vt_local = TObject("DebuggerTests.ValueTypesTest")
}, "locals");
var dt = new DateTime(2021, 2, 3, 4, 6, 7);
var vt_local_props = await GetObjectOnFrame(pause_location["callFrames"][0], "vt_local");
Assert.Equal(5, vt_local_props.Count());
CheckString(vt_local_props, "StringField", "string#0");
CheckValueType(vt_local_props, "SimpleStructField", "DebuggerTests.ValueTypesTest.SimpleStruct");
CheckValueType(vt_local_props, "SimpleStructProperty", "DebuggerTests.ValueTypesTest.SimpleStruct");
await CheckDateTime(vt_local_props, "DT", new DateTime(2020, 1, 2, 3, 4, 5));
CheckEnum(vt_local_props, "RGB", "DebuggerTests.RGB", "Blue");
// Check ss_local's properties
var ss_local_props = await GetObjectOnFrame(pause_location["callFrames"][0], "ss_local");
await CheckProps(ss_local_props, new
{
V = TGetter("V"),
str_member = TString("set in MethodWithLocalStructs#SimpleStruct#str_member"),
dt = TDateTime(dt),
gs = TValueType("DebuggerTests.ValueTypesTest.GenericStruct<System.DateTime>"),
Kind = TEnum("System.DateTimeKind", "Utc")
}, "ss_local");
{
var gres = await InvokeGetter(GetAndAssertObjectWithName(locals, "ss_local"), "V");
await CheckValue(gres.Value["result"], TNumber(0xDEADBEEF + 2), $"ss_local#V");
// Check ss_local.gs
var gs_props = await GetObjectOnLocals(ss_local_props, "gs");
CheckString(gs_props, "StringField", "set in MethodWithLocalStructs#SimpleStruct#gs#StringField");
CheckObject(gs_props, "List", "System.Collections.Generic.List<System.DateTime>", description: "Count = 1");
}
// Check gs_local's properties
var gs_local_props = await GetObjectOnFrame(pause_location["callFrames"][0], "gs_local");
await CheckProps(gs_local_props, new
{
StringField = TString("gs_local#GenericStruct<ValueTypesTest>#StringField"),
List = TObject("System.Collections.Generic.List<DebuggerTests.ValueTypesTest>", is_null: true),
Options = TEnum("DebuggerTests.Options", "None")
}, "gs_local");
// Check vt_local's properties
var exp = new[]
{
("SimpleStructProperty", 2, "Utc"),
("SimpleStructField", 5, "Local")
};
foreach (var (name, bias, dt_kind) in exp)
{
dt = new DateTime(2020 + bias, 1 + bias, 2 + bias, 3 + bias, 5 + bias, 6 + bias);
await CompareObjectPropertiesFor(vt_local_props, name,
new
{
V = TGetter("V"),
str_member = TString($"{name}#string#0#SimpleStruct#str_member"),
dt = TDateTime(dt),
gs = TValueType("DebuggerTests.ValueTypesTest.GenericStruct<System.DateTime>"),
Kind = TEnum("System.DateTimeKind", dt_kind)
},
label: $"vt_local_props.{name}");
var gres = await InvokeGetter(GetAndAssertObjectWithName(vt_local_props, name), "V");
await CheckValue(gres.Value["result"], TNumber(0xDEADBEEF + (uint)dt.Month), $"{name}#V");
}
// FIXME: check ss_local.gs.List's members
}
[Theory]
[InlineData("BoxingTest", false)]
[InlineData("BoxingTestAsync", true)]
public async Task InspectBoxedLocals(string method_name, bool is_async) => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTest",
method_name,
17,
is_async ? "MoveNext" : method_name,
$"window.setTimeout(function() {{ invoke_static_method_async('[debugger-test] DebuggerTest:{method_name}'); }}, 1);",
wait_for_event_fn: async (pause_location) =>
{
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
var dt = new DateTime(2310, 1, 2, 3, 4, 5);
await CheckProps(locals, new
{
n_i = TNumber(5),
o_i = TNumber(5),
o_n_i = TNumber(5),
o_s = TString("foobar"),
o_obj = TObject("Math"),
n_gs = TValueType("DebuggerTests.ValueTypesTest.GenericStruct<int>"),
o_gs = TValueType("DebuggerTests.ValueTypesTest.GenericStruct<int>"),
o_n_gs = TValueType("DebuggerTests.ValueTypesTest.GenericStruct<int>"),
n_dt = TDateTime(dt),
o_dt = TDateTime(dt),
o_n_dt = TDateTime(dt),
o_null = TObject("object", is_null: true),
o_ia = TArray("int[]", 2),
}, "locals");
foreach (var name in new[] { "n_gs", "o_gs", "o_n_gs" })
{
var gs = GetAndAssertObjectWithName(locals, name);
var gs_props = await GetProperties(gs["value"]?["objectId"]?.Value<string>());
await CheckProps(gs_props, new
{
List = TObject("System.Collections.Generic.List<int>", is_null: true),
StringField = TString("n_gs#StringField"),
Options = TEnum("DebuggerTests.Options", "None")
}, name);
}
var o_ia_props = await GetObjectOnLocals(locals, "o_ia");
await CheckProps(o_ia_props, new[]
{
TNumber(918),
TNumber(58971)
}, nameof(o_ia_props));
});
[Theory]
[InlineData("BoxedTypeObjectTest", false)]
[InlineData("BoxedTypeObjectTestAsync", true)]
public async Task InspectBoxedTypeObject(string method_name, bool is_async) => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTest",
method_name,
9,
is_async ? "MoveNext" : method_name,
$"window.setTimeout(function() {{ invoke_static_method_async('[debugger-test] DebuggerTest:{method_name}'); }}, 1);",
wait_for_event_fn: async (pause_location) =>
{
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
var dt = new DateTime(2310, 1, 2, 3, 4, 5);
await CheckProps(locals, new
{
i = TNumber(5),
o0 = TNumber(5),
o1 = TNumber(5),
o2 = TNumber(5),
o3 = TNumber(5),
oo = TObject("object"),
oo0 = TObject("object"),
}, "locals");
});
[Theory]
[InlineData("BoxedAsClass", false)]
[InlineData("BoxedAsClassAsync", true)]
public async Task InspectBoxedAsClassLocals(string method_name, bool is_async) => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTest",
method_name,
6,
is_async ? "MoveNext" : method_name,
$"window.setTimeout(function() {{ invoke_static_method_async('[debugger-test] DebuggerTest:{method_name}'); }}, 1);",
wait_for_event_fn: async (pause_location) =>
{
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
var dt = new DateTime(2310, 1, 2, 3, 4, 5);
Console.WriteLine(locals);
await CheckProps(locals, new
{
vt_dt = TDateTime(new DateTime(4819, 5, 6, 7, 8, 9)),
vt_gs = TValueType("Math.GenericStruct<string>"),
e = TEnum("System.IO.FileMode", "0"),
ee = TEnum("System.IO.FileMode", "Append")
}, "locals");
});
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task InspectLocalsWithStructsStaticAsync(bool use_cfo)
{
UseCallFunctionOnBeforeGetProperties = use_cfo;
var debugger_test_loc = "dotnet://debugger-test.dll/debugger-valuetypes-test.cs";
await SetBreakpoint(debugger_test_loc, 54, 12);
var pause_location = await EvaluateAndCheck(
"window.setTimeout(function() { invoke_static_method_async (" +
"'[debugger-test] DebuggerTests.ValueTypesTest:MethodWithLocalStructsStaticAsync'" +
"); }, 1);",
debugger_test_loc, 54, 12, "MoveNext"); //BUG: method name
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
await CheckProps(locals, new
{
ss_local = TObject("DebuggerTests.ValueTypesTest.SimpleStruct"),
gs_local = TValueType("DebuggerTests.ValueTypesTest.GenericStruct<int>"),
result = TBool(true)
},
"locals#0");
var dt = new DateTime(2021, 2, 3, 4, 6, 7);
// Check ss_local's properties
var ss_local_props = await GetObjectOnFrame(pause_location["callFrames"][0], "ss_local");
await CheckProps(ss_local_props, new
{
V = TGetter("V"),
str_member = TString("set in MethodWithLocalStructsStaticAsync#SimpleStruct#str_member"),
dt = TDateTime(dt),
gs = TValueType("DebuggerTests.ValueTypesTest.GenericStruct<System.DateTime>"),
Kind = TEnum("System.DateTimeKind", "Utc")
}, "ss_local");
{
var gres = await InvokeGetter(GetAndAssertObjectWithName(locals, "ss_local"), "V");
await CheckValue(gres.Value["result"], TNumber(0xDEADBEEF + 2), $"ss_local#V");
// Check ss_local.gs
await CompareObjectPropertiesFor(ss_local_props, "gs",
new
{
StringField = TString("set in MethodWithLocalStructsStaticAsync#SimpleStruct#gs#StringField"),
List = TObject("System.Collections.Generic.List<System.DateTime>", description: "Count = 1"),
Options = TEnum("DebuggerTests.Options", "Option1")
}
);
}
// Check gs_local's properties
var gs_local_props = await GetObjectOnFrame(pause_location["callFrames"][0], "gs_local");
await CheckProps(gs_local_props, new
{
StringField = TString("gs_local#GenericStruct<ValueTypesTest>#StringField"),
List = TObject("System.Collections.Generic.List<int>", description: "Count = 2"),
Options = TEnum("DebuggerTests.Options", "Option2")
}, "gs_local");
// FIXME: check ss_local.gs.List's members
}
[Theory]
[InlineData(137, 12, "MethodWithLocalsForToStringTest", false, false)]
[InlineData(147, 12, "MethodWithArgumentsForToStringTest", true, false)]
[InlineData(192, 12, "MethodWithArgumentsForToStringTestAsync", true, true)]
[InlineData(182, 12, "MethodWithArgumentsForToStringTestAsync", false, true)]
public async Task InspectLocalsForToStringDescriptions(int line, int col, string method_name, bool call_other, bool invoke_async)
{
string entry_method_name = $"[debugger-test] DebuggerTests.ValueTypesTest:MethodWithLocalsForToStringTest{(invoke_async ? "Async" : String.Empty)}";
int frame_idx = 0;
var debugger_test_loc = "dotnet://debugger-test.dll/debugger-valuetypes-test.cs";
await SetBreakpoint(debugger_test_loc, line, col);
var eval_expr = "window.setTimeout(function() {" +
(invoke_async ? "invoke_static_method_async (" : "invoke_static_method (") +
$"'{entry_method_name}'," +
(call_other ? "true" : "false") +
"); }, 1);";
Console.WriteLine($"{eval_expr}");
var pause_location = await EvaluateAndCheck(eval_expr, debugger_test_loc, line, col, invoke_async ? "MoveNext" : method_name);
var dt0 = new DateTime(2020, 1, 2, 3, 4, 5);
var dt1 = new DateTime(2010, 5, 4, 3, 2, 1);
var ts = dt0 - dt1;
var dto = new DateTimeOffset(dt0, new TimeSpan(4, 5, 0));
var frame_locals = await GetProperties(pause_location["callFrames"][frame_idx]["callFrameId"].Value<string>());
await CheckProps(frame_locals, new
{
call_other = TBool(call_other),
dt0 = TDateTime(dt0),
dt1 = TDateTime(dt1),
dto = TValueType("System.DateTimeOffset", dto.ToString()),
ts = TValueType("System.TimeSpan", ts.ToString()),
dec = TValueType("System.Decimal", "123987123"),
guid = TValueType("System.Guid", "3D36E07E-AC90-48C6-B7EC-A481E289D014"),
dts = TArray("System.DateTime[]", 2),
obj = TObject("DebuggerTests.ClassForToStringTests"),
sst = TObject("DebuggerTests.StructForToStringTests")
}, "locals#0");
var dts_0 = new DateTime(1983, 6, 7, 5, 6, 10);
var dts_1 = new DateTime(1999, 10, 15, 1, 2, 3);
var dts_elements = await GetObjectOnLocals(frame_locals, "dts");
await CheckDateTime(dts_elements, "0", dts_0);
await CheckDateTime(dts_elements, "1", dts_1);
// TimeSpan
await CompareObjectPropertiesFor(frame_locals, "ts",
new
{
Days = TNumber(3530),
Minutes = TNumber(2),
Seconds = TNumber(4),
}, "ts_props", num_fields: 12);
// DateTimeOffset
await CompareObjectPropertiesFor(frame_locals, "dto",
new
{
Day = TNumber(2),
Year = TNumber(2020),
DayOfWeek = TEnum("System.DayOfWeek", "Thursday")
}, "dto_props", num_fields: 20);
var DT = new DateTime(2004, 10, 15, 1, 2, 3);
var DTO = new DateTimeOffset(dt0, new TimeSpan(2, 14, 0));
await CompareObjectPropertiesFor(frame_locals, "obj",
new
{
DT = TDateTime(DT),
DTO = TValueType("System.DateTimeOffset", DTO.ToString()),
TS = TValueType("System.TimeSpan", ts.ToString()),
Dec = TValueType("System.Decimal", "1239871"),
Guid = TValueType("System.Guid", "3D36E07E-AC90-48C6-B7EC-A481E289D014")
}, "obj_props");
DTO = new DateTimeOffset(dt0, new TimeSpan(3, 15, 0));
var sst_props = await CompareObjectPropertiesFor(frame_locals, "sst",
new
{
DT = TDateTime(DT),
DTO = TValueType("System.DateTimeOffset", DTO.ToString()),
TS = TValueType("System.TimeSpan", ts.ToString()),
Dec = TValueType("System.Decimal", "1239871"),
Guid = TValueType("System.Guid", "3D36E07E-AC90-48C6-B7EC-A481E289D014")
}, "sst_props");
}
[Fact]
public async Task InspectLocals()
{
var wait_res = await RunUntil("locals_inner");
var locals = await GetProperties(wait_res["callFrames"][1]["callFrameId"].Value<string>());
}
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task InspectLocalsForStructInstanceMethod(bool use_cfo) => await CheckInspectLocalsAtBreakpointSite(
"dotnet://debugger-test.dll/debugger-array-test.cs", 258, 12,
"GenericInstanceMethod<DebuggerTests.SimpleClass>",
"window.setTimeout(function() { invoke_static_method_async ('[debugger-test] DebuggerTests.EntryClass:run'); })",
use_cfo: use_cfo,
wait_for_event_fn: async (pause_location) =>
{
var frame_locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
await CheckProps(frame_locals, new
{
sc_arg = TObject("DebuggerTests.SimpleClass"),
@this = TValueType("DebuggerTests.Point"),
local_gs = TValueType("DebuggerTests.SimpleGenericStruct<int>")
},
"locals#0");
await CompareObjectPropertiesFor(frame_locals, "local_gs",
new
{
Id = TString("local_gs#Id"),
Color = TEnum("DebuggerTests.RGB", "Green"),
Value = TNumber(4)
},
label: "local_gs#0");
await CompareObjectPropertiesFor(frame_locals, "sc_arg",
TSimpleClass(10, 45, "sc_arg#Id", "Blue"),
label: "sc_arg#0");
await CompareObjectPropertiesFor(frame_locals, "this",
TPoint(90, -4, "point#Id", "Green"),
label: "this#0");
});
[Fact]
public async Task MulticastDelegateTest() => await CheckInspectLocalsAtBreakpointSite(
"MulticastDelegateTestClass", "Test", 5, "Test",
"window.setTimeout(function() { invoke_static_method('[debugger-test] MulticastDelegateTestClass:run'); })",
wait_for_event_fn: async (pause_location) =>
{
var frame_locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
var this_props = await GetObjectOnLocals(frame_locals, "this");
await CheckProps(this_props, new
{
TestEvent = TSymbol("System.EventHandler<string>"),
Delegate = TSymbol("System.MulticastDelegate")
}, "this_props");
});
[Theory]
[InlineData("EmptyClass", false)]
[InlineData("EmptyClass", true)]
[InlineData("EmptyStruct", false)]
[InlineData("EmptyStruct", true)]
public async Task EmptyTypeWithNoLocalsOrParams(string type_name, bool is_async) => await CheckInspectLocalsAtBreakpointSite(
type_name,
$"StaticMethodWithNoLocals{ (is_async ? "Async" : "") }",
1,
is_async ? "MoveNext" : "StaticMethodWithNoLocals",
$"window.setTimeout(function() {{ invoke_static_method('[debugger-test] {type_name}:run'); }})",
wait_for_event_fn: async (pause_location) =>
{
var frame_locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
AssertEqual(0, frame_locals.Values<JToken>().Count(), "locals");
});
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task StaticMethodWithLocalEmptyStructThatWillGetExpanded(bool is_async) => await CheckInspectLocalsAtBreakpointSite(
"EmptyStruct",
$"StaticMethodWithLocalEmptyStruct{ (is_async ? "Async" : "") }",
1,
is_async ? "MoveNext" : "StaticMethodWithLocalEmptyStruct",
$"window.setTimeout(function() {{ invoke_static_method('[debugger-test] EmptyStruct:run'); }})",
wait_for_event_fn: async (pause_location) =>
{
var frame_locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
await CheckProps(frame_locals, new
{
es = TValueType("EmptyStruct")
}, "locals");
var es = GetAndAssertObjectWithName(frame_locals, "es");
var es_props = await GetProperties(es["value"]["objectId"]?.Value<string>());
AssertEqual(0, es_props.Values<JToken>().Count(), "es_props");
});
[Fact]
public async Task PreviousFrameForAReflectedCall() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.GetPropertiesTests.CloneableStruct", "SimpleStaticMethod", 1, "SimpleStaticMethod",
"window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerTests.GetPropertiesTests.TestWithReflection:run'); })",
wait_for_event_fn: async (pause_location) =>
{
var frame = FindFrame(pause_location, "InvokeReflectedStaticMethod");
Assert.NotNull(frame);
var frame_locals = await GetProperties(frame["callFrameId"].Value<string>());
await CheckProps(frame_locals, new
{
mi = TObject("System.Reflection.RuntimeMethodInfo"), //this is what is returned when debugging desktop apps using VS
dt = TDateTime(new DateTime(4210, 3, 4, 5, 6, 7)),
i = TNumber(4),
strings = TArray("string[]", 1),
cs = TValueType("DebuggerTests.GetPropertiesTests.CloneableStruct"),
num = TNumber(10),
name = TString("foobar"),
some_date = TDateTime(new DateTime(1234, 6, 7, 8, 9, 10)),
num1 = TNumber(100),
str2 = TString("xyz"),
num3 = TNumber(345),
str3 = TString("abc")
}, "InvokeReflectedStaticMethod#locals");
});
JObject FindFrame(JObject pause_location, string function_name)
=> pause_location["callFrames"]
?.Values<JObject>()
?.Where(f => f["functionName"]?.Value<string>() == function_name)
?.FirstOrDefault();
[Fact]
public async Task DebugLazyLoadedAssemblyWithPdb()
{
int line = 9;
await SetBreakpoint(".*/lazy-debugger-test.cs$", line, 0, use_regex: true);
await LoadAssemblyDynamically(
Path.Combine(DebuggerTestAppPath, "lazy-debugger-test.dll"),
Path.Combine(DebuggerTestAppPath, "lazy-debugger-test.pdb"));
var source_location = "dotnet://lazy-debugger-test.dll/lazy-debugger-test.cs";
Assert.Contains(source_location, scripts.Values);
System.Threading.Thread.Sleep(1000);
var pause_location = await EvaluateAndCheck(
"window.setTimeout(function () { invoke_static_method('[lazy-debugger-test] LazyMath:IntAdd', 5, 10); }, 1);",
source_location, line, 8,
"IntAdd");
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
CheckNumber(locals, "a", 5);
CheckNumber(locals, "b", 10);
}
[Fact]
public async Task DebugLazyLoadedAssemblyWithEmbeddedPdb()
{
int line = 9;
await SetBreakpoint(".*/lazy-debugger-test-embedded.cs$", line, 0, use_regex: true);
await LoadAssemblyDynamically(
Path.Combine(DebuggerTestAppPath, "lazy-debugger-test-embedded.dll"),
null);
var source_location = "dotnet://lazy-debugger-test-embedded.dll/lazy-debugger-test-embedded.cs";
Assert.Contains(source_location, scripts.Values);
var pause_location = await EvaluateAndCheck(
"window.setTimeout(function () { invoke_static_method('[lazy-debugger-test-embedded] LazyMath:IntAdd', 5, 10); }, 1);",
source_location, line, 8,
"IntAdd");
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
CheckNumber(locals, "a", 5);
CheckNumber(locals, "b", 10);
}
[Fact]
public async Task DebugLazyLoadedAssemblyWithEmbeddedPdbALC()
{
int line = 9;
await SetBreakpoint(".*/lazy-debugger-test-embedded.cs$", line, 0, use_regex: true);
var pause_location = await LoadAssemblyDynamicallyALCAndRunMethod(
Path.Combine(DebuggerTestAppPath, "lazy-debugger-test-embedded.dll"),
null, "LazyMath", "IntAdd");
var source_location = "dotnet://lazy-debugger-test-embedded.dll/lazy-debugger-test-embedded.cs";
Assert.Contains(source_location, scripts.Values);
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
CheckNumber(locals, "a", 5);
CheckNumber(locals, "b", 10);
}
[Fact]
public async Task CannotDebugLazyLoadedAssemblyWithoutPdb()
{
int line = 9;
await SetBreakpoint(".*/lazy-debugger-test.cs$", line, 0, use_regex: true);
await LoadAssemblyDynamically(
Path.Combine(DebuggerTestAppPath, "lazy-debugger-test.dll"),
null);
// wait to bit to catch if the event might be raised a bit late
await Task.Delay(1000);
var source_location = "dotnet://lazy-debugger-test.dll/lazy-debugger-test.cs";
Assert.DoesNotContain(source_location, scripts.Values);
}
[Fact]
public async Task GetSourceUsingSourceLink()
{
var bp = await SetBreakpointInMethod("debugger-test-with-source-link.dll", "DebuggerTests.ClassToBreak", "TestBreakpoint", 0);
var pause_location = await EvaluateAndCheck(
"window.setTimeout(function() { invoke_static_method ('[debugger-test-with-source-link] DebuggerTests.ClassToBreak:TestBreakpoint'); }, 1);",
"dotnet://debugger-test-with-source-link.dll/test.cs",
bp.Value["locations"][0]["lineNumber"].Value<int>(),
bp.Value["locations"][0]["columnNumber"].Value<int>(),
"TestBreakpoint");
var sourceToGet = JObject.FromObject(new
{
scriptId = pause_location["callFrames"][0]["functionLocation"]["scriptId"].Value<string>()
});
var source = await cli.SendCommand("Debugger.getScriptSource", sourceToGet, token);
Assert.True(source.IsOk);
}
[Fact]
public async Task InspectTaskAtLocals() => await CheckInspectLocalsAtBreakpointSite(
"InspectTask",
"RunInspectTask",
10,
"<RunInspectTask>b__0" ,
$"window.setTimeout(function() {{ invoke_static_method_async('[debugger-test] InspectTask:RunInspectTask'); }}, 1);",
wait_for_event_fn: async (pause_location) =>
{
var locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
CheckNumber(locals, "a", 10);
var t_props = await GetObjectOnLocals(locals, "t");
await CheckProps(t_props, new
{
Status = TGetter("Status")
}, "t_props", num_fields: 53);
});
[Fact]
public async Task InspectLocalsWithIndexAndPositionWithDifferentValues() //https://github.com/xamarin/xamarin-android/issues/6161
{
await EvaluateAndCheck(
"window.setTimeout(function() { invoke_static_method('[debugger-test] MainPage:CallSetValue'); }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", 758, 16,
"set_SomeValue",
locals_fn: (locals) =>
{
CheckNumber(locals, "view", 150);
}
);
}
//TODO add tests covering basic stepping behavior as step in/out/over
}
}