Struct gdb_command::GdbCommand

source ·
pub struct GdbCommand<'a> { /* private fields */ }
Expand description

Struct contains information about arguments for gdb to run.

Implementations§

Construct GdbCommand from given ExecType.

Arguments
  • type - execution type to run gdb.

Add stdin for executable. You should call this method before using r method.

Arguments
  • file - path to stdin file

Add new gdb command to execute.

Arguments
  • cmd - gdb command parameter (-ex).
Examples found in repository?
src/lib.rs (line 204)
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
    pub fn bt(&mut self) -> &'a mut GdbCommand {
        self.ex("bt")
    }

    /// Add command to get disassembly (-ex 'x/16i $pc')
    pub fn disassembly(&mut self) -> &'a mut GdbCommand {
        self.ex("x/16i $pc")
    }

    /// Add command to get registers (-ex 'i r')
    pub fn regs(&mut self) -> &'a mut GdbCommand {
        self.ex("i r")
    }

    /// Add command to get mappings (-ex 'info proc mappings')
    pub fn mappings(&mut self) -> &'a mut GdbCommand {
        self.ex("info proc mappings")
    }

    /// Add command to get cmd line.
    pub fn cmdline(&mut self) -> &'a mut GdbCommand {
        self.ex("info proc cmdline")
    }

    /// Add command to get environment variables
    pub fn env(&mut self) -> &'a mut GdbCommand {
        self.ex("show environment")
    }

    /// Add command to get process status
    pub fn status(&mut self) -> &'a mut GdbCommand {
        self.ex("info proc status")
    }

    /// Add command to get info
    pub fn sources(&mut self) -> &'a mut GdbCommand {
        self.ex("info sources")
    }

    /// Break at main
    pub fn bmain(&mut self) -> &'a mut GdbCommand {
        self.args.push("-ex".to_string());
        self.args.push("b main".to_string());
        self
    }

    /// Print lines from source file
    ///
    /// # Arguments
    ///
    /// * `location` - lines centered around the line specified by location.
    /// If None then location is current line.
    pub fn list<T: Into<Option<&'a str>>>(&mut self, location: T) -> &'a mut GdbCommand {
        if let Some(loc) = location.into() {
            self.ex(format!("list {}", loc))
        } else {
            self.ex("list")
        }
    }

    /// Get memory contents (string of hex bytes)
    ///
    /// # Arguments
    ///
    /// * `expr` - expression that represents the start memory address.
    ///
    /// * `size` - size of memory in bytes to get.
    pub fn mem<T: AsRef<str>>(&mut self, expr: T, size: usize) -> &'a mut GdbCommand {
        self.ex(format!("x/{}bx {}", size, expr.as_ref()))
    }

    /// Add command to get siginfo
    pub fn siginfo(&mut self) -> &'a mut GdbCommand {
        self.ex("p/x $_siginfo")
    }

Run gdb with provided commands and return raw stdout.

Examples found in repository?
src/lib.rs (line 285)
283
284
285
286
287
288
289
290
291
    pub fn launch(&self) -> error::Result<Vec<String>> {
        // Get raw output from Gdb.
        let stdout = self.raw()?;

        // Split stdout into lines.
        let output = String::from_utf8_lossy(&stdout);

        self.parse(output)
    }

Add command to run program

Arguments
  • file - path to stdin file

Add command to continue execution

Add command to get backtrace (-ex bt)

Add command to get disassembly (-ex ‘x/16i $pc’)

Add command to get registers (-ex ‘i r’)

Add command to get mappings (-ex ‘info proc mappings’)

Add command to get cmd line.

Add command to get environment variables

Add command to get process status

Add command to get info

Break at main

Print lines from source file

Arguments
  • location - lines centered around the line specified by location. If None then location is current line.

Get memory contents (string of hex bytes)

Arguments
  • expr - expression that represents the start memory address.

  • size - size of memory in bytes to get.

Add command to get siginfo

Execute gdb and get result for each command.

Return value.

The return value is a vector of strings for each command executed.

Parse raw gdb output.

Return value.

The return value is a vector of strings for each command executed.

Examples found in repository?
src/lib.rs (line 290)
283
284
285
286
287
288
289
290
291
    pub fn launch(&self) -> error::Result<Vec<String>> {
        // Get raw output from Gdb.
        let stdout = self.raw()?;

        // Split stdout into lines.
        let output = String::from_utf8_lossy(&stdout);

        self.parse(output)
    }

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.