Skip to content

File not found error using gdbserver and cortex-M #1580

@antcpl

Description

@antcpl

Describe the bug
When trying to use the gdbserver with CORTEX_M architecture and MCU os, the xml files to configure the target seems to be at the wrong place.

Sample Code
Possible to reproduce the bug using : qiling/examples/mcu/stm32f411_gpio_hook.py and enabling the debug using the gdbserver.

Expected behavior
No crash

Screenshots
Traceback (most recent call last):
File "/home/antoine/branch_dev_qiling/qiling/examples/mcu/stm32f411_gpio_hook.py", line 30, in
test_mcu_gpio_stm32f411()
File "/home/antoine/branch_dev_qiling/qiling/examples/mcu/stm32f411_gpio_hook.py", line 26, in test_mcu_gpio_stm32f411
ql.run(count=10000)
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/core.py", line 581, in run
debugger = debugger(self)
^^^^^^^^^^^^^^
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/gdb/gdb.py", line 129, in init
self.features = QlGdbFeatures(self.ql.arch.type, self.ql.os.type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/gdb/xmlregs.py", line 45, in init
xmltree = QlGdbFeatures.__load_target_xml(archtype, ostype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/gdb/xmlregs.py", line 70, in __load_target_xml
tree = ElementTree.parse(filename)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/xml/etree/ElementTree.py", line 1204, in parse
tree.parse(source, parser)
File "/usr/lib/python3.12/xml/etree/ElementTree.py", line 558, in parse
source = open(source, "rb")
^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/gdb/xml/cortex_m/target.xml'

Additional context
Creating the directory : qiling/debugger/gdb/xml/cortex_m and adding those files in the directory :

  • arm-m-profile.xml :
<?xml version="1.0"?>
<!-- Copyright (C) 2010-2020 Free Software Foundation, Inc.

     Copying and distribution of this file, with or without modification,
     are permitted in any medium without royalty provided the copyright
     notice and this notice are preserved.  -->

<!DOCTYPE feature SYSTEM "gdb-target.dtd">
<feature name="org.gnu.gdb.arm.m-profile">
  <reg name="r0" bitsize="32" regnum="0"/>
  <reg name="r1" bitsize="32"/>
  <reg name="r2" bitsize="32"/>
  <reg name="r3" bitsize="32"/>
  <reg name="r4" bitsize="32"/>
  <reg name="r5" bitsize="32"/>
  <reg name="r6" bitsize="32"/>
  <reg name="r7" bitsize="32"/>
  <reg name="r8" bitsize="32"/>
  <reg name="r9" bitsize="32"/>
  <reg name="r10" bitsize="32"/>
  <reg name="r11" bitsize="32"/>
  <reg name="r12" bitsize="32"/>
  <reg name="sp" bitsize="32" type="data_ptr"/>
  <reg name="lr" bitsize="32"/>
  <reg name="pc" bitsize="32" type="code_ptr"/>
  <reg name="xpsr" bitsize="32" regnum="25"/>
</feature>
  • target.xml :
<?xml version="1.0"?>
<!-- Copyright (C) 2009-2016 Free Software Foundation, Inc.

 *!Copying and distribution of this file, with or without modification,
 *!are permitted in any medium without royalty provided the copyright
 *!notice and this notice are preserved.  -->

<!DOCTYPE target SYSTEM "gdb-target.dtd">
<target xmlns:xi="http://www.w3.org/2001/XInclude">
    <architecture>arm</architecture>
    <xi:include href="arm-m-profile.xml"/>
</target>

The arm-m-profile.xml file comes from qiling/debugger/gdb/xml, I just moved it to the location where the code seems to wait it.

This is quite a dirty fix, maybe code modifications would make more sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions