src/core/breakpoint.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 1018 99476ef5580a
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2006,2007 INESC Porto, INRIA
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Author: Gustavo Carneiro <gjc@inescporto.pt>
    19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    20  */
    21 #ifndef BREAKPOINT_H
    22 #define BREAKPOINT_H
    23 
    24 namespace ns3 {
    25 
    26 /* Hacker macro to place breakpoints for selected machines.
    27  * Actual use is strongly discouraged of course ;)
    28  * Copied from GLib 2.12.9.
    29  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
    30  *
    31  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
    32  * file for a list of people on the GLib Team.  See the ChangeLog
    33  * files for a list of changes.  These files are distributed with
    34  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
    35  */
    36 
    37 /**
    38  * \ingroup debugging
    39  *
    40  * Inserts a breakpoint instruction (or equivalent system call) into
    41  * the code for selected machines.  When an NS_ASSERT cannot verify its condition, 
    42  * this macro is used. Falls back to calling
    43  * AssertBreakpoint() for architectures where breakpoint assembly
    44  * instructions are not supported.
    45  */
    46 #if (defined (__i386__) || defined (__amd64__) || defined (__x86_64__)) && defined (__GNUC__) && __GNUC__ >= 2
    47 #  define NS_BREAKPOINT() \
    48    do{ __asm__ __volatile__ ("int $03"); }while(false)
    49 #elif defined (_MSC_VER) && defined (_M_IX86)
    50 #  define NS_BREAKPOINT() \
    51    do{ __asm int 3h }while(false)
    52 #elif defined (__alpha__) && !defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2
    53 #  define NS_BREAKPOINT() \
    54    do{ __asm__ __volatile__ ("bpt"); }while(false)
    55 #else	/* !__i386__ && !__alpha__ */
    56 #  define NS_BREAKPOINT()    ns3::BreakpointFallback ()
    57 #endif
    58 
    59 /**
    60  * \brief fallback breakpoint function
    61  *
    62  * This function is used by the NS_BREAKPOINT() macro as a fallback
    63  * for when breakpoint assembly instructions are not available.  It
    64  * attempts to halt program execution either by a raising SIGTRAP, on
    65  * unix systems, or by dereferencing a null pointer.
    66  * 
    67  * Normally you should not call this function directly.
    68  */
    69 void BreakpointFallback (void);
    70 
    71 
    72 }//namespace ns3
    73 
    74 
    75 #endif /* BREAKPOINT_H */