首页 > gdb调试c++时,遇到endl就无法继续调试

gdb调试c++时,遇到endl就无法继续调试

使用gcc编译时候,编译选项如下:

g++ -std=c++11 -g -o cpp730 cpp730.cpp

程序可以正常运行,但是使用gdb.exe调试的时候,遇到endl,就无法继续调试,每次都卡在这个语句.

用来试验的代码比较简单

#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main(){
    string temp("abcdefg");
    
    cout << temp << endl;
    
    for (auto &a : temp)
        a = toupper(a);
    
    cout << temp << endl;
    
    return 0;
}

g++和gdb都是最新的版本,然后gdb用来调试C语言程序没有出现问题.


更新: 不好意思,弄错了。64位能正确单步跟踪 std::cout << std::endl 的,必须是 Mingw-w64 那套编译器。

补充 : 你是不是在用 Tdm-mingw x86-64 (64位版本)的最新本版本(tdm64-gcc-5.1.0-2.exe)的编译环境?
我今天测试了,tdm64-gcc-5.1.0-2.exe 版本有此问题!(调试到 << endl 就卡)
请退回前一版本: tdm64-gcc-5.1.0.exe
(下载页面 https://sourceforge.net/proje... )
一切OK了。
我明天有空的话,我向作者提交这个问题。

---------------(以下分析没错,但不是此问题根本原因)---------
1、endl 其实是一个函数的地址;
2、然后看你好像是在endl语句上,执行了 “s” 指令,也就是单步进入(函数)
3、由于endl是C++标准库的内容,没有对应的源代码。
你试试在那一行上用 n 吧。

【热门文章】
【热门文章】