Skip to content

Refactor qdb - #1549

Merged
xwings merged 20 commits into
qilingframework:devfrom
elicn:refactor-qdb
Apr 12, 2025
Merged

xwings merged 20 commits into
qilingframework:devfrom
elicn:refactor-qdb

Conversation

@elicn

@elicn elicn commented Mar 19, 2025 •

Copy link
Copy Markdown
Member

qdb refactored from ground up, overall improving feature stability, reliability and maintainability.
Note: some debug prints are still present; waiting for feedback.

Highlights:

  • Misc cosmetic improvements
  • Revised classes and mixin hierarchy to be more intuitive
  • Consolidated and de-duplicated common functionality
  • Heavily commented and documented the code, in addition to annotations
  • Branch prediction greatly improved
    • Assembly analysis now based on Capstone objects rather than unreliable string parsing
    • More corner cases are now covered
    • Prediction target got more accurate
  • Going backwards greatly improved
    • Now also reverting memory layout in addition to memory contents
    • Snapshot memory footprint has been reduced
  • qdb commands can now evaluate compound expressions, e.g. x/8i ($pc + $sp + (4 * $r1))
  • Rewrote all tests to reflect meaningful scenarios
  • Bug fixes

TODO:

  • Redesign classes hierarchy
  • Improve snapshots by covering more operating system resources, such as file descriptors, etc.
  • Make existing commands more resemble to their gdb equivalents
  • Support more commands

Screenshot 1: context dump, predicting branch taken upwards
image

Screenshot 2: examine command taking an expression as its argument
image

@elicn
elicn requested a review from ucgJhe March 19, 2025 17:07
@elicn
elicn marked this pull request as ready for review March 26, 2025 18:32
@elicn

elicn commented Mar 26, 2025

Copy link
Copy Markdown
Member Author

@ucgJhe, would appreciate your feedback.
Once you approve, we can move on to other's reviews.

@ucgJhe ucgJhe left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are all my reviews so far. As for the capstone engine issue, not quite sure anything will be broken if we upgrade it. Everything is fine after I upgraded my local version to capstone==5.0.5, and run tests/test_onlinux.sh.

I also pushed my solutions here: https://github.com/ucgJhe/qiling/tree/refactor-qdb

Comment thread qiling/debugger/qdb/qdb.py Resolved
Comment thread qiling/debugger/qdb/qdb.py Resolved
Comment thread qiling/debugger/qdb/render/render.py Resolved
brmark = f'{color.RED}{bmark}{color.RESET}'

trace_line = f"0x{insn.address:08x} │ {opcode:15s} {insn.mnemonic:10} {insn.op_str:35s}"
# <DEBUG>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe only show this messages when QL_VERBOSE is DEBUG ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the target indication quite informative actually.
Maybe change the message format to be more elegant?

@ucgJhe ucgJhe Mar 31, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's a good idea

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll figure something out.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also another DEBUG message in render.py. Do you think thats also nessassary ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snapshot diff prints removed.

@ucgJhe ucgJhe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me once it's fixed

Comment thread qiling/debugger/qdb/utils.py Resolved
@elicn

elicn commented Mar 31, 2025

Copy link
Copy Markdown
Member Author

Enabled show sub-commands as follows:

  • show args [num] : Show function call arguments
  • show mem [filter] : Dump memory map
  • show breakpoints : List all breakpoints
  • show marks : List marked symbols
  • show snapshot : Show diff of last snapshot
  • show entry : Show program entry point(s)

@xwings

xwings commented Apr 1, 2025

Copy link
Copy Markdown
Member

@elicn you approval is needed.

@elicn

elicn commented Apr 1, 2025

Copy link
Copy Markdown
Member Author

@elicn you approval is needed.

Once we get @ucgJhe's green light, we can merge.

@ucgJhe

ucgJhe commented Apr 1, 2025

Copy link
Copy Markdown
Collaborator

@elicn you approval is needed.

Once we get @ucgJhe's green light, we can merge.

I was thinking about change command show to something like info but I guess the sub-command stuff is also okay

@elicn

elicn commented Apr 1, 2025

Copy link
Copy Markdown
Member Author

I was thinking about change command show to something like info but I guess the sub-command stuff is also okay

Yes, I was thinking about renaming show to info to make it more gdb-like, but I thought you'd want to preserve your original naming. If that is what you meant, it is an easy change.

@ucgJhe

ucgJhe commented Apr 1, 2025

Copy link
Copy Markdown
Collaborator

I was thinking about change command show to something like info but I guess the sub-command stuff is also okay

Yes, I was thinking about renaming show to info to make it more gdb-like, but I thought you'd want to preserve your original naming. If that is what you meant, it is an easy change.

yes, rename to info will be better

@elicn

elicn commented Apr 2, 2025

Copy link
Copy Markdown
Member Author

@xwings, we can merge now.

@xwings
xwings merged commit f4464b9 into qilingframework:dev Apr 12, 2025
@elicn
elicn deleted the refactor-qdb branch April 14, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants