From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7432 invoked by alias); 19 Oct 2010 08:48:57 -0000 Received: (qmail 7420 invoked by uid 22791); 19 Oct 2010 08:48:55 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,TW_CP,TW_VN X-Spam-Check-By: sourceware.org Received: from mail-qw0-f41.google.com (HELO mail-qw0-f41.google.com) (209.85.216.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Oct 2010 08:48:50 +0000 Received: by qwd6 with SMTP id 6so83450qwd.0 for ; Tue, 19 Oct 2010 01:48:48 -0700 (PDT) Received: by 10.224.198.9 with SMTP id em9mr2419790qab.222.1287478128465; Tue, 19 Oct 2010 01:48:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.37.149 with HTTP; Tue, 19 Oct 2010 01:48:28 -0700 (PDT) In-Reply-To: References: From: Hui Zhu Date: Tue, 19 Oct 2010 08:48:00 -0000 Message-ID: Subject: [PATCH] tracepoint: fix tfile byte order issue To: gdb-patches ml 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/msg00290.txt.bz2 Ping ---------- Forwarded message ---------- From: Hui Zhu Date: Thu, Oct 14, 2010 at 14:40 Subject: [PATCH] tracepoint: fix tfile byte order issue To: gdb-patches ml Hi, I found that the "target tfile" doesn't handle the issue that byte order of target part is different with host part. For example: In target part: In gdbserver/tracepoint.c:add_traceframe tframe->tpnum =3D tpoint->number; It set this number directly. In gdbserver/tracepoint.c:agent_mem_read memcpy (mspace, &from, sizeof (from)); The address is set to memory directly. In host part: In ttacepoint.c:tfile_trace_find gotten =3D read (trace_fd, &tpnum, 2); After read, it is used directly. If the byte order of target and host is same, everything is OK. But if the target and host is not same, it will get error. So I make a patch to let host part use extract_unsigned_integer covert the number. =A0It will not affect current code. =A0But can handle byte order issue. Thanks, Hui 2010-10-14 =A0Hui Zhu =A0 =A0 =A0 =A0 =A0* tracepoint.c (tfile_get_traceframe_address): Call =A0 =A0 =A0 =A0extract_unsigned_integer. =A0 =A0 =A0 =A0(tfile_trace_find): Ditto. =A0 =A0 =A0 =A0(tfile_fetch_registers): Ditto. =A0 =A0 =A0 =A0(tfile_xfer_partial): Ditto. =A0 =A0 =A0 =A0(tfile_get_trace_state_variable_value): Ditto. --- =A0tracepoint.c | =A0 31 ++++++++++++++++++++++++++++++- =A01 file changed, 30 insertions(+), 1 deletion(-) --- a/tracepoint.c +++ b/tracepoint.c @@ -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 *)&tpnum= , 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 ())); =A0 =A0 =A0 offset +=3D 2; =A0 =A0 =A0 if (tpnum =3D=3D 0) =A0 =A0 =A0 =A0break; @@ -3711,6 +3717,9 @@ tfile_trace_find (enum trace_find_type t =A0 =A0 =A0 =A0perror_with_name (trace_filename); =A0 =A0 =A0 else if (gotten < 4) =A0 =A0 =A0 =A0error (_("Premature end of file while reading trace file")); + =A0 =A0 =A0data_size =3D (int) extract_unsigned_integer ((gdb_byte *)&dat= a_size, 4, + =A0 =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 =A0 (get_current_arch ())); =A0 =A0 =A0 offset +=3D 4; =A0 =A0 =A0 switch (type) =A0 =A0 =A0 =A0{ @@ -3832,6 +3841,10 @@ tfile_fetch_registers (struct target_ops =A0 =A0 =A0 =A0 =A0 =A0perror_with_name (trace_filename); =A0 =A0 =A0 =A0 =A0else if (gotten < 2) =A0 =A0 =A0 =A0 =A0 =A0error (_("Premature end of file while reading trace = file")); + =A0 =A0 =A0 =A0 =A0mlen =3D (unsigned short) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0extract_unsigned_integer ((gdb_byte *)&mle= n, 2, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0gdbarch_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 =A0 =A0 =A0 =A0lseek (trace_fd, mlen, SEEK_CUR); =A0 =A0 =A0 =A0 =A0pos +=3D (8 + 2 + mlen); =A0 =A0 =A0 =A0 =A0break; @@ -3924,12 +3937,18 @@ tfile_xfer_partial (struct target_ops *o =A0 =A0 =A0 =A0 =A0 =A0perror_with_name (trace_filename); =A0 =A0 =A0 =A0 =A0else if (gotten < 8) =A0 =A0 =A0 =A0 =A0 =A0error (_("Premature end of file while reading trace = file")); - + =A0 =A0 =A0 =A0 =A0maddr =3D extract_unsigned_integer ((gdb_byte *)&maddr= , 8, + =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 =A0 =A0 =A0 =A0gotten =3D read (trace_fd, &mlen, 2); =A0 =A0 =A0 =A0 =A0if (gotten < 0) =A0 =A0 =A0 =A0 =A0 =A0perror_with_name (trace_filename); =A0 =A0 =A0 =A0 =A0else if (gotten < 2) =A0 =A0 =A0 =A0 =A0 =A0error (_("Premature end of file while reading trace = file")); + =A0 =A0 =A0 =A0 =A0mlen =3D (unsigned short) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0extract_unsigned_integer ((gdb_byte *)&mle= n, 2, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0gdbarch_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 =A0 =A0 =A0 =A0/* If the block includes the first part of the desired =A0 =A0 =A0 =A0 =A0 =A0 range, return as much it has; GDB will re-request t= he =A0 =A0 =A0 =A0 =A0 =A0 remainder, which might be in a different block of t= his @@ -4032,6 +4051,10 @@ tfile_get_trace_state_variable_value (in =A0 =A0 =A0 =A0 =A0 =A0perror_with_name (trace_filename); =A0 =A0 =A0 =A0 =A0else if (gotten < 2) =A0 =A0 =A0 =A0 =A0 =A0error (_("Premature end of file while reading trace = file")); + =A0 =A0 =A0 =A0 =A0mlen =3D (unsigned short) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0extract_unsigned_integer ((gdb_byte *)&mle= n, 2, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0gdbarch_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 =A0 =A0 =A0 =A0lseek (trace_fd, mlen, SEEK_CUR); =A0 =A0 =A0 =A0 =A0pos +=3D (8 + 2 + mlen); =A0 =A0 =A0 =A0 =A0break; @@ -4041,6 +4064,9 @@ tfile_get_trace_state_variable_value (in =A0 =A0 =A0 =A0 =A0 =A0perror_with_name (trace_filename); =A0 =A0 =A0 =A0 =A0else if (gotten < 4) =A0 =A0 =A0 =A0 =A0 =A0error (_("Premature end of file while reading trace = file")); + =A0 =A0 =A0 =A0 =A0vnum =3D (int) extract_unsigned_integer ((gdb_byte *)&= vnum, 4, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0gdbarch_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 =A0(get_current_arch ())); =A0 =A0 =A0 =A0 =A0if (tsvnum =3D=3D vnum) =A0 =A0 =A0 =A0 =A0 =A0{ =A0 =A0 =A0 =A0 =A0 =A0 =A0gotten =3D read (trace_fd, val, 8); @@ -4048,6 +4074,9 @@ tfile_get_trace_state_variable_value (in =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0perror_with_name (trace_filename); =A0 =A0 =A0 =A0 =A0 =A0 =A0else if (gotten < 8) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0error (_("Premature end of file while readin= g trace file")); + =A0 =A0 =A0 =A0 =A0 =A0 =A0*val =3D extract_unsigned_integer ((gdb_byte *= )val, 8, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0gdbarch_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 ())); =A0 =A0 =A0 =A0 =A0 =A0 =A0return 1; =A0 =A0 =A0 =A0 =A0 =A0} =A0 =A0 =A0 =A0 =A0lseek (trace_fd, 8, SEEK_CUR);