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 #include "dbe_structs.h"
27 enum cpf_instr_type_t {
28 CPF_INSTR_TYPE_LD = 0, // profiled load instruction
29 CPF_INSTR_TYPE_ST, // profiled store instruction
30 CPF_INSTR_TYPE_PREFETCH, // profiled prefetch instruction
31 CPF_INSTR_TYPE_BRTARGET, // branch target
32 CPF_INSTR_TYPE_UNKNOWN, // unidentified instruction
33 CPF_INSTR_TYPE_NTYPES // total # of instr types
46 template <typename Key_t, typename Value_t> class Map;
56 void new_src_file(SourceFile *source, int lineno, Function *func = NULL);
57 void new_include_file(SourceFile *source, Function *func);
58 void end_include_file(Function *func);
59 void push_src_files(Function *func);
62 Vector<SrcFileInfo*> *stack;
71 DBGD_ERR_CANT_OPEN_FILE,
73 DBGD_ERR_BAD_ELF_FORMAT,
80 static Stabs *NewStabs(char *_path, char *lo_name);
81 Stabs(char *_path, char *_lo_name);
84 bool is_relocatable(){ return isRelocatable; }
85 long long get_textsz() { return textsz; }
86 Platform_t get_platform() { return platform; }
87 WSize_t get_class() { return wsize;}
88 Stab_status get_status() { return status;}
90 Stab_status read_stabs(ino64_t srcInode, Module *module, Vector<ComC*> *comComs, bool readDwarf = false);
91 Stab_status read_archive(LoadObject *lo);
92 bool read_symbols(Vector<Function*> *functions);
93 uint64_t mapOffsetToAddress(uint64_t img_offset);
94 char *sym_name(uint64_t target, uint64_t instr, int flag);
95 Elf *openElf (bool dbg_info = false);
96 void read_hwcprof_info(Module *module);
98 void read_dwarf_from_dot_o(Module *mod);
100 static bool is_fortran(Sp_lang_code lc) { return (lc == Sp_lang_fortran) || (lc == Sp_lang_fortran90); }
101 static Function *find_func(char *fname, Vector<Function*> *functions, bool fortran, bool inner_names=false);
102 Module *append_Module(LoadObject *lo, char *name, int lastMod = 0);
103 Function *append_Function(Module *module, char *fname);
104 Function *append_Function(Module *module, char *linkerName, uint64_t pc);
105 Function *map_PC_to_func(uint64_t pc, uint64_t &low_pc, Vector<Function*> *functions);
106 char *path; // path to the object file
107 char *lo_name; // User name of load object
110 Elf *elfDbg; // ELF with debug info
111 Elf *elfDis; // ELF for disasm
112 Stab_status status; // current stabs status
114 long long textsz; // text segment size
115 Platform_t platform; // Sparc, Sparcv9, Intel
116 WSize_t wsize; // word size: 32 or 64
118 Symbol *last_PC_to_sym;
120 Vector<cpf_stabs_t> analyzerInfoMap; // stabs->section mapping
122 bool check_Comm(Vector<ComC*> *comComs);
123 void check_Info(Vector<ComC*> *comComs);
124 void check_Loop(Vector<ComC*> *comComs);
125 void check_AnalyzerInfo();
126 void append_local_funcs(Module *module, int first_ind);
127 Stab_status srcline_Stabs (Module *module, unsigned int StabSec, unsigned int StabStrSec, bool comdat);
128 Stab_status archive_Stabs (LoadObject *lo, unsigned int StabSec, unsigned int StabStrSec, bool comdat);
130 // Interface with Elf Symbol Table
132 void readSymSec(unsigned int sec, Elf *elf);
134 void get_save_addr(bool need_swap_endian);
135 Symbol *map_PC_to_sym(uint64_t pc);
137 Vector<Symbol*> *SymLst; // list of func symbols
138 Vector<Symbol*> *SymLstByName; // list of func symbols sorted by Name
139 Vector<Reloc*> *RelLst; // list of text relocations
140 Vector<Reloc*> *RelPLTLst; // list of PLT relocations
141 Vector<Symbol*> *LocalLst; // list of local func symbols
142 Vector<char*> *LocalFile; // list of local files
143 Vector<int> *LocalFileIdx; // start index in LocalLst
145 Elf *openElf(char *fname, Stab_status &st);
146 Map<const char*, Symbol*> *get_elf_symbols();
149 bool st_check_symtab, st_check_relocs;
150 Function *createFunction(LoadObject *lo, Module *module, Symbol *sym);
151 void fixSymtabAlias();
153 // Interface with dwarf
156 Vector<Module*> *stabsModules;
157 static char *get_type_name(int t);
160 #endif /* _STABS_H */