1 /* Copyright (C) 2021-2023 Free Software Foundation, Inc.
2 Contributed by Oracle.
3
4 This file is part of GNU Binutils.
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 as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 This program 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 this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21 #ifndef _CALLSTACK_H
22 #define _CALLSTACK_H
23
24 #include <stdio.h>
25 #include "dbe_structs.h"
26 #include "Experiment.h"
27 #include "DbeLock.h"
28
29 class DataDescriptor;
30 class FramePacket;
31 class DbeInstr;
32 class Histable;
33 template <class ITEM> class Vector;
34 class CallStackNode;
35
36 class Descendants /* : public DbeLock */
37 {
38 public:
39 Descendants ();
40 ~Descendants ();
41 CallStackNode *find (Histable *hi, int *index);
42 void append (CallStackNode *item);
43 void insert (int ind, CallStackNode *item);
44 int volatile count;
45
46 private:
47
48 enum
49 {
50 DELTA = 8
51 };
52
53 int limit;
54 CallStackNode **data;
55 CallStackNode *first_data[4];
56 };
57
58 class CallStackNode : public Descendants
59 {
60 public:
61 CallStackNode (CallStackNode *_ancestor, Histable *_instr);
62 ~CallStackNode ();
63 bool compare (long start, long end, Vector<Histable*> *objs, CallStackNode *mRoot);
64 void dump ();
65
66 CallStackNode *
67 get_ancestor ()
68 {
69 return ancestor;
70 }
71
72 Histable *
73 get_instr ()
74 {
75 return instr;
76 }
77
78 CallStackNode *alt_node;
79 Histable *instr;
80 CallStackNode *ancestor;
81 };
82
83 class CallStack
84 {
85 public:
86 static CallStack *getInstance (Experiment *exp);
87 virtual ~CallStack () { };
88
89 virtual void add_stack (DataDescriptor *dDscr, long idx, FramePacket *frp,
90 cstk_ctx_chunk* cstCtxChunk) = 0;
91
92 // Creates a call stack representation for objs and
93 // returns an opaque pointer to it
94 virtual void *add_stack (Vector<Histable*> *objs) = 0;
95
96 // Debugging methods
97 virtual void print (FILE *) = 0;
98
99 // Call stack inquiries
100 static int stackSize (void *stack);
101 static Histable *getStackPC (void *stack, int n);
102 static Vector<Histable*> *getStackPCs (void *stack, bool get_hide_stack = false);
103 static void setHideStack (void *stack, void *hideStack);
104 static int compare (void *stack1, void *stack2);
105
106 virtual CallStackNode *
107 get_node (int)
108 {
109 return NULL;
110 };
111
112 };
113
114 #endif /* _CALLSTACK_H */