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

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

问题描述

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



Main.cpp:

  #include< iostream> 
#includeDomain.h

int main()
{
域y;
std :: cout<<< y.x <的std :: ENDL; //< - 在这里设置断点无问题
return 0;
}

Domain.cpp:

  #includeDomain.h

Domain :: Domain()
{
x = 4; //< - 跳过这里的断点
}

Domain.h :

  #ifndef DOMAIN_H_ 
#define DOMAIN_H_

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

#endif / * DOMAIN_H_ * /

但是,问题不存在,如果我把所有东西放在一个文件中:



Main2.cpp:

  #include< iostream> 

int main()
{

class Domain
{
public:
int x;
Domain()
{
x = 4; //< - 现在无需设置断点!
};

};

域y;

std :: cout<<< y.x <的std :: ENDL;

return 0;
}

为什么会这样?我如何更改这个,以便我可以在使用多个文件时设置断点?



我可以确认断点在运行时不起作用在终端中手动调试器,当我通过Eclipse CDT运行它时,我得到了这个问题中讨论的相同的错误,这显然从未回答过:



为什么Eclipse CDT忽略断点?



我正在使用:




  • Eclipse Kepler

  • Mac OSX 10.8.4

  • gdb 6.3.5(Apple版)

  • gcc 4.2.1与 -O0 -g3 标志



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

解决方案

你可能会碰到这个GDB 错误



这个bug一直被修复,但是你的版本GDB非常旧(而苹果不大可能更新)。


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:

#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?

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:

Why does Eclipse CDT ignore breakpoints?

I am using:

  • 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.

解决方案

You are likely hitting this GDB bug.

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天全站免登陆