当使用多个源文件时,GDB不会破坏某些代码行 [英] GDB does not break on some lines of code when using multiple source files

查看:217
本文介绍了当使用多个源文件时,GDB不会破坏某些代码行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,我想通过在非默认构造函数中设置断点来调试,但我设置的断点从未命中。下面是一个例子程序,这个问题出现了。在main函数中设置的断点没有问题,但是在Domain.cpp文件中设置的任何断点都被忽略:

I have a program that I'd like to debug by setting a breakpoint in a non-default constructor, but the breakpoint I set is never hit. Below is an example program where this problem comes up. There is no problem hitting breakpoints set in the main function, but any breakpoints set in the Domain.cpp file are ignored:

Main.cpp:

#include <iostream>
#include "Domain.h"

int main()
{
  Domain y;
  std::cout << y.x << std::endl;  // <- No problem setting breakpoint here
  return 0;
}

Domain.cpp: b
$ b

Domain.cpp:

#include "Domain.h"

Domain::Domain()
{
  x = 4;  // <- A breakpoint here is skipped
}

Domain.h :

#ifndef DOMAIN_H_
#define DOMAIN_H_

class Domain
{
public:
  int x;
public:
  Domain();
};

#endif /* DOMAIN_H_ */

如果我将所有内容放入一个文件:

However, the problem does not exist if I put everything into a single file:

Main2.cpp

#include <iostream>

int main()
{

  class Domain
  {
  public:
    int x;
    Domain()
    {
      x = 4;  // <- No problem setting breakpoint here now!
    };

  };

  Domain y;

  std::cout << y.x << std::endl;

  return 0;
}

为什么会这样?我可以改变这个,这样我可以设置断点,当我使用多个文件?

Why is this the case? How can I change this so that I'm able to set breakpoints when I use multiple files?

我可以确认断点不工作,当我运行调试器在终端中,当我运行它通过Eclipse CDT,其中我得到相同的错误讨论这个问题,显然从来没有回答:

I can confirm that the breakpoints aren't working both when I run the debugger manually in a terminal and when I run it through Eclipse CDT, where I get the same error discussed in this question which was apparently never answered:

Eclipse CDT为什么会忽略断点?

我使用的是:


  • Eclipse Kepler

  • Mac OSX 10.8.4

  • gdb 6.3.5(Apple版本)

  • gcc 4.2.1与 -O0 -g3 标志

  • Eclipse Kepler
  • Mac OSX 10.8.4
  • gdb 6.3.5 (Apple version)
  • gcc 4.2.1 with -O0 and -g3 flags

请耐心等待。我仍在学习绳索。

Please be patient with me. I'm still learning the ropes.

推荐答案

你可能会碰到这个GDB 错误

You are likely hitting this GDB bug.

这个错误早已修复, GDB非常老(而且苹果不太可能更新)。

This bug has long been fixed, but your version of GDB is very old (and Apple is unlikely to update it).

这篇关于当使用多个源文件时,GDB不会破坏某些代码行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆