Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp99752imm; Tue, 3 Jul 2018 14:48:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcyEV5SAfZ+iXMS1ZdDghjTGRTwbCtVIZV1PETgMIxi5PEPK6+5JP9TJbCJU4qI8CFX6kmE X-Received: by 2002:a62:4585:: with SMTP id n5-v6mr23483862pfi.32.1530654508140; Tue, 03 Jul 2018 14:48:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530654508; cv=none; d=google.com; s=arc-20160816; b=R6cV+DF6vIGBUkLMXSB8XJhfoYSI+IsY9nWD7wR1zYgPi45LbaPDm7LroSVuVW09wH RcpY3kgHSXPQyBatF+7xzpRivcPlqg+2vBpksMD/vwzDxGJZ4vvLGZSskVj07xtYjF/G cMQJYyi9l4e3Y/RV0XvBjIFRQcwjQMsSwgZiiDjigCP8BU+7d+Ct55WzEwPP+YsEVCNG eCeCuaaEeLQcJ6bTFadifpnmByeAtLAY2LpLKcCSuogsezridowjvD+wptqz7KrNH5AY 7A2HqVzg81KKC9asYbMm24M62adwI4qXHXZ4OpC2lVYQetmcmnV2efIEDfma3TeXZw0q N2wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature:arc-authentication-results; bh=xOShNDsoiZ8MUk6u3liD1/BCSsbe7P0jBLi7SmFn65Q=; b=QWyBLSNUjaA4pJV/7miGa3JVglAQkQjWi2R5M734KxWRWS1bMVGAMpuHTjDFnEw/Yc K+aQWiiJ6z1APFTQ2aqk0CsRhOdQY0e6pScvCAiBNAkbOdwcp8a4PWEnh3yBUaRmmKWl Ljc7KRM929SJpd+PJF6D4ugrduJTRqKZ9Js3q6CYULv94HexJ/7agvTADvucLjV7G/Jy UB/9i+MgIyxDhSE+AsTzlDFL2wnNxi9OSan3cPeM0QqRGHjcAlnCWroQ9H70yOtUJd5z JSkeNjSrXGrkzLNfJRaWH5hOVjr33UPdqDBgeaFDWx/JjAL7RUMUfAAMIRNqT6kTs4TP +VQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=XY02TXXF; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=gGogoQHi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d185-v6si2006015pfc.176.2018.07.03.14.48.13; Tue, 03 Jul 2018 14:48:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=XY02TXXF; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=gGogoQHi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753392AbeGCVrd (ORCPT + 99 others); Tue, 3 Jul 2018 17:47:33 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:47388 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752775AbeGCVra (ORCPT ); Tue, 3 Jul 2018 17:47:30 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w63Lgx8F019294; Tue, 3 Jul 2018 14:47:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=facebook; bh=xOShNDsoiZ8MUk6u3liD1/BCSsbe7P0jBLi7SmFn65Q=; b=XY02TXXFB/3GlmA1E/8Y2Imnsv8WF6MUKQaUnPMH3LZHsbLe3ncTtQvWzi0GvCVe1R2W QB1B39XWfJDlyfSRGVO9G/6B1xa1tLhE/mauL+zsxVJCfmxwkgsVi1vIOBfxVLd6mBjW VpZDRMohZJB+MkjFicsXCXnkvAEr2NtxTZ8= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2k0fvf87e6-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 03 Jul 2018 14:47:09 -0700 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.25) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 3 Jul 2018 17:46:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xOShNDsoiZ8MUk6u3liD1/BCSsbe7P0jBLi7SmFn65Q=; b=gGogoQHi3z/fdmW/aNWeeWaUpDoA//AINRUFbevLTJ74nzApSYXP33kn8JqjmLDVubEvA7YVRUNImjhifVPt/UBRDcYsM5s8ALoIKMjOuDbZSy/TBd/ja51NdOiLhd6aEwqjeGOViUBhhzSKh/Wj6+4vQdqBPXW3hNHbVDHr534= Received: from w1t1fb (2620:10d:c090:200::5:808d) by BYAPR15MB2501.namprd15.prod.outlook.com (2603:10b6:a02:88::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.25; Tue, 3 Jul 2018 21:46:12 +0000 Date: Tue, 3 Jul 2018 22:46:00 +0100 From: Okash Khawaja To: Jakub Kicinski CC: Daniel Borkmann , Martin KaFai Lau , Alexei Starovoitov , Yonghong Song , "Quentin Monnet" , "David S. Miller" , , , Subject: Re: [PATCH bpf-next v2 2/3] bpf: btf: add btf print functionality Message-ID: <20180703214559.GA4448@w1t1fb> References: <20180702183913.669030439@fb.com> <20180702191324.570616684@fb.com> <20180702220659.6baa77ba@cakuba.netronome.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20180702220659.6baa77ba@cakuba.netronome.com> User-Agent: Mutt/1.9.5 (2018-04-13) X-Originating-IP: [2620:10d:c090:200::5:808d] X-ClientProxiedBy: MWHPR19CA0076.namprd19.prod.outlook.com (2603:10b6:320:1f::14) To BYAPR15MB2501.namprd15.prod.outlook.com (2603:10b6:a02:88::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d79c539c-c12c-45b0-1ffd-08d5e12e65db X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020);SRVR:BYAPR15MB2501; X-Microsoft-Exchange-Diagnostics: 1;BYAPR15MB2501;3:IVMQsz3DKCX6q87/XIvEg5d4aKgbKyzMrE5F/kq+Xsrj50KTFAo/a0tMAP7cdGvXp4MAX/9PtSnRQY4+8a/X8Lj7LxuAOpZYGOf11rCIOUXlpyU8mpGeUSr9PsRstD/W4CfUocbsBjhZy7ht84lL6sHUqwHanBtaeB3+nrEVYmhJGaO++4jmVVte41yqhCBW1e8BUZGLMjDv1aICER7zvKpykRLG1N12tjxuadL8AaOzCkecPjKD0Kl+JB6hUpgu;25:n1I1psamh94TN7II3uM/GI9D5nooUHS1Bbhox5FqWAATjo4Yb2J1utsqoDi1TFFMXqSejJvJJzXCipPI+tyAUX3lllCs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cDUW;4:dhcdtyAkpXQJGPL/rXeh+RDRG46TihQ90DVXuGcPZJEiEUxK+aleV3SYREQ4xn+jexiWoF2F7/ArKlUwr3TQ5w4YsCDEsfuU1qMmi8ZsY7U5/F7D/28txVwe480wDOh7MY1fx/BBWfz4LB2Ia1JV3h1LRx/+y9/TF0HOC4yd7340BTmHGnRfJYdB8sj2UIe1+XYZVe/9mpDIu4BjlJJz1fJIsJhWT8YBqN5T2zl8kQYwKg3S7rkenLSn3k8JEbvbFvVcnf1dhcgHMNKtb11tqf4U3/3Uw8SLWzmP1txiOBlaKowncvKjTGgaWvnJ+R6pqsJ3s8ej6Ok1IWBtnoPD0/XDVeQcD+7XUJWKCvP1D0A= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(81227570615382)(17755550239193); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231254)(11241501184)(944501410)(52105095)(10201501046)(3002001)(93006095)(93001095)(149027)(150027)(6041310)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(6072148)(201708071742011)(7699016);SRVR:BYAPR15MB2501;BCL:0;PCL:0;RULEID:;SRVR:BYAPR15MB2501; X-Forefront-PRVS: 0722981D2A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(366004)(396003)(136003)(376002)(39860400002)(346002)(199004)(189003)(486006)(53936002)(106356001)(6246003)(33716001)(105586002)(1076002)(46003)(97736004)(478600001)(6916009)(68736007)(33656002)(6116002)(5660300001)(23726003)(47776003)(386003)(229853002)(16526019)(50466002)(186003)(6666003)(305945005)(33896004)(52396003)(52116002)(6496006)(25786009)(86362001)(9686003)(11346002)(55016002)(446003)(81156014)(76176011)(2906002)(8936002)(8676002)(476003)(7736002)(81166006)(14444005)(54906003)(39060400002)(58126008)(16586007)(316002)(4326008)(18370500001)(42262002)(309714004);DIR:OUT;SFP:1102;SCL:1;SRVR:BYAPR15MB2501;H:w1t1fb;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BYAPR15MB2501;23:H69b5dJwjGjKuGGkuDaiiSKaJuxnJ70is3TwK0QHA?= =?us-ascii?Q?PVhcqN5jvjfgIZVWd2S0vkv8YT39GJzVewiCVUrc2GlMX+npTS8p5dTBGgo0?= =?us-ascii?Q?Yp0AVM6rmSKjR4YCHP88PX0K/jzkm1jL4wNCX2tdriVzYJIR2iG1Jr8xdIBP?= =?us-ascii?Q?A9I4OHavp7fXDF+4f/ysAvbkxMiY+n0vzzKUCPWZ8Hf60VkGTjfMMwclDnCX?= =?us-ascii?Q?E2pqPeAsFAet5G1kBPG+Fw11DwEQFzKKEMP/scJUe4Dbuqy4kMsnkVBVwGIs?= =?us-ascii?Q?bUX5tC6+xv/bgh0b1eMCR+zVE5i8ZLyM6T5UHYKoBVLvd6jNDBRgqS5QLDZj?= =?us-ascii?Q?UIzpNaInKQjqXSlEQ1Uu8mLn3TaLGW35IR8ajvbV1SUMQXctOQbC7aFKOoJH?= =?us-ascii?Q?eeZ28qMW9VD1lBptmvkikXH/xM+fWEmwHJURHSjSZyXddn4u10U/4qf+4XfI?= =?us-ascii?Q?FXhfjCzMcumv0QWddPTLi9eMKs/RXKsrVdymLkdYbN37/AsQPnyac3aEIq09?= =?us-ascii?Q?Z6qr2Q8jQS9nOWh4dP3ci4d+ITmJyctseBBHdOaxMODOz2xAjVqW5OfIgSK1?= =?us-ascii?Q?xnTrqMYkXy8KKjVuWvoWd+jqvg3kjkIZz5IN9Vw6HoWWkel0T7cCyB2KCPAw?= =?us-ascii?Q?JuwxXqq0SIcs3eHEUlyGpSFjj2G8CXGe1JmSVmPWEURPXlAXy508qMZSp7Mc?= =?us-ascii?Q?VOcZaKlbXHljkH5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rFamUTqQE7EYr+criyfYvvwq/EoB6W9LzpXMTI9kLjCPauuvRVnTG7dzcczdyNIchbqj/lBiW4s2cmuBQ/opdBWVDypk6Jtnai5Xuslgh1AzL7HMBzV2H2x68;20:ARGUOTKjY/5xj/Emmd8bcPYcp1+67FqxeUypDcuwrrCiWi057lYdwk2vV3YP4wl35bvEeR3COOUnZDVCTKFx3tNBSJ2pgTSsfCzMuPvqXxUBOy2O48jsGAigFMho2lHVYOKZIZ63eRWKmXBh7bNu//X5nXgd/eUsn8kPaFA9Zog= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2018 21:46:12.8152 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d79c539c-c12c-45b0-1ffd-08d5e12e65db X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR15MB2501 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-03_09:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 02, 2018 at 10:06:59PM -0700, Jakub Kicinski wrote: > On Mon, 2 Jul 2018 11:39:15 -0700, Okash Khawaja wrote: [...] > > > +#define BITS_PER_BYTE_MASK (BITS_PER_BYTE - 1) > > +#define BITS_PER_BYTE_MASKED(bits) ((bits) & BITS_PER_BYTE_MASK) > > Perhaps it's just me but BIT_OFFSET or BIT_COUNT as a name of this macro > would make it more obvious to parse in the code below. I don't mind either. However these macro names are also used inside kernel for same purpose. For sake of consistency, I'd recommend we keep them :) > > > +#define BITS_ROUNDDOWN_BYTES(bits) ((bits) >> 3) > > +#define BITS_ROUNDUP_BYTES(bits) \ > > + (BITS_ROUNDDOWN_BYTES(bits) + !!BITS_PER_BYTE_MASKED(bits)) > > + > > +static int btf_dumper_do_type(const struct btf_dumper *d, uint32_t type_id, > > + uint8_t bit_offset, const void *data); > > + > > +static void btf_dumper_ptr(const void *data, json_writer_t *jw, > > + bool is_plain_text) > > +{ > > + if (is_plain_text) > > + jsonw_printf(jw, "%p", *((uintptr_t *)data)); > > + else > > + jsonw_printf(jw, "%u", *((uintptr_t *)data)); > > +} > > + > > +static int btf_dumper_modifier(const struct btf_dumper *d, uint32_t type_id, > > + const void *data) > > +{ > > + int32_t actual_type_id = btf__resolve_type(d->btf, type_id); > > Please prefer kernel types like __u32 wherever possible. > > > + int ret; > > + > > + if (actual_type_id < 0) > > + return actual_type_id; > > + > > + ret = btf_dumper_do_type(d, actual_type_id, 0, data); > > + > > + return ret; > > ret is unnecessary. > > > +} > > + > > +static void btf_dumper_enum(const void *data, json_writer_t *jw) > > +{ > > + jsonw_printf(jw, "%d", *((int32_t *)data)); > > Unnecessary parenthesis. There is a lot of those, please remove them > all. > > > +} > > + > > +static int btf_dumper_array(const struct btf_dumper *d, uint32_t type_id, > > + const void *data) > > +{ > > + const struct btf_type *t = btf__type_by_id(d->btf, type_id); > > + struct btf_array *arr = (struct btf_array *)(t + 1); > > + int64_t elem_size; > > + int ret = 0; > > + uint32_t i; > > + > > + elem_size = btf__resolve_size(d->btf, arr->type); > > + if (elem_size < 0) > > + return elem_size; > > + > > + jsonw_start_array(d->jw); > > + for (i = 0; i < arr->nelems; i++) { > > + ret = btf_dumper_do_type(d, arr->type, 0, > > + data + (i * elem_size)); > > Unnecessary parenthesis. > > > + if (ret) > > + break; > > + } > > + > > + jsonw_end_array(d->jw); > > + return ret; > > +} > > + > > +static void btf_dumper_int_bits(uint32_t int_type, uint8_t bit_offset, > > + const void *data, json_writer_t *jw, > > + bool is_plain_text) > > +{ > > + uint32_t bits = BTF_INT_BITS(int_type); > > + uint16_t total_bits_offset; > > + uint16_t bytes_to_copy; > > + uint16_t bits_to_copy; > > Please use normal int types for things which don't have to be > explicitly sized. Using explicitly sized variables is bad style, > and ALU operations other than on word or byte quantities are usually > slower on modern CPUs. > > > + uint8_t upper_bits; > > + union { > > + uint64_t u64_num; > > + uint8_t u8_nums[8]; > > Are the int types in BTF constrained to 64bit at most? > > > + } print_num; > > + > > + total_bits_offset = bit_offset + BTF_INT_OFFSET(int_type); > > + data += BITS_ROUNDDOWN_BYTES(total_bits_offset); > > + bit_offset = BITS_PER_BYTE_MASKED(total_bits_offset); > > + bits_to_copy = bits + bit_offset; > > + bytes_to_copy = BITS_ROUNDUP_BYTES(bits_to_copy); > > + > > + print_num.u64_num = 0; > > + memcpy(&print_num.u64_num, data, bytes_to_copy); > > This scheme is unlikely to work on big endian machines... Can you give an example how? > > > + upper_bits = BITS_PER_BYTE_MASKED(bits_to_copy); > > + if (upper_bits) { > > + uint8_t mask = (1 << upper_bits) - 1; > > + > > + print_num.u8_nums[bytes_to_copy - 1] &= mask; > > + } > > + > > + print_num.u64_num >>= bit_offset; > > + > > + if (is_plain_text) > > + jsonw_printf(jw, "0x%llx", print_num.u64_num); > > + else > > + jsonw_printf(jw, "%llu", print_num.u64_num); > > +} > > + > > +static int btf_dumper_int(const struct btf_type *t, uint8_t bit_offset, > > + const void *data, json_writer_t *jw, > > + bool is_plain_text) > > +{ > > + uint32_t *int_type = (uint32_t *)(t + 1); > > + uint32_t bits = BTF_INT_BITS(*int_type); > > + int ret = 0; > > + > > + /* if this is bit field */ > > + if (bit_offset || BTF_INT_OFFSET(*int_type) || > > + BITS_PER_BYTE_MASKED(bits)) { > > + btf_dumper_int_bits(*int_type, bit_offset, data, jw, > > + is_plain_text); > > + return ret; > > + } > > + > > + switch (BTF_INT_ENCODING(*int_type)) { > > + case 0: > > + if (BTF_INT_BITS(*int_type) == 64) > > + jsonw_printf(jw, "%lu", *((uint64_t *)data)); > > + else if (BTF_INT_BITS(*int_type) == 32) > > + jsonw_printf(jw, "%u", *((uint32_t *)data)); > > + else if (BTF_INT_BITS(*int_type) == 16) > > + jsonw_printf(jw, "%hu", *((uint16_t *)data)); > > + else if (BTF_INT_BITS(*int_type) == 8) > > + jsonw_printf(jw, "%hhu", *((uint8_t *)data)); > > + else > > + btf_dumper_int_bits(*int_type, bit_offset, data, jw, > > + is_plain_text); > > + break; > > + case BTF_INT_SIGNED: > > + if (BTF_INT_BITS(*int_type) == 64) > > + jsonw_printf(jw, "%ld", *((int64_t *)data)); > > + else if (BTF_INT_BITS(*int_type) == 32) > > + jsonw_printf(jw, "%d", *((int32_t *)data)); > > + else if (BTF_INT_BITS(*int_type) == 16) > > Please drop the double space. Both for 16 where it makes no sense and > for 8 where it's marginally useful but not really. > > > + jsonw_printf(jw, "%hd", *((int16_t *)data)); > > + else if (BTF_INT_BITS(*int_type) == 8) > > + jsonw_printf(jw, "%hhd", *((int8_t *)data)); > > + else > > + btf_dumper_int_bits(*int_type, bit_offset, data, jw, > > + is_plain_text); > > + break; > > + case BTF_INT_CHAR: > > + if (*((char *)data) == '\0') > > + jsonw_null(jw); > > Mm.. I don't think 0 char is equivalent to null. Yes, thanks. Will fix. > > > + else if (isprint(*((char *)data))) > > + jsonw_printf(jw, "\"%c\"", *((char *)data)); > > This looks very suspicious. So if I see a "6" for a char field it's > either a 6 ('\u0006') or a 54 ('6')... It will always be 54. May be I missed your point. Could you explain why it would be other than 54? > > > + else > > + if (is_plain_text) > > + jsonw_printf(jw, "%hhx", *((char *)data)); > > + else > > + jsonw_printf(jw, "%hhd", *((char *)data)); > > ... I think you need to always print a string, and express it as > \u00%02hhx for non-printable. Okay that makes sense > > > + break; > > + case BTF_INT_BOOL: > > + jsonw_bool(jw, *((int *)data)); > > + break; > > + default: > > + /* shouldn't happen */ > > + ret = -EINVAL; > > You only set ret to something else than 0 here just to break and > immediately return. Please remove the ret variable. > > > + break; > > + } > > + > > + return ret; > > +} > > + > > +static int btf_dumper_struct(const struct btf_dumper *d, uint32_t type_id, > > + const void *data) > > +{ > > + const struct btf_type *t = btf__type_by_id(d->btf, type_id); > > Please don't call functions which need error checking as initialized > the if below looks very awkward.. > > > + struct btf_member *m; > > + int ret = 0; > > + > > + int i, vlen; > > + > > + if (!t) > > + return -EINVAL; > > + > > + vlen = BTF_INFO_VLEN(t->info); > > + jsonw_start_object(d->jw); > > + m = (struct btf_member *)(t + 1); > > + > > + for (i = 0; i < vlen; i++) { > > + jsonw_name(d->jw, btf__name_by_offset(d->btf, m[i].name_off)); > > + ret = btf_dumper_do_type(d, m[i].type, > > + BITS_PER_BYTE_MASKED(m[i].offset), data > > + + BITS_ROUNDDOWN_BYTES(m[i].offset)); > > Please use a temp variable to avoid this awkward multi-line sum. > > > + if (ret) > > + return ret; > > You can't return without jsonw_end_object(). > > > + } > > + > > + jsonw_end_object(d->jw); > > + > > + return 0; > > +} > > + > > +static int btf_dumper_do_type(const struct btf_dumper *d, uint32_t type_id, > > + uint8_t bit_offset, const void *data) > > +{ > > + const struct btf_type *t = btf__type_by_id(d->btf, type_id); > > + int ret = 0; > > + > > + switch (BTF_INFO_KIND(t->info)) { > > + case BTF_KIND_INT: > > + ret = btf_dumper_int(t, bit_offset, data, d->jw, > > + d->is_plain_text); > > + break; > > + case BTF_KIND_STRUCT: > > + case BTF_KIND_UNION: > > + ret = btf_dumper_struct(d, type_id, data); > > + break; > > + case BTF_KIND_ARRAY: > > + ret = btf_dumper_array(d, type_id, data); > > + break; > > + case BTF_KIND_ENUM: > > + btf_dumper_enum(data, d->jw); > > + break; > > + case BTF_KIND_PTR: > > + btf_dumper_ptr(data, d->jw, d->is_plain_text); > > + break; > > + case BTF_KIND_UNKN: > > + jsonw_printf(d->jw, "(unknown)"); > > + break; > > + case BTF_KIND_FWD: > > + /* map key or value can't be forward */ > > Right, but you have to print _something_, otherwise we would have a > name without a value, which would break JSON, no? > > > + ret = -EINVAL; > > + break; > > + case BTF_KIND_TYPEDEF: > > + case BTF_KIND_VOLATILE: > > + case BTF_KIND_CONST: > > + case BTF_KIND_RESTRICT: > > + ret = btf_dumper_modifier(d, type_id, data); > > + break; > > + default: > > + jsonw_printf(d->jw, "(unsupported-kind"); > > + ret = -EINVAL; > > + break; > > + } > > + > > + return ret; > > Why return ret; at all, there is no code after the switch just return > directly from cases and save 9 LOC. > > > +} > > + > > +int32_t btf_dumper_type(const struct btf_dumper *d, uint32_t type_id, > > + const void *data) > > +{ > > + if (!d) > > + return -EINVAL; > > No need for defensive programming. > > > + return btf_dumper_do_type(d, type_id, 0, data); > > +} > > --- /dev/null > > +++ b/tools/bpf/bpftool/btf_dumper.h > > @@ -0,0 +1,23 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* Copyright (c) 2018 Facebook */ > > + > > +#ifndef BTF_DUMPER_H > > +#define BTF_DUMPER_H > > + > > +struct btf_dumper { > > + const struct btf *btf; > > + json_writer_t *jw; > > + bool is_plain_text; > > +}; > > + > > +/* btf_dumper_type - print data along with type information > > + * @d: an instance containing context for dumping types > > + * @type_id: index in btf->types array. this points to the type to be dumped > > + * @data: pointer the actual data, i.e. the values to be printed > > + * > > + * Returns zero on success and negative error code otherwise > > + */ > > +int32_t btf_dumper_type(const struct btf_dumper *d, uint32_t type_id, > > + const void *data); > > + > > +#endif > > Please don't add header files for a single struct and single function. > Just put this in main.h. Thanks for your feedback. I'll reply with v3. Okash