2 * See the dyninst/COPYRIGHT file for copyright information.
4 * We provide the Paradyn Tools (below described as "Paradyn")
5 * on an AS IS basis, and do not warrant its validity or performance.
6 * We reserve the right to update, modify, or discontinue this
7 * software at any time. We shall have no obligation to supply such
8 * updates or modifications or any other form of support to you.
10 * By your use of Paradyn, you understand and agree that we (or any
11 * other person or entity with proprietary rights in Paradyn) are
12 * under no obligation to provide either maintenance services,
13 * update services, notices of latent defects, or correction of
14 * defects for Paradyn.
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35 #include "Aggregate.h"
39 #include "annotations.h"
44 using namespace Dyninst;
45 using namespace SymtabAPI;
47 #if !defined(SERIALIZATION_DISABLED)
48 bool addSymID(SerializerBase *sb, Symbol *sym, Address id)
54 SerContextBase *scb = sb->getContext();
57 fprintf(stderr, "%s[%d]: SERIOUS: FIXME\n", FILE__, __LINE__);
61 SerContext<Symtab> *scs = dynamic_cast<SerContext<Symtab> *>(scb);
65 fprintf(stderr, "%s[%d]: SERIOUS: FIXME\n", FILE__, __LINE__);
69 Symtab *st = scs->getScope();
73 fprintf(stderr, "%s[%d]: SERIOUS: FIXME\n", FILE__, __LINE__);
77 dyn_hash_map<Address, Symbol *> *smap = NULL;
79 if (!st->getAnnotation(smap, IdToSymAnno))
81 smap = new dyn_hash_map<Address, Symbol *>();
83 if (!st->addAnnotation(smap, IdToSymAnno))
85 fprintf(stderr, "%s[%d]: ERROR: failed to add IdToSymMap anno to Symtab\n",
93 if (serializer_debug_flag())
95 dyn_hash_map<Address, Symbol *>::iterator iter = smap->find(id);
96 if (iter != smap->end())
98 fprintf(stderr, "%s[%d]: WARNING: already have mapping for IdToSym\n",
107 Symbol * getSymForID(SerializerBase *sb, Address id)
112 SerContextBase *scb = sb->getContext();
115 fprintf(stderr, "%s[%d]: SERIOUS: FIXME\n", FILE__, __LINE__);
119 SerContext<Symtab> *scs = dynamic_cast<SerContext<Symtab> *>(scb);
123 fprintf(stderr, "%s[%d]: SERIOUS: FIXME\n", FILE__, __LINE__);
127 Symtab *st = scs->getScope();
131 fprintf(stderr, "%s[%d]: SERIOUS: FIXME\n", FILE__, __LINE__);
135 dyn_hash_map<Address, Symbol *> *smap = NULL;
136 if (!st->getAnnotation(smap, IdToSymAnno))
138 fprintf(stderr, "%s[%d]: ERROR: failed to find IdToSymMap anno on Symtab\n",
143 dyn_hash_map<Address, Symbol *>::iterator iter = smap->find(id);
144 if (iter == smap->end())
146 fprintf(stderr, "%s[%d]: ERROR: failed to find id %p in IdToSymMap\n",
147 FILE__, __LINE__, (void *)id);
153 bool addSymID(SerializerBase *, Symbol *, Address)
158 Symbol * getSymForID(SerializerBase *, Address)
164 Symbol *Symbol::magicEmitElfSymbol() {
165 // I have no idea why this is the way it is,
166 // but emitElf needs it...
167 return new Symbol("",
179 SYMTAB_EXPORT const string& Symbol::getMangledName() const
184 SYMTAB_EXPORT const string& Symbol::getPrettyName() const
189 SYMTAB_EXPORT const string& Symbol::getTypedName() const
194 bool Symbol::setOffset(Offset newOffset)
200 bool Symbol::setPtrOffset(Offset newOffset)
202 ptr_offset_ = newOffset;
206 bool Symbol::setLocalTOC(Offset toc)
212 SYMTAB_EXPORT bool Symbol::setModule(Module *mod)
218 SYMTAB_EXPORT bool Symbol::isFunction() const
220 return (getFunction() != NULL);
223 SYMTAB_EXPORT bool Symbol::setFunction(Function *func)
229 SYMTAB_EXPORT Function * Symbol::getFunction() const
231 if (aggregate_ == NULL)
233 return dynamic_cast<Function *>(aggregate_);
236 SYMTAB_EXPORT bool Symbol::isVariable() const
238 return (getVariable() != NULL);
241 SYMTAB_EXPORT bool Symbol::setVariable(Variable *var)
247 SYMTAB_EXPORT Variable * Symbol::getVariable() const
249 return dynamic_cast<Variable *>(aggregate_);
252 SYMTAB_EXPORT bool Symbol::setSize(unsigned ns)
258 SYMTAB_EXPORT bool Symbol::setRegion(Region *r)
264 SYMTAB_EXPORT Symbol::SymbolTag Symbol::tag() const
270 SYMTAB_EXPORT bool Symbol::setSymbolType(SymbolType sType)
272 if ((sType != ST_UNKNOWN)&&
273 (sType != ST_FUNCTION)&&
274 (sType != ST_OBJECT)&&
275 (sType != ST_MODULE)&&
276 (sType != ST_NOTYPE))
279 SymbolType oldType = type_;
281 if (module_ && module_->exec())
282 module_->exec()->changeType(this, oldType);
284 // TODO: update aggregate with information
289 SYMTAB_EXPORT bool Symbol::setVersionFileName(std::string &fileName)
291 std::string *fn_p = NULL;
292 if (getAnnotation(fn_p, SymbolFileNameAnno))
296 fprintf(stderr, "%s[%d]: inconsistency here\n", FILE__, __LINE__);
300 fprintf(stderr, "%s[%d]: WARNING, already have filename set for symbol %s\n",
301 FILE__, __LINE__, getMangledName().c_str());
307 // not sure if we need to copy here or not, so let's do it...
308 std::string *fn = new std::string(fileName);
309 if (!addAnnotation(fn, SymbolFileNameAnno))
311 fprintf(stderr, "%s[%d]: failed to add anno here\n", FILE__, __LINE__);
320 SYMTAB_EXPORT bool Symbol::setVersions(std::vector<std::string> &vers)
322 std::vector<std::string> *vn_p = NULL;
323 if (getAnnotation(vn_p, SymbolVersionNamesAnno))
327 fprintf(stderr, "%s[%d]: inconsistency here\n", FILE__, __LINE__);
330 fprintf(stderr, "%s[%d]: WARNING, already have versions set for symbol %s\n", FILE__, __LINE__, getMangledName().c_str());
335 if (!addAnnotation(&vers, SymbolVersionNamesAnno))
337 fprintf(stderr, "%s[%d]: failed to add anno here\n", FILE__, __LINE__);
344 SYMTAB_EXPORT bool Symbol::getVersionFileName(std::string &fileName)
346 std::string *fn_p = NULL;
348 if (getAnnotation(fn_p, SymbolFileNameAnno))
352 fprintf(stderr, "%s[%d]: inconsistency here\n", FILE__, __LINE__);
363 SYMTAB_EXPORT bool Symbol::getVersions(std::vector<std::string> *&vers)
365 std::vector<std::string> *vn_p = NULL;
367 if (getAnnotation(vn_p, SymbolVersionNamesAnno))
371 fprintf(stderr, "%s[%d]: inconsistency here\n", FILE__, __LINE__);
383 SYMTAB_EXPORT bool Symbol::setMangledName(std::string name)
389 Serializable *Symbol::serialize_impl(SerializerBase *, const char *) THROW_SPEC (SerializerError)
394 void Symbol::restore_module_and_region(SerializerBase *, std::string &, Offset) THROW_SPEC (SerializerError)
398 std::ostream& Dyninst::SymtabAPI::operator<< (ostream &os, const Symbol &s)
401 << " mangled=" << s.getMangledName()
402 << " pretty=" << s.getPrettyName()
403 << " module=" << s.module_
404 //<< " type=" << (unsigned) s.type_
405 << " type=" << s.symbolType2Str(s.type_)
406 //<< " linkage=" << (unsigned) s.linkage_
407 << " linkage=" << s.symbolLinkage2Str(s.linkage_)
408 << " offset=0x" << hex << s.offset_ << dec
409 << " size=0x" << hex << s.size_ << dec
410 << " ptr_offset=0x" << hex << s.ptr_offset_ << dec
411 << " localTOC=0x" << hex << s.localTOC_ << dec
412 //<< " tag=" << (unsigned) s.tag_
413 << " tag=" << s.symbolTag2Str(s.tag_)
414 << " isAbs=" << s.isAbsolute_
415 << " isCommon=" << s.isCommonStorage_
416 << (s.isFunction() ? " [FUNC]" : "")
417 << (s.isVariable() ? " [VAR]" : "")
418 << (s.isInSymtab() ? "[STA]" : "[DYN]")
427 ostream & Dyninst::SymtabAPI::operator<< (ostream &s, const ExceptionBlock &eb)
429 s << "tryStart=" << eb.tryStart_
430 << "trySize=" << eb.trySize_
431 << "catchStart=" << eb.catchStart_
432 << "hasTry=" << eb.trySize_ ;
436 bool Symbol::operator==(const Symbol& s) const
438 // explicitly ignore tags when comparing symbols
440 // compare sections by offset, not pointer
441 if (!region_ && s.region_) return false;
442 if (region_ && !s.region_) return false;
445 if (region_->getDiskOffset() != s.region_->getDiskOffset())
449 // compare modules by name, not pointer
450 if (!module_ && s.module_) return false;
451 if (module_ && !s.module_) return false;
454 if (module_->fullName() != s.module_->fullName())
458 return ( (type_ == s.type_)
459 && (linkage_ == s.linkage_)
460 && (offset_ == s.offset_)
461 && (size_ == s.size_)
462 && (isDynamic_ == s.isDynamic_)
463 && (isAbsolute_ == s.isAbsolute_)
464 && (isCommonStorage_ == s.isCommonStorage_)
465 && (versionHidden_ == s.versionHidden_)
466 && (mangledName_ == s.mangledName_)
467 && (prettyName_ == s.prettyName_)
468 && (typedName_ == s.typedName_));
471 Symtab *Symbol::getSymtab() const {
472 return module_->exec();
479 linkage_(SL_UNKNOWN),
480 visibility_(SV_UNKNOWN),
490 mangledName_(Symbol::emptyString),
491 prettyName_(Symbol::emptyString),
492 typedName_(Symbol::emptyString),
496 isCommonStorage_(false),
497 versionHidden_(false)
501 Symbol::Symbol(const std::string& name,
534 isCommonStorage_(cs),
535 versionHidden_(false)
541 std::string *sfa_p = NULL;
543 if (getAnnotation(sfa_p, SymbolFileNameAnno))
545 if (!removeAnnotation(SymbolFileNameAnno))
547 fprintf(stderr, "%s[%d]: failed to remove file name anno\n",
554 void Symbol::setReferringSymbol(Symbol* referringSymbol)
556 referring_= referringSymbol;
559 Symbol* Symbol::getReferringSymbol() {