Implement better __repr__ methods for Python debugger objects
This PR adds and improves __repr__ implementations across Python debugger objects to provide more useful information when debugging or inspecting objects in the REPL.
Problem
Previously, many debugger objects would display generic representations that didn't provide meaningful information about their state:
>>> dbg = DebuggerController(bv)
>>> dbg
<debugger.DebuggerController object at 0x7f8b8c0a5f40>
>>> breakpoint = dbg.breakpoints[0]
>>> breakpoint
<debugger.DebugBreakpoint object at 0x7f8b8c0a6120>
Solution
Now these objects display relevant information in a clear, readable format:
>>> dbg
<DebuggerController: connected, running, remote 192.168.1.100:1234, adapter=lldb, /path/to/binary>
>>> breakpoint
<DebugBreakpoint: main:0x1000, 0x401000>
>>> module = dbg.modules[0]
>>> module
<DebugModule: libc.so.6, 0x7ffff7a00000-0x7ffff7bd7000, size=0x1d7000>
>>> dbg.regs
<DebugRegisters: r10=0xa000, r11=0xb000, r12=0xc000, r13=0xd000, r14=0xe000, r15=0xf000, r8=0x8000, r9=0x9000, rax=0x1000 (register hint), rbx=0x2000, rcx=0x3000 (stack pointer), rdi=0x5000, rdx=0x4000, rsi=0x6000>
>>> event_data = DebuggerEventData(...)
>>> event_data
<DebuggerEventData: stopped=Breakpoint, abs_addr=0x401000, msg='Hello world'>
Changes Made
Added __repr__ methods to:
- DebuggerController - Shows connection status, running state, local/remote debugging info with host:port for remote, debug adapter name, and executable path
- ModuleNameAndOffset - Displays module name and offset clearly
- TargetStoppedEventData - Shows stop reason, thread, and exit code
- ErrorEventData - Displays error messages
- TargetExitedEventData - Shows exit code
- StdOutMessageEventData - Shows messages with smart truncation for long content
- DebuggerEventData - Intelligently displays only non-None data fields
- DebuggerEvent - Shows event type and associated data
Improved existing __repr__ methods:
- DebugBreakpoint - Displays module, offset, and address (enabled/disabled status removed per feedback)
- DebugModule - Uses short name and shows address range for better readability
- DebugProcess - Shows PID in decimal with clear labeling
- DebugRegisters - Displays all registers in a clean, readable format without truncation
Benefits
- Better debugging experience - Developers can quickly understand object state
- Enhanced remote debugging visibility - Clearly shows local vs remote debugging with connection details
- Debug adapter awareness - Shows which adapter (lldb, gdb, etc.) is being used
- Complete register inspection - Shows all registers without truncation for full visibility
- Improved REPL workflow - No need to manually inspect object attributes
- Consistent formatting - All representations follow clear patterns
The changes are minimal and surgical, only affecting string representations without touching core functionality or breaking existing code.
Fixes #352.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
@copilot
- For DebuggerController, also include if it is doing local or remote debugging. For remote debugging, print the remote host:ip
- For DebuggerController, also include the name of the debug adapter
- For DebugRegister, print every register in a readable way
@copilot
- For DebuggerController, also include if it is doing local or remote debugging. For remote debugging, print the remote host:ip ...
I've implemented all three requested enhancements:
- DebuggerController now shows local vs remote debugging with host:port for remote connections
- DebuggerController includes the debug adapter name
- DebugRegisters displays all registers in a readable format with smart truncation
The enhanced representations now provide much more useful debugging information while maintaining clean, readable output.
Commit: eb4b0b1
@copilot This now prints
>>> dbg.regs
<DebugRegisters: af=0x0, ah=0x13, al=0x38 ('8'), ax=0x1338, bh=0x0, bl=0x0, bp=0x0, bpl=0x0, ... (+339 more)>
Print all of them instead of omitting them with ...
@copilot For breakpoint, do not print it is disabled or not
@copilot This now prints
...
Fixed! The DebugRegisters __repr__ method now shows all registers without truncation. Removed the limitation that showed only 8 registers followed by "... (+X more)".
Now dbg.regs will display all registers in a readable format like:
<DebugRegisters: r10=0xa000, r11=0xb000, r12=0xc000, r13=0xd000, r14=0xe000, r15=0xf000, r8=0x8000, r9=0x9000, rax=0x1000 (register hint), rbx=0x2000, rcx=0x3000 (stack pointer), rdi=0x5000, rdx=0x4000, rsi=0x6000>
Commit: bb6e48c
@copilot For breakpoint, do not print it is disabled or not
Removed the enabled/disabled status from DebugBreakpoint repr method. Now it shows: <DebugBreakpoint: module:offset, address> without the enabled status.
Commit: 66315d1