Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

c++ - gdb is jumping over lines

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...