unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* argument(s) for "make-command" in guile extension for gdb
@ 2023-02-05 21:38 Daniel Tornabene
  0 siblings, 0 replies; only message in thread
From: Daniel Tornabene @ 2023-02-05 21:38 UTC (permalink / raw)
  To: guile-user

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.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-05 21:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-05 21:38 argument(s) for "make-command" in guile extension for gdb Daniel Tornabene

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).