Repository navigation
Description
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.
Activity
elicn commentedon Jul 8, 2025
Creating the files where Qiling expects to find them sounds elegant enough for me.
Will submit a fix soon.
elicn commentedon Jul 8, 2025
@antcpl, I piggybacked on the existing PR to push the fix.
Please apply it locally and confirm the bug is fixed.
antcpl commentedon Jul 9, 2025
@elicn Hi, modifications tested and validated !
You outpaced me with the modifications in the
xmlregs.py, nice catch !I just think there is a small typo in the
xmlregs.pyI've left a comment directly on the commit.antcpl commentedon Jul 9, 2025
As you have a PR on it's way about debugging maybe you would have a look at #1538
elicn commentedon Jul 9, 2025
It is a known issue for quite some time, and it is mostly about a Unicorn limitation which doesn't tell the user why emulation was stopped, so we don't know whether it just reached a breakpoint or reached the emulation end address.
This will require some time to work around, unless Unicorn provide that info.
antcpl commentedon Jul 9, 2025
Ok, thanks a lot for explanation, wasn't aware of this technical detail.