diff options
Diffstat (limited to 'tools/driver')
-rw-r--r-- | tools/driver/Driver.cpp | 43 | ||||
-rw-r--r-- | tools/driver/Platform.h | 15 |
2 files changed, 22 insertions, 36 deletions
diff --git a/tools/driver/Driver.cpp b/tools/driver/Driver.cpp index f02b081b8f0f..91b92d25f434 100644 --- a/tools/driver/Driver.cpp +++ b/tools/driver/Driver.cpp @@ -51,7 +51,6 @@ static void reset_stdin_termios (); static bool g_old_stdin_termios_is_valid = false; static struct termios g_old_stdin_termios; -static char *g_debugger_name = (char *) ""; static Driver *g_driver = NULL; // In the Driver::MainLoop, we change the terminal settings. This function is @@ -146,16 +145,12 @@ Driver::Driver () : // We want to be able to handle CTRL+D in the terminal to have it terminate // certain input m_debugger.SetCloseInputOnEOF (false); - g_debugger_name = (char *) m_debugger.GetInstanceName(); - if (g_debugger_name == NULL) - g_debugger_name = (char *) ""; g_driver = this; } Driver::~Driver () { g_driver = NULL; - g_debugger_name = NULL; } @@ -872,7 +867,6 @@ PrepareCommandsForSourcing (const char *commands_data, size_t commands_size, int { enum PIPES { READ, WRITE }; // Constants 0 and 1 for READ and WRITE - bool success = true; ::FILE *commands_file = NULL; fds[0] = -1; fds[1] = -1; @@ -887,10 +881,9 @@ PrepareCommandsForSourcing (const char *commands_data, size_t commands_size, int ssize_t nrwr = write(fds[WRITE], commands_data, commands_size); if (nrwr < 0) { - fprintf(stderr, "error: write(%i, %p, %zd) failed (errno = %i) " + fprintf(stderr, "error: write(%i, %p, %" PRIu64 ") failed (errno = %i) " "when trying to open LLDB commands pipe\n", - fds[WRITE], commands_data, commands_size, errno); - success = false; + fds[WRITE], commands_data, static_cast<uint64_t>(commands_size), errno); } else if (static_cast<size_t>(nrwr) == commands_size) { @@ -916,14 +909,12 @@ PrepareCommandsForSourcing (const char *commands_data, size_t commands_size, int "error: fdopen(%i, \"r\") failed (errno = %i) when " "trying to open LLDB commands pipe\n", fds[READ], errno); - success = false; } } } else { fprintf(stderr, "error: can't create pipe file descriptors for LLDB commands\n"); - success = false; } return commands_file; @@ -956,6 +947,18 @@ CleanupAfterCommandSourcing (int fds[2]) } +std::string +EscapeString (std::string arg) +{ + std::string::size_type pos = 0; + while ((pos = arg.find_first_of("\"\\", pos)) != std::string::npos) + { + arg.insert (pos, 1, '\\'); + pos += 2; + } + return '"' + arg + '"'; +} + void Driver::MainLoop () { @@ -1005,13 +1008,13 @@ Driver::MainLoop () { char arch_name[64]; if (m_debugger.GetDefaultArchitecture (arch_name, sizeof (arch_name))) - commands_stream.Printf("target create --arch=%s \"%s\"", arch_name, m_option_data.m_args[0].c_str()); + commands_stream.Printf("target create --arch=%s %s", arch_name, EscapeString(m_option_data.m_args[0]).c_str()); else - commands_stream.Printf("target create \"%s\"", m_option_data.m_args[0].c_str()); + commands_stream.Printf("target create %s", EscapeString(m_option_data.m_args[0]).c_str()); if (!m_option_data.m_core_file.empty()) { - commands_stream.Printf(" --core \"%s\"", m_option_data.m_core_file.c_str()); + commands_stream.Printf(" --core %s", EscapeString(m_option_data.m_core_file).c_str()); } commands_stream.Printf("\n"); @@ -1019,23 +1022,17 @@ Driver::MainLoop () { commands_stream.Printf ("settings set -- target.run-args "); for (size_t arg_idx = 1; arg_idx < num_args; ++arg_idx) - { - const char *arg_cstr = m_option_data.m_args[arg_idx].c_str(); - if (strchr(arg_cstr, '"') == NULL) - commands_stream.Printf(" \"%s\"", arg_cstr); - else - commands_stream.Printf(" '%s'", arg_cstr); - } + commands_stream.Printf(" %s", EscapeString(m_option_data.m_args[arg_idx]).c_str()); commands_stream.Printf("\n"); } } else if (!m_option_data.m_core_file.empty()) { - commands_stream.Printf("target create --core \"%s\"\n", m_option_data.m_core_file.c_str()); + commands_stream.Printf("target create --core %s\n", EscapeString(m_option_data.m_core_file).c_str()); } else if (!m_option_data.m_process_name.empty()) { - commands_stream.Printf ("process attach --name \"%s\"", m_option_data.m_process_name.c_str()); + commands_stream.Printf ("process attach --name %s", EscapeString(m_option_data.m_process_name).c_str()); if (m_option_data.m_wait_for) commands_stream.Printf(" --waitfor"); diff --git a/tools/driver/Platform.h b/tools/driver/Platform.h index 8995512a0f8f..c42d7e3da9d4 100644 --- a/tools/driver/Platform.h +++ b/tools/driver/Platform.h @@ -10,12 +10,11 @@ #ifndef lldb_Platform_h_ #define lldb_Platform_h_ -#include "lldb/Host/HostGetOpt.h" - #if defined( _WIN32 ) // this will stop signal.h being included #define _INC_SIGNAL + #include "lldb/Host/HostGetOpt.h" #include <io.h> #if defined( _MSC_VER ) #include <eh.h> @@ -93,7 +92,7 @@ extern int tcgetattr( int fildes, struct termios *termios_p ); #else - + #include "lldb/Host/HostGetOpt.h" #include <inttypes.h> #include <libgen.h> @@ -103,16 +102,6 @@ #include <pthread.h> #include <sys/time.h> - -#if !defined(__ANDROID_NDK__) - #include <histedit.h> - #if defined(__FreeBSD__) || defined(__NetBSD__) - #include <readline/readline.h> - #else - #include <editline/readline.h> - #endif -#endif - #endif #endif // lldb_Platform_h_ |