hp.com!davidm | beca885 | 2004-10-15 13:48:38 +0000 | [diff] [blame] | 1 | /* libunwind - a platform-independent unwind library |
| 2 | Copyright (C) 2004 Hewlett-Packard Co |
| 3 | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
| 4 | |
| 5 | This file is part of libunwind. |
| 6 | |
| 7 | Permission is hereby granted, free of charge, to any person obtaining |
| 8 | a copy of this software and associated documentation files (the |
| 9 | "Software"), to deal in the Software without restriction, including |
| 10 | without limitation the rights to use, copy, modify, merge, publish, |
| 11 | distribute, sublicense, and/or sell copies of the Software, and to |
| 12 | permit persons to whom the Software is furnished to do so, subject to |
| 13 | the following conditions: |
| 14 | |
| 15 | The above copyright notice and this permission notice shall be |
| 16 | included in all copies or substantial portions of the Software. |
| 17 | |
| 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 22 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 24 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 25 | |
| 26 | #include <signal.h> |
| 27 | #include <stdint.h> |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <unistd.h> |
| 31 | |
| 32 | #include <sys/types.h> |
| 33 | |
| 34 | pid_t self; |
| 35 | int global[64]; |
| 36 | |
| 37 | int |
| 38 | func (int arg) |
| 39 | { |
| 40 | int sum = 0, i, max, arr[1024]; |
| 41 | |
| 42 | if (arg == 0) |
| 43 | { |
| 44 | sum = global[2]; |
| 45 | sum += sum + sum * getppid (); |
| 46 | return sum; |
| 47 | } |
| 48 | else |
| 49 | { |
| 50 | max = arg; |
| 51 | if (max >= 64) |
| 52 | max = 64; |
| 53 | |
| 54 | for (i = 0; i < max; ++i) |
| 55 | arr[i] = func (arg - 1); |
| 56 | |
| 57 | for (i = 0; i < max; ++i) |
| 58 | if (arr[i] > 16) |
| 59 | sum += arr[i]; |
| 60 | else |
| 61 | sum -= arr[i]; |
| 62 | } |
| 63 | return sum; |
| 64 | } |
| 65 | |
| 66 | int |
| 67 | bar (int v) |
| 68 | { |
| 69 | extern long f (long); |
hp.com!davidm | 9fa361e | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 70 | int arr[1] = { v }; |
hp.com!davidm | beca885 | 2004-10-15 13:48:38 +0000 | [diff] [blame] | 71 | uintptr_t r; |
| 72 | |
| 73 | /* This is a vain attempt to use up lots of registers to force |
| 74 | the frame-chain info to be saved on the memory stack on ia64. |
| 75 | It happens to work with gcc v3.3.4 and gcc v3.4.1 but perhaps |
| 76 | not with any other compiler. */ |
| 77 | r = (uintptr_t) malloc(f (arr[0]) |
| 78 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 79 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 80 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 81 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 82 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 83 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 84 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 85 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 86 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 87 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 88 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 89 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 90 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 91 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 92 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 93 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) |
| 94 | + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + (f (v) + f (v)) |
| 95 | )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) |
| 96 | ))))))))))))))))))))))))))))))))))))))))))))))))))))))); |
| 97 | if (r < 2) |
| 98 | v = r; |
| 99 | |
| 100 | kill (self, SIGUSR1); /* tell test-ptrace to start single-stepping */ |
| 101 | v = func (v); |
| 102 | kill (self, SIGUSR2); /* tell test-ptrace to stop single-stepping */ |
| 103 | return v; |
| 104 | } |
| 105 | |
| 106 | int |
| 107 | main (int argc, char **argv) |
| 108 | { |
| 109 | int val = argc; |
| 110 | |
| 111 | signal (SIGUSR1, SIG_IGN); |
| 112 | signal (SIGUSR2, SIG_IGN); |
| 113 | |
| 114 | self = getpid (); |
| 115 | |
| 116 | printf ("sum = %d\n", bar (val)); |
| 117 | return 0; |
| 118 | } |