这是我要调试的代码片段:当我尝试使用 GDB 进行调试时,循环结束后for i = 0
,它不会跳转到循环内的第一行for i = 1
。相反,它跳到中间的另一行,然后跳到第一行。我无法弄清楚为什么以及如何解决它。请给我你的意见。
for(i = 0; i < fileSum; i++)
{
char *fileName ; //= NULL;
// fileName = GetFileName(dataset->groundTruthFolder, trainImageFiles[i], dataset->groundTruthExtension);
fileName = new char[strlen(dataset->groundTruthFolder) + strlen(trainImageFiles[i]) + strlen(dataset->groundTruthExtension) + 1];
sprintf(fileName, "%s%s%s", dataset->groundTruthFolder, trainImageFiles[i], dataset->groundTruthExtension);
printf("GetFileName: fileName-%s \n", fileName);
LLabelImage groundTruth(fileName, domain);
// delete[] fileName;
// fileName = NULL;
int width = groundTruth.GetWidth(), height = groundTruth.GetHeight();
int subWidth = (width + subSample - 1) / subSample;
int subHeight = (height + subSample - 1) / subSample;
for(k = 0; k < subHeight; k++) for(j = 0; j < subWidth; j++)
{
unsigned char gtVal = groundTruth(j * subSample, k * subSample, 0);
if(gtVal > 0) classCounts[gtVal - 1]++, total++;
printf("k = %d,j = %d, gtVal = %d\n", k, j, gtVal);
}
int dummy = 0;
printf("i = %d\n", i);
}
这是 gdb 控制台的快照:
Breakpoint 2, LDenseUnaryPixelPotential::InitTrainData (this=0x80aad08, trainImageFiles=...) at potential.cpp:665
665 int dummy = 0;
(gdb) n
666 printf("i = %d\n", i);
(gdb) n
i = 1
650 LLabelImage groundTruth(fileName, domain);
(gdb) n
640 for(i = 0; i < fileSum; i++)
(gdb) n
Breakpoint 1, LDenseUnaryPixelPotential::InitTrainData (this=0x80aad08, trainImageFiles=...) at potential.cpp:645
645 fileName = new char[strlen(dataset->groundTruthFolder) + strlen(trainImageFiles[i]) + strlen(dataset->groundTruthExtension) + 1];
(gdb)
请注意,控制是从 666 到 650 再到 640,而不是直接从 666 到 640。
以前,我使用 -g 选项编译,现在我使用-g -O0选项编译。同样的问题仍然存在。
这是我的Makefile:
CC = g++
OBJS = main.o
SOURCES = main.cpp
LIBS = -lIL -pthread
EXE = ale
FLAGS = -g -O0 -Wno-write-strings
$(EXE): .
$(CC) $(FLAGS) -c $(SOURCES) -o $(OBJS)
$(CC) -o $(EXE) $(OBJS) $(LIBS)
clean:
rm -rf *.o ale