2 * Copyright (c) 1996-2009 Barton P. Miller
4 * We provide the Paradyn Parallel Performance Tools (below
5 * described as "Paradyn") on an AS IS basis, and do not warrant its
6 * validity or performance. We reserve the right to update, modify,
7 * or discontinue this software at any time. We shall have no
8 * obligation to supply such updates or modifications or any other
9 * form of support to you.
11 * By your use of Paradyn, you understand and agree that we (or any
12 * other person or entity with proprietary rights in Paradyn) are
13 * under no obligation to provide either maintenance services,
14 * update services, notices of latent defects, or correction of
15 * defects for Paradyn.
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 /************************************************************************
33 * $Id: Symbol.h,v 1.20 2008/11/03 15:19:24 jaw Exp $
34 * Symbol.h: symbol table objects.
35 ************************************************************************/
37 #if !defined(_Symbol_h_)
41 /************************************************************************
43 ************************************************************************/
46 #include "Annotatable.h"
47 #include "Serialization.h"
49 #ifndef CASE_RETURN_STR
50 #define CASE_RETURN_STR(x) case x: return #x
59 class localVarCollection;
68 /************************************************************************
70 ************************************************************************/
72 class Symbol : public Serializable,
73 public AnnotatableSparse
75 friend class typeCommon;
79 friend class Aggregate;
80 friend class relocationEntry;
82 friend std::string parseStabString(Module *, int linenum, char *, int,
98 static const char *symbolType2Str(SymbolType t);
107 static const char *symbolLinkage2Str(SymbolLinkage t);
116 static const char *symbolTag2Str(SymbolTag t);
118 enum SymbolVisibility {
125 static const char *symbolVisibility2Str(SymbolVisibility t);
127 SYMTAB_EXPORT Symbol();
129 SYMTAB_EXPORT static Symbol *magicEmitElfSymbol();
131 SYMTAB_EXPORT Symbol (const std::string name,
136 Module *module = NULL,
144 SYMTAB_EXPORT ~Symbol();
146 SYMTAB_EXPORT bool operator== (const Symbol &) const;
148 /***********************************************************
149 Name Output Functions
150 ***********************************************************/
151 SYMTAB_EXPORT const std::string& getMangledName () const;
152 SYMTAB_EXPORT const std::string& getPrettyName() const;
153 SYMTAB_EXPORT const std::string& getTypedName() const;
155 SYMTAB_EXPORT Module *getModule() const { return module_; }
156 SYMTAB_EXPORT Symtab *getSymtab() const;
157 SYMTAB_EXPORT SymbolType getType () const { return type_; }
158 SYMTAB_EXPORT SymbolLinkage getLinkage () const { return linkage_; }
159 SYMTAB_EXPORT Offset getOffset() const { return offset_; }
160 SYMTAB_EXPORT Offset getPtrOffset() const { return ptr_offset_; }
161 SYMTAB_EXPORT unsigned getSize() const { return size_; }
162 SYMTAB_EXPORT Region *getRegion() const { return region_; }
164 SYMTAB_EXPORT bool isInDynSymtab() const { return (type_ != ST_DELETED) && isDynamic_; }
165 SYMTAB_EXPORT bool isInSymtab() const { return (type_ != ST_DELETED) && !isDynamic_; }
166 SYMTAB_EXPORT bool isAbsolute() const { return isAbsolute_; }
167 SYMTAB_EXPORT bool isCommonStorage() const { return isCommonStorage_; }
169 SYMTAB_EXPORT bool isFunction() const;
170 SYMTAB_EXPORT bool setFunction(Function * func);
171 SYMTAB_EXPORT Function * getFunction() const;
173 SYMTAB_EXPORT bool isVariable() const;
174 SYMTAB_EXPORT bool setVariable(Variable *var);
175 SYMTAB_EXPORT Variable * getVariable() const;
177 SYMTAB_EXPORT SymbolVisibility getVisibility() const { return visibility_; }
179 SYMTAB_EXPORT int getIndex() const { return index_; }
180 SYMTAB_EXPORT bool setIndex(int index) { index_ = index; return true; }
181 SYMTAB_EXPORT int getStrIndex() const { return strindex_; }
182 SYMTAB_EXPORT bool setStrIndex(int strindex) { strindex_ = strindex; return true; }
183 SYMTAB_EXPORT void setReferringSymbol (Symbol *referringSymbol);
184 SYMTAB_EXPORT Symbol* getReferringSymbol ();
186 //////////////// Modification
187 SYMTAB_EXPORT bool setOffset (Offset newOffset);
188 SYMTAB_EXPORT bool setPtrOffset (Offset newOffset);
189 SYMTAB_EXPORT bool setSize(unsigned ns);
190 SYMTAB_EXPORT bool setModule(Module *mod);
192 SYMTAB_EXPORT bool setMangledName(std::string &name);
193 SYMTAB_EXPORT bool setPrettyName(std::string &name);
194 SYMTAB_EXPORT bool setTypedName(std::string &name);
196 SYMTAB_EXPORT bool setSymbolType(SymbolType sType);
198 SYMTAB_EXPORT SymbolTag tag () const;
199 SYMTAB_EXPORT bool setDynamic(bool d) { isDynamic_ = d; return true;}
200 SYMTAB_EXPORT bool setAbsolute(bool a) { isAbsolute_ = a; return true; }
201 SYMTAB_EXPORT bool setCommonStorage(bool cs) { isCommonStorage_ = cs; return true; }
203 SYMTAB_EXPORT bool setVersionFileName(std::string &fileName);
204 SYMTAB_EXPORT bool setVersions(std::vector<std::string> &vers);
205 SYMTAB_EXPORT bool setVersionNum(unsigned verNum);
207 SYMTAB_EXPORT bool getVersionFileName(std::string &fileName);
208 SYMTAB_EXPORT bool getVersions(std::vector<std::string> *&vers);
209 SYMTAB_EXPORT bool getVersionNum(unsigned &verNum);
212 std::ostream& operator<< (std::ostream &os, const Symbol &s);
214 //////////// DEPRECATED
215 SYMTAB_EXPORT Region *getSec () const { return getRegion(); }
216 SYMTAB_EXPORT Offset getAddr () const { return getOffset(); }
217 SYMTAB_EXPORT const std::string&getModuleName () const;
218 SYMTAB_EXPORT const std::string &getName() const { return getMangledName(); }
219 SYMTAB_EXPORT bool setAddr (Offset newAddr) { return setOffset(newAddr); }
220 SYMTAB_EXPORT bool setModuleName(std::string) { return false; }
224 static std::string emptyString;
225 int getInternalType() { return internal_type_; }
226 void setInternalType(int i) { internal_type_ = i; }
233 SymbolLinkage linkage_;
234 SymbolVisibility visibility_;
236 Offset ptr_offset_; // Function descriptor offset. Not available on all platforms.
239 unsigned size_; // size of this symbol. This is NOT available on all platforms.
244 Aggregate * aggregate_; // Pointer to Function or Variable container, if appropriate.
246 std::string mangledName_;
247 std::string prettyName_;
248 std::string typedName_;
254 bool isCommonStorage_;
256 std::vector<std::string> verNames_;
258 void restore_module_and_region(SerializerBase *,
259 std::string &, Offset) THROW_SPEC (SerializerError);
263 SYMTAB_EXPORT Serializable * serialize_impl(SerializerBase *,
264 const char *tag = "Symbol") THROW_SPEC (SerializerError);
267 class LookupInterface
270 SYMTAB_EXPORT LookupInterface();
271 SYMTAB_EXPORT virtual bool getAllSymbolsByType(std::vector<Symbol *> &ret,
272 Symbol::SymbolType sType) = 0;
273 SYMTAB_EXPORT virtual bool findSymbolByType(std::vector<Symbol *> &ret,
274 const std::string name,
275 Symbol::SymbolType sType,
276 bool isMangled = false,
277 bool isRegex = false,
278 bool checkCase = false) = 0;
279 SYMTAB_EXPORT virtual bool findType(Type *&type, std::string name) = 0;
280 SYMTAB_EXPORT virtual bool findVariableType(Type *&type, std::string name)= 0;
282 SYMTAB_EXPORT virtual ~LookupInterface();
285 std::ostream& operator<< (std::ostream &os, const Symbol &s);
287 }//namespace SymtabAPI
290 #endif /* !defined(_Symbol_h_) */