[lldb-dev] Fwd: [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/

Johnny Chen johnny.chen at apple.com
Tue Aug 2 13:55:36 PDT 2011


Thanks, David!

Begin forwarded message:

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20110802/e948239f/attachment.html>


More information about the lldb-dev mailing list