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