LCOV - code coverage report
Current view: directory - memory/mozalloc - mozalloc_abort.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 12 0 0.0 %
Date: 2012-06-02 Functions: 3 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * vim: sw=4 ts=4 et :
       3                 :  */
       4                 : /* ***** BEGIN LICENSE BLOCK *****
       5                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       6                 :  *
       7                 :  * The contents of this file are subject to the Mozilla Public License Version
       8                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       9                 :  * the License. You may obtain a copy of the License at
      10                 :  * http://www.mozilla.org/MPL/
      11                 :  *
      12                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      13                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      14                 :  * for the specific language governing rights and limitations under the
      15                 :  * License.
      16                 :  *
      17                 :  * The Original Code is Mozilla Code
      18                 :  *
      19                 :  * The Initial Developer of the Original Code is
      20                 :  * The Mozilla Foundation.
      21                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      22                 :  * the Initial Developer. All Rights Reserved.
      23                 :  *
      24                 :  * Contributor(s):
      25                 :  *   Chris Jones <jones.chris.g@gmail.com>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      29                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #include <stdio.h>
      42                 : #include <stdlib.h>             // for abort()
      43                 : 
      44                 : #if defined(_MSC_VER)           // MSVC
      45                 : #  include <intrin.h>           // for __debugbreak()
      46                 : #elif defined(XP_WIN)           // mingw
      47                 : #  include <windows.h>          // for DebugBreak
      48                 : #elif defined(XP_UNIX)
      49                 : #  include <unistd.h>           // for _exit
      50                 : #  include <signal.h>
      51                 : #endif
      52                 : 
      53                 : #if defined(XP_WIN) || defined(XP_OS2)
      54                 : #  define MOZALLOC_EXPORT __declspec(dllexport)
      55                 : #endif
      56                 : 
      57                 : #include "mozilla/mozalloc_abort.h"
      58                 : 
      59                 : static int gDummyCounter;
      60                 : 
      61                 : // Not inlining this function avoids the compiler making optimizations
      62                 : // that end up corrupting stack traces.
      63                 : MOZ_NEVER_INLINE static void
      64               0 : TouchBadMemory()
      65                 : {
      66                 :     // XXX this should use the frame poisoning code
      67               0 :     volatile int *p = 0;
      68               0 :     gDummyCounter += *p;   // TODO annotation saying we know 
      69                 :                            // this is crazy
      70               0 : }
      71                 : 
      72                 : void
      73               0 : mozalloc_abort(const char* const msg)
      74                 : {
      75               0 :     fputs(msg, stderr);
      76               0 :     fputs("\n", stderr);
      77                 : 
      78                 : #if defined(_MSC_VER)
      79                 :     __debugbreak();
      80                 : #elif defined(XP_WIN)
      81                 :     DebugBreak();
      82                 : #endif
      83                 : 
      84                 :     // On *NIX platforms the prefered way to abort is by touching bad memory,
      85                 :     // since this generates a stack trace inside our own code (avoiding
      86                 :     // problems with starting the trace inside libc, where we might not have
      87                 :     // symbols and can get lost).
      88                 : 
      89               0 :     TouchBadMemory();
      90                 : 
      91                 :     // If we haven't aborted yet, we can try to raise SIGABRT which might work
      92                 :     // on some *NIXs, but not OS X (it doesn't trigger breakpad there).
      93                 :     // Note that we don't call abort(), since raise is likelier to give us
      94                 :     // useful stack data, and also since abort() is redirected to call this
      95                 :     // function (see below).
      96                 : #if defined(XP_UNIX) && !defined(XP_MACOSX)
      97               0 :     raise(SIGABRT);
      98                 : #endif
      99                 : 
     100                 :     // Still haven't aborted?  Try _exit().
     101               0 :     _exit(127);
     102                 : }
     103                 : 
     104                 : #if defined(XP_UNIX)
     105                 : // Define abort() here, so that it is used instead of the system abort(). This
     106                 : // lets us control the behavior when aborting, in order to get better results
     107                 : // on *NIX platfrorms. See mozalloc_abort for details.
     108               0 : void abort(void)
     109                 : {
     110               0 :   mozalloc_abort("Redirecting call to abort() to mozalloc_abort\n");
     111                 : }
     112                 : #endif
     113                 : 

Generated by: LCOV version 1.7