njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Assertions and panics. m_libcassert.c ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
sewardj | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame^] | 10 | Copyright (C) 2000-2013 Julian Seward |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 31 | #include "pub_core_basics.h" |
sewardj | 4cfea4f | 2006-10-14 19:26:10 +0000 | [diff] [blame] | 32 | #include "pub_core_vki.h" |
sewardj | 745fc45 | 2006-10-17 02:03:11 +0000 | [diff] [blame] | 33 | #include "pub_core_vkiscnums.h" |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 34 | #include "pub_core_libcsetjmp.h" // to keep threadstate.h happy |
njn | 49b45ba | 2005-07-20 02:41:31 +0000 | [diff] [blame] | 35 | #include "pub_core_threadstate.h" |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 36 | #include "pub_core_libcbase.h" |
| 37 | #include "pub_core_libcassert.h" |
| 38 | #include "pub_core_libcprint.h" |
njn | 49b45ba | 2005-07-20 02:41:31 +0000 | [diff] [blame] | 39 | #include "pub_core_libcproc.h" // For VG_(gettid)() |
| 40 | #include "pub_core_stacktrace.h" |
njn | 9abd608 | 2005-06-17 21:31:45 +0000 | [diff] [blame] | 41 | #include "pub_core_syscall.h" |
njn | e070c20 | 2005-06-20 23:58:15 +0000 | [diff] [blame] | 42 | #include "pub_core_tooliface.h" // For VG_(details).{name,bug_reports_to} |
sewardj | f349d55 | 2005-11-14 17:01:01 +0000 | [diff] [blame] | 43 | #include "pub_core_options.h" // For VG_(clo_xml) |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 44 | |
| 45 | /* --------------------------------------------------------------------- |
| 46 | Assertery. |
| 47 | ------------------------------------------------------------------ */ |
| 48 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 49 | #if defined(VGP_x86_linux) || defined(VGP_x86_darwin) |
| 50 | # define GET_STARTREGS(srP) \ |
| 51 | { UInt eip, esp, ebp; \ |
| 52 | __asm__ __volatile__( \ |
| 53 | "call 0f;" \ |
| 54 | "0: popl %0;" \ |
| 55 | "movl %%esp, %1;" \ |
| 56 | "movl %%ebp, %2;" \ |
| 57 | : "=r" (eip), "=r" (esp), "=r" (ebp) \ |
| 58 | : /* reads none */ \ |
| 59 | : "memory" \ |
| 60 | ); \ |
| 61 | (srP)->r_pc = (ULong)eip; \ |
| 62 | (srP)->r_sp = (ULong)esp; \ |
| 63 | (srP)->misc.X86.r_ebp = ebp; \ |
| 64 | } |
| 65 | #elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin) |
| 66 | # define GET_STARTREGS(srP) \ |
| 67 | { ULong rip, rsp, rbp; \ |
| 68 | __asm__ __volatile__( \ |
| 69 | "leaq 0(%%rip), %0;" \ |
| 70 | "movq %%rsp, %1;" \ |
| 71 | "movq %%rbp, %2;" \ |
| 72 | : "=r" (rip), "=r" (rsp), "=r" (rbp) \ |
| 73 | : /* reads none */ \ |
| 74 | : "memory" \ |
| 75 | ); \ |
| 76 | (srP)->r_pc = rip; \ |
| 77 | (srP)->r_sp = rsp; \ |
| 78 | (srP)->misc.AMD64.r_rbp = rbp; \ |
| 79 | } |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 80 | #elif defined(VGP_ppc32_linux) |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 81 | # define GET_STARTREGS(srP) \ |
| 82 | { UInt cia, r1, lr; \ |
| 83 | __asm__ __volatile__( \ |
| 84 | "mflr 0;" /* r0 = lr */ \ |
| 85 | "bl m_libcassert_get_ip;" /* lr = pc */ \ |
| 86 | "m_libcassert_get_ip:\n" \ |
| 87 | "mflr %0;" /* %0 = pc */ \ |
| 88 | "mtlr 0;" /* restore lr */ \ |
| 89 | "mr %1,1;" /* %1 = r1 */ \ |
| 90 | "mr %2,0;" /* %2 = lr */ \ |
| 91 | : "=r" (cia), "=r" (r1), "=r" (lr) \ |
| 92 | : /* reads none */ \ |
| 93 | : "r0" /* trashed */ \ |
| 94 | ); \ |
sewardj | f5f1e12 | 2010-01-02 13:24:58 +0000 | [diff] [blame] | 95 | (srP)->r_pc = (ULong)cia; \ |
| 96 | (srP)->r_sp = (ULong)r1; \ |
| 97 | (srP)->misc.PPC32.r_lr = lr; \ |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 98 | } |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 99 | #elif defined(VGP_ppc64_linux) |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 100 | # define GET_STARTREGS(srP) \ |
| 101 | { ULong cia, r1, lr; \ |
| 102 | __asm__ __volatile__( \ |
| 103 | "mflr 0;" /* r0 = lr */ \ |
| 104 | "bl .m_libcassert_get_ip;" /* lr = pc */ \ |
| 105 | ".m_libcassert_get_ip:\n" \ |
| 106 | "mflr %0;" /* %0 = pc */ \ |
| 107 | "mtlr 0;" /* restore lr */ \ |
| 108 | "mr %1,1;" /* %1 = r1 */ \ |
| 109 | "mr %2,0;" /* %2 = lr */ \ |
| 110 | : "=r" (cia), "=r" (r1), "=r" (lr) \ |
| 111 | : /* reads none */ \ |
| 112 | : "r0" /* trashed */ \ |
| 113 | ); \ |
sewardj | f5f1e12 | 2010-01-02 13:24:58 +0000 | [diff] [blame] | 114 | (srP)->r_pc = cia; \ |
| 115 | (srP)->r_sp = r1; \ |
| 116 | (srP)->misc.PPC64.r_lr = lr; \ |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 117 | } |
| 118 | #elif defined(VGP_arm_linux) |
| 119 | # define GET_STARTREGS(srP) \ |
sewardj | fa5ce56 | 2010-09-23 22:05:59 +0000 | [diff] [blame] | 120 | { UInt block[6]; \ |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 121 | __asm__ __volatile__( \ |
| 122 | "str r15, [%0, #+0];" \ |
| 123 | "str r14, [%0, #+4];" \ |
| 124 | "str r13, [%0, #+8];" \ |
| 125 | "str r12, [%0, #+12];" \ |
| 126 | "str r11, [%0, #+16];" \ |
sewardj | fa5ce56 | 2010-09-23 22:05:59 +0000 | [diff] [blame] | 127 | "str r7, [%0, #+20];" \ |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 128 | : /* out */ \ |
| 129 | : /* in */ "r"(&block[0]) \ |
| 130 | : /* trash */ "memory" \ |
| 131 | ); \ |
| 132 | (srP)->r_pc = block[0] - 8; \ |
| 133 | (srP)->r_sp = block[1]; \ |
| 134 | (srP)->misc.ARM.r14 = block[2]; \ |
| 135 | (srP)->misc.ARM.r12 = block[3]; \ |
| 136 | (srP)->misc.ARM.r11 = block[4]; \ |
sewardj | fa5ce56 | 2010-09-23 22:05:59 +0000 | [diff] [blame] | 137 | (srP)->misc.ARM.r7 = block[5]; \ |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 138 | } |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 139 | #elif defined(VGP_s390x_linux) |
| 140 | # define GET_STARTREGS(srP) \ |
| 141 | { ULong ia, sp, fp, lr; \ |
| 142 | __asm__ __volatile__( \ |
| 143 | "bras %0,0f;" \ |
| 144 | "0: lgr %1,15;" \ |
| 145 | "lgr %2,11;" \ |
| 146 | "lgr %3,14;" \ |
| 147 | : "=r" (ia), "=r" (sp),"=r" (fp),"=r" (lr) \ |
| 148 | /* no read & clobber */ \ |
| 149 | ); \ |
| 150 | (srP)->r_pc = ia; \ |
| 151 | (srP)->r_sp = sp; \ |
| 152 | (srP)->misc.S390X.r_fp = fp; \ |
| 153 | (srP)->misc.S390X.r_lr = lr; \ |
| 154 | } |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 155 | #elif defined(VGP_mips32_linux) |
| 156 | # define GET_STARTREGS(srP) \ |
| 157 | { UInt pc, sp, fp, ra, gp; \ |
| 158 | asm("move $8, $31;" /* t0 = ra */ \ |
| 159 | "bal m_libcassert_get_ip;" /* ra = pc */ \ |
| 160 | "m_libcassert_get_ip:\n" \ |
| 161 | "move %0, $31;" \ |
| 162 | "move $31, $8;" /* restore lr */ \ |
| 163 | "move %1, $29;" \ |
| 164 | "move %2, $30;" \ |
| 165 | "move %3, $31;" \ |
| 166 | "move %4, $28;" \ |
| 167 | : "=r" (pc), \ |
| 168 | "=r" (sp), \ |
| 169 | "=r" (fp), \ |
| 170 | "=r" (ra), \ |
| 171 | "=r" (gp) \ |
| 172 | : /* reads none */ \ |
| 173 | : "$8" /* trashed */ ); \ |
| 174 | (srP)->r_pc = (ULong)pc - 8; \ |
| 175 | (srP)->r_sp = (ULong)sp; \ |
| 176 | (srP)->misc.MIPS32.r30 = (ULong)fp; \ |
| 177 | (srP)->misc.MIPS32.r31 = (ULong)ra; \ |
| 178 | (srP)->misc.MIPS32.r28 = (ULong)gp; \ |
| 179 | } |
petarj | 4df0bfc | 2013-02-27 23:17:33 +0000 | [diff] [blame] | 180 | #elif defined(VGP_mips64_linux) |
| 181 | # define GET_STARTREGS(srP) \ |
| 182 | { ULong pc, sp, fp, ra, gp; \ |
| 183 | asm("move $8, $31;" /* t0 = ra */ \ |
| 184 | "bal m_libcassert_get_ip;" /* ra = pc */ \ |
| 185 | "m_libcassert_get_ip:\n" \ |
| 186 | "move %0, $31;" \ |
| 187 | "move $31, $8;" /* restore lr */ \ |
| 188 | "move %1, $29;" \ |
| 189 | "move %2, $30;" \ |
| 190 | "move %3, $31;" \ |
| 191 | "move %4, $28;" \ |
| 192 | : "=r" (pc), \ |
| 193 | "=r" (sp), \ |
| 194 | "=r" (fp), \ |
| 195 | "=r" (ra), \ |
| 196 | "=r" (gp) \ |
| 197 | : /* reads none */ \ |
| 198 | : "$8" /* trashed */ ); \ |
| 199 | (srP)->r_pc = (ULong)pc - 8; \ |
| 200 | (srP)->r_sp = (ULong)sp; \ |
| 201 | (srP)->misc.MIPS64.r30 = (ULong)fp; \ |
| 202 | (srP)->misc.MIPS64.r31 = (ULong)ra; \ |
| 203 | (srP)->misc.MIPS64.r28 = (ULong)gp; \ |
| 204 | } |
njn | 9450d24 | 2005-06-26 20:50:05 +0000 | [diff] [blame] | 205 | #else |
| 206 | # error Unknown platform |
| 207 | #endif |
| 208 | |
| 209 | #define BACKTRACE_DEPTH 100 // nice and deep! |
njn | 3161e80 | 2005-06-20 03:38:27 +0000 | [diff] [blame] | 210 | |
njn | f39e9a3 | 2005-06-12 02:43:17 +0000 | [diff] [blame] | 211 | /* Pull down the entire world */ |
| 212 | void VG_(exit)( Int status ) |
| 213 | { |
njn | 5b6b8fa | 2009-05-19 05:28:43 +0000 | [diff] [blame] | 214 | #if defined(VGO_linux) |
njn | f39e9a3 | 2005-06-12 02:43:17 +0000 | [diff] [blame] | 215 | (void)VG_(do_syscall1)(__NR_exit_group, status ); |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 216 | #elif defined(VGO_darwin) |
njn | f39e9a3 | 2005-06-12 02:43:17 +0000 | [diff] [blame] | 217 | (void)VG_(do_syscall1)(__NR_exit, status ); |
njn | 5b6b8fa | 2009-05-19 05:28:43 +0000 | [diff] [blame] | 218 | #else |
| 219 | # error Unknown OS |
| 220 | #endif |
njn | f39e9a3 | 2005-06-12 02:43:17 +0000 | [diff] [blame] | 221 | /*NOTREACHED*/ |
njn | 4eeb0e5 | 2009-06-09 22:46:32 +0000 | [diff] [blame] | 222 | // We really shouldn't reach here. Just in case we do, use some very crude |
| 223 | // methods to force abort |
| 224 | __builtin_trap(); |
| 225 | *(volatile Int*)0 = 'x'; |
njn | f39e9a3 | 2005-06-12 02:43:17 +0000 | [diff] [blame] | 226 | } |
| 227 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 228 | // Print the scheduler status. |
sewardj | 745fc45 | 2006-10-17 02:03:11 +0000 | [diff] [blame] | 229 | void VG_(show_sched_status) ( void ) |
njn | 49b45ba | 2005-07-20 02:41:31 +0000 | [diff] [blame] | 230 | { |
| 231 | Int i; |
| 232 | VG_(printf)("\nsched status:\n"); |
| 233 | VG_(printf)(" running_tid=%d\n", VG_(get_running_tid)()); |
| 234 | for (i = 1; i < VG_N_THREADS; i++) { |
| 235 | if (VG_(threads)[i].status == VgTs_Empty) continue; |
| 236 | VG_(printf)( "\nThread %d: status = %s\n", i, |
| 237 | VG_(name_of_ThreadStatus)(VG_(threads)[i].status) ); |
| 238 | VG_(get_and_pp_StackTrace)( i, BACKTRACE_DEPTH ); |
| 239 | } |
| 240 | VG_(printf)("\n"); |
| 241 | } |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 242 | |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 243 | __attribute__ ((noreturn)) |
florian | bbd9a21 | 2012-10-14 00:16:28 +0000 | [diff] [blame] | 244 | static void report_and_quit ( const HChar* report, |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 245 | UnwindStartRegs* startRegsIN ) |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 246 | { |
njn | 49b45ba | 2005-07-20 02:41:31 +0000 | [diff] [blame] | 247 | Addr stacktop; |
| 248 | Addr ips[BACKTRACE_DEPTH]; |
njn | 5f5ef2a | 2009-05-11 08:01:09 +0000 | [diff] [blame] | 249 | Int n_ips; |
sewardj | 4278172 | 2006-12-17 19:36:06 +0000 | [diff] [blame] | 250 | ThreadState *tst |
| 251 | = VG_(get_ThreadState)( VG_(lwpid_to_vgtid)( VG_(gettid)() ) ); |
njn | 49b45ba | 2005-07-20 02:41:31 +0000 | [diff] [blame] | 252 | |
| 253 | // If necessary, fake up an ExeContext which is of our actual real CPU |
| 254 | // state. Could cause problems if we got the panic/exception within the |
| 255 | // execontext/stack dump/symtab code. But it's better than nothing. |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 256 | UnwindStartRegs startRegs; |
| 257 | VG_(memset)(&startRegs, 0, sizeof(startRegs)); |
| 258 | |
| 259 | if (startRegsIN == NULL) { |
| 260 | GET_STARTREGS(&startRegs); |
| 261 | } else { |
| 262 | startRegs = *startRegsIN; |
njn | 49b45ba | 2005-07-20 02:41:31 +0000 | [diff] [blame] | 263 | } |
| 264 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 265 | stacktop = tst->os_state.valgrind_stack_init_SP; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 266 | |
| 267 | n_ips = |
njn | 5f5ef2a | 2009-05-11 08:01:09 +0000 | [diff] [blame] | 268 | VG_(get_StackTrace_wrk)( |
| 269 | 0/*tid is unknown*/, |
| 270 | ips, BACKTRACE_DEPTH, |
| 271 | NULL/*array to dump SP values in*/, |
| 272 | NULL/*array to dump FP values in*/, |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 273 | &startRegs, stacktop |
njn | 5f5ef2a | 2009-05-11 08:01:09 +0000 | [diff] [blame] | 274 | ); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 275 | VG_(clo_xml) = False; |
njn | 5f5ef2a | 2009-05-11 08:01:09 +0000 | [diff] [blame] | 276 | VG_(pp_StackTrace) (ips, n_ips); |
njn | 49b45ba | 2005-07-20 02:41:31 +0000 | [diff] [blame] | 277 | |
sewardj | 745fc45 | 2006-10-17 02:03:11 +0000 | [diff] [blame] | 278 | VG_(show_sched_status)(); |
njn | b8329f0 | 2009-04-16 00:33:20 +0000 | [diff] [blame] | 279 | VG_(printf)( |
| 280 | "\n" |
| 281 | "Note: see also the FAQ in the source distribution.\n" |
| 282 | "It contains workarounds to several common problems.\n" |
| 283 | "In particular, if Valgrind aborted or crashed after\n" |
| 284 | "identifying problems in your program, there's a good chance\n" |
| 285 | "that fixing those problems will prevent Valgrind aborting or\n" |
| 286 | "crashing, especially if it happened in m_mallocfree.c.\n" |
| 287 | "\n" |
| 288 | "If that doesn't help, please report this bug to: %s\n\n" |
| 289 | "In the bug report, send all the above text, the valgrind\n" |
| 290 | "version, and what OS and version you are using. Thanks.\n\n", |
| 291 | report); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 292 | VG_(exit)(1); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 293 | } |
| 294 | |
florian | bbd9a21 | 2012-10-14 00:16:28 +0000 | [diff] [blame] | 295 | void VG_(assert_fail) ( Bool isCore, const HChar* expr, const HChar* file, |
| 296 | Int line, const HChar* fn, const HChar* format, ... ) |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 297 | { |
| 298 | va_list vargs; |
florian | 5869ded | 2013-01-29 04:25:45 +0000 | [diff] [blame] | 299 | HChar buf[512]; |
florian | bbd9a21 | 2012-10-14 00:16:28 +0000 | [diff] [blame] | 300 | const HChar* component; |
| 301 | const HChar* bugs_to; |
florian | 5869ded | 2013-01-29 04:25:45 +0000 | [diff] [blame] | 302 | UInt written; |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 303 | |
| 304 | static Bool entered = False; |
| 305 | if (entered) |
sewardj | 745fc45 | 2006-10-17 02:03:11 +0000 | [diff] [blame] | 306 | VG_(exit)(2); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 307 | entered = True; |
| 308 | |
| 309 | va_start(vargs, format); |
florian | 5869ded | 2013-01-29 04:25:45 +0000 | [diff] [blame] | 310 | written = VG_(vsnprintf) ( buf, sizeof(buf), format, vargs ); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 311 | va_end(vargs); |
| 312 | |
florian | 5869ded | 2013-01-29 04:25:45 +0000 | [diff] [blame] | 313 | if (written >= sizeof(buf)) { |
| 314 | VG_(printf)("\nvalgrind: %s: buf is too small, sizeof(buf) = %u, " |
| 315 | "written = %d\n", __func__, (unsigned)sizeof(buf), written); |
| 316 | } |
| 317 | |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 318 | if (isCore) { |
| 319 | component = "valgrind"; |
| 320 | bugs_to = VG_BUGS_TO; |
| 321 | } else { |
| 322 | component = VG_(details).name; |
| 323 | bugs_to = VG_(details).bug_reports_to; |
| 324 | } |
| 325 | |
sewardj | f349d55 | 2005-11-14 17:01:01 +0000 | [diff] [blame] | 326 | if (VG_(clo_xml)) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 327 | VG_(printf_xml)("</valgrindoutput>\n"); |
sewardj | f349d55 | 2005-11-14 17:01:01 +0000 | [diff] [blame] | 328 | |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 329 | // Treat vg_assert2(0, "foo") specially, as a panicky abort |
| 330 | if (VG_STREQ(expr, "0")) { |
| 331 | VG_(printf)("\n%s: %s:%d (%s): the 'impossible' happened.\n", |
njn | 8a7b41b | 2007-09-23 00:51:24 +0000 | [diff] [blame] | 332 | component, file, line, fn ); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 333 | } else { |
| 334 | VG_(printf)("\n%s: %s:%d (%s): Assertion '%s' failed.\n", |
| 335 | component, file, line, fn, expr ); |
| 336 | } |
| 337 | if (!VG_STREQ(buf, "")) |
| 338 | VG_(printf)("%s: %s\n", component, buf ); |
| 339 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 340 | report_and_quit(bugs_to, NULL); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | __attribute__ ((noreturn)) |
florian | bbd9a21 | 2012-10-14 00:16:28 +0000 | [diff] [blame] | 344 | static void panic ( const HChar* name, const HChar* report, const HChar* str, |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 345 | UnwindStartRegs* startRegs ) |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 346 | { |
sewardj | f349d55 | 2005-11-14 17:01:01 +0000 | [diff] [blame] | 347 | if (VG_(clo_xml)) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 348 | VG_(printf_xml)("</valgrindoutput>\n"); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 349 | VG_(printf)("\n%s: the 'impossible' happened:\n %s\n", name, str); |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 350 | report_and_quit(report, startRegs); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 351 | } |
| 352 | |
florian | bbd9a21 | 2012-10-14 00:16:28 +0000 | [diff] [blame] | 353 | void VG_(core_panic_at) ( const HChar* str, UnwindStartRegs* startRegs ) |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 354 | { |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 355 | panic("valgrind", VG_BUGS_TO, str, startRegs); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 356 | } |
| 357 | |
florian | bbd9a21 | 2012-10-14 00:16:28 +0000 | [diff] [blame] | 358 | void VG_(core_panic) ( const HChar* str ) |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 359 | { |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 360 | VG_(core_panic_at)(str, NULL); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 361 | } |
| 362 | |
florian | bbd9a21 | 2012-10-14 00:16:28 +0000 | [diff] [blame] | 363 | void VG_(tool_panic) ( const HChar* str ) |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 364 | { |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 365 | panic(VG_(details).name, VG_(details).bug_reports_to, str, NULL); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 366 | } |
| 367 | |
njn | 49b45ba | 2005-07-20 02:41:31 +0000 | [diff] [blame] | 368 | /* Print some helpful-ish text about unimplemented things, and give up. */ |
florian | bbd9a21 | 2012-10-14 00:16:28 +0000 | [diff] [blame] | 369 | void VG_(unimplemented) ( const HChar* msg ) |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 370 | { |
sewardj | f349d55 | 2005-11-14 17:01:01 +0000 | [diff] [blame] | 371 | if (VG_(clo_xml)) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 372 | VG_(printf_xml)("</valgrindoutput>\n"); |
| 373 | VG_(umsg)("\n"); |
| 374 | VG_(umsg)("Valgrind detected that your program requires\n"); |
| 375 | VG_(umsg)("the following unimplemented functionality:\n"); |
| 376 | VG_(umsg)(" %s\n", msg); |
| 377 | VG_(umsg)("This may be because the functionality is hard to implement,\n"); |
| 378 | VG_(umsg)("or because no reasonable program would behave this way,\n"); |
| 379 | VG_(umsg)("or because nobody has yet needed it. " |
| 380 | "In any case, let us know at\n"); |
| 381 | VG_(umsg)("%s and/or try to work around the problem, if you can.\n", |
| 382 | VG_BUGS_TO); |
| 383 | VG_(umsg)("\n"); |
| 384 | VG_(umsg)("Valgrind has to exit now. Sorry. Bye!\n"); |
| 385 | VG_(umsg)("\n"); |
sewardj | 745fc45 | 2006-10-17 02:03:11 +0000 | [diff] [blame] | 386 | VG_(show_sched_status)(); |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 387 | VG_(exit)(1); |
| 388 | } |
| 389 | |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 390 | /*--------------------------------------------------------------------*/ |
| 391 | /*--- end ---*/ |
| 392 | /*--------------------------------------------------------------------*/ |