This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
我在调试2838x_cm_cia402_solution这个例程时,发现循环体都是进入两次之后增量才加1,请问这是为什么呢?和CM4内核或者编译优化选项有关吗?
说明如下:
在CiA402_Init函数中,有如下PDO初始化语句,
for (j = 0; j < LocalAxes[AxisCnt].Objects.sRxPDOMap0.u16SubIndex0; j++)
{
LocalAxes[AxisCnt].Objects.sRxPDOMap0.aEntries[j] += AxisCnt* (ObjectOffset << 16);
}
这个PDO的Subindex0是5,也就是LocalAxes[AxisCnt].Objects.sRxPDOMap0.u16SubIndex0值为5。
因此按说应该是执行5次for循环中的语句后结束循环
但是调试时发现,j是每执行2次for循环中的语句,才会加1,所以是执行了10次单步操作,才结束了循环,而不是5次。
你好,很奇怪的是这个应该就是一个for循环,跟Subindex0本身应该也没什么关系。
有单步调试的时候看过j的值是如何增加的吗?再或者,Subindex0的值有没有变化?
您好 我录制了以上视频 是单步执行的 虽然for循环的判断条件也就是subindex0是5(因为1600对象里有5个entry)但是可以看到for循环的循环体是执行了10次单步操作后退出for循环的
我看了后续的代码 也是同样的现象 如果subindex0是3 循环体会被单步执行6次
这是E2E的回复:
When optimization is enabled, compiler may change the order of instructions, hence single stepping may not seem sequential. I would recommend you disable the optimization level or use opt_level=0 if you want a smooth debug experience. If you want to debug with O2, you may look at the Disassembly code.
似乎优化会对代码执行有影响