Predator  [unstable] git snapshot
symbt.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Kamil Dudka <kdudka@redhat.com>
3  *
4  * This file is part of predator.
5  *
6  * predator is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * any later version.
10  *
11  * predator is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with predator. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef H_GUARD_SYMBT_H
21 #define H_GUARD_SYMBT_H
22 
23 /**
24  * @file symbt.hh
25  * SymBackTrace - backtrace management
26  */
27 
28 class SymProc;
29 
30 enum EMsgLevel {
34 };
35 
36 namespace CodeStorage {
37  struct Fnc;
38  struct Storage;
39 }
40 
41 /// backtrace management
42 class SymBackTrace {
43  public:
44  /**
45  * @param stor reference to storage object, used for resolving fnc IDs
46  */
48  ~SymBackTrace();
49 
50  SymBackTrace(const SymBackTrace &);
51 
52  /**
53  * @todo consider fitness of this method in the public interface of
54  * SymBackTrace
55  */
56  const CodeStorage::Storage& stor() const;
57 
58  public:
59  /**
60  * enter a call of function, thus enlarge the backtrace by one
61  * @param fncId ID of function, which is being called
62  * @param loc location of the call related to the caller (definitely @b
63  * not location of the called function)
64  */
65  void pushCall(int fncId, const struct cl_loc *loc);
66 
67  /**
68  * leave the call of function on top of the backtrace
69  * @note it's safe to ignore the return value
70  */
71  const CodeStorage::Fnc* popCall();
72 
73  /// size of the backtrace, aka @b call @b depth
74  unsigned size() const;
75 
76  /**
77  * count occurrences of the given function. Zero means the function
78  * does not occur in the backtrace. Non-zero means the function occurs
79  * in the backtrace. Moreover, if the value is more than one, the
80  * function has been called @b recursively.
81  * @note The function is not implemented or used right now, but is going
82  * to be as soon as we allow recursion. We need the returned value to
83  * distinguish among different instances of the same local variable.
84  */
85  int countOccurrencesOfFnc(int fncId) const;
86 
87  /**
88  * same as countOccurrencesOfFnc(), but operating on top of the
89  * backtrace stack
90  */
91  int countOccurrencesOfTopFnc() const;
92 
93  /// return the topmost function in the backtrace
94  const CodeStorage::Fnc* topFnc() const;
95 
96  /// return location of call of the topmost function in the backtrace
97  const struct cl_loc* topCallLoc() const;
98 
99  protected:
100  /**
101  * stream out the backtrace, using CL_NOTE_MSG; or do nothing if the
102  * backtrace is trivial
103  * @return true if the backtrace is @b not trivial
104  */
105  bool printBackTrace() const;
106  friend class SymProc;
107  friend class SymExecEngine;
108 
109  private:
111 
112  struct Private;
113  Private *d;
114 };
115 
116 #endif /* H_GUARD_SYMBT_H */