From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EEB30A2EDB for ; Fri, 6 Sep 2019 14:20:09 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6C49B1F30B; Fri, 6 Sep 2019 14:20:09 +0200 (CEST) Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by dpdk.org (Postfix) with ESMTP id 1187D1F305 for ; Fri, 6 Sep 2019 14:20:08 +0200 (CEST) Received: by mail-wr1-f43.google.com with SMTP id q14so6340910wrm.9 for ; Fri, 06 Sep 2019 05:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RZG7q7PklBmNmJTgU7ZjI6AtgwEXR69xhgQagNgMicE=; b=P9wx/ON+VARRiX543UWqMKJL2nK55CEYj+hMKXZt+lOlHyIwNH+bUz8EOTjZfN3bxO B4/z+OUmrRN8PzgODoH9LG/P6TRr+ChOo87XmBS7f6vIN7cAr1XwyFstU9bjwyPmxkgo cb6e/6+X2ad9awoyP4bWljkHd899Qs10eeT+qakIBQ6bee8qvSIxUwOYCf2F7U0lqC8x 0oGqebS9qrp0CkhXECQPfWS/aP6fAfDWNdCOjBNhIxOIS42VVrSGs3PWLqqV/cdOyCSb VxPNswPNemzyJb6UHIh/sQ+btHuYLlCcD18KcRsasJFvMYSQQ5f8ttVLQJlbio5sWYHO IEZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RZG7q7PklBmNmJTgU7ZjI6AtgwEXR69xhgQagNgMicE=; b=OxtdtG/rnOS6EU5x3z4HQaWZVZ8AAM7uR/zaoiRbY0lOMWMpxU4QAU0NDx+A3WSD/H BJChL6yYwOcvicjjlpbSxVYzuUF9NxQCUuX2P+ZZGcsRmntQkDFWCasj/oNKhmv9T1xF /gPdgC6QRQsJxygG40c4j16tzwx69pwNqSYyW24/ZWvrjC4narh4rOv2iyn8MTLBbNiO fL4tLvPb9f6EU63R0lOqsSQJ0tX0wiSk05civgXRTAM18KbQq+Y9NaCtKb1gxAUKziWl nFEA/N/ratx0GA9M320a133CV5TfPG31+sSNUsXBuoIRZVFhhqSJWOfRWuS7c+xSgcla tCOA== X-Gm-Message-State: APjAAAWZIMACFMgeNmOjdlWLpdKbYbzObCgG0VM/VEhvA8uGjDvZyB9l +7Nwr/pe8ZKEQmcVkH/yoOAcxw== X-Google-Smtp-Source: APXvYqzVGdGbKv2vE31Aek5wpuzj3SCRnDM5NCWhUglbPtmPLg7MJFklUiZN6EqpiA1jYZ+PL4i0lA== X-Received: by 2002:a5d:46c4:: with SMTP id g4mr6352346wrs.189.1567772407771; Fri, 06 Sep 2019 05:20:07 -0700 (PDT) Received: from tom.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id v4sm8949916wrg.56.2019.09.06.05.20.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2019 05:20:07 -0700 (PDT) From: Robin Jarry To: Neil Horman Cc: dev@dpdk.org, John McNamara , stable@dpdk.org, Olivier Matz Date: Fri, 6 Sep 2019 14:19:55 +0200 Message-Id: <20190906121955.24046-1-robin.jarry@6wind.com> X-Mailer: git-send-email 2.23.0.rc1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] usertools: fix python 3 support of dpdk-pmdinfo.py X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Running this script on ubuntu-18.04 with python 3 and pyelftools installed produces no output but no error is reported neither: ~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd ~$ echo $? 0 While with python 2, it works: ~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd {"pci_ids": [], "name": "dpio"} {"pci_ids": [], "name": "dpbp"} {"pci_ids": [], "name": "dpaa2_qdma"} ..... Looking in the code of pyelftools, ELFFile.get_section_by_name performs a lookup in a _section_name_map dictionary which contains a mapping of section names to section numbers. Section names are strings, not bytes. We must not encode the string before using it as argument to this function. Otherwise the lookup fails and the script assumes there is no ELF section in the file. Then it exits without any error. Also, section tags are strings, not bytes, fix the following error on python 3: Traceback (most recent call last): File "usertools/dpdk-pmdinfo.py", line 612, in main() File "usertools/dpdk-pmdinfo.py", line 601, in main readelf.process_dt_needed_entries() File "usertools/dpdk-pmdinfo.py", line 442, in process_dt_needed_entries rc = tag.needed.find(b"librte_pmd") TypeError: must be str, not bytes Fixes: c67c9a5c646a ("tools: query binaries for HW and other support information") Cc: Neil Horman Fixes: 54ca545dce4b ("make python scripts python2/3 compliant") Cc: John McNamara Cc: stable@dpdk.org Signed-off-by: Robin Jarry Reviewed-by: Olivier Matz --- usertools/dpdk-pmdinfo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index 03623d5b8b48..d2d4aa3c143f 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -14,7 +14,7 @@ import string import sys from elftools.common.exceptions import ELFError -from elftools.common.py3compat import (byte2int, bytes2str, str2bytes) +from elftools.common.py3compat import (byte2int, bytes2str) from elftools.elf.elffile import ELFFile from optparse import OptionParser @@ -267,7 +267,7 @@ def _section_from_spec(self, spec): return None except ValueError: # Not a number. Must be a name then - return self.elffile.get_section_by_name(str2bytes(spec)) + return self.elffile.get_section_by_name(spec) def pretty_print_pmdinfo(self, pmdinfo): global pcidb @@ -439,7 +439,7 @@ def process_dt_needed_entries(self): for tag in dynsec.iter_tags(): if tag.entry.d_tag == 'DT_NEEDED': - rc = tag.needed.find(b"librte_pmd") + rc = tag.needed.find("librte_pmd") if (rc != -1): library = search_file(tag.needed, runpath + ":" + ldlibpath + -- 2.23.0.rc1