From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27269 invoked by alias); 12 Oct 2012 13:08:48 -0000 Received: (qmail 27257 invoked by uid 22791); 12 Oct 2012 13:08:47 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-pb0-f41.google.com (HELO mail-pb0-f41.google.com) (209.85.160.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 12 Oct 2012 13:08:43 +0000 Received: by mail-pb0-f41.google.com with SMTP id rq2so3246152pbb.0 for ; Fri, 12 Oct 2012 06:08:42 -0700 (PDT) Received: by 10.68.241.133 with SMTP id wi5mr13495409pbc.48.1350047322862; Fri, 12 Oct 2012 06:08:42 -0700 (PDT) Received: from archlinux ([117.202.20.138]) by mx.google.com with ESMTPS id qd9sm4435748pbb.31.2012.10.12.06.08.40 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 12 Oct 2012 06:08:42 -0700 (PDT) From: chandan r To: "Andrew Pinski" Cc: gdb@sourceware.org Subject: Re: Extending GDB: Python: Wrong handling of 64-bit pointers References: <87y5jfr1ri.fsf@gmail.com>,,<87mwzs8m30.fsf@gmail.com>, User-agent: mu4e 0.9.8.5; emacs 24.2.1 In-reply-to: Date: Fri, 12 Oct 2012 13:08:00 -0000 Message-ID: <87vcef257f.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2012-10/txt/msg00068.txt.bz2 Andrew Pinski writes: > On Thu, Oct 11, 2012 at 7:23 PM, chandan r wrote: >> >> Andrew Pinski writes: >> >>> On Tue, Oct 9, 2012 at 10:30 AM, chandan r wrote: >>>> Hi all, >>>> >>>> As the following CLI interactions show, GDB's python support code seems to be >>>> mishandling 64-bit pointers (GNU/Linux on x86-64): >>>> >>>> NOTE: "p" is a pointer of type "struct task_struct *" >>>> >>>> (gdb) python print gdb.parse_and_eval("p") >>>> 0xffff88001f5f7600 >>>> (gdb) python print long(gdb.parse_and_eval("p")) >>>> -131940868983296 >>>> (gdb) show version >>>> show version >>>> GNU gdb (GDB) 7.5 >>>> Copyright (C) 2012 Free Software Foundation, Inc. >>>> License GPLv3+: GNU GPL version 3 or later >>>> This is free software: you are free to change and redistribute it. >>>> There is NO WARRANTY, to the extent permitted by law. Type "show copying" >>>> and "show warranty" for details. >>>> This GDB was configured as "x86_64-unknown-linux-gnu". >>>> For bug reporting instructions, please see: >>>> . >>>> >>>> Is it GDB or am I messing up something here? >>> >>> Nothing looks wrong as -131940868983296 is the same as >>> 0xffff88001f5f7600 in signed integer. >>> (gdb) p/x -131940868983296 >>> $1 = 0xffff88001f5f7600 >>> >>> Thanks, >>> Andrew Pinski >>> >>>> >>>> -- >>>> Chandan >> >> But shouldn't pointer values be read/printed without interpretting the sign >> bit?. >> >> Right now I have to do 'long(str(gdb.parse_and_eval('p')), 16)' to obtain the >> correct value. > > > What is the correct value for pointers cast to an long? I don't see > the issue here as you have a pointer which is 64bits and you cast > directly to a signed long. > > Thanks, > Andrew Pinski > >> >> -- >> chandan I used long() based on the instructions given in http://dmalcolm.fedorapeople.org/presentations/PyCon-US-2011/GdbPythonPresentation/GdbPython.html#11 Any suggestions for the correct way to convert the pointer into a Python value?