Problem with breakpoints in gdb

Posted by Greven on Thu 05 Feb 2004 10:36 PM — 10 posts, 31,291 views.

Canada #0
I'm trying to set a break point, but I'm getting this error:
Quote:
(gdb) break fight.c:525
Breakpoint 1 at 0x80e1bca: file fight.c, line 525.
(gdb) cont
Continuing.
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0x80e1bca: Input/output error.
The same program may be running in another process.


I get similar problem when I try to boot it from within gdb,but the breakpoint is -2. My compilation flags are:
Quote:
DEBUG = -ggdb
C_FLAGS = -g3 -g2 -W -Wall $(DEFINES) $(PROF) $(NOCRYPT) $(DBUGFLG) $(DEBUG) -export-dynamic


I'm really unclear on what the problem may be, or what I can do about it.
USA #1
Looks like you might have the program running twice (under two separate process.)
Canada #2
nope, only one, I checked that. This might help:
dwadmins@godlike:~/src$ ps ux
USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
dwadmins   555  0.0  0.2  2104 1836 ?        S    Feb04   0:00 /bin/bash ./swr-watch
dwadmins   904  0.0  0.4  6232 3204 ?        S    Feb04   0:00 sshd: dwadmins@pts/14
dwadmins   905  0.0  0.3  2372 2432 pts/14   S    Feb04   0:00 -bash
dwadmins   562  1.3  1.4 11528 11496 ?       SN   Feb04  21:13 swr 4848 hotboot 5 0 0 0 -1
dwadmins  2298  0.0  0.1  2788 1368 pts/14   R    18:32   0:00 ps ux
dwadmins@godlike:~/src$ gdb swr 562
GNU gdb 5.3
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-slackware-linux"...
Attaching to program: /home/mud/darkwars/dwadmins/src/swr, process 562
Reading symbols from /lib/libdl.so.2...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /usr/lib/libz.so.1...done.
Loaded symbols for /usr/lib/libz.so.1
Reading symbols from /lib/libcrypt.so.1...done.
Loaded symbols for /lib/libcrypt.so.1
Reading symbols from /usr/lib/libstdc++.so.5...done.
Loaded symbols for /usr/lib/libstdc++.so.5
Reading symbols from /lib/libm.so.6...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /usr/lib/libgcc_s.so.1...done.
Loaded symbols for /usr/lib/libgcc_s.so.1
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/libnss_files.so.2...done.
Loaded symbols for /lib/libnss_files.so.2
Reading symbols from /lib/libnss_dns.so.2...done.
Loaded symbols for /lib/libnss_dns.so.2
Reading symbols from /lib/libresolv.so.2...done.
Loaded symbols for /lib/libresolv.so.2
0x282765e2 in select () from /lib/libc.so.6
(gdb) break fight.c:525
Breakpoint 1 at 0x80e1bca: file fight.c, line 525.
(gdb) cont
Continuing.
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0x80e1bca: Input/output error.
The same program may be running in another process.
(gdb) quit
The program is running.  Quit anyway (and detach it)? (y or n) y
Detaching from program: /home/mud/darkwars/dwadmins/src/swr, process 562
dwadmins@godlike:~/src$ 
Amended on Fri 06 Feb 2004 01:33 AM by Greven
USA #3
One thing you can try is to start the process with GDB directly, i.e.

gdb ../src/swr
(in gdb) run 4848

Not sure if that will help though...
Canada #4
Quote:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
dwadmins 555 0.0 0.2 2104 1836 ? S Feb04 0:00 /bin/bash ./swr-watch
dwadmins 904 0.0 0.4 6232 3204 ? S Feb04 0:00 sshd: dwadmins@pts/14
dwadmins 905 0.0 0.3 2372 2432 pts/14 S Feb04 0:00 -bash
dwadmins 562 1.3 1.4 10888 10976 ? SN Feb04 21:34 swr 4848 hotboot 5 0 0 0 -1
dwadmins 2659 0.0 0.1 2800 1368 pts/14 R 18:57 0:00 ps ux
dwadmins@godlike:~/port/area$ gdb ../src/swr
GNU gdb 5.3
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-slackware-linux"...run
(gdb) run 4872
Starting program: /home/mud/darkwars/dwadmins/port/src/swr 4872
Warning:
Cannot insert breakpoint -2.
Error accessing memory address 0x22a76520: Input/output error.
.


I tried that before, which is what makes this kinda strange
Amended on Fri 06 Feb 2004 01:59 AM by Greven
Australia Forum Administrator #5
OK, let's see what you are trying to set the breakpoint on.

In gdb type:

list fight.c:525

Just curious, maybe it is a literal or something.
Australia Forum Administrator #6
Quote:

dwadmins 562 1.3 1.4 10888 10976 ? SN Feb04 21:34 swr 4848 hotboot 5 0 0 0 -1
dwadmins 2659 0.0 0.1 2800 1368 pts/14 R 18:57 0:00 ps ux
dwadmins@godlike:~/port/area$ gdb ../src/swr


In your example you have two copies - the one running in process 562, and the new one you are gdb'ing.

If the process ID is 562, try typing:

gdb swr 562

(In the earlier posts 4848 is the port, not the PID).
Canada #7
Ok, here is what I get
Quote:
wadmins@godlike:~$ gdb /src/swr 562
GNU gdb 5.3
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-slackware-linux"...
Attaching to program: /home/mud/darkwars/dwadmins/src/swr, process 562
Reading symbols from /lib/libdl.so.2...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /usr/lib/libz.so.1...done.
Loaded symbols for /usr/lib/libz.so.1
Reading symbols from /lib/libcrypt.so.1...done.
Loaded symbols for /lib/libcrypt.so.1
Reading symbols from /usr/lib/libstdc++.so.5...done.
Loaded symbols for /usr/lib/libstdc++.so.5
Reading symbols from /lib/libm.so.6...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /usr/lib/libgcc_s.so.1...done.
Loaded symbols for /usr/lib/libgcc_s.so.1
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/libnss_files.so.2...done.
Loaded symbols for /lib/libnss_files.so.2
Reading symbols from /lib/libnss_dns.so.2...done.
Loaded symbols for /lib/libnss_dns.so.2
Reading symbols from /lib/libresolv.so.2...done.
Loaded symbols for /lib/libresolv.so.2
0x282765e2 in select () from /lib/libc.so.6
(gdb) break fight.c:525
Breakpoint 1 at 0x80e1bca: file fight.c, line 525.
(gdb) list fight.c:525
520 case 4: *gsn_ptr = gsn_flexible_arms; break;
521 case 5: *gsn_ptr = gsn_knives; break;
522 case 6: *gsn_ptr = gsn_blasters; break;
523 case 8: *gsn_ptr = gsn_bludgeons; break;
524 case 9: *gsn_ptr = gsn_bowcasters; break;
525 case 11: *gsn_ptr = gsn_force_pikes; break;
526
527 }
528 if ( *gsn_ptr != -1 )
529 bonus = (int) ( ch->pcdata->learned[*gsn_ptr] );
(gdb)


I can understand how it might not work depending where I am setting the break point, but it doesn't seem to mattter where I actually put the break, I get the same error when I've attached to the pid.
Amended on Fri 06 Feb 2004 10:18 PM by Greven
Australia Forum Administrator #8
I cannot reproduce this, as you might expect, as I did all the breakpoint stuff in my recent forum post without any problems.

However a Google search for:

gdb "cannot insert breakpoint -2"

reveals quite a few posts from people with similar problems.

Sounds it might be a problem with shared libraries, which doesn't seem to apply in your case, or just a bug in the particular Linux kernel.

All I can suggest doing is:

* Upgrade your Linux version; or
* Download and compile a newer version of gdb, if applicable

Try searching for your particular OS version (is it Slackware?, it looks like it might be) and see if there is a known problem with gdb and that version.
Canada #9
Actually, I'm on a payed server, so I can't do any upgrades myself. If thats the case, I'll contact my admin, thanks.