bnahill / PyCortexMDebug

A set of GDB/Python-based utilities to make life debugging ARM Cortex M processors a bit easier
GNU General Public License v3.0
175 stars 34 forks source link

unsupported operand type(s) for /: 'lxml.objectify.StringElement' and 'int' when attempting to use the `svd` command #52

Closed Niautanor closed 2 years ago

Niautanor commented 2 years ago

I get the error mentioned in the title when attempting to read out any peripheral register. I suspect that this might be SVD dependent but I can reproduce this with the STM32L4x6.svd from cmsis-svd.

This error seems to be raised here as a result of the size field of a register being parsed as a string rather than an integer.

Here is a patch that fixes this for me. I'm not sure if that is the right solution though since it feels kinda hacky

diff --git a/cmdebug/svd.py b/cmdebug/svd.py
index fc5eb99..8364454 100755
--- a/cmdebug/svd.py
+++ b/cmdebug/svd.py
@@ -383,6 +383,9 @@ class SVDPeripheralRegister:
                 for f in fields:
                     self.fields[str(f.name)] = SVDPeripheralRegisterField(f, self)

+        if type(self.size) is not int:
+            self.size = int(str(self.size), 0)
+
     def refactor_parent(self, parent: SVDPeripheral) -> None:
         self.parent_base_address = parent.base_address

The strange thing about this is that I remember that I didn't have this issue before. I unfortunately don't really remember what I changed about my setup since then.

bnahill commented 2 years ago

Looks like this got broken in commit 08dfc0170d61665978edc7b80118667b1078c31e

It works now on my machine--can you confirm?

Niautanor commented 2 years ago

Yep. It now works for me too. Thank you