Link Here
|
60 |
#endif /* PRINT_STACK_TRACE */ |
60 |
#endif /* PRINT_STACK_TRACE */ |
61 |
|
61 |
|
62 |
#if SA_RESETHAND == 0 && !_SQUID_WINDOWS_ |
62 |
#if SA_RESETHAND == 0 && !_SQUID_WINDOWS_ |
63 |
--- src/tools.cc.orig 2014-10-31 12:36:43.000000000 +0300 |
|
|
64 |
+++ src/tools.cc 2014-11-21 14:11:25.000000000 +0300 |
65 |
@@ -71,6 +71,13 @@ |
66 |
#include <errno.h> |
67 |
#endif |
68 |
|
69 |
+#if PRINT_STACK_TRACE |
70 |
+#ifdef __FreeBSD__ |
71 |
+#define UNW_LOCAL_ONLY |
72 |
+#include <libunwind.h> |
73 |
+#endif |
74 |
+#endif |
75 |
+ |
76 |
#define DEAD_MSG "\ |
77 |
The Squid Cache (version %s) died.\n\ |
78 |
\n\ |
79 |
@@ -411,6 +418,45 @@ |
80 |
} |
81 |
|
82 |
#endif |
83 |
+#ifdef __FreeBSD__ |
84 |
+ do { |
85 |
+ unw_context_t unw_ctx; |
86 |
+ unw_cursor_t unw_cp; |
87 |
+ unw_word_t sp, ip, off; |
88 |
+ int rc = 0; |
89 |
+ char procname[256]; |
90 |
+ size_t frame; |
91 |
+ |
92 |
+ bzero((void *)&unw_ctx, sizeof(unw_ctx)); |
93 |
+ bzero((void *)&unw_cp, sizeof(unw_cp)); |
94 |
+ |
95 |
+ if ((rc = unw_getcontext(&unw_ctx))) { |
96 |
+ fprintf(debug_log, "Failed to trace own stack: " |
97 |
+ "unw_context() said '%s'.\n", unw_strerror(rc)); |
98 |
+ break; |
99 |
+ } |
100 |
+ if ((rc = unw_init_local(&unw_cp, &unw_ctx))) { |
101 |
+ fprintf(debug_log, "Failed to trace own stack: " |
102 |
+ "unw_init_local() said '%s'.\n", unw_strerror(rc)); |
103 |
+ break; |
104 |
+ } |
105 |
+ frame = 0; |
106 |
+ fprintf(debug_log, "Backtrace follows (deepest frame first):\n"); |
107 |
+ while ((rc = unw_step(&unw_cp)) > 0) { |
108 |
+ frame++; |
109 |
+ ip = 0; sp = 0; |
110 |
+ unw_get_reg(&unw_cp, UNW_REG_IP, &ip); |
111 |
+ unw_get_reg(&unw_cp, UNW_REG_SP, &sp); |
112 |
+ off = 0; |
113 |
+ rc = unw_get_proc_name(&unw_cp, procname, sizeof(procname), &off); |
114 |
+ if (rc) |
115 |
+ snprintf (procname, sizeof(procname), "[unknown]"); |
116 |
+ fprintf(debug_log, "#%zd: %s + 0x%zx, ip = 0x%zx, sp = 0x%zx\n", |
117 |
+ frame, procname, (size_t)off, (size_t)ip, (size_t)sp); |
118 |
+ } |
119 |
+ fprintf(debug_log, "Use addr2line of similar to translate offsets to line information.\n"); |
120 |
+ } while (0); |
121 |
+#endif /* __FreeBSD__ */ |
122 |
#endif /* PRINT_STACK_TRACE */ |
123 |
|
124 |
#if SA_RESETHAND == 0 && !_SQUID_WINDOWS_ |