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. */
24 // A Module object represents a .o file that was used to build up a segement.
25 // Its main function is to compute source and disassembly annotations
26 // Text reordering and/or function outlining imply that a module may
30 #include "Hist_data.h"
32 #define MOD_FLAG_UNKNOWN 0x01
43 template <class ITEM> class Vector;
57 contains (InlinedSubr *p)
59 return low_pc <= p->low_pc && high_pc >= p->high_pc;
63 contains (uint64_t pc)
65 return low_pc <= pc && high_pc > pc;
69 class Module : public HistableFile
72 // Annotated Source or Disassembly
89 // The following enums are duplicated in Java
105 virtual int64_t get_size ();
106 virtual void set_name (char *str);
107 virtual Vector<Histable*> *get_comparable_objs ();
108 virtual int readFile ();
110 virtual Histable_type
123 set_file_name (char *fnm)
130 char *anno_str (char *fnm = NULL);
132 // generate annotated source/disassembly data
133 Hist_data *get_data (DbeView *dbev, MetricList *mlist,
134 Histable::Type type, TValue *ftotal, SourceFile *srcFile,
135 Function *func, Vector<int> *marks, int threshold,
136 int vis_bits, int src_visible, bool hex_visible,
137 bool func_scope, bool src_only,
138 Vector<int_pair_t> *marks2d = NULL,
139 Vector<int_pair_t> *marks2d_inc = NULL);
141 Vector<uint64_t> *getAddrs (Function *func);
142 SourceFile *setIncludeFile (char *includeFile);
157 getResolvedObjectPath ()
159 return stabsPath ? stabsPath : get_name ();
169 void read_stabs (bool all = true);
170 void dump_dataobjects (FILE *out);
171 DataObject *get_dobj (uint32_t dtype_id);
172 void reset_datatypes ();
173 void read_hwcprof_info ();
175 SourceFile *findSource (const char *fname, bool create);
176 bool openStabs (bool all = true);
177 LoadObject *createLoadObject (const char *lo_name);
178 JMethod *find_jmethod (const char *nm, const char *sig);
180 unsigned int flags; // flags used for marking traversals
181 Sp_lang_code lang_code; // What is source lang. in module
182 char *file_name; // Full path to actual source file
183 Vector<Function*> *functions; // Unordered list of functions
184 LoadObject *loadobject; // Parent loadobject
185 LoadObject *dot_o_file; // The .o file with debug information
186 unsigned fragmented; // -xF used when compiling module
187 int real_timestamp; // Linked timestamp from N_OPT stab
188 int curr_timestamp; // Current object timestamp from N_OPT stab
189 char *comp_flags; // compiler flags used to compile module
190 char *comp_dir; // directory used to compile module
191 char *linkerStabName; // Name from 'N_UNDF' stab
192 Stabs *objStabs; // stabs of object file
196 uint64_t hdrOffset; // offset in .debug_info
197 unsigned hwcprof; // hwcprof info status
198 Vector<inst_info_t*> *infoList; // merged list
199 Vector<memop_info_t*> ldMemops; // load instructions
200 Vector<memop_info_t*> stMemops; // store instructions
201 Vector<memop_info_t*> pfMemops; // prefetch instructions
202 Vector<target_info_t*> bTargets; // branch targets
203 Vector<datatype_t*> *datatypes; // object type descriptors
204 Vector<SourceFile*> *includes;
205 Module *indexStabsLink; // correspondent module for the .o file
206 InlinedSubr *inlinedSubr;
209 void removeStabsTmp (); // Remove temporary *.o (got from *.a)
211 // Check timestamp, warn users if src/dis/stabs later than exp.
212 Anno_Errors checkTimeStamp (bool chkDis);
214 // Set paths for reading Stabs and Symbols
215 bool read_ar (int ar, int obj, char *obj_base);
218 // Open appropriate symbol tables, construct set of PC ranges,
219 // and maps to source lines for each PC
220 Stabs *openDebugInfo ();
222 // Construct PC index table
225 // Compute data--scan data to compute metrics per-src-line/dis-line
226 bool computeMetrics (DbeView *dbev, Function *func, MetricList *mlist,
227 Histable::Type type, bool src_metric,
228 bool func_scope, SourceFile *source);
230 void init_index (Hist_data *witems, int &wlindex, int &wmsize, int &wmindex);
232 void set_src_data (Function *func, int vis_bits, int cmpline_visible,
233 int funcline_visible);
234 void set_dis_data (Function *func, int vis_bits, int cmpline_visible,
235 int src_visible, bool hex_vis, bool func_scope,
236 int funcline_visible);
237 void set_src (Anno_Types type, DbeLine *dbeline);
238 void set_dis (DbeInstr *instr, Anno_Types type, bool nextFile, char *dis_str);
240 void set_one (Hist_data::HistItem *org_item, Anno_Types type, const char *text);
241 void set_ComCom (int vis_bits);
243 virtual char *get_disasm (uint64_t inst_address, uint64_t end_address,
244 uint64_t start_address, uint64_t f_offset,
248 Anno_Errors openSourceFlag;
249 bool hexVisible; // show hex code in disasm
250 time_t disMTime; // Creating time for disassembly
251 time_t stabsMTime; // Creating time for stabs
252 SourceFile *main_source;
253 SourceFile *curr_inc; // pointer to include file or NULL
254 SourceFile *srcContext;
255 Vector<ComC*> *comComs; // table of compiler comments
257 Hist_data *src_items;
258 Hist_data *dis_items;
259 Hist_data *data_items;
265 int name_idx; // index of name metric in list for src/dis
266 int size_index; // index of size metric in list for src/dis
267 int addr_index; // index of address metric in list for src/dis
269 int curline; // line# of next source line to be processed
270 int cindex, cline; // index and src line of next compiler-comment
271 int sindex, sline; // index and src line of next item in src_items
273 DbeInstr *daddr; // pointer to next DbeInstr with metrics
274 int mindex; // MP index and src line of next metric-value
275 int mline; // MP line to be processed by source
277 char *disPath; // path for disassembly
278 char *stabsPath; // path for reading stabs
279 char *stabsTmp; // temporary *.o from *.a
280 char *disName; // library/path for disassembly
281 char *stabsName; // library/path for stabs
284 #endif /* _MODULE_H */