00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2006,2007 INESC Porto, INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Gustavo Carneiro <gjc@inescporto.pt> 00019 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00020 */ 00021 #ifndef BREAKPOINT_H 00022 #define BREAKPOINT_H 00023 00024 namespace ns3 { 00025 00026 /* Hacker macro to place breakpoints for selected machines. 00027 * Actual use is strongly discouraged of course ;) 00028 * Copied from GLib 2.12.9. 00029 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald 00030 * 00031 * Modified by the GLib Team and others 1997-2000. See the AUTHORS 00032 * file for a list of people on the GLib Team. See the ChangeLog 00033 * files for a list of changes. These files are distributed with 00034 * GLib at ftp://ftp.gtk.org/pub/gtk/. 00035 */ 00036 00037 /** 00038 * \ingroup debugging 00039 * 00040 * Inserts a breakpoint instruction (or equivalent system call) into 00041 * the code for selected machines. When an NS_ASSERT cannot verify its condition, 00042 * this macro is used. Falls back to calling 00043 * AssertBreakpoint() for architectures where breakpoint assembly 00044 * instructions are not supported. 00045 */ 00046 #if (defined (__i386__) || defined (__amd64__) || defined (__x86_64__)) && defined (__GNUC__) && __GNUC__ >= 2 00047 # define NS_BREAKPOINT() \ 00048 do{ __asm__ __volatile__ ("int $03"); }while(false) 00049 #elif defined (_MSC_VER) && defined (_M_IX86) 00050 # define NS_BREAKPOINT() \ 00051 do{ __asm int 3h }while(false) 00052 #elif defined (__alpha__) && !defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2 00053 # define NS_BREAKPOINT() \ 00054 do{ __asm__ __volatile__ ("bpt"); }while(false) 00055 #else /* !__i386__ && !__alpha__ */ 00056 # define NS_BREAKPOINT() ns3::BreakpointFallback () 00057 #endif 00058 00059 /** 00060 * \brief fallback breakpoint function 00061 * 00062 * This function is used by the NS_BREAKPOINT() macro as a fallback 00063 * for when breakpoint assembly instructions are not available. It 00064 * attempts to halt program execution either by a raising SIGTRAP, on 00065 * unix systems, or by dereferencing a null pointer. 00066 * 00067 * Normally you should not call this function directly. 00068 */ 00069 void BreakpointFallback (void); 00070 00071 00072 }//namespace ns3 00073 00074 00075 #endif /* BREAKPOINT_H */