tracechild.cc revision 8118
13115SN/A/*
23115SN/A * Copyright (c) 2006 The Regents of The University of Michigan
33115SN/A * All rights reserved.
43115SN/A *
53115SN/A * Redistribution and use in source and binary forms, with or without
63115SN/A * modification, are permitted provided that the following conditions are
73115SN/A * met: redistributions of source code must retain the above copyright
83115SN/A * notice, this list of conditions and the following disclaimer;
93115SN/A * redistributions in binary form must reproduce the above copyright
103115SN/A * notice, this list of conditions and the following disclaimer in the
113115SN/A * documentation and/or other materials provided with the distribution;
123115SN/A * neither the name of the copyright holders nor the names of its
133115SN/A * contributors may be used to endorse or promote products derived from
143115SN/A * this software without specific prior written permission.
153115SN/A *
163115SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173115SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183115SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193115SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203115SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213115SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223115SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233115SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243115SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253115SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263115SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273115SN/A *
283115SN/A * Authors: Gabe Black
293115SN/A */
303115SN/A
313115SN/A#include <iostream>
323115SN/A#include <errno.h>
333115SN/A#include <sys/ptrace.h>
343115SN/A#include <stdint.h>
353115SN/A
368117Sgblack@eecs.umich.edu#include "arch/i686/tracechild.hh"
373115SN/A
383115SN/Ausing namespace std;
393115SN/A
408108SN/Aint64_t
418117Sgblack@eecs.umich.eduI686TraceChild::getRegs(user_regs_struct & myregs, int num)
423115SN/A{
438108SN/A    assert(num < numregs && num >= 0);
448108SN/A    switch (num) {
458108SN/A      //GPRs
468108SN/A      case EAX: return myregs.eax;
478108SN/A      case EBX: return myregs.ebx;
488108SN/A      case ECX: return myregs.ecx;
498108SN/A      case EDX: return myregs.edx;
508108SN/A      //Index registers
518108SN/A      case ESI: return myregs.esi;
528108SN/A      case EDI: return myregs.edi;
538108SN/A      //Base pointer and stack pointer
548108SN/A      case EBP: return myregs.ebp;
558108SN/A      case ESP: return myregs.esp;
568108SN/A      //Segmentation registers
578115SN/A      case CS: return myregs.xcs;
588115SN/A      case DS: return myregs.xds;
598115SN/A      case ES: return myregs.xes;
608115SN/A      case FS: return myregs.xfs;
618115SN/A      case GS: return myregs.xgs;
628115SN/A      case SS: return myregs.xss;
638108SN/A      //PC
648108SN/A      case EIP: return myregs.eip;
658108SN/A      default:
668108SN/A        assert(0);
678108SN/A        return 0;
688108SN/A    }
693115SN/A}
703115SN/A
718108SN/Abool
728117Sgblack@eecs.umich.eduI686TraceChild::update(int pid)
733115SN/A{
748108SN/A    oldregs = regs;
758108SN/A    if (ptrace(PTRACE_GETREGS, pid, 0, &regs) != 0)
768108SN/A        return false;
778108SN/A    for (unsigned int x = 0; x < numregs; x++) {
788108SN/A        regDiffSinceUpdate[x] = (getRegVal(x) != getOldRegVal(x));
798108SN/A    }
803115SN/A}
813115SN/A
828117Sgblack@eecs.umich.eduI686TraceChild::I686TraceChild()
833115SN/A{
848108SN/A    for (unsigned int x = 0; x < numregs; x++)
858108SN/A        regDiffSinceUpdate[x] = false;
863115SN/A}
873115SN/A
888108SN/Aint64_t
898117Sgblack@eecs.umich.eduI686TraceChild::getRegVal(int num)
903115SN/A{
918108SN/A    return getRegs(regs, num);
923115SN/A}
933115SN/A
948108SN/Aint64_t
958117Sgblack@eecs.umich.eduI686TraceChild::getOldRegVal(int num)
963115SN/A{
978108SN/A    return getRegs(oldregs, num);
983115SN/A}
993115SN/A
1008118Sgblack@eecs.umich.edubool
1018118Sgblack@eecs.umich.eduI686TraceChild::sendState(int socket)
1028118Sgblack@eecs.umich.edu{
1038118Sgblack@eecs.umich.edu    return false;
1048118Sgblack@eecs.umich.edu}
1058118Sgblack@eecs.umich.edu
1068108SN/ATraceChild *
1078108SN/AgenTraceChild()
1083115SN/A{
1098117Sgblack@eecs.umich.edu    return new I686TraceChild;
1103115SN/A}
111