Skip to content

Commit f1e47da

Browse files
committed
qdb: fix TempBreakpoint when working with mcu
1 parent 778b979 commit f1e47da

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

qiling/debugger/qdb/qdb.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,25 @@ def dbg_hook(self: QlQdb, init_hook: str):
3939

4040
# self.ql.loader.entry_point # ld.so
4141
# self.ql.loader.elf_entry # .text of binary
42-
if self.ql.archtype != QL_ARCH.CORTEX_M:
4342

44-
if init_hook:
45-
init_hook = _parse_int(init_hook)
43+
if init_hook:
44+
pause_entry = _parse_int(init_hook)
45+
else:
46+
pause_entry = self.ql.loader.entry_point
47+
48+
self.set_breakpoint(pause_entry, is_temp=True)
4649

47-
self.set_breakpoint(init_hook, is_temp=True)
50+
self.cur_addr = self.ql.loader.entry_point
4851

49-
self.cur_addr = self.ql.loader.entry_point
52+
if self.ql.archtype == QL_ARCH.CORTEX_M:
53+
self._run()
54+
55+
else:
5056
self._init_state = self.ql.save()
5157

52-
self.do_context()
58+
if pause_entry != self.cur_addr:
59+
self.do_context()
60+
5361
self.interactive()
5462

5563
@property
@@ -114,12 +122,19 @@ def _run(self: Qldbg, address: int = 0, end: int = 0, count: int = 0) -> None:
114122
if self.ql.archtype == QL_ARCH.CORTEX_M and self.ql.count != 0:
115123

116124
while self.ql.count:
117-
self.ql.arch.step()
118-
self.ql.count -= 1
119-
if self.cur_addr in self.bp_list.keys():
120-
print(f"{color.CYAN}[+] hit breakpoint at 0x{self.cur_addr:08x}{color.END}")
125+
126+
if (bp := self.bp_list.pop(self.cur_addr, None)):
127+
if isinstance(bp, TempBreakpoint):
128+
self.del_breakpoint(bp)
129+
else:
130+
print(f"{color.CYAN}[+] hit breakpoint at 0x{self.cur_addr:08x}{color.END}")
131+
121132
self.do_context()
122133
break
134+
135+
self.ql.arch.step()
136+
self.ql.count -= 1
137+
123138
return
124139

125140
if self.ql.archtype in (QL_ARCH.ARM, QL_ARCH.ARM_THUMB, QL_ARCH.CORTEX_M) and is_thumb(self.ql.reg.cpsr):
@@ -224,7 +239,7 @@ def do_step(self: QlQdb, *args) -> Optional[bool]:
224239
self.ql.count -= 1
225240

226241
else:
227-
self._run(count=count)
242+
self._run(count=1)
228243

229244
self.do_context()
230245

@@ -254,9 +269,10 @@ def do_start(self: QlQdb, *args) -> None:
254269
restore qiling instance context to initial state
255270
"""
256271

257-
self.ql.restore(self._init_state)
272+
if self.ql.archtype != QL_ARCH.CORTEX_M:
258273

259-
self.do_context()
274+
self.ql.restore(self._init_state)
275+
self.do_context()
260276

261277
@parse_int
262278
def do_breakpoint(self: QlQdb, address: Optional[int] = 0) -> None:

0 commit comments

Comments
 (0)