From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id ECEC53858402 for ; Mon, 18 Oct 2021 15:46:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ECEC53858402 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [172.16.0.95] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 9A2AC1ECEB; Mon, 18 Oct 2021 11:46:27 -0400 (EDT) Subject: Re: [PATCHv2 3/3] gdb/python: add TargetConnection.send_remote_packet method To: Andrew Burgess , gdb-patches@sourceware.org References: <4cb41fa4660ae5c39493c1d8985017938eaceb8d.1634550226.git.andrew.burgess@embecosm.com> From: Simon Marchi Message-ID: <045d6d7c-e3d1-4e1c-d51f-907df15c9002@simark.ca> Date: Mon, 18 Oct 2021 11:46:27 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <4cb41fa4660ae5c39493c1d8985017938eaceb8d.1634550226.git.andrew.burgess@embecosm.com> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Oct 2021 15:46:29 -0000 On 2021-10-18 5:45 a.m., Andrew Burgess wrote: > This commit adds a new method to the gdb.TargetConnection object type: > 'send_remote_packet'. This new method is equivalent to the 'maint > packet' CLI command, it allows a custom packet to be sent to a remote > target. > > Not all gdb.TargetConnection instances will support > send_remote_packet, e.g. the 'native' target doesn't. If the > send_remote_packet method is invoked on a TargetConnection that is not > 'remote' or 'extended-remote' then an exception is thrown. > > The result of calling TargetConnection.send_remote_packet is a string > containing the reply that came from the remote. Another way of doing this (that I think fits well with Python) would be to have the send_remote_packet method only on RemoteTargetConnection objects. The RemoteTargetConnection class would inherit from TargetConnection. Users could check the type of the connection with: if isinstance(conn, gdb.RemoteTargetConnection): conn.send_remote_packet(...) If they try to call send_remote_packet on a target connection that isn't a RemoteTargetConnection, they just get a "'TargetConnection' object has no attribute 'send_remote_packet'" error. Doing it like this would allow us to add more target-specific information to RemoteTargetConnection, like the protocol used, address, port, without polluting the common interface. Simon