LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2016, 06:35 AM   #1
asif_bahrainwala
Member
 
Registered: Mar 2015
Posts: 47

Rep: Reputation: Disabled
ptrace SINGLE_STEP


Hi,
While writing a debugger [http://www.secretmango.com/jimb/Whit...e/ptrace.html]
After attaching to the process using ptrace(PTRACE_ATTACH....), I am unable to set my breakpoints in the target tracee , it crashes whenever we set one

But when we use ptrace SingleStep after we return from waitpid, it all works fine
I want to know why must we call ptrace Single step (causing the debugger to break on waitpid with SIGTRAP) right after the tracee has stopped (due to attaching).

I cant find any material on this.
 
Old 11-11-2016, 07:30 AM   #2
asif_bahrainwala
Member
 
Registered: Mar 2015
Posts: 47

Original Poster
Rep: Reputation: Disabled
if(WIFSTOPPED(status)){.....

user uregs1={};
ptrace(PTRACE_GETREGS,rpid,NULL,&uregs1);
printf("rip0=%lx\n",uregs1.regs.rip);fflush(stdout);

ptrace(PTRACE_SINGLESTEP, tid, 0, 0); //let it continue one step
tid=waitpid(-1, &status, __WALL);

ptrace(PTRACE_GETREGS,rpid,NULL,&uregs1);
printf("rip0=%lx\n",uregs1.regs.rip);fflush(stdout);

both print the same RIP (after executing one instruction)...this probably tells me that the first RIP value was incorrect (and now ptrace with single step is required to get the right value), probably incorrect due to the pipeline nature of a processor
 
  


Reply

Tags
ptrace



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ptrace conundrum asif_bahrainwala Programming 1 08-19-2016 01:43 PM
how to use ptrace Sanaa K Ubuntu 1 10-21-2013 01:45 AM
Ptrace Question Simple12 Programming 10 09-07-2012 06:44 AM
Ptrace - Help me undersatnd Ptrace jiikka Linux - General 3 03-19-2009 02:33 AM
ptrace jucovschi Programming 0 08-28-2003 03:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration