From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32767 invoked by alias); 14 Oct 2010 06:41:07 -0000 Received: (qmail 32758 invoked by uid 22791); 14 Oct 2010 06:41:06 -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-wy0-f169.google.com (HELO mail-wy0-f169.google.com) (74.125.82.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Oct 2010 06:40:59 +0000 Received: by wyf28 with SMTP id 28so3499608wyf.0 for ; Wed, 13 Oct 2010 23:40:57 -0700 (PDT) Received: by 10.216.131.161 with SMTP id m33mr1787961wei.13.1287038457444; Wed, 13 Oct 2010 23:40:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.169.14 with HTTP; Wed, 13 Oct 2010 23:40:37 -0700 (PDT) From: Hui Zhu Date: Thu, 14 Oct 2010 06:41:00 -0000 Message-ID: Subject: [PATCH] tracepoint: fix tfile byte order issue To: gdb-patches ml Content-Type: text/plain; charset=ISO-8859-1 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/msg00238.txt.bz2 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 = 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 = 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. It will not affect current code. But can handle byte order issue. Thanks, Hui 2010-10-14 Hui Zhu * tracepoint.c (tfile_get_traceframe_address): Call extract_unsigned_integer. (tfile_trace_find): Ditto. (tfile_fetch_registers): Ditto. (tfile_xfer_partial): Ditto. (tfile_get_trace_state_variable_value): Ditto. --- tracepoint.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) --- 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 = (short) extract_unsigned_integer ((gdb_byte *)&tpnum, 2, + gdbarch_byte_order + (get_current_arch ())); tp = get_tracepoint_by_number_on_target (tpnum); /* FIXME this is a poor heuristic if multiple locations */ @@ -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 = (short) extract_unsigned_integer ((gdb_byte *)&tpnum, 2, + gdbarch_byte_order + (get_current_arch ())); offset += 2; if (tpnum == 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 = (int) extract_unsigned_integer ((gdb_byte *)&data_size, 4, + gdbarch_byte_order + (get_current_arch ())); offset += 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 = (unsigned short) + extract_unsigned_integer ((gdb_byte *)&mlen, 2, + gdbarch_byte_order + (get_current_arch ())); lseek (trace_fd, mlen, SEEK_CUR); pos += (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 = extract_unsigned_integer ((gdb_byte *)&maddr, 8, + gdbarch_byte_order + (get_current_arch ())); gotten = 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 = (unsigned short) + extract_unsigned_integer ((gdb_byte *)&mlen, 2, + gdbarch_byte_order + (get_current_arch ())); /* 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 = (unsigned short) + extract_unsigned_integer ((gdb_byte *)&mlen, 2, + gdbarch_byte_order + (get_current_arch ())); lseek (trace_fd, mlen, SEEK_CUR); pos += (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 = (int) extract_unsigned_integer ((gdb_byte *)&vnum, 4, + gdbarch_byte_order + (get_current_arch ())); if (tsvnum == vnum) { gotten = 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 = extract_unsigned_integer ((gdb_byte *)val, 8, + gdbarch_byte_order + (get_current_arch ())); return 1; } lseek (trace_fd, 8, SEEK_CUR);