[dpdk-stable] [PATCH] usertools: fix python 3 support of dpdk-pmdinfo.py
Robin Jarry
robin.jarry at 6wind.com
Fri Sep 6 14:19:55 CEST 2019
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 <module>
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 <nhorman at tuxdriver.com>
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: John McNamara <john.mcnamara at intel.com>
Cc: stable at dpdk.org
Signed-off-by: Robin Jarry <robin.jarry at 6wind.com>
Reviewed-by: Olivier Matz <olivier.matz at 6wind.com>
---
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
More information about the stable
mailing list