gdb is jumping over lines
gdb is jumping over lines
我对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_;
行被调用了两次,为什么?
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();
还当我"next"时,上面的行没有被调用,为什么?
您将要进入的库已经使用优化和调试符号构建(最有可能的是-g -O2
,这是Linux构建的默认值)。
调试优化后的代码有些困难,因为控制流优化导致代码"跳来跳去",一些变量变成了"<optimized out>
"等等。
你可以用CXXFLAGS = -g -O0
来重建这个库,或者你可以学习用优化来调试。
后一个是非常有用的技能,因为很多时候你的程序在优化模式下只会崩溃,无论如何你都必须在那个模式下调试它。
相关文章:
- clang C++17 std::vector over align type 使用 -mavx 编译时元素 SIGSE
- Array.at(index) over Array[index]
- C++ Iterating Over va_list
- 在 [over.ass]/2 的例子中,为什么 *bptr = dobj2;调用 D::operator=(const B&)?
- [over.unary]/2 中注释中提到的隐藏的编译示例
- WebRTC 'goog-remb' 和 'transport-cc' SDP lines
- 我们在哪里可以使用std::barrier over std::latch
- dynamic_cast over共享库在使用clang编译的Android上的Qt中失败
- 为什么选择 (;;){} over while(1).
- HBITMAP/BITMAP to BITMAPINFOHEADER -> over network - > BITMAPINFOHEADER to HBITMAP/BITMAP
- HTTP over TCP/IP?
- getenv( "LINES" ) 在 Windows 上不起作用
- OpenGL 2d HUD over 3d不会渲染任何内容
- std::max_element skip over NANs
- advantage of QString over std::string
- 在基于 Eclipse 的 IDE 中调试C++ - 是否有类似 "step over loop/cycle" 的东西?
- iterating over c++ map<int, list<int>>
- vector push_back over std::copy
- H.264 over RTP-识别SPS和PPS帧
- gdb is jumping over lines