<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Thanks, David!<br><div><br><div>Begin forwarded message:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 1.0);"><b>From: </b></span><span style="font-family:'Helvetica'; font-size:medium;">Johnny Chen <<a href="mailto:johnny.chen@apple.com">johnny.chen@apple.com</a>><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 1.0);"><b>Subject: </b></span><span style="font-family:'Helvetica'; font-size:medium;"><b>[Lldb-commits] [lldb] r136720 - in /lldb/trunk: ./ include/lldb/Host/ include/lldb/Host/freebsd/ lib/ source/ source/Host/ source/Host/common/ source/Host/freebsd/ source/Plugins/ source/Plugins/Platform/ source/Plugins/Platform/FreeBSD/ tools/driver/</b><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 1.0);"><b>Date: </b></span><span style="font-family:'Helvetica'; font-size:medium;">August 2, 2011 1:52:42 PM PDT<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 1.0);"><b>To: </b></span><span style="font-family:'Helvetica'; font-size:medium;"><a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br></span></div><br><div>Author: johnny<br>Date: Tue Aug  2 15:52:42 2011<br>New Revision: 136720<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=136720&view=rev">http://llvm.org/viewvc/llvm-project?rev=136720&view=rev</a><br>Log:<br>Patch by David Forsythe to build lldb on FreeBSD!<br><br>I did not take the patch for ClangExpressionParser.cpp since there was a<br>recent change by Peter for the same line.  Feel free to disagree. :-)<br><br>Reference:<br>----------------------------------------------------------------------<br>r136580 | pcc | 2011-07-30 15:42:24 -0700 (Sat, 30 Jul 2011) | 3 lines<br><br>Add reloc arg to standard JIT createJIT()<br><br>Fixes non-__APPLE__ build.  Patch by Matt Johnson!<br>----------------------------------------------------------------------<br><br>Also, I ignore the part of the patch to remove the RegisterContextDarwin*.h/.cpp.<br><br>Added:<br>    lldb/trunk/source/Host/freebsd/<br>    lldb/trunk/source/Host/freebsd/Host.cpp<br>    lldb/trunk/source/Host/freebsd/Makefile<br>    lldb/trunk/source/Plugins/Platform/FreeBSD/<br>    lldb/trunk/source/Plugins/Platform/FreeBSD/Makefile<br>    lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp<br>    lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h<br>Modified:<br>    lldb/trunk/Makefile<br>    lldb/trunk/include/lldb/Host/SocketAddress.h<br>    lldb/trunk/include/lldb/Host/freebsd/Config.h<br>    lldb/trunk/lib/Makefile<br>    lldb/trunk/source/Host/Makefile<br>    lldb/trunk/source/Host/common/Host.cpp<br>    lldb/trunk/source/Plugins/Makefile<br>    lldb/trunk/source/Plugins/Platform/Makefile<br>    lldb/trunk/source/lldb.cpp<br>    lldb/trunk/tools/driver/IOChannel.h<br>    lldb/trunk/tools/driver/Makefile<br><br>Modified: lldb/trunk/Makefile<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/Makefile?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/Makefile?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/Makefile (original)<br>+++ lldb/trunk/Makefile Tue Aug  2 15:52:42 2011<br>@@ -30,7 +30,6 @@<br><br> # Set Python include directory<br> PYTHON_INC_DIR = $(shell python-config --includes)<br>-<br> # Set common LLDB build flags.<br> CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/include <br> CPP.Flags += -I$(PROJ_OBJ_DIR)/$(LLDB_LEVEL)/include<br><br>Modified: lldb/trunk/include/lldb/Host/SocketAddress.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/SocketAddress.h?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/SocketAddress.h?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/include/lldb/Host/SocketAddress.h (original)<br>+++ lldb/trunk/include/lldb/Host/SocketAddress.h Tue Aug  2 15:52:42 2011<br>@@ -16,6 +16,10 @@<br> #include <netdb.h><br> #include <netinet/in.h><br><br>+#if defined(__FreeBSD__)<br>+#include <sys/types.h><br>+#endif<br>+<br> // C++ Includes<br> // Other libraries and framework includes<br> // Project includes<br><br>Modified: lldb/trunk/include/lldb/Host/freebsd/Config.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/freebsd/Config.h?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/freebsd/Config.h?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/include/lldb/Host/freebsd/Config.h (original)<br>+++ lldb/trunk/include/lldb/Host/freebsd/Config.h Tue Aug  2 15:52:42 2011<br>@@ -27,4 +27,4 @@<br><br> //#define LLDB_CONFIG_FCNTL_GETPATH_SUPPORTED 1<br><br>-#endif // #ifndef liblldb_Platform_Config_h_<br>\ No newline at end of file<br>+#endif // #ifndef liblldb_Platform_Config_h_<br><br>Modified: lldb/trunk/lib/Makefile<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/lib/Makefile?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/lib/Makefile?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/lib/Makefile (original)<br>+++ lldb/trunk/lib/Makefile Tue Aug  2 15:52:42 2011<br>@@ -73,7 +73,8 @@<br>               lldbPluginObjectContainerUniversalMachO.a \<br>               lldbPluginObjectFileMachO.a \<br>               lldbPluginSymbolVendorMacOSX.a \<br>-              lldbPluginPlatformMacOSX.a<br>+              lldbPluginPlatformMacOSX.a \<br>+<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">    </span><span class="Apple-tab-span" style="white-space:pre">    </span>  lldbPluginProcessDarwin<br> endif<br><br> ifeq ($(HOST_OS),Linux)<br>@@ -83,6 +84,11 @@<br>               lldbHostLinux.a<br> endif<br><br>+ifeq ($(HOST_OS),FreeBSD)<br>+  USEDLIBS += lldbHostFreeBSD.a \<br>+<span class="Apple-tab-span" style="white-space:pre">      </span><span class="Apple-tab-span" style="white-space:pre">    </span><span class="Apple-tab-span" style="white-space:pre">    </span>  lldbPluginPlatformFreeBSD.a<br>+endif<br>+<br> include $(LEVEL)/Makefile.common<br><br> ifeq ($(HOST_OS),Darwin)<br>@@ -108,7 +114,7 @@<br>     endif<br> endif<br><br>-ifeq ($(HOST_OS), Linux)<br>+ifeq ($(HOST_OS),Linux)<br>     # Include everything from the .a's into the shared library.<br>     ProjLibsOptions := -Wl,--whole-archive $(ProjLibsOptions) \<br>                        -Wl,--no-whole-archive<br>@@ -117,3 +123,13 @@<br>     # Link in python<br>     LD.Flags += $(PYTHON_BUILD_FLAGS) -lrt<br> endif<br>+<br>+ifeq ($(HOST_OS),FreeBSD)<br>+    # Include everything from the .a's into the shared library.<br>+    ProjLibsOptions := -Wl,--whole-archive $(ProjLibsOptions) \<br>+                       -Wl,--no-whole-archive<br>+    # Don't allow unresolved symbols.<br>+    LLVMLibsOptions += -Wl,--no-undefined<br>+    # Link in python<br>+    LD.Flags += $(PYTHON_BUILD_FLAGS) -lrt -L/usr/local/lib -lexecinfo<br>+endif<br><br>Modified: lldb/trunk/source/Host/Makefile<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/Makefile?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/Makefile?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/source/Host/Makefile (original)<br>+++ lldb/trunk/source/Host/Makefile Tue Aug  2 15:52:42 2011<br>@@ -21,4 +21,8 @@<br> DIRS += linux<br> endif<br><br>+ifeq ($(HOST_OS),FreeBSD)<br>+DIRS += freebsd<br>+endif<br>+<br> include $(LLDB_LEVEL)/Makefile<br><br>Modified: lldb/trunk/source/Host/common/Host.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/source/Host/common/Host.cpp (original)<br>+++ lldb/trunk/source/Host/common/Host.cpp Tue Aug  2 15:52:42 2011<br>@@ -43,6 +43,12 @@<br><br> #include <sys/wait.h><br><br>+#elif defined (__FreeBSD__)<br>+<br>+#include <sys/wait.h><br>+#include <sys/sysctl.h><br>+#include <pthread_np.h><br>+<br> #endif<br><br> using namespace lldb;<br>@@ -357,6 +363,8 @@<br>             g_vendor.SetCString("apple");<br> #elif defined (__linux__)<br>         g_vendor.SetCString("gnu");<br>+#elif defined (__FreeBSD__)<br>+        g_vendor.SetCString("freebsd");<br> #endif<br>     }<br>     return g_vendor;<br>@@ -372,6 +380,8 @@<br>         g_os_string.SetCString("darwin");<br> #elif defined (__linux__)<br>         g_os_string.SetCString("linux");<br>+#elif defined (__FreeBSD__)<br>+        g_os_string.SetCString("freebsd");<br> #endif<br>     }<br>     return g_os_string;<br>@@ -410,6 +420,8 @@<br> {<br> #if defined (__APPLE__)<br>     return ::mach_thread_self();<br>+#elif defined(__FreeBSD__)<br>+    return lldb::tid_t(pthread_getthreadid_np());<br> #else<br>     return lldb::tid_t(pthread_self());<br> #endif<br>@@ -470,19 +482,17 @@<br> {<br> }<br><br>-#if !defined (__APPLE__) // see macosx/Host.mm<br>+#if !defined (__APPLE__) && !defined (__FreeBSD__) // see macosx/Host.mm<br> void<br> Host::ThreadCreated (const char *thread_name)<br> {<br> }<br><br>-void<br> Host::Backtrace (Stream &strm, uint32_t max_frames)<br> {<br>     // TODO: Is there a way to backtrace the current process on linux? Other systems?<br> }<br><br>-<br> size_t<br> Host::GetEnvironment (StringList &env)<br> {<br>@@ -1120,9 +1130,7 @@<br>     return NULL;<br> }<br><br>-<br>-#if !defined (__APPLE__) // see macosx/Host.mm<br>-<br>+#if !defined (__APPLE__) && !defined (__FreeBSD__) // see macosx/Host.mm<br> bool<br> Host::GetOSBuildString (std::string &s)<br> {<br>@@ -1136,21 +1144,27 @@<br>     s.clear();<br>     return false;<br> }<br>+#endif<br><br>+#if !defined(__APPLE__)<br> uint32_t<br> Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos)<br> {<br>     process_infos.Clear();<br>     return process_infos.GetSize();<br> }<br>+#endif<br><br>+#if !defined (__APPLE__) && !defined (__FreeBSD__)<br> bool<br> Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)<br> {<br>     process_info.Clear();<br>     return false;<br> }<br>+#endif<br><br>+#if !defined (__APPLE__)<br> bool<br> Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no)<br> {<br><br>Added: lldb/trunk/source/Host/freebsd/Host.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/freebsd/Host.cpp?rev=136720&view=auto">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/freebsd/Host.cpp?rev=136720&view=auto</a><br>==============================================================================<br>--- lldb/trunk/source/Host/freebsd/Host.cpp (added)<br>+++ lldb/trunk/source/Host/freebsd/Host.cpp Tue Aug  2 15:52:42 2011<br>@@ -0,0 +1,277 @@<br>+//===-- source/Host/freebsd/Host.cpp ------------------------------*- C++ -*-===//<br>+//<br>+//                     The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+<br>+// C Includes<br>+#include <stdio.h><br>+#include <execinfo.h><br>+#include <sys/types.h><br>+#include <sys/user.h><br>+#include <sys/utsname.h><br>+#include <sys/sysctl.h><br>+<br>+// C++ Includes<br>+// Other libraries and framework includes<br>+// Project includes<br>+#include "lldb/Core/Error.h"<br>+#include "lldb/Host/Endian.h"<br>+#include "lldb/Host/Host.h"<br>+#include "lldb/Core/DataExtractor.h"<br>+#include "lldb/Core/StreamFile.h"<br>+#include "lldb/Core/StreamString.h"<br>+#include "lldb/Target/Process.h"<br>+<br>+#include "llvm/Support/Host.h"<br>+<br>+extern "C" {<br>+    char **environ;<br>+}<br>+<br>+using namespace lldb;<br>+using namespace lldb_private;<br>+<br>+class FreeBSDThread<br>+{<br>+public:<br>+    FreeBSDThread(const char *thread_name)<br>+    {<br>+        Host::SetThreadName (LLDB_INVALID_PROCESS_ID, LLDB_INVALID_THREAD_ID, thread_name);<br>+    }<br>+    static void PThreadDestructor (void *v)<br>+    {<br>+        delete (FreeBSDThread*)v;<br>+    }<br>+};<br>+<br>+static pthread_once_t g_thread_create_once = PTHREAD_ONCE_INIT;<br>+static pthread_key_t g_thread_create_key = 0;<br>+<br>+static void<br>+InitThreadCreated()<br>+{<br>+    ::pthread_key_create (&g_thread_create_key, FreeBSDThread::PThreadDestructor);<br>+}<br>+<br>+void<br>+Host::ThreadCreated (const char *thread_name)<br>+{<br>+    ::pthread_once (&g_thread_create_once, InitThreadCreated);<br>+    if (g_thread_create_key)<br>+    {<br>+        ::pthread_setspecific (g_thread_create_key, new FreeBSDThread(thread_name));<br>+    }<br>+}<br>+<br>+void<br>+Host::Backtrace (Stream &strm, uint32_t max_frames)<br>+{<br>+    char backtrace_path[] = "/tmp/lldb-backtrace-tmp-XXXXXX";<br>+    int backtrace_fd = ::mkstemp (backtrace_path);<br>+    if (backtrace_fd != -1)<br>+    {<br>+        std::vector<void *> frame_buffer (max_frames, NULL);<br>+        int count = ::backtrace (&frame_buffer[0], frame_buffer.size());<br>+        ::backtrace_symbols_fd (&frame_buffer[0], count, backtrace_fd);<br>+        <br>+        const off_t buffer_size = ::lseek(backtrace_fd, 0, SEEK_CUR);<br>+<br>+        if (::lseek(backtrace_fd, 0, SEEK_SET) == 0)<br>+        {<br>+            char *buffer = (char *)::malloc (buffer_size);<br>+            if (buffer)<br>+            {<br>+                ssize_t bytes_read = ::read (backtrace_fd, buffer, buffer_size);<br>+                if (bytes_read > 0)<br>+                    strm.Write(buffer, bytes_read);<br>+                ::free (buffer);<br>+            }<br>+        }<br>+        ::close (backtrace_fd);<br>+        ::unlink (backtrace_path);<br>+    }<br>+}<br>+<br>+size_t<br>+Host::GetEnvironment (StringList &env)<br>+{<br>+    char *v;<br>+    char **var = environ;<br>+    for (var = environ; var != NULL; ++var) {<br>+        v = strchr(*var, (int)'-');<br>+        if (v == NULL)<br>+            continue;<br>+        env.AppendString(v);<br>+    }<br>+    return env.GetSize();<br>+}<br>+<br>+bool<br>+Host::GetOSVersion(uint32_t &major, <br>+                   uint32_t &minor, <br>+                   uint32_t &update)<br>+{<br>+    struct utsname un;<br>+    int status;<br>+<br>+    if (uname(&un) < 0)<br>+        return false;<br>+<br>+    status = sscanf(un.release, "%u.%u-%u", &major, &minor, &update);<br>+    return status == 3;<br>+}<br>+<br>+Error<br>+Host::LaunchProcess (ProcessLaunchInfo &launch_info)<br>+{<br>+    Error error;<br>+    assert(!"Not implemented yet!!!");<br>+    return error;<br>+}<br>+<br>+bool<br>+Host::GetOSBuildString (std::string &s)<br>+{<br>+    int mib[2] = { CTL_KERN, KERN_OSREV };<br>+    char cstr[PATH_MAX];<br>+    size_t cstr_len = sizeof(cstr);<br>+    if (::sysctl (mib, 2, cstr, &cstr_len, NULL, 0) == 0)<br>+    {<br>+        s.assign (cstr, cstr_len);<br>+        return true;<br>+    }<br>+    s.clear();<br>+    return false;<br>+}<br>+<br>+bool<br>+Host::GetOSKernelDescription (std::string &s)<br>+{<br>+    int mib[2] = { CTL_KERN, KERN_VERSION };<br>+    char cstr[PATH_MAX];<br>+    size_t cstr_len = sizeof(cstr);<br>+    if (::sysctl (mib, 2, cstr, &cstr_len, NULL, 0) == 0)<br>+    {<br>+        s.assign (cstr, cstr_len);<br>+        return true;<br>+    }<br>+    s.clear();<br>+    return false;<br>+}<br>+<br>+static bool<br>+GetFreeBSDProcessArgs (const ProcessInstanceInfoMatch *match_info_ptr,<br>+                      ProcessInstanceInfo &process_info)<br>+{<br>+    if (process_info.ProcessIDIsValid()) {<br>+        int mib[3] = { CTL_KERN, KERN_PROC_ARGS, process_info.GetProcessID() };<br>+<br>+        char arg_data[8192];<br>+        size_t arg_data_size = sizeof(arg_data);<br>+        if (::sysctl (mib, 3, arg_data, &arg_data_size , NULL, 0) == 0)<br>+        {<br>+            DataExtractor data (arg_data, arg_data_size, lldb::endian::InlHostByteOrder(), sizeof(void *));<br>+            uint32_t offset = 0;<br>+            uint32_t start_offset;<br>+            uint32_t argc = data.GetU32 (&offset);<br>+            const char *cstr;<br>+            <br>+            cstr = data.GetCStr (&offset);<br>+            if (cstr)<br>+            {<br>+                process_info.GetExecutableFile().SetFile(cstr, false);<br>+<br>+                if (match_info_ptr == NULL || <br>+                    NameMatches (process_info.GetExecutableFile().GetFilename().GetCString(),<br>+                                 match_info_ptr->GetNameMatchType(),<br>+                                 match_info_ptr->GetProcessInfo().GetName()))<br>+                {<br>+                    // Skip NULLs<br>+                    while (1)<br>+                    {<br>+                        const uint8_t *p = data.PeekData(offset, 1);<br>+                        if ((p == NULL) || (*p != '\0'))<br>+                            break;<br>+                        ++offset;<br>+                    }<br>+                    // Now extract all arguments<br>+                    Args &proc_args = process_info.GetArguments();<br>+                    for (int i=0; i<argc; ++i)<br>+                    {<br>+                        start_offset = offset;<br>+                        cstr = data.GetCStr(&offset);<br>+                        if (cstr)<br>+                            proc_args.AppendArgument(cstr);<br>+                    }<br>+                    return true;<br>+                }<br>+            }<br>+        }<br>+    }<br>+    return false;<br>+}<br>+<br>+static bool<br>+GetFreeBSDProcessCPUType (ProcessInstanceInfo &process_info)<br>+{<br>+    if (process_info.ProcessIDIsValid()) {<br>+        // TODO: This<br>+        // return true;<br>+    }<br>+    process_info.GetArchitecture().Clear();<br>+    return false;<br>+}<br>+<br>+static bool<br>+GetFreeBSDProcessUserAndGroup(ProcessInstanceInfo &process_info)<br>+{<br>+    struct kinfo_proc proc_kinfo;<br>+    size_t proc_kinfo_size;<br>+<br>+    if (process_info.ProcessIDIsValid()) <br>+    {<br>+        int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID,<br>+            process_info.GetProcessID() };<br>+        proc_kinfo_size = sizeof(struct kinfo_proc);<br>+<br>+        if (::sysctl (mib, 4, &proc_kinfo, &proc_kinfo_size, NULL, 0) == 0)<br>+        {<br>+            if (proc_kinfo_size > 0)<br>+            {<br>+                process_info.SetParentProcessID (proc_kinfo.ki_ppid);<br>+                process_info.SetUserID (proc_kinfo.ki_ruid);<br>+                process_info.SetGroupID (proc_kinfo.ki_rgid);<br>+                process_info.SetEffectiveUserID (proc_kinfo.ki_uid);<br>+                if (proc_kinfo.ki_ngroups > 0)<br>+                    process_info.SetEffectiveGroupID (proc_kinfo.ki_groups[0]);<br>+                else<br>+                    process_info.SetEffectiveGroupID (UINT32_MAX);            <br>+                return true;<br>+            }<br>+        }<br>+    }<br>+    process_info.SetParentProcessID (LLDB_INVALID_PROCESS_ID);<br>+    process_info.SetUserID (UINT32_MAX);<br>+    process_info.SetGroupID (UINT32_MAX);<br>+    process_info.SetEffectiveUserID (UINT32_MAX);<br>+    process_info.SetEffectiveGroupID (UINT32_MAX);            <br>+    return false;<br>+}<br>+<br>+bool<br>+Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)<br>+{<br>+    process_info.SetProcessID(pid);<br>+    if (GetFreeBSDProcessArgs(NULL, process_info)) {<br>+        // should use libprocstat instead of going right into sysctl?<br>+        GetFreeBSDProcessCPUType(process_info);<br>+        GetFreeBSDProcessUserAndGroup(process_info);<br>+        return true;<br>+    }<br>+    process_info.Clear();<br>+    return false;<br>+}<br><br>Added: lldb/trunk/source/Host/freebsd/Makefile<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/freebsd/Makefile?rev=136720&view=auto">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/freebsd/Makefile?rev=136720&view=auto</a><br>==============================================================================<br>--- lldb/trunk/source/Host/freebsd/Makefile (added)<br>+++ lldb/trunk/source/Host/freebsd/Makefile Tue Aug  2 15:52:42 2011<br>@@ -0,0 +1,16 @@<br>+##===- source/Host/freebsd/Makefile --------------------------*- Makefile -*-===##<br>+# <br>+#                     The LLVM Compiler Infrastructure<br>+#<br>+# This file is distributed under the University of Illinois Open Source<br>+# License. See LICENSE.TXT for details.<br>+# <br>+##===----------------------------------------------------------------------===##<br>+<br>+LLDB_LEVEL := ../../..<br>+LIBRARYNAME := lldbHostFreeBSD<br>+BUILD_ARCHIVE = 1<br>+<br>+CPPFLAGS += -I/usr/local/include<br>+<br>+include $(LLDB_LEVEL)/Makefile<br><br>Modified: lldb/trunk/source/Plugins/Makefile<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Makefile?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Makefile?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/source/Plugins/Makefile (original)<br>+++ lldb/trunk/source/Plugins/Makefile Tue Aug  2 15:52:42 2011<br>@@ -21,7 +21,7 @@<br> <span class="Apple-tab-span" style="white-space:pre">      </span>LanguageRuntime/ObjC/AppleObjCRuntime<br><br> ifeq ($(HOST_OS),Darwin)<br>-DIRS += DynamicLoader/MacOSX-DYLD ObjectContainer/Universal-Mach-O \<br>+DIRS += Process/Darwin DynamicLoader/MacOSX-DYLD ObjectContainer/Universal-Mach-O \<br> <span class="Apple-tab-span" style="white-space:pre">  </span>ObjectFile/Mach-O SymbolVendor/MacOSX<br> #DIRS += Process/MacOSX-User<br> endif<br><br>Added: lldb/trunk/source/Plugins/Platform/FreeBSD/Makefile<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/Makefile?rev=136720&view=auto">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/Makefile?rev=136720&view=auto</a><br>==============================================================================<br>--- lldb/trunk/source/Plugins/Platform/FreeBSD/Makefile (added)<br>+++ lldb/trunk/source/Plugins/Platform/FreeBSD/Makefile Tue Aug  2 15:52:42 2011<br>@@ -0,0 +1,14 @@<br>+##===- source/Plugins/Platform/Linux/Makefile --------------*- Makefile -*-===##<br>+#<br>+#                     The LLVM Compiler Infrastructure<br>+#<br>+# This file is distributed under the University of Illinois Open Source<br>+# License. See LICENSE.TXT for details.<br>+#<br>+##===----------------------------------------------------------------------===##<br>+<br>+LLDB_LEVEL := ../../../..<br>+LIBRARYNAME := lldbPluginPlatformFreeBSD<br>+BUILD_ARCHIVE = 1<br>+<br>+include $(LLDB_LEVEL)/Makefile<br><br>Added: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp?rev=136720&view=auto">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp?rev=136720&view=auto</a><br>==============================================================================<br>--- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp (added)<br>+++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp Tue Aug  2 15:52:42 2011<br>@@ -0,0 +1,262 @@<br>+//===-- PlatformFreeBSD.cpp ---------------------------------------*- C++ -*-===//<br>+//<br>+//                     The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+<br>+#include "PlatformFreeBSD.h"<br>+<br>+// C Includes<br>+#include <stdio.h><br>+#include <sys/utsname.h><br>+<br>+// C++ Includes<br>+// Other libraries and framework includes<br>+// Project includes<br>+#include "lldb/Core/Error.h"<br>+#include "lldb/Core/Module.h"<br>+#include "lldb/Core/ModuleList.h"<br>+#include "lldb/Core/PluginManager.h"<br>+#include "lldb/Core/StreamString.h"<br>+#include "lldb/Host/FileSpec.h"<br>+#include "lldb/Host/Host.h"<br>+#include "lldb/Target/Target.h"<br>+#include "lldb/Target/Process.h"<br>+<br>+using namespace lldb;<br>+using namespace lldb_private;<br>+<br>+Platform *<br>+PlatformFreeBSD::CreateInstance ()<br>+{<br>+    return new PlatformFreeBSD();<br>+}<br>+<br>+const char *<br>+PlatformFreeBSD::GetPluginNameStatic()<br>+{<br>+    return "plugin.platform.FreeBSD";<br>+}<br>+<br>+const char *<br>+PlatformFreeBSD::GetPluginDescriptionStatic()<br>+{<br>+    return "Default platform plugin for FreeBSD";<br>+}<br>+<br>+void<br>+PlatformFreeBSD::Initialize ()<br>+{<br>+    static bool g_initialized = false;<br>+<br>+    if (!g_initialized)<br>+    {<br>+        PlatformSP default_platform_sp (CreateInstance());<br>+        Platform::SetDefaultPlatform (default_platform_sp);<br>+        PluginManager::RegisterPlugin(GetPluginNameStatic(),<br>+                                      GetPluginDescriptionStatic(),<br>+                                      CreateInstance);<br>+        g_initialized = true;<br>+    }<br>+}<br>+<br>+void<br>+PlatformFreeBSD::Terminate ()<br>+{<br>+<span class="Apple-tab-span" style="white-space:pre">    </span>PluginManager::UnregisterPlugin (PlatformFreeBSD::CreateInstance);<br>+}<br>+<br>+<br>+Error<br>+PlatformFreeBSD::ResolveExecutable (const FileSpec &exe_file,<br>+                                  const ArchSpec &exe_arch,<br>+                                  lldb::ModuleSP &exe_module_sp)<br>+{<br>+    Error error;<br>+    // Nothing special to do here, just use the actual file and architecture<br>+<br>+    FileSpec resolved_exe_file (exe_file);<br>+    <br>+    // If we have "ls" as the exe_file, resolve the executable loation based on<br>+    // the current path variables<br>+    if (!resolved_exe_file.Exists())<br>+        resolved_exe_file.ResolveExecutableLocation ();<br>+<br>+    // Resolve any executable within a bundle on MacOSX<br>+    Host::ResolveExecutableInBundle (resolved_exe_file);<br>+<br>+    if (resolved_exe_file.Exists())<br>+    {<br>+        if (exe_arch.IsValid())<br>+        {<br>+            error = ModuleList::GetSharedModule (resolved_exe_file, <br>+                                                 exe_arch, <br>+                                                 NULL,<br>+                                                 NULL, <br>+                                                 0, <br>+                                                 exe_module_sp, <br>+                                                 NULL, <br>+                                                 NULL);<br>+        <br>+            if (exe_module_sp->GetObjectFile() == NULL)<br>+            {<br>+                exe_module_sp.reset();<br>+                error.SetErrorStringWithFormat ("'%s%s%s' doesn't contain the architecture %s",<br>+                                                exe_file.GetDirectory().AsCString(""),<br>+                                                exe_file.GetDirectory() ? "/" : "",<br>+                                                exe_file.GetFilename().AsCString(""),<br>+                                                exe_arch.GetArchitectureName());<br>+            }<br>+        }<br>+        else<br>+        {<br>+            // No valid architecture was specified, ask the platform for<br>+            // the architectures that we should be using (in the correct order)<br>+            // and see if we can find a match that way<br>+            StreamString arch_names;<br>+            ArchSpec platform_arch;<br>+            for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, platform_arch); ++idx)<br>+            {<br>+                error = ModuleList::GetSharedModule (resolved_exe_file, <br>+                                                     platform_arch, <br>+                                                     NULL,<br>+                                                     NULL, <br>+                                                     0, <br>+                                                     exe_module_sp, <br>+                                                     NULL, <br>+                                                     NULL);<br>+                // Did we find an executable using one of the <br>+                if (error.Success())<br>+                {<br>+                    if (exe_module_sp && exe_module_sp->GetObjectFile())<br>+                        break;<br>+                    else<br>+                        error.SetErrorToGenericError();<br>+                }<br>+                <br>+                if (idx > 0)<br>+                    arch_names.PutCString (", ");<br>+                arch_names.PutCString (platform_arch.GetArchitectureName());<br>+            }<br>+            <br>+            if (error.Fail() || !exe_module_sp)<br>+            {<br>+                error.SetErrorStringWithFormat ("'%s%s%s' doesn't contain any '%s' platform architectures: %s",<br>+                                                exe_file.GetDirectory().AsCString(""),<br>+                                                exe_file.GetDirectory() ? "/" : "",<br>+                                                exe_file.GetFilename().AsCString(""),<br>+                                                GetShortPluginName(),<br>+                                                arch_names.GetString().c_str());<br>+            }<br>+        }<br>+    }<br>+    else<br>+    {<br>+        error.SetErrorStringWithFormat ("'%s%s%s' does not exist",<br>+                                        exe_file.GetDirectory().AsCString(""),<br>+                                        exe_file.GetDirectory() ? "/" : "",<br>+                                        exe_file.GetFilename().AsCString(""));<br>+    }<br>+<br>+    return error;<br>+}<br>+<br>+Error<br>+PlatformFreeBSD::GetFile (const FileSpec &platform_file, <br>+                        const UUID *uuid, FileSpec &local_file)<br>+{<br>+    // Default to the local case<br>+    local_file = platform_file;<br>+    return Error();<br>+}<br>+<br>+<br>+//------------------------------------------------------------------<br>+/// Default Constructor<br>+//------------------------------------------------------------------<br>+PlatformFreeBSD::PlatformFreeBSD () :<br>+    Platform(true)<br>+{<br>+}<br>+<br>+//------------------------------------------------------------------<br>+/// Destructor.<br>+///<br>+/// The destructor is virtual since this class is designed to be<br>+/// inherited from by the plug-in instance.<br>+//------------------------------------------------------------------<br>+PlatformFreeBSD::~PlatformFreeBSD()<br>+{<br>+}<br>+<br>+bool<br>+PlatformFreeBSD::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)<br>+{<br>+    return Host::GetProcessInfo (pid, process_info);<br>+}<br>+<br>+bool<br>+PlatformFreeBSD::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)<br>+{<br>+    if (idx == 0)<br>+    {<br>+        arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture);<br>+        return arch.IsValid();<br>+    }<br>+    return false;<br>+}<br>+<br>+void<br>+PlatformFreeBSD::GetStatus (Stream &strm)<br>+{<br>+    struct utsname un;<br>+<br>+    if (uname(&un)) {<br>+        strm << "FreeBSD";<br>+        return;<br>+    }<br>+<br>+    strm << un.sysname << ' ' << un.release << ' ' << un.version << '\n';<br>+}<br>+<br>+size_t<br>+PlatformFreeBSD::GetSoftwareBreakpointTrapOpcode (Target &target, <br>+                                                BreakpointSite *bp_site)<br>+{<br>+    static const uint8_t g_i386_opcode[] = { 0xCC };<br>+<br>+    ArchSpec arch = target.GetArchitecture();<br>+    const uint8_t *opcode = NULL;<br>+    size_t opcode_size = 0;<br>+<br>+    switch (arch.GetCore())<br>+    {<br>+    default:<br>+        assert(false && "CPU type not supported!");<br>+        break;<br>+<br>+    case ArchSpec::eCore_x86_32_i386:<br>+    case ArchSpec::eCore_x86_64_x86_64:<br>+        opcode = g_i386_opcode;<br>+        opcode_size = sizeof(g_i386_opcode);<br>+        break;<br>+    }<br>+<br>+    bp_site->SetTrapOpcode(opcode, opcode_size);<br>+    return opcode_size;<br>+}<br>+<br>+lldb::ProcessSP<br>+PlatformFreeBSD::Attach(lldb::pid_t pid,<br>+                      Debugger &debugger,<br>+                      Target *target,<br>+                      Listener &listener,<br>+                      Error &error)<br>+{<br>+    ProcessSP processSP;<br>+    assert(!"Not implemented yet!");<br>+    return processSP;<br>+}<br><br>Added: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h?rev=136720&view=auto">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h?rev=136720&view=auto</a><br>==============================================================================<br>--- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h (added)<br>+++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h Tue Aug  2 15:52:42 2011<br>@@ -0,0 +1,109 @@<br>+//===-- PlatformFreeBSD.h -----------------------------------------*- C++ -*-===//<br>+//<br>+//                     The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+<br>+#ifndef liblldb_PlatformFreeBSD_h_<br>+#define liblldb_PlatformFreeBSD_h_<br>+<br>+// C Includes<br>+// C++ Includes<br>+// Other libraries and framework includes<br>+// Project includes<br>+#include "lldb/Target/Platform.h"<br>+<br>+namespace lldb_private {<br>+<br>+    class PlatformFreeBSD : public Platform<br>+    {<br>+    public:<br>+<br>+        static void<br>+        Initialize ();<br>+<br>+        static void<br>+        Terminate ();<br>+        <br>+        PlatformFreeBSD ();<br>+<br>+        virtual<br>+        ~PlatformFreeBSD();<br>+<br>+        //------------------------------------------------------------<br>+        // lldb_private::PluginInterface functions<br>+        //------------------------------------------------------------<br>+        static Platform *<br>+        CreateInstance ();<br>+<br>+        static const char *<br>+        GetPluginNameStatic();<br>+<br>+        static const char *<br>+        GetPluginDescriptionStatic();<br>+<br>+        virtual const char *<br>+        GetPluginName()<br>+        {<br>+            return GetPluginNameStatic();<br>+        }<br>+        <br>+        virtual const char *<br>+        GetShortPluginName()<br>+        {<br>+            return "PlatformFreeBSD";<br>+        }<br>+        <br>+        virtual uint32_t<br>+        GetPluginVersion()<br>+        {<br>+            return 1;<br>+        }<br>+<br>+        //------------------------------------------------------------<br>+        // lldb_private::Platform functions<br>+        //------------------------------------------------------------<br>+        virtual Error<br>+        ResolveExecutable (const FileSpec &exe_file,<br>+                           const ArchSpec &arch,<br>+                           lldb::ModuleSP &module_sp);<br>+<br>+        virtual const char *<br>+        GetDescription ()<br>+        {<br>+            return GetPluginDescriptionStatic();<br>+        }<br>+<br>+        virtual void<br>+        GetStatus (Stream &strm);<br>+<br>+        virtual Error<br>+        GetFile (const FileSpec &platform_file,<br>+                 const UUID* uuid, FileSpec &local_file);<br>+<br>+        virtual bool<br>+        GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &proc_info);<br>+<br>+        virtual bool<br>+        GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch);<br>+<br>+        virtual size_t<br>+        GetSoftwareBreakpointTrapOpcode (Target &target, <br>+                                         BreakpointSite *bp_site);<br>+<br>+        virtual lldb::ProcessSP<br>+        Attach(lldb::pid_t pid, Debugger &debugger, Target *target,<br>+               Listener &listener, Error &error);<br>+<br>+    protected:<br>+        <br>+        <br>+    private:<br>+        DISALLOW_COPY_AND_ASSIGN (PlatformFreeBSD);<br>+    };<br>+} // namespace lldb_private<br>+<br>+#endif  // liblldb_PlatformFreeBSD_h_<br><br>Modified: lldb/trunk/source/Plugins/Platform/Makefile<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Makefile?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Makefile?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/source/Plugins/Platform/Makefile (original)<br>+++ lldb/trunk/source/Plugins/Platform/Makefile Tue Aug  2 15:52:42 2011<br>@@ -19,6 +19,10 @@<br><br> ifeq ($(HOST_OS),Linux)<br>   DIRS += Linux<br>-endif  <br>+endif<br>+<br>+ifeq ($(HOST_OS),FreeBSD)<br>+  DIRS += FreeBSD<br>+endif<br><br> include $(LLDB_LEVEL)/Makefile<br><br>Modified: lldb/trunk/source/lldb.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/source/lldb.cpp (original)<br>+++ lldb/trunk/source/lldb.cpp Tue Aug  2 15:52:42 2011<br>@@ -56,6 +56,10 @@<br> #include "Plugins/Process/Linux/ProcessLinux.h"<br> #endif<br><br>+#if defined (__FreeBSD__)<br>+#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"<br>+#endif<br>+<br> #include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"<br> #include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"<br><br>@@ -116,6 +120,9 @@<br>         ProcessLinux::Initialize();<br>         DynamicLoaderLinuxDYLD::Initialize();<br> #endif<br>+#if defined (__FreeBSD__)<br>+<span class="Apple-tab-span" style="white-space:pre">  </span><span class="Apple-tab-span" style="white-space:pre">    </span>PlatformFreeBSD::Initialize();<br>+#endif<br>         //----------------------------------------------------------------------<br>         // Platform agnostic plugins<br>         //----------------------------------------------------------------------<br>@@ -181,6 +188,10 @@<br>     ProcessLinux::Terminate();<br>     DynamicLoaderLinuxDYLD::Terminate();<br> #endif<br>+<br>+#if defined (__FreeBSD__)<br>+<span class="Apple-tab-span" style="white-space:pre">   </span>PlatformFreeBSD::Terminate();<br>+#endif<br><br>     DynamicLoaderStatic::Terminate();<br><br><br>Modified: lldb/trunk/tools/driver/IOChannel.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/IOChannel.h?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/IOChannel.h?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/tools/driver/IOChannel.h (original)<br>+++ lldb/trunk/tools/driver/IOChannel.h Tue Aug  2 15:52:42 2011<br>@@ -13,7 +13,11 @@<br> #include <string><br> #include <queue><br><br>+#if defined(__FreeBSD__)<br>+#include <readline/readline.h><br>+#else<br> #include <editline/readline.h><br>+#endif<br> #include <histedit.h><br> #include <pthread.h><br> #include <sys/time.h><br><br>Modified: lldb/trunk/tools/driver/Makefile<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Makefile?rev=136720&r1=136719&r2=136720&view=diff">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Makefile?rev=136720&r1=136719&r2=136720&view=diff</a><br>==============================================================================<br>--- lldb/trunk/tools/driver/Makefile (original)<br>+++ lldb/trunk/tools/driver/Makefile Tue Aug  2 15:52:42 2011<br>@@ -23,3 +23,9 @@<br> <span class="Apple-tab-span" style="white-space:pre">   </span>LD.Flags += -Wl,-rpath,$(LibDir)<br> endif<br><br>+ifeq ($(HOST_OS),FreeBSD)<br>+<span class="Apple-tab-span" style="white-space:pre">   </span>CPP.Flags += -I/usr/include/edit #-v<br>+<span class="Apple-tab-span" style="white-space:pre">     </span>LD.Flags += -lEnhancedDisassembly<br>+<span class="Apple-tab-span" style="white-space:pre">        </span>LD.Flags += -Wl,-rpath,$(LibDir)<br>+endif<br>+<br><br><br>_______________________________________________<br>lldb-commits mailing list<br><a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits<br></div></blockquote></div><br></body></html>