gjc@1018: /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ gjc@1018: /* gjc@1018: * Copyright (c) 2006,2007 INESC Porto, INRIA gjc@1018: * gjc@1018: * This program is free software; you can redistribute it and/or modify gjc@1018: * it under the terms of the GNU General Public License version 2 as gjc@1018: * published by the Free Software Foundation; gjc@1018: * gjc@1018: * This program is distributed in the hope that it will be useful, gjc@1018: * but WITHOUT ANY WARRANTY; without even the implied warranty of gjc@1018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the gjc@1018: * GNU General Public License for more details. gjc@1018: * gjc@1018: * You should have received a copy of the GNU General Public License gjc@1018: * along with this program; if not, write to the Free Software gjc@1018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA gjc@1018: * gjc@1018: * Author: Gustavo Carneiro gjc@1018: * Author: Mathieu Lacage gjc@1018: */ gjc@1018: #ifndef BREAKPOINT_H gjc@1018: #define BREAKPOINT_H gjc@1018: gjc@1018: namespace ns3 { gjc@1018: gjc@1018: /* Hacker macro to place breakpoints for selected machines. gjc@1018: * Actual use is strongly discouraged of course ;) gjc@1018: * Copied from GLib 2.12.9. gjc@1018: * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald gjc@1018: * gjc@1018: * Modified by the GLib Team and others 1997-2000. See the AUTHORS gjc@1018: * file for a list of people on the GLib Team. See the ChangeLog gjc@1018: * files for a list of changes. These files are distributed with gjc@1018: * GLib at ftp://ftp.gtk.org/pub/gtk/. gjc@1018: */ gjc@1018: gjc@1018: /** gjc@1018: * \ingroup debugging gjc@1018: * gjc@1018: * Inserts a breakpoint instruction (or equivalent system call) into gjc@1018: * the code for selected machines. When an NS_ASSERT cannot verify its condition, gjc@1018: * this macro is used. Falls back to calling gjc@1018: * AssertBreakpoint() for architectures where breakpoint assembly gjc@1018: * instructions are not supported. gjc@1018: */ gjc@1018: #if (defined (__i386__) || defined (__amd64__) || defined (__x86_64__)) && defined (__GNUC__) && __GNUC__ >= 2 gjc@1018: # define NS_BREAKPOINT() \ gjc@1018: do{ __asm__ __volatile__ ("int $03"); }while(false) gjc@1018: #elif defined (_MSC_VER) && defined (_M_IX86) gjc@1018: # define NS_BREAKPOINT() \ gjc@1018: do{ __asm int 3h }while(false) gjc@1018: #elif defined (__alpha__) && !defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2 gjc@1018: # define NS_BREAKPOINT() \ gjc@1018: do{ __asm__ __volatile__ ("bpt"); }while(false) gjc@1018: #else /* !__i386__ && !__alpha__ */ gjc@1018: # define NS_BREAKPOINT() ns3::BreakpointFallback () gjc@1018: #endif gjc@1018: gjc@1018: /** gjc@1018: * \brief fallback breakpoint function gjc@1018: * gjc@1018: * This function is used by the NS_BREAKPOINT() macro as a fallback gjc@1018: * for when breakpoint assembly instructions are not available. It gjc@1018: * attempts to halt program execution either by a raising SIGTRAP, on gjc@1018: * unix systems, or by dereferencing a null pointer. gjc@1018: * gjc@1018: * Normally you should not call this function directly. gjc@1018: */ gjc@1018: void BreakpointFallback (void); gjc@1018: gjc@1018: gjc@1018: }//namespace ns3 gjc@1018: gjc@1018: gjc@1018: #endif /* BREAKPOINT_H */