Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB does not break on some lines of code when using multiple source files

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.

like image 987
Neal Kruis Avatar asked Feb 07 '26 17:02

Neal Kruis


1 Answers

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

like image 167
Employed Russian Avatar answered Feb 09 '26 05:02

Employed Russian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!