From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24221 invoked by alias); 25 Aug 2017 21:05:10 -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 23703 invoked by uid 89); 25 Aug 2017 21:05:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 Aug 2017 21:05:07 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id v7PL4rQ5003049 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 25 Aug 2017 17:05:00 -0400 Received: by simark.ca (Postfix, from userid 112) id 43D1F1EA22; Fri, 25 Aug 2017 17:04:53 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 9CA011E5E1; Fri, 25 Aug 2017 17:04:37 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 25 Aug 2017 21:05:00 -0000 From: Simon Marchi To: Yao Qi Cc: Pedro Alves , Lionel Flandrin , Simon Marchi , gdb-patches@sourceware.org Subject: Re: Check for truncated registers in process_g_packet In-Reply-To: References: <20161018111023.4hzeyfzzpaneyfds@localhost.localdomain> <33a1f569-995b-342a-dbb9-ea14ab377d1a@ericsson.com> <20161018160657.rdvxgcam3uibsgst@localhost.localdomain> <6f2568ee-7677-63e8-2d51-65ac531b3a84@redhat.com> Message-ID: <99a028d3486fedc258429c8c22e4777c@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 25 Aug 2017 21:04:54 +0000 X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00492.txt.bz2 On 2017-08-25 12:53, Yao Qi wrote: > This patch 9dc193c causes a regression, > > $ make check RUNTESTFLAGS="--target_board=native-extended-gdbserver > multi-arch-exec.exp" > FAIL: gdb.multi/multi-arch-exec.exp: continue across exec that changes > architecture > > This test passes on the previous commit. The test > passes also if I revert this commit on mainline. From what I can see, the line that causes the problem is stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); at infrun.c:5321. At this point, the process we are debugging has exec'ed. It used to be a 64-bits process, it is now a 32-bits process. However, current_inferior_->gdbarch still points to the 64-bits gdbarch. It's only the follow_exec call a few lines below that will update it to the new gdbarch. By reading the PC, we send a g packet. The response contains the registers of a 32-bits process, but we interpret them as those of a 64-bits process (because get_remote_arch_state uses current_inferior_->gdbarch). If I move the line mentioned above just after the follow_exec call, gdb interprets the g reply with the right/new gdbarch, so the test case works. I don't know if it breaks anything else, but so far I didn't find anything before that point that relied on stop_pc. I sent that change to the buildbot to check. So from what I understand, it looks like a pre-existing bug that this patch uncovered. I think we were interpreting the g reply containing 32-bits registers using the 64-bits register map all along, which that stop_pc had a bogus value. To confirm this, I checked out the commit just prior this patch. I see stop_pc having a value of 0 (it could be anything I guess). If I move the assignment of stop_pc just after follow_exec, I see a value of 0xf7fd9a20. That value is the mapping address of the dynamic loader in the process: f7fd9000-f7ffb000 r-xp 00000000 fc:01 395792 /lib/i386-linux-gnu/ld-2.23.so plus the entry point in it: Entry point address: 0xa20 so it makes sense that the process is stopped at this address. Simon