From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119816 invoked by alias); 8 Sep 2018 22:54:48 -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 119787 invoked by uid 89); 8 Sep 2018 22:54:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3 autolearn=ham version=3.3.2 spammy= X-HELO: sessmg22.ericsson.net Received: from sessmg22.ericsson.net (HELO sessmg22.ericsson.net) (193.180.251.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 08 Sep 2018 22:54:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1536447283; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=j/eRJcMfKAP3C0F3rrBqgAVqRalqnuh1B6V09Stxvhw=; b=IGv50lX/lR/AluLf5tJfbKLpkHy5+L2KhVbCrhimMyLIuxVNUxlKeU6+6kNPUOoc QcGck1TcdDThvA2RTBJQ1m+pF5K7JM6l7SXeVVccLry3+YTmjhyY4KNImr6bbl0d Ng3orO9XcYNveVcGEqHIpfmYoVYX7w5GyEydhu51R3A=; Received: from ESESSMB501.ericsson.se (Unknown_Domain [153.88.183.119]) by sessmg22.ericsson.net (Symantec Mail Security) with SMTP id 4D.5C.31332.333549B5; Sun, 9 Sep 2018 00:54:43 +0200 (CEST) Received: from ESESBMB504.ericsson.se (153.88.183.171) by ESESSMB501.ericsson.se (153.88.183.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Sun, 9 Sep 2018 00:54:42 +0200 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (153.88.183.157) by ESESBMB504.ericsson.se (153.88.183.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Sun, 9 Sep 2018 00:54:42 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HWJJlhEUX6HyxPnMBWClfbYlTkRxZ+MKv4SKkAGAqB4=; b=IqfwENBcHG1rWMAz+V25CaxgPpMnRLCH6Od47aydJTipa4QVUJBIOFsXkZVnOnhutYNVF/Q58wFTXqHcuQUb6GJzxmKKjsSe2Hgwz5d5BWxC2545OW+zEWfk3XK9UuKI8gvotiwPHoI2mas4GRTZmOngnmYyqUMHTCqAPhmC600= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from [100.94.32.129] (192.176.1.81) by SN6PR15MB2399.namprd15.prod.outlook.com (2603:10b6:805:24::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.17; Sat, 8 Sep 2018 22:54:37 +0000 Subject: Re: [PATCH 3/5] Add support for 'info proc files' on FreeBSD core dumps. To: John Baldwin , References: <20180908003659.37482-1-jhb@FreeBSD.org> <20180908003659.37482-4-jhb@FreeBSD.org> From: Simon Marchi Message-ID: <26938c44-7bab-3951-ff2f-d0567d3aee39@ericsson.com> Date: Sat, 08 Sep 2018 22:54:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180908003659.37482-4-jhb@FreeBSD.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Return-Path: simon.marchi@ericsson.com Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00212.txt.bz2 On 2018-09-08 01:36 AM, John Baldwin wrote: > Walk the list of struct kinfo_file objects in the > NT_FREEBSD_PROCSTAT_FILES core dump note outputting a description of > each open file descriptor. For sockets, the local and remote socket > addresses are displayed in place of the file name field. For UNIX > local domain sockets, only a single address is displayed since most > UNIX sockets only have one valid address and printing both pathnames > could be quite long. The output format was somewhat inspired by the > output of the "procstat -f" command on FreeBSD, but with a few less > details and some fields were condensed. Just some nits, LGTM otherwise. > diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c > index 9e6d7276c4..a8b5b2f146 100644 > --- a/gdb/fbsd-tdep.c > +++ b/gdb/fbsd-tdep.c > @@ -90,18 +90,115 @@ > #define KF_STRUCTSIZE 0x0 > #define KF_TYPE 0x4 > #define KF_FD 0x8 > +#define KF_FLAGS 0x10 > +#define KF_OFFSET 0x18 In sys/user.h, it says: /* XXX Hidden alignment padding here on amd64 */ Does that mean the field offsets can be different for other arches? > +/* Constats for socket types. These match SOCK_* constants in "Constats" > +/* Helper function to print out an IPv6 socket address. The address > + is formatted similar to inet_ntop. */ > + > +static void > +fbsd_print_sockaddr_in6 (void *sockaddr) > +{ > + struct fbsd_sockaddr_in6 *sin6 = > + reinterpret_cast(sockaddr); > + uint16_t words[ARRAY_SIZE(sin6->sin6_addr) / 2]; > + > + /* Populate the array of 16-bit words from network-order bytes. */ > + for (int i = 0; i < ARRAY_SIZE(words); i++) > + words[i] = (sin6->sin6_addr[i * 2] << 8) | sin6->sin6_addr[i * 2 + 1]; > + > + /* Find the longest run of zero words. */ > + int best, bestlen, current, len; > + > + best = -1; > + bestlen = 0; > + current = -1; > + len = 0; > + for (int i = 0; i < ARRAY_SIZE(words); i++) > + { > + if (words[i] == 0) > + { > + if (current >= 0) > + len++; > + else > + { > + current = i; > + len = 1; > + } > + } > + else > + { > + if (current >= 0 && len > bestlen) > + { > + best = current; > + bestlen = len; > + } > + current = -1; > + len = 0; > + } > + } > + if (current >= 0 && len > bestlen) > + { > + best = current; > + bestlen = len; > + } > + if (bestlen < 2) > + best = -1; > + > + for (int i = 0; i < ARRAY_SIZE(words); i++) > + { > + if (best >= 0 && i >= best && i < best + bestlen) > + { > + if (i == best || i == ARRAY_SIZE(words) - 1) > + printf_filtered (":"); > + } > + else > + { > + if (i != 0) > + printf_filtered (":"); > + printf_filtered ("%x", words[i]); > + } > + } > + printf_filtered (".%u", (sin6->sin6_port[0] << 8) | sin6->sin6_port[1]); > +} Hmm, I suppose we'll want to re-use this ipv6 address printing code for the Linux... We can take care of moving it to a common file then. > +/* Implement "info proc files" for a corefile. */ > + > +static void > +fbsd_core_info_proc_files (struct gdbarch *gdbarch) > +{ > + asection *section; > + unsigned char *descdata, *descend; > + size_t note_size; Don't hesitate to declare them variables at the point you use the the first time :). > + > + section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files"); > + if (section == NULL) > + { > + warning (_("unable to find open files in core file")); > + return; > + } > + > + note_size = bfd_get_section_size (section); > + if (note_size < 4) > + error (_("malformed core note - too short for header")); > + > + gdb::def_vector contents (note_size); > + if (!bfd_get_section_contents (core_bfd, section, contents.data (), > + 0, note_size)) > + error (_("could not get core note contents")); > + > + descdata = contents.data (); > + descend = descdata + note_size; > + > + /* Skip over the structure size. */ > + descdata += 4; > + > + printf_filtered (_("Open files:\n\n")); > + printf_filtered (" %6s %6s %10s %9s %s\n", > + "FD", "Type", "Offset", "Flags ", "Name"); > + > + while (descdata + KF_PATH < descend) > + { > + LONGEST fd, flags, offset, type, vnode_type; > + ULONGEST structsize; > + > + structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE); > + if (structsize < KF_PATH) > + error (_("malformed core note - vmmap entry too small")); Copy pasta? Actually, there seems to be the same mistake in fbsd_core_vnode_path. Simon