From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2883 invoked by alias); 24 Apr 2014 14:04:34 -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 2872 invoked by uid 89); 24 Apr 2014 14:04:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 24 Apr 2014 14:04:33 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3OE4TQ3031719 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Apr 2014 10:04:30 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3OE4Ss0003188; Thu, 24 Apr 2014 10:04:28 -0400 Message-ID: <535919EB.3050409@redhat.com> Date: Thu, 24 Apr 2014 14:04:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: Yao Qi CC: gdb-patches@sourceware.org Subject: Re: [PATCH] Compute the function length instead of hard coding it References: <1398343381-24249-1-git-send-email-yao@codesourcery.com> In-Reply-To: <1398343381-24249-1-git-send-email-yao@codesourcery.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-SW-Source: 2014-04/txt/msg00498.txt.bz2 (Is there really no way to query GDB for the function's size directly? Seems like something that "info symbol main" should be spit out.) On 04/24/2014 01:43 PM, Yao Qi wrote: > +set main_length "" > +set test "disassemble main" > +gdb_test_multiple $test $test { > + -re ".*$hex <\\+($decimal)>:\[^\r\n\]+\r\nEnd of assembler dump\.\r\n$gdb_prompt $" { > + set main_length $expect_out(1,string) > + pass $test > + } > + -re ".*$gdb_prompt $" { > + fail $test > + # Bail out here, because we can't do the following tests if > + # $main_length is unknown. > + return -1 > + } Instead of this -re, best do if { $main_length == "" } { return -1 } after gdb_test_multiple, as $main_length is unknown on e.g., internal error or timeout too. > +} > +# Calculate the size of the last instruction. Single instruction > +# shouldn't be longer than 10 bytes. x86 has instructions longer than that, though it's not likely we'll see them as last instruction. You want to disassemble two instructions. So instead of having to hard code some number and having to explain it in a comment, how about just asking GDB what we want, with x/i ? That is: (gdb) x /2i main+72 0x45d854 : retq 0x45d855: nopl (%rax) > + > +set test "disassemble main+$main_length,+10" > +gdb_test_multiple $test $test { > + -re ".*($hex) :\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" { > + set start $expect_out(1,string) > + set end $expect_out(2,string) > + > + set main_length [expr $main_length + $end - $start] > + pass $test > + } > + -re ".*$gdb_prompt $" { > + fail $test > + # Bail out here, because we can't do the following tests if > + # $main_length is unknown. > + return -1 Same comment here as above. -- Pedro Alves