1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
/* Copyright (C) 2021-2024 Free Software Foundation, Inc.
Contributed by Oracle.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef _MODULE_H
#define _MODULE_H
// A Module object represents a .o file that was used to build up a segement.
// Its main function is to compute source and disassembly annotations
// Text reordering and/or function outlining imply that a module may
// not be contiguous.
#include "Histable.h"
#include "Hist_data.h"
#define MOD_FLAG_UNKNOWN 0x01
class LoadObject;
class MetricList;
class ComC;
class Disasm;
class Hist_data;
class Stabs;
class SourceFile;
class DataObject;
class JMethod;
template <class ITEM> class Vector;
class InlinedSubr
{
public:
InlinedSubr ();
DbeLine *dbeLine;
Function *func;
char *fname;
uint64_t low_pc;
uint64_t high_pc;
int level;
bool
contains (InlinedSubr *p)
{
return low_pc <= p->low_pc && high_pc >= p->high_pc;
}
bool
contains (uint64_t pc)
{
return low_pc <= pc && high_pc > pc;
}
};
class Module : public HistableFile
{
public:
// Annotated Source or Disassembly
enum Anno_Errors
{
AE_OK,
AE_NOTREAD,
AE_NOSRC,
AE_NOOBJ,
AE_NOLOBJ,
AE_NOSTABS,
AE_NOSYMTAB,
AE_TIMESRC,
AE_TIMEDIS,
AE_TIMESTABS,
AE_TIMESTABS_DIFF,
AE_OTHER
};
// The following enums are duplicated in Java
enum Anno_Types
{
AT_LIST = 0,
AT_SRC,
AT_SRC_ONLY,
AT_DIS,
AT_COM,
AT_QUOTE,
AT_FUNC,
AT_EMPTY,
AT_DIS_ONLY
};
Module ();
virtual ~Module ();
virtual int64_t get_size ();
virtual void set_name (char *str);
virtual Vector<Histable*> *get_comparable_objs ();
virtual int readFile ();
virtual Histable_type
get_type ()
{
return MODULE;
}
inline Anno_Errors
get_status ()
{
return status;
}
inline void
set_file_name (char *fnm)
{
free (file_name);
file_name = fnm;
}
// get error string
char *anno_str (char *fnm = NULL);
// generate annotated source/disassembly data
Hist_data *get_data (DbeView *dbev, MetricList *mlist,
Histable::Type type, TValue *ftotal, SourceFile *srcFile,
Function *func, Vector<int> *marks, int threshold,
int vis_bits, int src_visible, bool hex_visible,
bool func_scope, bool src_only,
Vector<int_pair_t> *marks2d = NULL,
Vector<int_pair_t> *marks2d_inc = NULL);
Vector<uint64_t> *getAddrs (Function *func);
SourceFile *setIncludeFile (char *includeFile);
SourceFile *
getIncludeFile ()
{
return curr_inc;
}
SourceFile *
getMainSrc ()
{
return main_source;
}
char *
getResolvedObjectPath ()
{
return stabsPath ? stabsPath : get_name ();
}
char *
getDebugPath ()
{
setFile ();
return stabsPath;
}
void read_stabs (bool all = true);
void dump_dataobjects (FILE *out);
DataObject *get_dobj (uint32_t dtype_id);
void reset_datatypes ();
void read_hwcprof_info ();
bool is_fortran ();
SourceFile *findSource (const char *fname, bool create);
bool openStabs (bool all = true);
LoadObject *createLoadObject (const char *lo_name);
JMethod *find_jmethod (const char *nm, const char *sig);
unsigned int flags; // flags used for marking traversals
Sp_lang_code lang_code; // What is source lang. in module
char *file_name; // Full path to actual source file
Vector<Function*> *functions; // Unordered list of functions
LoadObject *loadobject; // Parent loadobject
LoadObject *dot_o_file; // The .o file with debug information
unsigned fragmented; // -xF used when compiling module
int real_timestamp; // Linked timestamp from N_OPT stab
int curr_timestamp; // Current object timestamp from N_OPT stab
char *comp_flags; // compiler flags used to compile module
char *comp_dir; // directory used to compile module
char *linkerStabName; // Name from 'N_UNDF' stab
Stabs *objStabs; // stabs of object file
bool readStabs;
bool hasStabs;
bool hasDwarf;
uint64_t hdrOffset; // offset in .debug_info
unsigned hwcprof; // hwcprof info status
Vector<inst_info_t*> *infoList; // merged list
Vector<memop_info_t*> ldMemops; // load instructions
Vector<memop_info_t*> stMemops; // store instructions
Vector<memop_info_t*> pfMemops; // prefetch instructions
Vector<target_info_t*> bTargets; // branch targets
Vector<datatype_t*> *datatypes; // object type descriptors
Vector<SourceFile*> *includes;
Module *indexStabsLink; // correspondent module for the .o file
InlinedSubr *inlinedSubr;
protected:
void removeStabsTmp (); // Remove temporary *.o (got from *.a)
// Check timestamp, warn users if src/dis/stabs later than exp.
Anno_Errors checkTimeStamp (bool chkDis);
// Set paths for reading Stabs and Symbols
bool read_ar (int ar, int obj, char *obj_base);
bool setFile ();
// Open appropriate symbol tables, construct set of PC ranges,
// and maps to source lines for each PC
Stabs *openDebugInfo ();
// Construct PC index table
bool openDisPC ();
// Compute data--scan data to compute metrics per-src-line/dis-line
bool computeMetrics (DbeView *dbev, Function *func, MetricList *mlist,
Histable::Type type, bool src_metric,
bool func_scope, SourceFile *source);
void init_line ();
void init_index (Hist_data *witems, int &wlindex, int &wmsize, int &wmindex);
void set_src_data (Function *func, int vis_bits, int cmpline_visible,
int funcline_visible);
void set_dis_data (Function *func, int vis_bits, int cmpline_visible,
int src_visible, bool hex_vis, bool func_scope,
int funcline_visible);
void set_src (Anno_Types type, DbeLine *dbeline);
void set_dis (DbeInstr *instr, Anno_Types type, bool nextFile, char *dis_str);
void set_MPSlave ();
void set_one (Hist_data::HistItem *org_item, Anno_Types type, const char *text);
void set_ComCom (int vis_bits);
virtual char *get_disasm (uint64_t inst_address, uint64_t end_address,
uint64_t start_address, uint64_t f_offset,
int64_t &inst_size);
Anno_Errors status;
Anno_Errors openSourceFlag;
bool hexVisible; // show hex code in disasm
time_t disMTime; // Creating time for disassembly
time_t stabsMTime; // Creating time for stabs
SourceFile *main_source;
SourceFile *curr_inc; // pointer to include file or NULL
SourceFile *srcContext;
Vector<ComC*> *comComs; // table of compiler comments
Disasm *disasm;
Hist_data *src_items;
Hist_data *dis_items;
Hist_data *data_items;
DbeView * cur_dbev;
TValue *total;
TValue *maximum;
TValue *maximum_inc;
TValue *empty;
int name_idx; // index of name metric in list for src/dis
int size_index; // index of size metric in list for src/dis
int addr_index; // index of address metric in list for src/dis
int curline; // line# of next source line to be processed
int cindex, cline; // index and src line of next compiler-comment
int sindex, sline; // index and src line of next item in src_items
int dindex;
DbeInstr *daddr; // pointer to next DbeInstr with metrics
int mindex; // MP index and src line of next metric-value
int mline; // MP line to be processed by source
char *disPath; // path for disassembly
char *stabsPath; // path for reading stabs
char *stabsTmp; // temporary *.o from *.a
char *disName; // library/path for disassembly
char *stabsName; // library/path for stabs
};
#endif /* _MODULE_H */
|