Documentation ¶
Overview ¶
Package gdb provides a convenient way to interact with the GDB/MI interface. The methods offered by this module are very low level, the main goals are:
- avoid the tedious parsing of the MI2 line-based text interface;
- bypass a known bug(https://sourceware.org/bugzilla/show_bug.cgi?id=8759) which prevents to distinguish the target program's output from MI2 records.
The objects returned as a result of the commands or as asynchronous notifications are generic Go maps suitable to be converted to JSON format with json.Unmarshal(). The fields present in such objects are blindly added according to the records returned from GDB (see https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Output-Syntax.html): tuples are map[string]interface{} and lists are []interface{}. There are a couple of exceptions to this:
- the record class, where present, is represented by the "class" field;
- the record type is represented using the "type" field as follows: "+": "status" "=": "notify" "~": "console" "@": "target" "&": "log"
- the optional result list is stored into a tuple under the "payload" field.
Index ¶
- type Gdb
- func (gdb *Gdb) Exit() error
- func (gdb *Gdb) Interrupt() error
- func (gdb *Gdb) Read(p []byte) (n int, err error)
- func (gdb *Gdb) Send(operation string, arguments ...string) (map[string]interface{}, error)
- func (gdb *Gdb) SendWithContext(ctx context.Context, operation string, arguments ...string) (map[string]interface{}, error)
- func (gdb *Gdb) Write(p []byte) (n int, err error)
- type NotificationCallback
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gdb ¶
type Gdb struct { io.ReadWriter Stdin io.WriteCloser // contains filtered or unexported fields }
Gdb represents a GDB instance. It implements the ReadWriter interface to read/write data from/to the target program's TTY.
func New ¶
func New(onNotification NotificationCallback) (*Gdb, error)
New creates and starts a new GDB instance. onNotification if not nil is the callback used to deliver to the client the asynchronous notifications sent by GDB. It returns a pointer to the newly created instance handled or an error.
func NewCmd ¶
func NewCmd(cmd []string, onNotification NotificationCallback) (*Gdb, error)
NewCmd creates a new GDB instance like New, but allows explicitely passing the gdb command to run (including all arguments). cmd is a which is passed as-is to exec.Command, so the first element should be the command to run, and the remaining elements should each contain a single argument.
func (*Gdb) Interrupt ¶
Interrupt sends a signal (SIGINT) to GDB so it can stop the target program and resume the processing of commands.
func (*Gdb) SendWithContext ¶
func (gdb *Gdb) SendWithContext(ctx context.Context, operation string, arguments ...string) (map[string]interface{}, error)
SendWithContext issues a command to GDB. Operation is the name of the MI2 command to execute without the leading "-" (this means that it is impossible send a CLI command), arguments is an optional list of arguments, in GDB parlance the can be: options, parameters or "--". It returns a generic object which represents the reply of GDB or an error in case the command cannot be delivered to GDB.
type NotificationCallback ¶
type NotificationCallback func(notification map[string]interface{})
NotificationCallback is a callback used to report the notifications that GDB send asynchronously through the MI2 interface. Responses to the commands are not part of these notifications. The notification generic object contains the notification sent by GDB.