List Info

Thread: break on a external source file




break on a external source file
user name
2007-09-21 17:21:31
How can I tell to gdb to put a breakpoint on a given line in
C++
source file, located in directory situated other than
current one ?

$cat -n main.cc
     1  #include <dir/print.h>
     2  int
     3  main(int argc, char **argv)
     4  {
     5      Print P(100);
     6      P.print();
     7      return 0;
     8  }
$ cat -n dir/print.h
     1  #ifndef PRINT_H
     2
     3  class Print
     4  {
     5      private:
     6          int val;
     7      public:
     8          Print(int v);
     9          void print();
    10  };
    11
    12  #endif
$ cat -n dir/print.cc
     1  #include <print.h>
     2  #include <iostream>
     3
     4  Print::Print(int v)
     5  {
     6      val=v+v;
     7  };
     8
     9  void Print::print()
    10  {
    11      std::cout<<val<<std::endl;
    12  }

g++  -g  -I. -Idir dir/print.cc  main.cc -o print

gdb print
(gdb) break dir/print.cc:6
Breakpoint 1 at 0x8048637: file dir/print.cc, line 6.
(gdb) break main.cc:6
Breakpoint 2 at 0x804871c: file main.cc, line 6.
(gdb)
(gdb) info break
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x08048637 in Print at
dir/print.cc:6
2   breakpoint     keep y   0x0804871c in main at main.cc:6
        breakpoint already hit 1 time
(gdb) run

Starting program: /home/user/print
Failed to read a valid object file image from memory.

Breakpoint 2, main () at main.cc:6
6           P.print();
(gdb) cont
Continuing.
200

Program exited normally.


In dir/print.cc:6 program is not interrupted by break, only
at
breakpoint from main.cc:6.

Re: break on a external source file
country flaguser name
United States
2007-09-21 17:39:18
On Sat, Sep 22, 2007 at 01:21:31AM +0300, costin_c wrote:
> How can I tell to gdb to put a breakpoint on a given
line in C++
> source file, located in directory situated other than
current one ?

You're doing it right.  The problem doesn't have to do with
that, but
with this:
>      4  Print::Print(int v)
>      5  {
>      6      val=v+v;
>      7  };

That's a constructor.  This is a known bug in GDB, for which
Vladimir
Prus has recently posted patches.

-- 
Daniel Jacobowitz
CodeSourcery

Re: break on a external source file
user name
2007-09-22 05:51:40
On 9/22/07, Daniel Jacobowitz <drowfalse.org> wrote:
> On Sat, Sep 22, 2007 at 01:21:31AM +0300, costin_c
wrote:
> > How can I tell to gdb to put a breakpoint on a
given line in C++
> > source file, located in directory situated other
than current one ?
>
> You're doing it right.  The problem doesn't have to do
with that, but
> with this:
> >      4  Print::Print(int v)
> >      5  {
> >      6      val=v+v;
> >      7  };
>
> That's a constructor.  This is a known bug in GDB, for
which Vladimir
> Prus has recently posted patches.
>

For line 11 form  Print::print() in  works fine
    9  void Print::print()
   10  {
   11      std::cout<<val<<std::endl;
   12  }

break dir/print.cc:11
Breakpoint 1 at 0x80486d0: file dir/print.cc, line 11.
(gdb) info break
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x080486d0 in Print::print() at
dir/print.cc:11
(gdb) r
Starting program: /home/user/print
Failed to read a valid object file image from memory.

Breakpoint 1, Print::print (this=0xbfb2c340) at
dir/print.cc:11
11          std::cout<<val<<std::endl;
(gdb) n
200
12      }
(gdb) n
main () at main.cc:7
7           return 0;

Re: break on a external source file
country flaguser name
United States
2007-09-22 08:52:44
On Sat, Sep 22, 2007 at 01:51:40PM +0300, costin_c wrote:
> For line 11 form  Print::print() in  works fine
>     9  void Print::print()

Right.  That is not a constructor.

-- 
Daniel Jacobowitz
CodeSourcery

Re: break on a external source file
country flaguser name
Finland
2007-09-22 09:08:11
Daniel Jacobowitz wrote:
> On Sat, Sep 22, 2007 at 01:21:31AM +0300, costin_c
wrote:
>> How can I tell to gdb to put a breakpoint on a
given line in C++
>> source file, located in directory situated other
than current one ?
> 
> You're doing it right.  The problem doesn't have to do
with that, but
> with this:
>>      4  Print::Print(int v)
>>      5  {
>>      6      val=v+v;
>>      7  };
> 
> That's a constructor.  This is a known bug in GDB, for
which Vladimir
> Prus has recently posted patches.
> 

Hi,

Are these patches already committed?

BR,

Claus



Re: break on a external source file
country flaguser name
United States
2007-09-22 10:37:33
On Sat, Sep 22, 2007 at 05:08:11PM +0300, Claus Baumgartner
wrote:
> Are these patches already committed?

Not yet, but I hope within the next few weeks.

-- 
Daniel Jacobowitz
CodeSourcery

[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )