From: Pedro Alves <palves@redhat.com>
To: Yao Qi <yao@codesourcery.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Compute the function length instead of hard coding it
Date: Thu, 24 Apr 2014 14:04:00 -0000 [thread overview]
Message-ID: <535919EB.3050409@redhat.com> (raw)
In-Reply-To: <1398343381-24249-1-git-send-email-yao@codesourcery.com>
(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 <main+72>: retq
0x45d855: nopl (%rax)
> +
> +set test "disassemble main+$main_length,+10"
> +gdb_test_multiple $test $test {
> + -re ".*($hex) <main\\+$main_length>:\[^\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
next prev parent reply other threads:[~2014-04-24 14:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-24 12:46 Yao Qi
2014-04-24 14:04 ` Pedro Alves [this message]
2014-04-25 1:36 ` Yao Qi
2014-04-25 10:37 ` Pedro Alves
2014-04-26 2:50 ` Yao Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=535919EB.3050409@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=yao@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox