【发布时间】:2019-06-26 10:19:24
【问题描述】:
我对 gdb 的理解有些问题。
我有一个main函数,这个main函数是我自己写的。
main 中的一些行,调用库中的一些函数,我认为库名并不重要,但它是 tesseract-ocr。
我在 main 中调用函数的行,构造函数在这里:
choiceItr = new tesseract::ChoiceIterator(itr);
我在上面一行的 gdb 处放了一个断点,然后运行,当它在那一行停止时,我使用 step 命令进入函数。
这是被调用的库函数:
ChoiceIterator::ChoiceIterator(const ResultIterator& result_it) {
ASSERT_HOST(result_it.it_->word() != NULL);
tesseract_ = result_it.tesseract_;
PAGE_RES_IT res_it(*result_it.it_);
WERD_CHOICE* best_choice = res_it.word()->best_choice;
BLOB_CHOICE_LIST_CLIST* choices = best_choice->blob_choices();
if (choices != NULL) {
BLOB_CHOICE_LIST_C_IT blob_choices_it(choices);
for (int blob = 0; blob < result_it.blob_index_; ++blob)
blob_choices_it.forward();
choice_it_ = new BLOB_CHOICE_IT(blob_choices_it.data());
choice_it_->mark_cycle_pt();
} else {
choice_it_ = NULL;
}
}
然后我使用 gdb 的“next”命令进入函数。
这是我的 gdb 控制台:
Breakpoint 1, pixsOfOneWord (langString=0x8049e7c "klm",
imageString=0x8049e71 "paket2.tif", outputData=0x8049c7b,
datapathString=0x8049e6f ".") at deneme234.cpp:161
161 choiceItr = new tesseract::ChoiceIterator(itr);
(gdb) step
tesseract::ChoiceIterator::ChoiceIterator (this=0x819e6f0, result_it=...)
at resultiterator.cpp:234
234 choice_it_ = new BLOB_CHOICE_IT(blob_choices_it.data());
(gdb) next
225 ASSERT_HOST(result_it.it_->word() != NULL);
(gdb) list
220 return it_->word()->box_word->BlobPosition(blob_index_) == SP_DROPCAP;
221 return false;
222 }
223
224 ChoiceIterator::ChoiceIterator(const ResultIterator& result_it) {
225 ASSERT_HOST(result_it.it_->word() != NULL);
226 tesseract_ = result_it.tesseract_;
227 PAGE_RES_IT res_it(*result_it.it_);
228 WERD_CHOICE* best_choice = res_it.word()->best_choice;
229 BLOB_CHOICE_LIST_CLIST* choices = best_choice->blob_choices();
(gdb) next
278 } // namespace tesseract.
(gdb) next
226 tesseract_ = result_it.tesseract_;
(gdb) next
278 } // namespace tesseract.
(gdb) next
226 tesseract_ = result_it.tesseract_;
(gdb) next
230 if (choices != NULL) {
(gdb)
如你所见,
tesseract_ = result_it.tesseract_;
line 被调用了两次,为什么?
PAGE_RES_IT res_it(*result_it.it_);
WERD_CHOICE* best_choice = res_it.word()->best_choice;
BLOB_CHOICE_LIST_CLIST* choices = best_choice->blob_choices();
当我“下一个”时,上面的行也没有被调用,为什么?
谢谢。
【问题讨论】:
-
您是否在编译时使用调试选项而不进行优化?
-
@VJo,感谢您的回复,我必须承认我没有编译库的(tesseract)源代码,我使用的是预编译包。当我看到我可以进入 tesseract 函数时,我认为编译没问题。我正在编译我自己的源代码,其中包含只有“-g”的 main。我将搜索编译 main 而不进行优化。但是你能说,我应该在没有优化和调试选项的情况下编译 tesseract 吗?如果是这样,使用哪些调试选项,您的意思是“-g”吗?提前致谢
-
如果您使用的是 g++,则传递
-g -O0以获得带有调试符号的未优化代码