Skip to content
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

os: fix debugger_present() for non Windows OSes #21573

Merged
merged 3 commits into from
May 25, 2024

Conversation

bstnbuck
Copy link
Contributor

So far the debugger_present() function only works partially. All Unix-based systems use the same procedure. C.ptrace() is used to check whether the process can “debug” itself. If this is the case, no debugger is present, but ptrace is now used as such. If it is called again, the function immediately returns that a debugger is present. However, the appropriate “detach” function cannot be used if the process “follows” itself.

Current behaviour on non Windows systems:

fn main(){
  if os.debugger_present(){
    println("debugger here")
  }else{
    println("no debugger")
  }

  println("###between os.debugger_present()###")

  if os.debugger_present(){
    println("debugger here")
  }else{
    println("no debugger")
  }
}

Output:

no debugger
###between os.debugger_present()###
debugger here   <<< this should also be "no debugger"

A child process must therefore be created to do this. After checking, it is killed again. The resulting return value is checked and returned.

Other procedures are dependent on compatible kernels and are not always functional. Windows has its own APIs and already works without problems.

Relevant literature:

The previous implementation only works correctly once on the first call. From then on, the process debugs itself, which not only falsifies all further calls, but also reduces performance. A child process achieves the same thing, except that it detaches itself again and allows further checks in the future.
@spytheman spytheman merged commit b4c560d into vlang:master May 25, 2024
63 checks passed
@bstnbuck bstnbuck deleted the fix_debugger_present_!win branch May 25, 2024 22:32
spytheman added a commit to felipensp/v that referenced this pull request May 27, 2024
* master:
  cgen: fix array fixed initialization on struct from call (vlang#21568)
  testing: implement a separate `-show-asserts` option, for cleaner test output (`-stats` still works, and still shows both the compilation stats and the asserts) (vlang#21578)
  toml: fix `@[toml: ]`, support `@[skip]` (vlang#21571)
  os: fix debugger_present() for non Windows OSes (vlang#21573)
  builtin: simplify splint_nth methods (vlang#21563)
  net.http: change default http.Server listening address to :9009, to avoid conflicts with tools, that start their own http servers on 8080 like bytehound (vlang#21570)
  os: make minior improvement to C function semantics and related code (vlang#21565)
  io: cleanup prefix_and_suffix/1 util function (vlang#21562)
  os: remove mut declarions for unchanged vars in `os_nix.c.v` (vlang#21564)
  builtin: reduce allocations in s.index_kmp/1 and s.replace/2 (vlang#21561)
  ci: shorten path used for unix domain socket tests (to fit in Windows path limits)
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.

None yet

2 participants