]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gprofng/src/Function.h
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gprofng / src / Function.h
1 /* Copyright (C) 2021-2024 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 _DBE_FUNCTION_H
22 #define _DBE_FUNCTION_H
23
24 // A Function object represents an individual function in a .o file.
25
26 #include "util.h"
27 #include "Histable.h"
28 #include "SourceFile.h"
29
30 class Module;
31 class Symbol;
32 class InlinedSubr;
33 struct SrcInfo;
34 struct PCInfo;
35 template <class ITEM> class Vector;
36
37 const uint64_t FUNC_NO_SAVE = (uint64_t) - 1;
38 const uint64_t FUNC_ROOT = (uint64_t) - 2;
39
40 enum
41 {
42 FUNC_FLAG_PLT = 1,
43 FUNC_FLAG_DYNAMIC = 2,
44 FUNC_FLAG_RESDER = 4, // set if derived function resolution has been done
45 FUNC_FLAG_NO_OFFSET = 8, // set if disassembly should not show offset from function
46 FUNC_FLAG_SIMULATED = 16, // not a real function like <Total>, <Unknown>, etc.
47 FUNC_FLAG_NATIVE = 32, // no byte code for JMethod
48 FUNC_NOT_JNI = 64, // a function name is not "Java_..."
49 FUNC_JNI_CHECKED = 128 // already checked for "Java_..."
50 };
51
52 const int MAXDBUF = 32768; // the longest demangled name handled
53
54 class Function : public Histable
55 {
56 public:
57
58 enum MPFuncTypes
59 {
60 MPF_DOALL,
61 MPF_PAR,
62 MPF_SECT,
63 MPF_TASK,
64 MPF_CLONE,
65 MPF_OUTL
66 };
67
68 Function (uint64_t _id);
69 virtual ~Function ();
70
71 virtual uint64_t get_addr ();
72 virtual char *get_name (NameFormat = NA);
73 virtual Vector<Histable*> *get_comparable_objs ();
74 virtual void set_name (char *); // Set the demangled name
75 virtual Histable *convertto (Histable_type type, Histable *obj = NULL);
76
77 virtual Histable_type
78 get_type ()
79 {
80 return FUNCTION;
81 };
82
83 virtual int64_t
84 get_size ()
85 {
86 return size;
87 };
88
89 void set_comparable_name (const char *string);
90 void set_mangled_name (const char *string);
91 void set_match_name (const char *string);
92
93 // Find any derived functions, and set their derivedNode
94 void findDerivedFunctions ();
95 void findKrakatoaDerivedFunctions ();
96 void add_PC_info (uint64_t offset, int lineno, SourceFile *cur_src = NULL);
97 void pushSrcFile (SourceFile* source, int lineno);
98 SourceFile *popSrcFile ();
99 int func_cmp (Function *func, SourceFile *srcContext = NULL);
100 void copy_PCInfo (Function *f);
101 DbeLine *mapPCtoLine (uint64_t addr, SourceFile *src = NULL);
102 DbeInstr *mapLineToPc (DbeLine *dbeLine);
103 DbeInstr *find_dbeinstr (int flag, uint64_t addr);
104 DbeInstr *create_hide_instr (DbeInstr *instr);
105 uint64_t find_previous_addr (uint64_t addr);
106 SourceFile *getDefSrc ();
107 char *getDefSrcName ();
108 void setDefSrc (SourceFile *sf);
109 void setLineFirst (int lineno);
110 Vector<SourceFile*> *get_sources ();
111
112 char *
113 get_mangled_name ()
114 {
115 return mangled_name;
116 }
117
118 char *
119 get_match_name ()
120 {
121 return match_name;
122 }
123
124 inline Function *
125 cardinal ()
126 {
127 return alias ? alias : this;
128 }
129
130 unsigned int flags; // FUNC_FLAG_*
131 Module *module; // pointer to module containing source
132 int line_first; // range of line numbers for function
133 int line_last;
134 int64_t size; // size of the function in bytes
135 uint64_t save_addr; // used for detection of leaf routines
136 DbeInstr *derivedNode; // If derived from another function
137 bool isOutlineFunction; // if outline (save assumed)
138 unsigned int chksum; // check sum of instructions
139 char *img_fname; // file containing function image
140 uint64_t img_offset; // file offset of the image
141 SourceFile *curr_srcfile;
142 DbeLine *defaultDbeLine;
143 Function *usrfunc; // User function
144 Function *alias;
145 bool isUsed;
146 bool isHideFunc;
147 SourceFile *def_source;
148 Function *indexStabsLink; // correspondent function for the .o file
149 Symbol *elfSym;
150 InlinedSubr *inlinedSubr;
151 int inlinedSubrCnt;
152
153 private:
154 DbeInstr **instHTable; // hash table for DbeInstr
155 int *addrIndexHTable; // hash table for addrs index
156 void setSource ();
157 PCInfo *lookup_PCInfo (uint64_t offset);
158 SrcInfo *new_srcInfo ();
159
160 char *mangled_name;
161 char *match_name; // mangled name, with globalization stripped
162 char *comparable_name; // demangled name, with globalization and blanks stripped
163 char *name_buf;
164 NameFormat current_name_format;
165 Vector<PCInfo*> *linetab;
166 Vector<DbeInstr*> *instrs;
167 Vector<uint64_t> *addrs;
168 uint64_t instr_id;
169 Vector<SourceFile*> *sources;
170 SrcInfo *curr_srcinfo; // the current source stack of the function
171 SrcInfo *srcinfo_list; // master list for SrcInfo
172 };
173
174 class JMethod : public Function
175 {
176 public:
177 JMethod (uint64_t _id);
178 virtual ~JMethod ();
179 virtual void set_name (char *);
180 virtual uint64_t get_addr ();
181
182 void
183 set_addr (Vaddr _addr)
184 {
185 addr = _addr;
186 }
187
188 uint64_t
189 get_mid ()
190 {
191 return mid;
192 }
193
194 void
195 set_mid (uint64_t _mid)
196 {
197 mid = _mid;
198 }
199
200 char *
201 get_signature ()
202 {
203 return signature;
204 }
205
206 void
207 set_signature (const char *s)
208 {
209 signature = dbe_strdup (s);
210 }
211
212 // Returns true if func's name matches method's as its JNI implementation
213 bool jni_match (Function *func);
214
215 private:
216 uint64_t mid;
217 Vaddr addr;
218 char *signature;
219 Function *jni_function;
220 };
221
222 #endif /* _DBE_FUNCTION_H */