這是我想要調試的代碼片段: 當我嘗試使用GDB進行調試時,在循環結束後for i = 0
,它不會跳轉到循環for i = 1
內的第一行。相反,它會跳到另一條線上,然後跳到第一條線。我無法弄清楚爲什麼以及如何解決它。請給我你的投入。gdb控制跳轉到隨機位置
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
看起來像你有未定義的行爲某處 –
對於(j = 0; j
666線?當然,你的問題是魔鬼的工作,然後;) – codeling