addrtranslate-solaris.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 <procfs.h>
00032 #include "addrtranslate-sysv.h"
00033 #include "common/h/headers.h"
00034
00035 namespace Dyninst {
00036
00037 class ProcessReaderProc : public ProcessReader {
00038 int as_fd;
00039 int ctl_fd;
00040 bool isStopped;
00041 int pid;
00042 public:
00043 ProcessReaderProc(int pid_);
00044 bool start();
00045 bool ReadMem(Address inTraced, void *inSelf, unsigned amount);
00046 bool GetReg(Dyninst::MachRegister, Dyninst::MachRegisterVal &) {return true;}
00047
00048 bool done();
00049
00050 virtual ~ProcessReaderProc();
00051 };
00052
00053 ProcessReader *AddressTranslateSysV::createDefaultDebugger(int pid)
00054 {
00055 return new ProcessReaderProc(pid);
00056 }
00057
00058 bool AddressTranslateSysV::setInterpreter()
00059 {
00060 char ld_name[128];
00061 bool found = false;
00062 prmap_t map_elm;
00063
00064 if (interpreter)
00065 return true;
00066 setInterpreterBase();
00067
00068
00069 char name[32];
00070 sprintf(name, "/proc/%d/map", pid);
00071 int map_fd = P_open(name, O_RDONLY, 0);
00072 if (map_fd == -1)
00073 return false;
00074
00075 while(read(map_fd, &map_elm, sizeof(map_elm)) == sizeof(map_elm)) {
00076 if (map_elm.pr_vaddr == interpreter_base) {
00077 sprintf(ld_name, "/proc/%d/object/%s", pid, map_elm.pr_mapname);
00078 found = true;
00079 break;
00080 }
00081 }
00082
00083 P_close(map_fd);
00084 if (!found)
00085 return false;
00086
00087 interpreter = files.getNode(ld_name, symfactory);
00088 if (interpreter)
00089 interpreter->markInterpreter();
00090 return (interpreter != NULL);
00091 }
00092
00093 bool AddressTranslateSysV::setAddressSize()
00094 {
00095 address_size = sizeof(void *);
00096 return true;
00097 }
00098
00099 LoadedLib *AddressTranslateSysV::getAOut()
00100 {
00101 return NULL;
00102 }
00103
00104 #include <sys/procfs.h>
00105
00106 ProcessReaderProc::ProcessReaderProc(int pid_) :
00107 as_fd(-1),
00108 ctl_fd(-1),
00109 isStopped(false),
00110 pid(pid_)
00111 {
00112
00113 }
00114
00115 bool ProcessReaderProc::start()
00116 {
00117 char temp[128];
00118 int result;
00119 long command;
00120
00121
00122 snprintf(temp, 128, "/proc/%d/ctl", pid);
00123 ctl_fd = P_open(temp, O_WRONLY | O_EXCL, 0);
00124 if (ctl_fd == -1)
00125 goto err;
00126
00127 snprintf(temp, 128, "/proc/%d/as", pid);
00128 as_fd = P_open(temp, O_RDONLY, 0);
00129 if (as_fd == -1)
00130 goto err;;
00131
00132
00133 command = PCSTOP;
00134 result = write(ctl_fd, &command, sizeof(long));
00135 if (result != sizeof(long))
00136 goto err;
00137 isStopped = true;
00138
00139 return true;
00140
00141 err:
00142 done();
00143 return false;
00144 }
00145
00146 bool ProcessReaderProc::ReadMem(Address inTraced, void *inSelf, unsigned amount)
00147 {
00148 off64_t loc = (off64_t) inTraced;
00149 unsigned res = pread64(as_fd, inSelf, amount, loc);
00150 return (res == amount);
00151 }
00152
00153 bool ProcessReaderProc::done()
00154 {
00155 int result = 0;
00156 if (isStopped && ctl_fd != -1) {
00157 long command[2];
00158 command[0] = PCRUN;
00159 command[1] = 0;
00160 result = write(ctl_fd, command, 2*sizeof(long));
00161 }
00162 if (ctl_fd != -1)
00163 P_close(ctl_fd);
00164 if (as_fd != -1)
00165 P_close(as_fd);
00166
00167 ctl_fd = as_fd = -1;
00168
00169 if (result != -1)
00170 isStopped = false;
00171
00172 return true;
00173 }
00174
00175 ProcessReaderProc::~ProcessReaderProc()
00176 {
00177 }
00178
00179 }
00180