1*22511Sdist /* 2*22511Sdist * Copyright (c) 1980 Regents of the University of California. 3*22511Sdist * All rights reserved. The Berkeley software License Agreement 4*22511Sdist * specifies the terms and conditions for redistribution. 5*22511Sdist */ 65504Slinton 7*22511Sdist #ifndef lint 8*22511Sdist static char sccsid[] = "@(#)rdwr.c 5.1 (Berkeley) 06/06/85"; 9*22511Sdist #endif not lint 105504Slinton /* 115504Slinton * These routines are used to access the debuggee process from 125504Slinton * outside the "process" module. 135504Slinton * 145504Slinton * They invoke "pio" which eventually leads to a call to "ptrace". 155504Slinton * The system generates an I/O error when a ptrace fails, we catch 165504Slinton * that here and assume its due to a misguided address. 175504Slinton */ 185504Slinton 195504Slinton #include "defs.h" 205504Slinton #include <errno.h> 215504Slinton #include "process.h" 225504Slinton #include "process.rep" 235504Slinton 245504Slinton # if (isvaxpx) 255504Slinton # include "pxinfo.h" 265504Slinton # endif 275504Slinton 285504Slinton typedef int INTFUNC(); 295504Slinton 305504Slinton extern INTFUNC *onsyserr(); 315504Slinton 325504Slinton LOCAL badaddr; 335504Slinton LOCAL rwerr(); 345504Slinton 355504Slinton /* 365504Slinton * Read from the process' instruction area. For px, this is actually 375504Slinton * the data area. 385504Slinton */ 395504Slinton 405504Slinton iread(buff, addr, nbytes) 415504Slinton char *buff; 425504Slinton ADDRESS addr; 435504Slinton int nbytes; 445504Slinton { 455504Slinton INTFUNC *f; 465504Slinton 475504Slinton f = onsyserr(EIO, &rwerr); 485504Slinton # if (isvaxpx) 495504Slinton badaddr = addr + ENDOFF; 505504Slinton pio(process, PREAD, DATASEG, buff, addr + ENDOFF, nbytes); 515504Slinton # else 525504Slinton badaddr = addr; 535504Slinton pio(process, PREAD, TEXTSEG, buff, addr, nbytes); 545504Slinton # endif 555504Slinton onsyserr(EIO, f); 565504Slinton } 575504Slinton 585504Slinton /* 595504Slinton * Write to the process' instruction area, usually in order to set 605504Slinton * or unset a breakpoint. 615504Slinton */ 625504Slinton 635504Slinton iwrite(buff, addr, nbytes) 645504Slinton char *buff; 655504Slinton ADDRESS addr; 665504Slinton int nbytes; 675504Slinton { 685504Slinton INTFUNC *f; 695504Slinton 705504Slinton f = onsyserr(EIO, &rwerr); 715504Slinton # if (isvaxpx) 725504Slinton badaddr = addr + ENDOFF; 735504Slinton pio(process, PWRITE, DATASEG, buff, addr + ENDOFF, nbytes); 745504Slinton # else 755504Slinton badaddr = addr; 765504Slinton pio(process, PWRITE, TEXTSEG, buff, addr, nbytes); 775504Slinton # endif 785504Slinton onsyserr(EIO, f); 795504Slinton } 805504Slinton 815504Slinton /* 825504Slinton * Read for the process' data area. 835504Slinton */ 845504Slinton 855504Slinton dread(buff, addr, nbytes) 865504Slinton char *buff; 875504Slinton ADDRESS addr; 885504Slinton int nbytes; 895504Slinton { 905504Slinton INTFUNC *f; 915504Slinton 925504Slinton f = onsyserr(EIO, &rwerr); 935504Slinton badaddr = addr; 945504Slinton pio(process, PREAD, DATASEG, buff, addr, nbytes); 955504Slinton onsyserr(EIO, f); 965504Slinton } 975504Slinton 985504Slinton /* 995504Slinton * Write to the process' data area. 1005504Slinton */ 1015504Slinton 1025504Slinton dwrite(buff, addr, nbytes) 1035504Slinton char *buff; 1045504Slinton ADDRESS addr; 1055504Slinton int nbytes; 1065504Slinton { 1075504Slinton INTFUNC *f; 1085504Slinton 1095504Slinton f = onsyserr(EIO, &rwerr); 1105504Slinton badaddr = addr; 1115504Slinton pio(process, PWRITE, DATASEG, buff, addr, nbytes); 1125504Slinton onsyserr(EIO, f); 1135504Slinton } 1145504Slinton 1155504Slinton /* 1165504Slinton * Error handler. 1175504Slinton */ 1185504Slinton 1195504Slinton LOCAL rwerr() 1205504Slinton { 1215504Slinton error("bad read/write process address 0x%x", badaddr); 1225504Slinton } 123