forked from tvondra/gdbpg
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathgdbpg.py
More file actions
1781 lines (1477 loc) · 58.3 KB
/
gdbpg.py
File metadata and controls
1781 lines (1477 loc) · 58.3 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
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
import gdb
import string
# Visibility options
NOT_NULL = "not_null"
HIDE_INVALID = "hide_invalid"
NEVER_SHOW = "never_show"
ALWAYS_SHOW = "always_show"
# TODO: Put these fields in a config file
PlanNodes = ['Result', 'Repeat', 'ModifyTable','Append', 'Sequence', 'Motion',
'AOCSScan', 'BitmapAnd', 'BitmapOr', 'Scan', 'SeqScan', 'DynamicSeqScan',
'TableScan', 'IndexScan', 'DynamicIndexScan', 'BitmapIndexScan',
'BitmapHeapScan', 'BitmapAppendOnlyScan', 'BitmapTableScan',
'DynamicTableScan', 'TidScan', 'SubqueryScan', 'FunctionScan',
'TableFunctionScan', 'ValuesScan', 'ExternalScan', 'AppendOnlyScan',
'Join', 'NestLoop', 'MergeJoin', 'HashJoin', 'ShareInputScan',
'Material', 'Sort', 'Agg', 'Window', 'Unique', 'Hash', 'SetOp',
'Limit', 'DML', 'SplitUpdate', 'AssertOp', 'RowTrigger',
'PartitionSelector' ]
# TODO: Put these fields in a config file
PathNodes = ['Path', 'AppendOnlyPath', 'AOCSPath', 'ExternalPath', 'PartitionSelectorPath',
'IndexPath', 'BitmapHeapPath', 'BitmapAndPath', 'BitmapOrPath', 'TidPath',
'CdbMotionPath', 'ForeignPath', 'AppendPath', 'MergeAppendPath', 'ResultPath',
'HashPath', 'MergePath', 'MaterialPath', 'NestPath', 'JoinPath', 'UniquePath']
# TODO: Put these defaults config file
DEFAULT_DISPLAY_METHODS = {
'regular_fields': 'format_regular_field',
'node_fields': 'format_optional_node_field',
'list_fields': 'format_optional_node_list',
'tree_fields': 'format_optional_node_field',
'datatype_methods': {
'char *': 'format_string_pointer_field',
'const char *': 'format_string_pointer_field',
'Bitmapset *': 'format_bitmapset_field',
'struct timeval': 'format_timeval_field',
'NameData': 'format_namedata_field',
'struct nameData': 'format_namedata_field',
'struct ItemPointerData': 'format_item_pointer_data_field',
},
'show_hidden': False,
'max_recursion_depth': 30
}
# TODO: generate these overrides in a yaml config file
FORMATTER_OVERRIDES = {
'A_Expr': {
'fields':{
'location': {'visibility': "never_show"},
},
},
'Aggref': {
'fields':{
'aggcollid': {'visibility': "not_null"},
'inputcollid': {'visibility': "not_null"},
'aggtranstype': {'visibility': "not_null"},
'location': {'visibility': "never_show"},
},
},
'BoolExpr': {
'fields':{
'args': {'skip_tag': True},
'location': {'visibility': "never_show"},
},
},
'CaseWhen': {
'fields':{
'location': {'visibility': "never_show"},
},
},
'ColumnDef': {
'fields': {
'identity': {
'visibility': "not_null",
'formatter': 'format_generated_when',
},
'generated': {
'visibility': "not_null",
'formatter': 'format_generated_when',
},
'collOid': {'visibility': "not_null"},
'location': {'visibility': "never_show"},
}
},
'Const': {
'fields': {
'consttypmod': {'visibility': "hide_invalid"},
'constcollid': {'visibility': "not_null"},
'location': {'visibility': "never_show"},
},
},
'Constraint': {
'fields': {
'location': {'visibility': "never_show"},
'conname': {'visibility': "not_null"},
'cooked_expr': {'visibility': "not_null"},
'generated_when': {
'visibility': "not_null",
'formatter': 'format_generated_when',
},
'indexname': {'visibility': "not_null"},
'indexspace': {'visibility': "not_null"},
'access_method': {'visibility': "not_null"},
'fk_matchtype': {
'visibility': "not_null",
'formatter': 'format_foreign_key_matchtype',
},
'fk_upd_action': {
'visibility': "not_null",
'formatter': 'format_foreign_key_actions',
},
'fk_del_action': {
'visibility': "not_null",
'formatter': 'format_foreign_key_actions',
},
'old_pktable_oid': {'visibility': "not_null"},
'trig1Oid': {'visibility': "not_null"},
'trig2Oid': {'visibility': "not_null"},
'trig3Oid': {'visibility': "not_null"},
'trig4Oid': {'visibility': "not_null"},
},
'datatype_methods': {
}
},
'CreateStmt': {
'fields': {
'inhRelations': {'formatter': "format_optional_oid_list"},
}
},
'DefElem': {
'fields': {
'defnamespace': {'visibility': "not_null"},
},
},
'DistinctExpr': {
'fields': {
'args': {'skip_tag': True},
'opcollid': {'visibility': "not_null"},
'inputcollid': {'visibility': "not_null"},
},
},
'EquivalenceClass': {
'fields': {
# TODO: These fields are nice to dump recursively, but
# they potentially have backwards references to their parents.
# Need a way to detect this condition and stop dumping
'ec_sources': {'formatter': 'minimal_format_node_field', },
'ec_derives': {'formatter': 'minimal_format_node_field', },
},
},
'EState': {
'fields':{
'es_plannedstmt': {'visibility': "never_show"},
# TODO: These fields crash gdbpg.py
'es_sharenode': {'visibility': "never_show"},
},
},
'ExprContext': {
'fields':{
'ecxt_estate': {'visibility': "never_show"},
},
},
'IndexOptInfo': {
'fields': {
'rel': {'formatter': 'minimal_format_node_field', }
},
},
'FuncExpr': {
'fields':{
'args': {'skip_tag': True},
'funccollid': {'visibility': "not_null"},
'inputcollid': {'visibility': "not_null"},
'location': {'visibility': "never_show"},
},
},
'FuncExprState': {
'fields':{
# TODO: These fields crash gdbpg.py
'fp_arg': {'visibility': "never_show"},
'fp_datum': {'visibility': "never_show"},
'fp_null': {'visibility': "never_show"},
},
},
'GenericExprState': {
'fields':{
'arg': {'skip_tag': True},
},
},
'IntoClause': {
'fields':{
'tableSpaceName': {'visibility': 'not_null'},
},
},
# TODO: It would be nice to be able to recurse into memory contexts and
# print the tree, but need to make its own NodeFormatter in order
# to make its output look like a tree
'MemoryContextData': {
'fields':{
'methods': {
'formatter': "format_pseudo_node_field",
'field_type': "node_field",
},
'parent': {'formatter': "minimal_format_memory_context_data_field"},
'prevchild': {'formatter': "minimal_format_memory_context_data_field"},
'firstchild': {'formatter': "minimal_format_memory_context_data_field"},
'nextchild': {'formatter': "minimal_format_memory_context_data_field"},
},
},
'NullIfExpr': {
'fields': {
'args': {'skip_tag': True},
'opcollid': {'visibility': "not_null"},
'inputcollid': {'visibility': "not_null"},
},
},
'OpExpr': {
'fields':{
'args': {'skip_tag': True},
'opcollid': {'visibility': "not_null"},
'inputcollid': {'visibility': "not_null"},
'location': {'visibility': 'never_show'},
},
},
'Param': {
'fields':{
'paramtypmod': {'visibility': "hide_invalid"},
'paramcollid': {'visibility': "not_null"},
'location': {'visibility': "never_show"},
},
},
'PartitionBoundSpec': {
'fields': {
'everyGenList': {'formatter': 'format_everyGenList_node'},
'location': {'visibility': "never_show"},
},
},
'PartitionElem': {
'fields': {
'location': {'visibility': "never_show"},
},
},
'PartitionSpec': {
'fields': {
'location': {'visibility': "never_show"},
},
},
'Path': {
'fields':{
'parent': {'formatter': 'minimal_format_node_field'},
},
},
'PlannerGlobal': {
'fields':{
'subroots': {'formatter': 'minimal_format_node_list'},
},
},
'PlannerInfo': {
'fields':{
'parent_root': {'formatter': 'minimal_format_node_field'},
'subroots': {'formatter': 'minimal_format_node_list'},
# TODO: Broken. Need to make dumping these fields possible
'simple_rel_array': {'visibility': 'never_show'},
'simple_rte_array': {'visibility': 'never_show'},
'upper_rels': {'formatter': 'minimal_format_node_field'},
'upper_targets': {'formatter': 'minimal_format_node_field'},
},
},
'Query': {
'fields':{
'result_relation': {'visibility': 'not_null'},
'hasAggs': {'visibility': 'not_null'},
'hasWindowFuncs': {'visibility': 'not_null'},
'hasSubLinks': {'visibility': 'not_null'},
'hasDynamicFunctions': {'visibility': 'not_null'},
'hasFuncsWithExecRestrictions': {'visibility': 'not_null'},
'hasDistinctOn': {'visibility': 'not_null'},
'hasRecursive': {'visibility': 'not_null'},
'hasModifyingCTE': {'visibility': 'not_null'},
'hasForUpdate': {'visibility': 'not_null'},
'hasRowSecurity': {'visibility': 'not_null'},
'canOptSelectLockingClause': {'visibility': 'not_null'},
'isTableValueSelect': {'visibility': 'not_null'},
},
},
'RangeTblEntry': {
'fields': {
'relid': {'visibility': "not_null"},
'relkind': {
'visibility': "not_null",
'formatter': 'format_char_field',
},
'rellockmode': {'visibility': "not_null"},
'tablesample': {'visibility': "not_null"},
'subquery': {'visibility': "not_null"},
'security_barrier': {'visibility': "not_null"},
'tablefunc': {'visibility': "not_null"},
'ctename': {'visibility': "not_null"},
'tcelevelsup': {'visibility': "not_null"},
'enrname': {'visibility': "not_null"},
'enrtuples': {'visibility': "not_null"},
'inh': {'visibility': "not_null"},
'requiredPerms': {'visibility': "not_null"},
'checkAsUser': {'visibility': "not_null"},
'selectedCols': {'visibility': "not_null"},
'insertedCols': {'visibility': "not_null"},
'updatedCols': {'visibility': "not_null"},
'extraUpdatedCols': {'visibility': "not_null"},
'eref': {'visibility': "never_show"},
},
},
'RangeVar': {
'fields': {
'catalogname': {'visibility': "not_null"},
'schemaname': {'visibility': "not_null"},
'relpersistence': {'formatter': "format_char_field"},
'location': {'visibility': "never_show"},
},
},
'RelabelType': {
'fields': {
'arg': {'skip_tag': True},
'resultcollid': {'visibility': "not_null"},
'resulttypmod': {'visibility': "hide_invalid"},
'location': {'visibility': "never_show"},
},
},
'RestrictInfo': {
'fields': {
'parent_ec': {'formatter': 'minimal_format_node_field', },
'scansel_cache': {'formatter': 'minimal_format_node_field', }
},
},
'SubLink': {
'fields': {
'location': {'visibility': "never_show"},
},
},
'TargetEntry': {
'fields':{
'expr': {'skip_tag': True},
'resname': {'visibility': "not_null"},
'ressortgroupref': {'visibility': "not_null"},
'resorigtbl': {'visibility': "not_null"},
'resorigcol': {'visibility': "not_null"},
'resjunk': {'visibility': "not_null"},
},
},
'TupleTableSlot': {
'fields': {
'tts_tupleDescriptor': {
'field_type': 'node_field',
'formatter': 'format_tuple_descriptor',
},
'PRIVATE_tts_isnull': {
'field_type': 'node_field',
'formatter': 'format_tts_isnulls',
},
'PRIVATE_tts_values': {
'field_type': 'node_field',
'formatter': 'format_tts_values',
},
},
},
'TypeName': {
'fields': {
'typeOid': {'visibility': "not_null"},
'typemod': {'visibility': "hide_invalid"},
'location': {'visibility': "never_show"},
},
},
'Var': {
'fields':{
'varno': {'formatter': "format_varno_field"},
'vartypmod': {'visibility': "hide_invalid"},
'varcollid': {'visibility': "not_null"},
'varlevelsup': {'visibility': "not_null"},
'varoattno': {'visibility': "hide_invalid"},
'location': {'visibility': "never_show"},
},
},
# Plan Nodes
'Plan': {
'fields': {
'extParam': {'visibility': "not_null"},
'allParam': {'visibility': "not_null"},
'operatorMemKB': {'visibility': "not_null"},
'lefttree': {
'field_type': 'tree_field',
'visibility': 'not_null',
},
'righttree': {
'field_type': 'tree_field',
'visibility': 'not_null',
},
# GPDB Only:
'motionNode': {'formatter': "minimal_format_node_field"},
'gpmon_pkt': {'visibility': "never_show"},
},
},
# GPDB Specific Plan nodes
'Motion': {
'fields': {
'hashFuncs': {'visibility': "not_null"},
'segidColIdx': {'visibility': "not_null"},
'numSortCols': {'visibility': "not_null"},
'sortColIdx': {'visibility': "not_null"},
'sortOperators': {'visibility': "not_null"},
'nullsFirst': {'visibility': "not_null"},
'senderSliceInfo': {'visibility': "not_null"},
},
},
# State Nodes
'PlanState': {
'fields': {
'lefttree': {
'field_type': 'tree_field',
'visibility': 'not_null',
'skip_tag': True
},
'righttree': {
'field_type': 'tree_field',
'visibility': 'not_null',
'skip_tag': True
},
'plan': { 'formatter': 'minimal_format_node_field', },
'state': { 'formatter': 'minimal_format_node_field', },
'instrument': {
'field_type': 'node_field',
'formatter': 'format_pseudo_node_field',
},
# GPDB only:
'gpmon_pkt': {'visibility': 'never_show'},
},
},
'AggState': {
'fields': {
'hashiter': {
'field_type': 'node_field',
'formatter': 'format_pseudo_node_field',
},
},
},
# GPDB Specific Partition related nodes
'PartitionBy': {
'fields': {
'location': {'visibility': "never_show"},
},
},
'PartitionRangeItem': {
'fields': {
'location': {'visibility': "never_show"},
},
},
# Pseudo nodes
'tupleDesc': {
'fields': {
'tdtypmod': {'visibility': "hide_invalid"},
'tdrefcount': {'visibility': "hide_invalid"},
},
},
'FormData_pg_attribute': {
'fields': {
'attstattarget': {'visibility': "hide_invalid"},
'attndims': {'visibility': "not_null"},
'attcacheoff': {'visibility': "hide_invalid"},
'atttypmod': {'visibility': "hide_invalid"},
'attstorage': {'formatter': "format_char_field"},
'attalign': {'formatter': "format_char_field"},
'attinhcount': {'visibility': "not_null"},
'attcollation': {'visibility': "not_null"},
},
},
'MotionConn': {
'fields': {
'sndQueue': {'visibility': "never_show"},
'unackQueue': {'visibility': "never_show"},
'conn_info': {
'field_type': 'node_field',
'formatter': 'format_pseudo_node_field',
},
'ackWaitBeginTime': {
'field_type': 'node_field',
'formatter': 'format_pseudo_node_field',
},
'activeXmitTime': {
'field_type': 'node_field',
'formatter': 'format_pseudo_node_field',
},
'remoteHostAndPort': {'formatter': "format_string_pointer_field"},
'localHostAndPort': {'formatter': "format_string_pointer_field"},
# TODO: need a sockaddr_storage dumping function
'peer': {
'field_type': 'node_field',
'formatter': 'format_pseudo_node_field',
'visibility': 'never_show',
},
},
},
}
StateNodes = []
for node in PlanNodes:
StateNodes.append(node + "State")
JoinNodes = ['NestLoop', 'MergeJoin', 'HashJoin', 'Join', 'NestLoopState',
'MergeJoinState', 'HashJoinState', 'JoinState']
recursion_depth = 0
def format_type(t, indent=0):
'strip the leading T_ from the node type tag'
t = str(t)
if t.startswith('T_'):
t = t[2:]
return add_indent(t, indent)
def get_base_datatype(l):
if isinstance(l, gdb.Type):
stripped_type = l.strip_typedefs()
else:
stripped_type = l.type.strip_typedefs()
while stripped_type.code in [gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_ARRAY]:
# from: https://sourceware.org/gdb/current/onlinedocs/gdb/Types-In-Python.html
#
# 'For a pointer type, the target type is the type of the
# pointed-to object. For an array type (meaning C-like
# arrays), the target type is the type of the elements of
# the array. For a function or method type, the target type
# is the type of the return value. For a complex type, the
# target type is the type of the elements. For a typedef,
# the target type is the aliased type.'
stripped_type = stripped_type.target()
return stripped_type
def get_base_datatype_string(l):
basetype = get_base_datatype(l)
if basetype.tag == None:
return str(basetype)
return basetype.tag
def is_old_style_list(l):
try:
x = l['head']
return True
except:
return False
def format_oid_list(lst, indent=0):
'format list containing Oid values directly (not warapped in Node)'
# handle NULL pointer (for List we return NIL)
if (str(lst) == '0x0'):
return '(NIL)'
# we'll collect the formatted items into a Python list
tlist = []
if is_old_style_list(lst):
item = lst['head']
# walk the list until we reach the last item
while str(item) != '0x0':
# get item from the list and just grab 'oid_value as int'
tlist.append(int(item['data']['oid_value']))
# next item
item = item['next']
else:
for col in range(0, lst['length']):
element = lst['elements'][col]
tlist.append(int(element['oid_value']))
return add_indent(str(tlist), indent)
def format_node_list(lst, indent=0, newline=False):
'format list containing Node values'
# handle NULL pointer (for List we return NIL)
if (str(lst) == '0x0'):
return add_indent('(NULL)', indent)
# we'll collect the formatted items into a Python list
tlist = []
if is_old_style_list(lst):
item = lst['head']
# walk the list until we reach the last item
while str(item) != '0x0':
# we assume the list contains Node instances, so grab a reference
# and cast it to (Node*)
node = cast(item['data']['ptr_value'], 'Node')
# append the formatted Node to the result list
tlist.append(format_node(node))
# next item
item = item['next']
else:
for col in range(0, lst['length']):
element = lst['elements'][col]
node = cast(element['ptr_value'], 'Node')
tlist.append(format_node(node))
retval = str(tlist)
if newline:
retval = "\n".join([str(t) for t in tlist])
return add_indent(retval, indent)
def format_char(value):
'''convert the 'value' into a single-character string (ugly, maybe there's a better way'''
str_val = str(value.cast(gdb.lookup_type('char')))
# remove the quotes (start/end)
return str_val.split(' ')[1][1:-1]
def format_bitmapset(bitmapset):
if (str(bitmapset) == '0x0'):
return '0x0'
num_words = int(bitmapset['nwords'])
retval = '0x'
for word in reversed(range(num_words)):
retval += '%08x' % int(bitmapset['words'][word])
return retval
def format_node_array(array, start_idx, length, indent=0):
items = []
for i in range(start_idx, start_idx + length - 1):
items.append(str(i) + " => " + format_node(array[i]))
return add_indent(("\n".join(items)), indent)
def max_depth_exceeded():
global recursion_depth
if recursion_depth >= DEFAULT_DISPLAY_METHODS['max_recursion_depth']:
return True
return False
def format_node(node, indent=0):
'format a single Node instance (only selected Node types supported)'
# Check the recursion depth
global recursion_depth
if max_depth_exceeded():
if is_node(node):
node = cast(node, 'Node')
return "%s %s <max_depth_exceeded>" % (format_type(node['type']), str(node))
else:
return "%s <max_depth_exceeded>" % str(node)
recursion_depth += 1
if str(node) == '0x0':
return add_indent('(NULL)', indent)
retval = ''
if is_a(node, 'A_Const'):
node = cast(node, 'A_Const')
retval = format_a_const(node)
elif is_a(node, 'List'):
node = cast(node, 'List')
retval = format_node_list(node, 0, True)
elif is_a(node, 'String'):
node = cast(node, 'Value')
retval = 'String [%s]' % getchars(node['val']['str'])
elif is_a(node, 'Integer'):
node = cast(node, 'Value')
retval = 'Integer [%s]' % node['val']['ival']
elif is_a(node, 'OidList'):
retval = 'OidList: %s' % format_oid_list(node)
elif is_a(node, 'IntList'):
retval = 'IntList: %s' % format_oid_list(node)
elif is_pathnode(node):
node_formatter = PlanStateFormatter(node)
retval += node_formatter.format()
elif is_plannode(node):
node_formatter = PlanStateFormatter(node)
retval += node_formatter.format()
elif is_statenode(node):
node_formatter = PlanStateFormatter(node)
retval += node_formatter.format()
else:
node_formatter = NodeFormatter(node)
retval += node_formatter.format()
recursion_depth -= 1
return add_indent(str(retval), indent)
def is_pathnode(node):
for nodestring in PathNodes:
if is_a(node, nodestring):
return True
return False
def is_plannode(node):
for nodestring in PlanNodes:
if is_a(node, nodestring):
return True
return False
def is_statenode(node):
for nodestring in StateNodes:
if is_a(node, nodestring):
return True
return False
def is_joinnode(node):
for nodestring in JoinNodes:
if is_a(node, nodestring):
return True
return False
def format_a_const(node, indent=0):
retval = "A_Const [%(val)s]" % {
'val': format_node(node['val'].address),
}
return add_indent(retval, indent)
def is_a(n, t):
'''checks that the node has type 't' (just like IsA() macro)'''
if not is_node(n):
return False
n = cast(n, 'Node')
return (str(n['type']) == ('T_' + t))
def is_xpr(l):
try:
x = l['xpr']
return True
except:
return False
def is_node(l):
'''return True if the value looks like a Node (has 'type' field)'''
if is_xpr(l):
return True
try:
x = l['type']
return True
except:
return False
def is_type(value, type_name, is_pointer):
t = gdb.lookup_type(type_name)
if(is_pointer):
t = t.pointer()
return (str(value.type) == str(t))
# This doesn't work for list types for some reason...
# return (gdb.types.get_basic_type(value.type) == gdb.types.get_basic_type(t))
def cast(node, type_name):
'''wrap the gdb cast to proper node type'''
# lookup the type with name 'type_name' and cast the node to it
t = gdb.lookup_type(type_name)
return node.cast(t.pointer())
def get_base_node_type(node):
if is_node(node):
node = cast(node, "Node")
return format_type(node['type'])
return None
def add_indent(val, indent, add_newline=False):
retval = ''
if add_newline == True:
retval += '\n'
retval += "\n".join([(("\t" * indent) + l) for l in val.split("\n")])
return retval
def getchars(arg):
if (str(arg) == '0x0'):
return str(arg)
retval = '"'
i=0
while arg[i] != ord("\0"):
character = int(arg[i].cast(gdb.lookup_type("char")))
if chr(character) in string.printable:
retval += "%c" % chr(character)
else:
retval += "\\x%x" % character
i += 1
retval += '"'
return retval
def get_node_fields(node):
nodefields = [("Node", True), ("Expr", True)]
type_name = str(node['type']).replace("T_", "")
t = gdb.lookup_type(type_name)
fields = []
for v in t.values():
for field, is_pointer in nodefields:
if is_type(v, field, is_pointer):
fields.append(v.name)
return fields
def get_list_fields(node):
listfields = [("List", True)]
type_name = str(node['type']).replace("T_", "")
t = gdb.lookup_type(type_name)
fields = []
for v in t.values():
for field, is_pointer in listfields:
if is_type(v, field, is_pointer):
fields.append(v.name)
return fields
def format_regular_field(node, field):
return node[field]
def format_string_pointer_field(node, field):
return getchars(node[field])
def format_char_field(node, field):
return "'%s'" % format_char(node[field])
def format_bitmapset_field(node, field):
return format_bitmapset(node[field])
def format_generated_when(node, field):
generated_when = {
'a': 'ATTRIBUTE_IDENTITY_ALWAYS',
'd': 'ATTRIBUTE_IDENTITY_BY_DEFAULT',
's': 'ATTRIBUTE_GENERATED_STORED',
}
fk_char = format_char(node[field])
if generated_when.get(fk_char) != None:
return generated_when.get(fk_char)
return fk_char
def format_foreign_key_matchtype(node, field):
foreign_key_matchtypes = {
'f': 'FKCONSTR_MATCH_FULL',
'p': 'FKCONSTR_MATCH_PARTIAL',
's': 'FKCONSTR_MATCH_SIMPLE',
}
fk_char = format_char(node[field])
if foreign_key_matchtypes.get(fk_char) != None:
return foreign_key_matchtypes.get(fk_char)
return fk_char
def format_foreign_key_actions(node, field):
foreign_key_actions = {
'a': 'FKONSTR_ACTION_NOACTION',
'r': 'FKCONSTR_ACTION_RESTRICT',
'c': 'FKCONSTR_ACTION_CASCADE',
'n': 'FKONSTR_ACTION_SETNULL',
'd': 'FKONSTR_ACTION_SETDEFAULT',
}
fk_char = format_char(node[field])
if foreign_key_actions.get(fk_char) != None:
return foreign_key_actions.get(fk_char)
return fk_char
def format_varno_field(node, field):
varno_type = {
65000: "INNER_VAR",
65001: "OUTER_VAR",
65002: "INDEX_VAR",
}
varno = int(node[field])
if varno_type.get(varno) != None:
return varno_type.get(varno)
return node[field]
def format_timeval_field(node, field):
return "%s.%s" %(node[field]['tv_sec'], node[field]['tv_usec'])
def format_namedata_field(node, field):
return getchars(node[field]['data'])
def format_item_pointer_data_field(node, field):
ip_blkid = node[field]['ip_blkid']
block_hi = int(ip_blkid['bi_hi'])
block_low = int(ip_blkid['bi_lo'])
block_id = block_hi << 16
block_id += block_low
return "(%s,%s)" % (block_id, node[field]['ip_posid'])
def format_optional_node_field(node, fieldname, cast_to=None, skip_tag=False, print_null=False, indent=1):
if cast_to != None:
node = cast(node, cast_to)
if str(node[fieldname]) != '0x0':
node_output = format_node(node[fieldname])
if skip_tag == True:
return add_indent('%s' % node_output, indent, True)
else:
retval = '[%s] ' % fieldname
if node_output.count('\n') > 0:
node_output = add_indent(node_output, 1, True)
retval += node_output
return add_indent(retval , indent, True)
elif print_null == True:
return add_indent("[%s] (NULL)" % fieldname, indent, True)
return ''
def format_optional_node_list(node, fieldname, cast_to=None, skip_tag=False, newLine=True, print_null=False, indent=1):
if cast_to != None:
node = cast(node, cast_to)
retval = ''
indent_add = 0
if str(node[fieldname]) != '0x0':
if is_a(node[fieldname], 'OidList') or is_a(node[fieldname], 'IntList'):
return format_optional_oid_list(node, fieldname, skip_tag, newLine, print_null, indent)
if skip_tag == False:
retval += add_indent('[%s]' % fieldname, indent, True)
indent_add = 1
if newLine == True:
retval += '\n'
retval += '%s' % format_node_list(node[fieldname], indent + indent_add, newLine)
else:
retval += ' %s' % format_node_list(node[fieldname], 0, newLine)
elif print_null == True:
return add_indent("[%s] (NIL)" % fieldname, indent, True)
return retval
def format_optional_oid_list(node, fieldname, skip_tag=False, newLine=False, print_null=False, indent=1):
retval = ''
if str(node[fieldname]) != '0x0':
node_type = format_type(node[fieldname]['type'])
if skip_tag == False:
retval += '[%s] %s' % (fieldname, format_node(node[fieldname]))
else:
retval += format_node(node[fieldname])
retval = add_indent(retval, indent, True)
elif print_null == True:
retval += add_indent("[%s] (NIL)" % fieldname, indent, True)