From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24852 invoked by alias); 18 Dec 2013 23:15:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 24843 invoked by uid 89); 18 Dec 2013 23:15:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ee0-f50.google.com Received: from mail-ee0-f50.google.com (HELO mail-ee0-f50.google.com) (74.125.83.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 18 Dec 2013 23:15:18 +0000 Received: by mail-ee0-f50.google.com with SMTP id c41so130172eek.37 for ; Wed, 18 Dec 2013 15:15:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=+mV6IzB3wYEizW4FBwNTbKN3edWFMx03wEsWAhuQlvE=; b=XG1hmJWrSVxrOgw4lLt8cRz+uy75XD6F6LUmAtW86VXIvuuXdzzc+mPVWc1aROBMTx MwPnblO6UY97qeWmag2tmsZfRdGsVC79R9OEAuPXIA7vU6n7IHzwI5v96ZpMI7geTWqd H17qIfAiD9OXpMjkIhYHc+lWw3+ReVeFTWWQNXoCzyWL7Mh9tM4X46Zj7nPVKtJeNPr4 q/RclRUe1TtvbrzX8s7mub2tRIATih5ACWnZaJXivdq4o8MS70OFlgTTfEiAL0MGjSrX W4AdjYzDJGo9bWptQN+LeW9E7nyhNj4jljXhG9x5NdlM6NwSBW9iJmFm2vUliRfCUygS JCsA== X-Gm-Message-State: ALoCoQmH57uKNk8nZkkk0xa+Ev57Rp+4/Xg4gD0bS3UhTgk/ztnm1pC8qEU4cXaqC/KuYcc+4pBoPxChLnILpLDO7ZU8XeuFa4KtFnENo8zJyQPZB2lKzOHXqLgw6bVysvwuug3yPLu4e2/CqR2e3cWKNTCl9Jm5qD/DLZokxX6cIWddeYJrxiAFHfO0GtlkIvHbkUpT0MZFDvu3p08alOK/QYINxdJe/Q== MIME-Version: 1.0 X-Received: by 10.15.75.68 with SMTP id k44mr31852617eey.57.1387408513290; Wed, 18 Dec 2013 15:15:13 -0800 (PST) Received: by 10.14.151.72 with HTTP; Wed, 18 Dec 2013 15:15:13 -0800 (PST) In-Reply-To: References: <871u1j2ldi.fsf@fleche.redhat.com> Date: Wed, 18 Dec 2013 23:15:00 -0000 Message-ID: Subject: Re: [RFC/Patch] Call overloaded operators to perform valid Python operations on struct/class values. From: Siva Chandra To: Doug Evans Cc: Tom Tromey , gdb-patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2013-12/txt/msg00729.txt.bz2 On Wed, Dec 18, 2013 at 8:37 AM, Doug Evans wrote: > Not that this could work, but for illustration's sake: > smart_ptr = gdb.parse_and_eval ("my_smart_ptr"); > dereferenced_smart_ptr = gdb.parse_and_eval("*%V" % smart_ptr) Should work. May be the '%' syntax would not (I am not sure). But, we could consider other alternatives [Replace occurrences of $1, $2, etc for example]. Is this an exhaustive solution or a cool fallback option when no other Pythonic way works? Consider something more complicated but uses only valid Python operators: C++: obj1.method1(obj2_ptr->method2(obj3 + obj4)) * obj5 This could be done in a Pythonic way as: obj1.invoke('method1', obj2_ptr.invoke('method2', obj3 + obj4)) * obj5 If we do this in a string replacement way: gdb.parse_and_eval('$1.method1($2->method2($3 + $4)) * $5', obj1, obj2_ptr, obj3, obj4, obj5) Above, the values objN in Python are equivalents of their C++ values. Also, I have cooked up the 'invoke' method on gdb.Value objects but we could have one for real. Lets see how your example would look like with this 'invoke' in place: C++: *my_smart_ptr; Python: smart_ptr.invoke('operator*') Or, one could have a debug method named "deref" (assuming debug methods would soon be a reality :-) to be an equivalent of "operator*". The Python would then look like this: smart_ptr.invoke('deref') [Side topic: Should smart_ptr.dereference() invoke 'operator*'? The documentation says this: "... behavior of Value.dereference is identical to applying the C unary operator * on a given value." And, I remember writing this myself :-)]