本文内容来源于国外程序员Denys Haryachyy 个人博客,下面是基于vpp 主线master分支在Ubuntu22.04环境进行测试验证。学习如何构建DPDK的debug版本,并且能够在DPDK源代码中进行单步调试。
主要是修改了两个文件,如下:
#修改ububtu deb包编译规则,增加不去除符号文件和调试信息(strip 操作)
build/external/deb/debian/rules
#dpdk make文件打开debug开关
build/external/packages/dpdk.mk
下面是修改后的patch文件内容:
diff --git a/build/external/deb/debian/rules b/build/external/deb/debian/rules
index 901d46897..b2a079bcd 100755
--- a/build/external/deb/debian/rules
+++ b/build/external/deb/debian/rules
@@ -31,3 +31,5 @@ override_dh_install:
override_dh_shlibdeps:
dh_shlibdeps -l$(INSTALL_DIR)lib/
+override_dh_strip:
+ dh_strip --exclude=librte
diff --git a/build/external/packages/dpdk.mk b/build/external/packages/dpdk.mk
index 04a069bb1..302522631 100644
--- a/build/external/packages/dpdk.mk
+++ b/build/external/packages/dpdk.mk
@@ -13,7 +13,7 @@
DPDK_PKTMBUF_HEADROOM ?= 128
DPDK_USE_LIBBSD ?= n
-DPDK_DEBUG ?= n
+DPDK_DEBUG ?= y
DPDK_TAP_PMD ?= n
DPDK_FAILSAFE_PMD ?= n
DPDK_MACHINE ?= default
重新编译vpp并运行启动vpp进程。进入GDB界面下面来调试一下dpdk收包模块的流程,由于我当前环境中show hardware无法查询到网卡收发包函数的具体名称,需要通过直接打印rte_eth_devices网卡设备来查询收发包函数。
#因为当前环境show hardware未查询到rx tx函数名称。
(gdb) p rte_eth_devices[0]
$1 = {rx_pkt_burst = 0x7f26bbead580 <eth_em_recv_scattered_pkts>,
tx_pkt_burst = 0x7f26bbeae050 <eth_em_xmit_pkts>, tx_pkt_prepare = 0x7f26bbeaf440 <eth_em_prep_pkts>,
rx_queue_count = 0x7f26bbeafde0 <eth_em_rx_queue_count>,
rx_descriptor_status = 0x7f26bbeafe50 <eth_em_rx_descriptor_status>,
tx_descriptor_status = 0x7f26bbeafea0 <eth_em_tx_descriptor_status>, data = 0xac03a8d40,
process_private = 0x0, dev_ops = 0x7f26bc93ab80 <eth_em_ops>, device = 0x5571f465ead0,
intr_handle = 0x5571f4619840, link_intr_cbs = {tqh_first = 0x0,
tqh_last = 0x7f26bcc55ad8 <rte_eth_devices+88>}, post_rx_burst_cbs = {0x0 <repeats 1024 times>},
pre_tx_burst_cbs = {0x0 <repeats 1024 times>}, state = RTE_ETH_DEV_ATTACHED, security_ctx = 0x0}
通过gdb list 函数名来查询函数所在的文件,下面提示查询不到函数对应的文件
(gdb) list eth_em_recv_scattered_pkts
849 ../src-dpdk/drivers/net/e1000/em_rxtx.c: No such file or directory.
接下来我们通过set substitute-path来修改搜索源码文件的路径,再次list 函数查询可以显示函数内容。
(gdb) set substitute-path '../src-dpdk/' '/home/jinsh/workspace/vpp-master/build/external/downloads/dpdk-23.03'
(gdb) list eth_em_recv_scattered_pkts
849 }
850
851 uint16_t
852 eth_em_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
853 uint16_t nb_pkts)
854 {
855 struct em_rx_queue *rxq;
856 volatile struct e1000_rx_desc *rx_ring;
857 volatile struct e1000_rx_desc *rxdp;
858 struct em_rx_entry *sw_ring;
substitute-path的详细用法可以在下面链接学习 https://www.irya.unam.mx/computo/sites/manuales/fce12/debugger/cl/commandref/gdb_mode/cmd_set_substitu.ht
设置函数断点eth_em_recv_scattered_pkts,并运行程序。程序会中断在网卡收包函数中,之后可以进行单步调试代码。
#设置断点函数到dpdk收包函数
(gdb) b eth_em_recv_scattered_pkts
Breakpoint 1 at 0x7f26bbead580: file ../src-dpdk/drivers/net/e1000/em_rxtx.c, line 854.
(gdb) c #运行程序
Continuing.
#gdb 停留在断点位置
Thread 1 "vpp_main" hit Breakpoint 1, eth_em_recv_scattered_pkts (rx_queue=0xac02777c0, rx_pkts=0x7f26c211b900, nb_pkts=32) at ../src-dpdk/drivers/net/e1000/em_rxtx.c:854
854 {
(gdb) list #显示源代码程序
849 }
850
851 uint16_t
852 eth_em_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
853 uint16_t nb_pkts)
854 {
855 struct em_rx_queue *rxq;
856 volatile struct e1000_rx_desc *rx_ring;
857 volatile struct e1000_rx_desc *rxdp;
858 struct em_rx_entry *sw_ring;
(gdb) next 继续运行程序
877 rx_ring = rxq->rx_ring;
(gdb) n
878 sw_ring = rxq->sw_ring;
本文分享自 DPDK VPP源码分析 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!