From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1374 invoked by alias); 5 Feb 2018 04:07:02 -0000 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 Received: (qmail 1359 invoked by uid 89); 5 Feb 2018 04:07:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy=gmt08, GMT08, GMT-08, gmt-08 X-HELO: mail-wm0-f46.google.com Received: from mail-wm0-f46.google.com (HELO mail-wm0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Feb 2018 04:06:59 +0000 Received: by mail-wm0-f46.google.com with SMTP id g1so23389391wmg.2 for ; Sun, 04 Feb 2018 20:06:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=0m4r4/cifSZqjgMFpLjb3xr2fIjd03uMf7tIAUx3+Ok=; b=Qt1hsMisslFZqYQQ/xSQczBwfzwt5QgBS6HbV5zg1aEmlXKE13ilGQW8Z2AbizwYgn WhaIm+IVY6FvzOFDC+L0+3t6XE59xQTpXxyDKKWYgjqjuEwOdOoKTlIWqGm6PBsJUjPP vOO4UlflgkvuUrkOigro3cQXg2Maw3OHKuNsZyWKCAJJVR9XUJ2OQg/D+GgbMPtrLbx0 H7LlyPcRUFLYJQhoRhV5UwlYNIAYDQOOTLXd2KqEIP/fICSuEaFGQIwwirYwO3gX6tGr 51llNOp5fOyRVTFuQ3cFHIW4qOiGzJmAclhTB8cfxgepWCxoKGheeorNUVh7MsV87xGo 8jgQ== X-Gm-Message-State: AKwxytfF4f33JwJZ5wr3pUHgDzs1JE5HxLjJFYGG43wXBChbfbgWoX7/ D+ot8SPq52xLYbrEnMTOzeCxDRjlabsoPhf9do199g== X-Google-Smtp-Source: AH8x2257/mQl/Gn+eg12wwYwxPI4xA8LbBfXT52uZOD2mKefk7Awd8IL+0zhZYmGWJEkcQ+YcWnxRy3QBm7nc7xDJ18= X-Received: by 10.28.63.81 with SMTP id m78mr36281893wma.102.1517803617309; Sun, 04 Feb 2018 20:06:57 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.122.19 with HTTP; Sun, 4 Feb 2018 20:06:56 -0800 (PST) In-Reply-To: References: From: Roman Popov Date: Mon, 05 Feb 2018 04:07:00 -0000 Message-ID: Subject: Re: GDB returns wrong type when traversing optimized-out Fields To: gdb@sourceware.org Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg00020.txt.bz2 I apologize for code typo in previous email. Here is correct code sample: template struct TRAITS { static const unsigned val1 = v1; static const unsigned val2 = v2; }; template < class TRAITS > struct foo { static const unsigned x1 = TRAITS::val1; static const unsigned x2 = TRAITS::val2; }; int main () { foo> f1; // SET BREAKPOINT HERE return 0; } -Roman 2018-02-04 20:02 GMT-08:00 Roman Popov : > Hi all, > I've encountered strange GDB behavior when requesting a value of > optimized-away field. > Instead of returning None or raising exception, GDB returns an > optimizied-out value of wrong type. > > Here is a small reproducer *optimize_out.cpp*: > > template > struct TRAITS { > static const unsigned val1 = v1; > static const unsigned val2 = v2; > }; > template < class TRAITS > > struct foo { > static const unsigned x1 = TRAITS::v1; > static const unsigned x2 = TRAITS::v2; > }; > > int main () { > foo> f1; > // SET BREAKPOINT HERE > return 0; > } > > # Using g++ 7.3 > $ g++ -g optimize_out.cpp > > # Using gdb 8.1 > $ gdb a.out > > (gdb) break optimize_out.cpp:14 > (gdb) r > (gdb) p f1 > $1 = {static x1 = , static x2 = } > > Ok, looks good. Now traverse fields: > > (gdb) python > >f1 = gdb.parse_and_eval("f1") > >for field in f1.type.fields(): > > print ("field name: ", field.name, "field type: ", field.type) > > field_val = f1[field] > > print ("optout?: ",field_val.is_optimized_out, "type: > ",field_val.type) > >end > field name: x1 field type: const unsigned int > optout?: True type: foo > > field name: x2 field type: const unsigned int > optout?: True type: foo > > > > > So type we get is foo >, not unsigned int. > > Looks like GDB-MI has same behavior. At least this code sample totatlly > confuses GDB GUI I use. > > Thanks, > Roman >