summaryrefslogtreecommitdiffstats
path: root/lldb/tools
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2010-10-17 22:03:32 +0000
committerGreg Clayton <gclayton@apple.com>2010-10-17 22:03:32 +0000
commitdd36defda7a1feb8f60478810adc897e7a15c00b (patch)
tree519d79f27a94b37b0580a05a3195c38179cf1038 /lldb/tools
parent95b6f045f1f104b96d443c404755c2757b6f6cf7 (diff)
downloadbcm5719-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/tools')
-rw-r--r--lldb/tools/darwin-debug/darwin-debug.cpp221
-rw-r--r--lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj1
2 files changed, 221 insertions, 1 deletions
diff --git a/lldb/tools/darwin-debug/darwin-debug.cpp b/lldb/tools/darwin-debug/darwin-debug.cpp
new file mode 100644
index 00000000000..f79d837e634
--- /dev/null
+++ b/lldb/tools/darwin-debug/darwin-debug.cpp
@@ -0,0 +1,221 @@
+//===-- Launcher.cpp --------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//----------------------------------------------------------------------
+// Darwin launch helper
+//
+// This program was written to allow programs to be launched in a new
+// Terminal.app window and have the application be stopped for debugging
+// at the program entry point.
+//
+// Although it uses posix_spawn(), it uses Darwin specific posix spawn
+// attribute flags to accomplish its task. It uses an "exec only" flag
+// which avoids forking this process, and it uses a "stop at entry"
+// flag to stop the program at the entry point.
+//
+// Since it uses darwin specific flags this code should not be compiled
+// on other systems.
+//----------------------------------------------------------------------
+#if defined (__APPLE__)
+
+#include <getopt.h>
+#include <mach/machine.h>
+#include <spawn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef _POSIX_SPAWN_DISABLE_ASLR
+#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
+#endif
+
+#define streq(a,b) strcmp(a,b) == 0
+
+static struct option g_long_options[] =
+{
+ { "arch", required_argument, NULL, 'a' },
+ { "disable-aslr", no_argument, NULL, 'd' },
+ { "no-env", no_argument, NULL, 'e' },
+ { "help", no_argument, NULL, 'h' },
+ { "setsid", no_argument, NULL, 's' },
+ { NULL, 0, NULL, 0 }
+};
+
+static void
+usage()
+{
+ puts (
+"NAME\n"
+" darwin-debug -- posix spawn a process that is stopped at the entry point\n"
+" for debugging.\n"
+"\n"
+"SYNOPSIS\n"
+" darwin-debug [--arch=<ARCH>] [--disable-aslr] [--no-env] [--setsid] [--help] -- <PROGRAM> [<PROGRAM-ARG> <PROGRAM-ARG> ....]\n"
+"\n"
+"DESCRIPTION\n"
+" darwin-debug will exec itself into a child process <PROGRAM> that is\n"
+" halted for debugging. It does this by using posix_spawn() along with\n"
+" darwin specific posix_spawn flags that allows exec only (no fork), and\n"
+" stop at the program entry point. Any program arguments <PROGRAM-ARG> are\n"
+" passed on to the exec as the arguments for the new process. The current\n"
+" environment will be passed to the new process unless the \"--no-env\"\n"
+" option is used.\n"
+"\n"
+"EXAMPLE\n"
+" darwin-debug --arch=i386 -- /bin/ls -al /tmp\n"
+);
+ exit (1);
+}
+
+static void
+exit_with_errno (int err, const char *prefix)
+{
+ if (err)
+ {
+ fprintf (stderr,
+ "%s%s",
+ prefix ? prefix : "",
+ strerror(err));
+ exit (err);
+ }
+}
+
+pid_t
+posix_spawn_for_debug (const char *path, char *const *argv, char *const *envp, cpu_type_t cpu_type, int disable_aslr)
+{
+ pid_t pid = 0;
+
+ posix_spawnattr_t attr;
+
+ exit_with_errno (::posix_spawnattr_init (&attr), "::posix_spawnattr_init (&attr) error: ");
+
+ // Here we are using a darwin specific feature that allows us to exec only
+ // since we want this program to turn into the program we want to debug,
+ // and also have the new program start suspended (right at __dyld_start)
+ // so we can debug it
+ short flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETEXEC;
+
+ // Disable ASLR if we were asked to
+ if (disable_aslr)
+ flags |= _POSIX_SPAWN_DISABLE_ASLR;
+
+ // Set the flags we just made into our posix spawn attributes
+ exit_with_errno (::posix_spawnattr_setflags (&attr, flags), "::posix_spawnattr_setflags (&attr, flags) error: ");
+
+
+ // Another darwin specific thing here where we can select the architecture
+ // of the binary we want to re-exec as.
+ if (cpu_type != 0)
+ {
+ size_t ocount = 0;
+ exit_with_errno (::posix_spawnattr_setbinpref_np (&attr, 1, &cpu_type, &ocount), "posix_spawnattr_setbinpref_np () error: ");
+ }
+
+ exit_with_errno (::posix_spawnp (&pid, path, NULL, &attr, (char * const*)argv, (char * const*)envp), "posix_spawn() error: ");
+
+ // This code will only be reached if the posix_spawn exec failed...
+ ::posix_spawnattr_destroy (&attr);
+
+ return pid;
+}
+
+
+int main (int argc, char *const *argv, char *const *envp, const char **apple)
+{
+ const char *program_name = strrchr(apple[0], '/');
+
+ if (program_name)
+ program_name++; // Skip the last slash..
+ else
+ program_name = apple[0];
+
+#if defined (DEBUG_LLDB_LAUNCHER)
+ printf("%s called with:\n", program_name);
+ for (int i=0; i<argc; ++i)
+ printf("argv[%u] = '%s'\n", i, argv[i]);
+#endif
+
+ cpu_type_t cpu_type = 0;
+ bool show_usage = false;
+ char ch;
+ int disable_aslr = 0; // By default we disable ASLR
+ int pass_env = 1;
+ while ((ch = getopt_long(argc, argv, "a:dfh?", g_long_options, NULL)) != -1)
+ {
+ switch (ch)
+ {
+ case 0:
+ break;
+
+ case 'a': // "-a i386" or "--arch=i386"
+ if (optarg)
+ {
+ if (streq (optarg, "i386"))
+ cpu_type = CPU_TYPE_I386;
+ else if (streq (optarg, "x86_64"))
+ cpu_type = CPU_TYPE_X86_64;
+ else if (strstr (optarg, "arm") == optarg)
+ cpu_type = CPU_TYPE_ARM;
+ else
+ {
+ ::fprintf (stderr, "error: unsupported cpu type '%s'\n", optarg);
+ ::exit (1);
+ }
+ }
+ break;
+
+ case 'd':
+ disable_aslr = 1;
+ break;
+
+ case 'e':
+ pass_env = 0;
+ break;
+
+ case 's':
+ // Create a new session to avoid having control-C presses kill our current
+ // terminal session when this program is launched from a .command file
+ ::setsid();
+ break;
+
+ case 'h':
+ case '?':
+ default:
+ show_usage = true;
+ break;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (show_usage || argc <= 0)
+ usage();
+
+#if defined (DEBUG_LLDB_LAUNCHER)
+ printf ("\n%s post options:\n", program_name);
+ for (int i=0; i<argc; ++i)
+ printf ("argv[%u] = '%s'\n", i, argv[i]);
+#endif
+
+ const char *exe_path = argv[0];
+
+ // Skip this inferior program name...
+ ++argv;
+
+ posix_spawn_for_debug (exe_path,
+ argv,
+ pass_env ? envp : NULL,
+ cpu_type,
+ disable_aslr);
+
+ return 0;
+}
+
+#endif // #if defined (__APPLE__)
+
diff --git a/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj b/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj
index 9cbe29e084b..6c5d9738175 100644
--- a/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj
+++ b/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj
@@ -369,7 +369,6 @@
isa = PBXProject;
buildConfigurationList = 1DEB914E08733D8E0010E9CD /* Build configuration list for PBXProject "debugserver" */;
compatibilityVersion = "Xcode 3.1";
- developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
OpenPOWER on IntegriCloud