https://blog.csdn.net/weixin_43092232/article/details/106243657
https://blog.csdn.net/www_dong/article/details/117374370
代码验证:
龙芯3A5000验证
$ cat test.c #include<stdio.h> int add ( int d1, int d2 ) { int d; d = d1 + 1; d = d + d2 + 2; return d; } int add1 ( int d1, int d2 ) { int d; d = d1 + 10; d = d + d2 + 20; return d; } int main() { int a = 0, b = 0; a = b + 1; a = add(a, b); a = a + 10; b = add1(a, b); b = a + b; return 1; } 桌面20.3系统 lihui@lihui-pc:~/community/build$ gcc -v gcc version 8.3.0 (Loongnix 8.3.0-6.lnd.vec.33) lihui@lihui-pc:~/community/build$ gdb/gdb -v GNU gdb (GDB) 14.0.50.20230705-git lihui@lihui-pc:~/community/build$ gcc -g test.c -o test lihui@lihui-pc:~/community/build$ objdump -d test 00000001200006d0 <add>: 1200006d0: 02ff4063 addi.d $r3,$r3,-48(0xfd0) 1200006d4: 29c0a076 st.d $r22,$r3,40(0x28) 1200006d8: 02c0c076 addi.d $r22,$r3,48(0x30) 1200006dc: 0015008d move $r13,$r4 1200006e0: 001500ac move $r12,$r5 1200006e4: 004081ad slli.w $r13,$r13,0x0 1200006e8: 29bf72cd st.w $r13,$r22,-36(0xfdc) 1200006ec: 0040818c slli.w $r12,$r12,0x0 1200006f0: 29bf62cc st.w $r12,$r22,-40(0xfd8) 1200006f4: 28bf72cc ld.w $r12,$r22,-36(0xfdc) 1200006f8: 0280058c addi.w $r12,$r12,1(0x1) 1200006fc: 29bfb2cc st.w $r12,$r22,-20(0xfec) 120000700: 28bfb2cd ld.w $r13,$r22,-20(0xfec) 120000704: 28bf62cc ld.w $r12,$r22,-40(0xfd8) 120000708: 001031ac add.w $r12,$r13,$r12 12000070c: 0280098c addi.w $r12,$r12,2(0x2) 120000710: 29bfb2cc st.w $r12,$r22,-20(0xfec) 120000714: 28bfb2cc ld.w $r12,$r22,-20(0xfec) 120000718: 00150184 move $r4,$r12 12000071c: 28c0a076 ld.d $r22,$r3,40(0x28) 120000720: 02c0c063 addi.d $r3,$r3,48(0x30) 120000724: 4c000020 jirl $r0,$r1,0 0000000120000728 <add1>: 120000728: 02ff4063 addi.d $r3,$r3,-48(0xfd0) 12000072c: 29c0a076 st.d $r22,$r3,40(0x28) 120000730: 02c0c076 addi.d $r22,$r3,48(0x30) 120000734: 0015008d move $r13,$r4 120000738: 001500ac move $r12,$r5 12000073c: 004081ad slli.w $r13,$r13,0x0 120000740: 29bf72cd st.w $r13,$r22,-36(0xfdc) 120000744: 0040818c slli.w $r12,$r12,0x0 120000748: 29bf62cc st.w $r12,$r22,-40(0xfd8) 12000074c: 28bf72cc ld.w $r12,$r22,-36(0xfdc) 120000750: 0280298c addi.w $r12,$r12,10(0xa) 120000754: 29bfb2cc st.w $r12,$r22,-20(0xfec) 120000758: 28bfb2cd ld.w $r13,$r22,-20(0xfec) 12000075c: 28bf62cc ld.w $r12,$r22,-40(0xfd8) 120000760: 001031ac add.w $r12,$r13,$r12 120000764: 0280518c addi.w $r12,$r12,20(0x14) 120000768: 29bfb2cc st.w $r12,$r22,-20(0xfec) 12000076c: 28bfb2cc ld.w $r12,$r22,-20(0xfec) 120000770: 00150184 move $r4,$r12 120000774: 28c0a076 ld.d $r22,$r3,40(0x28) 120000778: 02c0c063 addi.d $r3,$r3,48(0x30) 12000077c: 4c000020 jirl $r0,$r1,0 0000000120000780 <main>: 120000780: 02ff8063 addi.d $r3,$r3,-32(0xfe0) 120000784: 29c06061 st.d $r1,$r3,24(0x18) 120000788: 29c04076 st.d $r22,$r3,16(0x10) 12000078c: 02c08076 addi.d $r22,$r3,32(0x20) 120000790: 29bfb2c0 st.w $r0,$r22,-20(0xfec) 120000794: 29bfa2c0 st.w $r0,$r22,-24(0xfe8) 120000798: 28bfa2cc ld.w $r12,$r22,-24(0xfe8) 12000079c: 0280058c addi.w $r12,$r12,1(0x1) 1200007a0: 29bfb2cc st.w $r12,$r22,-20(0xfec) 1200007a4: 28bfa2cd ld.w $r13,$r22,-24(0xfe8) 1200007a8: 28bfb2cc ld.w $r12,$r22,-20(0xfec) 1200007ac: 001501a5 move $r5,$r13 1200007b0: 00150184 move $r4,$r12 1200007b4: 57ff1fff bl -228(0xfffff1c) # 1200006d0 <add> 1200007b8: 0015008c move $r12,$r4 1200007bc: 29bfb2cc st.w $r12,$r22,-20(0xfec) 1200007c0: 28bfb2cc ld.w $r12,$r22,-20(0xfec) 1200007c4: 0280298c addi.w $r12,$r12,10(0xa) 1200007c8: 29bfb2cc st.w $r12,$r22,-20(0xfec) 1200007cc: 28bfa2cd ld.w $r13,$r22,-24(0xfe8) 1200007d0: 28bfb2cc ld.w $r12,$r22,-20(0xfec) 1200007d4: 001501a5 move $r5,$r13 1200007d8: 00150184 move $r4,$r12 1200007dc: 57ff4fff bl -180(0xfffff4c) # 120000728 <add1> 1200007e0: 0015008c move $r12,$r4 1200007e4: 29bfa2cc st.w $r12,$r22,-24(0xfe8) 1200007e8: 28bfa2cd ld.w $r13,$r22,-24(0xfe8) 1200007ec: 28bfb2cc ld.w $r12,$r22,-20(0xfec) 1200007f0: 001031ac add.w $r12,$r13,$r12 1200007f4: 29bfa2cc st.w $r12,$r22,-24(0xfe8) 1200007f8: 0280040c addi.w $r12,$r0,1(0x1) 1200007fc: 00150184 move $r4,$r12 120000800: 28c06061 ld.d $r1,$r3,24(0x18) 120000804: 28c04076 ld.d $r22,$r3,16(0x10) 120000808: 02c08063 addi.d $r3,$r3,32(0x20) 12000080c: 4c000020 jirl $r0,$r1,0 验证next lihui@lihui-pc:~/community/build$ gdb/gdb test ... (gdb) start Temporary breakpoint 1 at 0x120000790: file test.c, line 20. Starting program: /home/lihui/community/build/test Temporary breakpoint 1, main () at test.c:20 20 int a = 0, b = 0; (gdb) l 15 return d; 16 } 17 18 int main() 19 { 20 int a = 0, b = 0; 21 a = b + 1; 22 a = add(a, b); 23 a = a + 10; 24 b = add1(a, b); (gdb) next 21 a = b + 1; (gdb) next 22 a = add(a, b); (gdb) next 23 a = a + 10; (gdb) next 24 b = add1(a, b); (gdb) next 25 b = a + b; (gdb) next 26 return 1; (gdb) next 27 } ... 验证step lihui@lihui-pc:~/community/build$ gdb/gdb test ... (gdb) start .. Temporary breakpoint 1, main () at test.c:20 20 int a = 0, b = 0; (gdb) step 21 a = b + 1; (gdb) step 22 a = add(a, b); (gdb) step add (d1=1, d2=0) at test.c:5 5 d = d1 + 1; (gdb) step 6 d = d + d2 + 2; (gdb) step 7 return d; (gdb) step 8 } (gdb) step main () at test.c:23 23 a = a + 10; (gdb) step 24 b = add1(a, b); (gdb) step add1 (d1=14, d2=0) at test.c:13 13 d = d1 + 10; (gdb) step 14 d = d + d2 + 20; (gdb) step 15 return d; (gdb) step 16 } (gdb) step main () at test.c:25 25 b = a + b; (gdb) step 26 return 1; (gdb) step 27 } 可以看到next命令遇到函数不进入,step遇到函数进入,符合预期。 验证nexti lihui@lihui-pc:~/community/build$ gdb/gdb test ... (gdb) start Temporary breakpoint 1 at 0x120000790: file test.c, line 20. Starting program: /home/lihui/community/build/test Temporary breakpoint 1, main () at test.c:20 20 int a = 0, b = 0; (gdb) nexti 20 int a = 0, b = 0; (gdb) nexti 21 a = b + 1; (gdb) nexti 0x000000012000079c 21 a = b + 1; (gdb) nexti 0x00000001200007a0 21 a = b + 1; (gdb) nexti 22 a = add(a, b); (gdb) nexti 0x00000001200007a8 22 a = add(a, b); (gdb) nexti 0x00000001200007ac 22 a = add(a, b); (gdb) nexti 0x00000001200007b0 22 a = add(a, b); (gdb) nexti 0x00000001200007b4 22 a = add(a, b); (gdb) nexti 0x00000001200007b8 22 a = add(a, b); (gdb) nexti 0x00000001200007bc 22 a = add(a, b); (gdb) nexti 23 a = a + 10; (gdb) nexti 0x00000001200007c4 23 a = a + 10; (gdb) nexti 0x00000001200007c8 23 a = a + 10; (gdb) nexti 24 b = add1(a, b); (gdb) nexti 0x00000001200007d0 24 b = add1(a, b); (gdb) nexti 0x00000001200007d4 24 b = add1(a, b); (gdb) nexti 0x00000001200007d8 24 b = add1(a, b); (gdb) nexti 0x00000001200007dc 24 b = add1(a, b); (gdb) nexti 0x00000001200007e0 24 b = add1(a, b); (gdb) nexti 0x00000001200007e4 24 b = add1(a, b); (gdb) nexti 25 b = a + b; (gdb) nexti 0x00000001200007ec 25 b = a + b; (gdb) nexti 0x00000001200007f0 25 b = a + b; (gdb) nexti 0x00000001200007f4 25 b = a + b; (gdb) nexti 26 return 1; (gdb) nexti 27 } nexti是逐条指令执行,但是没有进入到add和add1函数,跳过了这两个函数继续执行下面的指令。 验证stepi lihui@lihui-pc:~/community/build$ gdb/gdb test ... (gdb) start Temporary breakpoint 1 at 0x120000790: file test.c, line 20. Starting program: /home/lihui/community/build/test Temporary breakpoint 1, main () at test.c:20 20 int a = 0, b = 0; (gdb) next 21 a = b + 1; (gdb) next 22 a = add(a, b); (gdb) stepi 0x00000001200007a8 22 a = add(a, b); (gdb) stepi 0x00000001200007ac 22 a = add(a, b); (gdb) stepi 0x00000001200007b0 22 a = add(a, b); (gdb) stepi 0x00000001200007b4 22 a = add(a, b); (gdb) stepi add (d1=0, d2=0) at test.c:3 3 { (gdb) stepi 0x00000001200006d4 3 { (gdb) stepi 0x00000001200006d8 3 { (gdb) stepi 0x00000001200006dc 3 { (gdb) stepi 0x00000001200006e0 3 { (gdb) stepi 0x00000001200006e4 3 { (gdb) stepi 0x00000001200006e8 3 { (gdb) stepi 0x00000001200006ec 3 { (gdb) stepi 0x00000001200006f0 3 { (gdb) stepi 5 d = d1 + 1; (gdb) stepi 0x00000001200006f8 5 d = d1 + 1; (gdb) stepi 0x00000001200006fc 5 d = d1 + 1; (gdb) stepi 6 d = d + d2 + 2; (gdb) stepi 0x0000000120000704 6 d = d + d2 + 2; (gdb) stepi 0x0000000120000708 6 d = d + d2 + 2; (gdb) stepi 6 d = d + d2 + 2; (gdb) stepi 0x0000000120000710 6 d = d + d2 + 2; (gdb) stepi 7 return d; (gdb) stepi 8 } (gdb) next main () at test.c:23 23 a = a + 10; (gdb) next 24 b = add1(a, b); (gdb) stepi 0x00000001200007d0 24 b = add1(a, b); (gdb) stepi 0x00000001200007d4 24 b = add1(a, b); (gdb) stepi 0x00000001200007d8 24 b = add1(a, b); (gdb) stepi 0x00000001200007dc 24 b = add1(a, b); (gdb) stepi add1 (d1=1, d2=0) at test.c:11 11 { (gdb) stepi 0x000000012000072c 11 { (gdb) stepi 0x0000000120000730 11 { (gdb) stepi 0x0000000120000734 11 { (gdb) stepi 0x0000000120000738 11 { (gdb) stepi 0x000000012000073c 11 { (gdb) stepi 0x0000000120000740 11 { (gdb) stepi 0x0000000120000744 11 { (gdb) stepi 0x0000000120000748 11 { (gdb) stepi 13 d = d1 + 10; (gdb) stepi 0x0000000120000750 13 d = d1 + 10; (gdb) stepi 0x0000000120000754 13 d = d1 + 10; (gdb) stepi 14 d = d + d2 + 20; (gdb) stepi 0x000000012000075c 14 d = d + d2 + 20; (gdb) stepi 0x0000000120000760 14 d = d + d2 + 20; (gdb) stepi 14 d = d + d2 + 20; (gdb) stepi 0x0000000120000768 14 d = d + d2 + 20; (gdb) stepi 15 return d; (gdb) stepi 16 } (gdb) next main () at test.c:25 25 b = a + b; (gdb) next 26 return 1; (gdb) next 27 } 可以看到stepi也是逐条指令执行,会进入到函数add和add1内部执行,符合预期
标签:r12,nexti,stepi,next,gdb,20,r22 From: https://www.cnblogs.com/lh03061238/p/17753932.html