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. */
25 // The Histable class hierarchy is used to build up a representation of
26 // the codeobjects (functions, modules, loadObjects, etc.) that make up the
27 // text address space of a program. The hierarchy is as follows:
30 // LoadObject (public)
34 // Dataobjects are objects from the data address space of a program.
35 // The reason for calling the base class "Histable" is because these
36 // objects are all valid objects for computing histograms on.
38 // A Histable object represents an object in the program text or data.
40 #include "dbe_structs.h"
42 #include "Expression.h"
49 template <class ITEM> class Vector;
53 friend class Hist_data;
58 INSTR, LINE, FUNCTION, MODULE, LOADOBJECT,
59 EADDR, MEMOBJ, INDEXOBJ, PAGE, DOBJECT,
60 SOURCEFILE, IOACTFILE, IOACTVFD, IOCALLSTACK,
61 HEAPCALLSTACK, EXPERIMENT, OTHER
64 // NameFormat for functions and function based objects
68 NA, LONG, SHORT, MANGLED, SONAME = 0x10
72 make_fmt (int fnfmt, bool sofmt = false)
74 return (NameFormat) (sofmt ? fnfmt | SONAME : fnfmt);
78 fname_fmt (NameFormat fmt)
80 return (fmt & ~SONAME);
84 soname_fmt (NameFormat fmt)
86 return (fmt & SONAME);
95 get_name (NameFormat = NA)
97 return name; // Return the name of the object
101 set_name (char * _name)
106 virtual void set_name_from_context (Expression::Context *) { }
107 virtual Type get_type () = 0;
121 virtual Vector<Histable*> *get_comparable_objs ();
122 Histable *get_compare_obj ();
125 convertto (Type, Histable* = NULL)
130 Vector<Histable*> *comparable_objs;
131 int64_t id; // A unique id of this object, within its specific Type
134 char *name; // Object name
136 void update_comparable_objs ();
137 void dump_comparable_objs ();
138 char *type_to_string ();
139 void delete_comparable_objs ();
142 typedef Histable::Type Histable_type;
144 // An Other object represents some random histable object
145 class Other : public Histable
159 // DbeInstr represents an instruction.
161 // Used by Analyzer for: Disassembly, PCs, Timeline, and Event tabs.
163 class DbeInstr : public Histable
166 DbeInstr (uint64_t _id, int _flags, Function *_func, uint64_t _addr);
174 virtual char *get_name (NameFormat = NA);
175 virtual int64_t get_size ();
176 virtual uint64_t get_addr ();
177 virtual Histable *convertto (Type type, Histable *obj = NULL);
178 DbeLine *mapPCtoLine (SourceFile *sf);
179 void add_inlined_info (StringBuilder *sb);
180 char *get_descriptor ();
181 int pc_cmp (DbeInstr *instr2);
184 uint64_t img_offset; // file offset of the image
193 NameFormat current_name_format;
196 class DbeEA : public Histable
200 DbeEA (DataObject *_dobj, Vaddr _eaddr)
224 virtual char *get_name (NameFormat = NA);
225 virtual Histable *convertto (Type type, Histable *obj = NULL);
231 // DbeLine represents a line in a source file.
233 // For each top-level DbeLine instance, there are three DbeLine subtypes:
235 // A The top-level DbeLine is associated with a sourceFile & lineno, but
236 // not any particular function. This form of DbeLine is used
237 // to represent Analyzer Source tab lines.
239 // B Function-specific lines, those associated with a function in addition
240 // to the the sourceFile & lineno, are stored in a linked list.
241 // (see "dbeline_func_next").
242 // This subtype is used to differentiate a line found in #included source
243 // that is referenced by multiple functions.
244 // It is used in the Analyzer Lines tab.
246 // C Function-specific "lines" that don't have line number info are referenced
247 // from each linked-list element's "dbeline_func_pseudo" field.
248 // This subtype is needed when a binary doesn't identify line numbers.
249 // It is used in the Analyzer Lines tab.
251 // When the user switches views between tabs, a selected object in the old
252 // tab must be translated to an approprate object in the new tab.
253 // When switching to the Source Tab, the top-level DbeLine (dbeline_base)
255 // When switching to the Lines Tab, a function-specific dbeline_func_*
259 class DbeLine : public Histable
268 DbeLine (Function *_func, SourceFile *sf, int _lineno);
270 virtual char *get_name (NameFormat = NA);
271 virtual int64_t get_size ();
272 virtual uint64_t get_addr ();
273 virtual Histable *convertto (Type type, Histable *obj = NULL);
275 void init_Offset (uint64_t p_offset);
276 int line_cmp (DbeLine *dbl);
293 return (flags & flag) != 0;
296 Function *func; // note: will be NULL in the base (head) dbeline
299 SourceFile *sourceFile; // Default source file
300 SourceFile *include; // included source file or NULL
302 DbeLine *dbeline_base;
303 // Head of list, a dbeline associated with sourceFile & lineno, but not func:
304 // dbeline_base->lineno: non-zero
305 // dbeline_base->sourceFile: non-null
306 // dbeline_base->func: NULL
307 // dbeline_base->dbeline_base: this
308 // dbeline_base->dbeline_func_next: first func-specific dbeline
310 DbeLine *dbeline_func_next;
311 // If non-null, pointer to a function-specific dbeline where:
312 // dbeline_func_next->lineno: same as dbeline_base->lineno
313 // dbeline_func_next->sourceFile: same as dbeline_base->sourceFile
314 // dbeline_func_next->func: pointer to unique function
315 // dbeline_func_next->dbeline_base: head of the linked list.
316 // dbeline_func_next->dbeline_func_next: next function-specific dbeline.
319 int current_name_format;
324 class HistableFile : public Histable, public DbeMessages
333 #endif /* _HISTABLE_H */