public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] fix py-inferior.exp for remote cross-endian testing
@ 2010-10-29 19:20 Nathan Froyd
  2010-10-29 19:49 ` Doug Evans
  0 siblings, 1 reply; 5+ messages in thread
From: Nathan Froyd @ 2010-10-29 19:20 UTC (permalink / raw)
  To: gdb-patches

The patch below fixes a problem seen when doing remote testing on a
target that has a different endianness from the host.  Python's pack
function will pack according to host endianness, but the search_memory
function searches according to target endianness.  Searching for a value
from the former with the latter, then, does not work correctly.

The solution taken is to discover the target endianness early on using
'show endian' (the Python interface ought to have a method for this...)
and then use that knowledge to explicitly indicate what endianness
Python's pack function should use for multi-byte values.  Strictly
speaking, the change in the final hunk is unnecessary (endianness will
always match in native testing), but is done for completeness.

Tested with cross to powerpc-linux-gnu from i686-pc-linux-gnu.  OK to
commit?

-Nathan

	* gdb.python/py-inferior.exp: Pack values in target endianness.
---
 gdb/testsuite/gdb.python/py-inferior.exp |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index 45f43a1..7998b92 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -34,6 +34,17 @@ clean_restart ${testfile}
 # Skip all tests if Python scripting is not enabled.
 if { [skip_python_tests] } { continue }
 
+gdb_test_multiple "show endian" "getting target endian" {
+    -re ".*little endian.*$gdb_prompt $" {
+        set python_pack_char "<"
+	# pass silently
+    }
+    -re ".*big endian.*$gdb_prompt $" {
+        set python_pack_char ">"
+	# pass silently
+    }
+}
+
 # The following tests require execution.
 
 if ![runto_main] then {
@@ -106,7 +117,7 @@ gdb_test "set int16_search_buf\[10\] = 0x1234" "" ""
 gdb_test "py search_buf = gdb.selected_frame ().read_var ('int16_search_buf')" "" ""
 gdb_test "py start_addr = search_buf.address" "" ""
 gdb_test "py length = search_buf.type.sizeof" "" ""
-gdb_test "py pattern = pack('H',0x1234)" "" \
+gdb_test "py pattern = pack('${python_pack_char}H',0x1234)" "" \
 
 gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
   "${one_pattern_found}" "find 16-bit pattern, with value pattern"
@@ -117,7 +128,7 @@ gdb_test "set int32_search_buf\[10\] = 0x12345678" "" ""
 gdb_test "py search_buf = gdb.selected_frame ().read_var ('int32_search_buf')" "" ""
 gdb_test "py start_addr = search_buf.address" "" ""
 gdb_test "py length = search_buf.type.sizeof" "" ""
-gdb_test "py pattern = pack('I',0x12345678)" "" \
+gdb_test "py pattern = pack('${python_pack_char}I',0x12345678)" "" \
 
 gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
   "${one_pattern_found}" "find 32-bit pattern, with python pattern"
@@ -128,7 +139,7 @@ gdb_test "set int64_search_buf\[10\] = 0xfedcba9876543210LL" "" ""
 gdb_test "py search_buf = gdb.selected_frame ().read_var ('int64_search_buf')" "" ""
 gdb_test "py start_addr = search_buf.address" "" ""
 gdb_test "py length = search_buf.type.sizeof" "" ""
-gdb_test "py pattern = pack('Q', 0xfedcba9876543210)" "" ""
+gdb_test "py pattern = pack('${python_pack_char}Q', 0xfedcba9876543210)" "" ""
 
 gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
   "${one_pattern_found}" "find 64-bit pattern, with value pattern"
@@ -141,8 +152,8 @@ gdb_test "set *(int32_t*) &search_buf\[13\] = 0x64646464" "" ""
 gdb_test "py search_buf = gdb.selected_frame ().read_var ('search_buf')" "" ""
 gdb_test "py start_addr = search_buf\[0\].address" "" ""
 gdb_test "py pattern1 = pack('B', 0x62)" "" ""
-gdb_test "py pattern2 = pack('H', 0x6363)" "" ""
-gdb_test "py pattern3 = pack('I', 0x64646464)" "" ""
+gdb_test "py pattern2 = pack('${python_pack_char}H', 0x6363)" "" ""
+gdb_test "py pattern3 = pack('${python_pack_char}I', 0x64646464)" "" ""
 
 gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern1)" \
     "${one_pattern_found}" "find mixed-sized pattern"
@@ -161,7 +172,7 @@ gdb_test "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
 gdb_test "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
 gdb_test "py start_addr = gdb.selected_frame ().read_var ('search_buf')" "" ""
 gdb_test "py length = gdb.selected_frame ().read_var ('search_buf_size')" "" ""
-gdb_test "py pattern = pack('I', 0x12345678)" "" ""
+gdb_test "py pattern = pack('${python_pack_char}I', 0x12345678)" "" ""
 gdb_test "py first = gdb.inferiors()\[0\].search_memory (start_addr,length, pattern)" "" ""
 gdb_test "py print first" "${one_pattern_found}" "search spanning large range 1st result"
 gdb_test "py start_addr = first + 1"
@@ -175,7 +186,7 @@ gdb_test "py print third" "${pattern_not_found}" "search spanning large range 3r
 
 if [isnative] {
     gdb_test "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531" "" ""
-    gdb_test "py pattern = pack('I', 0xfdb97531)" "" ""
+    gdb_test "py pattern = pack('${python_pack_char}I', 0xfdb97531)" "" ""
     gdb_test "py start_addr = gdb.selected_frame ().read_var ('search_buf')" "" ""
     gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
       "${one_pattern_found}" "find pattern straddling chunk boundary"
-- 
1.6.3.2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix py-inferior.exp for remote cross-endian testing
  2010-10-29 19:20 [PATCH] fix py-inferior.exp for remote cross-endian testing Nathan Froyd
@ 2010-10-29 19:49 ` Doug Evans
  2010-10-29 20:16   ` Daniel Jacobowitz
  0 siblings, 1 reply; 5+ messages in thread
From: Doug Evans @ 2010-10-29 19:49 UTC (permalink / raw)
  To: Nathan Froyd; +Cc: gdb-patches

On Fri, Oct 29, 2010 at 7:20 PM, Nathan Froyd <froydnj@codesourcery.com> wrote:
> The patch below fixes a problem seen when doing remote testing on a
> target that has a different endianness from the host.  Python's pack
> function will pack according to host endianness, but the search_memory
> function searches according to target endianness.  Searching for a value
> from the former with the latter, then, does not work correctly.
>
> The solution taken is to discover the target endianness early on using
> 'show endian' (the Python interface ought to have a method for this...)
> and then use that knowledge to explicitly indicate what endianness
> Python's pack function should use for multi-byte values.  Strictly
> speaking, the change in the final hunk is unnecessary (endianness will
> always match in native testing), but is done for completeness.
>
> Tested with cross to powerpc-linux-gnu from i686-pc-linux-gnu.  OK to
> commit?
>
> -Nathan
>
>        * gdb.python/py-inferior.exp: Pack values in target endianness.

Hi.  This patch is ok with me.

[btw, one could get the value of endianness from python with
gdb.parameter("endian").
Or at least should.  On my machine it returns "".
We probably want to fix that.  Your patch is fine with me as is though.]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix py-inferior.exp for remote cross-endian testing
  2010-10-29 19:49 ` Doug Evans
@ 2010-10-29 20:16   ` Daniel Jacobowitz
  2010-11-01 20:13     ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jacobowitz @ 2010-10-29 20:16 UTC (permalink / raw)
  To: Doug Evans; +Cc: Nathan Froyd, gdb-patches

On Fri, Oct 29, 2010 at 07:49:44PM +0000, Doug Evans wrote:
> Hi.  This patch is ok with me.
> 
> [btw, one could get the value of endianness from python with
> gdb.parameter("endian").
> Or at least should.  On my machine it returns "".
> We probably want to fix that.  Your patch is fine with me as is though.]

(gdb) py print gdb.parameter("endian")

(gdb) set endian big
The target is assumed to be big endian
(gdb) py print gdb.parameter("endian")
big
(gdb) set endian little
The target is assumed to be little endian
(gdb) py print gdb.parameter("endian")
little
(gdb) set endian auto
The target endianness is set automatically (currently little endian)
(gdb) py print gdb.parameter("endian")
auto
(gdb) show endian
The target endianness is set automatically (currently little endian)

So that's at least one obvious bug ("" vs "auto"), and one more
complex bug (what should it return for auto?).  I'm inclined to say
that it should return auto, and there should be some other way to find
out "auto what?"; OTOH, it's a general problem with parameters...

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix py-inferior.exp for remote cross-endian testing
  2010-10-29 20:16   ` Daniel Jacobowitz
@ 2010-11-01 20:13     ` Tom Tromey
  2010-11-03 17:24       ` Doug Evans
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2010-11-01 20:13 UTC (permalink / raw)
  To: Doug Evans; +Cc: Nathan Froyd, gdb-patches

>>>>> "Daniel" == Daniel Jacobowitz <dan@codesourcery.com> writes:

Daniel> So that's at least one obvious bug ("" vs "auto"), and one more
Daniel> complex bug (what should it return for auto?).  I'm inclined to say
Daniel> that it should return auto, and there should be some other way to find
Daniel> out "auto what?"; OTOH, it's a general problem with parameters...

Could you file a bug report for this?

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix py-inferior.exp for remote cross-endian testing
  2010-11-01 20:13     ` Tom Tromey
@ 2010-11-03 17:24       ` Doug Evans
  0 siblings, 0 replies; 5+ messages in thread
From: Doug Evans @ 2010-11-03 17:24 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Nathan Froyd, gdb-patches

On Mon, Nov 1, 2010 at 1:17 PM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Daniel" == Daniel Jacobowitz <dan@codesourcery.com> writes:
>
> Daniel> So that's at least one obvious bug ("" vs "auto"), and one more
> Daniel> complex bug (what should it return for auto?).  I'm inclined to say
> Daniel> that it should return auto, and there should be some other way to find
> Daniel> out "auto what?"; OTOH, it's a general problem with parameters...
>
> Could you file a bug report for this?

http://sourceware.org/bugzilla/show_bug.cgi?id=12188

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-11-03 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-29 19:20 [PATCH] fix py-inferior.exp for remote cross-endian testing Nathan Froyd
2010-10-29 19:49 ` Doug Evans
2010-10-29 20:16   ` Daniel Jacobowitz
2010-11-01 20:13     ` Tom Tromey
2010-11-03 17:24       ` Doug Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).