Open-CMSIS-Pack / devtools

Open-CMSIS-Pack development tools - C++
Apache License 2.0
76 stars 59 forks source link

[svdconv] disableCondition Inheritance leads to a segment violation #1796

Open ckudera opened 1 month ago

ckudera commented 1 month ago

Describe the bug The inheritance (deriveFrom) of element disableCondition leads to a segment violation.

To Reproduce To reproduce, run the following svd with svdconv:

<?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
  <name>test</name>
  <version>1.0</version>
  <description>Test_Example device</description>
  <addressUnitBits>8</addressUnitBits>
  <width>32</width>
  <peripherals>
    <peripheral>
      <name>PeripheralA</name>
      <disableCondition>0 == 0</disableCondition>
      <baseAddress>0x40004000</baseAddress>
      <addressBlock>
        <offset>0x0</offset>
        <size>0x1000</size>
        <usage>registers</usage>
      </addressBlock>
      <registers>
        <register>
          <name>RegisterA</name>
          <addressOffset>0x0</addressOffset>
        </register>
      </registers>
    </peripheral>
    <peripheral derivedFrom="PeripheralA">
      <name>PeripheralB</name>
      <baseAddress>0x40002000</baseAddress>
    </peripheral>
  </peripherals>
</device>

Results in:

$ ./svdconv --generate header --fields enum /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd
Exception or Segmentation fault occurred!
  11 : segment violation

CMSIS SVD Check / Converter 3.3.47+p98-g07416995 (Sep 30 2024 14:55:46)
Copyright (C) 2010-2024 ARM Ltd and ARM Germany GmbH. All rights reserved.

Arguments: ./svdconv --generate header --fields enum /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd

*** INFO M317: /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd (Line 19) 
  Register <description> not set.

*** INFO M332: /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd (Line 9) 
  Peripheral 'PeripheralA' has only one Register.

*** INFO M317: /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd (Line 9) 
  Peripheral <description> not set.

*** INFO M332: /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd (Line 25) 
  Peripheral 'PeripheralB' has only one Register.

*** INFO M317: /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd (Line 25) 
  Peripheral <description> not set.

*** WARNING M223: /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd (Line 2) 
  Input File Name 'value_inheritance' does not match the tag <name> in the <device> section: 'test'

*** INFO M356: /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd
  No Interrupt definitions found.

*** WARNING M209: /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd
  CPU section not set. This is required for CMSIS Headerfile generation and debug support.

*** WARNING M209: /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd
  CPU section not set. This is required for CMSIS Headerfile generation and debug support.

*** CRITICAL ERROR M104: /mnt/data/Temp/ARMify/svd-test-files/value_inheritance.svd
  Exception or Segmentation fault occurred!
  11 : segment violation

Expected behavior The value of disableCondition should be inherited.

Environment (please complete the following information):

Additional context Workaround: Specify same disableCondition in derived peripheral.

E.g.:

<?xml version='1.0' encoding='utf-8'?>
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
  <name>test</name>
  <version>1.0</version>
  <description>Test_Example device</description>
  <addressUnitBits>8</addressUnitBits>
  <width>32</width>
  <peripherals>
    <peripheral>
      <name>PeripheralA</name>
      <disableCondition>0 == 0</disableCondition>
      <baseAddress>0x40004000</baseAddress>
      <addressBlock>
        <offset>0x0</offset>
        <size>0x1000</size>
        <usage>registers</usage>
      </addressBlock>
      <registers>
        <register>
          <name>RegisterA</name>
          <addressOffset>0x0</addressOffset>
        </register>
      </registers>
    </peripheral>
    <peripheral derivedFrom="PeripheralA">
      <name>PeripheralB</name>
      <disableCondition>0 == 0</disableCondition>
      <baseAddress>0x40002000</baseAddress>
    </peripheral>
  </peripherals>
</device>