gdb正在跳过线路 [英] gdb is jumping over lines
问题描述
我在理解gdb时遇到了一些问题。
我有一个主要功能,我自己写了这个主要功能。
在这个main中的一些行,调用库中的一些函数,我认为库名不重要,但它是tesseract-ocr。
我的行主要调用一个函数,构造函数在这里:
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_ =新的BLOB_CHOICE_IT(blob_choices_it.data());
choice_it _-> mark_cycle_pt();
} else {
choice_it_ = NULL;
$ / code>
然后我使用gdb的next
这里是我的gdb控制台:
断点1 ,pixsOfOneWord(langString = 0x8049e7cklm,
imageString = 0x8049e71paket2.tif,outputData = 0x8049c7b,
datapathString = 0x8049e6f。)at deneme234.cpp:161
161 choiceItr = new tesseract :: ChoiceIterator(itr);
(gdb)步骤
tesseract :: ChoiceIterator :: ChoiceIterator(this = 0x819e6f0,result_it = ...)
在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返回它_-> word() - > box_word-> BlobPosition(blob_index_)== SP_DROPCAP;
221返回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} //命名空间tesseract。
(gdb)next
226 tesseract_ = result_it.tesseract_;
(gdb)next
278} //命名空间tesseract。
(gdb)next
226 tesseract_ = result_it.tesseract_;
(gdb)next
230 if(choices!= NULL){
(gdb)
,您可以看到,
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();
当我下一个,上面的行没有被调用时,为什么?
感谢您的宝贵意见。
调试符号(很可能是 -g -O2
,这是Linux版本的默认设置)。
调试优化代码有点难,因为控制流优化会导致代码跳来跳去,一些变量会变成<优化出>
等。
您可以使用 CXXFLAGS = -g -O0
重建库,或者您可以学习使用优化进行调试。
后者是一种非常有用的技巧,因为很多时候你的程序只会在优化模式下崩溃,你必须在该模式下调试它。 / p>
i have some problems on understanding gdb.
i have a main function, i wrote this main function on myself.
Some lines in this main, call some functions in a library, i think library name is not important but it is tesseract-ocr.
my line in main which call a function, a constructor is here:
choiceItr = new tesseract::ChoiceIterator(itr);
i put a break point at gdb on above line, and run, when it stops on that line i use step command to go into the function.
Here is the library function who is called:
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;
}
}
then i use "next" command of gdb to walk in function.
here is my gdb console:
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)
as you can see,
tesseract_ = result_it.tesseract_;
line has been called two times, why?
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();
also when i "next", above lines was not called, why?
Thanks in advnce.
The library you are stepping into has been built with optimization and debug symbols (most likely -g -O2
, which is the default for Linux builds).
Debugging optimized code is somewhat hard, as control flow optimization causes the code to "jump around", some variables become "<optimized out>
", etc.
You can rebuild the library with CXXFLAGS = -g -O0
, or you can learn to debug with optimization on.
The latter is a very useful skill, as many times your program will only crash in optimized mode, and you'll have to debug it in that mode anyway.
这篇关于gdb正在跳过线路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!