You are not logged in.

#1 2016-12-20 15:55:16

blablubs82352
Member
Registered: 2016-09-25
Posts: 21

GDB ignore breakpoint

Hey,

I installed arch on my notebook. I'm quite familiar with gdb.
Problem is that gdb is not breaking at breakpoints set before.
I would guess something is wrong with the config of gdb for my user. But I have
no idea how to debug this.
Anybody an idea?

So a simple example.c

int main(void)
{
    int a = 0; 
    int b = 3;
    int c;
    c = a + b;
    return 1;
}

compile it with gcc -g -o example example.c
when debugging with ~>gdb example and setting a break at e.g. line 6 it does not
break.

GNU gdb (GDB) 7.12
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from example...done.
(gdb) break 6
Breakpoint 1 at 0x4004b8: file example.c, line 6.
(gdb) r
Starting program: /tmp/example 
[Inferior 1 (process 1921) exited with code 01]
(gdb) 

But if it run as root #> gdb example

...output as before
(gdb) break 6
Breakpoint 1 at 0x4004b8: file example.c, line 6.
(gdb) r
Starting program: /tmp/example 

Breakpoint 1, main () at example.c:6
warning: Source file is more recent than executable.
6           c = a + b;
(gdb) 

thanks

blablubs82352

Offline

#2 2016-12-20 16:01:51

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,740

Re: GDB ignore breakpoint

I would venture that those statements were optimized out.  That program returns 1.  There is no output.  There is no storage.  a, b and c have no purpose.

Try printing c before you exit.

Edit:  I stopped reading before you introduced root.  Now I've no idea
Edit 2: Um, "warning: Source file is more recent than executable."

Last edited by ewaller (2016-12-20 16:12:48)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2016-12-20 20:56:19

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: GDB ignore breakpoint

Huh, when I do exactly what you did, I have the following results:

[jbs@dmb-gaming-laptop example_debug]$ pwd
/home/jbs/cpp/tests/example_debug
[jbs@dmb-gaming-laptop example_debug]$ ls
example.c
[jbs@dmb-gaming-laptop example_debug]$ gcc -g -o example example.c 
[jbs@dmb-gaming-laptop example_debug]$ ls
example  example.c
[jbs@dmb-gaming-laptop example_debug]$ gdb example
GNU gdb (GDB) 7.12
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from example...done.
(gdb) break 6
Breakpoint 1 at 0x4004b8: file example.c, line 6.
(gdb) r
Starting program: /home/jbs/cpp/tests/example_debug/example 

Breakpoint 1, main () at example.c:6
6           c = a + b;
(gdb) quit
A debugging session is active.

        Inferior 1 [process 1300] will be killed.

Quit anyway? (y or n) y
[jbs@dmb-gaming-laptop example_debug]$ whoami
jbs
[jbs@dmb-gaming-laptop example_debug]$ 

Contents of example.c:

[jbs@dmb-gaming-laptop example_debug]$ cat example.c 
int main(void)
{
    int a = 0; 
    int b = 3;
    int c;
    c = a + b;
    return 1;
}
[jbs@dmb-gaming-laptop example_debug]$ 

So it worked for me, as a standard user. Is your executable owned by root by chance?? Or is /tmp owned by root in your case? It shouldn't be, AFAIK, but you wont know until you check. The "source is more recent then executable" warning, as ewaller pointed out, would also be worth investigating. I'm not sure why this worked for me but not for you. sad


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#4 2016-12-20 22:18:03

blablubs82352
Member
Registered: 2016-09-25
Posts: 21

Re: GDB ignore breakpoint

Hi,
Recompiling doesn't make anything better. It doesn't matter where or as who the code is compiled.
I know my other netbook with similar arch setup has the same problem. But as for you,  at a friend of mine it works perfectly.

I checked show configuration is the same for root and my user.

   configure --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu
             --with-auto-load-dir=$debugdir:$datadir/auto-load
             --with-auto-load-safe-path=$debugdir:$datadir/auto-load
             --with-expat
             --with-gdb-datadir=/usr/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/lib/gdb (relocatable)
             --without-libunwind-ia64
             --with-lzma
             --with-python=/usr (relocatable)
             --with-guile
             --with-separate-debug-dir=/usr/lib/debug (relocatable)
             --with-system-gdbinit=/etc/gdb/gdbinit
             --without-babeltrace

Offline

#5 2017-01-14 10:21:04

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 237

Re: GDB ignore breakpoint

[dimich@dimich tmp]$ cat > example.c
int main(void)
{
    int a = 0; 
    int b = 3;
    int c;
    c = a + b;
    return 1;
}
[dimich@dimich tmp]$ gcc -g -o example example.c
[dimich@dimich tmp]$ 
[dimich@dimich tmp]$ gdb ./example
GNU gdb (GDB) 7.12
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./example...done.
(gdb) break 6
Breakpoint 1 at 0x4004b8: file example.c, line 6.
(gdb) r
Starting program: /home/dimich/tmp/example 

Breakpoint 1, main () at example.c:6
6	    c = a + b;
(gdb) 

¯\_(ツ)_/¯

Offline

#6 2017-05-03 09:15:27

blablubs82352
Member
Registered: 2016-09-25
Posts: 21

Re: GDB ignore breakpoint

Hi,
mysteriously with one of the latest updates this issue disappeared.
I have no idea, what was the issue which caused this problem.
/blablubs82352

Offline

Board footer

Powered by FluxBB