blob: 2a33f17f4da5ffde867f711b3e9678d95fb231f7 [file] [log] [blame]
andrewa38d0012018-08-06 00:25:33 -04001.. _gdb_examples:
2
3.. toctree::
4
5GDB Examples
6===============
7
8In this section we have a few useful gdb commands.
9
10Starting GDB
11----------------------------
12
John DeNisco2ba9dcf2018-08-23 14:04:22 -040013Once at the gdb prompt, VPP can be started by running the following commands:
andrewa38d0012018-08-06 00:25:33 -040014
15.. code-block:: console
16
17 (gdb) run -c /etc/vpp/startup.conf
18 Starting program: /scratch/vpp-master/build-root/install-vpp_debug-native/vpp/bin/vpp -c /etc/vpp/startup.conf
19 [Thread debugging using libthread_db enabled]
20 Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Damjan Marion79dcbc72018-09-12 14:01:10 +020021 vlib_plugin_early_init:361: plugin path /scratch/vpp-master/build-root/install-vpp_debug-native/vpp/lib/vpp_plugins:/scratch/vpp-master/build-root/install-vpp_debug-native/vpp/lib/vpp_plugins
andrewa38d0012018-08-06 00:25:33 -040022 ....
23
24Backtrace
25----------------------------
26
John DeNisco2ba9dcf2018-08-23 14:04:22 -040027If you encounter errors when running VPP, such as VPP terminating due to a segfault
John DeNiscoce96dda2018-08-14 16:04:09 -040028or abort signal, then you can run the VPP debug binary and then execute **backtrace** or **bt**.
andrewa38d0012018-08-06 00:25:33 -040029
30.. code-block:: console
31
32 (gdb) bt
33 #0 ip4_icmp_input (vm=0x7ffff7b89a40 <vlib_global_main>, node=0x7fffb6bb6900, frame=0x7fffb6725ac0) at /scratch/vpp-master/build-data/../src/vnet/ip/icmp4.c:187
34 #1 0x00007ffff78da4be in dispatch_node (vm=0x7ffff7b89a40 <vlib_global_main>, node=0x7fffb6bb 6900, type=VLIB_NODE_TYPE_INTERNAL, dispatch_state=VLIB_NODE_STATE_POLLING, frame=0x7fffb6725ac0, last_time_stamp=10581236529 65565) at /scratch/vpp-master/build-data/../src/vlib/main.c:988
Paul Vinciguerra7fa3dd22019-10-27 17:28:10 -040035 #2 0x00007ffff78daa77 in dispatch_pending_node (vm=0x7ffff7b89a40 <vlib_global_main>, pending_frame_index=6, last_time_stamp=1058123652965565) at /scratch/vpp-master/build-data/../src/vlib/main.c:1138
andrewa38d0012018-08-06 00:25:33 -040036 ....
37
38Get to the GDB prompt
39---------------------------------------
40
John DeNisco2ba9dcf2018-08-23 14:04:22 -040041When VPP is running, you can get to the command prompt by pressing **CTRL+C**.
andrewa38d0012018-08-06 00:25:33 -040042
43Breakpoints
44---------------------------------------
45
John DeNisco2ba9dcf2018-08-23 14:04:22 -040046When at the GDB prompt, set a breakpoint by running the commands below:
andrewa38d0012018-08-06 00:25:33 -040047
48.. code-block:: console
49
50 (gdb) break ip4_icmp_input
51 Breakpoint 4 at 0x7ffff6b9c00b: file /scratch/vpp-master/build-data/../src/vnet/ip/icmp4.c, line 142.
52
53List the breakpoints already set:
54
55.. code-block:: console
56
57 (gdb) i b
58 Num Type Disp Enb Address What
59 1 breakpoint keep y 0x00007ffff6b9c00b in ip4_icmp_input at /scratch/vpp-master/build-data/../src/vnet/ip/icmp4.c:142
60 breakpoint already hit 3 times
61 2 breakpoint keep y 0x00007ffff6b9c00b in ip4_icmp_input at /scratch/vpp-master/build-data/../src/vnet/ip/icmp4.c:142
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020062 3 breakpoint keep y 0x00007ffff640f646 in tw_timer_expire_timers_internal_1t_3w_1024sl_ov
andrewa38d0012018-08-06 00:25:33 -040063 at /scratch/vpp-master/build-data/../src/vppinfra/tw_timer_template.c:775
64
65Delete a breakpoint:
66
67.. code-block:: console
68
69 (gdb) del 2
70 (gdb) i b
71 Num Type Disp Enb Address What
72 1 breakpoint keep y 0x00007ffff6b9c00b in ip4_icmp_input at /scratch/vpp-master/build-data/../src/vnet/ip/icmp4.c:142
73 breakpoint already hit 3 times
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020074 3 breakpoint keep y 0x00007ffff640f646 in tw_timer_expire_timers_internal_1t_3w_1024sl_ov
andrewa38d0012018-08-06 00:25:33 -040075 at /scratch/vpp-master/build-data/../src/vppinfra/tw_timer_template.c:775
76
77Step/Next/List
78---------------------------------------
79
80Step through the code using (s)tep into, (n)ext, and list some lines before and after where you are with list.
81
82.. code-block:: console
83
84 Thread 1 "vpp_main" hit Breakpoint 1, ip4_icmp_input (vm=0x7ffff7b89a40 <vlib_global_main>, node=0x7fffb6bb6900, frame=0x7fffb6709480)
85 at /scratch/jdenisco/vpp-master/build-data/../src/vnet/ip/icmp4.c:142
86 142 {
87 (gdb) n
88 143 icmp4_main_t *im = &icmp4_main;
89 (
90 (gdb) list
91 202 vlib_put_next_frame (vm, node, next, n_left_to_next);
92 203 }
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020093 204
andrewa38d0012018-08-06 00:25:33 -040094 205 return frame->n_vectors;
95 206 }
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020096 207
andrewa38d0012018-08-06 00:25:33 -040097 208 /* *INDENT-OFF* */
98 209 VLIB_REGISTER_NODE (ip4_icmp_input_node,static) = {
99 210 .function = ip4_icmp_input,
100 211 .name = "ip4-icmp-input",
101
102Examining Data and packets
103-----------------------------------------------
104
105To look at data and packets use e(x)amine or (p)rint.
106
107
108For example in this code look at the ip packet:
109
110.. code-block:: console
111
112 (gdb) p/x *ip0
113 $3 = {{ip_version_and_header_length = 0x45, tos = 0x0, length = 0x5400,
114 fragment_id = 0x7049, flags_and_fragment_offset = 0x40, ttl = 0x40, protocol = 0x1,
115 checksum = 0x2ddd, {{src_address = {data = {0xa, 0x0, 0x0, 0x2},
116 data_u32 = 0x200000a, as_u8 = {0xa, 0x0, 0x0, 0x2}, as_u16 = {0xa, 0x200},
117 as_u32 = 0x200000a}, dst_address = {data = {0xa, 0x0, 0x0, 0xa}, data_u32 = 0xa00000a,
118 as_u8 = {0xa, 0x0, 0x0, 0xa}, as_u16 = {0xa, 0xa00}, as_u32 = 0xa00000a}},
119 address_pair = {src = {data = {0xa, 0x0, 0x0, 0x2}, data_u32 = 0x200000a,
120 as_u8 = {0xa, 0x0, 0x0, 0x2}, as_u16 = {0xa, 0x200}, as_u32 = 0x200000a},
121 dst = {data = {0xa, 0x0, 0x0, 0xa}, data_u32 = 0xa00000a, as_u8 = {0xa, 0x0, 0x0, 0xa},
122 as_u16 = {0xa, 0xa00}, as_u32 = 0xa00000a}}}}, {checksum_data_64 =
123 {0x40704954000045, 0x200000a2ddd0140}, checksum_data_64_32 = {0xa00000a}},
124 {checksum_data_32 = {0x54000045, 0x407049, 0x2ddd0140, 0x200000a, 0xa00000a}}}
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200125
andrewa38d0012018-08-06 00:25:33 -0400126Then the icmp header
127
128.. code-block:: console
129
130 (gdb) p/x *icmp0
131 $4 = {type = 0x8, code = 0x0, checksum = 0xf148}
132
133Then look at the actual bytes:
134
135.. code-block:: console
136
137 (gdb) x/50w ip0
138 0x7fde9953510e: 0x54000045 0x00407049 0x2ddd0140 0x0200000a
139 0x7fde9953511e: 0x0a00000a 0xf1480008 0x03000554 0x5b6b2e8a
140 0x7fde9953512e: 0x00000000 0x000ca99a 0x00000000 0x13121110
141 0x7fde9953513e: 0x17161514 0x1b1a1918 0x1f1e1d1c 0x23222120