gpt4 book ai didi

c++ - gdb 控件跳转到随机位置

转载 作者:行者123 更新时间:2023-11-28 07:57:35 26 4
gpt4 key购买 nike

这是我要调试的代码片段:当我尝试使用 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 选项编译。仍然存在同样的问题。

这是我的生成文件:

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

最佳答案

实际上,我进一步调试发现,当控件到达循环结束时,正在调用“LLabelImage”的析构函数来删除数据。

关于c++ - gdb 控件跳转到随机位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12351303/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com