From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23497 invoked by alias); 20 Oct 2010 08:50:34 -0000 Received: (qmail 23477 invoked by uid 22791); 20 Oct 2010 08:50:30 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,TW_VN X-Spam-Check-By: sourceware.org Received: from mail-wy0-f169.google.com (HELO mail-wy0-f169.google.com) (74.125.82.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 Oct 2010 08:50:21 +0000 Received: by wyf28 with SMTP id 28so3683066wyf.0 for ; Wed, 20 Oct 2010 01:50:19 -0700 (PDT) Received: by 10.216.175.83 with SMTP id y61mr1931251wel.30.1287564618587; Wed, 20 Oct 2010 01:50:18 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.179.14 with HTTP; Wed, 20 Oct 2010 01:49:58 -0700 (PDT) In-Reply-To: <201010191020.04495.pedro@codesourcery.com> References: <201010191020.04495.pedro@codesourcery.com> From: Hui Zhu Date: Wed, 20 Oct 2010 08:50:00 -0000 Message-ID: Subject: Re: [PATCH] tracepoint: fix tfile byte order issue To: Pedro Alves Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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 X-SW-Source: 2010-10/txt/msg00313.txt.bz2 On Tue, Oct 19, 2010 at 17:20, Pedro Alves wrote: > On Tuesday 19 October 2010 09:48:28, Hui Zhu wrote: > >> @@ -3665,6 +3665,9 @@ tfile_get_traceframe_address (off_t tfra >> =A0 =A0 perror_with_name (trace_filename); >> =A0 else if (gotten < 2) >> =A0 =A0 error (_("Premature end of file while reading trace file")); >> + =A0tpnum =3D (short) extract_unsigned_integer ((gdb_byte *)&tpnum, 2, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 gdbarch_byte_order >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 (get_current_arch ())); >> >> =A0 tp =3D get_tracepoint_by_number_on_target (tpnum); >> =A0 /* FIXME this is a poor heuristic if multiple locations */ >> @@ -3703,6 +3706,9 @@ tfile_trace_find (enum trace_find_type t >> =A0 =A0 =A0 =A0perror_with_name (trace_filename); >> =A0 =A0 =A0 else if (gotten < 2) >> =A0 =A0 =A0 =A0error (_("Premature end of file while reading trace file"= )); >> + =A0 =A0 =A0tpnum =3D (short) extract_unsigned_integer ((gdb_byte *)&tp= num, 2, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 gdbarch_byte_order >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (get_current_arch ())); > > "The data in this section is raw binary, not a > hexadecimal or other encoding; its endianness matches the target's > endianness." > > Please use target_gdbarch instead. > > And use extract_signed_integer thus avoiding the casts. > > -- > Pedro Alves > Thanks Pedro. I make a new patch change to use target_gdbarch and use extract_signed_integer in signed value. And I found that tfile_trace_find define the size of a frame to a int: int data_size; But I found that gdbserver/tracepoint.c:struct traceframe: unsigned int data_size : 32; So I change this int to unsigned int. Please help me review the new one. Best, Hui 2010-10-20 Hui Zhu * tracepoint.c (tfile_get_traceframe_address): Call extract_signed_integer. (tfile_trace_find): Call extract_signed_integer and extract_unsigned_integer. Change data_size to unsigned int. (tfile_fetch_registers): Call extract_unsigned_integer. (tfile_xfer_partial): Ditto. (tfile_get_trace_state_variable_value): Call extract_signed_integer and extract_unsigned_integer. --- tracepoint.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) --- a/tracepoint.c +++ b/tracepoint.c @@ -3665,6 +3665,9 @@ tfile_get_traceframe_address (off_t tfra perror_with_name (trace_filename); else if (gotten < 2) error (_("Premature end of file while reading trace file")); + tpnum =3D (short) extract_signed_integer ((gdb_byte *)&tpnum, 2, + gdbarch_byte_order + (target_gdbarch)); tp =3D get_tracepoint_by_number_on_target (tpnum); /* FIXME this is a poor heuristic if multiple locations */ @@ -3688,7 +3691,7 @@ tfile_trace_find (enum trace_find_type t { short tpnum; int tfnum =3D 0, found =3D 0, gotten; - int data_size; + unsigned int data_size; struct breakpoint *tp; off_t offset, tframe_offset; ULONGEST tfaddr; @@ -3703,6 +3706,9 @@ tfile_trace_find (enum trace_find_type t perror_with_name (trace_filename); else if (gotten < 2) error (_("Premature end of file while reading trace file")); + tpnum =3D (short) extract_signed_integer ((gdb_byte *)&tpnum, 2, + gdbarch_byte_order + (target_gdbarch)); offset +=3D 2; if (tpnum =3D=3D 0) break; @@ -3711,6 +3717,9 @@ tfile_trace_find (enum trace_find_type t perror_with_name (trace_filename); else if (gotten < 4) error (_("Premature end of file while reading trace file")); + data_size =3D (unsigned int) extract_unsigned_integer + ((gdb_byte *)&data_size, 4, + gdbarch_byte_order (target_gdbarch)); offset +=3D 4; switch (type) { @@ -3832,6 +3841,10 @@ tfile_fetch_registers (struct target_ops perror_with_name (trace_filename); else if (gotten < 2) error (_("Premature end of file while reading trace file")); + mlen =3D (unsigned short) + extract_unsigned_integer ((gdb_byte *)&mlen, 2, + gdbarch_byte_order + (target_gdbarch)); lseek (trace_fd, mlen, SEEK_CUR); pos +=3D (8 + 2 + mlen); break; @@ -3924,12 +3937,18 @@ tfile_xfer_partial (struct target_ops *o perror_with_name (trace_filename); else if (gotten < 8) error (_("Premature end of file while reading trace file")); - + maddr =3D extract_unsigned_integer ((gdb_byte *)&maddr, 8, + gdbarch_byte_order + (target_gdbarch)); gotten =3D read (trace_fd, &mlen, 2); if (gotten < 0) perror_with_name (trace_filename); else if (gotten < 2) error (_("Premature end of file while reading trace file")); + mlen =3D (unsigned short) + extract_unsigned_integer ((gdb_byte *)&mlen, 2, + gdbarch_byte_order + (target_gdbarch)); /* If the block includes the first part of the desired range, return as much it has; GDB will re-request the remainder, which might be in a different block of this @@ -4032,6 +4051,10 @@ tfile_get_trace_state_variable_value (in perror_with_name (trace_filename); else if (gotten < 2) error (_("Premature end of file while reading trace file")); + mlen =3D (unsigned short) + extract_unsigned_integer ((gdb_byte *)&mlen, 2, + gdbarch_byte_order + (target_gdbarch)); lseek (trace_fd, mlen, SEEK_CUR); pos +=3D (8 + 2 + mlen); break; @@ -4041,6 +4064,9 @@ tfile_get_trace_state_variable_value (in perror_with_name (trace_filename); else if (gotten < 4) error (_("Premature end of file while reading trace file")); + vnum =3D (int) extract_signed_integer ((gdb_byte *)&vnum, 4, + gdbarch_byte_order + (target_gdbarch)); if (tsvnum =3D=3D vnum) { gotten =3D read (trace_fd, val, 8); @@ -4048,6 +4074,9 @@ tfile_get_trace_state_variable_value (in perror_with_name (trace_filename); else if (gotten < 8) error (_("Premature end of file while reading trace file")); + *val =3D extract_signed_integer ((gdb_byte *)val, 8, + gdbarch_byte_order + (target_gdbarch)); return 1; } lseek (trace_fd, 8, SEEK_CUR);