This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Can't set bkpt at throw statement
- From: "Allen Hopkins" <allenh at eecs dot berkeley dot edu>
- To: gdb at sources dot redhat dot com
- Date: Wed, 11 Aug 2004 18:17:09 -0700
- Subject: Can't set bkpt at throw statement
I have two essentially identical C++ classes with essentially identical
methods that both throw the same exception. In gdb, I'm able to set a
breakpoint at the "throw" statement in one class, but not in the other.
Here are the break commands, first on the one that succeeds, then on
the one that fails:
(gdb) break Ethel.cpp:12
Breakpoint 1 at 0x80488b5: file Ethel.cpp, line 12.
(gdb) break Fred.cpp:12
Note: breakpoint -1 (disabled) also set at pc 0x0.
Breakpoint 2 at 0x0: file Fred.cpp, line 12.
(gdb) run
Starting program: /tmp/allenh/metro_dev/examples/stuck/run.x
Warning:
Cannot insert breakpoint 2.
Error accessing memory address 0x0: Input/output error.
Here is a shar of a simple demo of the problem. You can also find these
files at http://www.eecs.berkeley.edu/~allenh/stuck.
Any advice may help save my sanity. Thanks.
-Allen Hopkins
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# DaBomb.h
# demo
# Ethel.cpp
# Ethel.h
# Fred.cpp
# Fred.h
# gdbrc
# main.cpp
# makefile
#
echo x - DaBomb.h
sed 's/^X//' >DaBomb.h << 'END-of-DaBomb.h'
X#ifndef DABOMB_H
X#define DABOMB_H
X
Xclass DaBomb {};
X
X#endif
END-of-DaBomb.h
echo x - demo
sed 's/^X//' >demo << 'END-of-demo'
X#!/bin/sh
X
Xmake
Xrun.x
Xgdb -x gdbrc run.x
X
END-of-demo
echo x - Ethel.cpp
sed 's/^X//' >Ethel.cpp << 'END-of-Ethel.cpp'
X#include "Ethel.h"
X#include "DaBomb.h"
X#include <iostream.h>
X
XEthel::Ethel(int i) {
X trigger = i;
X};
X
Xvoid Ethel::myFunc(int i)
X{
X if (i == trigger) {
X throw DaBomb();
X } else {
X cout << "Ethel says " << i << endl;
X }
X};
END-of-Ethel.cpp
echo x - Ethel.h
sed 's/^X//' >Ethel.h << 'END-of-Ethel.h'
X#ifndef ETHEL_H
X#define ETHEL_H
X
Xclass Ethel;
X
Xclass Ethel {
X public:
X int trigger;
X Ethel(int i);
X void myFunc(int i);
X};
X
X#endif
END-of-Ethel.h
echo x - Fred.cpp
sed 's/^X//' >Fred.cpp << 'END-of-Fred.cpp'
X#include "Fred.h"
X#include "DaBomb.h"
X#include <iostream.h>
X
XFred::Fred(int i) {
X trigger = i;
X};
X
Xvoid Fred::myFunc(int i)
X{
X if (i == trigger) {
X throw DaBomb();
X } else {
X cout << "Fred says " << i << endl;
X }
X};
END-of-Fred.cpp
echo x - Fred.h
sed 's/^X//' >Fred.h << 'END-of-Fred.h'
X#ifndef FRED_H
X#define FRED_H
X
Xclass Fred;
X
Xclass Fred {
X public:
X int trigger;
X Fred(int i);
X void myFunc(int i);
X};
X
X#endif
END-of-Fred.h
echo x - gdbrc
sed 's/^X//' >gdbrc << 'END-of-gdbrc'
Xbreak Fred.cpp:12
Xbreak Ethel.cpp:12
Xrun
END-of-gdbrc
echo x - main.cpp
sed 's/^X//' >main.cpp << 'END-of-main.cpp'
X#include "Fred.h"
X#include "Ethel.h"
X#include "DaBomb.h"
X#include <iostream.h>
X
Xint main(int argc, char* argv[])
X{
X Fred* fred = new Fred(3);
X Ethel* ethel = new Ethel(7);
X
X for (int i = 0; i < 10; i++) {
X
X try {
X fred->myFunc(i);
X } catch (DaBomb) {
X cout << "FRED threw DaBomb." << endl;
X }
X
X try {
X ethel->myFunc(i);
X } catch (DaBomb) {
X cout << "ETHEL threw DaBomb." << endl;
X }
X }
X}
END-of-main.cpp
echo x - makefile
sed 's/^X//' >makefile << 'END-of-makefile'
XOPTS = -ggdb -Wno-deprecated
X
Xall: Ethel.o Fred.o main.o
X g++ $(OPTS) -o run.x \
X Ethel.o Fred.o main.o
X
XEthel.o: Ethel.cpp Ethel.h
X g++ $(OPTS) -c Ethel.cpp
X
XFred.o: Fred.cpp Fred.h
X g++ $(OPTS) -c Fred.cpp
X
Xmain.o: ./main.cpp
X g++ $(OPTS) -c ./main.cpp
X
Xclean:
X rm -f *.o run.x
END-of-makefile
exit