Extract DPDK PMD info JSON strings from an ELF file. :returns: A list of DPDK drivers info dictionaries.
(paths: Iterable[Path], search_plugins: bool)
| 107 | |
| 108 | # ---------------------------------------------------------------------------- |
| 109 | def parse_pmdinfo(paths: Iterable[Path], search_plugins: bool) -> List[dict]: |
| 110 | """ |
| 111 | Extract DPDK PMD info JSON strings from an ELF file. |
| 112 | |
| 113 | :returns: |
| 114 | A list of DPDK drivers info dictionaries. |
| 115 | """ |
| 116 | binaries = set(paths) |
| 117 | for p in paths: |
| 118 | binaries.update(get_needed_libs(p)) |
| 119 | if search_plugins: |
| 120 | # cast to list to avoid errors with update while iterating |
| 121 | binaries.update(list(get_plugin_libs(binaries))) |
| 122 | |
| 123 | drivers = [] |
| 124 | |
| 125 | for b in binaries: |
| 126 | logging.debug("analyzing %s", b) |
| 127 | try: |
| 128 | for s in get_elf_strings(b, ".rodata", "PMD_INFO_STRING="): |
| 129 | try: |
| 130 | info = json.loads(s) |
| 131 | scrub_pci_ids(info) |
| 132 | drivers.append(info) |
| 133 | except ValueError as e: |
| 134 | # invalid JSON, should never happen |
| 135 | logging.warning("%s: %s", b, e) |
| 136 | except ELFError as e: |
| 137 | # only happens for discovered plugins that are not ELF |
| 138 | logging.debug("%s: cannot parse ELF: %s", b, e) |
| 139 | |
| 140 | return drivers |
| 141 | |
| 142 | |
| 143 | # ---------------------------------------------------------------------------- |
no test coverage detected