From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22070 invoked by alias); 23 May 2012 16:10:36 -0000 Received: (qmail 22009 invoked by uid 22791); 23 May 2012 16:10:34 -0000 X-SWARE-Spam-Status: No, hits=-7.4 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,TW_XF,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 23 May 2012 16:10:19 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4NGA6M0019844 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 23 May 2012 12:10:06 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q4NGA40a019804; Wed, 23 May 2012 12:10:05 -0400 Message-ID: <4FBD0BDC.4070007@redhat.com> Date: Wed, 23 May 2012 16:10:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: Jerome Guitton CC: Doug Evans , gdb-patches@sourceware.org Subject: Re: [RFC] setting the raw content of a register References: <1337697398-25866-1-git-send-email-guitton@adacore.com> <4FBBA8C8.4030909@redhat.com> <20120522152459.GQ51051@adacore.com> <4FBBBF75.4040605@redhat.com> <20120523154226.GT51051@adacore.com> <4FBD0A28.9090503@redhat.com> In-Reply-To: <4FBD0A28.9090503@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit 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 X-SW-Source: 2012-05/txt/msg00901.txt.bz2 On 05/23/2012 05:02 PM, Pedro Alves wrote: > On 05/23/2012 04:42 PM, Jerome Guitton wrote: > >> I can have a look. >> >> Still, we will have the problem that I was mentioning for cross >> targets: we sometimes lose the sign of the NaN. e.g. when debugging a >> ppc-elf target from a x86-linux host, {double} {0xFFF0000000000050} >> probably evaluates to NaN(0x100000001) instead of >> -NaN(0x000000050). Same kind of issue for denorms. We may improve the >> precision of the evaluation here, but I fear that it will take some >> time to catch all the possible cases. A new command would give a work >> around to anyone hitting such a precision loss. > > > The idea was for that expression to result in no evaluation, but on a > reinterpret cast. We can create GDB side arrays without involving the > inferior, like so: > > (gdb) p {1} > $1 = {1} > (gdb) p sizeof {1} > $2 = 4 > > or: > > (gdb) p/c (char[1]) {1} > $3 = {1 '\001'} > > But we can't reinterpret / cast a byte array to anything else: > > (gdb) p (char) $3 > evaluation of this expression requires the target program to be active > (gdb) p (int) $1 > evaluation of this expression requires the target program to be active > > This is because we try to follow C's semantics, and try to decay the array > to a pointer. And a pointer implies an address on the inferior, which implies > copying the array into the inferior, which requires malloc'ing a block of > memory in the inferior. > > Sounds like we're missing a "reinterpret cast" operator, or steal some > invalid C cast syntax for the effect. > > For non-scalars, we could just steal the regular cast: > > struct foo > { > char c; > }; > > (gdb) p (struct foo) (char[1]) {1} > > as that is not a valid C cast ("error: conversion to non-scalar type requested" in gcc). > > In fact, I think that'd be already quite useful. > > But what to do with casts to scalars? > Actually, casting arrays to floats appears to also be invalid. I didn't check any standard, but gcc gives: struct foo { char c; }; char array[] = { 0xff }; int main () { float f = (float) array; } $ gcc array.c -o array array.c: In function ‘main’: array.c:6:3: error: pointer value used where a floating point value was expected Still leaves scalars out though. But I'm beginning to think I misunderstood where the precision is being lost. -- Pedro Alves