This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

how to analyse eg 'info registers' multi-line output using pexpect


Two problems with the code below.

Problem 1.
I know I can check for a string in the contents of the child process' output 
eg the output of 'info registers' in gdb
but how do I get the full contents returned by 'info registers' so I can "go
to town" on it?

I managed to do it in the code below by changing the logfile destination to
my_log.txt.
However, I then have the problem that I don't know when/how to change the
logfile destination back
to stdout again. At present the switch back happens before the contents go
to my_log.txt


Problem 2.
At the top of the code I'd like to start qemu up before gdb which attaches
to it.
I can do this using subprocesses by putting an & on the end of the commands.
Unfortunately, with pexpect, if I leave the & out, qemu fires up but blocks
the startup of gdb
and If I add the &, qemu doesn't happen or does but instantly disappears.
BTW I tried pexpect's run command too.


[code]
import pexpect, os, sys
#pexpect.run('ls -l')    #this works ok
#problem if you add & on nothing happens and if you don't it blocks gdb's
invocation below
#child1 = pexpect.spawn('terminator -x qemu -s -S -fda floppy.img -boot a
&')  
#child1 = pexpect.spawn('qemu -s -S -fda floppy.img -boot a &') 

child = pexpect.spawn    ('gdb &') 
#===========================
child.logfile = sys.stdout      #<========================= set logfile
destination
#either/or
fout = file('my_log.txt','w') 
#child.logfile = fout   
#===========================                                    
child.expect_exact         ('(gdb) ') #space significant?       
child.send               ('target remote localhost:1234\n')      
child.send               ('set architecture i8086\n')
child.send               ('set disassembly-flavor intel\n')     
child.send               ('b *0x00007c00\n')
child.expect_exact         ('Breakpoint 1 at 0x7c00')
child.expect_exact         ('(gdb) ')                           
child.setdelaybeforesend = 10
child.send               ('c\n')                                
child.logfile = fout            #<========================= change logfile
destination
child.send               ('info registers\n')
child.expect               ('.*')
child.logfile = sys.stdout      #<===================== change logfile
destinatio back
child.send              ('print $ax\n')
child.send              ('print $bx\n')
[/code]

Any help much appreciated. 
-- 
View this message in context: http://old.nabble.com/how-to-analyse-eg-%27info-registers%27-multi-line-output-using-pexpect-tp26240898p26240898.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]