-
Notifications
You must be signed in to change notification settings - Fork 239
--threads -t crash: Failed to PTRACE_GETREGS: No such process #93
Comments
Attaching after the launch also works
|
Thanks for the report, I tried running your test case and I can reproduce the problem. Adding @jamespic who contributed the threading code and might have an idea. The threading code is tricky because when I'll spend some time thinking about the issue and try to make some time to dig into this problem later this week. In the mean time, if you are able to get a core dump or stack trace of the Python process when it crashes that would be helpful. The |
One way that this could be fixed would be to disassemble PyInterpreterState *
PyInterpreterState_Head(void)
{
return interp_head;
} This is trivially compiled to a
The math is pretty simple. The function starts with a If a future version of Python changed the implementation the assumption that this could be disassembled this way would break, but it looks like they haven't changed this code since at least 2.7 if not earlier. You can also access this data via DWARF, which is more portable/correct, but probably trickier to use. Using DWARF would also require having debug symbols available which isn't that big a deal but something to think about. |
I did consider using the disassembly method, but the project I'm using PyFlame on compiles their own Python executable with some weird compiler flags, that mean the disassembly for that function is different (the assembly you posted looks like PIC, so you'd get different assembly on statically addressed builds). One option I did ponder, is that since that function is pure, it could be copied into PyFlame's address space, and executed there. At the time that seemed harder, but a couple of workarounds later, I'm not so sure. I'll try and reproduce this issue when I get chance. My best guess is that it's related to the cleanup code - when PyFlame exits, it cleans up the extra chunk of memory that it mmaped into the profiled process's address space, and maybe that's failing if the process has already terminated. |
Here's a proof of concept of how you would do this with disassembly: c9165de I'm using Capstone, but the code is simple enough that the x86 decoding logic could be hard coded. Capstone is a bit more "portable" in the sense that it can also decode ARM etc., but this code is extremely implementation dependent so I'm not sure if that's a real win. You could handle static/PIC cases this way, since Capstone knows how to decode all of the different ways of accessing memory, although it might end up becoming a bit of a mess. This code seems to crash eventually as well and it has some other problems, but it shows the general idea of how the approach would work. It would be nice to know why the current calling code fails though, because that might end up being simpler once all of the corner cases are added for disassembly. |
This is actually way simpler than I thought -- the code path for cleaning up when |
* fix a bug (#93) in PtraceDetach when threads are enabled
I've tagged v1.5.1 which fixes this. |
Thanks! Works much better now - still sometimes crashes very early:
and ubuntu crash reporter showing sigsegv in python pyflametest.py |
* origin/master: (42 commits) refactor the main probe loop (uber-archive#108) be less aggressive about probing for libpython in attach mode (uber-archive#107) add version string to -h output Switch to PTRACE_TRACEME to fix startup race conditions. (uber-archive#106) tag v1.5.2 fix a bug with venv deactivation in runtests.sh (uber-archive#105) augment version string (uber-archive#103) remove pointless build note (uber-archive#101) Switch to -p to specify the process to trace, fixes uber-archive#99 (uber-archive#100) explain how --abi works relase v1.5.1, which fixes uber-archive#93 convert the man page to pandoc, fixes uber-archive#97 Fix a bug in PtraceDetach when threads are enabled (uber-archive#94) detect when test suite is run from within a virtualenv (uber-archive#95) remove an unneeded skipif and yapf the tests tag 1.5.0 release use skipif here as well Unicode support (uber-archive#92) Various autoconf improvements. move all Python.h checks to configure.ac ...
@fillest Probably the same issue as #114 . My (unconfirmed) theory on that one is that it's getting wait events from grandchild processes, which is confusing Pyflame. I should have some time to look at this soon (next week or so). If you are able to reproduce this issue reliably though, that would be great, just in case they are different. |
@fillest Would you mind testing against master (specifically, d1942a5 or later, also tagged as v1.5.5)? I fixed #114 in that change, and am interested to know if it fixes your issue or not. Since you are getting a segfault I don't think my change will fix your crash, but it would help to know if you are still seeing crashes. And of course, anything you can do to repro an issue would be great. |
The text was updated successfully, but these errors were encountered: