Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* controlling gdb via python's pexpect
@ 2009-11-05 20:27 fpga
  2009-11-05 20:35 ` George Russell
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: fpga @ 2009-11-05 20:27 UTC (permalink / raw)
  To: gdb


Can someone please give me an example of how this is done.
I'm afraid the documentation is not helping me.
Thx
-- 
View this message in context: http://old.nabble.com/controlling-gdb-via-python%27s-pexpect-tp26221261p26221261.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-05 20:27 controlling gdb via python's pexpect fpga
@ 2009-11-05 20:35 ` George Russell
  2009-11-06 10:56   ` Gaius Mulley
  2009-11-06  9:11 ` fpga
  2009-11-06 10:44 ` fpga
  2 siblings, 1 reply; 14+ messages in thread
From: George Russell @ 2009-11-05 20:35 UTC (permalink / raw)
  To: fpga; +Cc: gdb

fpga wrote:
> Can someone please give me an example of how this is done.
> I'm afraid the documentation is not helping me.
> Thx
>   
Hi,

I have had some success in controlling GDB (via MI) from python, using 
the subprocess module and communicating with GDB via pipes. 
(http://docs.python.org/library/subprocess.html)

The main issue so far is that some applications detect when they are 
running with pipes instead of a terminal for output, and buffer program 
output by block rather than line as on a terminal, leading to delays in 
receiving program output issued via printf, for example, unless it is 
followed by an explicit fflush call.

(I too would be interested in an example of using pexpect to control GDB)
Cheers,
George Russell


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-06  9:11 ` fpga
@ 2009-11-06  7:15   ` fpga
  2009-11-06  9:12   ` fpga
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: fpga @ 2009-11-06  7:15 UTC (permalink / raw)
  To: gdb




fpga wrote:
> 
> Can someone please give me an example of how this is done.
> I'm afraid the documentation is not helping me.
> Thx
> 

George
You've got further than I have!
I tried to use subprocess but failed.
pexpect was suggested by experts on the python forum.
Unfortuntely they appear incapable of correcting my trivial example of
opening a terminal and sending the command 'gdb' to it.
Any snippets most welcome.
Looking at my repositories I see libdevel-gdb-perl.
I like python's orderliness but have noticed that when python fails perl
usually delivers.
-- 
View this message in context: http://old.nabble.com/controlling-gdb-via-python%27s-pexpect-tp26221261p26227761.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
@ 2009-11-06  9:11 ` fpga
  2009-11-06  7:15   ` fpga
                     ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: fpga @ 2009-11-06  9:11 UTC (permalink / raw)
  To: gdb



fpga wrote:
> 
> Can someone please give me an example of how this is done.
> I'm afraid the documentation is not helping me.
> Thx
> 

George
You've got further than I have!
I tried to use subprocess before trying pexpect but failed.
pexpect was suggested by experts on the python forum.
Unfortuntely they appear incapable of correcting my trivial example of
opening a terminal and sending the command 'gdb' to it.
Any snippets most welcome.
Looking at my repositories I see libdevel-gdb-perl.
I like python's orderliness but have noticed that when python fails perl
usually delivers.
-- 
View this message in context: http://old.nabble.com/controlling-gdb-via-python%27s-pexpect-tp26221261p26227761.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-06  9:11 ` fpga
  2009-11-06  7:15   ` fpga
@ 2009-11-06  9:12   ` fpga
  2009-11-06 10:23   ` fpga
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: fpga @ 2009-11-06  9:12 UTC (permalink / raw)
  To: gdb



fpga wrote:
> 
> Can someone please give me an example of how this is done.
> I'm afraid the documentation is not helping me.
> Thx
> 

Thx George
You've got further than I have!
I tried to use subprocess before trying pexpect but failed.
pexpect was suggested by experts on the python forum.
Unfortuntely they appear incapable of correcting my trivial example of
opening a terminal and sending the command 'gdb' to it.
Any snippets most welcome.
Looking at my repositories I see libdevel-gdb-perl.
I like python's orderliness but have noticed that when python fails perl
usually delivers.
-- 
View this message in context: http://old.nabble.com/controlling-gdb-via-python%27s-pexpect-tp26221261p26227761.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-06  9:11 ` fpga
  2009-11-06  7:15   ` fpga
  2009-11-06  9:12   ` fpga
@ 2009-11-06 10:23   ` fpga
  2009-11-06 10:28   ` George Russell
  2009-11-06 10:39   ` Greg Law
  4 siblings, 0 replies; 14+ messages in thread
From: fpga @ 2009-11-06 10:23 UTC (permalink / raw)
  To: gdb



fpga wrote:
> 
> Can someone please give me an example of how this is done.
> I'm afraid the documentation is not helping me.
> Thx
> 

Thx George
You've got further than I have!
I tried to use subprocess before trying pexpect but failed.
pexpect was suggested by experts on the python forum.
Unfortuntely they seem unable to correct my trivial example of opening a
terminal and sending 'gdb' to it.
Therefore any working snippets would be welcome.
Looking at my repositories I see libdevel-gdb-perl.
I like python's orderliness but have noticed that when python fails perl
usually delivers.
-- 
View this message in context: http://old.nabble.com/controlling-gdb-via-python%27s-pexpect-tp26221261p26227761.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-06  9:11 ` fpga
                     ` (2 preceding siblings ...)
  2009-11-06 10:23   ` fpga
@ 2009-11-06 10:28   ` George Russell
  2009-11-06 10:39   ` Greg Law
  4 siblings, 0 replies; 14+ messages in thread
From: George Russell @ 2009-11-06 10:28 UTC (permalink / raw)
  To: fpga; +Cc: gdb

fpga wrote:
> fpga wrote:
>   
>> Can someone please give me an example of how this is done.
>> I'm afraid the documentation is not helping me.
>> Thx
>>
>>     
>
> Thx George
> You've got further than I have!
> I tried to use subprocess before trying pexpect but failed.
> pexpect was suggested by experts on the python forum.
> Unfortuntely they appear incapable of correcting my trivial example of
> opening a terminal and sending the command 'gdb' to it.
> Any snippets most welcome.
> Looking at my repositories I see libdevel-gdb-perl.
> I like python's orderliness but have noticed that when python fails perl
> usually delivers.
>   
See

http://www.dalkescientific.com/writings/diary/archive/2005/04/12/wrapping_command_line_programs.html
http://www.dalkescientific.com/writings/diary/archive/2005/04/15/wrapping_command_line_programs_II.html
http://www.dalkescientific.com/writings/diary/archive/2005/04/17/wrapping_command_line_programs_III.html
http://www.dalkescientific.com/writings/diary/archive/2005/04/18/wrapping_command_line_programs_IV.html
http://www.dalkescientific.com/writings/diary/archive/2005/04/18/wrapping_command_line_programs_V.html

for an assortment of tips on control of external processes from Python.

Cheers,
George


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-06  9:11 ` fpga
                     ` (3 preceding siblings ...)
  2009-11-06 10:28   ` George Russell
@ 2009-11-06 10:39   ` Greg Law
  4 siblings, 0 replies; 14+ messages in thread
From: Greg Law @ 2009-11-06 10:39 UTC (permalink / raw)
  To: fpga; +Cc: gdb

fpga wrote:
> 
> 
> fpga wrote:
>> Can someone please give me an example of how this is done.
>> I'm afraid the documentation is not helping me.
>> Thx
>>
> 
> George
> You've got further than I have!
> I tried to use subprocess but failed.

Yeah, pipes might appear to work at first if you're "lucky", but pretty 
quickly you'll come unstuck due to problems with buffering.

Here's a trivial example for gdb with pexpect:

import pexpect, sys
child = pexpect.spawn( 'gdb a.out')
child.setlog( sys.stdout)
child.expect_exact ('(gdb) ')
child.send ('run\n')
child.expect_exact ('Program exited normally.')
child.expect_exact ('(gdb) ')
child.send ('quit\n')
child.expect( pexpect.EOF


Note that the pexpect.expect method takes a regular expression but 
"expect_exact" doesn't.  If you're going to use the expect method be 
sure to escape things like parentheses.

Greg
-- 
Greg Law, Undo Software                       http://undo-software.com/


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-05 20:27 controlling gdb via python's pexpect fpga
  2009-11-05 20:35 ` George Russell
  2009-11-06  9:11 ` fpga
@ 2009-11-06 10:44 ` fpga
  2 siblings, 0 replies; 14+ messages in thread
From: fpga @ 2009-11-06 10:44 UTC (permalink / raw)
  To: gdb


That's given me something to look at.
Thank you to both of you!

fpga wrote:
> 
> Can someone please give me an example of how this is done.
> I'm afraid the documentation is not helping me.
> Thx
> 

-- 
View this message in context: http://old.nabble.com/controlling-gdb-via-python%27s-pexpect-tp26221261p26229502.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-05 20:35 ` George Russell
@ 2009-11-06 10:56   ` Gaius Mulley
  2009-11-06 10:56     ` Gaius Mulley
  2009-11-06 11:07     ` fpga
  0 siblings, 2 replies; 14+ messages in thread
From: Gaius Mulley @ 2009-11-06 10:56 UTC (permalink / raw)
  To: George Russell; +Cc: fpga, gdb

George Russell <george@codeplay.com> writes:

> fpga wrote:
>> Can someone please give me an example of how this is done.
>> I'm afraid the documentation is not helping me.
>> Thx
>>   
> Hi,
>
> I have had some success in controlling GDB (via MI) from python, using
> the subprocess module and communicating with GDB via
> pipes. (http://docs.python.org/library/subprocess.html)
>
> The main issue so far is that some applications detect when they are
> running with pipes instead of a terminal for output, and buffer
> program output by block rather than line as on a terminal, leading to
> delays in receiving program output issued via printf, for example,
> unless it is followed by an explicit fflush call.
>
> (I too would be interested in an example of using pexpect to control GDB)
> Cheers,
> George Russell

Hi,

for what it is worth feel free to download 
http://floppsie.comp.glam.ac.uk/download/python/twingdb.tar.gz

which was written to run two gdb's debugging a stage1 and stage2
generation of a compiler and single step until a line number differs.
It is written in Python and uses pexpect

The code is very alpha - but it worked well enough to find the bug I
was hunting.

regards,
Gaius


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-06 10:56   ` Gaius Mulley
@ 2009-11-06 10:56     ` Gaius Mulley
  2009-11-06 11:07     ` fpga
  1 sibling, 0 replies; 14+ messages in thread
From: Gaius Mulley @ 2009-11-06 10:56 UTC (permalink / raw)
  To: George Russell; +Cc: fpga, gdb

Gaius Mulley <gaius@glam.ac.uk> writes:

> for what it is worth feel free to download 
> http://floppsie.comp.glam.ac.uk/download/python/twingdb.tar.gz

ahh correction, make that

  http://floppsie.comp.glam.ac.uk/download/python/tgdb-0.1.tar.gz

instead..

regards,
Gaius


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-06 10:56   ` Gaius Mulley
  2009-11-06 10:56     ` Gaius Mulley
@ 2009-11-06 11:07     ` fpga
  2009-11-06 16:55       ` Gaius Mulley
  1 sibling, 1 reply; 14+ messages in thread
From: fpga @ 2009-11-06 11:07 UTC (permalink / raw)
  To: gdb




Gaius Mulley wrote:
> 
> George Russell <george@codeplay.com> writes:
> 
>> fpga wrote:
>>> Can someone please give me an example of how this is done.
>>> I'm afraid the documentation is not helping me.
>>> Thx
>>>   
>> Hi,
>>
>> I have had some success in controlling GDB (via MI) from python, using
>> the subprocess module and communicating with GDB via
>> pipes. (http://docs.python.org/library/subprocess.html)
>>
>> The main issue so far is that some applications detect when they are
>> running with pipes instead of a terminal for output, and buffer
>> program output by block rather than line as on a terminal, leading to
>> delays in receiving program output issued via printf, for example,
>> unless it is followed by an explicit fflush call.
>>
>> (I too would be interested in an example of using pexpect to control GDB)
>> Cheers,
>> George Russell
> 
> Hi,
> 
> for what it is worth feel free to download 
> http://floppsie.comp.glam.ac.uk/download/python/twingdb.tar.gz
> 
> which was written to run two gdb's debugging a stage1 and stage2
> generation of a compiler and single step until a line number differs.
> It is written in Python and uses pexpect
> 
> The code is very alpha - but it worked well enough to find the bug I
> was hunting.
> 
> regards,
> Gaius
> 
> 

Hi Gaius
I'd like to download this but get
The requested URL /download/python/twingdb.tar.gz was not found on this
server.

-- 
View this message in context: http://old.nabble.com/controlling-gdb-via-python%27s-pexpect-tp26221261p26229834.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-06 11:07     ` fpga
@ 2009-11-06 16:55       ` Gaius Mulley
  2009-11-06 17:57         ` fpga
  0 siblings, 1 reply; 14+ messages in thread
From: Gaius Mulley @ 2009-11-06 16:55 UTC (permalink / raw)
  To: fpga; +Cc: gdb

fpga <mgbg25171@blueyonder.co.uk> writes:

> Hi Gaius
> I'd like to download this but get
> The requested URL /download/python/twingdb.tar.gz was not found on this
> server.

Hi,

all restored now - although

http://floppsie.comp.glam.ac.uk/download/python/tgdb-0.1.tar.gz

is a cleaner package,

regards,
Gaius


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: controlling gdb via python's pexpect
  2009-11-06 16:55       ` Gaius Mulley
@ 2009-11-06 17:57         ` fpga
  0 siblings, 0 replies; 14+ messages in thread
From: fpga @ 2009-11-06 17:57 UTC (permalink / raw)
  To: gdb


I got that one too. Thx

Gaius Mulley wrote:
> 
> fpga <mgbg25171@blueyonder.co.uk> writes:
> 
>> Hi Gaius
>> I'd like to download this but get
>> The requested URL /download/python/twingdb.tar.gz was not found on this
>> server.
> 
> Hi,
> 
> all restored now - although
> 
> http://floppsie.comp.glam.ac.uk/download/python/tgdb-0.1.tar.gz
> 
> is a cleaner package,
> 
> regards,
> Gaius
> 
> 

-- 
View this message in context: http://old.nabble.com/controlling-gdb-via-python%27s-pexpect-tp26221261p26230152.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2009-11-06 11:07 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-05 20:27 controlling gdb via python's pexpect fpga
2009-11-05 20:35 ` George Russell
2009-11-06 10:56   ` Gaius Mulley
2009-11-06 10:56     ` Gaius Mulley
2009-11-06 11:07     ` fpga
2009-11-06 16:55       ` Gaius Mulley
2009-11-06 17:57         ` fpga
2009-11-06  9:11 ` fpga
2009-11-06  7:15   ` fpga
2009-11-06  9:12   ` fpga
2009-11-06 10:23   ` fpga
2009-11-06 10:28   ` George Russell
2009-11-06 10:39   ` Greg Law
2009-11-06 10:44 ` fpga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox