[lldb-dev] [patch] segfault and misbehavior on the process connect command.

Viktor Kutuzov vkutuzov at accesssoftek.com
Fri Mar 30 13:19:51 PDT 2012


Hi everyone,

here is a patch, which should fix two problems in lldb.

The first problem is a segmentation fault on the 'process connect' command. The segfault occurs in lldb_private::Module::GetObjectFile in case no executable module was specified and/or loaded. There is a log to reproduce:

  freebsd1# ./lldb
  (lldb) platform select remote-freebsd
  Host: FreeBSD 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30 UTC 2012     root at farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC<mailto:root at farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC>
    Hostname: localhost
  (lldb) process connect localhost
  Segmentation fault (core dumped)


This is a stack trace for this case:

Program received signal SIGSEGV, Segmentation fault.
0x00000008042c5344 in pthread_mutex_lock () from /lib/libthr.so.3
(gdb) bt
#0  0x00000008042c5344 in pthread_mutex_lock () from /lib/libthr.so.3
#1  0x000000080149c7c5 in lldb_private::Mutex::Lock (mutex_ptr=0x18) at /usr/home/projects/llvm-lldb/tools/lldb/source/Host/common/Mutex.cpp:212
#2  0x000000080149c791 in lldb_private::Mutex::Locker::Locker () at SmallPtrSet.h:159
#3  0x00000008013b0c40 in lldb_private::Module::GetObjectFile (this=0x0) at /usr/home/projects/llvm-lldb/tools/lldb/source/Core/Module.cpp:945
#4  0x00000008023b5b1c in ProcessPOSIX::ProcessPOSIX (this=0x805f4b800, target=@0x808b8d100<mailto:target=@0x808b8d100>, listener=@0x805c94d90<mailto:listener=@0x805c94d90>)
    at /usr/home/projects/llvm-lldb/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp:76
#5  0x00000008023bd00a in ProcessFreeBSD::ProcessFreeBSD (this=0x805f4b800, target=@0x808b8d100<mailto:target=@0x808b8d100>, listener=@0x805c94d90<mailto:listener=@0x805c94d90>)
    at /usr/home/projects/llvm-lldb/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp:122
#6  0x00000008023bcdb1 in ProcessFreeBSD::CreateInstance (target=@0x808b8d100<mailto:target=@0x808b8d100>, listener=@0x805c94d90<mailto:listener=@0x805c94d90>, crash_file_path=0x0)
    at /usr/home/projects/llvm-lldb/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp:41
#7  0x0000000801702cb3 in lldb_private::Process::FindPlugin (target=@0x808b8d100<mailto:target=@0x808b8d100>, plugin_name=0x0, listener=@0x805c94d90<mailto:listener=@0x805c94d90>, crash_file_path=0x0)
    at /usr/home/projects/llvm-lldb/tools/lldb/source/Target/Process.cpp:735
#8  0x000000080172a27e in lldb_private::Target::CreateProcess (this=0x808b8d100, listener=@0x805c94d90<mailto:listener=@0x805c94d90>, plugin_name=0x0, crash_file=0x0)
    at /usr/home/projects/llvm-lldb/tools/lldb/source/Target/Target.cpp:154
#9  0x00000008012fde09 in CommandObjectProcessConnect::Execute (this=0x805c2fc00, command=@0x7fffffffbf10<mailto:command=@0x7fffffffbf10>, result=@0x805d48140<mailto:result=@0x805d48140>)
    at /usr/home/projects/llvm-lldb/tools/lldb/source/Commands/CommandObjectProcess.cpp:873
#10 0x00000008014bdf20 in lldb_private::CommandObject::ExecuteWithOptions (this=0x805c2fc00, args=@0x7fffffffbf10<mailto:args=@0x7fffffffbf10>, result=@0x805d48140<mailto:result=@0x805d48140>)
    at /usr/home/projects/llvm-lldb/tools/lldb/source/Interpreter/CommandObject.cpp:281
#11 0x00000008014b2263 in lldb_private::CommandInterpreter::HandleCommand (this=0x805ca4200, command_line=0x80a41f198 "process connect localhost", add_to_history=true, result=@0x805d48140<mailto:result=@0x805d48140>,
    override_context=0x0, repeat_on_empty_command=true, no_context_switching=false) at /usr/home/projects/llvm-lldb/tools/lldb/source/Interpreter/CommandInterpreter.cpp:1540
#12 0x000000080124a7b5 in lldb::SBCommandInterpreter::HandleCommand (this=0x7fffffffc2f0, command_line=0x80a41f198 "process connect localhost", result=@0x7fffffffc2f8<mailto:result=@0x7fffffffc2f8>, add_to_history=true)
    at /usr/home/projects/llvm-lldb/tools/lldb/source/API/SBCommandInterpreter.cpp:97
#13 0x000000000040b666 in Driver::HandleIOEvent (this=0x7fffffffd718, event=@0x7fffffffc560<mailto:event=@0x7fffffffc560>) at /usr/home/projects/llvm-lldb/tools/lldb/tools/driver/Driver.cpp:980
#14 0x000000000040cc3e in Driver::MainLoop (this=0x7fffffffd718) at /usr/home/projects/llvm-lldb/tools/lldb/tools/driver/Driver.cpp:1406
#15 0x000000000040d28b in main (argc=1, argv=0x7fffffffd888, envp=0x7fffffffd898) at /usr/home/projects/llvm-lldb/tools/lldb/tools/driver/Driver.cpp:1540

The second problem is a misbehavior after an unseccessful  process connect commend has been involved. The process connect leaves an 'undefined' process object if the command has been finished with an error. There is a log to reproduce:

  freebsd1# ./lldb /bin/ls
  Current executable set to '/bin/ls' (x86_64).
  (lldb) platform select remote-freebsd
  Host: FreeBSD 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30 UTC 2012     root at farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC<mailto:root at farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC>
  (lldb) process connect localhost
  error: remote connections are not supported
  (lldb) process connect connect://localhost
  error: Process 0 is currently being debugged, kill the process before connecting.
  (lldb) exit
The second error should not appear as far as I understood. This patch fixes it by deleting a process object.


Would somebody review and apply this patch if it looks ok?
Thanks.
Viktor.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20120330/e7e23b9b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lldb-commandobjectprocess-crash.patch
Type: application/octet-stream
Size: 1038 bytes
Desc: lldb-commandobjectprocess-crash.patch
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20120330/e7e23b9b/attachment.obj>


More information about the lldb-dev mailing list