xref: /netbsd-src/external/bsd/lutok/dist/debug.hpp (revision 9b0eec67b2e263eb41d1beb36e3329a2a9419668)
1a1563752Sjmmv // Copyright 2011 Google Inc.
2a1563752Sjmmv // All rights reserved.
3a1563752Sjmmv //
4a1563752Sjmmv // Redistribution and use in source and binary forms, with or without
5a1563752Sjmmv // modification, are permitted provided that the following conditions are
6a1563752Sjmmv // met:
7a1563752Sjmmv //
8a1563752Sjmmv // * Redistributions of source code must retain the above copyright
9a1563752Sjmmv //   notice, this list of conditions and the following disclaimer.
10a1563752Sjmmv // * Redistributions in binary form must reproduce the above copyright
11a1563752Sjmmv //   notice, this list of conditions and the following disclaimer in the
12a1563752Sjmmv //   documentation and/or other materials provided with the distribution.
13a1563752Sjmmv // * Neither the name of Google Inc. nor the names of its contributors
14a1563752Sjmmv //   may be used to endorse or promote products derived from this software
15a1563752Sjmmv //   without specific prior written permission.
16a1563752Sjmmv //
17a1563752Sjmmv // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18a1563752Sjmmv // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19a1563752Sjmmv // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20a1563752Sjmmv // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21a1563752Sjmmv // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22a1563752Sjmmv // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23a1563752Sjmmv // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24a1563752Sjmmv // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25a1563752Sjmmv // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26a1563752Sjmmv // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27a1563752Sjmmv // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28a1563752Sjmmv 
29a1563752Sjmmv /// \file debug.hpp
30a1563752Sjmmv /// Provides the debug wrapper class for the Lua C debug state.
31a1563752Sjmmv 
32a1563752Sjmmv #if !defined(LUTOK_DEBUG_HPP)
33a1563752Sjmmv #define LUTOK_DEBUG_HPP
34a1563752Sjmmv 
35a1563752Sjmmv #include <string>
36*9b0eec67Sjmmv #if defined(_LIBCPP_VERSION) || __cplusplus >= 201103L
37*9b0eec67Sjmmv #include <memory>
38*9b0eec67Sjmmv #else
39a1563752Sjmmv #include <tr1/memory>
40*9b0eec67Sjmmv #endif
41a1563752Sjmmv 
42a1563752Sjmmv namespace lutok {
43a1563752Sjmmv 
44a1563752Sjmmv 
45a1563752Sjmmv class state;
46a1563752Sjmmv 
47a1563752Sjmmv 
48a1563752Sjmmv /// A model for the Lua debug state.
49a1563752Sjmmv ///
50a1563752Sjmmv /// This extremely-simple class provides a mechanism to hide the internals of
51a1563752Sjmmv /// the C native lua_Debug type, exposing its internal fields using friendlier
52a1563752Sjmmv /// C++ types.
53a1563752Sjmmv ///
54a1563752Sjmmv /// This class also acts as a complement to the state class by exposing any
55a1563752Sjmmv /// state-related functions as methods of this function.  For example, while it
56a1563752Sjmmv /// might seem that get_info() belongs in state, we expose it from here because
57a1563752Sjmmv /// its result is really mutating a debug object, not the state object.
58a1563752Sjmmv class debug {
59a1563752Sjmmv     struct impl;
60a1563752Sjmmv 
61a1563752Sjmmv     /// Pointer to the shared internal implementation.
62*9b0eec67Sjmmv #if defined(_LIBCPP_VERSION) || __cplusplus >= 201103L
63*9b0eec67Sjmmv     std::shared_ptr< impl > _pimpl;
64*9b0eec67Sjmmv #else
65a1563752Sjmmv     std::tr1::shared_ptr< impl > _pimpl;
66*9b0eec67Sjmmv #endif
67a1563752Sjmmv 
68a1563752Sjmmv public:
69a1563752Sjmmv     debug(void);
70a1563752Sjmmv     ~debug(void);
71a1563752Sjmmv 
72a1563752Sjmmv     void get_info(state&, const std::string&);
73a1563752Sjmmv     void get_stack(state&, const int);
74a1563752Sjmmv 
75a1563752Sjmmv     int event(void) const;
76a1563752Sjmmv     std::string name(void) const;
77a1563752Sjmmv     std::string name_what(void) const;
78a1563752Sjmmv     std::string what(void) const;
79a1563752Sjmmv     std::string source(void) const;
80a1563752Sjmmv     int current_line(void) const;
81a1563752Sjmmv     int n_ups(void) const;
82a1563752Sjmmv     int line_defined(void) const;
83a1563752Sjmmv     int last_line_defined(void) const;
84a1563752Sjmmv     std::string short_src(void) const;
85a1563752Sjmmv };
86a1563752Sjmmv 
87a1563752Sjmmv 
88a1563752Sjmmv }  // namespace lutok
89a1563752Sjmmv 
90a1563752Sjmmv #endif  // !defined(LUTOK_DEBUG_HPP)
91