From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25626 invoked by alias); 9 Apr 2013 16:03:03 -0000 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 Received: (qmail 25616 invoked by uid 89); 9 Apr 2013 16:03:03 -0000 X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,TW_CP,TW_XS autolearn=ham version=3.3.1 Received: from gbenson.demon.co.uk (HELO blade.wire.rat) (80.177.220.214) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 09 Apr 2013 16:03:01 +0000 Received: by blade.wire.rat (Postfix, from userid 500) id 41E98263F7F; Tue, 9 Apr 2013 17:02:58 +0100 (BST) Date: Tue, 09 Apr 2013 19:26:00 -0000 From: Gary Benson To: Aleksandar Ristovski Cc: Jan Kratochvil , "gdb-patches@sourceware.org" Subject: Re: [patch 6/6] gdbserver build-id attribute generator Message-ID: <20130409160258.GE5005@blade.wire.rat> Mail-Followup-To: Aleksandar Ristovski , Jan Kratochvil , "gdb-patches@sourceware.org" References: <51530465.30503@qnx.com> <20130327145028.GA17905@host2.jankratochvil.net> <515353CF.40601@qnx.com> <5154ADD2.9040206@qnx.com> <20130331174322.GB21374@host2.jankratochvil.net> <515B05D8.1000003@qnx.com> <20130403193258.GA9853@host2.jankratochvil.net> <515ECB30.5010504@qnx.com> <20130409112930.GA5005@blade.wire.rat> <51640D8D.80306@qnx.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="gKMricLos+KVdGMg" Content-Disposition: inline In-Reply-To: <51640D8D.80306@qnx.com> X-Virus-Found: No X-SW-Source: 2013-04/txt/msg00243.txt.bz2 --gKMricLos+KVdGMg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1523 Aleksandar Ristovski wrote: > On 13-04-09 07:29 AM, Gary Benson wrote: > > Aleksandar Ristovski wrote: > > > (linux_qxfer_libraries_svr4): Add optional build-id attribute > > > to reply XML document. > > > > For the record this is the only part of your patchset that clashes > > with the gdbserver work I'm doing. It's not an *awful* clash, but > > it will require a manual merge. I'm happy to do that if necessary. > > Thank you for your update. I'm sorry for the clash. If there is > something obvious I can do in this patch to reduce the clash let me > know. There's nothing obvious, and you don't need to apologise. We just both happen to be working in the same area at the same time. > BTW, I am not familiar with your patch, if you want you can give me > an overview here or offline. The gdbserver side of it is that GDB can pass arguments in the annex of qXfer:libraries-svr4:read+ to instruct the remote to transfer the list starting from a specific link map rather than sending the whole list. I've attached my work-in-progress patch for the gdbserver side, but you can see the full thing in the gbenson/rtld-probes branch in archer git if you like. A lot of the code is actually the same, but somewhat reordered and with indentation changes which makes the patch harder to read. Your work seems closer to being accepted than mine, so I imagine what will happen is that you'll commit your patches and I'll rebase mine on top of that. I have no problem with that. Cheers, Gary -- http://gbenson.net/ --gKMricLos+KVdGMg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdbserver-changes.patch" Content-length: 8812 diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 72c51e0..beb3b8f 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -5677,6 +5677,12 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf, }; const struct link_map_offsets *lmo; unsigned int machine; + int ptr_size; + CORE_ADDR lm_addr = 0, lm_prev = 0; + int allocated = 1024; + char *p; + CORE_ADDR l_name, l_addr, l_ld, l_next, l_prev; + int header_done = 0; if (writebuf != NULL) return -2; @@ -5687,128 +5693,146 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf, xsnprintf (filename, sizeof filename, "/proc/%d/exe", pid); is_elf64 = elf_64_file_p (filename, &machine); lmo = is_elf64 ? &lmo_64bit_offsets : &lmo_32bit_offsets; + ptr_size = is_elf64 ? 8 : 4; - if (priv->r_debug == 0) - priv->r_debug = get_r_debug (pid, is_elf64); + if (annex[0] == '\0') + { + int r_version = 0; - /* We failed to find DT_DEBUG. Such situation will not change for this - inferior - do not retry it. Report it to GDB as E01, see for the reasons - at the GDB solib-svr4.c side. */ - if (priv->r_debug == (CORE_ADDR) -1) - return -1; + if (priv->r_debug == 0) + priv->r_debug = get_r_debug (pid, is_elf64); - if (priv->r_debug == 0) - { - document = xstrdup ("\n"); + /* We failed to find DT_DEBUG. Such situation will not change + for this inferior - do not retry it. Report it to GDB as + E01, see for the reasons at the GDB solib-svr4.c side. */ + if (priv->r_debug == (CORE_ADDR) -1) + return -1; + + if (priv->r_debug != 0) + { + if (linux_read_memory (priv->r_debug + lmo->r_version_offset, + (unsigned char *) &r_version, + sizeof (r_version)) != 0 + || r_version != 1) + { + warning ("unexpected r_debug version %d", r_version); + } + else if (read_one_ptr (priv->r_debug + lmo->r_map_offset, + &lm_addr, ptr_size) != 0) + { + warning ("unable to read r_map from 0x%lx", + (long) priv->r_debug + lmo->r_map_offset); + } + } } else { - int allocated = 1024; - char *p; - const int ptr_size = is_elf64 ? 8 : 4; - CORE_ADDR lm_addr, lm_prev, l_name, l_addr, l_ld, l_next, l_prev; - int r_version, header_done = 0; - - document = xmalloc (allocated); - strcpy (document, "r_debug + lmo->r_version_offset, - (unsigned char *) &r_version, - sizeof (r_version)) != 0 - || r_version != 1) + while (annex[0] != '\0') { - warning ("unexpected r_debug version %d", r_version); - goto done; + const char *sep; + CORE_ADDR *addrp; + int len; + + sep = strchr (annex, '='); + if (!sep) + break; + + len = sep - annex; + if (len == 5 && !strncmp (annex, "start", 5)) + addrp = &lm_addr; + else if (len == 4 && !strncmp (annex, "prev", 4)) + addrp = &lm_prev; + else + { + annex = strchr (sep, ';'); + if (!annex) + break; + annex++; + continue; + } + + annex = decode_address_to_semicolon (addrp, sep + 1); } + } - if (read_one_ptr (priv->r_debug + lmo->r_map_offset, - &lm_addr, ptr_size) != 0) + document = xmalloc (allocated); + strcpy (document, "l_name_offset, + &l_name, ptr_size) == 0 + && read_one_ptr (lm_addr + lmo->l_addr_offset, + &l_addr, ptr_size) == 0 + && read_one_ptr (lm_addr + lmo->l_ld_offset, + &l_ld, ptr_size) == 0 + && read_one_ptr (lm_addr + lmo->l_prev_offset, + &l_prev, ptr_size) == 0 + && read_one_ptr (lm_addr + lmo->l_next_offset, + &l_next, ptr_size) == 0) + { + unsigned char libname[PATH_MAX]; + + if (lm_prev != l_prev) { - warning ("unable to read r_map from 0x%lx", - (long) priv->r_debug + lmo->r_map_offset); - goto done; + warning ("Corrupted shared library list: 0x%lx != 0x%lx", + (long) lm_prev, (long) l_prev); + break; } - lm_prev = 0; - while (read_one_ptr (lm_addr + lmo->l_name_offset, - &l_name, ptr_size) == 0 - && read_one_ptr (lm_addr + lmo->l_addr_offset, - &l_addr, ptr_size) == 0 - && read_one_ptr (lm_addr + lmo->l_ld_offset, - &l_ld, ptr_size) == 0 - && read_one_ptr (lm_addr + lmo->l_prev_offset, - &l_prev, ptr_size) == 0 - && read_one_ptr (lm_addr + lmo->l_next_offset, - &l_next, ptr_size) == 0) + /* Not checking for error because reading may stop before + we've got PATH_MAX worth of characters. */ + libname[0] = '\0'; + linux_read_memory (l_name, libname, sizeof (libname) - 1); + libname[sizeof (libname) - 1] = '\0'; + if (libname[0] != '\0') { - unsigned char libname[PATH_MAX]; + /* 6x the size for xml_escape_text below. */ + size_t len = 6 * strlen ((char *) libname); + char *name; - if (lm_prev != l_prev) + if (!header_done) { - warning ("Corrupted shared library list: 0x%lx != 0x%lx", - (long) lm_prev, (long) l_prev); - break; + /* Terminate `", - name, (unsigned long) lm_addr, - (unsigned long) l_addr, (unsigned long) l_ld); - free (name); - } - else if (lm_prev == 0) - { - sprintf (p, " main-lm=\"0x%lx\"", (unsigned long) lm_addr); - p = p + strlen (p); + document = xrealloc (document, 2 * allocated); + allocated *= 2; + p = document + document_len; } - if (l_next == 0) - break; - - lm_prev = lm_addr; - lm_addr = l_next; + name = xml_escape_text ((char *) libname); + p += sprintf (p, "", + name, (unsigned long) lm_addr, + (unsigned long) l_addr, (unsigned long) l_ld); + free (name); } - done: - if (!header_done) + else if (lm_prev == 0) { - /* Empty list; terminate `"); + sprintf (p, " main-lm=\"0x%lx\"", (unsigned long) lm_addr); + p = p + strlen (p); } - else - strcpy (p, ""); + + lm_prev = lm_addr; + lm_addr = l_next; } + if (!header_done) + { + /* Empty list; terminate `"); + } + else + strcpy (p, ""); + document_len = strlen (document); if (offset < document_len) document_len -= offset; diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index 6bb36d8..0a8f68b 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -1115,8 +1115,7 @@ handle_qxfer_libraries_svr4 (const char *annex, if (writebuf != NULL) return -2; - if (annex[0] != '\0' || !target_running () - || the_target->qxfer_libraries_svr4 == NULL) + if (!target_running () || the_target->qxfer_libraries_svr4 == NULL) return -1; return the_target->qxfer_libraries_svr4 (annex, readbuf, writebuf, offset, len); @@ -1743,7 +1742,8 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) PBUFSIZ - 1); if (the_target->qxfer_libraries_svr4 != NULL) - strcat (own_buf, ";qXfer:libraries-svr4:read+"); + strcat (own_buf, ";qXfer:libraries-svr4:read+" + ";augmented-libraries-svr4-read+"); else { /* We do not have any hook to indicate whether the non-SVR4 target --gKMricLos+KVdGMg--