A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
breakpoint.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006,2007 INESC Porto, INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Gustavo Carneiro <gjc@inescporto.pt>
7 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8 */
9#ifndef BREAKPOINT_H
10#define BREAKPOINT_H
11
12/**
13 * \file
14 * \ingroup breakpoint
15 * NS_BREAKPOINT() macro definition and ns3::BreakpointFallback
16 * function declaration.
17 */
18
19namespace ns3
20{
21
22/* Hacker macro to place breakpoints for selected machines.
23 * Actual use is strongly discouraged of course ;)
24 * Copied from GLib 2.12.9.
25 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
26 *
27 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
28 * file for a list of people on the GLib Team. See the ChangeLog
29 * files for a list of changes. These files are distributed with
30 * GLib at ftp://ftp.gtk.org/pub/gtk/.
31 */
32
33/**
34 * \ingroup debugging
35 * \defgroup breakpoint Breakpoints
36 *
37 * \brief Trigger a debugger breakpoint.
38 */
39
40/**
41 * \ingroup breakpoint
42 *
43 * Inserts a breakpoint instruction (or equivalent system call) into
44 * the code for selected machines. When an NS_ASSERT cannot verify
45 * its condition, this macro is used. Falls back to calling
46 * ns3::BreakpointFallback() for architectures where breakpoint assembly
47 * instructions are not supported.
48 */
49#if (defined(__i386__) || defined(__amd64__) || defined(__x86_64__)) && defined(__GNUC__) && \
50 __GNUC__ >= 2
51#define NS_BREAKPOINT() \
52 do \
53 { \
54 __asm__ __volatile__("int $03"); \
55 } while (false)
56#elif defined(_MSC_VER) && defined(_M_IX86)
57#define NS_BREAKPOINT() \
58 do \
59 { \
60 __asm int 3h \
61 } while (false)
62#elif defined(__alpha__) && !defined(__osf__) && defined(__GNUC__) && __GNUC__ >= 2
63#define NS_BREAKPOINT() \
64 do \
65 { \
66 __asm__ __volatile__("bpt"); \
67 } while (false)
68#else /* !__i386__ && !__alpha__ */
69#define NS_BREAKPOINT() ns3::BreakpointFallback()
70#endif
71
72/**
73 * \ingroup breakpoint
74 *
75 * \brief fallback breakpoint function
76 *
77 * This function is used by the NS_BREAKPOINT() macro as a fallback
78 * for when breakpoint assembly instructions are not available. It
79 * attempts to halt program execution either by a raising SIGTRAP, on
80 * unix systems, or by dereferencing a null pointer.
81 *
82 * Normally you should not call this function directly.
83 */
85
86} // namespace ns3
87
88#endif /* BREAKPOINT_H */
void BreakpointFallback()
fallback breakpoint function
Definition breakpoint.cc:43
Every class exported by the ns3 library is enclosed in the ns3 namespace.