1132bfccd21960e462352175f8553a5bdce8a210cnjn
2132bfccd21960e462352175f8553a5bdce8a210cnjn/*--------------------------------------------------------------------*/
3132bfccd21960e462352175f8553a5bdce8a210cnjn/*--- Assertions and panics.                        m_libcassert.c ---*/
4132bfccd21960e462352175f8553a5bdce8a210cnjn/*--------------------------------------------------------------------*/
5132bfccd21960e462352175f8553a5bdce8a210cnjn
6132bfccd21960e462352175f8553a5bdce8a210cnjn/*
7132bfccd21960e462352175f8553a5bdce8a210cnjn   This file is part of Valgrind, a dynamic binary instrumentation
8132bfccd21960e462352175f8553a5bdce8a210cnjn   framework.
9132bfccd21960e462352175f8553a5bdce8a210cnjn
100f157ddb404bcde7815a1c5bf2d7e41c114f3d73sewardj   Copyright (C) 2000-2013 Julian Seward
11132bfccd21960e462352175f8553a5bdce8a210cnjn      jseward@acm.org
12132bfccd21960e462352175f8553a5bdce8a210cnjn
13132bfccd21960e462352175f8553a5bdce8a210cnjn   This program is free software; you can redistribute it and/or
14132bfccd21960e462352175f8553a5bdce8a210cnjn   modify it under the terms of the GNU General Public License as
15132bfccd21960e462352175f8553a5bdce8a210cnjn   published by the Free Software Foundation; either version 2 of the
16132bfccd21960e462352175f8553a5bdce8a210cnjn   License, or (at your option) any later version.
17132bfccd21960e462352175f8553a5bdce8a210cnjn
18132bfccd21960e462352175f8553a5bdce8a210cnjn   This program is distributed in the hope that it will be useful, but
19132bfccd21960e462352175f8553a5bdce8a210cnjn   WITHOUT ANY WARRANTY; without even the implied warranty of
20132bfccd21960e462352175f8553a5bdce8a210cnjn   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21132bfccd21960e462352175f8553a5bdce8a210cnjn   General Public License for more details.
22132bfccd21960e462352175f8553a5bdce8a210cnjn
23132bfccd21960e462352175f8553a5bdce8a210cnjn   You should have received a copy of the GNU General Public License
24132bfccd21960e462352175f8553a5bdce8a210cnjn   along with this program; if not, write to the Free Software
25132bfccd21960e462352175f8553a5bdce8a210cnjn   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26132bfccd21960e462352175f8553a5bdce8a210cnjn   02111-1307, USA.
27132bfccd21960e462352175f8553a5bdce8a210cnjn
28132bfccd21960e462352175f8553a5bdce8a210cnjn   The GNU General Public License is contained in the file COPYING.
29132bfccd21960e462352175f8553a5bdce8a210cnjn*/
30132bfccd21960e462352175f8553a5bdce8a210cnjn
31c7561b931e249acf3768ead77638545b0ccaa8f1njn#include "pub_core_basics.h"
324cfea4f9480393ed6799db463b2e0fb8865a1a2fsewardj#include "pub_core_vki.h"
33745fc459ce4ce9264d8844bf1ab695d235a4ce01sewardj#include "pub_core_vkiscnums.h"
3449b45ba90382fd313e40555559f5f5aaa23033b4njn#include "pub_core_threadstate.h"
35180a7500bf2464d5b16cddb5618b91fb3f095998philippe#include "pub_core_gdbserver.h"
364f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe#include "pub_core_aspacemgr.h"
37132bfccd21960e462352175f8553a5bdce8a210cnjn#include "pub_core_libcbase.h"
38132bfccd21960e462352175f8553a5bdce8a210cnjn#include "pub_core_libcassert.h"
39132bfccd21960e462352175f8553a5bdce8a210cnjn#include "pub_core_libcprint.h"
4049b45ba90382fd313e40555559f5f5aaa23033b4njn#include "pub_core_libcproc.h"      // For VG_(gettid)()
4138a74d2cc4670e3eb559adff51a376cd6ec98005philippe#include "pub_core_machine.h"
4238a74d2cc4670e3eb559adff51a376cd6ec98005philippe#include "pub_core_stacks.h"
4349b45ba90382fd313e40555559f5f5aaa23033b4njn#include "pub_core_stacktrace.h"
449abd608244d8123868d027f616fa928156615d5anjn#include "pub_core_syscall.h"
45e070c20d9f3e651f478bba6bdb6fc34aa1f9514dnjn#include "pub_core_tooliface.h"     // For VG_(details).{name,bug_reports_to}
46f349d55d40891b890d0da268cfb9f092af0fc8f4sewardj#include "pub_core_options.h"       // For VG_(clo_xml)
47132bfccd21960e462352175f8553a5bdce8a210cnjn
48132bfccd21960e462352175f8553a5bdce8a210cnjn/* ---------------------------------------------------------------------
49132bfccd21960e462352175f8553a5bdce8a210cnjn   Assertery.
50132bfccd21960e462352175f8553a5bdce8a210cnjn   ------------------------------------------------------------------ */
51132bfccd21960e462352175f8553a5bdce8a210cnjn
5259570ffbe31930ab4d678754daaeec0715117a3dsewardj#if defined(VGP_x86_linux) || defined(VGP_x86_darwin)
5359570ffbe31930ab4d678754daaeec0715117a3dsewardj#  define GET_STARTREGS(srP)                              \
5459570ffbe31930ab4d678754daaeec0715117a3dsewardj      { UInt eip, esp, ebp;                               \
5559570ffbe31930ab4d678754daaeec0715117a3dsewardj        __asm__ __volatile__(                             \
5659570ffbe31930ab4d678754daaeec0715117a3dsewardj           "call 0f;"                                     \
5759570ffbe31930ab4d678754daaeec0715117a3dsewardj           "0: popl %0;"                                  \
5859570ffbe31930ab4d678754daaeec0715117a3dsewardj           "movl %%esp, %1;"                              \
5959570ffbe31930ab4d678754daaeec0715117a3dsewardj           "movl %%ebp, %2;"                              \
6059570ffbe31930ab4d678754daaeec0715117a3dsewardj           : "=r" (eip), "=r" (esp), "=r" (ebp)           \
6159570ffbe31930ab4d678754daaeec0715117a3dsewardj           : /* reads none */                             \
6259570ffbe31930ab4d678754daaeec0715117a3dsewardj           : "memory"                                     \
6359570ffbe31930ab4d678754daaeec0715117a3dsewardj        );                                                \
6459570ffbe31930ab4d678754daaeec0715117a3dsewardj        (srP)->r_pc = (ULong)eip;                         \
6559570ffbe31930ab4d678754daaeec0715117a3dsewardj        (srP)->r_sp = (ULong)esp;                         \
6659570ffbe31930ab4d678754daaeec0715117a3dsewardj        (srP)->misc.X86.r_ebp = ebp;                      \
6759570ffbe31930ab4d678754daaeec0715117a3dsewardj      }
6859570ffbe31930ab4d678754daaeec0715117a3dsewardj#elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin)
6959570ffbe31930ab4d678754daaeec0715117a3dsewardj#  define GET_STARTREGS(srP)                              \
7059570ffbe31930ab4d678754daaeec0715117a3dsewardj      { ULong rip, rsp, rbp;                              \
7159570ffbe31930ab4d678754daaeec0715117a3dsewardj        __asm__ __volatile__(                             \
7259570ffbe31930ab4d678754daaeec0715117a3dsewardj           "leaq 0(%%rip), %0;"                           \
7359570ffbe31930ab4d678754daaeec0715117a3dsewardj           "movq %%rsp, %1;"                              \
7459570ffbe31930ab4d678754daaeec0715117a3dsewardj           "movq %%rbp, %2;"                              \
7559570ffbe31930ab4d678754daaeec0715117a3dsewardj           : "=r" (rip), "=r" (rsp), "=r" (rbp)           \
7659570ffbe31930ab4d678754daaeec0715117a3dsewardj           : /* reads none */                             \
7759570ffbe31930ab4d678754daaeec0715117a3dsewardj           : "memory"                                     \
7859570ffbe31930ab4d678754daaeec0715117a3dsewardj        );                                                \
7959570ffbe31930ab4d678754daaeec0715117a3dsewardj        (srP)->r_pc = rip;                                \
8059570ffbe31930ab4d678754daaeec0715117a3dsewardj        (srP)->r_sp = rsp;                                \
8159570ffbe31930ab4d678754daaeec0715117a3dsewardj        (srP)->misc.AMD64.r_rbp = rbp;                    \
8259570ffbe31930ab4d678754daaeec0715117a3dsewardj      }
836e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj#elif defined(VGP_ppc32_linux)
8459570ffbe31930ab4d678754daaeec0715117a3dsewardj#  define GET_STARTREGS(srP)                              \
8559570ffbe31930ab4d678754daaeec0715117a3dsewardj      { UInt cia, r1, lr;                                 \
8659570ffbe31930ab4d678754daaeec0715117a3dsewardj        __asm__ __volatile__(                             \
8759570ffbe31930ab4d678754daaeec0715117a3dsewardj           "mflr 0;"                   /* r0 = lr */      \
8859570ffbe31930ab4d678754daaeec0715117a3dsewardj           "bl m_libcassert_get_ip;"   /* lr = pc */      \
8959570ffbe31930ab4d678754daaeec0715117a3dsewardj           "m_libcassert_get_ip:\n"                       \
9059570ffbe31930ab4d678754daaeec0715117a3dsewardj           "mflr %0;"                  /* %0 = pc */      \
9159570ffbe31930ab4d678754daaeec0715117a3dsewardj           "mtlr 0;"                   /* restore lr */   \
9259570ffbe31930ab4d678754daaeec0715117a3dsewardj           "mr %1,1;"                  /* %1 = r1 */      \
9359570ffbe31930ab4d678754daaeec0715117a3dsewardj           "mr %2,0;"                  /* %2 = lr */      \
9459570ffbe31930ab4d678754daaeec0715117a3dsewardj           : "=r" (cia), "=r" (r1), "=r" (lr)             \
9559570ffbe31930ab4d678754daaeec0715117a3dsewardj           : /* reads none */                             \
9659570ffbe31930ab4d678754daaeec0715117a3dsewardj           : "r0" /* trashed */                           \
9759570ffbe31930ab4d678754daaeec0715117a3dsewardj        );                                                \
98f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj        (srP)->r_pc = (ULong)cia;                         \
99f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj        (srP)->r_sp = (ULong)r1;                          \
100f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj        (srP)->misc.PPC32.r_lr = lr;                      \
10159570ffbe31930ab4d678754daaeec0715117a3dsewardj      }
102cae0cc22b83ffb260ee8379e92099c5a701944cbcarll#elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
10359570ffbe31930ab4d678754daaeec0715117a3dsewardj#  define GET_STARTREGS(srP)                              \
10459570ffbe31930ab4d678754daaeec0715117a3dsewardj      { ULong cia, r1, lr;                                \
10559570ffbe31930ab4d678754daaeec0715117a3dsewardj        __asm__ __volatile__(                             \
10659570ffbe31930ab4d678754daaeec0715117a3dsewardj           "mflr 0;"                   /* r0 = lr */      \
10759570ffbe31930ab4d678754daaeec0715117a3dsewardj           "bl .m_libcassert_get_ip;"  /* lr = pc */      \
10859570ffbe31930ab4d678754daaeec0715117a3dsewardj           ".m_libcassert_get_ip:\n"                      \
10959570ffbe31930ab4d678754daaeec0715117a3dsewardj           "mflr %0;"                  /* %0 = pc */      \
11059570ffbe31930ab4d678754daaeec0715117a3dsewardj           "mtlr 0;"                   /* restore lr */   \
11159570ffbe31930ab4d678754daaeec0715117a3dsewardj           "mr %1,1;"                  /* %1 = r1 */      \
11259570ffbe31930ab4d678754daaeec0715117a3dsewardj           "mr %2,0;"                  /* %2 = lr */      \
11359570ffbe31930ab4d678754daaeec0715117a3dsewardj           : "=r" (cia), "=r" (r1), "=r" (lr)             \
11459570ffbe31930ab4d678754daaeec0715117a3dsewardj           : /* reads none */                             \
11559570ffbe31930ab4d678754daaeec0715117a3dsewardj           : "r0" /* trashed */                           \
11659570ffbe31930ab4d678754daaeec0715117a3dsewardj        );                                                \
117f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj        (srP)->r_pc = cia;                                \
118f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj        (srP)->r_sp = r1;                                 \
119f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj        (srP)->misc.PPC64.r_lr = lr;                      \
12059570ffbe31930ab4d678754daaeec0715117a3dsewardj      }
12159570ffbe31930ab4d678754daaeec0715117a3dsewardj#elif defined(VGP_arm_linux)
12259570ffbe31930ab4d678754daaeec0715117a3dsewardj#  define GET_STARTREGS(srP)                              \
123fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj      { UInt block[6];                                    \
12459570ffbe31930ab4d678754daaeec0715117a3dsewardj        __asm__ __volatile__(                             \
12559570ffbe31930ab4d678754daaeec0715117a3dsewardj           "str r15, [%0, #+0];"                          \
12659570ffbe31930ab4d678754daaeec0715117a3dsewardj           "str r14, [%0, #+4];"                          \
12759570ffbe31930ab4d678754daaeec0715117a3dsewardj           "str r13, [%0, #+8];"                          \
12859570ffbe31930ab4d678754daaeec0715117a3dsewardj           "str r12, [%0, #+12];"                         \
12959570ffbe31930ab4d678754daaeec0715117a3dsewardj           "str r11, [%0, #+16];"                         \
130fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj           "str r7,  [%0, #+20];"                         \
13159570ffbe31930ab4d678754daaeec0715117a3dsewardj           : /* out */                                    \
13259570ffbe31930ab4d678754daaeec0715117a3dsewardj           : /* in */ "r"(&block[0])                      \
13359570ffbe31930ab4d678754daaeec0715117a3dsewardj           : /* trash */ "memory"                         \
13459570ffbe31930ab4d678754daaeec0715117a3dsewardj        );                                                \
13559570ffbe31930ab4d678754daaeec0715117a3dsewardj        (srP)->r_pc = block[0] - 8;                       \
136d474ab25fa26da6adf1f1fd4199379887eb377f6sewardj        (srP)->misc.ARM.r14 = block[1];                   \
137d474ab25fa26da6adf1f1fd4199379887eb377f6sewardj        (srP)->r_sp = block[2];                           \
13859570ffbe31930ab4d678754daaeec0715117a3dsewardj        (srP)->misc.ARM.r12 = block[3];                   \
13959570ffbe31930ab4d678754daaeec0715117a3dsewardj        (srP)->misc.ARM.r11 = block[4];                   \
140fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj        (srP)->misc.ARM.r7  = block[5];                   \
14159570ffbe31930ab4d678754daaeec0715117a3dsewardj      }
142f0c1250e324f6684757c6a15545366447ef1d64fsewardj#elif defined(VGP_arm64_linux)
143f0c1250e324f6684757c6a15545366447ef1d64fsewardj#  define GET_STARTREGS(srP)                              \
144f0c1250e324f6684757c6a15545366447ef1d64fsewardj      { ULong block[4];                                   \
145f0c1250e324f6684757c6a15545366447ef1d64fsewardj        __asm__ __volatile__(                             \
146f0c1250e324f6684757c6a15545366447ef1d64fsewardj           "adr x19, 0;"                                  \
147f0c1250e324f6684757c6a15545366447ef1d64fsewardj           "str x19, [%0, #+0];"   /* pc */               \
148f0c1250e324f6684757c6a15545366447ef1d64fsewardj           "mov x19, sp;"                                 \
149f0c1250e324f6684757c6a15545366447ef1d64fsewardj           "str x19, [%0, #+8];"   /* sp */               \
150f0c1250e324f6684757c6a15545366447ef1d64fsewardj           "str x29, [%0, #+16];"  /* fp */               \
151f0c1250e324f6684757c6a15545366447ef1d64fsewardj           "str x30, [%0, #+24];"  /* lr */               \
152f0c1250e324f6684757c6a15545366447ef1d64fsewardj           : /* out */                                    \
153f0c1250e324f6684757c6a15545366447ef1d64fsewardj           : /* in */ "r"(&block[0])                      \
154f0c1250e324f6684757c6a15545366447ef1d64fsewardj           : /* trash */ "memory","x19"                   \
155f0c1250e324f6684757c6a15545366447ef1d64fsewardj        );                                                \
156f0c1250e324f6684757c6a15545366447ef1d64fsewardj        (srP)->r_pc = block[0];                           \
157f0c1250e324f6684757c6a15545366447ef1d64fsewardj        (srP)->r_sp = block[1];                           \
158f0c1250e324f6684757c6a15545366447ef1d64fsewardj        (srP)->misc.ARM64.x29 = block[2];                 \
159f0c1250e324f6684757c6a15545366447ef1d64fsewardj        (srP)->misc.ARM64.x30 = block[3];                 \
160f0c1250e324f6684757c6a15545366447ef1d64fsewardj      }
161b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj#elif defined(VGP_s390x_linux)
162b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj#  define GET_STARTREGS(srP)                              \
163b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      { ULong ia, sp, fp, lr;                             \
164b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj        __asm__ __volatile__(                             \
165b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj           "bras %0,0f;"                                  \
166b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj           "0: lgr %1,15;"                                \
167b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj           "lgr %2,11;"                                   \
168b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj           "lgr %3,14;"                                   \
169b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj           : "=r" (ia), "=r" (sp),"=r" (fp),"=r" (lr)     \
170b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj           /* no read & clobber */                        \
171b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj        );                                                \
172b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj        (srP)->r_pc = ia;                                 \
173b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj        (srP)->r_sp = sp;                                 \
174b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj        (srP)->misc.S390X.r_fp = fp;                      \
175b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj        (srP)->misc.S390X.r_lr = lr;                      \
176b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      }
1775db15403e889d4db339b342bc2a824ef0bfaa654sewardj#elif defined(VGP_mips32_linux)
1785db15403e889d4db339b342bc2a824ef0bfaa654sewardj#  define GET_STARTREGS(srP)                              \
1795db15403e889d4db339b342bc2a824ef0bfaa654sewardj      { UInt pc, sp, fp, ra, gp;                          \
1805db15403e889d4db339b342bc2a824ef0bfaa654sewardj      asm("move $8, $31;"             /* t0 = ra */       \
1815db15403e889d4db339b342bc2a824ef0bfaa654sewardj          "bal m_libcassert_get_ip;"  /* ra = pc */       \
1825db15403e889d4db339b342bc2a824ef0bfaa654sewardj          "m_libcassert_get_ip:\n"                        \
1835db15403e889d4db339b342bc2a824ef0bfaa654sewardj          "move %0, $31;"                                 \
1845db15403e889d4db339b342bc2a824ef0bfaa654sewardj          "move $31, $8;"             /* restore lr */    \
1855db15403e889d4db339b342bc2a824ef0bfaa654sewardj          "move %1, $29;"                                 \
1865db15403e889d4db339b342bc2a824ef0bfaa654sewardj          "move %2, $30;"                                 \
1875db15403e889d4db339b342bc2a824ef0bfaa654sewardj          "move %3, $31;"                                 \
1885db15403e889d4db339b342bc2a824ef0bfaa654sewardj          "move %4, $28;"                                 \
1895db15403e889d4db339b342bc2a824ef0bfaa654sewardj          : "=r" (pc),                                    \
1905db15403e889d4db339b342bc2a824ef0bfaa654sewardj            "=r" (sp),                                    \
1915db15403e889d4db339b342bc2a824ef0bfaa654sewardj            "=r" (fp),                                    \
1925db15403e889d4db339b342bc2a824ef0bfaa654sewardj            "=r" (ra),                                    \
1935db15403e889d4db339b342bc2a824ef0bfaa654sewardj            "=r" (gp)                                     \
1945db15403e889d4db339b342bc2a824ef0bfaa654sewardj          : /* reads none */                              \
1955db15403e889d4db339b342bc2a824ef0bfaa654sewardj          : "$8" /* trashed */ );                         \
1965db15403e889d4db339b342bc2a824ef0bfaa654sewardj        (srP)->r_pc = (ULong)pc - 8;                      \
1975db15403e889d4db339b342bc2a824ef0bfaa654sewardj        (srP)->r_sp = (ULong)sp;                          \
1985db15403e889d4db339b342bc2a824ef0bfaa654sewardj        (srP)->misc.MIPS32.r30 = (ULong)fp;               \
1995db15403e889d4db339b342bc2a824ef0bfaa654sewardj        (srP)->misc.MIPS32.r31 = (ULong)ra;               \
2005db15403e889d4db339b342bc2a824ef0bfaa654sewardj        (srP)->misc.MIPS32.r28 = (ULong)gp;               \
2015db15403e889d4db339b342bc2a824ef0bfaa654sewardj      }
2024df0bfc0614379192c780c944415dc420d9cfe8epetarj#elif defined(VGP_mips64_linux)
2034df0bfc0614379192c780c944415dc420d9cfe8epetarj#  define GET_STARTREGS(srP)                              \
2044df0bfc0614379192c780c944415dc420d9cfe8epetarj      { ULong pc, sp, fp, ra, gp;                          \
2054df0bfc0614379192c780c944415dc420d9cfe8epetarj      asm("move $8, $31;"             /* t0 = ra */       \
2064df0bfc0614379192c780c944415dc420d9cfe8epetarj          "bal m_libcassert_get_ip;"  /* ra = pc */       \
2074df0bfc0614379192c780c944415dc420d9cfe8epetarj          "m_libcassert_get_ip:\n"                        \
2084df0bfc0614379192c780c944415dc420d9cfe8epetarj          "move %0, $31;"                                 \
2094df0bfc0614379192c780c944415dc420d9cfe8epetarj          "move $31, $8;"             /* restore lr */    \
2104df0bfc0614379192c780c944415dc420d9cfe8epetarj          "move %1, $29;"                                 \
2114df0bfc0614379192c780c944415dc420d9cfe8epetarj          "move %2, $30;"                                 \
2124df0bfc0614379192c780c944415dc420d9cfe8epetarj          "move %3, $31;"                                 \
2134df0bfc0614379192c780c944415dc420d9cfe8epetarj          "move %4, $28;"                                 \
2144df0bfc0614379192c780c944415dc420d9cfe8epetarj          : "=r" (pc),                                    \
2154df0bfc0614379192c780c944415dc420d9cfe8epetarj            "=r" (sp),                                    \
2164df0bfc0614379192c780c944415dc420d9cfe8epetarj            "=r" (fp),                                    \
2174df0bfc0614379192c780c944415dc420d9cfe8epetarj            "=r" (ra),                                    \
2184df0bfc0614379192c780c944415dc420d9cfe8epetarj            "=r" (gp)                                     \
2194df0bfc0614379192c780c944415dc420d9cfe8epetarj          : /* reads none */                              \
2204df0bfc0614379192c780c944415dc420d9cfe8epetarj          : "$8" /* trashed */ );                         \
2214df0bfc0614379192c780c944415dc420d9cfe8epetarj        (srP)->r_pc = (ULong)pc - 8;                      \
2224df0bfc0614379192c780c944415dc420d9cfe8epetarj        (srP)->r_sp = (ULong)sp;                          \
2234df0bfc0614379192c780c944415dc420d9cfe8epetarj        (srP)->misc.MIPS64.r30 = (ULong)fp;               \
2244df0bfc0614379192c780c944415dc420d9cfe8epetarj        (srP)->misc.MIPS64.r31 = (ULong)ra;               \
2254df0bfc0614379192c780c944415dc420d9cfe8epetarj        (srP)->misc.MIPS64.r28 = (ULong)gp;               \
2264df0bfc0614379192c780c944415dc420d9cfe8epetarj      }
227112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#elif defined(VGP_tilegx_linux)
228112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#  define GET_STARTREGS(srP)                              \
22962cee7a76f79da8ffd0c3d018e18699147391249zliu      { ULong pc, sp, fp, ra;                              \
230112711afefcfcd43680c7c4aa8d38ef180e8811esewardj        __asm__ __volatile__(                             \
231112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          "move r8, lr \n"                                \
232112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          "jal 0f \n"                                     \
233112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          "0:\n"                                          \
234112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          "move %0, lr \n"                                \
235112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          "move lr, r8 \n"      /* put old lr back*/      \
236112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          "move %1, sp \n"                                \
237112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          "move %2, r52 \n"                               \
238112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          "move %3, lr \n"                                \
239112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          : "=r" (pc),                                    \
240112711afefcfcd43680c7c4aa8d38ef180e8811esewardj            "=r" (sp),                                    \
241112711afefcfcd43680c7c4aa8d38ef180e8811esewardj            "=r" (fp),                                    \
242112711afefcfcd43680c7c4aa8d38ef180e8811esewardj            "=r" (ra)                                     \
243112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          : /* reads none */                              \
244112711afefcfcd43680c7c4aa8d38ef180e8811esewardj          : "%r8" /* trashed */ );                        \
245112711afefcfcd43680c7c4aa8d38ef180e8811esewardj        (srP)->r_pc = (ULong)pc - 8;                      \
246112711afefcfcd43680c7c4aa8d38ef180e8811esewardj        (srP)->r_sp = (ULong)sp;                          \
247112711afefcfcd43680c7c4aa8d38ef180e8811esewardj        (srP)->misc.TILEGX.r52 = (ULong)fp;               \
248112711afefcfcd43680c7c4aa8d38ef180e8811esewardj        (srP)->misc.TILEGX.r55 = (ULong)ra;               \
249112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      }
2509450d245afa7cd6e49f2734c2a621047df0d01ecnjn#else
2519450d245afa7cd6e49f2734c2a621047df0d01ecnjn#  error Unknown platform
2529450d245afa7cd6e49f2734c2a621047df0d01ecnjn#endif
2539450d245afa7cd6e49f2734c2a621047df0d01ecnjn
2549450d245afa7cd6e49f2734c2a621047df0d01ecnjn#define BACKTRACE_DEPTH    100         // nice and deep!
2553161e808ce76595c60447d041715a3ece1f9665dnjn
256180a7500bf2464d5b16cddb5618b91fb3f095998philippe__attribute__ ((__noreturn__))
257180a7500bf2464d5b16cddb5618b91fb3f095998philippestatic void exit_wrk( Int status, Bool gdbserver_call_allowed)
258f39e9a36dca9642668a66c6b054f81c88650bcb9njn{
259180a7500bf2464d5b16cddb5618b91fb3f095998philippe   static Bool exit_called = False;
260180a7500bf2464d5b16cddb5618b91fb3f095998philippe   // avoid recursive exit during gdbserver call.
261180a7500bf2464d5b16cddb5618b91fb3f095998philippe
262180a7500bf2464d5b16cddb5618b91fb3f095998philippe   if (gdbserver_call_allowed && !exit_called) {
263180a7500bf2464d5b16cddb5618b91fb3f095998philippe      const ThreadId atid = 1; // Arbitrary tid used to call/terminate gdbsrv.
264180a7500bf2464d5b16cddb5618b91fb3f095998philippe      exit_called = True;
265180a7500bf2464d5b16cddb5618b91fb3f095998philippe      if (status != 0 && VG_(gdbserver_stop_at) (VgdbStopAt_ValgrindAbExit)) {
266180a7500bf2464d5b16cddb5618b91fb3f095998philippe         if (VG_(gdbserver_init_done)()) {
267180a7500bf2464d5b16cddb5618b91fb3f095998philippe            VG_(umsg)("(action at valgrind abnormal exit) vgdb me ... \n");
268180a7500bf2464d5b16cddb5618b91fb3f095998philippe            VG_(gdbserver) (atid);
269180a7500bf2464d5b16cddb5618b91fb3f095998philippe         } else {
270180a7500bf2464d5b16cddb5618b91fb3f095998philippe            VG_(umsg)("(action at valgrind abnormal exit) "
271180a7500bf2464d5b16cddb5618b91fb3f095998philippe                      "Early valgrind exit : vgdb not yet usable\n");
272180a7500bf2464d5b16cddb5618b91fb3f095998philippe         }
273180a7500bf2464d5b16cddb5618b91fb3f095998philippe      }
274180a7500bf2464d5b16cddb5618b91fb3f095998philippe      if (VG_(gdbserver_init_done)()) {
275180a7500bf2464d5b16cddb5618b91fb3f095998philippe         // Always terminate the gdbserver when Valgrind exits, so as
276180a7500bf2464d5b16cddb5618b91fb3f095998philippe         // to e.g. cleanup the FIFOs.
277180a7500bf2464d5b16cddb5618b91fb3f095998philippe         VG_(gdbserver_exit) (atid,
278180a7500bf2464d5b16cddb5618b91fb3f095998philippe                              status == 0 ? VgSrc_ExitProcess : VgSrc_FatalSig);
279180a7500bf2464d5b16cddb5618b91fb3f095998philippe      }
280180a7500bf2464d5b16cddb5618b91fb3f095998philippe   }
281180a7500bf2464d5b16cddb5618b91fb3f095998philippe   exit_called = True;
282180a7500bf2464d5b16cddb5618b91fb3f095998philippe
283421c26e30de64ccf441ec398c1f8beda7afbb47cflorian   VG_(exit_now) (status);
284421c26e30de64ccf441ec398c1f8beda7afbb47cflorian}
285421c26e30de64ccf441ec398c1f8beda7afbb47cflorian
286421c26e30de64ccf441ec398c1f8beda7afbb47cflorian/* Call the appropriate system call and nothing else. This function should
287421c26e30de64ccf441ec398c1f8beda7afbb47cflorian   be called in places where the dependencies of VG_(exit) need to be
288421c26e30de64ccf441ec398c1f8beda7afbb47cflorian   avoided. */
289421c26e30de64ccf441ec398c1f8beda7afbb47cflorian__attribute__ ((__noreturn__))
290421c26e30de64ccf441ec398c1f8beda7afbb47cflorianvoid VG_(exit_now)( Int status )
291421c26e30de64ccf441ec398c1f8beda7afbb47cflorian{
2925b6b8faafbfa52635d444dd58b107d3a4081c86cnjn#if defined(VGO_linux)
293f39e9a36dca9642668a66c6b054f81c88650bcb9njn   (void)VG_(do_syscall1)(__NR_exit_group, status );
2946e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj#elif defined(VGO_darwin)
295f39e9a36dca9642668a66c6b054f81c88650bcb9njn   (void)VG_(do_syscall1)(__NR_exit, status );
2965b6b8faafbfa52635d444dd58b107d3a4081c86cnjn#else
2975b6b8faafbfa52635d444dd58b107d3a4081c86cnjn#  error Unknown OS
2985b6b8faafbfa52635d444dd58b107d3a4081c86cnjn#endif
299f39e9a36dca9642668a66c6b054f81c88650bcb9njn   /*NOTREACHED*/
3004eeb0e50fd10c08a396c6d3c53f296287a47d9c3njn   // We really shouldn't reach here.  Just in case we do, use some very crude
3014eeb0e50fd10c08a396c6d3c53f296287a47d9c3njn   // methods to force abort
3024eeb0e50fd10c08a396c6d3c53f296287a47d9c3njn   __builtin_trap();
3034eeb0e50fd10c08a396c6d3c53f296287a47d9c3njn   *(volatile Int*)0 = 'x';
304f39e9a36dca9642668a66c6b054f81c88650bcb9njn}
305f39e9a36dca9642668a66c6b054f81c88650bcb9njn
306180a7500bf2464d5b16cddb5618b91fb3f095998philippe/* Pull down the entire world */
307180a7500bf2464d5b16cddb5618b91fb3f095998philippevoid VG_(exit)( Int status )
308180a7500bf2464d5b16cddb5618b91fb3f095998philippe{
309180a7500bf2464d5b16cddb5618b91fb3f095998philippe   exit_wrk (status, True);
310180a7500bf2464d5b16cddb5618b91fb3f095998philippe}
311180a7500bf2464d5b16cddb5618b91fb3f095998philippe
312180a7500bf2464d5b16cddb5618b91fb3f095998philippe/* Pull down the entire world */
313180a7500bf2464d5b16cddb5618b91fb3f095998philippevoid VG_(client_exit)( Int status )
314180a7500bf2464d5b16cddb5618b91fb3f095998philippe{
315180a7500bf2464d5b16cddb5618b91fb3f095998philippe   exit_wrk (status, False);
316180a7500bf2464d5b16cddb5618b91fb3f095998philippe}
317180a7500bf2464d5b16cddb5618b91fb3f095998philippe
318180a7500bf2464d5b16cddb5618b91fb3f095998philippe
319c7561b931e249acf3768ead77638545b0ccaa8f1njn// Print the scheduler status.
3204f6f336badda2171d6e842cca3de63b53f4c9f0bphilippestatic void show_sched_status_wrk ( Bool host_stacktrace,
32138a74d2cc4670e3eb559adff51a376cd6ec98005philippe                                    Bool stack_usage,
3224f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe                                    Bool exited_threads,
323518850bf0da07ed3e2244e307268ae0fd80e93a8florian                                    const UnwindStartRegs* startRegsIN)
32449b45ba90382fd313e40555559f5f5aaa23033b4njn{
32549b45ba90382fd313e40555559f5f5aaa23033b4njn   Int i;
3264f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe   if (host_stacktrace) {
3274f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      const Bool save_clo_xml = VG_(clo_xml);
3284f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      Addr stacktop;
3294f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      Addr ips[BACKTRACE_DEPTH];
3304f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      Int  n_ips;
3314f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      ThreadState *tst
3324f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe         = VG_(get_ThreadState)( VG_(lwpid_to_vgtid)( VG_(gettid)() ) );
3334f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe
3344f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      // If necessary, fake up an ExeContext which is of our actual real CPU
3354f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      // state.  Could cause problems if we got the panic/exception within the
3364f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      // execontext/stack dump/symtab code.  But it's better than nothing.
3374f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      UnwindStartRegs startRegs;
3384f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      VG_(memset)(&startRegs, 0, sizeof(startRegs));
3394f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe
3404f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      if (startRegsIN == NULL) {
3414f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe         GET_STARTREGS(&startRegs);
3424f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      } else {
3434f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe         startRegs = *startRegsIN;
3444f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      }
3454f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe
3464f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      stacktop = tst->os_state.valgrind_stack_init_SP;
3474f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe
3484f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      n_ips =
3494f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe         VG_(get_StackTrace_wrk)(
3504f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe            0/*tid is unknown*/,
3514f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe            ips, BACKTRACE_DEPTH,
3524f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe            NULL/*array to dump SP values in*/,
3534f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe            NULL/*array to dump FP values in*/,
3544f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe            &startRegs, stacktop
3554f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe         );
3564f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      VG_(printf)("\nhost stacktrace:\n");
3574f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      VG_(clo_xml) = False;
3584f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      VG_(pp_StackTrace) (ips, n_ips);
3594f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      VG_(clo_xml) = save_clo_xml;
3604f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe   }
3614f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe
36249b45ba90382fd313e40555559f5f5aaa23033b4njn   VG_(printf)("\nsched status:\n");
36349b45ba90382fd313e40555559f5f5aaa23033b4njn   VG_(printf)("  running_tid=%d\n", VG_(get_running_tid)());
36449b45ba90382fd313e40555559f5f5aaa23033b4njn   for (i = 1; i < VG_N_THREADS; i++) {
3654f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      VgStack* stack
3664f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe         = (VgStack*)VG_(threads)[i].os_state.valgrind_stack_base;
3674f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      /* If a thread slot was never used (yet), valgrind_stack_base is 0.
3684f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe         If a thread slot is used by a thread or was used by a thread which
3694f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe         has exited, then valgrind_stack_base points to the stack base. */
3704f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      if (VG_(threads)[i].status == VgTs_Empty
3714f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe          && (!exited_threads || stack == 0)) continue;
372026fe8634d7a56b101bb8e43a6666b2f0d00d38dphilippe      VG_(printf)("\nThread %d: status = %s (lwpid %d)\n", i,
373026fe8634d7a56b101bb8e43a6666b2f0d00d38dphilippe                  VG_(name_of_ThreadStatus)(VG_(threads)[i].status),
374026fe8634d7a56b101bb8e43a6666b2f0d00d38dphilippe                  VG_(threads)[i].os_state.lwpid);
3754f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe      if (VG_(threads)[i].status != VgTs_Empty)
3764f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe         VG_(get_and_pp_StackTrace)( i, BACKTRACE_DEPTH );
37738a74d2cc4670e3eb559adff51a376cd6ec98005philippe      if (stack_usage && VG_(threads)[i].client_stack_highest_byte != 0 ) {
37838a74d2cc4670e3eb559adff51a376cd6ec98005philippe         Addr start, end;
37938a74d2cc4670e3eb559adff51a376cd6ec98005philippe
38038a74d2cc4670e3eb559adff51a376cd6ec98005philippe         start = end = 0;
38138a74d2cc4670e3eb559adff51a376cd6ec98005philippe         VG_(stack_limits)(VG_(threads)[i].client_stack_highest_byte,
38238a74d2cc4670e3eb559adff51a376cd6ec98005philippe                           &start, &end);
38338a74d2cc4670e3eb559adff51a376cd6ec98005philippe         if (start != end)
38438a74d2cc4670e3eb559adff51a376cd6ec98005philippe            VG_(printf)("client stack range: [%p %p] client SP: %p\n",
38538a74d2cc4670e3eb559adff51a376cd6ec98005philippe                        (void*)start, (void*)end, (void*)VG_(get_SP)(i));
38638a74d2cc4670e3eb559adff51a376cd6ec98005philippe         else
38738a74d2cc4670e3eb559adff51a376cd6ec98005philippe            VG_(printf)("client stack range: ???????\n");
38838a74d2cc4670e3eb559adff51a376cd6ec98005philippe      }
38938a74d2cc4670e3eb559adff51a376cd6ec98005philippe      if (stack_usage && stack != 0)
3904f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe          VG_(printf)("valgrind stack top usage: %ld of %ld\n",
391d0720e4a624bdfe7ce2494d690e7a88f986b93c1philippe                      VG_(clo_valgrind_stacksize)
392026fe8634d7a56b101bb8e43a6666b2f0d00d38dphilippe                        - VG_(am_get_VgStack_unused_szB)
393026fe8634d7a56b101bb8e43a6666b2f0d00d38dphilippe                               (stack, VG_(clo_valgrind_stacksize)),
394d0720e4a624bdfe7ce2494d690e7a88f986b93c1philippe                      (SizeT) VG_(clo_valgrind_stacksize));
39549b45ba90382fd313e40555559f5f5aaa23033b4njn   }
39649b45ba90382fd313e40555559f5f5aaa23033b4njn   VG_(printf)("\n");
39749b45ba90382fd313e40555559f5f5aaa23033b4njn}
398c7561b931e249acf3768ead77638545b0ccaa8f1njn
3994f6f336badda2171d6e842cca3de63b53f4c9f0bphilippevoid VG_(show_sched_status) ( Bool host_stacktrace,
40038a74d2cc4670e3eb559adff51a376cd6ec98005philippe                              Bool stack_usage,
4014f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe                              Bool exited_threads)
4024f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe{
4034f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe   show_sched_status_wrk (host_stacktrace,
40438a74d2cc4670e3eb559adff51a376cd6ec98005philippe                          stack_usage,
4054f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe                          exited_threads,
4064f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe                          NULL);
4074f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe}
4084f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe
409132bfccd21960e462352175f8553a5bdce8a210cnjn__attribute__ ((noreturn))
410bbd9a21ca8518fc34cd7b6254a61d72f82495120florianstatic void report_and_quit ( const HChar* report,
411518850bf0da07ed3e2244e307268ae0fd80e93a8florian                              const UnwindStartRegs* startRegsIN )
412132bfccd21960e462352175f8553a5bdce8a210cnjn{
4134f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe   show_sched_status_wrk (True,  // host_stacktrace
41438a74d2cc4670e3eb559adff51a376cd6ec98005philippe                          False, // stack_usage
4154f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe                          False, // exited_threads
4164f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe                          startRegsIN);
417b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn   VG_(printf)(
418b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "\n"
419b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "Note: see also the FAQ in the source distribution.\n"
420b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "It contains workarounds to several common problems.\n"
421b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "In particular, if Valgrind aborted or crashed after\n"
422b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "identifying problems in your program, there's a good chance\n"
423b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "that fixing those problems will prevent Valgrind aborting or\n"
424b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "crashing, especially if it happened in m_mallocfree.c.\n"
425b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "\n"
426b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "If that doesn't help, please report this bug to: %s\n\n"
427b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "In the bug report, send all the above text, the valgrind\n"
428b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      "version, and what OS and version you are using.  Thanks.\n\n",
429b8329f0ce649067dc5d9d74f8392c6a0ab8d2d40njn      report);
430132bfccd21960e462352175f8553a5bdce8a210cnjn   VG_(exit)(1);
431132bfccd21960e462352175f8553a5bdce8a210cnjn}
432132bfccd21960e462352175f8553a5bdce8a210cnjn
433bbd9a21ca8518fc34cd7b6254a61d72f82495120florianvoid VG_(assert_fail) ( Bool isCore, const HChar* expr, const HChar* file,
434bbd9a21ca8518fc34cd7b6254a61d72f82495120florian                        Int line, const HChar* fn, const HChar* format, ... )
435132bfccd21960e462352175f8553a5bdce8a210cnjn{
43674054f4eac95d1ff81274b9d08be662494210134florian   va_list vargs, vargs_copy;
437bbd9a21ca8518fc34cd7b6254a61d72f82495120florian   const HChar* component;
438bbd9a21ca8518fc34cd7b6254a61d72f82495120florian   const HChar* bugs_to;
4395869dedfc08dd385b3672b51becbb713f5c8931aflorian   UInt written;
440132bfccd21960e462352175f8553a5bdce8a210cnjn
441132bfccd21960e462352175f8553a5bdce8a210cnjn   static Bool entered = False;
442132bfccd21960e462352175f8553a5bdce8a210cnjn   if (entered)
443745fc459ce4ce9264d8844bf1ab695d235a4ce01sewardj      VG_(exit)(2);
444132bfccd21960e462352175f8553a5bdce8a210cnjn   entered = True;
445132bfccd21960e462352175f8553a5bdce8a210cnjn
446132bfccd21960e462352175f8553a5bdce8a210cnjn   if (isCore) {
447132bfccd21960e462352175f8553a5bdce8a210cnjn      component = "valgrind";
448132bfccd21960e462352175f8553a5bdce8a210cnjn      bugs_to   = VG_BUGS_TO;
449132bfccd21960e462352175f8553a5bdce8a210cnjn   } else {
450132bfccd21960e462352175f8553a5bdce8a210cnjn      component = VG_(details).name;
451132bfccd21960e462352175f8553a5bdce8a210cnjn      bugs_to   = VG_(details).bug_reports_to;
452132bfccd21960e462352175f8553a5bdce8a210cnjn   }
453132bfccd21960e462352175f8553a5bdce8a210cnjn
454f349d55d40891b890d0da268cfb9f092af0fc8f4sewardj   if (VG_(clo_xml))
455738856f99eea33d86ce91dcb1d6cd5b151e307casewardj      VG_(printf_xml)("</valgrindoutput>\n");
456f349d55d40891b890d0da268cfb9f092af0fc8f4sewardj
457132bfccd21960e462352175f8553a5bdce8a210cnjn   // Treat vg_assert2(0, "foo") specially, as a panicky abort
458132bfccd21960e462352175f8553a5bdce8a210cnjn   if (VG_STREQ(expr, "0")) {
459132bfccd21960e462352175f8553a5bdce8a210cnjn      VG_(printf)("\n%s: %s:%d (%s): the 'impossible' happened.\n",
4608a7b41b41b46c0aa7bd4b6678b82285437e7f08cnjn                  component, file, line, fn );
461132bfccd21960e462352175f8553a5bdce8a210cnjn   } else {
462132bfccd21960e462352175f8553a5bdce8a210cnjn      VG_(printf)("\n%s: %s:%d (%s): Assertion '%s' failed.\n",
463132bfccd21960e462352175f8553a5bdce8a210cnjn                  component, file, line, fn, expr );
464132bfccd21960e462352175f8553a5bdce8a210cnjn   }
46574054f4eac95d1ff81274b9d08be662494210134florian
46674054f4eac95d1ff81274b9d08be662494210134florian   /* Check whether anything will be written */
46774054f4eac95d1ff81274b9d08be662494210134florian   HChar buf[5];
46874054f4eac95d1ff81274b9d08be662494210134florian   va_start(vargs, format);
46974054f4eac95d1ff81274b9d08be662494210134florian   va_copy(vargs_copy, vargs);
47074054f4eac95d1ff81274b9d08be662494210134florian   written = VG_(vsnprintf) ( buf, sizeof(buf), format, vargs );
47174054f4eac95d1ff81274b9d08be662494210134florian   va_end(vargs);
47274054f4eac95d1ff81274b9d08be662494210134florian
47374054f4eac95d1ff81274b9d08be662494210134florian   if (written > 0) {
47474054f4eac95d1ff81274b9d08be662494210134florian      VG_(printf)("%s: ", component);
47574054f4eac95d1ff81274b9d08be662494210134florian      VG_(vprintf)(format, vargs_copy);
47674054f4eac95d1ff81274b9d08be662494210134florian      VG_(printf)("\n");
47774054f4eac95d1ff81274b9d08be662494210134florian   }
478132bfccd21960e462352175f8553a5bdce8a210cnjn
47959570ffbe31930ab4d678754daaeec0715117a3dsewardj   report_and_quit(bugs_to, NULL);
480132bfccd21960e462352175f8553a5bdce8a210cnjn}
481132bfccd21960e462352175f8553a5bdce8a210cnjn
482132bfccd21960e462352175f8553a5bdce8a210cnjn__attribute__ ((noreturn))
483bbd9a21ca8518fc34cd7b6254a61d72f82495120florianstatic void panic ( const HChar* name, const HChar* report, const HChar* str,
484518850bf0da07ed3e2244e307268ae0fd80e93a8florian                    const UnwindStartRegs* startRegs )
485132bfccd21960e462352175f8553a5bdce8a210cnjn{
486f349d55d40891b890d0da268cfb9f092af0fc8f4sewardj   if (VG_(clo_xml))
487738856f99eea33d86ce91dcb1d6cd5b151e307casewardj      VG_(printf_xml)("</valgrindoutput>\n");
488132bfccd21960e462352175f8553a5bdce8a210cnjn   VG_(printf)("\n%s: the 'impossible' happened:\n   %s\n", name, str);
48959570ffbe31930ab4d678754daaeec0715117a3dsewardj   report_and_quit(report, startRegs);
490132bfccd21960e462352175f8553a5bdce8a210cnjn}
491132bfccd21960e462352175f8553a5bdce8a210cnjn
492518850bf0da07ed3e2244e307268ae0fd80e93a8florianvoid VG_(core_panic_at) ( const HChar* str, const UnwindStartRegs* startRegs )
493132bfccd21960e462352175f8553a5bdce8a210cnjn{
49459570ffbe31930ab4d678754daaeec0715117a3dsewardj   panic("valgrind", VG_BUGS_TO, str, startRegs);
495132bfccd21960e462352175f8553a5bdce8a210cnjn}
496132bfccd21960e462352175f8553a5bdce8a210cnjn
497bbd9a21ca8518fc34cd7b6254a61d72f82495120florianvoid VG_(core_panic) ( const HChar* str )
498132bfccd21960e462352175f8553a5bdce8a210cnjn{
49959570ffbe31930ab4d678754daaeec0715117a3dsewardj   VG_(core_panic_at)(str, NULL);
500132bfccd21960e462352175f8553a5bdce8a210cnjn}
501132bfccd21960e462352175f8553a5bdce8a210cnjn
502bbd9a21ca8518fc34cd7b6254a61d72f82495120florianvoid VG_(tool_panic) ( const HChar* str )
503132bfccd21960e462352175f8553a5bdce8a210cnjn{
50459570ffbe31930ab4d678754daaeec0715117a3dsewardj   panic(VG_(details).name, VG_(details).bug_reports_to, str, NULL);
505132bfccd21960e462352175f8553a5bdce8a210cnjn}
506132bfccd21960e462352175f8553a5bdce8a210cnjn
50749b45ba90382fd313e40555559f5f5aaa23033b4njn/* Print some helpful-ish text about unimplemented things, and give up. */
508bbd9a21ca8518fc34cd7b6254a61d72f82495120florianvoid VG_(unimplemented) ( const HChar* msg )
509132bfccd21960e462352175f8553a5bdce8a210cnjn{
510f349d55d40891b890d0da268cfb9f092af0fc8f4sewardj   if (VG_(clo_xml))
511738856f99eea33d86ce91dcb1d6cd5b151e307casewardj      VG_(printf_xml)("</valgrindoutput>\n");
512738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("\n");
513738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("Valgrind detected that your program requires\n");
514738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("the following unimplemented functionality:\n");
515738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("   %s\n", msg);
516738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("This may be because the functionality is hard to implement,\n");
517738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("or because no reasonable program would behave this way,\n");
518738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("or because nobody has yet needed it.  "
519738856f99eea33d86ce91dcb1d6cd5b151e307casewardj             "In any case, let us know at\n");
520738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("%s and/or try to work around the problem, if you can.\n",
521738856f99eea33d86ce91dcb1d6cd5b151e307casewardj             VG_BUGS_TO);
522738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("\n");
523738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("Valgrind has to exit now.  Sorry.  Bye!\n");
524738856f99eea33d86ce91dcb1d6cd5b151e307casewardj   VG_(umsg)("\n");
5254f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe   VG_(show_sched_status)(False,  // host_stacktrace
52638a74d2cc4670e3eb559adff51a376cd6ec98005philippe                          False,  // stack_usage
5274f6f336badda2171d6e842cca3de63b53f4c9f0bphilippe                          False); // exited_threads
528132bfccd21960e462352175f8553a5bdce8a210cnjn   VG_(exit)(1);
529132bfccd21960e462352175f8553a5bdce8a210cnjn}
530132bfccd21960e462352175f8553a5bdce8a210cnjn
531132bfccd21960e462352175f8553a5bdce8a210cnjn/*--------------------------------------------------------------------*/
532132bfccd21960e462352175f8553a5bdce8a210cnjn/*--- end                                                          ---*/
533132bfccd21960e462352175f8553a5bdce8a210cnjn/*--------------------------------------------------------------------*/
534