• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2010 stefan.demharter@gmx.net
3    Copyright (C) 2010 arun.sharma@google.com
4 
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
12 
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
23 
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <libunwind.h>
28 #include "compiler.h"
29 
30 #define panic(args...)				\
31 	{ fprintf (stderr, args); exit (-1); }
32 
33 static int verbose;
34 
35 struct Test
36 {
37   public: // --- ctor/dtor ---
TestTest38     Test() { ++counter_; }
~TestTest39     ~Test() { -- counter_; }
TestTest40     Test(const Test&) { ++counter_; }
41 
42   public: // --- static members ---
43     static int counter_;
44 };
45 
46 int Test::counter_ = 0;
47 
48 // Called by foo
bar()49 extern "C" void bar()
50 {
51   Test t;
52   try {
53     Test t;
54     throw 5;
55   } catch (...) {
56     Test t;
57     if (verbose)
58       printf("Throwing an int\n");
59     throw 6;
60   }
61 }
62 
main(int argc,char ** argv UNUSED)63 int main(int argc, char **argv UNUSED)
64 {
65   if (argc > 1)
66     verbose = 1;
67   try {
68     Test t;
69     bar();
70   } catch (int) {
71     // Dtor of all Test-object has to be called.
72     if (Test::counter_ != 0)
73       panic("Counter non-zero\n");
74     return Test::counter_;
75   } catch (...) {
76     // An int was thrown - we should not get here.
77     panic("Int was thrown why are we here?\n");
78   }
79   exit(0);
80 }
81