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] attach failed,(Not allowed to attach to process.) #52829

Closed
Mervyen opened this issue Dec 22, 2021 · 7 comments
Closed

[LLDB] attach failed,(Not allowed to attach to process.) #52829

Mervyen opened this issue Dec 22, 2021 · 7 comments
Labels

Comments

@Mervyen
Copy link

Mervyen commented Dec 22, 2021

M1chip macOS 11.6

~ » lldb --version
lldb-1300.0.32.2
Swift version 5.5-dev

when I debug a jni project, I want to attach to this jni process.
·use jps to get the java pid.
·lldb attach to this pid, and then I got this error.

~ » sudo lldb
Password:
(lldb) attach 54994
error: attach failed: attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)
(lldb) quit

I also get the lldb log from clion
(clion use the system default lldb. I get the same error both in clion and terminal using lldb)

Processing command: type summary add --skip-pointers --summary-string "${var%d} ${var}" --category cplusplus "char" "signed char"
HandleCommand, cmd_obj : 'type summary add'
HandleCommand, (revised) command_string: 'type summary add --skip-pointers --summary-string "${var%d} ${var}" --category cplusplus "char" "signed char"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '--skip-pointers --summary-string "${var%d} ${var}" --category cplusplus "char" "signed char"'
HandleCommand, command succeeded
Processing command: type summary add --skip-pointers --summary-string "${var%u} ${var}" --category cplusplus "unsigned char"
HandleCommand, cmd_obj : 'type summary add'
HandleCommand, (revised) command_string: 'type summary add --skip-pointers --summary-string "${var%u} ${var}" --category cplusplus "unsigned char"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '--skip-pointers --summary-string "${var%u} ${var}" --category cplusplus "unsigned char"'
HandleCommand, command succeeded
Processing command: type category enable objc
HandleCommand, cmd_obj : 'type category enable'
HandleCommand, (revised) command_string: 'type category enable objc'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): 'objc'
HandleCommand, command succeeded
Processing command: script import lldb_formatters.jetbrains_stl_formatters
HandleCommand, cmd_obj : 'script'
HandleCommand, (revised) command_string: 'script import lldb_formatters.jetbrains_stl_formatters'
HandleCommand, wants_raw_input:'True'
HandleCommand, command line after removing command name(s): 'import lldb_formatters.jetbrains_stl_formatters'
thread created
Processing command: script import lldb_formatters.jetbrains_stl_formatters
HandleCommand, cmd_obj : 'script'
HandleCommand, (revised) command_string: 'script import lldb_formatters.jetbrains_stl_formatters'
HandleCommand, wants_raw_input:'True'
HandleCommand, command line after removing command name(s): 'import lldb_formatters.jetbrains_stl_formatters'
thread created
HandleCommand, command succeeded
Processing command: type synthetic add -l lldb_formatters.jetbrains_stl_formatters.StdDequeSynthProvider -x "^std::deque<.+> >(( )?&)?$"
HandleCommand, cmd_obj : 'type synthetic add'
HandleCommand, (revised) command_string: 'type synthetic add -l lldb_formatters.jetbrains_stl_formatters.StdDequeSynthProvider -x "^std::deque<.+> >(( )?&)?$"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-l lldb_formatters.jetbrains_stl_formatters.StdDequeSynthProvider -x "^std::deque<.+> >(( )?&)?$"'
HandleCommand, command succeeded
Processing command: type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::deque<.+> >(( )?&)?$"
HandleCommand, cmd_obj : 'type summary add'
HandleCommand, (revised) command_string: 'type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::deque<.+> >(( )?&)?$"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::deque<.+> >(( )?&)?$"'
HandleCommand, command succeeded
Processing command: type synthetic add -l lldb_formatters.jetbrains_stl_formatters.StdHashtableSynthProvider -x "^(std::tr1::)unordered_set<.+>."
HandleCommand, cmd_obj : 'type synthetic add'
HandleCommand, (revised) command_string: 'type synthetic add -l lldb_formatters.jetbrains_stl_formatters.StdHashtableSynthProvider -x "^(std::tr1::)unordered_set<.+>.
"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-l lldb_formatters.jetbrains_stl_formatters.StdHashtableSynthProvider -x "^(std::tr1::)unordered_set<.+>."'
HandleCommand, command succeeded
Processing command: type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^(std::tr1::)unordered_set<.+>.
"
HandleCommand, cmd_obj : 'type summary add'
HandleCommand, (revised) command_string: 'type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^(std::tr1::)unordered_set<.+>."'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^(std::tr1::)unordered_set<.+>.
"'
HandleCommand, command succeeded
Processing command: type synthetic add -l lldb_formatters.jetbrains_stl_formatters.StdHashtableSynthProvider -x "^(std::tr1::)unordered_map<.+>."
HandleCommand, cmd_obj : 'type synthetic add'
HandleCommand, (revised) command_string: 'type synthetic add -l lldb_formatters.jetbrains_stl_formatters.StdHashtableSynthProvider -x "^(std::tr1::)unordered_map<.+>.
"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-l lldb_formatters.jetbrains_stl_formatters.StdHashtableSynthProvider -x "^(std::tr1::)unordered_map<.+>."'
HandleCommand, command succeeded
Processing command: type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^(std::tr1::)unordered_map<.+>.
"
HandleCommand, cmd_obj : 'type summary add'
HandleCommand, (revised) command_string: 'type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^(std::tr1::)unordered_map<.+>."'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^(std::tr1::)unordered_map<.+>.
"'
HandleCommand, command succeeded
Processing command: type synthetic add -l lldb.formatters.cpp.gnu_libstdcpp.StdMapSynthProvider -x "^std::multimap<.+> >(( )?&)?$"
HandleCommand, cmd_obj : 'type synthetic add'
HandleCommand, (revised) command_string: 'type synthetic add -l lldb.formatters.cpp.gnu_libstdcpp.StdMapSynthProvider -x "^std::multimap<.+> >(( )?&)?$"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-l lldb.formatters.cpp.gnu_libstdcpp.StdMapSynthProvider -x "^std::multimap<.+> >(( )?&)?$"'
HandleCommand, command succeeded
Processing command: type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::multimap<.+> >(( )?&)?$"
HandleCommand, cmd_obj : 'type summary add'
HandleCommand, (revised) command_string: 'type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::multimap<.+> >(( )?&)?$"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::multimap<.+> >(( )?&)?$"'
HandleCommand, command succeeded
Processing command: type synthetic add -l lldb_formatters.jetbrains_stl_formatters.StdSetSynthProvider -x "^std::set<.+> >(( )?&)?$"
HandleCommand, cmd_obj : 'type synthetic add'
HandleCommand, (revised) command_string: 'type synthetic add -l lldb_formatters.jetbrains_stl_formatters.StdSetSynthProvider -x "^std::set<.+> >(( )?&)?$"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-l lldb_formatters.jetbrains_stl_formatters.StdSetSynthProvider -x "^std::set<.+> >(( )?&)?$"'
HandleCommand, command succeeded
Processing command: type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::set<.+> >(( )?&)?$"
HandleCommand, cmd_obj : 'type summary add'
HandleCommand, (revised) command_string: 'type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::set<.+> >(( )?&)?$"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::set<.+> >(( )?&)?$"'
HandleCommand, command succeeded
Processing command: type synthetic add -l lldb_formatters.jetbrains_stl_formatters.StdSetSynthProvider -x "^std::multiset<.+> >(( )?&)?$"
HandleCommand, cmd_obj : 'type synthetic add'
HandleCommand, (revised) command_string: 'type synthetic add -l lldb_formatters.jetbrains_stl_formatters.StdSetSynthProvider -x "^std::multiset<.+> >(( )?&)?$"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-l lldb_formatters.jetbrains_stl_formatters.StdSetSynthProvider -x "^std::multiset<.+> >(( )?&)?$"'
HandleCommand, command succeeded
Processing command: type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::multiset<.+> >(( )?&)?$"
HandleCommand, cmd_obj : 'type summary add'
HandleCommand, (revised) command_string: 'type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::multiset<.+> >(( )?&)?$"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^std::multiset<.+> >(( )?&)?$"'
HandleCommand, command succeeded
Processing command: type synthetic add -l lldb_formatters.jetbrains_stl_formatters.libcxx_hash_table_SynthProvider -x "^(std::_1::)unordered(multi)?(map|set)<.+> >$"
HandleCommand, cmd_obj : 'type synthetic add'
HandleCommand, (revised) command_string: 'type synthetic add -l lldb_formatters.jetbrains_stl_formatters.libcxx_hash_table_SynthProvider -x "^(std::_1::)unordered(multi)?(map|set)<.+> >$"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-l lldb_formatters.jetbrains_stl_formatters.libcxx_hash_table_SynthProvider -x "^(std::_1::)unordered(multi)?(map|set)<.+> >$"'
HandleCommand, command succeeded
Processing command: type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^(std::_1::)unordered(multi)?(map|set)<.+>."
HandleCommand, cmd_obj : 'type summary add'
HandleCommand, (revised) command_string: 'type summary add -F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^(std::_1::)unordered(multi)?(map|set)<.+>.
"'
HandleCommand, wants_raw_input:'False'
HandleCommand, command line after removing command name(s): '-F lldb_formatters.jetbrains_stl_formatters.SizeSummaryProvider -e -x "^(std::_1::)unordered(multi)?(map|set)<.+>.*"'
HandleCommand, command succeeded
HandleCommand, command succeeded
Processing command: settings set target.max-string-summary-length 256
HandleCommand, cmd_obj : 'settings set'
HandleCommand, (revised) command_string: 'settings set target.max-string-summary-length 256'
HandleCommand, wants_raw_input:'True'
HandleCommand, command line after removing command name(s): 'target.max-string-summary-length 256'
HandleCommand, command succeeded
Target::AddBreakpoint (internal = no) => break_id = 1: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/com_Mervyen_MyKeyBoard.cpp', line = 36, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 2: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/com_Mervyen_MyKeyBoard.cpp', line = 116, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 3: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/KeyBoard.h', line = 15, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 4: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/KeyBoard.cpp', line = 9, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 5: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/KeyBoard.cpp', line = 13, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 6: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/KeyBoard.cpp', line = 17, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 7: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/KeyBoard.cpp', line = 21, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 8: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/KeyBoard.cpp', line = 25, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 9: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/com_Mervyen_MyKeyBoard.cpp', line = 10, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 10: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/com_Mervyen_MyKeyBoard.cpp', line = 51, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 11: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/com_Mervyen_MyKeyBoard.cpp', line = 67, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 12: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/com_Mervyen_MyKeyBoard.cpp', line = 83, exact_match = 0
Target::AddBreakpoint (internal = no) => break_id = 13: file = '/Users/Downloads/ndkPack/MyKeyBoard/jni/com_Mervyen_MyKeyBoard.cpp', line = 99, exact_match = 0
Process::SetPublicState (state = attaching, restarted = 0)
Host::StartMonitoringChildProcess (callback, pid=55879, monitor_signals=0) source = 0x15b7162e0
thread created
Process::AttachCompletionHandler::AttachCompletionHandler process=0x15c8a5c18, exec_count=0
Process::ControlPrivateStateThread (signal = 4)
Sending control event of type: 4.
thread created
Process::RunPrivateStateThread (arg = 0x15c8a5c18, pid = 54994) thread starting...
timeout = , event_sp)...
Process::RunPrivateStateThread (arg = 0x15c8a5c18, pid = 54994) got a control event: 4
timeout =
timeout = , event_sp)...
timeout = , event_sp)...
Process::SetExitStatus (status=-1 (0xffffffff), description="attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)")
Process::SetPrivateState (exited)
Process::SetPrivateState (exited) stop_id = 1
Process::AttachCompletionHandler::PerformAction called with state exited (10)
Ran next event action, result was 2.
Process::ShouldBroadcastEvent (0x14b6509f0) => new state: exited, last broadcast state: exited - YES
Process::HandlePrivateEvent (pid = 54994) broadcasting new state exited (old state attaching) to hijacked
Process::RunPrivateStateThread (arg = 0x15c8a5c18, pid = 54994) about to exit with internal state exited...
Process::RunPrivateStateThread (arg = 0x15c8a5c18, pid = 54994) thread exiting...
Process::SetPublicState (state = exited, restarted = 0)
timeout = , event_sp) => exited
Process::SetExitStatus (status=6 (0x00000006), description="destroying when not connected to debugserver")
Process::SetExitStatus () ignoring exit status because state was already set to eStateExited
Process::ControlPrivateStateThread (signal = 1)
Sending control event of type: 1.
::waitpid (pid = 55879, &status, 0) => pid = 55879, status = 0x00000000 (EXITED), signal = 0, exit_status = 0
Process::SetExitStatus (status=6 (0x00000006), description="destroying when not connected to debugserver")
Process::SetExitStatus () ignoring exit status because state was already set to eStateExited
Went to stop the private state thread, but it was already invalid.
Target::DisableAllWatchpoints
Target::ClearAllWatchpointHitCounts
Target::ClearAllWatchpointHistoricValues
Went to stop the private state thread, but it was already invalid.

if you need more info,plz tell me.

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 15, 2022

@llvm/issue-subscribers-lldb

@JDevlieghere
Copy link
Member

Based on the version number, it sounds like this is an issue with the LLDB that ships with Xcode. Unless it also reproduces with the lldb from llvm.org, I recommend filing a bug report with Apple.

That said, the logs you pasted here are not the logs the error message is talking about. They are system logs that you can access through Console.app.

Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.

@jimingham
Copy link
Collaborator

Note, however, that on macOS you can only attach the debugger to programs that have specifically marked themselves as allowing debugging. Standard practice for most apps/executables is not to mark the release builds "debuggable". So this failure is actually expected behavior for something like a java you installed rather than hand-building.

As Jonas said, you can look in console for error messages, but most likely you are going to find that java was not built to allow debugging. You can also verify this by running:

codesign -d --entitlements --

if that doesn't include the get_task_allow entitlement, you won't be allowed to attach to it.

If you want to debug an app on macOS, you either have to disable SIP, or build a copy of the binary that opts into debugging (the debug builds of most projects will allow debugging...)

Anyway, lldb has no control over what it is and isn't allowed to attach to, that's a policy decision made by the OS, and quite deliberately placed outside the debugger's hands. So this isn't an lldb bug...

@Mervyen
Copy link
Author

Mervyen commented Feb 11, 2022

Note, however, that on macOS you can only attach the debugger to programs that have specifically marked themselves as allowing debugging. Standard practice for most apps/executables is not to mark the release builds "debuggable". So this failure is actually expected behavior for something like a java you installed rather than hand-building.

As Jonas said, you can look in console for error messages, but most likely you are going to find that java was not built to allow debugging. You can also verify this by running:

codesign -d --entitlements --

if that doesn't include the get_task_allow entitlement, you won't be allowed to attach to it.

If you want to debug an app on macOS, you either have to disable SIP, or build a copy of the binary that opts into debugging (the debug builds of most projects will allow debugging...)

Anyway, lldb has no control over what it is and isn't allowed to attach to, that's a policy decision made by the OS, and quite deliberately placed outside the debugger's hands. So this isn't an lldb bug...

Thx for the reply!!! At first I have no idea whether it is a llbd Bug, so I open this issue. Sorry for that.

but I do build this app in debugging. Cause I write this app, and I run this app in IDEA with Debug.
got the console.app err meassage asfollows,there is errcode = 0x00000005. And can you give me some keyword to search?
attach failed

@Mervyen
Copy link
Author

Mervyen commented Feb 11, 2022

Based on the version number, it sounds like this is an issue with the LLDB that ships with Xcode. Unless it also reproduces with the lldb from llvm.org, I recommend filing a bug report with Apple.

That said, the logs you pasted here are not the logs the error message is talking about. They are system logs that you can access through Console.app.

Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.

Thx for reply!!! I downloaded the sourcecode from llvm.org and build the lldb. It still didn't work for me. And I forgot to reply you. thx again!

@jimingham
Copy link
Collaborator

Finding the reason why the attach is denied is a little annoying because of how Console filtering works. What you want to do is find the "task_for_pid" failure message from debugserver, then look at the other - non-debugserver logs from the same time, and in there will be some complaint about the binary. But the search field in Console is a filter not a search, so you have to remember where the interesting debugserver entry is, undo the filter, then find that entry again (I usually mark the time) and look around there.

@Mervyen
Copy link
Author

Mervyen commented Feb 14, 2022

Finding the reason why the attach is denied is a little annoying because of how Console filtering works. What you want to do is find the "task_for_pid" failure message from debugserver, then look at the other - non-debugserver logs from the same time, and in there will be some complaint about the binary. But the search field in Console is a filter not a search, so you have to remember where the interesting debugserver entry is, undo the filter, then find that entry again (I usually mark the time) and look around there.

That's cool! I do find the error. this process doesn't have "get-task-allow" .
image

(I rerun the process, so the pid is not the same, but the process is the same one.)
and this is a java, how can I add the "get-task-allow" to? Or anyother keyword to search for? thx!
image

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

No branches or pull requests

5 participants