View | Details | Raw Unified | Return to bug 7
Collapse All | Expand All

(-)a/src/core/assert.cc (-41 lines)
Removed Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2006 INRIA
4
 * All rights reserved.
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 2 as
8
 * published by the Free Software Foundation;
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
 */
21
22
#include "assert.h"
23
24
namespace ns3 {
25
26
void
27
AssertBreakpoint (void)
28
{
29
  int *a = 0;
30
  /**
31
   * we test here to allow a debugger to change the value of
32
   * the variable 'a' to allow the debugger to avoid the 
33
   * subsequent segfault.
34
   */
35
  if (a == 0)
36
    {
37
      *a = 0;
38
    }
39
}
40
41
}//namespace ns3
(-)a/src/core/assert.h (-28 / +4 lines)
 Lines 21-55    Link Here 
21
#ifndef ASSERT_H
21
#ifndef ASSERT_H
22
#define ASSERT_H
22
#define ASSERT_H
23
23
24
/**
25
 * \defgroup assert Assert
26
 * \brief assert functions and macros
27
 *
28
 * The assert macros are used to verify
29
 * at runtime that a certain condition is true. If it is
30
 * not true, the program halts. These checks are built
31
 * into the program only in debugging builds. They are
32
 * removed in optimized builds.
33
 */
34
35
namespace ns3 {
36
37
/**
38
 * \ingroup debugging
39
 *
40
 * When an NS_ASSERT cannot verify its condition, 
41
 * this function is called. This is where you should
42
 * be able to put a breakpoint with a debugger if
43
 * you want to catch assertions before the program 
44
 * halts.
45
 */
46
void AssertBreakpoint (void);
47
48
}//namespace ns3
49
50
#ifdef NS3_ASSERT_ENABLE
24
#ifdef NS3_ASSERT_ENABLE
51
25
52
#include <iostream>
26
#include <iostream>
27
28
#include "breakpoint.h"
53
29
54
/**
30
/**
55
 * \ingroup assert
31
 * \ingroup assert
 Lines 68-74   void AssertBreakpoint (void); Link Here 
68
          std::cout << "assert failed. file=" << __FILE__ <<    \
44
          std::cout << "assert failed. file=" << __FILE__ <<    \
69
            ", line=" << __LINE__ << ", cond=\""#condition <<   \
45
            ", line=" << __LINE__ << ", cond=\""#condition <<   \
70
            "\"" << std::endl;                                  \
46
            "\"" << std::endl;                                  \
71
          ns3::AssertBreakpoint ();                             \
47
          NS_BREAKPOINT ();                                     \
72
        }                                                       \
48
        }                                                       \
73
    }                                                           \
49
    }                                                           \
74
  while (false)
50
  while (false)
 Lines 89-95   void AssertBreakpoint (void); Link Here 
89
      if (!(condition))                         \
65
      if (!(condition))                         \
90
        {                                       \
66
        {                                       \
91
          std::cout << message << std::endl;    \
67
          std::cout << message << std::endl;    \
92
          ns3::AssertBreakpoint ();             \
68
          NS_BREAKPOINT ();                     \
93
        }                                       \
69
        }                                       \
94
    }                                           \
70
    }                                           \
95
  while (false)
71
  while (false)
(-)2e160da082a1 (+58 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2006,2007 INRIA, INESC Porto
4
 * All rights reserved.
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 2 as
8
 * published by the Free Software Foundation;
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
 * Author: Gustavo Carneiro <gjc@inescporto.pt>
21
 */
22
23
#include "breakpoint.h"
24
#include "ns3/core-config.h"
25
#ifdef HAVE_SIGNAL_H
26
# include <signal.h>
27
#endif
28
29
namespace ns3 {
30
31
#ifdef HAVE_SIGNAL_H
32
33
void
34
Breakpoint (void)
35
{
36
  raise (SIGTRAP);
37
}
38
39
#else
40
41
void
42
Breakpoint (void)
43
{
44
  int *a = 0;
45
  /**
46
   * we test here to allow a debugger to change the value of
47
   * the variable 'a' to allow the debugger to avoid the 
48
   * subsequent segfault.
49
   */
50
  if (a == 0)
51
    {
52
      *a = 0;
53
    }
54
}
55
56
#endif // HAVE_SIGNAL_H
57
58
}//namespace ns3
(-)2e160da082a1 (+76 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2006,2007 INESC Porto, INRIA
4
 * All rights reserved.
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 2 as
8
 * published by the Free Software Foundation;
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 * Author: Gustavo Carneiro <gjc@inescporto.pt>
20
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
21
 */
22
#ifndef BREAKPOINT_H
23
#define BREAKPOINT_H
24
25
namespace ns3 {
26
27
/* Hacker macro to place breakpoints for selected machines.
28
 * Actual use is strongly discouraged of course ;)
29
 * Copied from GLib 2.12.9.
30
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
31
 *
32
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
33
 * file for a list of people on the GLib Team.  See the ChangeLog
34
 * files for a list of changes.  These files are distributed with
35
 * GLib at ftp://ftp.gtk.org/pub/gtk/. 
36
 */
37
38
/**
39
 * \ingroup debugging
40
 *
41
 * Inserts a breakpoint instruction (or equivalent system call) into
42
 * the code for selected machines.  When an NS_ASSERT cannot verify its condition, 
43
 * this macro is used. Falls back to calling
44
 * AssertBreakpoint() for architectures where breakpoint assembly
45
 * instructions are not supported.
46
 */
47
#if (defined (__i386__) || defined (__amd64__) || defined (__x86_64__)) && defined (__GNUC__) && __GNUC__ >= 2
48
#  define NS_BREAKPOINT() \
49
   do{ __asm__ __volatile__ ("int $03"); }while(false)
50
#elif defined (_MSC_VER) && defined (_M_IX86)
51
#  define NS_BREAKPOINT() \
52
   do{ __asm int 3h }while(false)
53
#elif defined (__alpha__) && !defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2
54
#  define NS_BREAKPOINT() \
55
   do{ __asm__ __volatile__ ("bpt"); }while(false)
56
#else	/* !__i386__ && !__alpha__ */
57
#  define NS_BREAKPOINT()    ns3::BreakpointFallback ()
58
#endif
59
60
/**
61
 * \brief fallback breakpoint function
62
 *
63
 * This function is used by the NS_DEBUG() macro as a fallback for
64
 * when breakpoint assembly instructions are not available.  It
65
 * attempts to halt program execution either by a raising SIGTRAP, on
66
 * unix systems, or by dereferencing a null pointer.
67
 * 
68
 * Normally you should never call this function directly.
69
 */
70
void BreakpointFallback (void);
71
72
73
}//namespace ns3
74
75
76
#endif /* BREAKPOINT_H */
(-)a/src/core/fatal-error.h (-3 / +3 lines)
 Lines 21-27    Link Here 
21
#ifndef FATAL_ERROR_H
21
#ifndef FATAL_ERROR_H
22
#define FATAL_ERROR_H
22
#define FATAL_ERROR_H
23
23
24
#include "assert.h"
24
#include "breakpoint.h"
25
#include <iostream>
25
#include <iostream>
26
26
27
/**
27
/**
 Lines 32-38    Link Here 
32
 *
32
 *
33
 * When this macro is hit at runtime, the user-specified 
33
 * When this macro is hit at runtime, the user-specified 
34
 * error message is output and the program is halted by calling
34
 * error message is output and the program is halted by calling
35
 * the ns3::AssertBreakpoint function. This macro is enabled
35
 * the NS_DEBUG_BREAKPOINT macro. This macro is enabled
36
 * unconditionally in all builds, including debug and optimized 
36
 * unconditionally in all builds, including debug and optimized 
37
 * builds.
37
 * builds.
38
 */
38
 */
 Lines 40-46    Link Here 
40
  do                                                    \
40
  do                                                    \
41
    {                                                   \
41
    {                                                   \
42
      std::cout << msg << std::endl;			\
42
      std::cout << msg << std::endl;			\
43
      ns3::AssertBreakpoint ();                         \
43
      NS_BREAKPOINT ();                                 \
44
    }                                                   \
44
    }                                                   \
45
  while (false)
45
  while (false)
46
46
(-)a/src/core/uid-manager.cc (+1 lines)
 Lines 20-25    Link Here 
20
 */
20
 */
21
#include "uid-manager.h"
21
#include "uid-manager.h"
22
#include "ns3/fatal-error.h"
22
#include "ns3/fatal-error.h"
23
#include "ns3/assert.h"
23
24
24
25
25
namespace ns3 {
26
namespace ns3 {
(-)a/src/core/wscript (-1 / +8 lines)
 Lines 15-20   def configure(conf): Link Here 
15
    e.define = 'HAVE_GETENV'
15
    e.define = 'HAVE_GETENV'
16
    e.run()
16
    e.run()
17
17
18
    e = conf.create_header_configurator()
19
    e.mandatory = False
20
    e.name = 'signal.h'
21
    e.define = 'HAVE_SIGNAL_H'
22
    e.run()
23
18
    conf.write_config_header('ns3/core-config.h')
24
    conf.write_config_header('ns3/core-config.h')
19
25
20
26
 Lines 26-32   def build(bld): Link Here 
26
    core.source = [
32
    core.source = [
27
        'callback-test.cc',
33
        'callback-test.cc',
28
        'debug.cc',
34
        'debug.cc',
29
        'assert.cc',
35
        'breakpoint.cc',
30
        'ptr.cc',
36
        'ptr.cc',
31
        'object.cc',
37
        'object.cc',
32
        'test.cc',
38
        'test.cc',
 Lines 58-63   def build(bld): Link Here 
58
        'object.h',
64
        'object.h',
59
        'debug.h',
65
        'debug.h',
60
        'assert.h',
66
        'assert.h',
67
        'breakpoint.h',
61
        'fatal-error.h',
68
        'fatal-error.h',
62
        'test.h',
69
        'test.h',
63
        'random-variable.h',
70
        'random-variable.h',

Return to bug 7