Rizin
unix-like reverse engineering framework and cli tools
|
#include "gdbclient/responses.h"
#include "gdbclient/commands.h"
#include "gdbclient/core.h"
#include "gdbclient/xml.h"
#include "arch.h"
#include "libgdbr.h"
#include "gdbr_common.h"
#include "packet.h"
#include "rz_util/rz_strbuf.h"
#include "rz_cons.h"
#include "rz_debug.h"
#include <assert.h>
Go to the source code of this file.
Macros | |
#define | QSUPPORTED_MAX_RETRIES 5 |
Variables | |
struct { | |
ut8 * buf | |
ut64 buflen | |
ut64 maxlen | |
bool valid | |
bool init | |
} | reg_cache |
attaches to a process
pid | of the process to attach to |
Definition at line 439 of file core.c.
References buffer_size, calloc(), cmd, CMD_ATTACH, test_evm::end, free(), g, gdbr_check_extended_mode(), gdbr_lock_enter(), gdbr_lock_leave(), handle_attach(), int, NULL, pid, read_packet(), reg_cache, send_msg(), and snprintf.
Referenced by __open().
|
static |
Definition at line 90 of file core.c.
References g.
Referenced by gdbr_connect(), gdbr_lock_enter(), and gdbr_lock_tryenter().
checks for extended mode availability
Definition at line 406 of file core.c.
References test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), read_packet(), reg_cache, send_ack(), and send_msg().
Referenced by gdbr_attach().
checks which subcommands of the vCont packet are supported
Definition at line 335 of file core.c.
References test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), NULL, read_packet(), send_ack(), and send_msg().
Referenced by gdbr_connect().
Definition at line 1539 of file core.c.
References test_evm::end, eprintf, g, gdbr_lock_enter(), gdbr_lock_leave(), handle_vFile_close(), read_packet(), send_msg(), and snprintf.
Referenced by gdbr_parse_processes_xml(), and rz_debug_gdb_map_get().
Function connects to a gdbserver instance.
server | string that represents the host |
number | that represents the port |
Definition at line 155 of file core.c.
References test_evm::end, g, GDB_MAX_PKTSZ, GDB_REMOTE_TYPE_LLDB, gdbr_break_process(), gdbr_check_vcont(), gdbr_connect_lldb(), gdbr_lock_enter(), gdbr_lock_leave(), gdbr_read_target_xml(), gdbr_select(), handle_qC(), handle_qSupported(), i, message, NULL, QSUPPORTED_MAX_RETRIES, read_packet(), reg_cache_init(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_sleep_begin(), rz_cons_sleep_end(), RZ_MAX, RZ_MIN, rz_socket_close(), rz_socket_connect_serial(), rz_socket_connect_tcp, rz_sys_getenv(), sdb_fmt(), send_ack(), and send_msg().
Referenced by __open().
Definition at line 129 of file core.c.
References test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), gdbr_read_target_xml(), read_packet(), reg_cache_init(), send_ack(), and send_msg().
Referenced by gdbr_connect().
Definition at line 950 of file core.c.
References CMD_C_CONT, CMD_C_CONT_SIG, command, test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), NULL, send_vcont(), snprintf, and write_thread_id().
Referenced by rz_debug_gdb_continue().
detaches from a process
pid | of the process to detach from (only the multiprocess/pid variant) |
Definition at line 495 of file core.c.
References test_evm::end, g, gdbr_disconnect(), gdbr_lock_enter(), gdbr_lock_leave(), reg_cache, and send_msg().
Referenced by __system(), and rz_debug_gdb_detach().
Definition at line 520 of file core.c.
References buffer_size, calloc(), cmd, CMD_DETACH_MP, test_evm::end, free(), g, gdbr_lock_enter(), gdbr_lock_leave(), NULL, pid, read_packet(), reg_cache, send_ack(), send_msg(), and snprintf.
Referenced by __system(), and rz_debug_gdb_detach().
disconnects the lib
Definition at line 283 of file core.c.
References test_evm::end, free(), g, gdbr_lock_enter(), gdbr_lock_leave(), reg_cache, and rz_socket_close().
Referenced by __close(), gdbr_detach(), stop_reason_exit(), and stop_reason_terminated().
Get absolute name of file executed to create a process
Definition at line 1635 of file core.c.
References test_evm::end, free(), g, gdbr_lock_enter(), gdbr_lock_leave(), len, memset(), msg, NULL, off, path, PFMT64x, pid, read_packet(), rz_str_append(), send_ack(), send_msg(), snprintf, and ut64().
Referenced by __open(), __system(), gdbr_pids_list(), gdbr_threads_list(), and rz_debug_gdb_info().
Get offset of lowest segment returned by 'qOffsets'
Definition at line 1931 of file core.c.
References test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), isxdigit, min, NULL, off, read_packet(), rz_str_startswith(), send_ack(), send_msg(), UINT64_MAX, and ut64().
Referenced by rz_debug_gdb_map_get().
void gdbr_invalidate_reg_cache | ( | void | ) |
invalidates the reg cache
Definition at line 1570 of file core.c.
References reg_cache.
Referenced by __system().
Definition at line 1696 of file core.c.
References test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), msg, pid, read_packet(), send_ack(), send_msg(), snprintf, and write_thread_id().
Referenced by gdbr_threads_list().
kills the process the remote gdbserver is debugging (TODO: handle pid)
pid | of the process to detach from (only the multiprocess/pid variant) \retuns a failure code (currently -1) or 0 if call successfully |
Definition at line 572 of file core.c.
References test_evm::end, g, gdbr_kill_pid(), gdbr_lock_enter(), gdbr_lock_leave(), reg_cache, and send_msg().
Referenced by rz_debug_gdb_kill().
Definition at line 605 of file core.c.
References buffer_size, calloc(), cmd, CMD_KILL_MP, test_evm::end, free(), g, gdbr_lock_enter(), gdbr_lock_leave(), NULL, pid, read_packet(), reg_cache, send_ack(), send_msg(), and snprintf.
Referenced by gdbr_kill().
Acquires the gdbr lock and sets up breaking.
Definition at line 105 of file core.c.
References g, gdbr_break_process(), rz_cons_break_push(), rz_cons_sleep_begin(), rz_cons_sleep_end(), and rz_th_lock_enter().
Referenced by __system(), gdbr_attach(), gdbr_check_extended_mode(), gdbr_check_vcont(), gdbr_close_file(), gdbr_connect(), gdbr_connect_lldb(), gdbr_continue(), gdbr_detach(), gdbr_detach_pid(), gdbr_disconnect(), gdbr_exec_file_read(), gdbr_get_baddr(), gdbr_is_thread_dead(), gdbr_kill(), gdbr_kill_pid(), gdbr_open_file(), gdbr_pids_list(), gdbr_read_file(), gdbr_read_memory(), gdbr_read_memory_page(), gdbr_read_registers_lldb(), gdbr_select(), gdbr_send_qRcmd(), gdbr_step(), gdbr_stop_reason(), gdbr_threads_list(), gdbr_write_bin_registers(), gdbr_write_memory(), gdbr_write_reg(), gdbr_write_register(), gdbr_write_registers(), remove_bp(), send_vcont(), set_bp(), and test_command().
void gdbr_lock_leave | ( | libgdbr_t * | g | ) |
Releases the gdbr lock.
Definition at line 117 of file core.c.
References assert(), g, rz_cons_break_pop(), and rz_th_lock_leave().
Referenced by __system(), gdbr_attach(), gdbr_check_extended_mode(), gdbr_check_vcont(), gdbr_close_file(), gdbr_connect(), gdbr_connect_lldb(), gdbr_continue(), gdbr_detach(), gdbr_detach_pid(), gdbr_disconnect(), gdbr_exec_file_read(), gdbr_get_baddr(), gdbr_is_thread_dead(), gdbr_kill(), gdbr_kill_pid(), gdbr_open_file(), gdbr_pids_list(), gdbr_read_file(), gdbr_read_memory(), gdbr_read_memory_page(), gdbr_read_registers(), gdbr_read_registers_lldb(), gdbr_select(), gdbr_send_qRcmd(), gdbr_step(), gdbr_stop_reason(), gdbr_threads_list(), gdbr_write_bin_registers(), gdbr_write_memory(), gdbr_write_reg(), gdbr_write_register(), gdbr_write_registers(), remove_bp(), send_vcont(), set_bp(), and test_command().
Definition at line 96 of file core.c.
References g, gdbr_break_process(), rz_cons_break_push(), and rz_th_lock_tryenter().
Referenced by gdbr_read_registers().
File read from remote target (only one file open at a time for now)
Definition at line 1445 of file core.c.
References buf, buf_len, calloc(), test_evm::end, eprintf, flags, free(), g, gdbr_lock_enter(), gdbr_lock_leave(), handle_vFile_open(), pack_hex(), read_packet(), send_msg(), and snprintf.
Referenced by gdbr_parse_processes_xml(), and rz_debug_gdb_map_get().
get a list of the child processes of the given pid
Definition at line 1731 of file core.c.
References test_evm::end, eprintf, free(), g, gdbr_exec_file_read(), gdbr_lock_enter(), gdbr_lock_leave(), gdbr_read_processes_xml(), rz_debug_pid_t::gid, list(), NULL, rz_debug_pid_t::path, rz_debug_pid_t::pid, pid, rz_debug_pid_t::ppid, read_packet(), read_thread_id(), rz_debug_pid_t::runnable, RZ_DBG_PROC_STOP, rz_list_append(), rz_list_free(), rz_list_new(), RZ_NEW0, send_ack(), send_msg(), rz_debug_pid_t::status, strdup(), and rz_debug_pid_t::uid.
Referenced by rz_debug_gdb_pids().
Definition at line 1485 of file core.c.
References command, test_evm::end, eprintf, g, GDB_MAX_PKTSZ, gdbr_lock_enter(), gdbr_lock_leave(), handle_vFile_pread(), INT32_MAX, PFMT64d, PFMT64x, read_packet(), RZ_MAX, RZ_MIN, send_msg(), snprintf, and ut64().
Referenced by gdbr_parse_processes_xml(), and rz_debug_gdb_map_get().
Definition at line 812 of file core.c.
References test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), gdbr_read_memory_page(), len, and autogen_x86imm::tmp.
Referenced by debug_gdb_read_at().
Definition at line 727 of file core.c.
References CMD_READMEM, command, delta, test_evm::end, eprintf, g, GDB_MAX_PKTSZ, gdbr_lock_enter(), gdbr_lock_leave(), handle_m(), len, memcpy(), PFMT64x, read_packet(), RZ_MAX, RZ_MIN, send_msg(), snprintf, and ut64().
Referenced by gdbr_read_memory().
Definition at line 685 of file core.c.
References CMD_READREGS, test_evm::end, g, GDB_REMOTE_TYPE_LLDB, gdbr_lock_leave(), gdbr_lock_tryenter(), gdbr_read_registers_lldb(), handle_g(), memcpy(), memset(), read_packet(), reg_cache, and send_msg().
Referenced by gdbr_write_reg(), gdbr_write_registers(), and rz_debug_gdb_reg_read().
Definition at line 653 of file core.c.
References test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), handle_lldb_read_reg(), memcpy(), read_packet(), reg_cache, and send_msg().
Referenced by gdbr_read_registers().
Definition at line 1377 of file core.c.
References BREAKPOINT, g, and remove_bp().
Referenced by rz_debug_gdb_breakpoint().
Definition at line 1392 of file core.c.
References ACCESS_WATCHPOINT, g, and remove_bp().
Referenced by rz_debug_gdb_breakpoint().
Definition at line 1380 of file core.c.
References g, HARDWARE_BREAKPOINT, and remove_bp().
Referenced by rz_debug_gdb_breakpoint().
Definition at line 1388 of file core.c.
References g, READ_WATCHPOINT, and remove_bp().
Referenced by rz_debug_gdb_breakpoint().
Definition at line 1384 of file core.c.
References g, remove_bp(), and WRITE_WATCHPOINT.
Referenced by rz_debug_gdb_breakpoint().
Select pid-tid
Definition at line 304 of file core.c.
References cmd, test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), pid, read_packet(), reg_cache, send_ack(), send_msg(), and write_thread_id().
Referenced by gdbr_connect(), rz_debug_gdb_select(), and rz_debug_gdb_wait().
int gdbr_send_qRcmd | ( | libgdbr_t * | g, |
const char * | cmd, | ||
PrintfCallback | cb_printf | ||
) |
sends a qRcmd packet which basically passes a command to the remote target's interpreter.
Definition at line 1574 of file core.c.
References buf, calloc(), cmd, test_evm::end, free(), g, gdbr_lock_enter(), gdbr_lock_leave(), isxdigit, len, pack_hex(), read_packet(), reg_cache, send_ack(), send_msg(), and unpack_hex().
Referenced by __system().
Function sets normal breakpoint (0xcc, int3)
gdbr | instance that contains the current context |
addrress | at this position the breakpoint will be added |
conditions | TODO: examine how this condition string should look like |
Definition at line 1357 of file core.c.
References BREAKPOINT, conditions, g, and set_bp().
Referenced by rz_debug_gdb_breakpoint().
Definition at line 1373 of file core.c.
References ACCESS_WATCHPOINT, conditions, g, and set_bp().
Referenced by rz_debug_gdb_breakpoint().
Definition at line 1361 of file core.c.
References conditions, g, HARDWARE_BREAKPOINT, and set_bp().
Referenced by rz_debug_gdb_breakpoint().
Definition at line 1369 of file core.c.
References conditions, g, READ_WATCHPOINT, and set_bp().
Referenced by rz_debug_gdb_breakpoint().
Definition at line 1365 of file core.c.
References conditions, g, set_bp(), and WRITE_WATCHPOINT.
Referenced by rz_debug_gdb_breakpoint().
Definition at line 929 of file core.c.
References CMD_C_STEP, test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), NULL, sdb_fmt(), send_vcont(), and write_thread_id().
Referenced by rz_debug_gdb_step().
gets reason why remote target stopped
Definition at line 391 of file core.c.
References test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), handle_stop_reason(), read_packet(), and send_msg().
Referenced by rz_debug_gdb_info(), and rz_debug_gdb_wait().
get list of threads for given pid
Definition at line 1833 of file core.c.
References test_evm::end, free(), g, gdbr_exec_file_read(), gdbr_is_thread_dead(), gdbr_lock_enter(), gdbr_lock_leave(), rz_debug_pid_t::gid, list(), NULL, rz_debug_pid_t::path, rz_debug_pid_t::pid, pid, read_packet(), read_thread_id(), rz_debug_pid_t::runnable, RZ_DBG_PROC_DEAD, RZ_DBG_PROC_STOP, rz_list_append(), rz_list_free(), rz_list_new(), RZ_NEW0, send_ack(), send_msg(), rz_debug_pid_t::status, strdup(), and rz_debug_pid_t::uid.
Referenced by rz_debug_gdb_threads().
Function writes general purpose registers.
gdbr | instance that contains the current context |
reg | contains the registers that should be written reg contains a comma separated string that uses <regname>=value,<regname>=value i.e. eax=0x123,ebx=0x234 |
Definition at line 975 of file core.c.
References buffer_size, calloc(), CMD_WRITEREGS, command, test_evm::end, free(), g, gdbr_lock_enter(), gdbr_lock_leave(), handle_G(), len, NULL, pack_hex(), read_packet(), reg_cache, regs, send_msg(), and snprintf.
Referenced by gdbr_write_reg().
Definition at line 860 of file core.c.
References calloc(), CMD_WRITEMEM, test_evm::end, free(), g, GDB_MAX_PKTSZ, gdbr_lock_enter(), gdbr_lock_leave(), handle_M(), len, pack_hex(), PFMT64x, read_packet(), RZ_MAX, send_msg(), snprintf, autogen_x86imm::tmp, and ut64().
Referenced by debug_gdb_write_at().
Definition at line 1058 of file core.c.
References test_evm::end, eprintf, g, gdbr_lock_enter(), gdbr_lock_leave(), gdbr_read_registers(), gdbr_write_bin_registers(), gdbr_write_register(), i, len, memcpy(), reg_cache, and value.
Referenced by rz_debug_gdb_reg_write().
Definition at line 1018 of file core.c.
References CMD_WRITEREG, command, test_evm::end, eprintf, g, gdbr_lock_enter(), gdbr_lock_leave(), handle_P(), len, memset(), MSG_NOT_SUPPORTED, pack_hex(), read_packet(), reg_cache, send_msg(), snprintf, and value.
Referenced by gdbr_write_reg().
Definition at line 1096 of file core.c.
References buffer_size, calloc(), CMD_WRITEREGS, command, test_evm::end, eprintf, free(), g, gdbr_lock_enter(), gdbr_lock_leave(), gdbr_read_registers(), handle_G(), hex2char(), i, len, memcpy(), memset(), NULL, pack_hex(), read_packet(), reg, reg_cache, RZ_FREE, send_msg(), snprintf, ut64(), value, and x.
char hex2char | ( | char * | hex | ) |
Definition at line 88 of file utils.c.
References hex, and hex2int().
Referenced by gdbr_write_registers().
|
static |
Definition at line 80 of file core.c.
References g, malloc(), and reg_cache.
Referenced by gdbr_connect(), and gdbr_connect_lldb().
int remove_bp | ( | libgdbr_t * | g, |
ut64 | address, | ||
enum Breakpoint | type, | ||
int | sizebp | ||
) |
Definition at line 1396 of file core.c.
References ACCESS_WATCHPOINT, BREAKPOINT, CMD_RBP, CMD_RHBP, CMD_RHWA, CMD_RHWR, CMD_RHWW, test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), handle_removebp(), HARDWARE_BREAKPOINT, PFMT64x, read_packet(), READ_WATCHPOINT, send_msg(), snprintf, autogen_x86imm::tmp, type, and WRITE_WATCHPOINT.
Referenced by gdbr_remove_bp(), gdbr_remove_hwa(), gdbr_remove_hwbp(), gdbr_remove_hwr(), and gdbr_remove_hww().
Function sends a vCont command to the gdbserver.
g | thre "instance" of the current libgdbr session |
command | the command that will be sent (i.e. 's,S,c,C...') |
Definition at line 1212 of file core.c.
References CMD_C, command, test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), handle_cont(), NULL, read_packet(), reg_cache, rz_cons_sleep_begin(), rz_cons_sleep_end(), rz_socket_is_connected(), rz_socket_write(), send_msg(), snprintf, and autogen_x86imm::tmp.
Referenced by gdbr_continue(), and gdbr_step().
int set_bp | ( | libgdbr_t * | g, |
ut64 | address, | ||
const char * | conditions, | ||
enum Breakpoint | type, | ||
int | sizebp | ||
) |
Definition at line 1302 of file core.c.
References ACCESS_WATCHPOINT, BREAKPOINT, CMD_BP, CMD_HBP, CMD_HWA, CMD_HWR, CMD_HWW, test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), handle_setbp(), HARDWARE_BREAKPOINT, PFMT64x, read_packet(), READ_WATCHPOINT, send_msg(), snprintf, autogen_x86imm::tmp, type, and WRITE_WATCHPOINT.
Referenced by gdbr_set_bp(), gdbr_set_hwa(), gdbr_set_hwbp(), gdbr_set_hwr(), and gdbr_set_hww().
Definition at line 1193 of file core.c.
References command, test_evm::end, g, gdbr_lock_enter(), gdbr_lock_leave(), hexdump(), read_packet(), and send_msg().
Definition at line 75 of file core.c.
Referenced by _server_handle_exec_file_read(), _server_handle_g(), _server_handle_M(), _server_handle_m(), _server_handle_qC(), _server_handle_qfThreadInfo(), _server_handle_qSupported(), gdbr_open_file(), gdbr_send_qRcmd(), rz_core_analysis_hasrefs_to_depth(), rz_core_syscallf(), uv__getpwuid_r(), uv_os_environ(), uv_os_gethostname(), and uv_os_tmpdir().
ut64 buflen |
Definition at line 76 of file core.c.
Referenced by _server_handle_exec_file_read(), _zip_cp437_to_utf8(), _zip_find_central_dir(), blowfish_crypt(), blowfish_decrypt(), cmd_print_op(), construct_rop_gadget(), file_vprintf(), handle_lldb_read_reg(), old_transform_op(), prompt_read(), rc2_crypt(), rc2_dcrypt(), rc4_crypt(), rol_crypt(), ror_crypt(), rot_crypt(), rot_decrypt(), rz_analysis_get_jmptbl_info(), rz_cmd_help(), rz_core_transform_op(), rz_core_write_block_op_at(), rz_debug_gdb_map_get(), rz_debug_gdb_reg_read(), rz_debug_gdb_reg_write(), rz_debug_qnx_reg_read(), rz_debug_qnx_reg_write(), rz_main_rz_asm(), rz_str_stringify_raw_buffer(), rz_type_format_nulltermstring(), sdb_querysf(), spp_run(), uv__fs_sendfile_emul(), uv__getrandom(), uv__random(), uv__random_devurandom(), uv__random_getentropy(), uv__random_getrandom(), uv__random_readpath(), uv__random_rtlgenrandom(), uv__random_sysctl(), uv__read(), uv__search_path(), uv_err_name_r(), uv_random(), uv_strerror_r(), and xor_crypt().
bool init | ( | void | ) |
Definition at line 77 of file core.c.
Referenced by fill_window(), gzifstream::gzifstream(), gzofstream::gzofstream(), lzma_lzma2_decoder_init(), lzma_lzma_decoder_init(), lzma_next_filter_init(), parseMod(), print_insn_mips(), rz_reg_free_internal(), and sh_il_signed().
ut64 maxlen |
Definition at line 76 of file core.c.
Referenced by cabd_extract(), de_bruijn(), de_bruijn_seq(), parse_line_header_source(), run_basic_block_analysis(), rz_core_rtr_cmd(), rz_core_yank_string(), rz_name_filter(), rz_regex_comp(), rz_table_tofancystring(), rz_table_tosimplestring(), search_hash(), strnlen(), and uv__fs_readlink().
struct { ... } reg_cache |
Referenced by gdbr_attach(), gdbr_check_extended_mode(), gdbr_detach(), gdbr_detach_pid(), gdbr_disconnect(), gdbr_invalidate_reg_cache(), gdbr_kill(), gdbr_kill_pid(), gdbr_read_registers(), gdbr_read_registers_lldb(), gdbr_select(), gdbr_send_qRcmd(), gdbr_write_bin_registers(), gdbr_write_reg(), gdbr_write_register(), gdbr_write_registers(), reg_cache_init(), and send_vcont().
bool valid |
Definition at line 77 of file core.c.
Referenced by compute_ref(), construct_rop_gadget(), do_rd_expr(), rd_character(), rd_expr(), rd_expr_and(), rd_expr_equal(), rd_expr_or(), rd_expr_shift(), rd_expr_unequal(), rd_expr_xor(), rd_factor(), rd_otherbasenumber(), rd_term(), rd_value(), rz_bin_pdb_parse_from_buf(), rz_debug_bp_add(), rz_il_validate_effect(), rz_il_validate_pure(), skipword(), and test_valids().