Fix a crash in *NetBSD::Factory::Launch
ClosedPublic

Authored by krytarowski on Feb 2 2018, 2:10 PM.

Details

Summary

We cannot call process_up->SetState() inside
the NativeProcessNetBSD::Factory::Launch
function because it triggers a NULL pointer
deference.

The generic code for launching a process in:
GDBRemoteCommunicationServerLLGS::LaunchProcess
sets the m_debugged_process_up pointer after
a successful call to m_process_factory.Launch().
If we attempt to call process_up->SetState()
inside a platform specific Launch function we
end up dereferencing a NULL pointer in
NativeProcessProtocol::GetCurrentThreadID().

Use the proper call process_up->SetState(,false)
that sets notify_delegates to false.

Sponsored by <The NetBSD Foundation>

Diff Detail

Repository
rL LLVM
krytarowski created this revision.Feb 2 2018, 2:10 PM
krytarowski edited the summary of this revision. (Show Details)Feb 2 2018, 2:10 PM
(gdb) r
Starting program: /public/llvm-build/bin/lldb-server g \*:1234 -- /usr/bin/look
[New process 15150]

Thread 1 received signal SIGSEGV, Segmentation fault.
lldb_private::NativeProcessProtocol::GetCurrentThreadID (this=0x0) at /public/llvm/tools/lldb/include/lldb/Host/common/NativeProcessProtocol.h:178
178       lldb::tid_t GetCurrentThreadID() { return m_current_thread_id; }
(gdb) bt
#0  lldb_private::NativeProcessProtocol::GetCurrentThreadID (this=0x0) at /public/llvm/tools/lldb/include/lldb/Host/common/NativeProcessProtocol.h:178
#1  0x0000000000600fab in lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SendStopReasonForState (this=0x7f7fffffddc0, process_state=lldb::eStateStopped)
    at /public/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp:1641
#2  0x000000000060135a in lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped (this=0x7f7fffffddc0, process=0x7f7ff7b7c000)
    at /public/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp:835
#3  0x00000000006014d1 in lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::ProcessStateChanged (this=0x7f7fffffddc0, process=0x7f7ff7b7c000, state=lldb::eStateStopped)
    at /public/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp:870
#4  0x00000000005412e1 in lldb_private::NativeProcessProtocol::SynchronouslyNotifyProcessStateChanged (this=0x7f7ff7b7c000, state=lldb::eStateStopped)
    at /public/llvm/tools/lldb/source/Host/common/NativeProcessProtocol.cpp:336
#5  0x0000000000542e5f in lldb_private::NativeProcessProtocol::SetState (this=0x7f7ff7b7c000, state=lldb::eStateStopped, notify_delegates=true)
    at /public/llvm/tools/lldb/source/Host/common/NativeProcessProtocol.cpp:422
#6  0x000000000059fc77 in lldb_private::process_netbsd::NativeProcessNetBSD::Factory::Launch (this=0x7f7fffffe3a8, launch_info=..., native_delegate=..., mainloop=...)
    at /public/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp:114
#7  0x00000000005fd82a in lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::LaunchProcess (this=0x7f7fffffddc0)
    at /public/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp:233
#8  0x0000000000418e16 in handle_launch (gdb_server=..., argc=1, argv=0x7f7fffffe6f8) at /public/llvm/tools/lldb/tools/lldb-server/lldb-gdbserver.cpp:195
#9  0x000000000041a228 in main_gdbserver (argc=1, argv=0x7f7fffffe6f8) at /public/llvm/tools/lldb/tools/lldb-server/lldb-gdbserver.cpp:525
#10 0x000000000041befd in main (argc=5, argv=0x7f7fffffe6d8) at /public/llvm/tools/lldb/tools/lldb-server/lldb-server.cpp:58
(gdb)
krytarowski added inline comments.Feb 2 2018, 2:35 PM
source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
116

Another option is to call:

process_up->SetState(StateType::eStateStopped, false);

Both work.

krytarowski edited the summary of this revision. (Show Details)
krytarowski marked an inline comment as done.
krytarowski removed a subscriber: llvm-commits.
labath accepted this revision.Feb 5 2018, 2:05 AM
This revision is now accepted and ready to land.Feb 5 2018, 2:05 AM
krytarowski closed this revision.Feb 5 2018, 5:18 AM