public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Matt Rice <ratmice@gmail.com>
To: Project Archer <archer@sourceware.org>
Subject: running multi-process in lockstep with python
Date: Sun, 19 Sep 2010 11:39:00 -0000	[thread overview]
Message-ID: <AANLkTi=GidE3_aC06sJDMBtU-bkCCn75yjUekgerm=At@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 606 bytes --]

this could use a fair amount of polish its probably not going to get unless
you guys are interested in including it, then i would try and clean up
the magic numbers into set/show commands, e.g. using an itset
and other stuff.

anyhow i think it shows off 2 of the newer features of gdb

in my tests lockstep1 foo increments to 10 or so
and lockstep2 foo increments to 5 then back to 0.

execution continues until reaching 6, 4.
where it hands control back to the user with both inferiors stopped.

now if it only could debug i386 + x86_64 simultaneously i'd be set
probably a twisted version comming up :/

[-- Attachment #2: lockstep.gdb --]
[-- Type: application/octet-stream, Size: 218 bytes --]

set pagination off

source lockstep.py

add-inferior -exec lockstep1
inferior 2
break foo 
commands
silent
set $x1 = i 
end
run

add-inferior -exec lockstep2
inferior 3 
break foo 
commands
silent
set $x2 = i 
end
run

[-- Attachment #3: lockstep.py --]
[-- Type: application/octet-stream, Size: 1031 bytes --]

run_on_match = "continue"
run_on_dont_match = "" 


def doLockStep ():
	global run_on_match
	global run_on_dont_match
	inferiors = dict()
	for inf in gdb.inferiors():
	  if inf.num > 1:
	    inferiors[inf.num] = inf

	print(inferiors)
	thr1 = inferiors[2].threads()[0]
	thr2 = inferiors[3].threads()[0]
	while thr1.is_running() == True or thr2.is_running() == True:
	  continue
	
	x1 = gdb.parse_and_eval("$x1")
	x2 = gdb.parse_and_eval("$x2")
	if x1 == x2:
	  gdb.execute("inferior 2")
	  gdb.execute(run_on_match) 
	  gdb.execute("inferior 3")
	  gdb.execute(run_on_match)
	  return 1
	else:
	  gdb.execute("inferior 2")
	  gdb.execute(run_on_dont_match)
	  gdb.execute("inferior 3")
	  gdb.execute(run_on_dont_match)
	  return 0


class Lockstep (gdb.Command):
	"""runs gdb continue in 2 inferiors until $x1 != $x2."""
     
	def __init__ (self):
	   super (Lockstep, self).__init__ ("lockstep", gdb.COMMAND_OBSCURE)
     
	def invoke (self, arg, from_tty):
	   while doLockStep() == 1:
	     continue

	   return 0
Lockstep ()

             reply	other threads:[~2010-09-19 11:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-19 11:39 Matt Rice [this message]
2010-09-21 21:50 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=GidE3_aC06sJDMBtU-bkCCn75yjUekgerm=At@mail.gmail.com' \
    --to=ratmice@gmail.com \
    --cc=archer@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).