public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Khoo Yit Phang <khooyp@cs.umd.edu>
To: <Paul_Koning@Dell.com>
Cc: Khoo Yit Phang <khooyp@cs.umd.edu>, <dje@google.com>,
	<tromey@redhat.com>, <gdb-patches@sourceware.org>
Subject: Re: Make the "python" command resemble the standard Python interpreter
Date: Mon, 06 Feb 2012 20:30:00 -0000	[thread overview]
Message-ID: <DA7C342D-9DBB-4759-902D-C1025CD3C7A0@cs.umd.edu> (raw)
In-Reply-To: <09787EF419216C41A903FD14EE5506DD0310E29D2F@AUSX7MCPC103.AMER.DELL.COM>

Hi,

Doug is right: Python's standard REPL (read-eval-print-loop), i.e., what you get when you run "python" from the shell or call the PyRun_InteractiveLoop function, has a slightly different behavior when defining the outermost block. (See some example transcripts at the end.)

So, copying and pasting in (non-GDB) Python has the hazards Doug is worried about. I suppose it's preferable to avoid this hazard in GDB's Python, probably by introducing another command such as "python-block".

Alternatively, I suppose it's possible to work around PyRun_InteractiveLoop by detecting a newline without indent, if we're willing to diverge from standard Python. 

Yit
February 6, 2012


 bash> python
 Python 2.7.2 (default, Nov 21 2011, 15:04:09) 
 [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> if 1 == 1:
 ...   print 1
 ... if 2 == 2:
   File "<stdin>", line 3
     if 2 == 2:
      ^
 SyntaxError: invalid syntax
 >>> if 1 == 1:
 ...   print 1
 ... 
 1
 >>> def foo():
 ...  return 1
 ... def bar():
   File "<stdin>", line 3
     def bar():
       ^
 SyntaxError: invalid syntax
 >>> def foo():
 ...   return 1
 ... 


On Feb 6, 2012, at 3:13 PM, <Paul_Koning@Dell.com> wrote:

> I'm confused.  "Python's repl expects a blank line to end a block"?  I'm not sure what a repl is, but Python doesn't require blank lines for anything.  End of block is defined by smaller indent.
> 
> I don't understand that error message at all.
> 
> 	paul
> 
> -----Original Message-----
> From: Doug Evans [mailto:dje@google.com] 
> Sent: Monday, February 06, 2012 3:09 PM
> To: Khoo Yit Phang
> Cc: Tom Tromey; Koning, Paul; gdb-patches@sourceware.org
> Subject: Re: Make the "python" command resemble the standard Python interpreter
> 
> On Mon, Jan 30, 2012 at 9:25 AM, Doug Evans <dje@google.com> wrote:
>> On Mon, Jan 30, 2012 at 9:18 AM, Doug Evans <dje@google.com> wrote:
>>> Plus, with some playing around I found this:
>>> 
>>> --- foo.gdb - snip ---
>>> python
>>> if 0 == 1:
>>>  print "foo"
>>> print "bar"
>>> end
>>> --- snip ---
>>> 
>>> (gdb) source foo.gdb
>>> bar
>>> (gdb)
>>> 
>>> But cut-n-paste that script into gdb and I get this:
>>> 
>>> (gdb) python
>>> if 0 == 1:
>>>  print "foo"
>>> print "bar"
>>> end
>>>>>> ... ...   File "<stdin>", line 3
>>>    print "bar"
>>>        ^
>>> SyntaxError: invalid syntax
>>>>>> 
>>> (gdb)
>>> 
>>> [For reference sake, here's how I cut-n-pasted it in emacs:
>>> C-x C-f foo.gdb RET C-space C-x ] C-b M-w C-x b RET C-y RET I hope I 
>>> transcribed that right.]
>>> 
>>> Python's repl expects a blank line to end the block.
>>> I don't know if there's a way to work around this.  Maybe there is.
>>> So now I'm even less comfortable.
>> 
>> btw, that's with the latest python-interactive script (that I could
>> find) applied (+ the sigint patch too).
>> 
>> For grin's sake, there's another example:
>> 
>> --- snip ---
>> python
>> if 0 == 1:
>>  print "foo"
>> end
>> ---
>> 
>> If I cut-n-paste that into gdb the "end" terminates the "if" block 
>> (heh, didn't expect that :-)), and afterwards I'm still in python.
>> Maybe this can be fixed too.
> 
> btw, in an effort to keep things moving along, to repeat something I mentioned earlier, If you, for example, add a new command, say, "python-block" ('tis the best I could come up with :-() that always behaved like python...end in scripts, then I think that would be ok: Users that want the existing script-like behaviour can switch to and use it instead of "python". IOW, "python-block" always behaves like the existing "python" command without arguments.
> 
> E.g.,
> 
> python-block
> if 0 == 1:
>  print "foo"
> end

  reply	other threads:[~2012-02-06 20:30 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-11  0:31 Khoo Yit Phang
2012-01-11  4:06 ` Joel Brobecker
2012-01-11 10:43 ` Kevin Pouget
2012-01-11 10:59   ` Joel Brobecker
2012-01-11 16:04   ` Khoo Yit Phang
2012-01-11 17:48     ` Khoo Yit Phang
2012-01-11 18:48     ` Kevin Pouget
2012-01-11 19:04       ` Khoo Yit Phang
2012-01-11 19:11         ` Kevin Pouget
2012-01-11 21:06           ` Khoo Yit Phang
2012-01-11 21:33             ` Tom Tromey
2012-01-11 22:22               ` Khoo Yit Phang
2012-01-20 21:25                 ` Tom Tromey
2012-01-20 21:31             ` Tom Tromey
2012-01-22 16:42               ` Khoo Yit Phang
2012-01-11 20:56 ` Tom Tromey
2012-01-11 21:30   ` Khoo Yit Phang
2012-01-11 21:41     ` Tom Tromey
2012-01-12  3:07   ` Khoo Yit Phang
2012-01-13 14:09   ` Phil Muldoon
2012-01-13 21:39     ` Khoo Yit Phang
2012-01-12 16:48 ` Doug Evans
2012-01-12 16:52   ` Khoo Yit Phang
2012-01-12 16:55   ` Paul_Koning
2012-01-12 17:24     ` Joel Brobecker
2012-01-12 17:30     ` Doug Evans
2012-01-12 17:38       ` Paul_Koning
2012-01-12 17:46         ` Doug Evans
2012-01-12 17:48           ` Doug Evans
2012-01-12 17:51             ` Paul_Koning
2012-01-12 18:06               ` Doug Evans
     [not found]                 ` <CADPb22T1ZmfiGeF9g-QZN6pCTBHwT5ByD9ddX_Dhxe4URvTAhw@mail.gmail.com>
2012-01-12 18:21                   ` Khoo Yit Phang
2012-01-12 18:36                     ` Doug Evans
2012-01-12 18:48                       ` Khoo Yit Phang
2012-01-12 21:22                         ` Doug Evans
2012-01-12 18:30                 ` Doug Evans
2012-01-21  1:56           ` Tom Tromey
2012-01-22 16:57             ` Khoo Yit Phang
2012-01-23 22:17               ` Doug Evans
2012-01-24 17:36                 ` Tom Tromey
2012-01-26 18:28                   ` Doug Evans
2012-01-30  6:50                     ` Khoo Yit Phang
2012-01-30 17:25                       ` Doug Evans
2012-01-30 19:57                         ` Doug Evans
2012-02-06 20:08                           ` Doug Evans
2012-02-06 20:13                             ` Paul_Koning
2012-02-06 20:30                               ` Khoo Yit Phang [this message]
2012-02-06 20:34                               ` Doug Evans
2012-02-06 20:59                                 ` Paul_Koning
2012-02-06 21:54                           ` 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=DA7C342D-9DBB-4759-902D-C1025CD3C7A0@cs.umd.edu \
    --to=khooyp@cs.umd.edu \
    --cc=Paul_Koning@Dell.com \
    --cc=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /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).