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
33 #include "Annotatable.h"
36 #include "Collections.h"
39 #include "LineInformation.h"
41 #include "annotations.h"
43 #include "common/h/pathName.h"
44 #include "common/h/serialize.h"
46 using namespace Dyninst;
47 using namespace Dyninst::SymtabAPI;
50 static SymtabError serr;
53 bool Module::findSymbol(std::vector<Symbol *> &found,
54 const std::string& name,
55 Symbol::SymbolType sType,
59 bool includeUndefined) {
60 unsigned orig_size = found.size();
61 std::vector<Symbol *> obj_syms;
63 if (exec()->findSymbol(obj_syms, name, sType, nameType, isRegex, checkCase, includeUndefined)) {
64 //fprintf(stderr, "%s[%d]: no symbols matching %s found\n", FILE__, __LINE__, name.c_str());
68 for (unsigned i = 0; i < obj_syms.size(); i++) {
69 if (obj_syms[i]->getModule() == this)
70 found.push_back(obj_syms[i]);
73 if (found.size() > orig_size)
79 bool Module::getAllSymbols(std::vector<Symbol *> &found) {
80 unsigned orig_size = found.size();
81 std::vector<Symbol *> obj_syms;
83 if (!exec()->getAllSymbols(obj_syms)) {
84 //fprintf(stderr, "%s[%d]: no symbols matching %s found\n", FILE__, __LINE__, name.c_str());
88 for (unsigned i = 0; i < obj_syms.size(); i++) {
89 if (obj_syms[i]->getModule() == this)
90 found.push_back(obj_syms[i]);
93 if (found.size() > orig_size)
99 const std::string &Module::fileName() const
104 const std::string &Module::fullName() const
109 Symtab *Module::exec() const
114 supportedLanguages Module::language() const
119 bool Module::hasLineInformation()
121 LineInformation *li = NULL;
122 if (getAnnotation(li, ModuleLineInfoAnno))
126 fprintf(stderr, "%s[%d]: weird inconsistency with getAnnotation here\n",
140 bool Module::getAddressRanges(std::vector<pair<Offset, Offset> >&ranges,
141 std::string lineSource, unsigned int lineNo)
143 unsigned int originalSize = ranges.size();
145 LineInformation *lineInformation = getLineInformation();
147 lineInformation->getAddressRanges( lineSource.c_str(), lineNo, ranges );
149 if ( ranges.size() != originalSize )
155 bool Module::getSourceLines(std::vector<Statement *> &lines, Offset addressInRange)
157 unsigned int originalSize = lines.size();
159 LineInformation *lineInformation = getLineInformation();
161 lineInformation->getSourceLines( addressInRange, lines );
163 if ( lines.size() != originalSize )
169 bool Module::getSourceLines(std::vector<LineNoTuple> &lines, Offset addressInRange)
171 unsigned int originalSize = lines.size();
173 LineInformation *lineInformation = getLineInformation();
175 lineInformation->getSourceLines( addressInRange, lines );
177 if ( lines.size() != originalSize )
183 bool Module::getStatements(std::vector<Statement *> &statements)
185 unsigned initial_size = statements.size();
186 LineInformation *li = getLineInformation();
190 //fprintf(stderr, "%s[%d]: WARNING: no line info for module %s\n", FILE__, __LINE__, fileName_.c_str());
191 //annotationsReport();
196 statements.resize(initial_size + li->getSize());
198 int index = initial_size;
200 for (LineInformation::const_iterator i = li->begin();
204 //statements[index].start_addr = (*i).first.first;
205 //statements[index].end_addr = (*i).first.second;
206 statements[index] = const_cast<Statement *>(&(*i).second);
210 for (LineInformation::const_iterator i = li->begin();
214 statements.push_back(const_cast<Statement *>(&(i->second)));
217 return (statements.size() > initial_size);
220 vector<Type *> *Module::getAllTypes()
222 exec_->parseTypesNow();
224 typeCollection *tc = NULL;
225 if (!getAnnotation(tc, ModuleTypeInfoAnno))
231 fprintf(stderr, "%s[%d]: failed to getAnnotation here\n", FILE__, __LINE__);
235 return tc->getAllTypes();
238 vector<pair<string, Type *> > *Module::getAllGlobalVars()
240 exec_->parseTypesNow();
242 typeCollection *tc = NULL;
243 if (!getAnnotation(tc, ModuleTypeInfoAnno))
249 fprintf(stderr, "%s[%d]: failed to addAnnotation here\n", FILE__, __LINE__);
253 return tc->getAllGlobalVariables();
256 typeCollection *Module::getModuleTypes()
258 exec_->parseTypesNow();
259 return getModuleTypesPrivate();
262 typeCollection *Module::getModuleTypesPrivate()
264 typeCollection *tc = NULL;
265 if (!getAnnotation(tc, ModuleTypeInfoAnno))
273 bool Module::findType(Type *&type, std::string name)
275 typeCollection *tc = getModuleTypes();
276 if (!tc) return false;
278 type = tc->findType(name);
286 bool Module::findVariableType(Type *&type, std::string name)
288 typeCollection *tc = getModuleTypes();
289 if (!tc) return false;
291 type = tc->findVariableType(name);
300 bool Module::setLineInfo(LineInformation *lineInfo)
302 LineInformation *li = NULL;
304 if (!getAnnotation(li, ModuleLineInfoAnno))
311 if (!addAnnotation(lineInfo, ModuleLineInfoAnno))
321 fprintf(stderr, "%s[%d]: REMOVED DELETE\n", FILE__, __LINE__);
325 if (!addAnnotation(lineInfo, ModuleLineInfoAnno))
327 fprintf(stderr, "%s[%d]: failed to add lineInfo annotation\n", FILE__, __LINE__);
334 LineInformation *Module::getLineInformation()
336 if (!exec_->isLineInfoValid_)
338 //fprintf(stderr, "%s[%d]: TRIGGERING FL INFO PARSE\n", FILE__, __LINE__);
339 exec_->parseLineInformation();
342 if (!exec_->isLineInfoValid_)
344 fprintf(stderr, "%s[%d]: FIXME\n", FILE__, __LINE__);
348 LineInformation *li = NULL;
349 if (getAnnotation(li, ModuleLineInfoAnno))
353 fprintf(stderr, "%s[%d]: weird inconsistency with getAnnotation here\n",
360 fprintf(stderr, "%s[%d]: EMPTY LINE INFO ANNO\n", FILE__, __LINE__);
368 bool Module::findLocalVariable(std::vector<localVar *>&vars, std::string name)
370 std::vector<Function *>mod_funcs;
372 if (!exec_->getAllFunctions(mod_funcs))
377 unsigned origSize = vars.size();
379 for (unsigned int i = 0; i < mod_funcs.size(); i++)
381 mod_funcs[i]->findLocalVariable(vars, name);
384 if (vars.size() > origSize)
390 Module::Module(supportedLanguages lang, Offset adr,
391 std::string fullNm, Symtab *img) :
397 fileName_ = extract_pathname_tail(fullNm);
403 language_(lang_Unknown),
409 Module::Module(const Module &mod) :
412 MODULE_ANNOTATABLE_CLASS(),
413 fileName_(mod.fileName_),
414 fullName_(mod.fullName_),
415 language_(mod.language_),
419 // Copy annotations here or no?
424 LineInformation *li = NULL;
425 if (getAnnotation(li, ModuleLineInfoAnno))
429 if (!removeAnnotation(ModuleLineInfoAnno))
431 fprintf(stderr, "%s[%d]: FIXME: failed to remove LineInfo\n",
436 fprintf(stderr, "%s[%d]: removed delete for %p\n", FILE__, __LINE__, li);
441 typeCollection *tc = NULL;
442 if (getAnnotation(tc, ModuleTypeInfoAnno))
446 if (!removeAnnotation(ModuleTypeInfoAnno))
448 fprintf(stderr, "%s[%d]: FIXME: failed to remove LineInfo\n",
457 bool Module::isShared() const
459 return exec_->getObjectType() == obj_SharedLib;
462 bool Module::getAllSymbolsByType(std::vector<Symbol *> &found, Symbol::SymbolType sType)
464 unsigned orig_size = found.size();
465 std::vector<Symbol *> obj_syms;
467 if (!exec()->getAllSymbolsByType(obj_syms, sType))
470 for (unsigned i = 0; i < obj_syms.size(); i++)
472 if (obj_syms[i]->getModule() == this)
473 found.push_back(obj_syms[i]);
476 if (found.size() > orig_size)
481 serr = No_Such_Symbol;
485 bool Module::getAllFunctions(std::vector<Function *> &ret)
487 return exec()->getAllFunctions(ret);
490 bool Module::operator==(Module &mod)
492 LineInformation *li = NULL;
493 LineInformation *li_src = NULL;
494 bool get_anno_res = false, get_anno_res_src = false;
495 get_anno_res = getAnnotation(li, ModuleLineInfoAnno);
496 get_anno_res_src = mod.getAnnotation(li_src, ModuleLineInfoAnno);
498 if (get_anno_res != get_anno_res_src)
500 fprintf(stderr, "%s[%d]: weird inconsistency with getAnnotation here\n",
509 fprintf(stderr, "%s[%d]: weird inconsistency with getAnnotation here\n",
514 if (li->getSize() != li_src->getSize())
524 fprintf(stderr, "%s[%d]: weird inconsistency with getAnnotation here\n",
530 if (exec_ && !mod.exec_) return false;
531 if (!exec_ && mod.exec_) return false;
534 if (exec_->file() != mod.exec_->file()) return false;
535 if (exec_->name() != mod.exec_->name()) return false;
539 (language_==mod.language_)
540 && (addr_==mod.addr_)
541 && (fullName_==mod.fullName_)
542 && (fileName_==mod.fileName_)
546 bool Module::setName(std::string newName)
549 fileName_ = extract_pathname_tail(fullName_);
553 void Module::setLanguage(supportedLanguages lang)
558 Offset Module::addr() const
563 bool Module::setDefaultNamespacePrefix(string str)
565 return exec_->setDefaultNamespacePrefix(str);
568 bool Module::findVariablesByName(std::vector<Variable *> &ret, const std::string& name,
573 std::vector<Variable *> tmp;
575 if (!exec()->findVariablesByName(tmp, name, nameType, isRegex, checkCase)) {
578 for (unsigned i = 0; i < tmp.size(); i++) {
579 if (tmp[i]->getModule() == this) {
580 ret.push_back(tmp[i]);
587 #if !defined(SERIALIZATION_DISABLED)
588 Serializable * Module::serialize_impl(SerializerBase *sb, const char *tag) THROW_SPEC (SerializerError)
590 ifxml_start_element(sb, tag);
591 gtranslate(sb, fileName_, "fileName");
592 gtranslate(sb, fullName_, "fullName");
593 gtranslate(sb, addr_, "Address");
594 gtranslate(sb, language_, supportedLanguages2Str, "Language");
595 ifxml_end_element(sb, tag);
599 SerContextBase *scb = sb->getContext();
602 fprintf(stderr, "%s[%d]: SERIOUS: FIXME\n", FILE__, __LINE__);
606 SerContext<Symtab> *scs = dynamic_cast<SerContext<Symtab> *>(scb);
610 fprintf(stderr, "%s[%d]: SERIOUS: FIXME\n", FILE__, __LINE__);
614 Symtab *st = scs->getScope();
618 fprintf(stderr, "%s[%d]: FIXME\n", FILE__, __LINE__);
627 Serializable *Statement::serialize_impl(SerializerBase *sb, const char *tag) THROW_SPEC(SerializerError)
629 ifxml_start_element(sb, tag);
630 gtranslate(sb, file_, "file");
631 gtranslate(sb, line_, "line");
632 gtranslate(sb, column, "column");
633 gtranslate(sb, start_addr_, "startAddress");
634 gtranslate(sb, end_addr_, "endAddress");
635 ifxml_end_element(sb, tag);
641 Serializable *Module::serialize_impl(SerializerBase *, const char *) THROW_SPEC (SerializerError)
646 Serializable *Statement::serialize_impl(SerializerBase *, const char *) THROW_SPEC(SerializerError)