From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18014 invoked by alias); 8 Jul 2007 01:22:15 -0000 Received: (qmail 18006 invoked by uid 22791); 8 Jul 2007 01:22:15 -0000 X-Spam-Check-By: sourceware.org Received: from ug-out-1314.google.com (HELO ug-out-1314.google.com) (66.249.92.172) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 08 Jul 2007 01:22:13 +0000 Received: by ug-out-1314.google.com with SMTP id s2so1039868uge for ; Sat, 07 Jul 2007 18:22:12 -0700 (PDT) Received: by 10.66.255.7 with SMTP id c7mr3911200ugi.1183857732779; Sat, 07 Jul 2007 18:22:12 -0700 (PDT) Received: from ?62.169.106.235? ( [62.169.106.235]) by mx.google.com with ESMTP id i4sm19507377nfh.2007.07.07.18.22.09 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 07 Jul 2007 18:22:12 -0700 (PDT) Message-ID: <46903BF1.6020901@portugalmail.pt> Date: Sun, 08 Jul 2007 01:22:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-BR; rv:1.8.0.12) Gecko/20070509 Thunderbird/1.5.0.12 Mnenhy/0.7.4.0 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Building solib-target.c when CORE_ADDR != ULONGEST. Content-Type: multipart/mixed; boundary="------------020907070905000602020108" 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: 2007-07/txt/msg00132.txt.bz2 This is a multi-part message in MIME format. --------------020907070905000602020108 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 772 Hi, Building solib-target.c on host where CORE_ADDR != ULONGEST is broken, because of this: static void library_list_start_segment (struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, VEC(gdb_xml_value_s) *attributes) { VEC(lm_info_p) **list = user_data; struct lm_info *last = VEC_last (lm_info_p, *list); ULONGEST *address_p = VEC_index (gdb_xml_value_s, attributes, 0)->value; VEC_safe_push (CORE_ADDR, last->segment_bases, address_p); } Pushing a ULONGEST* into a CORE_ADDR VEC doesn't work. I'm using the attached patch to try to catch invalid data send by a (remote) target, but I guess it isn't correct for all archs. I was building arm-wince-mingw32ce on i686-pc-cygwin. Cheers, Pedro Alves --------------020907070905000602020108 Content-Type: text/x-diff; name="solib-target_CORE_ADDR.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="solib-target_CORE_ADDR.diff" Content-length: 1952 2007-07-08 Pedro Alves * solib-target.c (core_addr_from_ulongest): New. (library_list_start_segment): Use core_addr_from_ulongest. --- gdb/solib-target.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) Index: src/gdb/solib-target.c =================================================================== --- src.orig/gdb/solib-target.c 2007-07-04 01:19:56.000000000 +0100 +++ src/gdb/solib-target.c 2007-07-07 16:32:44.000000000 +0100 @@ -72,6 +72,43 @@ solib_target_parse_libraries (const char #include "xml-support.h" +static int +core_addr_from_ulongest (CORE_ADDR* to, const ULONGEST* from) +{ + int erange = 0; + + if (sizeof (*to) == 4 && sizeof (*from) == 8) + { + unsigned int high_part; + unsigned int low_part; + CORE_ADDR neg_one = ~ (CORE_ADDR) 0; + + high_part = *from >> 32; + low_part = *from & 0xffffffff; + + if (neg_one < 1) + { + /* CORE_ADDR is signed. */ + if (high_part != 0xffffffff && high_part != 0) + erange = 1; + else if (high_part == 0xffffffff && low_part < 0x80000000) + erange = 1; + } + else if (high_part != 0) + erange = 1; + } + + *to = (CORE_ADDR) *from; + + if (erange) + { + errno = ERANGE; + return -1; + } + + return 0; +} + /* Handle the start of a element. */ static void @@ -82,8 +119,12 @@ library_list_start_segment (struct gdb_x VEC(lm_info_p) **list = user_data; struct lm_info *last = VEC_last (lm_info_p, *list); ULONGEST *address_p = VEC_index (gdb_xml_value_s, attributes, 0)->value; + CORE_ADDR address; + + if (core_addr_from_ulongest (&address, address_p) < 0) + warning (_("Target reported an out-of-range address.")); - VEC_safe_push (CORE_ADDR, last->segment_bases, address_p); + VEC_safe_push (CORE_ADDR, last->segment_bases, &address); } /* Handle the start of a element. */ --------------020907070905000602020108--