mostang.com!davidm | ef59373 | 2003-09-19 06:56:12 +0000 | [diff] [blame] | 1 | /* libunwind - a platform-independent unwind library |
| 2 | Copyright (C) 2003 Hewlett-Packard Co |
| 3 | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
| 4 | |
| 5 | This file is part of libunwind. |
| 6 | |
| 7 | Copyright (c) 2003 Hewlett-Packard Co. |
| 8 | |
| 9 | Permission is hereby granted, free of charge, to any person obtaining |
| 10 | a copy of this software and associated documentation files (the |
| 11 | "Software"), to deal in the Software without restriction, including |
| 12 | without limitation the rights to use, copy, modify, merge, publish, |
| 13 | distribute, sublicense, and/or sell copies of the Software, and to |
| 14 | permit persons to whom the Software is furnished to do so, subject to |
| 15 | the following conditions: |
| 16 | |
| 17 | The above copyright notice and this permission notice shall be |
| 18 | included in all copies or substantial portions of the Software. |
| 19 | |
| 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 27 | |
| 28 | #ifdef HAVE_CONFIG_H |
| 29 | # include "config.h" |
| 30 | #endif |
| 31 | |
| 32 | #if HAVE_EXECINFO_H |
| 33 | # include <execinfo.h> |
| 34 | #else |
| 35 | extern int backtrace (void **, int); |
| 36 | #endif |
| 37 | #include <stdio.h> |
| 38 | #include <string.h> |
| 39 | |
| 40 | #define UNW_LOCAL_ONLY /* must define this for consistency with backtrace() */ |
| 41 | #include <libunwind.h> |
| 42 | |
| 43 | int verbose; |
| 44 | |
| 45 | int |
| 46 | f257 (void) |
| 47 | { |
| 48 | void *buffer[300]; |
| 49 | int i, n; |
| 50 | |
| 51 | if (verbose) |
| 52 | printf ("First backtrace:\n"); |
| 53 | n = backtrace (buffer, 300); |
| 54 | if (verbose) |
| 55 | for (i = 0; i < n; ++i) |
| 56 | printf ("[%d] ip=%p\n", i, buffer[i]); |
| 57 | |
| 58 | unw_flush_cache (unw_local_addr_space, 0, 0); |
| 59 | |
| 60 | if (verbose) |
| 61 | printf ("\nSecond backtrace:\n"); |
| 62 | n = backtrace (buffer, 300); |
| 63 | if (verbose) |
| 64 | for (i = 0; i < n; ++i) |
| 65 | printf ("[%d] ip=%p\n", i, buffer[i]); |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | #define F(n,m) \ |
| 70 | int \ |
| 71 | f##n (void) \ |
| 72 | { \ |
| 73 | return f##m (); \ |
| 74 | } |
| 75 | |
| 76 | /* Here, we rely on the fact that the script-cache's hash-table is 256 |
| 77 | entries big. With 257 functions, we're guaranteed to get at least |
| 78 | one hash-collision. */ |
| 79 | F(256,257) F(255,256) F(254,255) F(253,254) |
| 80 | F(252,253) F(251,252) F(250,251) F(249,250) |
| 81 | F(248,249) F(247,248) F(246,247) F(245,246) |
| 82 | F(244,245) F(243,244) F(242,243) F(241,242) |
| 83 | F(240,241) F(239,240) F(238,239) F(237,238) |
| 84 | F(236,237) F(235,236) F(234,235) F(233,234) |
| 85 | F(232,233) F(231,232) F(230,231) F(229,230) |
| 86 | F(228,229) F(227,228) F(226,227) F(225,226) |
| 87 | F(224,225) F(223,224) F(222,223) F(221,222) |
| 88 | F(220,221) F(219,220) F(218,219) F(217,218) |
| 89 | F(216,217) F(215,216) F(214,215) F(213,214) |
| 90 | F(212,213) F(211,212) F(210,211) F(209,210) |
| 91 | F(208,209) F(207,208) F(206,207) F(205,206) |
| 92 | F(204,205) F(203,204) F(202,203) F(201,202) |
| 93 | F(200,201) F(199,200) F(198,199) F(197,198) |
| 94 | F(196,197) F(195,196) F(194,195) F(193,194) |
| 95 | F(192,193) F(191,192) F(190,191) F(189,190) |
| 96 | F(188,189) F(187,188) F(186,187) F(185,186) |
| 97 | F(184,185) F(183,184) F(182,183) F(181,182) |
| 98 | F(180,181) F(179,180) F(178,179) F(177,178) |
| 99 | F(176,177) F(175,176) F(174,175) F(173,174) |
| 100 | F(172,173) F(171,172) F(170,171) F(169,170) |
| 101 | F(168,169) F(167,168) F(166,167) F(165,166) |
| 102 | F(164,165) F(163,164) F(162,163) F(161,162) |
| 103 | F(160,161) F(159,160) F(158,159) F(157,158) |
| 104 | F(156,157) F(155,156) F(154,155) F(153,154) |
| 105 | F(152,153) F(151,152) F(150,151) F(149,150) |
| 106 | F(148,149) F(147,148) F(146,147) F(145,146) |
| 107 | F(144,145) F(143,144) F(142,143) F(141,142) |
| 108 | F(140,141) F(139,140) F(138,139) F(137,138) |
| 109 | F(136,137) F(135,136) F(134,135) F(133,134) |
| 110 | F(132,133) F(131,132) F(130,131) F(129,130) |
| 111 | F(128,129) F(127,128) F(126,127) F(125,126) |
| 112 | F(124,125) F(123,124) F(122,123) F(121,122) |
| 113 | F(120,121) F(119,120) F(118,119) F(117,118) |
| 114 | F(116,117) F(115,116) F(114,115) F(113,114) |
| 115 | F(112,113) F(111,112) F(110,111) F(109,110) |
| 116 | F(108,109) F(107,108) F(106,107) F(105,106) |
| 117 | F(104,105) F(103,104) F(102,103) F(101,102) |
| 118 | F(100,101) F(99,100) F(98,99) F(97,98) |
| 119 | F(96,97) F(95,96) F(94,95) F(93,94) |
| 120 | F(92,93) F(91,92) F(90,91) F(89,90) |
| 121 | F(88,89) F(87,88) F(86,87) F(85,86) |
| 122 | F(84,85) F(83,84) F(82,83) F(81,82) |
| 123 | F(80,81) F(79,80) F(78,79) F(77,78) |
| 124 | F(76,77) F(75,76) F(74,75) F(73,74) |
| 125 | F(72,73) F(71,72) F(70,71) F(69,70) |
| 126 | F(68,69) F(67,68) F(66,67) F(65,66) |
| 127 | F(64,65) F(63,64) F(62,63) F(61,62) |
| 128 | F(60,61) F(59,60) F(58,59) F(57,58) |
| 129 | F(56,57) F(55,56) F(54,55) F(53,54) |
| 130 | F(52,53) F(51,52) F(50,51) F(49,50) |
| 131 | F(48,49) F(47,48) F(46,47) F(45,46) |
| 132 | F(44,45) F(43,44) F(42,43) F(41,42) |
| 133 | F(40,41) F(39,40) F(38,39) F(37,38) |
| 134 | F(36,37) F(35,36) F(34,35) F(33,34) |
| 135 | F(32,33) F(31,32) F(30,31) F(29,30) |
| 136 | F(28,29) F(27,28) F(26,27) F(25,26) |
| 137 | F(24,25) F(23,24) F(22,23) F(21,22) |
| 138 | F(20,21) F(19,20) F(18,19) F(17,18) |
| 139 | F(16,17) F(15,16) F(14,15) F(13,14) |
| 140 | F(12,13) F(11,12) F(10,11) F(9,10) |
| 141 | F(8,9) F(7,8) F(6,7) F(5,6) |
| 142 | F(4,5) F(3,4) F(2,3) F(1,2) |
| 143 | |
| 144 | int |
| 145 | main (int argc, char **argv) |
| 146 | { |
| 147 | if (argc > 1 && strcmp (argv[1], "-v") == 0) |
| 148 | verbose = 1; |
| 149 | |
| 150 | return f1 (); |
| 151 | } |