binutils-gdb/gdb/common/rsp-low.h

102 lines
3.8 KiB
C
Raw Normal View History

move some rsp bits into rsp-low.h This moves various low-level remote serial protocol bits into common/rsp-low.[ch]. This is as close to a pure move as possible. There are some redundancies remaining but those will be dealt with in a subsequent patch. Note that the two variants of remote_escape_output disagreed on the treatment of "*". On the theory that quoting cannot hurt but the absence possibly can, I chose the gdbserver variant to be the canonical one. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare. * remote.c: Include rsp-low.h. (hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte) (fromhex, hex2bin, tohex, bin2hex, remote_escape_output) (remote_unescape_input): Move to common/rsp-low.c. * common/rsp-low.h: New file. * common/rsp-low.c: New file. * Makefile.in (SFILES): Add common/rsp-low.c. (HFILES_NO_SRCDIR): Add common/rsp-low.h. (COMMON_OBS): Add rsp-low.o. (rsp-low.o): New target. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * server.c: Include rsp-low.h. * remote-utils.h (convert_ascii_to_int, convert_int_to_ascii) (unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't declare. * remote-utils.c: Include rsp-low.h. (fromhex, hexchars, ishex, unhexify, tohex, hexify) (remote_escape_output, remote_unescape_input, unpack_varlen_hex) (convert_int_to_ascii, convert_ascii_to_int): Move to common/rsp-low.c. * regcache.c: Include rsp-low.h. * ax.c: Include rsp-low.h. * Makefile.in (SFILES): Add common/rsp-low.c. (OBS): Add rsp-low.o. (rsp-low.o): New target.
2014-01-18 22:32:47 +01:00
/* Low-level RSP routines for GDB, the GNU debugger.
Copyright (C) 1988-2018 Free Software Foundation, Inc.
move some rsp bits into rsp-low.h This moves various low-level remote serial protocol bits into common/rsp-low.[ch]. This is as close to a pure move as possible. There are some redundancies remaining but those will be dealt with in a subsequent patch. Note that the two variants of remote_escape_output disagreed on the treatment of "*". On the theory that quoting cannot hurt but the absence possibly can, I chose the gdbserver variant to be the canonical one. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare. * remote.c: Include rsp-low.h. (hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte) (fromhex, hex2bin, tohex, bin2hex, remote_escape_output) (remote_unescape_input): Move to common/rsp-low.c. * common/rsp-low.h: New file. * common/rsp-low.c: New file. * Makefile.in (SFILES): Add common/rsp-low.c. (HFILES_NO_SRCDIR): Add common/rsp-low.h. (COMMON_OBS): Add rsp-low.o. (rsp-low.o): New target. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * server.c: Include rsp-low.h. * remote-utils.h (convert_ascii_to_int, convert_int_to_ascii) (unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't declare. * remote-utils.c: Include rsp-low.h. (fromhex, hexchars, ishex, unhexify, tohex, hexify) (remote_escape_output, remote_unescape_input, unpack_varlen_hex) (convert_int_to_ascii, convert_ascii_to_int): Move to common/rsp-low.c. * regcache.c: Include rsp-low.h. * ax.c: Include rsp-low.h. * Makefile.in (SFILES): Add common/rsp-low.c. (OBS): Add rsp-low.o. (rsp-low.o): New target.
2014-01-18 22:32:47 +01:00
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef COMMON_RSP_LOW_H
#define COMMON_RSP_LOW_H
remote: C++ify thread_item and threads_listing_context This patch C++ifies the thread_item and threads_listing_context structures in remote.c. thread_item::{extra,name} are changed to std::string. As a result, there's a bit of awkwardness in remote_update_thread_list, where we have to xstrdup those strings when filling the private_thread_info structure. This is removed in the following patch, where private_thread_info is also C++ified and its corresponding fields made std::string too. The xstrdup then becomes an std::move. Other than that there's nothing really special, it's a usual day-to-day VEC -> vector and char* -> std::string change. It allows removing a cleanup in remote_update_thread_list. Note that an overload of hex2bin that returns a gdb::byte_vector is added, with corresponding selftests. gdb/ChangeLog: * remote.c (struct thread_item): Add constructor, disable copy construction and copy assignment, define default move construction and move assignment. <extra, name>: Change type to std::string. <core>: Initialize. <thread_handle>: Make non-pointer. (thread_item_t): Remove typedef. (DEF_VEC_O(thread_item_t)): Remove. (threads_listing_context) <contains_thread>: New method. <remove_thread>: New method. <items>: Change type to std::vector. (clear_threads_listing_context): Remove. (threads_listing_context_remove): Remove. (remote_newthread_step): Use thread_item constructor, adjust to change to std::vector. (start_thread): Use thread_item constructor, adjust to change to std::vector. (end_thread): Adjust to change to std::vector and std::string. (remote_get_threads_with_qthreadinfo): Use thread_item constructor, adjust to std::vector. (remote_update_thread_list): Adjust to change to std::vector and std::string, use threads_listing_context methods. (remove_child_of_pending_fork): Adjust. (remove_new_fork_children): Adjust. * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add rsp-low-selftests.c. (SUBDIR_UNITTESTS_OBS): Add rsp-low-selftests.o. * unittests/rsp-low-selftests.c: New file. * common/rsp-low.h: Include common/byte-vector.h. (hex2bin): New overload. * common/rsp-low.c (hex2bin): New overload.
2017-11-24 16:40:13 +01:00
#include "common/byte-vector.h"
move some rsp bits into rsp-low.h This moves various low-level remote serial protocol bits into common/rsp-low.[ch]. This is as close to a pure move as possible. There are some redundancies remaining but those will be dealt with in a subsequent patch. Note that the two variants of remote_escape_output disagreed on the treatment of "*". On the theory that quoting cannot hurt but the absence possibly can, I chose the gdbserver variant to be the canonical one. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare. * remote.c: Include rsp-low.h. (hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte) (fromhex, hex2bin, tohex, bin2hex, remote_escape_output) (remote_unescape_input): Move to common/rsp-low.c. * common/rsp-low.h: New file. * common/rsp-low.c: New file. * Makefile.in (SFILES): Add common/rsp-low.c. (HFILES_NO_SRCDIR): Add common/rsp-low.h. (COMMON_OBS): Add rsp-low.o. (rsp-low.o): New target. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * server.c: Include rsp-low.h. * remote-utils.h (convert_ascii_to_int, convert_int_to_ascii) (unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't declare. * remote-utils.c: Include rsp-low.h. (fromhex, hexchars, ishex, unhexify, tohex, hexify) (remote_escape_output, remote_unescape_input, unpack_varlen_hex) (convert_int_to_ascii, convert_ascii_to_int): Move to common/rsp-low.c. * regcache.c: Include rsp-low.h. * ax.c: Include rsp-low.h. * Makefile.in (SFILES): Add common/rsp-low.c. (OBS): Add rsp-low.o. (rsp-low.o): New target.
2014-01-18 22:32:47 +01:00
/* Convert hex digit A to a number, or throw an exception. */
extern int fromhex (int a);
/* Convert number NIB to a hex digit. */
extern int tohex (int nib);
/* Write a character representing the low order four bits of NIBBLE in
hex to *BUF. Returns BUF+1. */
move some rsp bits into rsp-low.h This moves various low-level remote serial protocol bits into common/rsp-low.[ch]. This is as close to a pure move as possible. There are some redundancies remaining but those will be dealt with in a subsequent patch. Note that the two variants of remote_escape_output disagreed on the treatment of "*". On the theory that quoting cannot hurt but the absence possibly can, I chose the gdbserver variant to be the canonical one. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare. * remote.c: Include rsp-low.h. (hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte) (fromhex, hex2bin, tohex, bin2hex, remote_escape_output) (remote_unescape_input): Move to common/rsp-low.c. * common/rsp-low.h: New file. * common/rsp-low.c: New file. * Makefile.in (SFILES): Add common/rsp-low.c. (HFILES_NO_SRCDIR): Add common/rsp-low.h. (COMMON_OBS): Add rsp-low.o. (rsp-low.o): New target. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * server.c: Include rsp-low.h. * remote-utils.h (convert_ascii_to_int, convert_int_to_ascii) (unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't declare. * remote-utils.c: Include rsp-low.h. (fromhex, hexchars, ishex, unhexify, tohex, hexify) (remote_escape_output, remote_unescape_input, unpack_varlen_hex) (convert_int_to_ascii, convert_ascii_to_int): Move to common/rsp-low.c. * regcache.c: Include rsp-low.h. * ax.c: Include rsp-low.h. * Makefile.in (SFILES): Add common/rsp-low.c. (OBS): Add rsp-low.o. (rsp-low.o): New target.
2014-01-18 22:32:47 +01:00
extern char *pack_nibble (char *buf, int nibble);
/* Write the low byte of BYTE in hex to *BUF. Returns BUF+2. */
move some rsp bits into rsp-low.h This moves various low-level remote serial protocol bits into common/rsp-low.[ch]. This is as close to a pure move as possible. There are some redundancies remaining but those will be dealt with in a subsequent patch. Note that the two variants of remote_escape_output disagreed on the treatment of "*". On the theory that quoting cannot hurt but the absence possibly can, I chose the gdbserver variant to be the canonical one. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare. * remote.c: Include rsp-low.h. (hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte) (fromhex, hex2bin, tohex, bin2hex, remote_escape_output) (remote_unescape_input): Move to common/rsp-low.c. * common/rsp-low.h: New file. * common/rsp-low.c: New file. * Makefile.in (SFILES): Add common/rsp-low.c. (HFILES_NO_SRCDIR): Add common/rsp-low.h. (COMMON_OBS): Add rsp-low.o. (rsp-low.o): New target. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * server.c: Include rsp-low.h. * remote-utils.h (convert_ascii_to_int, convert_int_to_ascii) (unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't declare. * remote-utils.c: Include rsp-low.h. (fromhex, hexchars, ishex, unhexify, tohex, hexify) (remote_escape_output, remote_unescape_input, unpack_varlen_hex) (convert_int_to_ascii, convert_ascii_to_int): Move to common/rsp-low.c. * regcache.c: Include rsp-low.h. * ax.c: Include rsp-low.h. * Makefile.in (SFILES): Add common/rsp-low.c. (OBS): Add rsp-low.o. (rsp-low.o): New target.
2014-01-18 22:32:47 +01:00
extern char *pack_hex_byte (char *pkt, int byte);
/* Read hex digits from BUFF and convert to a number, which is stored
in RESULT. Reads until a non-hex digit is seen. Returns a pointer
to the terminating character. */
Constify unpack_varlen_hex & fix fallout I ran into non-const unpack_varlen_hex while working on something else, and decided to just fix it first. Ends up constifying a good deal of remote packet parsing. gdb/ChangeLog: 2017-09-29 Pedro Alves <palves@redhat.com> * common/rsp-low.c (unpack_varlen_hex): Constify. * common/rsp-low.h (unpack_varlen_hex): Constify. * linux-nat.c (linux_child_static_tracepoint_markers_by_strid): Constify. * remote.c (remote_set_permissions, read_ptid) (remote_current_thread, remote_get_threads_with_qthreadinfo) (remote_static_tracepoint_marker_at) (remote_static_tracepoint_markers_by_strid) (stop_reply_extract_thread, remote_parse_stop_reply): Constify. * tracepoint.c (parse_trace_status, parse_tracepoint_status) (parse_tracepoint_definition, parse_tsv_definition) (parse_static_tracepoint_marker_definition): Constify. * tracepoint.h (parse_static_tracepoint_marker_definition) (parse_trace_status, parse_tracepoint_status) (parse_tracepoint_definition, parse_tsv_definition): Constify. gdb/gdbserver/ChangeLog: 2017-09-29 Pedro Alves <palves@redhat.com> * ax.c (gdb_parse_agent_expr): Constify. * ax.h (gdb_parse_agent_expr): Constify. * mem-break.c (add_breakpoint_condition, add_breakpoint_commands): Constify. * mem-break.h (add_breakpoint_condition, add_breakpoint_commands): Constify. * remote-utils.c (hex_or_minus_one, read_ptid): Constify. * remote-utils.h (read_ptid): Constify. * server.c (handle_qxfer_exec_file, handle_query, handle_v_cont) (process_point_options, process_serial_event): Constify. * tracepoint.c (add_tracepoint_action, cmd_qtdp, cmd_qtdpsrc) (cmd_qtdv, cmd_qtenable_disable, cmd_qtro, cmd_qtframe, cmd_qtp) (cmd_qtbuffer): Constify.
2017-09-29 18:15:36 +02:00
extern const char *unpack_varlen_hex (const char *buff, ULONGEST *result);
move some rsp bits into rsp-low.h This moves various low-level remote serial protocol bits into common/rsp-low.[ch]. This is as close to a pure move as possible. There are some redundancies remaining but those will be dealt with in a subsequent patch. Note that the two variants of remote_escape_output disagreed on the treatment of "*". On the theory that quoting cannot hurt but the absence possibly can, I chose the gdbserver variant to be the canonical one. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare. * remote.c: Include rsp-low.h. (hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte) (fromhex, hex2bin, tohex, bin2hex, remote_escape_output) (remote_unescape_input): Move to common/rsp-low.c. * common/rsp-low.h: New file. * common/rsp-low.c: New file. * Makefile.in (SFILES): Add common/rsp-low.c. (HFILES_NO_SRCDIR): Add common/rsp-low.h. (COMMON_OBS): Add rsp-low.o. (rsp-low.o): New target. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * server.c: Include rsp-low.h. * remote-utils.h (convert_ascii_to_int, convert_int_to_ascii) (unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't declare. * remote-utils.c: Include rsp-low.h. (fromhex, hexchars, ishex, unhexify, tohex, hexify) (remote_escape_output, remote_unescape_input, unpack_varlen_hex) (convert_int_to_ascii, convert_ascii_to_int): Move to common/rsp-low.c. * regcache.c: Include rsp-low.h. * ax.c: Include rsp-low.h. * Makefile.in (SFILES): Add common/rsp-low.c. (OBS): Add rsp-low.o. (rsp-low.o): New target.
2014-01-18 22:32:47 +01:00
/* HEX is a string of characters representing hexadecimal digits.
Convert pairs of hex digits to bytes and store sequentially into
BIN. COUNT is the maximum number of characters to convert. This
will convert fewer characters if the number of hex characters
actually seen is odd, or if HEX terminates before COUNT characters.
Returns the number of characters actually converted. */
move some rsp bits into rsp-low.h This moves various low-level remote serial protocol bits into common/rsp-low.[ch]. This is as close to a pure move as possible. There are some redundancies remaining but those will be dealt with in a subsequent patch. Note that the two variants of remote_escape_output disagreed on the treatment of "*". On the theory that quoting cannot hurt but the absence possibly can, I chose the gdbserver variant to be the canonical one. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare. * remote.c: Include rsp-low.h. (hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte) (fromhex, hex2bin, tohex, bin2hex, remote_escape_output) (remote_unescape_input): Move to common/rsp-low.c. * common/rsp-low.h: New file. * common/rsp-low.c: New file. * Makefile.in (SFILES): Add common/rsp-low.c. (HFILES_NO_SRCDIR): Add common/rsp-low.h. (COMMON_OBS): Add rsp-low.o. (rsp-low.o): New target. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * server.c: Include rsp-low.h. * remote-utils.h (convert_ascii_to_int, convert_int_to_ascii) (unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't declare. * remote-utils.c: Include rsp-low.h. (fromhex, hexchars, ishex, unhexify, tohex, hexify) (remote_escape_output, remote_unescape_input, unpack_varlen_hex) (convert_int_to_ascii, convert_ascii_to_int): Move to common/rsp-low.c. * regcache.c: Include rsp-low.h. * ax.c: Include rsp-low.h. * Makefile.in (SFILES): Add common/rsp-low.c. (OBS): Add rsp-low.o. (rsp-low.o): New target.
2014-01-18 22:32:47 +01:00
extern int hex2bin (const char *hex, gdb_byte *bin, int count);
remote: C++ify thread_item and threads_listing_context This patch C++ifies the thread_item and threads_listing_context structures in remote.c. thread_item::{extra,name} are changed to std::string. As a result, there's a bit of awkwardness in remote_update_thread_list, where we have to xstrdup those strings when filling the private_thread_info structure. This is removed in the following patch, where private_thread_info is also C++ified and its corresponding fields made std::string too. The xstrdup then becomes an std::move. Other than that there's nothing really special, it's a usual day-to-day VEC -> vector and char* -> std::string change. It allows removing a cleanup in remote_update_thread_list. Note that an overload of hex2bin that returns a gdb::byte_vector is added, with corresponding selftests. gdb/ChangeLog: * remote.c (struct thread_item): Add constructor, disable copy construction and copy assignment, define default move construction and move assignment. <extra, name>: Change type to std::string. <core>: Initialize. <thread_handle>: Make non-pointer. (thread_item_t): Remove typedef. (DEF_VEC_O(thread_item_t)): Remove. (threads_listing_context) <contains_thread>: New method. <remove_thread>: New method. <items>: Change type to std::vector. (clear_threads_listing_context): Remove. (threads_listing_context_remove): Remove. (remote_newthread_step): Use thread_item constructor, adjust to change to std::vector. (start_thread): Use thread_item constructor, adjust to change to std::vector. (end_thread): Adjust to change to std::vector and std::string. (remote_get_threads_with_qthreadinfo): Use thread_item constructor, adjust to std::vector. (remote_update_thread_list): Adjust to change to std::vector and std::string, use threads_listing_context methods. (remove_child_of_pending_fork): Adjust. (remove_new_fork_children): Adjust. * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add rsp-low-selftests.c. (SUBDIR_UNITTESTS_OBS): Add rsp-low-selftests.o. * unittests/rsp-low-selftests.c: New file. * common/rsp-low.h: Include common/byte-vector.h. (hex2bin): New overload. * common/rsp-low.c (hex2bin): New overload.
2017-11-24 16:40:13 +01:00
/* Like the above, but return a gdb::byte_vector. */
gdb::byte_vector hex2bin (const char *hex);
Implement the ability to set/unset environment variables to GDBserver when starting the inferior This patch implements the ability to set/unset environment variables on the remote target, mimicking what GDB already offers to the user. There are two features present here: user-set and user-unset environment variables. User-set environment variables are only the variables that are explicitly set by the user, using the 'set environment' command. This means that variables that were already present in the environment when starting GDB/GDBserver are not transmitted/considered by this feature. User-unset environment variables are variables that are explicitly unset by the user, using the 'unset environment' command. The idea behind this patch is to store user-set and user-unset environment variables in two separate sets, both part of gdb_environ. Then, when extended_remote_create_inferior is preparing to start the inferior, it will iterate over the two sets and set/unset variables accordingly. Three new packets are introduced: - QEnvironmentHexEncoded, which is used to set environment variables, and contains an hex-encoded string in the format "VAR=VALUE" (VALUE can be empty if the user set a variable with a null value, by doing 'set environment VAR='). - QEnvironmentUnset, which is used to unset environment variables, and contains an hex-encoded string in the format "VAR". - QEnvironmentReset, which is always the first packet to be transmitted, and is used to reset the environment, i.e., discard any changes made by the user on previous runs. The QEnvironmentHexEncoded packet is inspired on LLDB's extensions to the RSP. Details about it can be seen here: <https://raw.githubusercontent.com/llvm-mirror/lldb/master/docs/lldb-gdb-remote.txt> I decided not to implement the QEnvironment packet because it is considered deprecated by LLDB. This packet, on LLDB, serves the same purpose of QEnvironmentHexEncoded, but sends the information using a plain text, non-hex-encoded string. The other two packets are new. This patch also includes updates to the documentation, testsuite, and unit tests, without introducing regressions. gdb/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * NEWS (Changes since GDB 8.0): Add entry mentioning new support for setting/unsetting environment variables on the remote target. (New remote packets): Add entries for QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset. * common/environ.c (gdb_environ::operator=): Extend method to handle m_user_set_env_list and m_user_unset_env_list. (gdb_environ::clear): Likewise. (match_var_in_string): Change type of first parameter from 'char *' to 'const char *'. (gdb_environ::set): Extend method to handle m_user_set_env_list and m_user_unset_env_list. (gdb_environ::unset): Likewise. (gdb_environ::clear_user_set_env): New method. (gdb_environ::user_set_envp): Likewise. (gdb_environ::user_unset_envp): Likewise. * common/environ.h (gdb_environ): Handle m_user_set_env_list and m_user_unset_env_list on move constructor/assignment. (unset): Add new default parameter 'update_unset_list = true'. (clear_user_set_env): New method. (user_set_envp): Likewise. (user_unset_envp): Likewise. (m_user_set_env_list): New std::set. (m_user_unset_env_list): Likewise. * common/rsp-low.c (hex2str): New function. (bin2hex): New overload for bin2hex function. * common/rsp-low.c (hex2str): New prototype. (str2hex): New overload prototype. * remote.c: Include "environ.h". Add QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset. (remote_protocol_features): Add QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset packets. (send_environment_packet): New function. (extended_remote_environment_support): Likewise. (extended_remote_create_inferior): Call extended_remote_environment_support. (_initialize_remote): Add QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset packet configs. * unittests/environ-selftests.c (gdb_selftest_env_var): New variable. (test_vector_initialization): New function. (test_init_from_host_environ): Likewise. (test_reinit_from_host_environ): Likewise. (test_set_A_unset_B_unset_A_cannot_find_A_can_find_B): Likewise. (test_unset_set_empty_vector): Likewise. (test_vector_clear): Likewise. (test_std_move): Likewise. (test_move_constructor): (test_self_move): Likewise. (test_set_unset_reset): Likewise. (run_tests): Rewrite in terms of the functions above. gdb/gdbserver/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * server.c (handle_general_set): Handle QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset packets. (handle_query): Inform remote that QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset are supported. gdb/doc/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.texinfo (set environment): Add @anchor. Explain that environment variables set by the user are sent to GDBserver. (unset environment): Likewise, but for unsetting variables. (Connecting) <Remote Packet>: Add "environment-hex-encoded", "QEnvironmentHexEncoded", "environment-unset", "QEnvironmentUnset", "environment-reset" and "QEnvironmentReset" to the table. (Remote Protocol) <QEnvironmentHexEncoded, QEnvironmentUnset, QEnvironmentReset>: New item, explaining the packet. gdb/testsuite/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.base/share-env-with-gdbserver.c: New file. * gdb.base/share-env-with-gdbserver.exp: Likewise.
2017-06-29 21:06:07 +02:00
/* Like hex2bin, but return a std::string. */
extern std::string hex2str (const char *hex);
Get rid of VEC(static_tracepoint_marker_p) This patch replaces VEC(static_tracepoint_marker_p) with std::vector, and does some c++ification around that. I thought a new overload of hex2str was useful, so I added it as well as corresponding unit tests. I also added an overload of ui_out::field_string that takes an std::string directly. gdb/ChangeLog: * tracepoint.h (struct static_tracepoint_marker): Initialize fields, define default constructor, move constructor and move assignment, disable the rest. <str_id, extra>: Make std::string. (release_static_tracepoint_marker): Remove. (free_current_marker): Remove. * tracepoint.c (free_current_marker): Remove. (parse_static_tracepoint_marker_definition): Adjust to std::string, use new hex2str overload. (release_static_tracepoint_marker): Remove. (print_one_static_tracepoint_marker): Get marker by reference and adjust to std::string. (info_static_tracepoint_markers_command): Adjust to std::vector changes * target.h (static_tracepoint_marker_p): Remove typedef. (DEF_VEC_P(static_tracepoint_marker_p)): Remove. (struct target_ops) <to_static_tracepoint_marker_at>: Return bool. <to_static_tracepoint_markers_by_strid>: Return std::vector. * target-debug.h (target_debug_print_VEC_static_tracepoint_marker_p_p): Remove. (target_debug_print_std_vector_static_tracepoint_marker): New. (target_debug_print_struct_static_tracepoint_marker_p): Rename to... (target_debug_print_static_tracepoint_marker_p): ... this. * target-delegates.c: Re-generate. * breakpoint.h (struct tracepoint) <static_trace_marker_id>: Make std::string. * breakpoint.c (init_breakpoint_sal): Adjust to std::string. (decode_static_tracepoint_spec): Adjust to std::vector. (tracepoint_print_one_detail): Adjust to std::string. (strace_marker_decode_location): Adjust to std::string. (update_static_tracepoint): Adjust to std::string, remove call to release_static_tracepoint_marker. * linux-nat.c (linux_child_static_tracepoint_markers_by_strid): Adjust to std::vector. * remote.c (remote_static_tracepoint_marker_at): Return bool. (remote_static_tracepoint_markers_by_strid): Adjust to std::vector. * common/rsp-low.h (hex2str): New overload with explicit count of bytes. * common/rsp-low.c (hex2str): New overload with explicit count of bytes. * unittests/rsp-low-selftests.c (test_hex2str): New function. (_initialize_rsp_low_selftests): Add test_hex2str test. * unittests/tracepoint-selftests.c (test_parse_static_tracepoint_marker_definition): Adjust to std::string.
2018-03-22 05:27:19 +01:00
/* Like hex2bin, but return a std::string. */
extern std::string hex2str (const char *hex, int count);
/* Convert some bytes to a hexadecimal representation. BIN holds the
bytes to convert. COUNT says how many bytes to convert. The
resulting characters are stored in HEX, followed by a NUL
character. Returns the number of bytes actually converted. */
move some rsp bits into rsp-low.h This moves various low-level remote serial protocol bits into common/rsp-low.[ch]. This is as close to a pure move as possible. There are some redundancies remaining but those will be dealt with in a subsequent patch. Note that the two variants of remote_escape_output disagreed on the treatment of "*". On the theory that quoting cannot hurt but the absence possibly can, I chose the gdbserver variant to be the canonical one. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare. * remote.c: Include rsp-low.h. (hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte) (fromhex, hex2bin, tohex, bin2hex, remote_escape_output) (remote_unescape_input): Move to common/rsp-low.c. * common/rsp-low.h: New file. * common/rsp-low.c: New file. * Makefile.in (SFILES): Add common/rsp-low.c. (HFILES_NO_SRCDIR): Add common/rsp-low.h. (COMMON_OBS): Add rsp-low.o. (rsp-low.o): New target. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * server.c: Include rsp-low.h. * remote-utils.h (convert_ascii_to_int, convert_int_to_ascii) (unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't declare. * remote-utils.c: Include rsp-low.h. (fromhex, hexchars, ishex, unhexify, tohex, hexify) (remote_escape_output, remote_unescape_input, unpack_varlen_hex) (convert_int_to_ascii, convert_ascii_to_int): Move to common/rsp-low.c. * regcache.c: Include rsp-low.h. * ax.c: Include rsp-low.h. * Makefile.in (SFILES): Add common/rsp-low.c. (OBS): Add rsp-low.o. (rsp-low.o): New target.
2014-01-18 22:32:47 +01:00
extern int bin2hex (const gdb_byte *bin, char *hex, int count);
Implement the ability to set/unset environment variables to GDBserver when starting the inferior This patch implements the ability to set/unset environment variables on the remote target, mimicking what GDB already offers to the user. There are two features present here: user-set and user-unset environment variables. User-set environment variables are only the variables that are explicitly set by the user, using the 'set environment' command. This means that variables that were already present in the environment when starting GDB/GDBserver are not transmitted/considered by this feature. User-unset environment variables are variables that are explicitly unset by the user, using the 'unset environment' command. The idea behind this patch is to store user-set and user-unset environment variables in two separate sets, both part of gdb_environ. Then, when extended_remote_create_inferior is preparing to start the inferior, it will iterate over the two sets and set/unset variables accordingly. Three new packets are introduced: - QEnvironmentHexEncoded, which is used to set environment variables, and contains an hex-encoded string in the format "VAR=VALUE" (VALUE can be empty if the user set a variable with a null value, by doing 'set environment VAR='). - QEnvironmentUnset, which is used to unset environment variables, and contains an hex-encoded string in the format "VAR". - QEnvironmentReset, which is always the first packet to be transmitted, and is used to reset the environment, i.e., discard any changes made by the user on previous runs. The QEnvironmentHexEncoded packet is inspired on LLDB's extensions to the RSP. Details about it can be seen here: <https://raw.githubusercontent.com/llvm-mirror/lldb/master/docs/lldb-gdb-remote.txt> I decided not to implement the QEnvironment packet because it is considered deprecated by LLDB. This packet, on LLDB, serves the same purpose of QEnvironmentHexEncoded, but sends the information using a plain text, non-hex-encoded string. The other two packets are new. This patch also includes updates to the documentation, testsuite, and unit tests, without introducing regressions. gdb/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * NEWS (Changes since GDB 8.0): Add entry mentioning new support for setting/unsetting environment variables on the remote target. (New remote packets): Add entries for QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset. * common/environ.c (gdb_environ::operator=): Extend method to handle m_user_set_env_list and m_user_unset_env_list. (gdb_environ::clear): Likewise. (match_var_in_string): Change type of first parameter from 'char *' to 'const char *'. (gdb_environ::set): Extend method to handle m_user_set_env_list and m_user_unset_env_list. (gdb_environ::unset): Likewise. (gdb_environ::clear_user_set_env): New method. (gdb_environ::user_set_envp): Likewise. (gdb_environ::user_unset_envp): Likewise. * common/environ.h (gdb_environ): Handle m_user_set_env_list and m_user_unset_env_list on move constructor/assignment. (unset): Add new default parameter 'update_unset_list = true'. (clear_user_set_env): New method. (user_set_envp): Likewise. (user_unset_envp): Likewise. (m_user_set_env_list): New std::set. (m_user_unset_env_list): Likewise. * common/rsp-low.c (hex2str): New function. (bin2hex): New overload for bin2hex function. * common/rsp-low.c (hex2str): New prototype. (str2hex): New overload prototype. * remote.c: Include "environ.h". Add QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset. (remote_protocol_features): Add QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset packets. (send_environment_packet): New function. (extended_remote_environment_support): Likewise. (extended_remote_create_inferior): Call extended_remote_environment_support. (_initialize_remote): Add QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset packet configs. * unittests/environ-selftests.c (gdb_selftest_env_var): New variable. (test_vector_initialization): New function. (test_init_from_host_environ): Likewise. (test_reinit_from_host_environ): Likewise. (test_set_A_unset_B_unset_A_cannot_find_A_can_find_B): Likewise. (test_unset_set_empty_vector): Likewise. (test_vector_clear): Likewise. (test_std_move): Likewise. (test_move_constructor): (test_self_move): Likewise. (test_set_unset_reset): Likewise. (run_tests): Rewrite in terms of the functions above. gdb/gdbserver/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * server.c (handle_general_set): Handle QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset packets. (handle_query): Inform remote that QEnvironmentHexEncoded, QEnvironmentUnset and QEnvironmentReset are supported. gdb/doc/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.texinfo (set environment): Add @anchor. Explain that environment variables set by the user are sent to GDBserver. (unset environment): Likewise, but for unsetting variables. (Connecting) <Remote Packet>: Add "environment-hex-encoded", "QEnvironmentHexEncoded", "environment-unset", "QEnvironmentUnset", "environment-reset" and "QEnvironmentReset" to the table. (Remote Protocol) <QEnvironmentHexEncoded, QEnvironmentUnset, QEnvironmentReset>: New item, explaining the packet. gdb/testsuite/ChangeLog: 2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.base/share-env-with-gdbserver.c: New file. * gdb.base/share-env-with-gdbserver.exp: Likewise.
2017-06-29 21:06:07 +02:00
/* Overloaded version of bin2hex that returns a std::string. */
extern std::string bin2hex (const gdb_byte *bin, int count);
/* Convert BUFFER, binary data at least LEN_UNITS addressable memory units
long, into escaped binary data in OUT_BUF. Only copy memory units that fit
completely in OUT_BUF. Set *OUT_LEN_UNITS to the number of units from
BUFFER successfully encoded in OUT_BUF, and return the number of bytes used
in OUT_BUF. The total number of bytes in the output buffer will be at most
OUT_MAXLEN_BYTES. This function properly escapes '*', and so is suitable
move some rsp bits into rsp-low.h This moves various low-level remote serial protocol bits into common/rsp-low.[ch]. This is as close to a pure move as possible. There are some redundancies remaining but those will be dealt with in a subsequent patch. Note that the two variants of remote_escape_output disagreed on the treatment of "*". On the theory that quoting cannot hurt but the absence possibly can, I chose the gdbserver variant to be the canonical one. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare. * remote.c: Include rsp-low.h. (hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte) (fromhex, hex2bin, tohex, bin2hex, remote_escape_output) (remote_unescape_input): Move to common/rsp-low.c. * common/rsp-low.h: New file. * common/rsp-low.c: New file. * Makefile.in (SFILES): Add common/rsp-low.c. (HFILES_NO_SRCDIR): Add common/rsp-low.h. (COMMON_OBS): Add rsp-low.o. (rsp-low.o): New target. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * server.c: Include rsp-low.h. * remote-utils.h (convert_ascii_to_int, convert_int_to_ascii) (unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't declare. * remote-utils.c: Include rsp-low.h. (fromhex, hexchars, ishex, unhexify, tohex, hexify) (remote_escape_output, remote_unescape_input, unpack_varlen_hex) (convert_int_to_ascii, convert_ascii_to_int): Move to common/rsp-low.c. * regcache.c: Include rsp-low.h. * ax.c: Include rsp-low.h. * Makefile.in (SFILES): Add common/rsp-low.c. (OBS): Add rsp-low.o. (rsp-low.o): New target.
2014-01-18 22:32:47 +01:00
for the server side as well as the client. */
extern int remote_escape_output (const gdb_byte *buffer, int len_units,
int unit_size, gdb_byte *out_buf,
int *out_len_units, int out_maxlen_bytes);
move some rsp bits into rsp-low.h This moves various low-level remote serial protocol bits into common/rsp-low.[ch]. This is as close to a pure move as possible. There are some redundancies remaining but those will be dealt with in a subsequent patch. Note that the two variants of remote_escape_output disagreed on the treatment of "*". On the theory that quoting cannot hurt but the absence possibly can, I chose the gdbserver variant to be the canonical one. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * remote.h (hex2bin, bin2hex, unpack_varlen_hex): Don't declare. * remote.c: Include rsp-low.h. (hexchars, ishex, unpack_varlen_hex, pack_nibble, pack_hex_byte) (fromhex, hex2bin, tohex, bin2hex, remote_escape_output) (remote_unescape_input): Move to common/rsp-low.c. * common/rsp-low.h: New file. * common/rsp-low.c: New file. * Makefile.in (SFILES): Add common/rsp-low.c. (HFILES_NO_SRCDIR): Add common/rsp-low.h. (COMMON_OBS): Add rsp-low.o. (rsp-low.o): New target. 2014-02-12 Tom Tromey <tromey@redhat.com> * tracepoint.c: Include rsp-low.h. * server.c: Include rsp-low.h. * remote-utils.h (convert_ascii_to_int, convert_int_to_ascii) (unhexify, hexify, remote_escape_output, unpack_varlen_hex): Don't declare. * remote-utils.c: Include rsp-low.h. (fromhex, hexchars, ishex, unhexify, tohex, hexify) (remote_escape_output, remote_unescape_input, unpack_varlen_hex) (convert_int_to_ascii, convert_ascii_to_int): Move to common/rsp-low.c. * regcache.c: Include rsp-low.h. * ax.c: Include rsp-low.h. * Makefile.in (SFILES): Add common/rsp-low.c. (OBS): Add rsp-low.o. (rsp-low.o): New target.
2014-01-18 22:32:47 +01:00
/* Convert BUFFER, escaped data LEN bytes long, into binary data
in OUT_BUF. Return the number of bytes written to OUT_BUF.
Raise an error if the total number of bytes exceeds OUT_MAXLEN.
This function reverses remote_escape_output. */
extern int remote_unescape_input (const gdb_byte *buffer, int len,
gdb_byte *out_buf, int out_maxlen);
#endif /* COMMON_RSP_LOW_H */