addrtranslate-bluegene.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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