unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Daniel Tornabene <d.t.peters777@gmail.com>
To: guile-user <guile-user@gnu.org>
Subject: argument(s) for "make-command" in guile extension for gdb
Date: Sun, 5 Feb 2023 15:38:50 -0600	[thread overview]
Message-ID: <CAMo=-SCrDxhwyt5r4y0EDCx6hCuKZo0nqoJ06w-un4N-THMeNQ@mail.gmail.com> (raw)

Hey all, asked on irc but didn't get any bites, read some of the source and
didn't immediately make sense of it (skimmed the source more like it) so
I'm trying here:

I'm writing an extension for GDB using guile and while testing out
different code snippets I've hit a wall trying to figure out how to pass in
multiple arguments to a command created by make-command.
https://sourceware.org/gdb/onlinedocs/gdb/Commands-In-Guile.html#Commands-In-Guile
In the docs
#:invoke (lambda (self args from-tty)
is the argument list and "args" is denoted as a representation of the
arguments (plural) as "a string" passed to the new command. So far I've
been able to create a command that takes a single argument, passed as an
unquoted string or symbol in the "args" position, but if I try to pass a
string, or multiple arguments, or quote them, or quote a list containing
multiple args as a list of strings or symbols, nothing seems to work. As
usual I suspect that there is a simple solution to this I'm missing but at
this point I'm at a loss as to how to create a command that takes multiple
arguments. Any help or direction would be appreciated.


as an example, I've taken the documentation code for disassembly in guile
and attempted to adapt it as a straight forward guile-implemented command:
Here's the code:

;;; the function that the command calls
 (define (multi-dis reg size)
    (let*
       ((wreg       (simple-format #f "$~A" reg))
        (nreg        (value->integer (parse-and-eval wreg)))
        (mem        (open-memory #:start nreg))
        (bv            (get-bytevector-n mem size))
        (bv-port    (open-bytevector-input-port bv))
        (arch        (current-arch))
        (dis           (arch-disassemble arch nreg #:port bv-port #:offset
nreg))
        (one          (car dis)))
      (format  #t "this is the first value of your disassembly ~x \n"
(assq-ref one 'address))
      (simple-format #t "this is the second value of your disassembly ~A
\n" (assq-ref one 'asm))))

;;; the attempted command definition with incorrect arg list to demonstrate
(register-command! (make-command "m-dis"
                                  #:command-class COMMAND_OBSCURE
                                  #:invoke (lambda (self reg size)
                                             (multi-dis reg size))))

this is the only version I wrote that would compile, but it still failed,
with the second argument producing an unnamed " a syntax error in
expression, near `10'
where the command at the gdb interpreter was
(gdb) m-dis rax 10

other attempts included those listed above
#:invoke (lambda (self "reg size" from-tty)

#:invoke (lambda (self '(reg size) from-tty)

etc...
All of the above resulted in "bad argument list" errors being thrown on
attempted compilation.


                 reply	other threads:[~2023-02-05 21:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMo=-SCrDxhwyt5r4y0EDCx6hCuKZo0nqoJ06w-un4N-THMeNQ@mail.gmail.com' \
    --to=d.t.peters777@gmail.com \
    --cc=guile-user@gnu.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).