# HG changeset patch # User Gustavo J. A. M. Carneiro # Date 1172675101 0 # Node ID 1b251c3666c61690e69ef0ddb2ef9b7352f49ca9 # Parent d8b5e567fc503defbf97a2e3a7c8266c650f7dd6 Add an improved breakpoint macro, which uses an appropriate breakpoint instruction rather than producing a segmentation fault where possible. diff -r d8b5e567fc50 -r 1b251c3666c6 SConstruct --- a/SConstruct Mon Feb 26 10:28:57 2007 +0100 +++ b/SConstruct Wed Feb 28 15:05:01 2007 +0000 @@ -57,6 +57,12 @@ def config_core (env, config): else: retval.append ('#undef HAVE_STDLIB_H') retval.append ('#undef HAVE_GETENV') + + if config.CheckCHeader ('signal.h') == 1: + retval.append ('#define HAVE_SIGNAL_H 1') + else: + retval.append ('#undef HAVE_SIGNAL_H') + return retval core.add_config (config_core) diff -r d8b5e567fc50 -r 1b251c3666c6 src/core/assert.cc --- a/src/core/assert.cc Mon Feb 26 10:28:57 2007 +0100 +++ b/src/core/assert.cc Wed Feb 28 15:05:01 2007 +0000 @@ -20,8 +20,22 @@ */ #include "assert.h" +#include "ns3/core-config.h" +#ifdef HAVE_SIGNAL_H +# include +#endif namespace ns3 { + +#ifdef HAVE_SIGNAL_H + +void +AssertBreakpoint (void) +{ + raise (SIGTRAP); +} + +#else void AssertBreakpoint (void) @@ -38,4 +52,6 @@ AssertBreakpoint (void) } } +#endif // HAVE_SIGNAL_H + }//namespace ns3 diff -r d8b5e567fc50 -r 1b251c3666c6 src/core/debug.h --- a/src/core/debug.h Mon Feb 26 10:28:57 2007 +0100 +++ b/src/core/debug.h Wed Feb 28 15:05:01 2007 +0000 @@ -137,4 +137,35 @@ private: #endif /* NS3_DEBUG_ENABLE */ + +/* Hacker macro to place breakpoints for selected machines. + * Actual use is strongly discouraged of course ;) + * Copied from GLib 2.12.9. + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * + * Modified by the GLib Team and others 1997-2000. See the AUTHORS + * file for a list of people on the GLib Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GLib at ftp://ftp.gtk.org/pub/gtk/. + */ + +/** + * \ingroup debugging + * + * Inserts a breakpoint instruction (or equivalent system call) into + * the code for selected machines. + */ +#if (defined (__i386__) || defined (__x86_64__)) && defined (__GNUC__) && __GNUC__ >= 2 +# define NS_DEBUG_BREAKPOINT() \ + do{ __asm__ __volatile__ ("int $03"); }while(false) +#elif defined (_MSC_VER) && defined (_M_IX86) +# define NS_DEBUG_BREAKPOINT() \ + do{ __asm int 3h }while(false) +#elif defined (__alpha__) && !defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2 +# define NS_DEBUG_BREAKPOINT() \ + do{ __asm__ __volatile__ ("bpt"); }while(false) +#else /* !__i386__ && !__alpha__ */ +# define NS_DEBUG_BREAKPOINT() ns3::AssertBreakpoint () +#endif + #endif /* DEBUG_H */ diff -r d8b5e567fc50 -r 1b251c3666c6 src/core/fatal-error.h --- a/src/core/fatal-error.h Mon Feb 26 10:28:57 2007 +0100 +++ b/src/core/fatal-error.h Wed Feb 28 15:05:01 2007 +0000 @@ -31,7 +31,7 @@ * * When this macro is hit at runtime, the user-specified * error message is output and the program is halted by calling - * the ns3::AssertBreakpoint function. This macro is enabled + * the NS_DEBUG_BREAKPOINT macro. This macro is enabled * unconditionally in all builds, including debug and optimized * builds. */ @@ -39,7 +39,7 @@ do \ { \ std::cout << msg << std::endl; \ - ns3::AssertBreakpoint (); \ + NS_DEBUG_BREAKPOINT (); \ } \ while (false)