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

lldb can't continue on NilAccessError, stuck after EXC_BAD_ACCESS #9753

Closed
timotheecour opened this issue Nov 19, 2018 · 9 comments
Closed

Comments

@timotheecour
Copy link
Member

nim c --debugger:native bugs/lldb/t01.nim
lldb bugs/lldb/t01

import segfaults

proc main =
  try:
    var x: ptr int
    echo x[]
  except NilAccessError:
    echo "caught a crash!"

echo "ok1"
main()
echo "ok2"
(lldb) r
Process 54064 launched: '/tmp/nim/app' (x86_64)
ok1
Process 54064 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00000001000112df app main_uF9bc3kVsWoixdO2cWVyMwg + 239 at /Users/timothee/git_clone/nim/timn/bugs/lldb/t01.nim:6
   3    proc main =
   4      try:
   5        var x: ptr int
-> 6        echo x[]
   7      except NilAccessError:
   8        echo "caught a crash!"
   9
Target 0: (app) stopped.
(lldb) c
Process 54064 resuming
Process 54064 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00000001000112df app main_uF9bc3kVsWoixdO2cWVyMwg + 239 at /Users/timothee/git_clone/nim/timn/bugs/lldb/t01.nim:6
   3    proc main =
   4      try:
   5        var x: ptr int
-> 6        echo x[]
   7      except NilAccessError:
   8        echo "caught a crash!"
   9
Target 0: (app) stopped.

note

I'm on OSX (mojave)
can't test on gdb because of https://stackoverflow.com/questions/52529838/gdb-8-2-cant-recognized-executable-file-on-macos-mojave-10-14 as mentioned here #9634

@alaviss
Copy link
Collaborator

alaviss commented Nov 19, 2018

If it only stuck there when lldb is concerned, then isn't it lldb's bug and not Nim's?

@timotheecour
Copy link
Member Author

not necessarily, see #9634 (comment) for another case where c++ code works but not nim code, with lldb;
for this issue, I haven't investigated c++ case

@alaviss
Copy link
Collaborator

alaviss commented Nov 19, 2018

I still don't see why this is a Nim bug. It's the compiler job to generate code that works correctly natively. The fact that it doesn't work on LLDB is an LLDB bug. You can't compare with C++ because of the differences between implementation of underlying functions and exceptions. I think you should raise this to the LLVM bug tracker. I'm certain that LLDB developers would be interested in it.

@timotheecour
Copy link
Member Author

just tried on ubuntu: lldb and gdb work fine ; so it's either an OSX problem or lldb on OSX problem;
unfortunately I can't try gdb on OSX because I'm on mojave and https://stackoverflow.com/questions/52529838/gdb-8-2-cant-recognized-executable-file-on-macos-mojave-10-14

can someone who's on an older version of OSX please try ?

@timotheecour
Copy link
Member Author

update: I tried using same technique as in #9634 (comment) ; result:

  • on OSX high sierra, 10.13.6, lldb has same issue; gdb works
  • on OSX mojave, lldb has the issue; gdb works

conclusion: this time, it's an lldb issue, unlike #9634

@timotheecour
Copy link
Member Author

update:
this could be root cause: https://stackoverflow.com/questions/26829119/how-to-make-lldb-ignore-exc-bad-access-exception
also related: https://bugs.llvm.org/show_bug.cgi?id=22868

lldb always stops on EXC_BAD_ACCESS and will not continue. The result is SIGSEGV cannot be passed. That is, this does not work:
process handle SIGSEGV --stop false --pass true --notify false
Programs that expect to continue processing by turning SIGSEGV into an exception cannot be run under lldb. In particular this affects the Go programming language:

there are embryos of solutions here: https://stackoverflow.com/questions/26829119/how-to-make-lldb-ignore-exc-bad-access-exception

@Araq
Copy link
Member

Araq commented Dec 4, 2018

Try to compile with -d:noSignalHandler.

@timotheecour
Copy link
Member Author

timotheecour commented Dec 4, 2018

just did, same issue; I'm pretty sure the culprit lies in #9753 (comment)
unfortunately, gdb is really in bad state on OSX (see Homebrew/homebrew-core#34750

If upstream refuses to fix macOS versions and nobody submits fixes to it, it might be better to pull gdb from homebrew completely and leave the patching to a tap. From homebrews perspective, fixing software and releasing that fixed software is up to upstream, debian openssl maintainers can probably tell you what a bad idea it is to leave patches to the packagers.

so arguments like "only gdb is supported" by Nim doesn't really help if you're on OSX; my hope is stuff like https://stackoverflow.com/questions/26829119/how-to-make-lldb-ignore-exc-bad-access-exception is fixable (even if requiring locally patched lldb) and lldb should be worthy of keeping as a supported option (it really mostly works apart from that, and has more modern codebase, more traction / features compared to gdb IIUC)

@timotheecour timotheecour changed the title lldb can't continue on NilAccessError lldb can't continue on NilAccessError, stuck after EXC_BAD_ACCESS Dec 4, 2018
@timotheecour
Copy link
Member Author

filed https://bugs.llvm.org/show_bug.cgi?id=40669, following up there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants