首页 > 其他分享 >单步指令区别step next stepi nexti

单步指令区别step next stepi nexti

时间:2023-10-10 10:25:06浏览次数:43  
标签:r12 nexti stepi next gdb 20 r22

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

相关文章

  • Vue 异步更新、$nextTick
    Vue是异步更新DOM的,想要在dom更新完成之后做某件事,可以使用 $nextTick  $nextTick:等dom更新后,才会触发执行此方法里的函数体语法:this.$nextTick( ()=>{   //业务逻辑}) eg:this.$nextTick( ()=>{   this.$refs.inp.focus()})......
  • beforeRouteEnter的执行时机以及其参数next的内部参数vm=>{}的执行实际
    beforeRouteEnter:(to,from,next)=>{console.log(1)next(vm=>{console.log(2)})}这里是先打印1,后打印21的时机是:to页面进入前,to页面的create都没执行2的时机是:to页面已经进入了,并且to页面的beforeMount执行后,mounted函数执行前,才去执行vm=>{},并打印2to.beforeCreate=>......
  • $nextTick函数的用法以及全局事件总线
    全局事件总线的目的是可以实现任意组件之间的通信。这里需要涉及到原型链的知识。在Vue里面,我们知道运行一个完整的项目是由若干个VueComponents组件和一个AppVueComponent组件加上一个Vue的实例对象而vc组件在通过this去获取属性的值时,首先会从vc实例对象里面找,没有的话就去vc......
  • next-key lock
    加锁基本单位next-keylock=gaplock+rowlock范围前开后闭区间加锁规则原则1加锁的基本单位是next-keylock。原则2查找过程中访问到的对象才会加锁。优化1索引上的等值查询,给唯一索引加锁的时候,next-keylock退化为行锁。优化2索引上的等值查......
  • 5 分钟理解 Next.js SSG (Static Site Generation / Static Export)
    5分钟理解Next.jsSSG(StaticSiteGeneration/StaticExport)在本篇文章中,我们将介绍Next.js中的SSG(静态网站生成)功能,以及它是如何工作的。我们将介绍SSG的基本概念,以及在Next.js中如何使用ServerComponents和ClientComponents来实现不同的数据获取策略。什......
  • Abp vNext 依赖注入
    文章目录介绍ABP的依赖注入系统是基于Microsoft的依赖注入扩展库(Microsoft.Extensions.DependencyInjectionnuget包)开发的。所以我们采用dotnet自带的注入方式也是支持的。由于ABP是一个模块化框架,因此每个模块都定义它自己的服务并在它自己的单独模块类中通过依赖注入进行......
  • Abp vNext 模块加载机制
    文章目录生命周期PreConfigureServices添加依赖注入或者其它配置之前ConfigureServices添加依赖注入或者其它配置PostConfigureServices添加依赖注入或者其它配置之后OnPreApplicationInitialization初始化所有模块之前OnApplicationInitialization初始化所有模块On......
  • XSAN数据恢复-存储空间从XSAN迁移到STORNEXT中误格式化系统的数据恢复案例
    XSAN数据恢复环境:昆腾存储,MACOS操作系统,划分了9个数据卷(1个META信息卷,8个DATA信息卷),存放视频类数据,MXF、MOV等格式文件。XSAN故障&分析:将存储空间从XSAN架构迁移到STORNEXT架构,迁移完成后发现存储空间中数据全部丢失。北亚企安数据恢复工程师分析META信息卷,读取其中的元信息,发......
  • Next.js 13.5 正式发布,速度大幅提升!
    9月19日,Next.js13.5正式发布,该版本通过以下方式提高了本地开发性能和可靠性:本地服务器启动速度提高22%:使用App和PagesRouter可以更快地进行迭代HMR(快速刷新)速度提高29%:在保存更改时进行更快的迭代内存使用量减少40%:在运行nextstart时测量优化的包导入:使用......
  • Nextcloud使用OCC命令重置密码
    Nextcloud使用OCC命令重置密码  一般来说,可以使用管理员账户来修改密码如果出现了忘记了管理员密码这种糟糕的情况,就只能通过OCC命令或修改数据库的方式来解决了。本文介绍较为方便的使用OCC命令重置密码方式。OCC命令的用法occ命令是ownCloud/Nextcloud的命令行界面......