guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

argument(s) for "make-command" in guile extension for gdb


From: Daniel Tornabene
Subject: argument(s) for "make-command" in guile extension for gdb
Date: Sun, 5 Feb 2023 15:38:50 -0600

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 via email to

[Prev in Thread] Current Thread [Next in Thread]