addrtranslate-bluegene.C

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 #include "common/h/addrtranslate.h"
00032 #include "common/src/addrtranslate-sysv.h"
00033 #include "common/h/linuxKludges.h"
00034 
00035 #include <linux/limits.h>
00036 
00037 #include <sys/ptrace.h>
00038 #include <sys/types.h>
00039 #include <sys/wait.h>
00040 #include <unistd.h> 
00041 
00042 #include <cstdlib>
00043 #include <cerrno>
00044 #include <sstream>
00045 using namespace std;
00046 
00047 using namespace Dyninst;
00048 
00049 ProcessReader *AddressTranslateSysV::createDefaultDebugger(int) {
00050   return NULL;
00051 }
00052 
00053 
00054 bool AddressTranslateSysV::setAddressSize() 
00055 {
00056   address_size = sizeof(void *);
00057   translate_printf("[%s:%u] - Set address size to %z.\n", __FILE__, __LINE__, address_size);
00058   return true;
00059 }
00060 
00061 
00062 static string deref_link(const char *path) {
00063   char buffer[PATH_MAX];
00064   char *p = realpath(path, buffer);
00065   return p ? string(p) : string(path);
00066 }
00067 
00068 
00069 string AddressTranslateSysV::getExecName() 
00070 {
00071   if (exec_name.empty())
00072   {
00073      ostringstream linkstream;
00074      linkstream << "/jobs/" << getenv("BG_JOBID") << "/exe";
00075      
00076      string linkname(linkstream.str());
00077      exec_name = deref_link(linkname.c_str());
00078      
00079      translate_printf("[%s:%u] - Got excutable path from %s: '%s'\n",
00080                       __FILE__, __LINE__, linkname.c_str(), exec_name.c_str());
00081   }
00082   return exec_name;  
00083 }
00084 
00085 
00086 LoadedLib *AddressTranslateSysV::getAOut()
00087 {
00088    return new LoadedLib(getExecName(), 0);
00089 }
00090 
00091 
00092 bool AddressTranslateSysV::setInterpreter() 
00093 {
00094   const char *fullpath = getExecName().c_str();
00095   FCNode *exe = files.getNode(fullpath, symfactory);
00096   if (!exe) {
00097     translate_printf("[%s:%u] - Unable to get FCNode: '%s'\n", __FILE__, __LINE__, fullpath);
00098     return false;
00099   }
00100 
00101   translate_printf("[%s:%u] - About to set interpreter.\n", __FILE__, __LINE__);
00102   string interp_name = exe->getInterpreter();
00103   if (interp_name == std::string("")) {
00104      return false;
00105   }
00106   interpreter = files.getNode(interp_name, symfactory);
00107   if (interpreter)
00108      interpreter->markInterpreter();
00109   translate_printf("[%s:%u] - Set interpreter name: '%s'\n", __FILE__, __LINE__, interp_name.c_str());
00110 
00111   return true;
00112 }
00113 
00114 #if defined(os_bg_compute)
00115 
00116 #include <elf.h>
00117 #include <link.h>
00118 extern char **environ;
00119 
00120 bool AddressTranslateSysV::setInterpreterBase() {
00121     if (set_interp_base) return true;
00122 
00123     Elf32_auxv_t *auxv;
00124     char **env_end = environ;
00125     while (*env_end++ != NULL);
00126     
00127     auxv = (Elf32_auxv_t *) env_end;
00128     for (;;) {
00129        if (auxv->a_type == AT_BASE) {
00130           interpreter_base = auxv->a_un.a_val;
00131           set_interp_base = true;
00132           return true;
00133        }
00134        if (auxv->a_type == AT_NULL) {
00135           set_interp_base = true;
00136           interpreter_base = 0;
00137           return 0;
00138        }
00139        auxv++;
00140     }
00141 
00142 }
00143 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1