Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Thread-scoped control flow and events #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 50 commits into
base: dev
Choose a base branch
from
Draft

Conversation

io-no
Copy link
Member

@io-no io-no commented Nov 3, 2024

This is the first PR that attempts to shift some functionalities of libdebug from a process-scoped to a thread-scoped basis.

I encourage a logical code review, even if it is a draft, to confirm the direction and APIs. I tried to adhere to what we decided together weeks ago, but I had to make some additional decisions.

All the limitations listed below are documented precisely in the code with some TODOs and, where necessary, with warnings for the users.

Why a draft?

  • There are still some race conditions in certain multithreaded cases (hence, do not expect the CI to pass).
  • The code can be cleaned up and better organized.
  • There are a LOT of tests to be done.

What this PR includes

  • The control flow operations (continue, finish, next, step, step_until, wait) are now process-scoped when called on the Debugger object and thread-scoped when called on a ThreadContext.
  • Defined events (e.g., breakpoints, syscall handlers, signal catchers, ...) can now be set as valid only for a thread. This is a very early version of this feature (see limitations below).
  • We now have an InternalThreadContext to hide and manage part of the new complexity introduced. It will be better employed when I address the limitations mentioned above.

What about limitations?

  • You can call a control flow function on a single specific thread or on the entire process, but nothing in between.
  • Some control flow functions like next and finish are still blocking. I have not changed them to better isolate some race conditions introduced by the new features.
  • I still need to implement the equivalent of ensure_process_stopped for a thread to allow access to thread-safe resources when a single thread is stopped but others are running. This is also useful for the first point.
  • The running, scheduled, ... flags can be better managed, as can the status flags of the debugger.
  • When you handle an event on a thread, you cannot handle the same event on another thread. This is related to the libdebug limitation of one object per event. I will address this with a dedicated PR that will involve a change in how we define events.
  • The pretty print of the syscall is not compatible with the thread-scoped handling of a syscall. This issue is related to the previous point.

Why did I not solve these limitations?

Because they are part of other changes that we want to apply to libdebug, which we have not yet implemented. I wanted to avoid adding layers of poor code to circumvent the problems. Also, it is already quite a large PR.

io-no added 30 commits October 28, 2024 00:07
@io-no io-no requested a review from Frank01001 November 3, 2024 23:49
@io-no io-no added the enhancement New feature or request label Nov 3, 2024
Copy link
Member

@Frank01001 Frank01001 left a comment

Choose a reason for hiding this comment

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

As far as what is implemented up to this point, it seems ok.

Base automatically changed from nanobind-conversion-2 to dev February 5, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants