asio socket->connect 调用后 GDB 断点停止工作

发布于 2024-10-09 14:06:49 字数 1069 浏览 0 评论 0原文

我在 Windows 上使用 Eclipse + Mingw + Boost。

当调试器在 Eclipse 中到达此代码片段时,我遇到的问题是:

int YarpInterface::connect_to_port(std::string ip, std::string port, tcp::socket* socket)
{    
    boost::asio::io_service io_service;
    tcp::resolver resolver(io_service);
    tcp::resolver::query query(boost::asio::ip::tcp::v4(), ip, port);
    tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
    tcp::resolver::iterator end;
    boost::system::error_code error = boost::asio::error::host_not_found;

    while (error && endpoint_iterator != end)
    {
       socket->close();
       socket->connect(*endpoint_iterator++, error);
    }
    if (error)
    {
       throw boost::system::system_error(error);
    }
    return true;
}

当我开始调试时,gdb 正确地停止在主程序中,我可以安全地单步执行我的代码,直到 socket->connect 调用,在此之后我失去对执行的所有控制,程序将继续执行直到退出。该行之后的所有断点都将被完全忽略。我在 gdb 日志中没有看到有用的错误消息。

我正在使用最新版本的 Mingw、Boost 和 Eclipse。我已经使用相同的编译器编译了我的代码并进行了升压,两者都启用了调试符号。

编辑:我还可以通过 boost 代码安全地单步进入调用,因此我非常确信当 gdb 进入更低级别的系统调用时会出现问题。

I am using Eclipse + Mingw + Boost on Windows.

The problem I have appears when the debugger gets to this code fragment in Eclipse:

int YarpInterface::connect_to_port(std::string ip, std::string port, tcp::socket* socket)
{    
    boost::asio::io_service io_service;
    tcp::resolver resolver(io_service);
    tcp::resolver::query query(boost::asio::ip::tcp::v4(), ip, port);
    tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
    tcp::resolver::iterator end;
    boost::system::error_code error = boost::asio::error::host_not_found;

    while (error && endpoint_iterator != end)
    {
       socket->close();
       socket->connect(*endpoint_iterator++, error);
    }
    if (error)
    {
       throw boost::system::system_error(error);
    }
    return true;
}

When I start debugging, gdb correctly stops inside the main, I can safely single step my code all the way until the socket->connect invocation, after this I loose all control over the execution and the program just continues to execute until it exits. All breakpoints after this line are ignored completely. I see no useful error messages in the gdb logs.

I am using the latest version of Mingw, Boost and Eclipse. I have compiled my code and boost using the same compiler, both with debug symbols enabled.

Edit: I can also step into the call all the way through boost code safely, therefore I am quite convinced that the problem occurs when gdb gets to the more low level system calls.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧情别恋 2024-10-16 14:06:49

这个问题似乎暂时得到了解决。对于其他在 Windows 下的 Eclipse 中使用 gdb 进行调试的可怜人来说,有用的技巧是:

1) 非常小心(观看)表达式。似乎 gdb 试图在每一步中解释这些。如果在这里提供错误的值,您将获得非常不稳定的调试体验。

2) 打印时要小心。就我而言,通过查看 gdb 日志,我注意到 gdb 实际上停止在所需的断点处,但 Eclipse 没有反应。问题是我的 cout 输出以某种方式打印在 gdb 输出中,因为这就是 Eclipse 从 gdb 检索信息的方式,它无法理解断点实际上已命中,并且只是永远等待在那里。

3)尽量不要迈太多步。特别是通过套接字->连接和异常调用。

The issue seems to be resolved for the time being. Useful tips for other poor souls debugging with gdb in Eclipse under Windows:

1) Be VERY careful about (Watch) Expressions. It seems that gdb tries to interpret these on every step. Provide wrong values here and you'll have a very unstable debugging experience.

2) Be careful with your printing. In my case, by looking at the gdb logs, I noticed that gdb does in fact stop at the required breakpoint, but Eclipse does not react. The issue was that my cout output somehow got printed in the gdb output, as this is how Eclipse retrieves information from gdb, it could not understand that the breakpoint was actually hit, and just waited there forever.

3) Try not to do too much stepping. Especially over socket->connect and exception calls.

不弃不离 2024-10-16 14:06:49

2) 打印时要小心。就我而言,通过查看 gdb
日志中,我注意到 gdb 实际上停止在所需的断点处,
但 Eclipse 没有反应。问题是我的 cout 输出不知何故
在 gdb 输出中打印,因为这就是 Eclipse 检索的方式
来自 gdb 的信息,它无法理解断点是
实际上击中了,然后就永远在那里等待。

这对我来说也是个问题 - 将 set new-console on 放入 .gdbinit 为我解决了这个问题。

2) Be careful with your printing. In my case, by looking at the gdb
logs, I noticed that gdb does in fact stop at the required breakpoint,
but Eclipse does not react. The issue was that my cout output somehow
got printed in the gdb output, as this is how Eclipse retrieves
information from gdb, it could not understand that the breakpoint was
actually hit, and just waited there forever.

This was also the issue for me - putting set new-console on into .gdbinit fixed it for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文