-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathomrtracecomponent.cpp
1462 lines (1268 loc) · 50.6 KB
/
omrtracecomponent.cpp
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
/*******************************************************************************
* Copyright IBM Corp. and others 1998
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
/* _GNU_SOURCE forces GLIBC_2.0 sscanf/vsscanf/fscanf for RHEL5 compatability */
#if defined(__GNUC__) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif /* defined(__GNUC__) && !defined(_GNU_SOURCE) */
#include <limits.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <assert.h>
#include <errno.h>
#include <ctype.h>
#include "omrtrace_internal.h"
#include "omrtrace.h"
#include "ute_core.h"
#include "omrutil.h"
static const char *UT_MISSING_TRACE_FORMAT = " Tracepoint format not in dat file";
#define MAX_QUALIFIED_NAME_LENGTH 16
omr_error_t
initializeComponentData(UtComponentData **componentDataPtr, UtModuleInfo *moduleInfo, const char *componentName)
{
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
UtComponentData *componentData = (UtComponentData *)omrmem_allocate_memory(sizeof(UtComponentData), OMRMEM_CATEGORY_TRACE);
UT_DBGOUT(2, ("<UT> initializeComponentData: %s\n", componentName));
if (componentData == NULL) {
UT_DBGOUT(1, ("<UT> Unable to allocate componentData for %s\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
initHeader(&componentData->header, UT_TRACE_COMPONENT_DATA, sizeof(UtComponentData));
componentData->componentName = (char *)omrmem_allocate_memory(strlen(componentName) + 1, OMRMEM_CATEGORY_TRACE);
if (componentData->componentName == NULL) {
UT_DBGOUT(1, ("<UT> Unable to allocate componentData's name field for %s\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
strcpy(componentData->componentName, componentName);
/* Setup the fully qualified name here as when we come to print out trace counters the modules may have been
* freed already. */
if (moduleInfo->traceVersionInfo->traceVersion >= 7 && moduleInfo->containerModule != NULL) {
char qualifiedName[MAX_QUALIFIED_NAME_LENGTH];
omrstr_printf(qualifiedName, MAX_QUALIFIED_NAME_LENGTH, "%s(%s)", moduleInfo->name, moduleInfo->containerModule->name);
componentData->qualifiedComponentName = (char *)omrmem_allocate_memory(strlen(qualifiedName) + 1, OMRMEM_CATEGORY_TRACE);
if (componentData->qualifiedComponentName == NULL) {
UT_DBGOUT(1, ("<UT> Unable to allocate componentData's name field for %s\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
strcpy(componentData->qualifiedComponentName, qualifiedName);
} else {
componentData->qualifiedComponentName = componentData->componentName;
}
if (moduleInfo->formatStringsFileName != NULL) {
componentData->formatStringsFileName = (char *)omrmem_allocate_memory(strlen(moduleInfo->formatStringsFileName) + 1, OMRMEM_CATEGORY_TRACE);
if (componentData->formatStringsFileName == NULL) {
UT_DBGOUT(1, ("<UT> Unable to allocate componentData's format strings file name field for %s\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
strcpy(componentData->formatStringsFileName, moduleInfo->formatStringsFileName);
} else {
componentData->formatStringsFileName = NULL;
}
componentData->moduleInfo = moduleInfo;
componentData->tracepointCount = moduleInfo->count;
componentData->numFormats = 0;
componentData->tracepointFormattingStrings = NULL;
componentData->tracepointcounters = NULL;
componentData->alreadyfailedtoloaddetails = 0;
componentData->next = NULL;
componentData->prev = NULL;
*componentDataPtr = componentData;
UT_DBGOUT(2, ("<UT> initializeComponentData complete: %s\n", componentName));
return OMR_ERROR_NONE;
}
/*
* This function is used during trace shutdown.
* omrTraceGlobal may have been NULLed before calling this function.
* Don't use UT_DBGOUT() macro.
*/
void
freeComponentData(OMR_TraceGlobal *global, UtComponentData *componentDataPtr)
{
int numFormats, i;
char *tempString;
OMRPORT_ACCESS_FROM_OMRPORT(global->portLibrary);
UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentData: %s\n", componentDataPtr->componentName));
numFormats = componentDataPtr->numFormats;
/* free any storage allocated for the format strings and names */
if (componentDataPtr->tracepointFormattingStrings != NULL) {
for (i = 0; i < numFormats; i++) {
tempString = componentDataPtr->tracepointFormattingStrings[i];
if (tempString != NULL && tempString != UT_MISSING_TRACE_FORMAT) {
omrmem_free_memory(tempString);
}
}
omrmem_free_memory(componentDataPtr->tracepointFormattingStrings);
}
if (componentDataPtr->tracepointcounters != NULL) {
omrmem_free_memory(componentDataPtr->tracepointcounters);
}
if (componentDataPtr->qualifiedComponentName != componentDataPtr->componentName && componentDataPtr->qualifiedComponentName != NULL) {
omrmem_free_memory(componentDataPtr->qualifiedComponentName);
}
if (componentDataPtr->componentName != NULL) {
omrmem_free_memory(componentDataPtr->componentName);
}
if (componentDataPtr->formatStringsFileName != NULL) {
omrmem_free_memory(componentDataPtr->formatStringsFileName);
}
omrmem_free_memory(componentDataPtr);
UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentData completed\n"));
return;
}
omr_error_t
initializeComponentList(UtComponentList **componentListPtr)
{
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
UtComponentList *componentList = (UtComponentList *)omrmem_allocate_memory(sizeof(UtComponentList), OMRMEM_CATEGORY_TRACE);
UT_DBGOUT(2, ("<UT> initializeComponentList: %p\n", componentListPtr));
if (componentList == NULL) {
UT_DBGOUT(1, ("<UT> Unable to allocate component list\n"));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
initHeader(&componentList->header, UT_TRACE_COMPONENT_LIST, sizeof(UtComponentList));
componentList->head = NULL;
componentList->deferredConfigInfoHead = NULL;
*componentListPtr = componentList;
UT_DBGOUT(2, ("<UT> initializeComponentList: %p completed\n", componentListPtr));
return OMR_ERROR_NONE;
}
/*
* This function is used during trace shutdown.
* omrTraceGlobal has been NULLed here. Don't use UT_DBGOUT() macro.
*/
omr_error_t
freeComponentList(OMR_TraceGlobal *global, UtComponentList *componentList)
{
UtComponentData *compData = componentList->head;
UtComponentData *tempCD;
UtDeferredConfigInfo *configInfo = componentList->deferredConfigInfoHead;
UtDeferredConfigInfo *tempCI;
OMRPORT_ACCESS_FROM_OMRPORT(global->portLibrary);
UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentList: %p\n", componentList));
while (compData != NULL) {
tempCD = compData->next;
UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentList: freeing CI [%p] from [%p]\n", compData, componentList));
freeComponentData(global, compData);
compData = tempCD;
}
while (configInfo != NULL) {
tempCI = configInfo->next;
UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentList: freeing CI [%p] from [%p]\n", configInfo, componentList));
if (configInfo->groupName != NULL) {
omrmem_free_memory(configInfo->groupName);
}
if (configInfo->componentName != NULL) {
omrmem_free_memory(configInfo->componentName);
}
omrmem_free_memory(configInfo);
configInfo = tempCI;
}
omrmem_free_memory(componentList);
UT_DBGOUT_NOGLOBAL(2, global->traceDebug, ("<UT> freeComponentList: %p finished processing\n", componentList));
return OMR_ERROR_NONE;
}
omr_error_t
addComponentToList(UtComponentData *componentData, UtComponentList *componentList)
{
UtComponentData *compDataCursor;
UtComponentData *endOfList;
UT_DBGOUT(1, ("<UT> addComponentToList: component: %s list: %p\n", componentData->componentName, componentList));
if (componentList == NULL) {
UT_DBGOUT(1, ("<UT> Not adding %s to NULL component list\n", componentData->componentName));
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
if (componentData == NULL) {
UT_DBGOUT(1, ("<UT> Not adding NULL component to component list\n"));
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
compDataCursor = componentList->head;
endOfList = componentList->head;
/* is it already in the list? */
while (compDataCursor != NULL) {
char *tempName = compDataCursor->componentName;
if (try_scan(&tempName, componentData->componentName) && *tempName == '\0') {
/* found the component in the component list */
UT_DBGOUT(1, ("<UT> addComponentToList: component %s found\n", componentData->componentName));
if (compDataCursor->moduleInfo != NULL && componentData->moduleInfo->traceVersionInfo->traceVersion >= 6) {
/* mirror existing active info into newly registering module */
memcpy(componentData->moduleInfo->active, compDataCursor->moduleInfo->active, compDataCursor->moduleInfo->count);
componentData->moduleInfo->next = compDataCursor->moduleInfo;
}
}
/* need to walk to end of list in all cases */
endOfList = compDataCursor;
compDataCursor = compDataCursor->next;
}
UT_DBGOUT(1, ("<UT> addComponentToList: adding %s [%p] at ", componentData->componentName, componentData));
if (endOfList == NULL) {
UT_DBGOUT(1, ("<UT> head\n"));
/* this is the head of the list */
componentList->head = componentData;
componentData->prev = NULL;
componentData->next = NULL;
} else {
UT_DBGOUT(1, ("<UT> end\n"));
/* add component to the end of the list */
endOfList->next = componentData;
componentData->prev = endOfList;
componentData->next = NULL;
}
return OMR_ERROR_NONE;
}
omr_error_t
processComponentDefferedConfig(UtComponentData *componentData, UtComponentList *componentList)
{
omr_error_t rc = OMR_ERROR_NONE;
UtDeferredConfigInfo *configInfo;
if (componentList == NULL || componentData == NULL) {
UT_DBGOUT(1, ("<UT> Can't process config info for a NULL component [%p] or NULL component list [%p]\n", componentData, componentList));
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
if (componentData->moduleInfo == NULL) {
UT_DBGOUT(1, ("<UT> Can't process defferred config info on a non live component: %s\n", componentData->componentName));
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
/* all the pent up config needs to be released */
if (componentList->deferredConfigInfoHead != NULL) {
UT_DBGOUT(2, ("<UT> processComponentDefferedConfig: component %s - applying global deferred config info\n", componentData->componentName));
configInfo = componentList->deferredConfigInfoHead;
while (configInfo != NULL) {
BOOLEAN configAppliesToAll = j9_cmdla_stricmp(configInfo->componentName, UT_ALL) == 0;
if (configAppliesToAll || j9_cmdla_stricmp(configInfo->componentName, componentData->componentName) == 0) {
/* Applying "all" options to components may fail because of missing groups or other inappropriate settings.
* We suppress messages when applying "all" options to new components.
*/
BOOLEAN suppressMessages = configAppliesToAll;
omr_error_t err = setTracePointsTo(componentData->componentName, componentList,
configInfo->all, configInfo->firstTracePoint,
configInfo->lastTracePoint, configInfo->value,
configInfo->level, configInfo->groupName,
suppressMessages, configInfo->setActive);
if (OMR_ERROR_NONE != err) {
if (!suppressMessages) {
UT_DBGOUT(1, ("<UT> can't activate deferred trace opts on %s\n", componentData->componentName));
rc = err;
}
}
}
configInfo = configInfo->next;
}
UT_DBGOUT(2, ("<UT> processComponentDefferedConfig: component %s - apply global deferred config info complete\n", componentData->componentName));
}
UT_DBGOUT(2, ("<UT> addComponentToList: component %s processed deferred config info\n", componentData->componentName));
return rc;
}
omr_error_t
removeModuleFromList(UtModuleInfo *module, UtComponentList *componentList)
{
UtComponentData *compDataCursor = componentList->head;
UtComponentData *prevCompData;
UT_DBGOUT(2, ("<UT> removeModuleFromList: searching for module %s in componentList %p\n", module->name, componentList));
/* for flight controller functinality, any unloaded components should be moved onto an unloaded list, so their
formatting strings and a memcpy of their moduleInfo is available */
while (compDataCursor != NULL) {
if (0 == strcmp(compDataCursor->componentName, module->name)) {
UT_DBGOUT(2, ("<UT> removeModuleFromList: found component %s in componentList %p\n", module->name, componentList));
/* remove this module from the linked list within the component */
if (module->traceVersionInfo->traceVersion < 6) {
/* pre version 6 modules can't be treated as a linked list */
compDataCursor->moduleInfo = NULL;
} else {
UtModuleInfo **moduleCursor = &compDataCursor->moduleInfo;
while (*moduleCursor != NULL) {
if (*moduleCursor == module) {
*moduleCursor = module->next;
break;
}
moduleCursor = &(*moduleCursor)->next;
}
}
/* if this component has no more modules, remove it from the list */
if (NULL == compDataCursor->moduleInfo) {
prevCompData = compDataCursor->prev;
if (NULL == prevCompData) {
/* this is the head of the list */
componentList->head = compDataCursor->next;
if (NULL != compDataCursor->next) {
compDataCursor->next->prev = NULL;
}
} else {
/* this is in the middle of the list */
prevCompData->next = compDataCursor->next;
if (compDataCursor->next != NULL) {
compDataCursor->next->prev = prevCompData;
}
}
if (componentList == OMR_TRACEGLOBAL(componentList)) {
/* ensure no-one tries to continue using this as it will be going away */
compDataCursor->moduleInfo = NULL;
/* add to the unloaded modules list */
addComponentToList(compDataCursor, OMR_TRACEGLOBAL(unloadedComponentList));
} else {
/* otherwise we are unloading it from some other list so free it before we lose
* our reference to it */
freeComponentData(omrTraceGlobal, compDataCursor);
}
}
return OMR_ERROR_NONE;
}
compDataCursor = compDataCursor->next;
}
UT_DBGOUT(2, ("<UT> removeModuleFromList: didn't find component %s in componentList %p\n", module->name, componentList));
return OMR_ERROR_INTERNAL;
}
static UtComponentData *
getComponentDataNext(const char *componentName, UtComponentList *componentList, UtComponentData *position)
{
UtComponentData *compDataCursor;
if (position == NULL) {
/* Beginning search from the first component */
compDataCursor = componentList->head;
} else {
/* Resuming search from the last component found with this name. */
compDataCursor = position->next;
}
UT_DBGOUT(4, ("<UT> getComponentData: searching for component %s in componentList %p\n", (componentName) ? componentName : "NULL", componentList));
if (componentName == NULL) {
UT_DBGOUT(1, ("<UT> Can't get ComponentData for NULL componentName\n"));
return NULL;
}
while (compDataCursor != NULL) {
char *tempName = compDataCursor->componentName;
if (try_scan(&tempName, (char *)componentName) && *tempName == '\0') {
UT_DBGOUT(4, ("<UT> getComponentData: found component %s [%p] in componentList %p\n", componentName, compDataCursor, componentList));
return compDataCursor;
}
compDataCursor = compDataCursor->next;
}
UT_DBGOUT(4, ("<UT> getComponentData: didn't find component %s in componentList %p\n", componentName, componentList));
return NULL;
}
UtComponentData *
getComponentData(const char *componentName, UtComponentList *componentList)
{
return getComponentDataNext(componentName, componentList, NULL);
}
static UtComponentData *
getComponentDataForModule(UtModuleInfo *moduleInfo, UtComponentList *componentList)
{
UtComponentData *compDataCursor;
/* Beginning search from the first component */
compDataCursor = componentList->head;
UT_DBGOUT(4, ("<UT> getComponentData: searching for component for module %p in componentList %p\n", moduleInfo, componentList));
while (compDataCursor != NULL) {
if (compDataCursor->moduleInfo == moduleInfo) {
UT_DBGOUT(4, ("<UT> getComponentData: found component %s [%p] in componentList %p\n", compDataCursor->qualifiedComponentName, compDataCursor, componentList));
return compDataCursor;
}
compDataCursor = compDataCursor->next;
}
UT_DBGOUT(4, ("<UT> getComponentData: didn't find component for module %p in componentList %p\n", moduleInfo, componentList));
return NULL;
}
static void
updateActiveArray(UtComponentData *compData, int32_t first, int32_t last, unsigned char value, int32_t setActive)
{
UtModuleInfo *moduleInfoCursor = compData->moduleInfo;
int32_t i;
while (moduleInfoCursor != NULL) {
if (value == 0) {
for (i = first; i <= last; i++) {
moduleInfoCursor->active[i] = value;
}
} else {
if (setActive) {
for (i = first; i <= last; i++) {
moduleInfoCursor->active[i] |= value;
}
} else {
for (i = first; i <= last; i++) {
moduleInfoCursor->active[i] &= ~value;
}
}
}
if (moduleInfoCursor->traceVersionInfo->traceVersion < 6) {
/* pre 6 modules can't be treated as linked list */
moduleInfoCursor = NULL;
} else {
moduleInfoCursor = moduleInfoCursor->next;
}
}
}
/* Utility function for parsing command line options */
static char *
newSubString(const char *buffer, size_t ret)
{
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
char *temp = (char *)omrmem_allocate_memory(ret + 1, OMRMEM_CATEGORY_TRACE);
UT_DBGOUT(2, ("<UT> newSubString: buffer %s size %d \n", buffer, ret));
if (temp == NULL) {
/*fprintf(stderr, "newSubString error\n");*/
return NULL;
}
strncpy(temp, buffer, ret);
temp[ret] = '\0';
UT_DBGOUT(2, ("<UT> newSubString: returning buffer %p \n", temp));
return temp;
}
/* Utility function for parsing command line options */
static void
freeSubString(char *buffer)
{
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
UT_DBGOUT(2, ("<UT> freeSubString: buffer %p\n", buffer));
omrmem_free_memory(buffer);
return;
}
/* Utility function for parsing command line options */
static int32_t
parseNumFromBuffer(const char *buffer, int ret)
{
int32_t rc = 0;
char *temp = newSubString(buffer, ret + 1);
UT_DBGOUT(2, ("<UT> parseNumFromBuffer: buffer %s\n", buffer));
if (temp == NULL) {
/*fprintf(stderr, "parseNum error\n");*/
return -1;
}
strncpy(temp, buffer, ret);
temp[ret] = '\0';
rc = atoi(temp);
freeSubString(temp);
UT_DBGOUT(2, ("<UT> parseNumFromBuffer: buffer %s found %d\n", buffer, rc));
return rc;
}
static omr_error_t
addDeferredConfigToList(const char *componentName, int32_t all, int32_t first, int32_t last,
unsigned char value, int level, const char *groupName,
UtDeferredConfigInfo **configList, int32_t setActive)
{
UtDeferredConfigInfo *dconfiginfo;
UtDeferredConfigInfo *temp;
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
/* 1) add to deferred options for components that register */
UT_DBGOUT(2, ("<UT> setTracePointsTo: component %s applying to all and adding to global deferred", componentName));
dconfiginfo = (UtDeferredConfigInfo *)omrmem_allocate_memory(sizeof(UtDeferredConfigInfo), OMRMEM_CATEGORY_TRACE);
if (dconfiginfo == NULL) {
UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate config info\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
dconfiginfo->componentName = (char *)omrmem_allocate_memory(strlen(componentName) + 1, OMRMEM_CATEGORY_TRACE);
if (dconfiginfo->componentName == NULL) {
UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate config info componentName\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
strcpy(dconfiginfo->componentName, componentName);
dconfiginfo->all = all;
dconfiginfo->firstTracePoint = first;
dconfiginfo->lastTracePoint = last;
dconfiginfo->value = value;
dconfiginfo->level = level;
dconfiginfo->setActive = setActive;
if (groupName == NULL) {
dconfiginfo->groupName = NULL;
} else {
dconfiginfo->groupName = (char *)omrmem_allocate_memory(strlen(groupName) + 1, OMRMEM_CATEGORY_TRACE);
if (dconfiginfo->groupName == NULL) {
UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate config info groupName\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
strcpy(dconfiginfo->groupName, groupName);
}
dconfiginfo->next = NULL;
if (*configList == NULL) {
*configList = dconfiginfo;
} else {
temp = *configList;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = dconfiginfo;
}
return OMR_ERROR_NONE;
}
/* for this function, we assume that componentName has been parsed, and contains a single
* component name only. */
static omr_error_t
setTracePointsForComponent(const char *componentName, UtComponentList *componentList, int32_t all, int32_t first, int32_t last,
unsigned char value, int level, const char *groupName, BOOLEAN suppressMessages, int32_t setActive)
{
UtComponentData *compData;
UtModuleInfo *modInfo = NULL;
omr_error_t rc = OMR_ERROR_NONE;
if (0 == j9_cmdla_strnicmp(componentName, UT_ALL, strlen(UT_ALL))) {
rc = addDeferredConfigToList(componentName,
all, first, last, value, level, groupName,
&componentList->deferredConfigInfoHead,
setActive);
compData = componentList->head;
while (compData != NULL) {
if (compData->moduleInfo != NULL) {
first = 0;
last = compData->moduleInfo->count - 1;
/* Don't configure auxiliary modules */
if (MODULE_IS_AUXILIARY(compData->moduleInfo)) {
compData = compData->next;
continue;
}
if (level != -1) {
setTracePointsByLevelTo(compData, level, value, setActive);
} else if (groupName != NULL) {
setTracePointGroupTo(groupName, compData, value, TRUE, setActive);
} else {
updateActiveArray(compData, first, last, value, setActive);
}
}
compData = compData->next;
}
return rc;
}
compData = getComponentData(componentName, componentList);
if (compData == NULL) {
/* add the information to the deferred configuration list */
addDeferredConfigToList(componentName,
all, first, last, value, level, groupName,
&componentList->deferredConfigInfoHead, setActive);
} else {
while (compData != NULL) { /* configuring live and registered module */
int32_t maxTraceId = compData->moduleInfo->count - 1;
UT_DBGOUT(2, ("<UT> setTracePointsTo: configuring registered component %s ", componentName));
if (all) {
first = 0;
last = maxTraceId;
}
modInfo = compData->moduleInfo;
if (first > maxTraceId) {
reportCommandLineError(suppressMessages, "Unable to set tracepoint %d in %s - tracepoint id out of range", first, componentName);
return OMR_ERROR_INTERNAL;
}
if (last > maxTraceId) {
reportCommandLineError(suppressMessages, "Tracepoint %d not in range 0->%d %s", last, maxTraceId, componentName);
last = maxTraceId;
return OMR_ERROR_INTERNAL;
}
/* Auxiliary tracepoints can't be set */
if (MODULE_IS_AUXILIARY(modInfo)) {
reportCommandLineError(suppressMessages, "Component %s is marked auxiliary and cannot be configured directly.", componentName);
return OMR_ERROR_INTERNAL;
}
if (groupName != NULL) {
UT_DBGOUT(2, ("by group %s\n", groupName));
rc = setTracePointGroupTo(groupName, compData, value, suppressMessages, setActive);
} else if (level != -1) {
UT_DBGOUT(2, ("by level %d\n", level));
rc = setTracePointsByLevelTo(compData, level, value, setActive);
} else {
UT_DBGOUT(2, ("by range %d-%d\n", first, last));
updateActiveArray(compData, first, last, value, setActive);
}
/* There may be more than one component with the same name, particularly in the case of
* libraries declared as submodules in tdf files. e.g. pool, j9util */
compData = getComponentDataNext(componentName, componentList, compData);
}
}
return rc;
}
/* valid ranges passed in in componentName are of one of the follwing forms:
* tpnid{j9vm.10}
* tpnid{j9vm.10-20}
* j9vm.10
* j9vm.10-20
* and so on
*/
static omr_error_t
parseAndSetTracePointsInRange(const char *componentName,
unsigned char value, int32_t setActive, BOOLEAN suppressMessages)
{
int length = 0;
const char *p;
omr_error_t rc = OMR_ERROR_INTERNAL;
int ret = 0;
int32_t firsttpid, lasttpid;
char *compName;
const char *temp;
UT_DBGOUT(2, ("<UT> parseAndSetTracePointsInRange: %s\n", componentName));
p = componentName;
if (*p == '\0') {
return OMR_ERROR_NONE;
}
/*
* Tracepoint ID specified ?
*/
if (0 == j9_cmdla_strnicmp(p, UT_TPID, strlen(UT_TPID)) &&
(p[strlen(UT_TPID)] == '(' || p[strlen(UT_TPID)] == '{')
) {
reportCommandLineError(suppressMessages, "Invalid trace options, use: tpnid{componentName.[integer_offset]}");
return OMR_ERROR_ILLEGAL_ARGUMENT;
} else if (0 == j9_cmdla_strnicmp(p, UT_TPNID, strlen(UT_TPNID)) &&
p[strlen(UT_TPNID)] == '{'
) {
length = 0;
length += (int)strlen(UT_TPNID) + 1; /* the prefix and the open brace */
/* Is there a close brace? */
if (strchr(p, '}') == NULL) {
reportCommandLineError(suppressMessages, "Error: unclosed braces");
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
}
if (componentName[0] == '!') {
value = 0x00;
}
p += length;
temp = p;
while (*temp != '}' && *temp != '\0') {
ret = 0;
if (*temp == ',') {
temp++, p++, length++;
}
/* skip leading spaces in a component name */
while (*temp == ' ') {
temp++, p++, length++;
}
while (*temp != '.') {
if (*temp == '}' || *temp == '\0') {
reportCommandLineError(suppressMessages, "Expecting tpnid{compname.offset} e.g. tpnid{j9trc.4}");
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
temp++;
ret++;
}
compName = newSubString(p, ret);
if (compName == NULL) {
UT_DBGOUT(1, ("<UT> Can't allocate substring while parsing command line\n"));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
length += ret + 1;
p += ret + 1; /* plus one for the full-stop */
ret = 0;
temp = p;
while (isdigit((int)*temp)) {
ret++;
temp++;
}
length += ret;
if (*temp == '-') {
firsttpid = parseNumFromBuffer(p, ret);
temp++;
p += ret + 1;
length++; /* plus one for the dash */
ret = 0;
if (!isdigit(*temp)) {
reportCommandLineError(suppressMessages, "Expecting tracepoint range specified as tpnid{componentName.offset1-offset2} e.g. tpnid{j9trc.2-6}");
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
while (isdigit(*temp)) {
ret++;
temp++;
}
lasttpid = parseNumFromBuffer(p, ret);
/* Swap if specified largest first. */
if (lasttpid < firsttpid) {
int32_t temptpid = firsttpid;
firsttpid = lasttpid;
lasttpid = temptpid;
}
rc = setTracePointsForComponent(compName, OMR_TRACEGLOBAL(componentList), FALSE, firsttpid, lasttpid, value, -1, NULL, suppressMessages, setActive);
length += ret;
p += ret;
} else {
firsttpid = lasttpid = parseNumFromBuffer(p, ret);
rc = setTracePointsForComponent(compName, OMR_TRACEGLOBAL(componentList), FALSE, firsttpid, lasttpid, value, -1, NULL, suppressMessages, setActive);
p += ret;
}
freeSubString(compName);
}
return rc;
}
omr_error_t
setTracePointsTo(const char *componentName, UtComponentList *componentList, int32_t all, int32_t first, int32_t last,
unsigned char value, int level, const char *groupName, BOOLEAN suppressMessages, int32_t setActive)
{
const char *tempstr = NULL;
char *compNamesBuffer;
int32_t stripbraces = FALSE;
size_t namelength = 0;
omr_error_t rc = OMR_ERROR_NONE;
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
if (componentName == NULL) {
reportCommandLineError(suppressMessages, "Can't set tracepoints for NULL componentName");
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
if (componentList == NULL) {
UT_DBGOUT(1, ("<UT> can't set tracepoints against NULL componentList\n"));
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
UT_DBGOUT(1, ("<UT> setTracePointsTo: component %s all= %s first=%d last=%d value=%d\n", componentName, (all ? "TRUE" : "FALSE"), first, last));
/* check for multiple components */
tempstr = strchr(componentName, ',');
if (NULL != tempstr) {
/* we have been passed multiple component names */
UT_DBGOUT(2, ("<UT> setTracePointsTo found component list: %s\n", componentName));
if (componentName[0] == '{') {
/* option is a list of components enclosed in braces */
componentName++;
stripbraces = TRUE;
} else if ((0 == j9_cmdla_strnicmp(componentName, UT_TPNID, strlen(UT_TPNID))) && (tempstr < strchr(componentName, '}'))) {
/* option is 'tpnid' followed by a list of components enclosed in braces */
componentName += (int)strlen(UT_TPNID) + 1; /* skip over the prefix and the open brace */
stripbraces = TRUE;
}
/* separate and process the first component name */
namelength = tempstr - componentName;
compNamesBuffer = (char *)omrmem_allocate_memory(strlen(componentName) + 1, OMRMEM_CATEGORY_TRACE);
if (compNamesBuffer == NULL) {
UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate tempname info\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
strncpy(compNamesBuffer, componentName, namelength);
compNamesBuffer[namelength] = '\0'; /* replace the comma and terminate the string */
rc = setTracePointsToParsed(compNamesBuffer, componentList, all, first, last, value, level, groupName, suppressMessages, setActive);
if (rc != OMR_ERROR_NONE) {
omrmem_free_memory(compNamesBuffer);
return rc;
}
componentName += namelength + 1;
namelength = strlen(componentName);
strcpy(compNamesBuffer, componentName);
compNamesBuffer[namelength] = '\0';
if (stripbraces == TRUE) {
compNamesBuffer[namelength - 1] = '\0'; /* blat the close brace out of the allocated copy */
}
/* recurse here in case the remainder is still a comma separated list */
rc = setTracePointsTo(compNamesBuffer, componentList, all, first, last, value, level, groupName, suppressMessages, setActive);
omrmem_free_memory(compNamesBuffer);
return rc;
}
/* if we get here we have a single option, but it might still be enclosed by braces */
if (componentName[0] == '{') {
componentName++;
compNamesBuffer = (char *)omrmem_allocate_memory(strlen(componentName) + 1, OMRMEM_CATEGORY_TRACE);
if (compNamesBuffer == NULL) {
UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate tempname info\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
namelength = strlen(componentName);
strcpy(compNamesBuffer, componentName);
compNamesBuffer[namelength - 1] = '\0'; /* blat the close brace out of the allocated copy */
rc = setTracePointsToParsed(compNamesBuffer, componentList, all, first, last, value, level, groupName, suppressMessages, setActive);
omrmem_free_memory(compNamesBuffer);
} else {
rc = setTracePointsToParsed(componentName, componentList, all, first, last, value, level, groupName, suppressMessages, setActive);
}
return rc;
}
omr_error_t
setTracePointsToParsed(const char *componentName, UtComponentList *componentList, int32_t all, int32_t first, int32_t last,
unsigned char value, int level, const char *groupName, BOOLEAN suppressMessages, int32_t setActive)
{
const char *tempstr = NULL;
char *newstr = NULL;
char *newstr2 = NULL;
size_t namelength = 0;
size_t groupnamelength = 0;
omr_error_t rc = OMR_ERROR_NONE;
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
UT_DBGOUT(2, ("<UT> setTracePointsToParsed: %s\n", componentName));
if (strchr(componentName, '.') != NULL) {
/* we have a range of tracepoints */
rc = parseAndSetTracePointsInRange(componentName, value, setActive, suppressMessages);
/* can't combine ranges and levels etc, so just duck out now */
return rc;
}
if ((tempstr = strchr(componentName, '{')) != NULL || (tempstr = strchr(componentName, '(')) != NULL) {
char closingBrace;
UT_DBGOUT(2, ("<UT> setTracePointsTo: has detected a suboption %s in %s\n", tempstr, componentName));
namelength = tempstr - componentName;
if (*tempstr == '{') {
closingBrace = '}';
} else {
closingBrace = ')';
}
/* Look for empty braces - this is always an error */
if (*(tempstr + 1) == closingBrace) {
reportCommandLineError(suppressMessages, "Error: found empty braces or parentheses");
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
/* Look for unclosed braces - another error */
if (strchr(tempstr, closingBrace) == NULL) {
reportCommandLineError(suppressMessages, "Error: unclosed braces or parentheses");
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
tempstr++; /* points at first option char now */
if (0 == j9_cmdla_strnicmp(tempstr, UT_LEVEL_KEYWORD, strlen(UT_LEVEL_KEYWORD)) ||
*tempstr == 'l' || *tempstr == 'L') {
while (!isdigit(*tempstr)) {
if (*tempstr == ',' || *tempstr == '}' || *tempstr == '\0') {
reportCommandLineError(suppressMessages, "Trace level required without an integer level specifier");
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
tempstr++;
}
sscanf(tempstr, "%d", &level);
newstr = (char *)omrmem_allocate_memory(namelength + 1, OMRMEM_CATEGORY_TRACE);
if (newstr == NULL) {
UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate tempname info\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
strncpy(newstr, componentName, namelength);
newstr[namelength] = '\0';
UT_DBGOUT(2, ("<UT> setTracePointsTo: Level detected %d in %s\n", level, newstr));
componentName = newstr;
/* actual configuration of the component will now fall through to below */
} else {
/* must be a group name note - types are now groups */
UT_DBGOUT(2, ("<UT> setTracePointsTo: A Group detected \n"));
newstr = (char *)omrmem_allocate_memory(namelength + 1, OMRMEM_CATEGORY_TRACE);
if (newstr == NULL) {
UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate tempname info\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
strncpy(newstr, componentName, namelength);
newstr[namelength] = '\0';
groupnamelength = strlen(componentName) - namelength;
newstr2 = (char *)omrmem_allocate_memory(groupnamelength - 1, OMRMEM_CATEGORY_TRACE);
if (newstr2 == NULL) {
UT_DBGOUT(1, ("<UT> Unable to set tracepoints in %s - can't allocate tempname info\n", componentName));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
strncpy(newstr2, componentName + namelength + 1, groupnamelength - 2);
newstr2[groupnamelength - 2] = '\0';
groupName = newstr2;
UT_DBGOUT(2, ("<UT> setTracePointsTo: Group %s detected in %s\n", groupName, newstr));
componentName = newstr;
}
}
rc = setTracePointsForComponent(componentName, componentList, all, first, last,
value, level, groupName, suppressMessages, setActive);
/* tidy up */
if (newstr != NULL) {
omrmem_free_memory(newstr);
}
if (newstr2 != NULL) {
omrmem_free_memory(newstr2);
}
return rc;
}