|
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 */ |