forked from mayhemer/logan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logan.js
1650 lines (1385 loc) · 46 KB
/
logan.js
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
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const LOG = false ? (output) => { console.log(output) } : () => { };
var logan = null;
Array.prototype.last = function() {
if (!this.length) {
return undefined;
}
return this[this.length - 1];
};
Array.prototype.remove = function(finder) {
let index = this.findIndex(finder);
if (index > -1) {
this.splice(index, 1);
}
};
Array.prototype.after = function(element, finder) {
let index = this.findIndex(finder);
if (index > -1) {
this.splice(index + 1, 0, element);
} else {
this.push(element);
}
};
Array.prototype.before = function(element, finder) {
let index = this.findIndex(finder);
if (index > -1) {
this.splice(index, 0, element);
} else {
this.unshift(element);
}
};
function ensure(array, itemName, def = {}) {
if (!(itemName in array)) {
array[itemName] = (typeof def === "function") ? def() : def;
}
return array[itemName];
}
function Bag(def = {}) {
for (let prop in def) {
this[prop] = def[prop];
}
}
Bag.prototype.on = function(prop, handler, elseHandler) {
if (!this[prop]) {
if (elseHandler) {
return elseHandler();
}
return undefined;
}
let val = handler(this[prop], this);
if (val) {
return (this[prop] = val);
}
delete this[prop];
};
Bag.prototype.data = function(name, key) {
let map = ensure(this, name, {});
return ensure(map, key, () => new Bag());
};
class Stringifier {
// map = { HumanReadableIdentifier: numeric-value, ... };
constructor(map) {
this.map = {};
for (let term in map) {
this[term] = map[term];
this.map[map[term]] = term + "";
}
}
}
class Enum extends Stringifier {
$(numeric, radix = 16) {
if (typeof numeric === "string") {
numeric = parseInt(numeric, radix);
}
return this.map[numeric] || numeric;
}
}
class Flags extends Stringifier {
$(numeric, radix = 10) {
if (typeof numeric === "string") {
numeric = parseInt(numeric, radix);
}
if (numeric == 0) {
return "0";
}
let result = "";
for (let flag in this.map) {
if (flag & numeric) {
if (result) {
result += ", ";
}
result += this.map[flag];
numeric &= ~flag;
}
}
return result + (numeric ? ` [unknow bits=${numeric.toString(2)}b]` : "");
}
}
const GREP_REGEXP = new RegExp("((?:0x)?[A-Fa-f0-9]{4,})", "g");
const POINTER_REGEXP = /^(?:0x)?0*([0-9A-Fa-f]+)$/;
const NULLPTR_REGEXP = /^(?:(?:0x)?0+|\(null\)|\(nil\))$/;
const CAPTURED_LINE_LABEL = "a log line";
const EPOCH_1970 = new Date("1970-01-01");
// Windows sometimes writes %p as upper-case-padded and sometimes as lower-case-unpadded
// 000001500B043028 -> 1500b043000
function pointerTrim(ptr) {
if (!ptr) {
return "0";
}
let pointer = ptr.match(POINTER_REGEXP);
if (pointer) {
return pointer[1].toLowerCase();
}
return ptr;
}
(function() {
// Configuration of the internals
const FILE_SLICE = 1 * 1024 * 1024;
const USE_RULES_TREE_OPTIMIZATION = true;
const ALLOW_NON_POINTER_ALIAS_GREPING = true;
const BLOCK_READING_ON_RECV_WAIT = true;
// ------------------------------
let IF_RULE_INDEXER = 0;
function isChildFile(file) {
return file.name.match(/[-\.]child[-\.]/);
}
function isRotateFile(file) {
return file.name.match(/^(.*)\.\d+$/);
}
function rotateFileBaseName(file) {
let baseName = isRotateFile(file);
if (baseName) {
return baseName[1];
}
return file.name;
}
function isZipFile(file) {
return file.name.match(/\.zip$/);
}
function escapeRegexp(s) {
return s.replace(/\n$/, "").replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
function unescapeRegexp(s) {
return s.replace(/\\([\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|])/g, "$1");
}
const printfToRegexpMap = [
// IMPORTANT!!!
// Use \\\ to escape regexp special characters in the match regexp (left),
// we escapeRegexp() the string prior to this conversion which adds
// a '\' before each of such chars.
[/%p/g, "((?:(?:0x)?[A-Fa-f0-9]+)|(?:\\(null\\))|(?:\\(nil\\)))"],
[/%d/g, "(-?[\\d]+)"],
[/%[hz]?u/g, "([\\d]+)"],
[/%s/g, "([^\\s]*)"],
[/%\\\*\\\$/g, "(.*$)"],
[/%\\\*/g, "(.*)"], // this must process after %*$ because this one is more general
[/%\d*[xX]/g, "((?:0x)?[A-Fa-f0-9]+)"],
[/%(?:\d+\\\.\d+)?f/g, "((?:[\\d]+)\.(?:[\\d]+))"],
[/%\\\/(.*)\\\/r/g, (m, p1) => "(" + unescapeRegexp(p1) + ")"]
];
function convertPrintfToRegexp(printf) {
if (RegExp.prototype.isPrototypeOf(printf)) {
// already converted
return printf;
}
let input = printf;
printf = escapeRegexp(printf);
for (let [source, target] of printfToRegexpMap) {
printf = printf.replace(source, target);
}
printf = '^' + printf + '$';
LOG("input '" + input + "' \nregexp '" + printf + "'");
return new RegExp(printf);
}
function ruleMappingGrade1(input) {
let splitter = /(\W)/;
let grade1 = input.split(splitter, 1)[0];
if (!grade1 || grade1.match(/%/g)) {
// grade1 contains a dynamic part or is empty, use the whole input as mapping
// this is specially handled in module.set_rule
return input;
}
return grade1;
}
function ruleMappingGrade2(input) {
let grade1 = ruleMappingGrade1(input);
let grade2 = input.substring(grade1.length);
return { grade1, grade2 };
}
function Schema(namespace, preparer) {
this.namespace = namespace;
this.preparer = preparer;
this.modules = {};
this.unmatch = [];
this._finalize = function() {
if (USE_RULES_TREE_OPTIMIZATION) {
for (let module of Object.values(this.modules)) {
for (let grade1 in module.rules_tree) {
module.rules_tree[grade1] = Object.values(module.rules_tree[grade1]);
}
}
}
// This is grep() handler, has to be added as last because its condition handler
// never returns true making following conditional rules process the line as well.
this.plainIf(function(state) {
for (let regexp of [GREP_REGEXP, logan._proc.nonPtrAliases]) {
if (!regexp) {
break;
}
let pointers = state.line.match(regexp);
if (pointers) {
if (pointers.length === 1 && state.line.trim() == pointers[0]) {
// It doesn't make sense to include lines only containing the pointer.
// TODO the condition here should be made even smarter to filter out
// more of just useless lines.
break;
}
for (let ptr of pointers) {
let obj = state.objs[pointerTrim(ptr)];
if (obj && obj._grep === state.schema) {
obj.capture();
}
}
}
}
}.bind(this), () => { throw "grep() internal consumer should never be called"; });
};
}
Schema.prototype.module = function(name, builder) {
builder(ensure(this.modules, name, new Module(name)));
}
Schema.prototype.plainIf = function(condition, consumer) {
let rule = { cond: condition, consumer: consumer, id: ++IF_RULE_INDEXER };
this.unmatch.push(rule);
return rule;
};
Schema.prototype.ruleIf = function(exp, condition, consumer) {
let rule = { regexp: convertPrintfToRegexp(exp), cond: condition, consumer: consumer, id: ++IF_RULE_INDEXER };
this.unmatch.push(rule);
return rule;
};
Schema.prototype.removeIf = function(rule) {
this.unmatch.remove(item => item.id === rule.id);
}
function Module(name) {
this.name = name;
this.rules_flat = [];
this.rules_tree = {};
this.set_rule = function(rule, input) {
if (USE_RULES_TREE_OPTIMIZATION) {
let mapping = ruleMappingGrade2(input);
if (mapping.grade2) {
let grade2 = ensure(this.rules_tree, mapping.grade1, {});
grade2[mapping.grade2] = rule;
} else {
// all one-grade rules go alone, to allow dynamic parts to be at the begining of rules
this.rules_flat.push(rule);
}
} else {
this.rules_flat.push(rule);
}
};
this.get_rules = function(input) {
if (USE_RULES_TREE_OPTIMIZATION) {
// logan.init() converts rules_tree to array.
return (this.rules_tree[ruleMappingGrade1(input)] || []).concat(this.rules_flat);
}
return this.rules_flat;
};
}
Module.prototype.rule = function(exp, consumer = function(ptr) { this.obj(ptr).capture(); }) {
this.set_rule({ regexp: convertPrintfToRegexp(exp), cond: null, consumer: consumer }, exp);
};
Module.prototype.ruleIf = function(exp, condition, consumer) {
this.set_rule({ regexp: convertPrintfToRegexp(exp), cond: condition, consumer: consumer }, exp);
};
function Obj(ptr, factual) {
this.factual = factual;
this.id = this.factual ? logan.objects.length : -1;
// NOTE: when this list is enhanced, UI.summary has to be updated the "collect properties manually" section
// NOTE: ordernum is only temporary
this.props = new Bag({ pointer: ptr, className: null, ordernum: this.id + 1000000 });
this.captures = [];
this.aliases = {};
this.destroyed = null;
this._grep = false;
// This is used for placing the summary of the object (to generate
// the unique ordered position, see UI.position.)
// Otherwise there would be no other way than to use the first capture
// that would lead to complicated duplications.
this.placement = new Capture({ placement: this, });
this.placement.time = logan._proc.timestamp;
this.placement.file = logan._proc.file;
this._class = function(className) {
ensure(logan.searchProps, className, { pointer: true, state: true, ordernum: 0 });
this.props.className = className;
this.props.ordernum = logan.searchProps[className].ordernum++;
};
if (this.factual) {
logan.objects.push(this);
}
}
Obj.prototype.on = Bag.prototype.on;
Obj.prototype.data = Bag.prototype.data;
Obj.prototype.create = function(className, capture = true) {
if (this.props.className) {
console.warn(logan.exceptionParse(`object already exists (${this.props.className}@${this.props.pointer} - ${this.props.state}), recreting automatically from scratch`));
}
if (this.props.className || this.captures.length) {
//
// this.captures.length:
//
// An existing temporary object(no class) found with something captured on.
// As this is very likely from a log line match right after a destructor line
// we want to scratch that. If this is an object created by e.g. mention() or
// link() before class() or create() call then that mention/link will point
// to a bad object!
//
// Correct solution:
// 1. add a log at the end of a detructor and destroy() using that instead
// 2. make sure a class()'ed only object is called class() before it's used
// the first time.
//
// This is not logged on purpose, since there is a lot of cases we recycle
// pointers for which we have created temps from link() et al as well as
// a lot of log lines written after object's respective destructor line.
this.destroy(undefined /* always */, false /* no auto-capture */);
return logan._proc.obj(this.__most_recent_accessor).create(className, capture);
}
this._class(className);
this.prop("state", "created");
if (capture) {
this.capture();
}
return this;
}
Obj.prototype.createOnce = function(className, onCreate = null, capture = true) {
if (this.props.className || this.captures.length) {
if (capture) {
this.capture();
}
} else {
this.create(className, capture);
if (onCreate) {
onCreate(this);
}
}
return this;
}
Obj.prototype.alias = function(alias) {
if (logan._proc.objs[alias] === this) {
return this;
}
if (alias.match(NULLPTR_REGEXP)) {
return this;
}
alias = pointerTrim(alias);
logan._proc.objs[alias] = this;
this.aliases[alias] = true;
if (!alias.match(POINTER_REGEXP)) {
logan._proc.update_alias_regexp();
}
return this;
};
Obj.prototype.unalias = function(alias) {
alias = alias || this.__most_recent_accessor;
if (!this.aliases[alias]) {
return this;
}
delete logan._proc.objs[alias];
delete this.aliases[alias];
if (!alias.match(POINTER_REGEXP)) {
logan._proc.update_alias_regexp();
}
return this;
};
Obj.prototype.inherits = function(obj, className) {
if (!obj) {
return this.create(className);
}
if (className) {
this._class(className);
}
let alias = Obj.prototype.isPrototypeOf(obj)
? obj.__most_recent_accessor : obj;
return this.alias(alias).capture();
};
Obj.prototype.destroy = function(ifClassName, capture = true) {
if (ifClassName && this.props.className !== ifClassName) {
return;
}
delete logan._proc.objs[this.props.pointer];
let updateAliasRegExp = false;
for (let alias in this.aliases) {
if (!updateAliasRegExp && alias.match(POINTER_REGEXP)) {
updateAliasRegExp = true;
}
delete logan._proc.objs[alias];
}
this.prop("state", "released");
delete this._references;
if (updateAliasRegExp) {
logan._proc.update_alias_regexp();
}
if (capture) {
this.capture();
}
let info = {};
this.capture({ destroyed: true }, info);
this.destroyed = info.capture;
};
function Capture(what, obj = null) {
what = what || {
// This is a raw line capture. We load them from disk when put on the screen.
file: logan._proc.file,
line: logan._proc.linenumber,
offset: logan._proc.filebinaryoffset,
};
this.id = logan.captures.length;
// This property takes surprisingly a lot of memory...
this.time = logan._proc.timestamp;
this.thread = logan._proc.thread;
this.obj = obj;
this.what = what;
this.eventspan = logan._proc.thread._event_stack.last();
logan.captures.push(this);
}
Obj.prototype.capture = function(what, info = null) {
let capture = Capture.prototype.isPrototypeOf(what) ? what : logan.capture(what, this);
if (info) {
info.capture = capture;
info.source = this;
info.index = this.captures.length;
}
this.captures.push(capture);
return this;
};
Obj.prototype.grep = function() {
this._grep = logan._proc.schema;
return this;
};
Obj.prototype.expect = function(format, consumer = (obj) => { obj.capture() }, error = () => true) {
let match = convertPrintfToRegexp(format);
let obj = this;
let thread = logan._proc.thread;
let schema = logan._proc.schema;
let rule = schema.plainIf(proc => {
if (proc.thread !== thread) {
return false;
}
if (!logan.parse(proc.line, match, function() {
return consumer.apply(this, [obj].concat(Array.from(arguments)).concat([this]));
}, line => {
return error(obj, line);
})) {
schema.removeIf(rule);
}
return false;
}, () => { throw "Obj.expect() handler should never be called"; });
return this;
};
Obj.prototype.follow = function(cond, consumer = (obj) => obj.capture(), error = () => true) {
let capture = {
obj: this,
module: logan._proc.module,
thread: logan._proc.thread,
};
if (typeof cond === "number") {
capture.count = cond;
capture.follow = (obj, line, proc) => {
obj.capture();
return --capture.count;
};
} else if (typeof cond === "string") {
capture.follow = (obj, line, proc) => {
return logan.parse(line, cond, function() {
return consumer.apply(this, [obj].concat(Array.from(arguments)).concat([this]));
}, line => {
return error(obj, line);
});
};
} else if (typeof cond === "function") {
capture.follow = cond;
} else {
throw logan.exceptionParse("follow() 'cond' argument unexpected type '" + typeof cond + "'");
}
logan._proc._pending_follow = capture;
return this;
};
Obj.prototype.prop = function(name, value, merge = false) {
ensure(logan.searchProps, this.props.className)[name] = true;
if (typeof merge === "funtion") {
merge = merge(this);
}
if (value === undefined) {
delete this.props[name];
} else if (typeof value === "function") {
this.props[name] = value(this.props[name] || 0, this);
} else if (merge && this.props[name]) {
this.props[name] += ("," + value);
} else {
this.props[name] = value;
}
return this.capture({ prop: name, value: this.props[name] });
};
Obj.prototype.propIf = function(name, value, cond, merge) {
if (!cond(this)) {
return this;
}
return this.prop(name, value, merge);
};
Obj.prototype.propIfNull = function(name, value) {
if (name in this.props) {
return this;
}
return this.prop(name, value);
};
Obj.prototype.state = function(state, merge = false) {
if (!state) {
return this.props["state"];
}
return this.prop("state", state, merge);
};
Obj.prototype.stateIf = function(state, cond, merge = false) {
if (!cond(this)) {
return this;
}
return this.prop("state", state, merge);
};
Obj.prototype.link = function(that) {
that = logan._proc.obj(that);
if (that.nullptr || this.nullptr) {
return this;
}
let capture = new Capture({ linkFrom: this, linkTo: that }, this);
this.capture(capture);
that.capture(capture);
return this;
};
Obj.prototype.mention = function(that) {
if (typeof that === "string" && that.match(NULLPTR_REGEXP)) {
return this;
}
that = logan._proc.obj(that);
this.capture({ expose: that });
return this;
};
Obj.prototype.class = function(className) {
if (this.props.className) {
// Already created
return this;
}
this._class(className);
return this.prop("state", "partial").prop("missing-constructor", true);
};
Obj.prototype.call = function(func) {
func.apply(logan._proc, [this].concat(Array.from(arguments).slice(1)));
return this;
};
Obj.prototype.ipcid = function(id) {
if (id === undefined) {
return this.ipc_id;
}
this.ipc_id = id;
return this.prop("ipc-id", id);
};
Obj.prototype.send = function(message) {
if (!logan._proc._ipc) {
return this;
}
if (this.ipc_id === undefined) {
return this;
}
let create = () => {
let origin = {};
this.capture({ dispatch: true }, origin);
LOG(" storing send() " + logan._proc.line + " ipcid=" + this.ipc_id);
return {
origin,
sender: this,
};
};
let id = message + "::" + this.ipc_id;
LOG(`send() with id = ${id}`);
let sync = logan._proc._sync[id];
if (!sync) {
logan._proc._sync[id] = create();
return this;
}
if (sync.sender) {
while (sync.next) {
sync = sync.next;
}
sync.next = create();
return this;
}
delete logan._proc._sync[id];
LOG(" send() calling on stored recv() " + logan._proc.line + " ipcid=" + this.ipc_id);
let proc = logan._proc.swap(sync.proc);
logan._proc.file.__base.recv_wait = false;
sync.func(sync.receiver, this);
logan._proc.restore(proc);
return this;
};
Obj.prototype.recv = function(message, func = () => { }) {
if (!logan._proc._ipc) {
return this;
}
if (this.ipc_id === undefined) {
return this;
}
const create = () => {
LOG(" blocking and storing recv() " + logan._proc.line + " ipcid=" + this.ipc_id + " file=" + logan._proc.file.name);
return {
func,
receiver: this,
proc: logan._proc.save(),
};
}
let id = message + "::" + this.ipc_id;
LOG(`recv() with id = ${id}`);
let sync = logan._proc._sync[id];
if (!sync) {
// There was no send() call for this ipcid and message, hence
// we have to wait. Store the recv() info and proccessing state
// and stop parsing this file.
logan._proc._sync[id] = create();
logan._proc.file.__base.recv_wait = true;
return this;
}
while (!sync.sender && sync.next) {
sync = sync.next;
}
if (!sync.sender) {
sync.next = create();
return this;
}
if (sync.next) {
logan._proc._sync[id] = sync.next;
} else {
delete logan._proc._sync[id];
}
LOG(" recv() taking stored send() " + logan._proc.line + " ipcid=" + this.ipc_id);
this.capture({ run: sync.origin });
func(this, sync.sender);
return this;
};
let loganImpl = {
// processing state sub-object, passed to rule consumers
_proc: {
_obj: function(ptr, store) {
if (Obj.prototype.isPrototypeOf(ptr)) {
return ptr;
}
ptr = pointerTrim(ptr);
let nullptr = ptr.match(NULLPTR_REGEXP);
if (nullptr) {
store = false;
}
let obj = this.objs[ptr];
if (!obj) {
obj = new Obj(ptr, store);
if (store) {
this.objs[ptr] = obj;
if (!ptr.match(POINTER_REGEXP)) {
logan._proc.update_alias_regexp();
}
}
}
obj.__most_recent_accessor = ptr;
obj.nullptr = nullptr;
return obj;
},
objIf: function(ptr) {
return this._obj(ptr, false);
},
obj: function(ptr) {
return this._obj(ptr, true);
},
service: function(name) {
return this.obj(`${this.file.__base.name}!${name}::service`).class(name).state("service");
},
duration: function(timestamp) {
if (!timestamp) {
return undefined;
}
return this.timestamp.getTime() - timestamp.getTime();
},
// private
save: function() {
return ["timestamp", "thread", "line", "file", "module", "raw", "filebinaryoffset"].reduce(
(result, prop) => (result[prop] = this[prop], result), {});
},
restore: function(from) {
for (let property in from) {
this[property] = from[property];
}
},
swap: function(through) {
let result = this.save();
this.restore(through);
return result;
},
update_alias_regexp: function() {
if (!ALLOW_NON_POINTER_ALIAS_GREPING) {
return;
}
let nonPtrAliases = [];
for (let obj of Object.keys(logan._proc.objs)) {
if (!obj.match(POINTER_REGEXP)) {
nonPtrAliases.push(escapeRegexp(obj));
}
}
this.nonPtrAliases = nonPtrAliases.length === 0 ? null : new RegExp("(" + nonPtrAliases.join("|") + ")", "g");
},
},
_schemes: {},
_schema: null,
_summaryProps: {},
schema: function(name, preparer, builder) {
this._schema = ensure(this._schemes, name, () => new Schema(name, preparer));
builder(this._schema);
},
defaultSchema: function(name) {
this._defaultSchema = name;
},
activeSchema: function(name) {
name = name || this._defaultSchema;
if (!this._schemes[name]) {
return false;
}
return (this._schema = this._schemes[name]);
},
summaryProps: function(className, arrayOfProps) {
if (this._summaryProps[className]) {
console.warn(`Overriding summary properties of class ${className}`);
}
this._summaryProps[className] = arrayOfProps;
},
parse: function(line, printf, consumer, unmatch) {
let result;
if (!this.processRule(line, convertPrintfToRegexp(printf), function() {
result = consumer.apply(this, arguments);
})) {
return (unmatch && unmatch.call(this._proc, line));
}
return result;
},
// The rest is considered private
exceptionParse: function(exception) {
if (typeof exception === "object") {
exception = "'" + exception.message + "' at " + exception.fileName + ":" + exception.lineNumber + "\n";
}
exception += "while processing '" + this._proc.raw +
"'\nat " + this._proc.file.name + ":" + this._proc.linenumber;
return new Error(exception);
},
files: [],
readBlockCounter: 0,
readCaptureQueue: [],
cache: false,
init: function() {
for (let schema of Object.values(this._schemes)) {
schema._finalize();
}
},
initProc: function(UI) {
this.objects = [];
this.captures = [];
this.searchProps = {};
this._proc.global = new Bag();
this._proc._sync = {};
delete this._proc.nonPtrAliases;
let zips = {};
let parents = {};
let children = {};
let bases = {};
for (let file of this.files) {
let basename = rotateFileBaseName(file);
file.__base = ensure(bases, basename, () => ({
name: basename, recv_wait: false,
}));
file.__base_order = 0; // will be updated from the first timestamp in the file
if (isChildFile(file)) {
file.__is_child = true;
children[basename] = true;
} else if (isZipFile(file)) {
file.__is_zip = true;
zips[basename] = true;
} else {
parents[basename] = true;
}
}
parents = Object.keys(parents).length;
children = Object.keys(children).length;
zips = Object.keys(zips).length;
if (parents > 1) {
UI.warn("More than one parent log - is that what you want?");
}
if (parents == 0 && children > 1 && zips == 0) {
UI.warn("Loading orphan child logs - is that what you want?");
}
this._proc._ipc = parents == 1 && children > 0;
this._proc.threads = {};
this._proc.objs = {};
netdiag.reset();
},
consumeURL: function(UI, url) {
this.seekId = 0;
this.initProc(UI);
UI.searchingEnabled(false);
let contentType = '';
UI.loadPhase("requesting...");
fetch(url, { mode: 'cors', credentials: 'omit', }).then(function(response) {
UI.loadPhase("fetching...");
if (response.headers.has('content-type')) {
contentType = response.headers.get('content-type');
}
return response.blob();
}).then(function(blob) {
if (contentType.match("zip")) {
this.consumeZIP(UI, blob);
} else {
blob.name = url;
this.consumeFiles(UI, [blob]);
}
UI.searchingEnabled(true);
}.bind(this)).catch((reason) => {
window.onerror(reason);
UI.searchingEnabled(true);
});
},
consumeZIP: function(UI, blob) {
UI.searchingEnabled(false);