10 "Debug Breakpoint parent class"
16 "Stand for software breakpoint"
22 return "Soft BP @0x%08x" % self.
addr
26 "Stand for an execution termination"
32 return "Terminate with %s" % self.
status
37 "Stand for memory breakpoint"
39 type2str = {csts.BREAKPOINT_READ:
"R",
40 csts.BREAKPOINT_WRITE: "W"}
49 for k, v
in self.type2str.items():
52 return "Memory BP @0x%08x, Size 0x%08x, Type %s" % (self.
addr,
59 for k, v
in cls.type2str.items():
60 if v ==
"R" and read is True:
62 if v ==
"W" and write
is True:
69 "Debugguer linked with a Jitter instance"
72 "myjit : jitter instance"
79 self.myjit.init_run(addr)
86 self.bp_list.append(bp)
87 self.myjit.add_breakpoint(addr, func)
90 "Set exception handler on EXCEPT_BREAKPOINT_INTERN"
91 raise NotImplementedError(
"Not implemented")
94 "add mem bp @[addr, addr + size], on read/write/both"
95 access_type = DebugBreakpointMemory.get_access_type(read=read,
98 self.hw_bp_list.append(dbm)
99 self.myjit.vm.add_memory_breakpoint(addr, size, access_type)
102 "remove the DebugBreakpointSoft instance"
103 self.bp_list.remove(dbs)
104 self.myjit.remove_breakpoints_by_callback(dbs.func)
107 "remove breakpoints @ addr"
112 "remove the DebugBreakpointMemory instance"
113 self.hw_bp_list.remove(dbm)
114 self.myjit.vm.remove_memory_breakpoint(dbm.addr, dbm.access_type)
118 "remove breakpoints @ addr"
119 access_type = DebugBreakpointMemory.get_access_type(read=read,
122 if bp.addr == addr
and bp.access_type == access_type:
128 if dbgsoft.addr == addr:
137 self.myjit.jit.log_mn = mn
139 self.myjit.jit.log_regs = regs
140 if newbloc
is not None:
141 self.myjit.jit.log_newbloc = newbloc
148 if isinstance(res, DebugBreakpointSoft):
149 print "Breakpoint reached @0x%08x" % res.addr
150 elif isinstance(res, ExceptionHandle):
151 if res == ExceptionHandle.memoryBreakpoint():
152 print "Memory breakpoint reached!"
155 except_flag = self.myjit.vm.get_exception()
156 self.myjit.vm.set_exception(except_flag ^ res.except_flag)
159 raise NotImplementedError(
"Unknown Except")
161 raise NotImplementedError(
"type res")
169 self.myjit.jit.set_options(jit_maxline=1)
170 self.myjit.jit.addr_mod =
interval([(self.myjit.pc, self.myjit.pc)])
171 self.myjit.jit.updt_automod_code(self.myjit.vm)
173 res = self.myjit.continue_run(step=
True)
176 self.myjit.jit.set_options(jit_maxline=50)
182 status = self.myjit.continue_run()
186 "hexdump @addr, size"
188 hexdump(self.myjit.vm.get_mem(addr, size))
191 "hexdump @addr, size"
192 return self.myjit.vm.get_mem(addr, size)
195 self.mem_watched.append((addr, size))
199 print "@0x%08x:" % addr
203 return getattr(self.myjit.cpu, reg_name)
208 if reg_name == self.myjit.ir_arch.pc.name:
211 setattr(self.myjit.cpu, reg_name, value)
214 "Return general purposes registers"
215 return self.myjit.cpu.get_gpreg()
220 "CommandLineInterpreter for Debugguer instance"
227 intro = color_g +
"=== Miasm2 Debugging shell ===\nIf you need help, "
228 intro +=
"type 'help' or '?'" + color_e
229 prompt = color_b +
"$> " + color_e
239 bp_list = self.dbg.bp_list
240 if len(bp_list) == 0:
241 print "No breakpoints."
243 for i, b
in enumerate(bp_list):
244 print "%d\t0x%08x" % (i, b.addr)
247 watch_list = self.dbg.mem_watched
248 if len(watch_list) == 0:
249 print "No memory watchpoints."
251 print "Num\tAddress \tSize"
252 for i, w
in enumerate(watch_list):
254 print "%d\t0x%08x\t0x%08x" % (i, addr, size)
257 regs = self.dbg.get_gpreg_all()
262 max_name_len = max(map(len, regs.keys() + [title1]))
266 title1,
" " * (max_name_len - len(title1)), title2)
269 for name, value
in sorted(regs.items(), key=
lambda x: x[0]):
270 print "%s%s | %s" % (name,
271 " " * (max_name_len - len(name)),
272 hex(value).replace(
"L",
""))
279 for i, dbg_obj
in enumerate(self.dbg.bp_list):
280 if dbg_obj.addr == addr:
284 print "Breakpoint 0x%08x already set (%d)" % (addr, i)
286 l = len(self.dbg.bp_list)
287 self.dbg.add_breakpoint(addr)
288 print "Breakpoint 0x%08x successfully added ! (%d)" % (addr, l)
290 display_mode = {
"mn":
None,
296 "regs": self.dbg.myjit.jit.log_regs,
297 "newbloc": self.dbg.myjit.jit.log_newbloc}
304 cmd_translate = {
"h":
"help",
314 if len(line) >= 2
and \
316 line[:1]
in cmd_translate:
317 line = cmd_translate[line[:1]] + line[1:]
319 if len(line) == 1
and line
in cmd_translate:
320 line = cmd_translate[line]
322 r = super(DebugCmd, self).
onecmd(line)
333 args = arg.split(
" ")
334 if args[-1].lower()
not in [
"on",
"off"]:
337 mode = args[-1].lower() ==
"on"
341 self.dbg.active_trace(**d)
345 print "Enable/Disable tracing."
346 print "Usage: display <mode1> <mode2> ... on|off"
347 print "Available modes are:"
350 print "Use 'info display' to get current values"
357 args = arg.split(
" ")
359 size = int(args[1], 0)
363 addr = int(args[0], 0)
365 self.dbg.watch_mem(addr, size)
368 print "Add a memory watcher."
369 print "Usage: watchmem <addr> [size]"
370 print "Use 'info watchmem' to get current memory watchers"
373 av_info = [
"registers",
379 print "'info' must be followed by the name of an info command."
380 print "List of info subcommands:"
384 if arg.startswith(
"b"):
388 if arg.startswith(
"d"):
391 for k, v
in self.display_mode.items():
392 print "%s\t\t%s" % (k, v)
394 if arg.startswith(
"w"):
398 if arg.startswith(
"r"):
403 print "Generic command for showing things about the program being"
404 print "debugged. Use 'info' without arguments to get the list of"
405 print "available subcommands."
411 addrs = arg.split(
" ")
415 print "Add breakpoints to argument addresses."
417 print "\tbreakpoint 0x11223344"
418 print "\tbreakpoint 1122 0xabcd"
429 print "Step program until it reaches a different source line."
430 print "Argument N means do this N times (or till program stops"
431 print "for another reason)."
437 args = arg.split(
" ")
439 size = int(args[1], 0)
442 addr = int(args[0], 0)
444 self.dbg.get_mem(addr, size)
447 print "Dump <addr> [size]. Dump size bytes at addr."
453 print "Launch or continue the current program"
461 except Exception, error:
462 print "*** Error: %s" % error
465 print "Exec a python command."
466 print "You can also use '!' shortcut."
469 print "Exit the interpreter."
470 print "You can also use the Ctrl-D shortcut."
def remove_breakpoint_by_addr
def get_breakpoint_by_addr
def remove_memory_breakpoint_by_addr_access
def init_memory_breakpoint
def add_memory_breakpoint
def remove_memory_breakpoint