|
CBMC
|
Interface for running and querying GDB. More...
#include <gdb_api.h>
Collaboration diagram for gdb_apit:Classes | |
| struct | memory_addresst |
| Memory address imbued with the explicit boolean data indicating if the address is null or not. More... | |
| struct | pointer_valuet |
| Data associated with the value of a pointer, i.e. More... | |
Public Types | |
| using | commandst = std::forward_list< std::string > |
Public Member Functions | |
| gdb_apit (const std::vector< std::string > &args, const bool log=false) | |
| Create a gdb_apit object. | |
| ~gdb_apit () | |
| Terminate the gdb process and close open streams (for reading from and writing to gdb) | |
| size_t | query_malloc_size (const std::string &pointer_expr) |
Get the exact allocated size for a pointer pointer_expr. | |
| void | create_gdb_process () |
Create a new gdb process for analysing the binary indicated by the first element in args | |
| bool | run_gdb_to_breakpoint (const std::string &breakpoint) |
| Run gdb to the given breakpoint. | |
| void | run_gdb_from_core (const std::string &corefile) |
| Run gdb with the given core file. | |
| std::optional< std::string > | get_value (const std::string &expr) |
| Get the memory address pointed to by the given pointer expression. | |
| pointer_valuet | get_memory (const std::string &expr) |
Get the value of a pointer associated with expr. | |
| const commandst & | get_command_log () |
| Return the vector of commands that have been written to gdb so far. | |
Protected Types | |
| enum class | gdb_statet { NOT_CREATED , CREATED , STOPPED } |
| typedef std::map< std::string, std::string > | gdb_output_recordt |
Protected Member Functions | |
| void | write_to_gdb (const std::string &command) |
| std::string | read_next_line () |
| std::string | read_most_recent_line () |
| std::string | eval_expr (const std::string &expr) |
| gdb_output_recordt | get_most_recent_record (const std::string &tag, const bool must_exist=false) |
| bool | most_recent_line_has_tag (const std::string &tag) |
| bool | was_command_accepted () |
| void | check_command_accepted () |
| void | collect_malloc_calls () |
| Intercepts the gdb-analysis at the malloc call-site to add the corresponding information into allocated_memory. | |
| std::string | get_value_from_record (const gdb_output_recordt &record, const std::string &value_name) |
| Locate and return the value for a given name. | |
| bool | hit_malloc_breakpoint (const gdb_output_recordt &stopped_record) |
| Check if the breakpoint we hit is inside a malloc. | |
| std::string | get_register_value (const gdb_output_recordt &record) |
| Parse the record produced by listing register value. | |
Static Protected Member Functions | |
| static gdb_output_recordt | parse_gdb_output_record (const std::string &s) |
| static std::string | r_opt (const std::string ®ex) |
| static std::string | r_or (const std::string ®ex_left, const std::string ®ex_right) |
Protected Attributes | |
| std::vector< std::string > | args |
| FILE * | response_stream |
| FILE * | command_stream |
| const bool | log |
| commandst | command_log |
| gdb_statet | gdb_state |
| std::map< std::string, size_t > | allocated_memory |
| track the allocated size for each malloc call maps hexadecimal address to the number of bytes | |
| const std::string | r_hex_addr = R"((0x(?:0|[1-9a-f][0-9a-f]*)))" |
| const std::string | r_id = R"(<([^<>]+)>)" |
| const std::string | r_char = R"(\\"(\\\\[0-7]{3})\\")" |
| const std::string | r_string = R"((\\".*\\"))" |
| const std::string | malloc_name = "malloc" |
| using gdb_apit::commandst = std::forward_list<std::string> |
|
protected |
|
strongprotected |
Create a gdb_apit object.
| args | arguments to pass to gdb, the first argument is the command to execute |
| log | boolean indicating whether gdb input and output should be logged |
Definition at line 28 of file gdb_api.cpp.
| gdb_apit::~gdb_apit | ( | ) |
Terminate the gdb process and close open streams (for reading from and writing to gdb)
Definition at line 33 of file gdb_api.cpp.
|
protected |
|
protected |
Intercepts the gdb-analysis at the malloc call-site to add the corresponding information into allocated_memory.
Definition at line 288 of file gdb_api.cpp.
| void gdb_apit::create_gdb_process | ( | ) |
Create a new gdb process for analysing the binary indicated by the first element in args
Definition at line 67 of file gdb_api.cpp.
|
protected |
Definition at line 416 of file gdb_api.cpp.
| const gdb_apit::commandst & gdb_apit::get_command_log | ( | ) |
Return the vector of commands that have been written to gdb so far.
Definition at line 190 of file gdb_api.cpp.
| pointer_valuet gdb_apit::get_memory | ( | const std::string & | expr | ) |
Get the value of a pointer associated with expr.
| expr | the expression to be analyzed |
pointer_valuet filled with data gdb produced for expr
|
protected |
Definition at line 250 of file gdb_api.cpp.
|
protected |
Parse the record produced by listing register value.
| record | gdb record for one register value |
| std::optional< std::string > gdb_apit::get_value | ( | const std::string & | expr | ) |
Get the memory address pointed to by the given pointer expression.
| expr | an expression of pointer type (e.g., &x with x being of type int or p with p being of type int *) |
|
protected |
Locate and return the value for a given name.
| record | gdb record to search |
| value_name | name of the value to be extracted |
value_name
|
protected |
Check if the breakpoint we hit is inside a malloc.
| stopped_record | gdb record pertaining to a breakpoint being hit |
Definition at line 269 of file gdb_api.cpp.
|
staticprotected |
Get the exact allocated size for a pointer pointer_expr.
| pointer_expr | expression with a pointer name |
Definition at line 56 of file gdb_api.cpp.
|
staticprotected |
|
protected |
Definition at line 235 of file gdb_api.cpp.
|
protected |
Definition at line 196 of file gdb_api.cpp.
Run gdb with the given core file.
| corefile | core dump |
Definition at line 275 of file gdb_api.cpp.
Run gdb to the given breakpoint.
| breakpoint | the breakpoint to set (can be e.g. a line number or a function name) |
Definition at line 345 of file gdb_api.cpp.
|
protected |
Definition at line 169 of file gdb_api.cpp.
|
protected |
|
protected |
|
protected |