This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Simple exception use-case
- From: Phil Muldoon <pmuldoon at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Mon, 28 Jul 2008 13:52:25 +0100
- Subject: Simple exception use-case
I want to start building these cases to guide the requirements for
better C++ exception handling in GDB. I'll start with existing
technology, and a novice C++ programmer. Example program:
cat simple.cxx
#include <iostream>
#include <exception>
using namespace std;
class simple : public exception
{
virtual const char* what() const throw()
{
return "simple exception occurred";
}
} simple;
int main () {
try
{
throw simple;
}
catch (exception &e)
{
cout << "Exception: " << e.what() << endl;
}
return 0;
}
In this scenario, I just want to catch the: "simple" exception type
being thrown. There are differences between Fedora's GDB (my chosen
distribution), and upstream GDB. For now, assume I am using upstream,
and a "recent" build (mine was built from today's CVS).
Generic exception catching mentions:
help catch
<snip useful info>
Raised exceptions may be caught:
catch throw - all exceptions, when thrown
catch throw <exceptname> - a particular exception, when thrown
catch catch - all exceptions, when caught
catch catch <exceptname> - a particular exception, when caught
So a programmer can catch all exceptions, or named exceptions. There is
also C++ specific information:
C++ exceptions may be caught:
catch throw - all exceptions, when thrown
catch catch - all exceptions, when caught
So for this simple use-case, I'll just stick with catch throw and catch
catch.
Build my simple C++ application:
g++ -g simple.cxx -o simple
and load it into GDB and tell GDB to catch C++ exceptions:
~/gdb_obj/gdb/gdb simple
GNU gdb (GDB) 6.8.50.20080728-cvs
(gdb) catch throw
Catchpoint 1 (throw)
Run the program:
(gdb) run
Starting program: /home/pmuldoon/exceptions/simple
Catchpoint 1 (exception thrown), 0x000000333d0c3d70 in __cxa_throw ()
from /usr/lib64/libstdc++.so.6
Well it caught something, but what?
(gdb) list
8 virtual const char* what() const throw()
9 {
10 return "simple exception occurred";
11 }
12 } simple;
13
14 int main () {
15 try
16 {
17 throw simple;
Well I think it is "throw simple", that is the last line shown. But it
would be neat if the catch would print the actual throw line, like a
simple breakpoint. Shown below:
(gdb) break main
Breakpoint 1 at 0x400be7: file simple.cxx, line 17.
(gdb) run
Starting program: /home/pmuldoon/exceptions/simple
Breakpoint 1, main () at simple.cxx:17
17 throw simple;
Anyway, there seems to be no debuginfo associated with the libstdc++
blobs. I'll just step until I return to my program and through the
catch statement. Then I can look at the exception object in detail:
Catchpoint 1 (exception thrown), 0x000000333d0c3d70 in __cxa_throw ()
from /usr/lib64/libstdc++.so.6
(gdb) s
Single stepping until exit from function __cxa_throw,
which has no line number information.
Exception: simple exception occurred
Program exited normally.
Well maybe not. I'm not sure why I lost control of the inferior. I'll
investigate the debuginfo. This is Fedora specific but similar would
apply for any distribution:
rpm -q gcc-debuginfo
gcc-debuginfo-4.3.0-8.x86_64
I know debuginfo is stored in /usr/lib/debug
find -type f -name "libstdc*"
./usr/lib64/libstdc++.so.6.0.10.debug
rpm -qf `pwd`/usr/lib64/libstdc++.so.6.0.10.debug
gcc-debuginfo-4.3.0-8.x86_64
So I do have debuginfo. I'm puzzled. Ok lets try the GDB
tailored/packaged to the distribution:
gdb simple
GNU gdb Fedora (6.8-11.fc9)
(gdb) catch catch
Function "__cxa_begin_catch" not defined.
(gdb) catch throw
Function "__cxa_throw" not defined.
No luck there. So I have a simple use case to solve. Comments?
Regards
Phil