addrtranslate-solaris.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 <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    //attach
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    //Stop the process
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 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1