public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Tom Tromey <tromey@adacore.com>,  gdb-patches@sourceware.org
Subject: Re: [PATCH 8/9] Implement gdb.execute_mi
Date: Thu, 18 May 2023 11:57:10 -0600	[thread overview]
Message-ID: <87h6s9zfnt.fsf@tromey.com> (raw)
In-Reply-To: <83bkk3tqh3.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 04 Apr 2023 22:08:40 +0300")

>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:

>> +Conversely, it is possible to execute @sc{GDB/MI} commands from
Eli>                                          ^^^^^^^^^^^
Eli> In print, @sc produces "small caps" only for lower-case letters, so
Eli> the above should use @sc{gdb/mi} (here and elsewhere).

Alright.  I was just copying something I saw somewhere else.
I'll go fix those up.

>> +Invoke a @sc{GDB/MI} command.  @var{command} is the name of the
>> +command, a string.  (Note that the leading @samp{-} should be omitted
>> +here.)

Eli> Why is it a good idea to omit the leading dash?

In MI, the leading '-' is not really part of the command name.  It seems
to be some kind of syntactic marker, though I have no idea why, as there
aren't any other possible such markers as far as I can tell.

Eli> And what does it mean for command switches, which start with two
Eli> dashes?

Nothing.

>> +This function returns a Python dictionary whose contents reflect the
>> +corresponding @sc{GDB/MI} command's output.  Refer to the
>> +documentation for these commands for details.  Lists are represented
>> +as Python lists, and tuples are represented as Python dictionaries.

Eli> Is this description enough to understand what will be returned?  What
Eli> about error messages, for example -- how are those returned?

I added a bit of text about this, and also a new test.

If the command fails, it will raise a Python exception.

It's possible in theory for a command to print some kind of warning but
still succeed.  (I don't know if this ever really happens.)  In this
case there's no way to know that this occurred.

I've appended the updated python.texi patch.

Tom


diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 5d714ee1ca3..99417802453 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -4584,6 +4584,42 @@ commands have been added:
 (@value{GDBP})
 @end smallexample
 
+Conversely, it is possible to execute @sc{gdb/mi} commands from
+Python, with the results being a Python object and not a
+specially-formatted string.  This is done with the
+@code{gdb.execute_mi} function.
+
+@findex gdb.execute_mi
+@defun gdb.execute_mi (command @r{[}, arg @r{]}@dots{})
+Invoke a @sc{gdb/mi} command.  @var{command} is the name of the
+command, a string.
+
+Note that the leading @samp{-} that is normally used with @sc{gdb/mi}
+is not technically part of the command name, and so should be omitted
+here.
+
+The arguments, @var{arg}, are passed to the command.  Each argument
+must also be a string.
+
+This function returns a Python dictionary whose contents reflect the
+corresponding @sc{GDB/MI} command's output.  Refer to the
+documentation for these commands for details.  Lists are represented
+as Python lists, and tuples are represented as Python dictionaries.
+
+If the command fails, it will raise a Python exception.
+@end defun
+
+Here is how this works using the commands from the example above:
+
+@smallexample
+(@value{GDBP}) python print(gdb.execute_mi("echo-dict", "abc", "def", "ghi"))
+@{'dict': @{'argv': ['abc', 'def', 'ghi']@}@}
+(@value{GDBP}) python print(gdb.execute_mi("echo-list", "abc", "def", "ghi"))
+@{'list': ['abc', 'def', 'ghi']@}
+(@value{GDBP}) python print(gdb.execute_mi("echo-string", "abc", "def", "ghi"))
+@{'string': 'abc, def, ghi'@}
+@end smallexample
+
 @node Parameters In Python
 @subsubsection Parameters In Python
 

  reply	other threads:[~2023-05-18 17:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04 17:08 [PATCH 0/9] Implement the DAP "loadedSources" request Tom Tromey
2023-04-04 17:08 ` [PATCH 1/9] Use field_signed from Python MI commands Tom Tromey
2023-04-04 17:08 ` [PATCH 2/9] Use member initializers in mi_parse Tom Tromey
2023-04-04 17:08 ` [PATCH 3/9] Use accessor for mi_parse::args Tom Tromey
2023-04-04 17:08 ` [PATCH 4/9] Change mi_parse_argv to a method Tom Tromey
2023-04-04 17:08 ` [PATCH 5/9] Introduce "static constructor" for mi_parse Tom Tromey
2023-04-04 17:08 ` [PATCH 6/9] Introduce mi_parse helper methods Tom Tromey
2023-04-04 17:08 ` [PATCH 7/9] Add second mi_parse constructor Tom Tromey
2023-04-04 17:08 ` [PATCH 8/9] Implement gdb.execute_mi Tom Tromey
2023-04-04 19:08   ` Eli Zaretskii
2023-05-18 17:57     ` Tom Tromey [this message]
2023-05-18 18:31       ` Eli Zaretskii
2023-05-18 20:15         ` Tom Tromey
2023-05-18 20:34           ` Matt Rice
2023-05-19 15:57             ` Tom Tromey
2023-04-04 17:08 ` [PATCH 9/9] Implement DAP loadedSources request Tom Tromey
2023-04-10 23:43 ` [PATCH 0/9] Implement the DAP "loadedSources" request Matt Rice

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=87h6s9zfnt.fsf@tromey.com \
    --to=tromey@adacore.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@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).