public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Jan Vrany <jan.vrany@fit.cvut.cz>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Subject: Re: [RFC 0/8] Create MI commands using python
Date: Sat, 20 Apr 2019 07:20:00 -0000	[thread overview]
Message-ID: <ff939c9c5490e968b99fca34a18bed21f7843d32.camel@fit.cvut.cz> (raw)
In-Reply-To: <8fe6b394-b1d4-6207-b9f6-acdfce4002bd@simark.ca>

Hi,

On Thu, 2019-04-18 at 12:03 -0400, Simon Marchi wrote:
> On 2019-04-18 11:23 a.m., Jan Vrany wrote:
> > This patch series adds a possibility to create new MI commands using python.
> > 
> > The code is based on a few year old attempt of Didier Nadeau who did the
> > heavy lifting. I merely updated his original code to work with today's GDB,
> > add tests and polished it a little.
> > 
> > At this point, there's no documentation. I expect a discussion and changes
> > in behavior and/or output - I'll write it once the rest is agreed on.
> 
> Hi Jan,
> 
> Thanks for doing this!
> 
> Here's the original thread:
> https://www.sourceware.org/ml/gdb-patches/2017-02/msg00088.html
> 
> One thing Pedro asked for (rightfully), is some kind of rationale: what's the
> point of this feature.  I'll try to provide some of it, since I helped Didier
> with this prototype at the time (done in an academic context).  Jan, please
> complete/correct as needed to share your own point of view.
> 
> As a GDB frontend developer, you want to display some application-specific data
> in your nice GUI frontend.  That data is extracted from the application's data
> structure in memory, and possibly from doing some kind of bookkeeping (putting
> breakpoints at strategic points to record things) or whatnot.
> 
> Today, it would be possible to do all of this in the front-end: you can read from
> memory and evaluate expressions to extract data from data structures in memory
> and you can put breakpoints to catch important events (which you try to hide from
> the user by resuming execution).
> 
> The downside to this is that all the logic to reconstitute legible data from the
> data structures may be non-trivial, and all that logic will be in the front-end.
> If you want to support more than one front-end, or want to provide some similar
> feature from the command line as well, it will have to be duplicated.
> 
> So the idea is to have a single implementation in Python, and have it accessible
> to the frontend.  Today, you could implement a custom CLI command in Python and
> call it from MI, from your frontend.  This is not ideal because the output would
> be CLI output, difficult to parse from MI (it's hard to know which output comes
> from which command).
> erSo the idea would be for front-ends to be able to load some scripts like:
> 

Exactly! I could not have said it better. Another aspect may be performance - doing 
extensive data structure analysis by walking variable object and/or inferior memory 
in frontend can easily result in hundreds of MI commands being sent. 

> class MyMICommand(gdb.MICommand):
>   def __init__(self):
>     super('-my-mi-command')
> 
>   def invoke(self, args):
>     return {'foo': 'bar'}
> 
> MyMICommand()
> 
> This would define the '-my-mi-command' command, which when called, would return:
> 
>   123-my-my-command
>   123^done,foo="bar"
> 
> So to answer one question Pedro had:
> 
> > I suppose they'll build the MI output "manually" ?
> 
> Ideally not.  They return a Python object (dict, list, string, int) which map pretty
> easily to MI data types.

Exactly. See parse_mi_result() in python/py-micmd.c
( https://bitbucket.org/janvrany/binutils-gdb/src/67fea07b27f59b5eb1dd99fe340d8222521e7df2/gdb/python/py-micmd.c?at=users%2Fjv%2Fvdb&fileviewer=file-view-default#py-micmd.c-36 )

To support even more OO style of programming, we can say that for 
any other object ("generic" case in the code above), a define API
method - say .to_mi_record() - which must return one of the recognized
objects (string, int, sequence, dict, iterator). 

I decided not to implement this until I get more experience with using 
Python-defined MI commands for real. 

Jan

  reply	other threads:[~2019-04-20  7:20 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18 15:23 Jan Vrany
2019-04-18 15:23 ` [RFC 1/8] Use std::map for MI commands in mi-cmds.c Jan Vrany
2019-04-25 19:13   ` Tom Tromey
2019-04-25 19:15   ` Tom Tromey
2019-04-25 19:34     ` Jan Vrany
2019-05-03 22:40   ` Simon Marchi
2019-05-03 22:45     ` Simon Marchi
2019-04-18 15:24 ` [RFC 4/8] mi/python: C++ify python MI command handling code Jan Vrany
2019-04-25 19:43   ` Tom Tromey
2019-04-18 15:24 ` [RFC 2/8] Use classes to represent MI Command instead of structures Jan Vrany
2019-04-25 19:25   ` Tom Tromey
2019-05-03 22:49     ` Simon Marchi
2019-05-03 22:57       ` Simon Marchi
2019-04-18 15:24 ` [RFC 7/8] mi/python: Add tests for python-defined MI commands Jan Vrany
2019-04-25 19:48   ` Tom Tromey
2019-04-18 15:24 ` [RFC 3/8] Create MI commands using python Jan Vrany
2019-04-25 19:42   ` Tom Tromey
2019-04-18 15:24 ` [RFC 6/8] mi/python: Handle python exception when executiong python-defined MI commands Jan Vrany
2019-04-25 19:46   ` Tom Tromey
2019-04-26 10:19     ` Jan Vrany
2019-04-18 15:24 ` [RFC 8/8] mi/python: Allow redefinition of python " Jan Vrany
2019-04-25 19:50   ` Tom Tromey
2019-05-03 15:26     ` Jan Vrany
2019-05-06 21:40       ` Tom Tromey
2019-05-07 11:26         ` Jan Vrany
2019-05-07 13:09           ` Simon Marchi
2019-05-07 13:19             ` Jan Vrany
2019-05-08  0:10               ` Simon Marchi
2019-05-08 18:00                 ` Tom Tromey
2019-04-18 16:03 ` [RFC 0/8] Create MI commands using python Simon Marchi
2019-04-20  7:20   ` Jan Vrany [this message]
2019-04-18 16:12 ` [RFC 5/8] mi/python: Polish MI output of python commands Jan Vrany
2019-04-25 19:50   ` Tom Tromey
2019-04-25 18:03 ` [RFC 0/8] Create MI commands using python Tom Tromey
2019-04-25 19:00   ` Simon Marchi
2019-04-25 19:01     ` Simon Marchi
2019-05-14 11:24 ` [PATCH v2 3/5] " Jan Vrany
2019-05-17  4:29   ` Simon Marchi
2019-05-28 20:35     ` Jan Vrany
2019-05-14 11:24 ` [PATCH v2 1/5] Use std::map for MI commands in mi-cmds.c Jan Vrany
2019-05-14 11:24 ` [PATCH v2 0/5] Create MI commands using python Jan Vrany
2019-05-14 11:24 ` [PATCH v2 2/5] Use classes to represent MI Command instead of structures Jan Vrany
2019-05-17  3:12   ` Simon Marchi
2019-05-14 11:24 ` [PATCH v2 5/5] mi/python: Add tests for python-defined MI commands Jan Vrany
2019-05-14 11:57 ` [PATCH v2 4/5] mi/python: Allow redefinition of python " Jan Vrany

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=ff939c9c5490e968b99fca34a18bed21f7843d32.camel@fit.cvut.cz \
    --to=jan.vrany@fit.cvut.cz \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /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).