Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 221681 Details for
Bug 325451
ptrace compatibility problem with PTRACE_{PEEK,POKE}USR_AREA
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
debugger.c
debugger.c (text/plain), 3.01 KB, created by
Brad Hinson
on 2007-10-09 19:28:50 UTC
(
hide
)
Description:
debugger.c
Filename:
MIME Type:
Creator:
Brad Hinson
Created:
2007-10-09 19:28:50 UTC
Size:
3.01 KB
patch
obsolete
>#include <unistd.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <sys/wait.h> >#include <sys/types.h> >#include <sys/ptrace.h> >#include <asm/ptrace.h> > >#define TARGET_ "./debuggee" >#define PTRACE_IGNORED (void *)0 > >static ptrace_area * pt_area = (ptrace_area *)0; >static struct user_regs_struct * pregs = (struct user_regs_struct *)0; > >static void writepc(pid_t pid, unsigned long new_pc) >{ > int rv; > > memset(pregs,0, sizeof(struct user_regs_struct)); > memset(pt_area,0, sizeof(ptrace_area)); > pt_area->len = sizeof(struct user_regs_struct); > pt_area->kernel_addr = (unsigned long)0; > pt_area->process_addr = (unsigned long)pregs; > rv = ptrace(PTRACE_PEEKUSR_AREA, pid, pt_area, 0); > if(rv == -1) > { > perror("PTRACE_PEEKUSR_AREA, failed\n"); > return; > } > pregs->psw.addr = new_pc; > rv = ptrace(PTRACE_POKEUSR_AREA, pid, pt_area, 0); > if(rv == -1) > { > perror("PTRACE_POKEUSR_AREA, failed\n"); > return; > } >} > >static unsigned long readpc(pid_t pid) >{ > int rv; > > memset(pregs,0, sizeof(struct user_regs_struct)); > memset(pt_area,0, sizeof(ptrace_area)); > pt_area->len = sizeof(struct user_regs_struct); > pt_area->kernel_addr = (unsigned long)0; > pt_area->process_addr = (unsigned long)pregs; > rv = ptrace(PTRACE_PEEKUSR_AREA, pid, pt_area, 0); > if(rv == -1) > { > perror("PTRACE_PEEKUSR_AREA, failed\n"); > return 0; > } > return pregs->psw.addr & 0x7fffffff; >} > >int main() >{ > int rv, status; > pid_t pid; > unsigned long pc, new_pc; > > pid = fork(); > switch(pid) > { > case -1: /* failed fork */ > return -1; > case 0: /* child process */ > ptrace(PTRACE_TRACEME, > PTRACE_IGNORED, PTRACE_IGNORED, PTRACE_IGNORED); > execl(TARGET_, TARGET_, (const char *)0); > _exit(-1); > break; > default: /* parent process */ > break; > } > > pt_area = (ptrace_area *)malloc(sizeof(ptrace_area)); > if(!pt_area) > { > ptrace(PTRACE_DETACH, pid, PTRACE_IGNORED,PTRACE_IGNORED); > return -1; > } > pregs = (struct user_regs_struct *)malloc(sizeof(struct user_regs_struct)); > if(!pregs) > { > free(pt_area); > ptrace(PTRACE_DETACH, pid, PTRACE_IGNORED,PTRACE_IGNORED); > return -1; > } > > ptrace(PTRACE_CONT, pid, PTRACE_IGNORED,PTRACE_IGNORED); > /* wait for process to stop */ > rv = waitpid(pid, &status, 0); > if(rv == -1) > { > printf("waitpid failed\n"); > kill(pid, 9); > return -1; > } > if(WIFSTOPPED(status)) > { > printf("process stopped\n"); > } > /* adjust PC */ > pc = readpc(pid); > new_pc = pc + 4; > printf("read PC = %8.8p\n", pc); > writepc(pid, new_pc); > printf("wrote PC = %8.8p\n", new_pc); > > ptrace(PTRACE_CONT, pid, PTRACE_IGNORED,PTRACE_IGNORED); > > /* did it work ? */ > > rv = waitpid(pid, &status, 0); > if(rv == -1) > { > printf("waitpid failed\n"); > kill(pid, 9); > return -1; > } > if(!WIFEXITED(status)) > { > pc = readpc(pid); > printf("read PC = %8.8p\n", pc); > ptrace(PTRACE_DETACH, pid, PTRACE_IGNORED,PTRACE_IGNORED); > } > free(pt_area); > free(pregs); > > return 0; >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 325451
:
221671
|
221681
|
221691
|
228891
|
228901
|
228911
|
251071