diff options
author | Greg Clayton <gclayton@apple.com> | 2010-10-17 22:03:32 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2010-10-17 22:03:32 +0000 |
commit | dd36defda7a1feb8f60478810adc897e7a15c00b (patch) | |
tree | 519d79f27a94b37b0580a05a3195c38179cf1038 /lldb/source | |
parent | 95b6f045f1f104b96d443c404755c2757b6f6cf7 (diff) | |
download | bcm5719-llvm-dd36defda7a1feb8f60478810adc897e7a15c00b.tar.gz bcm5719-llvm-dd36defda7a1feb8f60478810adc897e7a15c00b.zip |
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/Core/FileSpec.cpp | 55 | ||||
-rw-r--r-- | lldb/source/Expression/IRDynamicChecks.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Host/common/Host.cpp | 153 | ||||
-rw-r--r-- | lldb/source/Host/macosx/Host.mm | 156 | ||||
-rw-r--r-- | lldb/source/Host/macosx/cfcpp/CFCMutableArray.cpp | 43 | ||||
-rw-r--r-- | lldb/source/Host/macosx/cfcpp/CFCMutableArray.h | 5 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 61 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | 73 | ||||
-rw-r--r-- | lldb/source/Target/Target.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Target/TargetList.cpp | 2 |
10 files changed, 441 insertions, 111 deletions
diff --git a/lldb/source/Core/FileSpec.cpp b/lldb/source/Core/FileSpec.cpp index 45cfc120a4b..1768a063035 100644 --- a/lldb/source/Core/FileSpec.cpp +++ b/lldb/source/Core/FileSpec.cpp @@ -574,42 +574,37 @@ FileSpec::GetFilename() const bool FileSpec::GetPath(char *path, size_t max_path_length) const { - if (max_path_length == 0) - return false; - - path[0] = '\0'; - const char *dirname = m_directory.AsCString(); - const char *filename = m_filename.AsCString(); - if (dirname) + if (max_path_length) { - if (filename && filename[0]) + const char *dirname = m_directory.AsCString(); + const char *filename = m_filename.AsCString(); + if (dirname) { - return (size_t)::snprintf (path, max_path_length, "%s/%s", dirname, filename) < max_path_length; + if (filename) + { + return (size_t)::snprintf (path, max_path_length, "%s/%s", dirname, filename) < max_path_length; + } + else + { + size_t dir_len = m_directory.GetLength() + 1; + if (dir_len < max_path_length) + { + ::memcpy (path, dirname, dir_len); + return true; + } + } } - else + else if (filename) { - ::strncpy (path, dirname, max_path_length); + size_t filename_len = m_filename.GetLength() + 1; + if (filename_len < max_path_length) + { + ::memcpy (path, filename, filename_len); + return true; + } } } - else if (filename) - { - ::strncpy (path, filename, max_path_length); - } - else - { - return false; - } - - // Any code paths that reach here assume that strncpy, or a similar function was called - // where any remaining bytes will be filled with NULLs and that the string won't be - // NULL terminated if it won't fit in the buffer. - - // If the last character is NULL, then all went well - if (path[max_path_length-1] == '\0') - return true; - - // Make sure the path is terminated, as it didn't fit into "path" - path[max_path_length-1] = '\0'; + path[0] = '\0'; return false; } diff --git a/lldb/source/Expression/IRDynamicChecks.cpp b/lldb/source/Expression/IRDynamicChecks.cpp index 16e5d3d3f01..ca2f8d0af57 100644 --- a/lldb/source/Expression/IRDynamicChecks.cpp +++ b/lldb/source/Expression/IRDynamicChecks.cpp @@ -33,7 +33,7 @@ static const char g_valid_pointer_check_text[] = "extern \"C\" void\n" "$__lldb_valid_pointer_check (unsigned char *$__lldb_arg_ptr)\n" "{\n" -" unsigned char $__lldb_local_val = *__lldb_arg_ptr;\n" +" unsigned char $__lldb_local_val = *$__lldb_arg_ptr;\n" "}"; static bool FunctionExists(const SymbolContext &sym_ctx, const char *name) diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index 16e1ea9459a..ea96e65f6cb 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -626,12 +626,140 @@ Host::GetModuleFileSpecForHostAddress (const void *host_addr) #if !defined (__APPLE__) // see Host.mm bool -Host::ResolveExecutableInBundle (FileSpec *file) +Host::ResolveExecutableInBundle (FileSpec &file) { - return false; + return false; } #endif + +bool +Host::GetLLDBPath (PathType path_type, FileSpec &file_spec) +{ + // To get paths related to LLDB we get the path to the exectuable that + // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB", + // on linux this is assumed to be the "lldb" main executable. If LLDB on + // linux is actually in a shared library (lldb.so??) then this function will + // need to be modified to "do the right thing". + + switch (path_type) + { + case ePathTypeLLDBShlibDir: + { + static ConstString g_lldb_so_dir; + if (!g_lldb_so_dir) + { + FileSpec lldb_file_spec (Host::GetModuleFileSpecForHostAddress ((void *)Host::GetLLDBPath)); + g_lldb_so_dir = lldb_file_spec.GetDirectory(); + } + file_spec.GetDirectory() = g_lldb_so_dir; + return file_spec.GetDirectory(); + } + break; + + case ePathTypeSupportExecutableDir: + { + static ConstString g_lldb_support_exe_dir; + if (!g_lldb_support_exe_dir) + { + FileSpec lldb_file_spec; + if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) + { + char raw_path[PATH_MAX]; + char resolved_path[PATH_MAX]; + lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); + +#if defined (__APPLE__) + char *framework_pos = ::strstr (raw_path, "LLDB.framework"); + if (framework_pos) + { + framework_pos += strlen("LLDB.framework"); + ::strncpy (framework_pos, "/Resources", PATH_MAX - (framework_pos - raw_path)); + } +#endif + FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); + g_lldb_support_exe_dir.SetCString(resolved_path); + } + } + file_spec.GetDirectory() = g_lldb_support_exe_dir; + return file_spec.GetDirectory(); + } + break; + + case ePathTypeHeaderDir: + { + static ConstString g_lldb_headers_dir; + if (!g_lldb_headers_dir) + { +#if defined (__APPLE__) + FileSpec lldb_file_spec; + if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) + { + char raw_path[PATH_MAX]; + char resolved_path[PATH_MAX]; + lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); + + char *framework_pos = ::strstr (raw_path, "LLDB.framework"); + if (framework_pos) + { + framework_pos += strlen("LLDB.framework"); + ::strncpy (framework_pos, "/Headers", PATH_MAX - (framework_pos - raw_path)); + } + FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); + g_lldb_headers_dir.SetCString(resolved_path); + } +#else + // TODO: Anyone know how we can determine this for linux?? + g_lldb_headers_dir.SetCString ("/opt/local/include/lldb"); +#endif + } + file_spec.GetDirectory() = g_lldb_headers_dir; + return file_spec.GetDirectory(); + } + break; + + case ePathTypePythonDir: + { + // TODO: Anyone know how we can determine this for linux?? + // For linux we are currently assuming the location of the lldb + // binary that contains this function is the directory that will + // contain lldb.so, lldb.py and embedded_interpreter.py... + + static ConstString g_lldb_python_dir; + if (!g_lldb_python_dir) + { + FileSpec lldb_file_spec; + if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) + { + char raw_path[PATH_MAX]; + char resolved_path[PATH_MAX]; + lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); + +#if defined (__APPLE__) + char *framework_pos = ::strstr (raw_path, "LLDB.framework"); + if (framework_pos) + { + framework_pos += strlen("LLDB.framework"); + ::strncpy (framework_pos, "/Resources/Python", PATH_MAX - (framework_pos - raw_path)); + } +#endif + FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); + g_lldb_python_dir.SetCString(resolved_path); + } + } + file_spec.GetDirectory() = g_lldb_python_dir; + return file_spec.GetDirectory(); + } + break; + + default: + assert (!"Unhandled PathType"); + break; + } + + return false; +} + uint32_t Host::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids) { @@ -727,4 +855,25 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no) { return false; } + + +lldb::pid_t +LaunchApplication (const FileSpec &app_file_spec) +{ + return LLDB_INVALID_PROCESS_ID; +} + +lldb::pid_t +Host::LaunchInNewTerminal +( + const char **argv, + const char **envp, + const ArchSpec *arch_spec, + bool stop_at_entry, + bool disable_aslr +) +{ + return LLDB_INVALID_PROCESS_ID; +} + #endif diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm index e3379d07cca..298aec4029c 100644 --- a/lldb/source/Host/macosx/Host.mm +++ b/lldb/source/Host/macosx/Host.mm @@ -8,10 +8,18 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/Host.h" + +#include <sys/types.h> +#include <sys/stat.h> + +#include "lldb/Core/ArchSpec.h" #include "lldb/Core/FileSpec.h" #include "lldb/Core/Log.h" +#include "lldb/Core/StreamFile.h" +#include "lldb/Core/StreamString.h" #include "cfcpp/CFCBundle.h" +#include "cfcpp/CFCMutableArray.h" #include "cfcpp/CFCMutableDictionary.h" #include "cfcpp/CFCReleaser.h" #include "cfcpp/CFCString.h" @@ -90,26 +98,26 @@ Host::ThreadCreated (const char *thread_name) bool -Host::ResolveExecutableInBundle (FileSpec *file) +Host::ResolveExecutableInBundle (FileSpec &file) { #if defined (__APPLE__) - if (file->GetFileType () == FileSpec::eFileTypeDirectory) - { - char path[PATH_MAX]; - if (file->GetPath(path, sizeof(path))) + if (file.GetFileType () == FileSpec::eFileTypeDirectory) { - CFCBundle bundle (path); - CFCReleaser<CFURLRef> url(bundle.CopyExecutableURL ()); - if (url.get()) - { - if (::CFURLGetFileSystemRepresentation (url.get(), YES, (UInt8*)path, sizeof(path))) + char path[PATH_MAX]; + if (file.GetPath(path, sizeof(path))) { - file->SetFile(path); - return true; + CFCBundle bundle (path); + CFCReleaser<CFURLRef> url(bundle.CopyExecutableURL ()); + if (url.get()) + { + if (::CFURLGetFileSystemRepresentation (url.get(), YES, (UInt8*)path, sizeof(path))) + { + file.SetFile(path); + return true; + } + } } - } } - } #endif return false; } @@ -124,8 +132,8 @@ Host::LaunchApplication (const FileSpec &app_file_spec) ::bzero (&app_params, sizeof (app_params)); app_params.flags = kLSLaunchDefaults | kLSLaunchDontAddToRecents | - kLSLaunchDontSwitch | - kLSLaunchNewInstance;// | 0x00001000; + kLSLaunchNewInstance; + FSRef app_fsref; CFCString app_cfstr (app_path, kCFStringEncodingUTF8); @@ -150,6 +158,122 @@ Host::LaunchApplication (const FileSpec &app_file_spec) return pid; } +lldb::pid_t +Host::LaunchInNewTerminal +( + const char **argv, + const char **envp, + const ArchSpec *arch_spec, + bool stop_at_entry, + bool disable_aslr +) +{ + if (!argv || !argv[0]) + return LLDB_INVALID_PROCESS_ID; + + OSStatus error = 0; + + FileSpec program (argv[0]); + + + char temp_file_path[PATH_MAX]; + const char *tmpdir = ::getenv ("TMPDIR"); + if (tmpdir == NULL) + tmpdir = "/tmp/"; + ::snprintf (temp_file_path, sizeof(temp_file_path), "%s%s-XXXXXX", tmpdir, program.GetFilename().AsCString()); + + if (::mktemp (temp_file_path) == NULL) + return LLDB_INVALID_PROCESS_ID; + + ::strncat (temp_file_path, ".command", sizeof (temp_file_path)); + + StreamFile command_file (temp_file_path, "w"); + + FileSpec darwin_debug_file_spec; + if (!Host::GetLLDBPath (ePathTypeSupportExecutableDir, darwin_debug_file_spec)) + return LLDB_INVALID_PROCESS_ID; + darwin_debug_file_spec.GetFilename().SetCString("darwin-debug"); + + if (!darwin_debug_file_spec.Exists()) + return LLDB_INVALID_PROCESS_ID; + + char launcher_path[PATH_MAX]; + darwin_debug_file_spec.GetPath(launcher_path, sizeof(launcher_path)); + command_file.Printf("\"%s\" ", launcher_path); + + if (arch_spec && arch_spec->IsValid()) + { + command_file.Printf("--arch=%s ", arch_spec->AsCString()); + } + + if (disable_aslr) + { + command_file.PutCString("--disable-aslr "); + } + + command_file.PutCString("-- "); + + if (argv) + { + for (size_t i=0; argv[i] != NULL; ++i) + { + command_file.Printf("\"%s\" ", argv[i]); + } + } + command_file.EOL(); + command_file.Close(); + if (::chmod (temp_file_path, S_IRWXU | S_IRWXG) != 0) + return LLDB_INVALID_PROCESS_ID; + + CFCMutableDictionary cf_env_dict; + + const bool can_create = true; + if (envp) + { + for (size_t i=0; envp[i] != NULL; ++i) + { + const char *env_entry = envp[i]; + const char *equal_pos = strchr(env_entry, '='); + if (equal_pos) + { + std::string env_key (env_entry, equal_pos); + std::string env_val (equal_pos + 1); + CFCString cf_env_key (env_key.c_str(), kCFStringEncodingUTF8); + CFCString cf_env_val (env_val.c_str(), kCFStringEncodingUTF8); + cf_env_dict.AddValue (cf_env_key.get(), cf_env_val.get(), can_create); + } + } + } + + LSApplicationParameters app_params; + ::bzero (&app_params, sizeof (app_params)); + app_params.flags = kLSLaunchDontAddToRecents | kLSLaunchAsync; + app_params.argv = NULL; + app_params.environment = (CFDictionaryRef)cf_env_dict.get(); + + CFCReleaser<CFURLRef> command_file_url (::CFURLCreateFromFileSystemRepresentation (NULL, + (const UInt8 *)temp_file_path, + strlen (temp_file_path), + false)); + + CFCMutableArray urls; + + // Terminal.app will open the ".command" file we have created + // and run our process inside it which will wait at the entry point + // for us to attach. + urls.AppendValue(command_file_url.get()); + + ProcessSerialNumber psn; + error = LSOpenURLsWithRole(urls.get(), kLSRolesShell, NULL, &app_params, &psn, 1); + + if (error != noErr) + return LLDB_INVALID_PROCESS_ID; + + ::pid_t pid = LLDB_INVALID_PROCESS_ID; + error = ::GetProcessPID(&psn, &pid); + return pid; +} + bool Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no) { diff --git a/lldb/source/Host/macosx/cfcpp/CFCMutableArray.cpp b/lldb/source/Host/macosx/cfcpp/CFCMutableArray.cpp index 3b92f03fa61..c3c0a11193a 100644 --- a/lldb/source/Host/macosx/cfcpp/CFCMutableArray.cpp +++ b/lldb/source/Host/macosx/cfcpp/CFCMutableArray.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "CFCMutableArray.h" +#include "CFCString.h" //---------------------------------------------------------------------- // CFCString constructor @@ -121,3 +122,45 @@ CFCMutableArray::AppendValue(const void *value, bool can_create) } return false; } + + +bool +CFCMutableArray::AppendCStringAsCFString (const char *s, CFStringEncoding encoding, bool can_create) +{ + CFMutableArrayRef array = get(); + if (array == NULL) + { + if (can_create == false) + return false; + array = ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); + reset ( array ); + } + if (array != NULL) + { + CFCString cf_str (s, encoding); + ::CFArrayAppendValue (array, cf_str.get()); + return true; + } + return false; +} + +bool +CFCMutableArray::AppendFileSystemRepresentationAsCFString (const char *s, bool can_create) +{ + CFMutableArrayRef array = get(); + if (array == NULL) + { + if (can_create == false) + return false; + array = ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); + reset ( array ); + } + if (array != NULL) + { + CFCString cf_path; + cf_path.SetFileSystemRepresentation(s); + ::CFArrayAppendValue (array, cf_path.get()); + return true; + } + return false; +} diff --git a/lldb/source/Host/macosx/cfcpp/CFCMutableArray.h b/lldb/source/Host/macosx/cfcpp/CFCMutableArray.h index eaadb8d5590..f78cd92ffab 100644 --- a/lldb/source/Host/macosx/cfcpp/CFCMutableArray.h +++ b/lldb/source/Host/macosx/cfcpp/CFCMutableArray.h @@ -29,6 +29,11 @@ public: const void * GetValueAtIndex(CFIndex idx) const; bool SetValueAtIndex(CFIndex idx, const void *value); bool AppendValue(const void *value, bool can_create = true); // Appends value and optionally creates a CFCMutableArray if this class doesn't contain one + bool AppendCStringAsCFString (const char *cstr, + CFStringEncoding encoding = kCFStringEncodingUTF8, + bool can_create = true); + bool AppendFileSystemRepresentationAsCFString (const char *s, + bool can_create = true); }; #endif // #ifndef CoreFoundationCPP_CFMutableArray_h_ diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index 42d2ef46438..9520150efab 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -164,34 +164,42 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete // Find the module that owns this code and use that path we get to // set the PYTHONPATH appropriately. - FileSpec this_module (Host::GetModuleFileSpecForHostAddress ((void *)init_lldb)); - std::string python_path; - - if (this_module.GetDirectory()) + FileSpec file_spec; + char python_dir_path[PATH_MAX]; + if (Host::GetLLDBPath (ePathTypePythonDir, file_spec)) { - // Append the directory that the module that loaded this code - // belongs to - python_path += this_module.GetDirectory().AsCString(""); - -#if defined (__APPLE__) - // If we are running on MacOSX we might be in a framework and should - // add an appropriate path so Resource can be found in a bundle + std::string python_path; + const char *curr_python_path = ::getenv ("PYTHONPATH"); + if (curr_python_path) + { + // We have a current value for PYTHONPATH, so lets append to it + python_path.append (curr_python_path); + } - if (::strstr(this_module.GetDirectory().AsCString(""), ".framework")) + if (file_spec.GetPath(python_dir_path, sizeof (python_dir_path))) + { + if (!python_path.empty()) + python_path.append (1, ':'); + python_path.append (python_dir_path); + } + + if (Host::GetLLDBPath (ePathTypeLLDBShlibDir, file_spec)) { - python_path.append(1, ':'); - python_path.append(this_module.GetDirectory().AsCString("")); - python_path.append("/Resources/Python"); + if (file_spec.GetPath(python_dir_path, sizeof (python_dir_path))) + { + if (!python_path.empty()) + python_path.append (1, ':'); + python_path.append (python_dir_path); + } } -#endif - // The the PYTHONPATH environment variable so that Python can find - // our lldb.py module and our _lldb.so. - ::setenv ("PYTHONPATH", python_path.c_str(), 1); + const char *pathon_path_env_cstr = python_path.c_str(); + ::setenv ("PYTHONPATH", pathon_path_env_cstr, 1); } Py_Initialize (); - PyObject *compiled_module = Py_CompileString (embedded_interpreter_string, "embedded_interpreter.py", + PyObject *compiled_module = Py_CompileString (embedded_interpreter_string, + "embedded_interpreter.py", Py_file_input); m_compiled_module = static_cast<void*>(compiled_module); @@ -310,14 +318,15 @@ ScriptInterpreterPython::InputReaderCallback int input_fd; FILE *input_fh = reader.GetDebugger().GetInputFileHandle(); if (input_fh != NULL) - input_fd = ::fileno (input_fh); + input_fd = ::fileno (input_fh); else - input_fd = STDIN_FILENO; + input_fd = STDIN_FILENO; script_interpreter->m_termios_valid = ::tcgetattr (input_fd, &script_interpreter->m_termios) == 0; - struct termios tmp_termios; - if (::tcgetattr (input_fd, &tmp_termios) == 0) + + if (script_interpreter->m_termios_valid) { + struct termios tmp_termios = script_interpreter->m_termios; tmp_termios.c_cc[VEOF] = _POSIX_VDISABLE; ::tcsetattr (input_fd, TCSANOW, &tmp_termios); } @@ -352,9 +361,9 @@ ScriptInterpreterPython::InputReaderCallback int input_fd; FILE *input_fh = reader.GetDebugger().GetInputFileHandle(); if (input_fh != NULL) - input_fd = ::fileno (input_fh); + input_fd = ::fileno (input_fh); else - input_fd = STDIN_FILENO; + input_fd = STDIN_FILENO; ::tcsetattr (input_fd, TCSANOW, &script_interpreter->m_termios); } diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index c9b5955ee09..3da1d59aa70 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -384,12 +384,28 @@ ProcessGDBRemote::DoLaunch { Error error; #if defined (LAUNCH_WITH_LAUNCH_SERVICES) - FileSpec app_file_spec (argv[0]); - pid_t pid = Host::LaunchApplication (app_file_spec); + ArchSpec inferior_arch(module->GetArchitecture()); + + //FileSpec app_file_spec (argv[0]); + pid_t pid = Host::LaunchInNewTerminal (argv, + envp, + &inferior_arch, + true, // stop at entry + (launch_flags & eLaunchFlagDisableASLR) != 0); + + // Let the app get launched and stopped... + sleep (1); + if (pid != LLDB_INVALID_PROCESS_ID) - error = DoAttachToProcessWithID (pid); + { + FileSpec program(argv[0]); + error = DoAttachToProcessWithName (program.GetFilename().AsCString(), false); + //error = DoAttachToProcessWithID (pid); + } else - error.SetErrorString("failed"); + { + error.SetErrorString("Host::LaunchApplication(() failed to launch process"); + } #else // ::LogSetBitMask (GDBR_LOG_DEFAULT); // ::LogSetOptions (LLDB_LOG_OPTION_THREADSAFE | LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD); @@ -1683,31 +1699,19 @@ ProcessGDBRemote::StartDebugserverProcess { // The debugserver binary is in the LLDB.framework/Resources // directory. - FileSpec framework_file_spec (Host::GetModuleFileSpecForHostAddress ((void *)lldb_private::Initialize)); - const char *framework_dir = framework_file_spec.GetDirectory().AsCString(); - const char *lldb_framework = ::strstr (framework_dir, "/LLDB.framework"); - - if (lldb_framework) + if (Host::GetLLDBPath (ePathTypeSupportExecutableDir, debugserver_file_spec)) { - int len = lldb_framework - framework_dir + strlen ("/LLDB.framework"); - ::snprintf (debugserver_path, - sizeof(debugserver_path), - "%.*s/Resources/%s", - len, - framework_dir, - DEBUGSERVER_BASENAME); - debugserver_file_spec.SetFile (debugserver_path); + debugserver_file_spec.GetFilename().SetCString(DEBUGSERVER_BASENAME); debugserver_exists = debugserver_file_spec.Exists(); - } - - if (debugserver_exists) - { - g_debugserver_file_spec = debugserver_file_spec; - } - else - { - g_debugserver_file_spec.Clear(); - debugserver_file_spec.Clear(); + if (debugserver_exists) + { + g_debugserver_file_spec = debugserver_file_spec; + } + else + { + g_debugserver_file_spec.Clear(); + debugserver_file_spec.Clear(); + } } } @@ -1731,9 +1735,9 @@ ProcessGDBRemote::StartDebugserverProcess #if !defined (__arm__) - // We don't need to do this for ARM, and we really shouldn't now that we - // have multiple CPU subtypes and no posix_spawnattr call that allows us - // to set which CPU subtype to launch... + // We don't need to do this for ARM, and we really shouldn't now + // that we have multiple CPU subtypes and no posix_spawnattr call + // that allows us to set which CPU subtype to launch... if (inferior_arch.GetType() == eArchTypeMachO) { cpu_type_t cpu = inferior_arch.GetCPUType(); @@ -1781,10 +1785,11 @@ ProcessGDBRemote::StartDebugserverProcess // Start args with "debugserver /file/path -r --" debugserver_args.AppendArgument(debugserver_path); debugserver_args.AppendArgument(debugserver_url); - debugserver_args.AppendArgument("--native-regs"); // use native registers, not the GDB registers - debugserver_args.AppendArgument("--setsid"); // make debugserver run in its own session so - // signals generated by special terminal key - // sequences (^C) don't affect debugserver + // use native registers, not the GDB registers + debugserver_args.AppendArgument("--native-regs"); + // make debugserver run in its own session so signals generated by + // special terminal key sequences (^C) don't affect debugserver + debugserver_args.AppendArgument("--setsid"); if (disable_aslr) debugserver_args.AppendArguments("--disable-aslr"); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 4a5ce2fa21b..943fda41143 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -402,7 +402,7 @@ Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files) { FileSpec bundle_executable(executable_sp->GetFileSpec()); - if (Host::ResolveExecutableInBundle (&bundle_executable)) + if (Host::ResolveExecutableInBundle (bundle_executable)) { ModuleSP bundle_exe_module_sp(GetSharedModule(bundle_executable, exe_arch)); diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp index 6033a60cf86..bb99a44bc5d 100644 --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -75,7 +75,7 @@ TargetList::CreateTarget if (!resolved_file.Exists()) resolved_file.ResolveExecutableLocation (); - if (!Host::ResolveExecutableInBundle (&resolved_file)) + if (!Host::ResolveExecutableInBundle (resolved_file)) resolved_file = file; error = ModuleList::GetSharedModule(resolved_file, |