1 /* Copyright (C) 2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
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)
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.
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. */
21 #ifndef _DBE_FUNCTION_H
22 #define _DBE_FUNCTION_H
24 // A Function object represents an individual function in a .o file.
28 #include "SourceFile.h"
35 template <class ITEM
> class Vector
;
37 const uint64_t FUNC_NO_SAVE
= (uint64_t) - 1;
38 const uint64_t FUNC_ROOT
= (uint64_t) - 2;
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_..."
52 const int MAXDBUF
= 32768; // the longest demangled name handled
54 class Function
: public Histable
68 Function (uint64_t _id
);
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
);
89 void set_comparable_name (const char *string
);
90 void set_mangled_name (const char *string
);
91 void set_match_name (const char *string
);
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 ();
127 return alias
? alias
: this;
130 unsigned int flags
; // FUNC_FLAG_*
131 Module
*module
; // pointer to module containing source
132 int line_first
; // range of line numbers for function
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
147 SourceFile
*def_source
;
148 Function
*indexStabsLink
; // correspondent function for the .o file
150 InlinedSubr
*inlinedSubr
;
154 DbeInstr
**instHTable
; // hash table for DbeInstr
155 int *addrIndexHTable
; // hash table for addrs index
157 PCInfo
*lookup_PCInfo (uint64_t offset
);
158 SrcInfo
*new_srcInfo ();
161 char *match_name
; // mangled name, with globalization stripped
162 char *comparable_name
; // demangled name, with globalization and blanks stripped
164 NameFormat current_name_format
;
165 Vector
<PCInfo
*> *linetab
;
166 Vector
<DbeInstr
*> *instrs
;
167 Vector
<uint64_t> *addrs
;
169 Vector
<SourceFile
*> *sources
;
170 SrcInfo
*curr_srcinfo
; // the current source stack of the function
171 SrcInfo
*srcinfo_list
; // master list for SrcInfo
174 class JMethod
: public Function
177 JMethod (uint64_t _id
);
179 virtual void set_name (char *);
180 virtual uint64_t get_addr ();
183 set_addr (Vaddr _addr
)
195 set_mid (uint64_t _mid
)
207 set_signature (const char *s
)
209 signature
= dbe_strdup (s
);
212 // Returns true if func's name matches method's as its JNI implementation
213 bool jni_match (Function
*func
);
219 Function
*jni_function
;
222 #endif /* _DBE_FUNCTION_H */