LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 08-19-2016, 12:10 PM   #1
asif_bahrainwala
Member
 
Registered: Mar 2015
Posts: 47

Rep: Reputation: Disabled
ptrace conundrum


Hi,
I am using ptrace to write my own debugger,
After I call ptrace(ptrace_attach...), my tracee gets a SIGSTOP,

while handling this in my debugger,
I have to call PTRACE_SINGLESTEP ,
waitpid,
then set my breakpoints,
then call ptrace(ptrace_cont...)

This works correctly, however I want to know why was ptrace_singlestep needed

I looked at http://stackoverflow.com/questions/1...ltiple-threads
and
http://eli.thegreenplace.net/2011/01...s-work-part-1/
 
Old 08-19-2016, 01:43 PM   #2
asif_bahrainwala
Member
 
Registered: Mar 2015
Posts: 47

Original Poster
Rep: Reputation: Disabled
my best guess is that when the debugger gets the "wait" to return since the child has received SIGSTOP, the child may not stop immediately and is still pending to be moved to the sleep queue and may execute few instructions.
To ensure that it predictably stops at the RIP queried using ptrace, we must call ptrace(PTRACE_SINGLESTEP ....) first. This will set the Trace flag bit and cause the CPU to break (int 1). Now we can query the registers, alter the memory etc.
 
  


Reply



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
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
Compile error in ptrace.c with 2.4.7 tinytim Linux - General 0 08-07-2001 07:01 AM

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

All times are GMT -5. The time now is 02:34 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