forked from openvswitch/ovs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ovs_gdb.py
1573 lines (1278 loc) · 50.9 KB
/
ovs_gdb.py
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 (c) 2018 Eelco Chaudron
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
# Files name:
# ovs_gdb.py
#
# Description:
# GDB commands and functions for Open vSwitch debugging
#
# Author:
# Eelco Chaudron
#
# Initial Created:
# 23 April 2018
#
# Notes:
# It implements the following GDB commands:
# - ovs_dump_bridge {ports|wanted}
# - ovs_dump_bridge_ports <struct bridge *>
# - ovs_dump_dp_netdev [ports]
# - ovs_dump_dp_netdev_poll_threads <struct dp_netdev *>
# - ovs_dump_dp_netdev_ports <struct dp_netdev *>
# - ovs_dump_dp_provider
# - ovs_dump_netdev
# - ovs_dump_netdev_provider
# - ovs_dump_ovs_list <struct ovs_list *> {[<structure>] [<member>] {dump}]}
# - ovs_dump_packets <struct dp_packet_batch|dp_packet> [tcpdump options]
# - ovs_dump_cmap <struct cmap *> {[<structure>] [<member>] {dump}]}
# - ovs_dump_hmap <struct hmap *> <structure> <member> {dump}
# - ovs_dump_simap <struct simap *>
# - ovs_dump_smap <struct smap *>
# - ovs_dump_udpif_keys {<udpif_name>|<udpif_address>} {short}
# - ovs_show_fdb {[<bridge_name>] {dbg} {hash}}
# - ovs_show_upcall {dbg}
#
# Example:
# $ gdb $(which ovs-vswitchd) $(pidof ovs-vswitchd)
# (gdb) source ./utilities/gdb/ovs_gdb.py
#
# (gdb) ovs_dump_<TAB>
# ovs_dump_bridge ovs_dump_bridge_ports ovs_dump_dp_netdev
# ovs_dump_dp_netdev_ports ovs_dump_netdev
#
# (gdb) ovs_dump_bridge
# (struct bridge *) 0x5615471ed2e0: name = br2, type = system
# (struct bridge *) 0x561547166350: name = br0, type = system
# (struct bridge *) 0x561547216de0: name = ovs_pvp_br0, type = netdev
# (struct bridge *) 0x5615471d0420: name = br1, type = system
#
# (gdb) p *(struct bridge *) 0x5615471d0420
# $1 = {node = {hash = 24776443, next = 0x0}, name = 0x5615471cca90 "br1",
# type = 0x561547163bb0 "system",
# ...
# ...
#
import gdb
import struct
import sys
import uuid
try:
from scapy.layers.l2 import Ether
from scapy.utils import tcpdump
except ModuleNotFoundError:
Ether = None
tcpdump = None
#
# Global #define's from OVS which might need updating based on a version.
#
N_UMAPS = 512
#
# The container_of code below is a copied from the Linux kernel project file,
# scripts/gdb/linux/utils.py. It has the following copyright header:
#
# # gdb helper commands and functions for Linux kernel debugging
# #
# # common utilities
# #
# # Copyright (c) Siemens AG, 2011-2013
# #
# # Authors:
# # Jan Kiszka <[email protected]>
# #
# # This work is licensed under the terms of the GNU GPL version 2.
#
class CachedType(object):
def __init__(self, name):
self._type = None
self._name = name
def _new_objfile_handler(self, event):
self._type = None
gdb.events.new_objfile.disconnect(self._new_objfile_handler)
def get_type(self):
if self._type is None:
self._type = gdb.lookup_type(self._name)
if self._type is None:
raise gdb.GdbError(
"cannot resolve type '{0}'".format(self._name))
if hasattr(gdb, 'events') and hasattr(gdb.events, 'new_objfile'):
gdb.events.new_objfile.connect(self._new_objfile_handler)
return self._type
long_type = CachedType("long")
def get_long_type():
global long_type
return long_type.get_type()
def offset_of(typeobj, field):
element = gdb.Value(0).cast(typeobj)
return int(str(element[field].address).split()[0], 16)
def container_of(ptr, typeobj, member):
return (ptr.cast(get_long_type()) -
offset_of(typeobj, member)).cast(typeobj)
def get_global_variable(name):
var = gdb.lookup_symbol(name)[0]
if var is None or not var.is_variable:
print("Can't find {} global variable, are you sure "
"you are debugging OVS?".format(name))
return None
return gdb.parse_and_eval(name)
def get_time_msec():
# There is no variable that stores the current time each iteration,
# to get a decent time time_now() value. For now we take the global
# "coverage_run_time" value, which is the current time + max 5 seconds
# (COVERAGE_RUN_INTERVAL)
return int(get_global_variable("coverage_run_time")), -5000
def get_time_now():
# See get_time_msec() above
return int(get_global_variable("coverage_run_time")) / 1000, -5
def eth_addr_to_string(eth_addr):
return "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}".format(
int(eth_addr['ea'][0]),
int(eth_addr['ea'][1]),
int(eth_addr['ea'][2]),
int(eth_addr['ea'][3]),
int(eth_addr['ea'][4]),
int(eth_addr['ea'][5]))
#
# Simple class to print a spinner on the console
#
class ProgressIndicator(object):
def __init__(self, message=None):
self.spinner = "/-\\|"
self.spinner_index = 0
self.message = message
if self.message is not None:
print(self.message, end='')
def update(self):
print("{}\b".format(self.spinner[self.spinner_index]), end='')
sys.stdout.flush()
self.spinner_index += 1
if self.spinner_index >= len(self.spinner):
self.spinner_index = 0
def pause(self):
print("\r\033[K", end='')
def resume(self):
if self.message is not None:
print(self.message, end='')
self.update()
def done(self):
self.pause()
#
# Class that will provide an iterator over an OVS cmap.
#
class ForEachCMAP(object):
def __init__(self, cmap, typeobj=None, member='node'):
self.cmap = cmap
self.first = True
self.typeobj = typeobj
self.member = member
# Cursor values
self.node = 0
self.bucket_idx = 0
self.entry_idx = 0
def __iter__(self):
return self
def __get_CMAP_K(self):
ptr_type = gdb.lookup_type("void").pointer()
return (64 - 4) / (4 + ptr_type.sizeof)
def __next(self):
ipml = self.cmap['impl']['p']
if self.node != 0:
self.node = self.node['next']['p']
if self.node != 0:
return
while self.bucket_idx <= ipml['mask']:
buckets = ipml['buckets'][self.bucket_idx]
while self.entry_idx < self.__get_CMAP_K():
self.node = buckets['nodes'][self.entry_idx]['next']['p']
self.entry_idx += 1
if self.node != 0:
return
self.bucket_idx += 1
self.entry_idx = 0
raise StopIteration
def __next__(self):
ipml = self.cmap['impl']['p']
if ipml['n'] == 0:
raise StopIteration
self.__next()
if self.typeobj is None:
return self.node
return container_of(self.node,
gdb.lookup_type(self.typeobj).pointer(),
self.member)
def next(self):
return self.__next__()
#
# Class that will provide an iterator over an OVS hmap.
#
class ForEachHMAP(object):
def __init__(self, hmap, typeobj=None, member='node'):
self.hmap = hmap
self.node = None
self.first = True
self.typeobj = typeobj
self.member = member
def __iter__(self):
return self
def __next(self, start):
for i in range(start, (self.hmap['mask'] + 1)):
self.node = self.hmap['buckets'][i]
if self.node != 0:
return
raise StopIteration
def __next__(self):
#
# In the real implementation the n values is never checked,
# however when debugging we do, as we might try to access
# a hmap that has been cleared/hmap_destroy().
#
if self.hmap['n'] <= 0:
raise StopIteration
if self.first:
self.first = False
self.__next(0)
elif self.node['next'] != 0:
self.node = self.node['next']
else:
self.__next((self.node['hash'] & self.hmap['mask']) + 1)
if self.typeobj is None:
return self.node
return container_of(self.node,
gdb.lookup_type(self.typeobj).pointer(),
self.member)
def next(self):
return self.__next__()
#
# Class that will provide an iterator over an Netlink attributes
#
class ForEachNL(object):
def __init__(self, nlattrs, nlattrs_len):
self.attr = nlattrs.cast(gdb.lookup_type('struct nlattr').pointer())
self.attr_len = int(nlattrs_len)
def __iter__(self):
return self
def round_up(self, val, round_to):
return int(val) + (round_to - int(val)) % round_to
def __next__(self):
if self.attr is None or \
self.attr_len < 4 or self.attr['nla_len'] < 4 or \
self.attr['nla_len'] > self.attr_len:
#
# Invalid attr set, maybe we should raise an exception?
#
raise StopIteration
attr = self.attr
self.attr_len -= self.round_up(attr['nla_len'], 4)
self.attr = self.attr.cast(gdb.lookup_type('void').pointer()) \
+ self.round_up(attr['nla_len'], 4)
self.attr = self.attr.cast(gdb.lookup_type('struct nlattr').pointer())
return attr
def next(self):
return self.__next__()
#
# Class that will provide an iterator over an OVS shash.
#
class ForEachSHASH(ForEachHMAP):
def __init__(self, shash, typeobj=None):
self.data_typeobj = typeobj
super(ForEachSHASH, self).__init__(shash['map'],
"struct shash_node", "node")
def __next__(self):
node = super(ForEachSHASH, self).__next__()
if self.data_typeobj is None:
return node
return node['data'].cast(gdb.lookup_type(self.data_typeobj).pointer())
def next(self):
return self.__next__()
#
# Class that will provide an iterator over an OVS simap.
#
class ForEachSIMAP(ForEachHMAP):
def __init__(self, shash):
super(ForEachSIMAP, self).__init__(shash['map'],
"struct simap_node", "node")
def __next__(self):
node = super(ForEachSIMAP, self).__next__()
return node['name'], node['data']
def next(self):
return self.__next__()
#
# Class that will provide an iterator over an OVS smap.
#
class ForEachSMAP(ForEachHMAP):
def __init__(self, shash):
super(ForEachSMAP, self).__init__(shash['map'],
"struct smap_node", "node")
def __next__(self):
node = super(ForEachSMAP, self).__next__()
return node['key'], node['value']
def next(self):
return self.__next__()
#
# Class that will provide an iterator over an OVS list.
#
class ForEachLIST(object):
def __init__(self, list, typeobj=None, member='node'):
self.list = list
self.node = list
self.typeobj = typeobj
self.member = member
def __iter__(self):
return self
def __next__(self):
if self.list.address == self.node['next']:
raise StopIteration
self.node = self.node['next']
if self.typeobj is None:
return self.node
return container_of(self.node,
gdb.lookup_type(self.typeobj).pointer(),
self.member)
def next(self):
return self.__next__()
#
# Class that will provide an iterator over an OFPACTS.
#
class ForEachOFPACTS(object):
def __init__(self, ofpacts, ofpacts_len):
self.ofpact = ofpacts.cast(gdb.lookup_type('struct ofpact').pointer())
self.length = int(ofpacts_len)
def __round_up(self, val, round_to):
return int(val) + (round_to - int(val)) % round_to
def __iter__(self):
return self
def __next__(self):
if self.ofpact is None or self.length <= 0:
raise StopIteration
ofpact = self.ofpact
length = self.__round_up(ofpact['len'], 8)
self.length -= length
self.ofpact = self.ofpact.cast(
gdb.lookup_type('void').pointer()) + length
self.ofpact = self.ofpact.cast(
gdb.lookup_type('struct ofpact').pointer())
return ofpact
def next(self):
return self.__next__()
#
# Implements the GDB "ovs_dump_bridges" command
#
class CmdDumpBridge(gdb.Command):
"""Dump all configured bridges.
Usage:
ovs_dump_bridge {ports|wanted}
"""
def __init__(self):
super(CmdDumpBridge, self).__init__("ovs_dump_bridge",
gdb.COMMAND_DATA)
def invoke(self, arg, from_tty):
ports = False
wanted = False
arg_list = gdb.string_to_argv(arg)
if len(arg_list) > 1 or \
(len(arg_list) == 1 and arg_list[0] != "ports" and
arg_list[0] != "wanted"):
print("usage: ovs_dump_bridge {ports|wanted}")
return
elif len(arg_list) == 1:
if arg_list[0] == "ports":
ports = True
else:
wanted = True
all_bridges = get_global_variable('all_bridges')
if all_bridges is None:
return
for node in ForEachHMAP(all_bridges,
"struct bridge", "node"):
print("(struct bridge *) {}: name = {}, type = {}".
format(node, node['name'].string(),
node['type'].string()))
if ports:
for port in ForEachHMAP(node['ports'],
"struct port", "hmap_node"):
CmdDumpBridgePorts.display_single_port(port, 4)
if wanted:
for port in ForEachSHASH(node['wanted_ports'],
typeobj="struct ovsrec_port"):
print(" (struct ovsrec_port *) {}: name = {}".
format(port, port['name'].string()))
# print port.dereference()
#
# Implements the GDB "ovs_dump_bridge_ports" command
#
class CmdDumpBridgePorts(gdb.Command):
"""Dump all ports added to a specific struct bridge*.
Usage:
ovs_dump_bridge_ports <struct bridge *>
"""
def __init__(self):
super(CmdDumpBridgePorts, self).__init__("ovs_dump_bridge_ports",
gdb.COMMAND_DATA)
@staticmethod
def display_single_port(port, indent=0):
indent = " " * indent
port = port.cast(gdb.lookup_type('struct port').pointer())
print("{}(struct port *) {}: name = {}, bridge = (struct bridge *) {}".
format(indent, port, port['name'].string(),
port['bridge']))
indent += " " * 4
for iface in ForEachLIST(port['ifaces'], "struct iface", "port_elem"):
print("{}(struct iface *) {}: name = {}, ofp_port = {}, "
"netdev = (struct netdev *) {}".
format(indent, iface, iface['name'],
iface['ofp_port'], iface['netdev']))
def invoke(self, arg, from_tty):
arg_list = gdb.string_to_argv(arg)
if len(arg_list) != 1:
print("usage: ovs_dump_bridge_ports <struct bridge *>")
return
bridge = gdb.parse_and_eval(arg_list[0]).cast(
gdb.lookup_type('struct bridge').pointer())
for node in ForEachHMAP(bridge['ports'],
"struct port", "hmap_node"):
self.display_single_port(node)
#
# Implements the GDB "ovs_dump_dp_netdev" command
#
class CmdDumpDpNetdev(gdb.Command):
"""Dump all registered dp_netdev structures.
Usage:
ovs_dump_dp_netdev [ports]
"""
def __init__(self):
super(CmdDumpDpNetdev, self).__init__("ovs_dump_dp_netdev",
gdb.COMMAND_DATA)
def invoke(self, arg, from_tty):
ports = False
arg_list = gdb.string_to_argv(arg)
if len(arg_list) > 1 or \
(len(arg_list) == 1 and arg_list[0] != "ports"):
print("usage: ovs_dump_dp_netdev [ports]")
return
elif len(arg_list) == 1:
ports = True
dp_netdevs = get_global_variable('dp_netdevs')
if dp_netdevs is None:
return
for dp in ForEachSHASH(dp_netdevs, typeobj=('struct dp_netdev')):
print("(struct dp_netdev *) {}: name = {}, class = "
"(struct dpif_class *) {}".
format(dp, dp['name'].string(), dp['class']))
if ports:
for node in ForEachHMAP(dp['ports'],
"struct dp_netdev_port", "node"):
CmdDumpDpNetdevPorts.display_single_port(node, 4)
#
# Implements the GDB "ovs_dump_dp_netdev_poll_threads" command
#
class CmdDumpDpNetdevPollThreads(gdb.Command):
"""Dump all poll_thread info added to a specific struct dp_netdev*.
Usage:
ovs_dump_dp_netdev_poll_threads <struct dp_netdev *>
"""
def __init__(self):
super(CmdDumpDpNetdevPollThreads, self).__init__(
"ovs_dump_dp_netdev_poll_threads",
gdb.COMMAND_DATA)
@staticmethod
def display_single_poll_thread(pmd_thread, indent=0):
indent = " " * indent
print("{}(struct dp_netdev_pmd_thread *) {}: core_id = {}, "
"numa_id {}".format(indent,
pmd_thread, pmd_thread['core_id'],
pmd_thread['numa_id']))
def invoke(self, arg, from_tty):
arg_list = gdb.string_to_argv(arg)
if len(arg_list) != 1:
print("usage: ovs_dump_dp_netdev_poll_threads "
"<struct dp_netdev *>")
return
dp_netdev = gdb.parse_and_eval(arg_list[0]).cast(
gdb.lookup_type('struct dp_netdev').pointer())
for node in ForEachCMAP(dp_netdev['poll_threads'],
"struct dp_netdev_pmd_thread", "node"):
self.display_single_poll_thread(node)
#
# Implements the GDB "ovs_dump_dp_netdev_ports" command
#
class CmdDumpDpNetdevPorts(gdb.Command):
"""Dump all ports added to a specific struct dp_netdev*.
Usage:
ovs_dump_dp_netdev_ports <struct dp_netdev *>
"""
def __init__(self):
super(CmdDumpDpNetdevPorts, self).__init__("ovs_dump_dp_netdev_ports",
gdb.COMMAND_DATA)
@staticmethod
def display_single_port(port, indent=0):
indent = " " * indent
print("{}(struct dp_netdev_port *) {}:".format(indent, port))
print("{} port_no = {}, n_rxq = {}, type = {}".
format(indent, port['port_no'], port['n_rxq'],
port['type'].string()))
print("{} netdev = (struct netdev *) {}: name = {}, "
"n_txq/rxq = {}/{}".
format(indent, port['netdev'],
port['netdev']['name'].string(),
port['netdev']['n_txq'],
port['netdev']['n_rxq']))
def invoke(self, arg, from_tty):
arg_list = gdb.string_to_argv(arg)
if len(arg_list) != 1:
print("usage: ovs_dump_dp_netdev_ports <struct dp_netdev *>")
return
dp_netdev = gdb.parse_and_eval(arg_list[0]).cast(
gdb.lookup_type('struct dp_netdev').pointer())
for node in ForEachHMAP(dp_netdev['ports'],
"struct dp_netdev_port", "node"):
# print node.dereference()
self.display_single_port(node)
#
# Implements the GDB "ovs_dump_dp_provider" command
#
class CmdDumpDpProvider(gdb.Command):
"""Dump all registered registered_dpif_class structures.
Usage:
ovs_dump_dp_provider
"""
def __init__(self):
super(CmdDumpDpProvider, self).__init__("ovs_dump_dp_provider",
gdb.COMMAND_DATA)
def invoke(self, arg, from_tty):
dp_providers = get_global_variable('dpif_classes')
if dp_providers is None:
return
for dp_class in ForEachSHASH(dp_providers,
typeobj="struct registered_dpif_class"):
print("(struct registered_dpif_class *) {}: "
"(struct dpif_class *) 0x{:x} = {{type = {}, ...}}, "
"refcount = {}".
format(dp_class,
int(dp_class['dpif_class']),
dp_class['dpif_class']['type'].string(),
dp_class['refcount']))
#
# Implements the GDB "ovs_dump_netdev" command
#
class CmdDumpNetdev(gdb.Command):
"""Dump all registered netdev structures.
Usage:
ovs_dump_netdev
"""
def __init__(self):
super(CmdDumpNetdev, self).__init__("ovs_dump_netdev",
gdb.COMMAND_DATA)
@staticmethod
def display_single_netdev(netdev, indent=0):
indent = " " * indent
print("{}(struct netdev *) {}: name = {:15}, auto_classified = {}, "
"netdev_class = {}".
format(indent, netdev, netdev['name'].string(),
netdev['auto_classified'], netdev['netdev_class']))
def invoke(self, arg, from_tty):
netdev_shash = get_global_variable('netdev_shash')
if netdev_shash is None:
return
for netdev in ForEachSHASH(netdev_shash, "struct netdev"):
self.display_single_netdev(netdev)
#
# Implements the GDB "ovs_dump_netdev_provider" command
#
class CmdDumpNetdevProvider(gdb.Command):
"""Dump all registered netdev providers.
Usage:
ovs_dump_netdev_provider
"""
def __init__(self):
super(CmdDumpNetdevProvider, self).__init__("ovs_dump_netdev_provider",
gdb.COMMAND_DATA)
@staticmethod
def is_class_vport_class(netdev_class):
netdev_class = netdev_class.cast(
gdb.lookup_type('struct netdev_class').pointer())
vport_construct = gdb.lookup_symbol('netdev_vport_construct')[0]
if netdev_class['construct'] == vport_construct.value():
return True
return False
@staticmethod
def display_single_netdev_provider(reg_class, indent=0):
indent = " " * indent
print("{}(struct netdev_registered_class *) {}: refcnt = {},".
format(indent, reg_class, reg_class['refcnt']))
print("{} (struct netdev_class *) 0x{:x} = {{type = {}, "
"is_pmd = {}, ...}}, ".
format(indent, int(reg_class['class']),
reg_class['class']['type'].string(),
reg_class['class']['is_pmd']))
if CmdDumpNetdevProvider.is_class_vport_class(reg_class['class']):
vport = container_of(
reg_class['class'],
gdb.lookup_type('struct vport_class').pointer(),
'netdev_class')
if vport['dpif_port'] != 0:
dpif_port = vport['dpif_port'].string()
else:
dpif_port = "\"\""
print("{} (struct vport_class *) 0x{:x} = "
"{{ dpif_port = {}, ... }}".
format(indent, int(vport), dpif_port))
def invoke(self, arg, from_tty):
netdev_classes = get_global_variable('netdev_classes')
if netdev_classes is None:
return
for reg_class in ForEachCMAP(netdev_classes,
"struct netdev_registered_class",
"cmap_node"):
self.display_single_netdev_provider(reg_class)
#
# Implements the GDB "ovs_dump_ovs_list" command
#
class CmdDumpOvsList(gdb.Command):
"""Dump all nodes of an ovs_list give
Usage:
ovs_dump_ovs_list <struct ovs_list *> {[<structure>] [<member>] {dump}]}
For example dump all the none quiescent OvS RCU threads:
(gdb) ovs_dump_ovs_list &ovsrcu_threads
(struct ovs_list *) 0x1400
(struct ovs_list *) 0xcc00
(struct ovs_list *) 0x6806
This is not very useful, so please use this with the container_of mode:
(gdb) set $threads = &ovsrcu_threads
(gdb) ovs_dump_ovs_list $threads 'struct ovsrcu_perthread' list_node
(struct ovsrcu_perthread *) 0x1400
(struct ovsrcu_perthread *) 0xcc00
(struct ovsrcu_perthread *) 0x6806
Now you can manually use the print command to show the content, or use the
dump option to dump the structure for all nodes:
(gdb) ovs_dump_ovs_list $threads 'struct ovsrcu_perthread' list_node dump
(struct ovsrcu_perthread *) 0x1400 =
{list_node = {prev = 0x48e80 <ovsrcu_threads>, next = 0xcc00}, mutex...
(struct ovsrcu_perthread *) 0xcc00 =
{list_node = {prev = 0x1400, next = 0x6806}, mutex ...
(struct ovsrcu_perthread *) 0x6806 =
{list_node = {prev = 0xcc00, next = 0x48e80 <ovsrcu_threads>}, ...
"""
def __init__(self):
super(CmdDumpOvsList, self).__init__("ovs_dump_ovs_list",
gdb.COMMAND_DATA)
def invoke(self, arg, from_tty):
arg_list = gdb.string_to_argv(arg)
typeobj = None
member = None
dump = False
if len(arg_list) != 1 and len(arg_list) != 3 and len(arg_list) != 4:
print("usage: ovs_dump_ovs_list <struct ovs_list *> "
"{[<structure>] [<member>] {dump}]}")
return
header = gdb.parse_and_eval(arg_list[0]).cast(
gdb.lookup_type('struct ovs_list').pointer())
if len(arg_list) >= 3:
typeobj = arg_list[1]
member = arg_list[2]
if len(arg_list) == 4 and arg_list[3] == "dump":
dump = True
for node in ForEachLIST(header.dereference()):
if typeobj is None or member is None:
print("(struct ovs_list *) {}".format(node))
else:
print("({} *) {} {}".format(
typeobj,
container_of(node,
gdb.lookup_type(typeobj).pointer(), member),
"=" if dump else ""))
if dump:
print(" {}\n".format(container_of(
node,
gdb.lookup_type(typeobj).pointer(),
member).dereference()))
#
# Implements the GDB "ovs_dump_cmap" command
#
class CmdDumpCmap(gdb.Command):
"""Dump all nodes of a given cmap
Usage:
ovs_dump_cmap <struct cmap *> {[<structure>] [<member>] {dump}]}
For example dump all the rules in a dpcls_subtable:
(gdb) ovs_dump_cmap &subtable->rules
(struct cmap *) 0x3e02758
This is not very useful, so please use this with the container_of mode:
(gdb) ovs_dump_cmap &subtable->rules "struct dpcls_rule" cmap_node
(struct dpcls_rule *) 0x3e02758
Now you can manually use the print command to show the content, or use the
dump option to dump the structure for all nodes:
(gdb) ovs_dump_cmap &subtable->rules "struct dpcls_rule" cmap_node dump
(struct dpcls_rule *) 0x3e02758 =
{cmap_node = {next = {p = 0x0}}, mask = 0x3dfe100, flow = {hash = ...
"""
def __init__(self):
super(CmdDumpCmap, self).__init__("ovs_dump_cmap",
gdb.COMMAND_DATA)
def invoke(self, arg, from_tty):
arg_list = gdb.string_to_argv(arg)
typeobj = None
member = None
dump = False
if len(arg_list) != 1 and len(arg_list) != 3 and len(arg_list) != 4:
print("usage: ovs_dump_cmap <struct cmap *> "
"{[<structure>] [<member>] {dump}]}")
return
cmap = gdb.parse_and_eval(arg_list[0]).cast(
gdb.lookup_type('struct cmap').pointer())
if len(arg_list) >= 3:
typeobj = arg_list[1]
member = arg_list[2]
if len(arg_list) == 4 and arg_list[3] == "dump":
dump = True
for node in ForEachCMAP(cmap.dereference()):
if typeobj is None or member is None:
print("(struct cmap *) {}".format(node))
else:
print("({} *) {} {}".format(
typeobj,
container_of(node,
gdb.lookup_type(typeobj).pointer(), member),
"=" if dump else ""))
if dump:
print(" {}\n".format(container_of(
node,
gdb.lookup_type(typeobj).pointer(),
member).dereference()))
#
# Implements the GDB "ovs_dump_hmap" command
#
class CmdDumpHmap(gdb.Command):
"""Dump all nodes of a given hmap
Usage:
ovs_dump_hmap <struct hmap *> <structure> <member> {dump}
For example dump all the bridges when the all_bridges variable is
optimized out due to LTO:
(gdb) ovs_dump_hmap "&'all_bridges.lto_priv.0'" "struct bridge" "node"
(struct bridge *) 0x55ec43069c70
(struct bridge *) 0x55ec430428a0
(struct bridge *) 0x55ec430a55f0
The 'dump' option will also include the full structure content in the
output.
"""
def __init__(self):
super(CmdDumpHmap, self).__init__("ovs_dump_hmap",
gdb.COMMAND_DATA)
def invoke(self, arg, from_tty):
arg_list = gdb.string_to_argv(arg)
typeobj = None
member = None
dump = False
if len(arg_list) != 3 and len(arg_list) != 4:
print("usage: ovs_dump_hmap <struct hmap *> "
"<structure> <member> {dump}")
return
hmap = gdb.parse_and_eval(arg_list[0]).cast(
gdb.lookup_type('struct hmap').pointer())
typeobj = arg_list[1]
member = arg_list[2]
if len(arg_list) == 4 and arg_list[3] == "dump":
dump = True
for node in ForEachHMAP(hmap.dereference(), typeobj, member):
print("({} *) {} {}".format(typeobj, node, "=" if dump else ""))
if dump:
print(" {}\n".format(node.dereference()))
#
# Implements the GDB "ovs_dump_simap" command
#
class CmdDumpSimap(gdb.Command):
"""Dump all key, value entries of a simap
Usage:
ovs_dump_simap <struct simap *>
"""
def __init__(self):
super(CmdDumpSimap, self).__init__("ovs_dump_simap",
gdb.COMMAND_DATA)
def invoke(self, arg, from_tty):
arg_list = gdb.string_to_argv(arg)
if len(arg_list) != 1:
print("ERROR: Missing argument!\n")
print(self.__doc__)
return
simap = gdb.parse_and_eval(arg_list[0]).cast(
gdb.lookup_type('struct simap').pointer())
values = dict()
max_name_len = 0
for name, value in ForEachSIMAP(simap.dereference()):
values[name.string()] = int(value)
if len(name.string()) > max_name_len:
max_name_len = len(name.string())
for name in sorted(values.keys()):
print("{}: {} / 0x{:x}".format(name.ljust(max_name_len),
values[name], values[name]))