Skip to content

Qdb Arm render and Arm branch predictor bug #1573

@antcpl

Description

@antcpl

Describe the bug
When trying to debug a cortex M target, two bugs happen one in render_arm.py, the other in branch_predictor_arm.py. Both are the same : cpsr = self.read_reg('cpsr'), this call uses the cpsr that doesn't exists on Armv7M, it's xpsr.

Screenshots
Traceback (most recent call last):
File "/home/antoine/branch_dev_qiling/qiling/examples/mcu/cortex_M/general_script.py", line 50, in
ql.run()
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/qdb/qdb.py", line 91, in init
self.dbg_hook([addr for addr in init_hook if int(addr, 0) != self.ql.loader.entry_point])
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/qdb/qdb.py", line 150, in dbg_hook
self.ql.os.run()
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/os/mcu/mcu.py", line 80, in run
self.ql.emu_start(current_address, 0, count=1)
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/core.py", line 774, in emu_start
raise self.internal_exception
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/core_hooks.py", line 141, in wrapper
return callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/core_hooks.py", line 226, in _hook_trace_cb
ret = hook.call(ql, addr, size)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/core_hooks_types.py", line 25, in call
return self.callback(ql, *args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/qdb/qdb.py", line 126, in __bp_handler
self.do_context()
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/qdb/qdb.py", line 401, in do_context
self.render.context_reg()
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/qdb/render/render.py", line 73, in wrapper
wrapped(*args, **kwargs)
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/qdb/render/render.py", line 238, in context_reg
self.print_mode_info()
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/qdb/render/render_arm.py", line 18, in print_mode_info
cpsr = self.read_reg('cpsr')
^^^^^^^^^^^^^^^^^^^^^
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/debugger/qdb/context.py", line 48, in read_reg
return self.ql.arch.regs.read(reg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/antoine/branch_dev_qiling/qilingenv/lib/python3.12/site-packages/qiling/arch/register.py", line 58, in read
register = self.register_mapping[register.lower()]
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
KeyError: 'cpsr'

Additional context
I've just tried to replace with xpsr string this work perfectly, you just have to find a way to make the correct call.

Metadata

Metadata

Assignees

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