[Lldb-commits] [lldb] r200565 - Fixing the Windows build for the changes brought in from the iohandler merge.
Deepak Panickal
deepak at codeplay.com
Fri Jan 31 10:48:47 PST 2014
Author: panickal
Date: Fri Jan 31 12:48:46 2014
New Revision: 200565
URL: http://llvm.org/viewvc/llvm-project?rev=200565&view=rev
Log:
Fixing the Windows build for the changes brought in from the iohandler merge.
Added:
lldb/trunk/include/lldb/Host/HostGetOpt.h
lldb/trunk/include/lldb/Host/windows/GetOptInc.h
lldb/trunk/include/lldb/Host/windows/editlinewin.h
lldb/trunk/source/Host/windows/EditLineWin.cpp
lldb/trunk/source/Host/windows/GetOptInc.cpp
Removed:
lldb/trunk/source/Host/windows/msvc/
lldb/trunk/tools/driver/ELWrapper.cpp
lldb/trunk/tools/driver/ELWrapper.h
lldb/trunk/tools/driver/GetOptWrapper.cpp
lldb/trunk/tools/driver/GetOptWrapper.h
Modified:
lldb/trunk/CMakeLists.txt
lldb/trunk/include/lldb/Host/Editline.h
lldb/trunk/source/Commands/CommandObjectGUI.cpp
lldb/trunk/source/Commands/CommandObjectType.cpp
lldb/trunk/source/Core/IOHandler.cpp
lldb/trunk/source/Host/common/OptionParser.cpp
lldb/trunk/source/Host/windows/CMakeLists.txt
lldb/trunk/source/Target/Process.cpp
lldb/trunk/tools/driver/CMakeLists.txt
lldb/trunk/tools/driver/Platform.h
lldb/trunk/tools/lldb-platform/lldb-platform.cpp
Modified: lldb/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/CMakeLists.txt?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/CMakeLists.txt (original)
+++ lldb/trunk/CMakeLists.txt Fri Jan 31 12:48:46 2014
@@ -1,10 +1,14 @@
if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
set(LLDB_DEFAULT_DISABLE_PYTHON 1)
+ set(LLDB_DEFAULT_DISABLE_CURSES 1)
else()
set(LLDB_DEFAULT_DISABLE_PYTHON 0)
+ set(LLDB_DEFAULT_DISABLE_CURSES 0)
endif()
set(LLDB_DISABLE_PYTHON ${LLDB_DEFAULT_DISABLE_PYTHON} CACHE BOOL
"Disables the Python scripting integration.")
+set(LLDB_DISABLE_CURSES ${LLDB_DEFAULT_DISABLE_CURSES} CACHE BOOL
+ "Disables the Curses integration.")
# If we are not building as a part of LLVM, build LLDB as an
# standalone project, using LLVM as an external library:
@@ -77,6 +81,10 @@ if (LLDB_DISABLE_PYTHON)
add_definitions( -DLLDB_DISABLE_PYTHON )
endif()
+if (LLDB_DISABLE_CURSES)
+ add_definitions( -DLLDB_DISABLE_CURSES )
+endif()
+
macro(add_lldb_definitions)
# We don't want no semicolons on LLDB_DEFINITIONS:
foreach(arg ${ARGN})
@@ -182,7 +190,10 @@ macro(add_lldb_library name)
else()
set(libkind STATIC)
endif()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
+ #PIC not needed on Win
+ if (NOT MSVC)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
+ endif()
add_library(${name} ${libkind} ${srcs})
#if (LLVM_COMMON_DEPENDS)
##add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
@@ -269,6 +280,22 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux")
list(APPEND system_libs ncurses panel)
endif()
+
+# Disable RTTI by default
+if(NOT LLDB_REQUIRES_RTTI)
+ if (NOT MSVC)
+ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR
+ "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+ #gnu && clang compilers
+ set(LLDB_COMPILE_FLAGS "-fno-rtti")
+ endif() #GNU or CLANG
+ else()
+ #MSVC
+ set(LLDB_COMPILE_FLAGS "/GR-")
+ endif() #NOT MSVC
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLDB_COMPILE_FLAGS}")
+endif()
+
#add_subdirectory(include)
add_subdirectory(docs)
if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
Modified: lldb/trunk/include/lldb/Host/Editline.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Editline.h?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Editline.h (original)
+++ lldb/trunk/include/lldb/Host/Editline.h Fri Jan 31 12:48:46 2014
@@ -15,7 +15,7 @@
#include <stdio.h>
#ifdef _WIN32
-#include "ELWrapper.h"
+#include "lldb/Host/windows/editlinewin.h"
#else
#include <histedit.h>
#endif
Added: lldb/trunk/include/lldb/Host/HostGetOpt.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostGetOpt.h?rev=200565&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Host/HostGetOpt.h (added)
+++ lldb/trunk/include/lldb/Host/HostGetOpt.h Fri Jan 31 12:48:46 2014
@@ -0,0 +1,20 @@
+//===-- GetOpt.h ------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#pragma once
+
+#ifndef _MSC_VER
+
+#include <unistd.h>
+#include <getopt.h>
+
+#else
+
+#include <lldb/Host/windows/GetOptInc.h>
+
+#endif
\ No newline at end of file
Added: lldb/trunk/include/lldb/Host/windows/GetOptInc.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/GetOptInc.h?rev=200565&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Host/windows/GetOptInc.h (added)
+++ lldb/trunk/include/lldb/Host/windows/GetOptInc.h Fri Jan 31 12:48:46 2014
@@ -0,0 +1,46 @@
+#pragma once
+
+// from getopt.h
+#define no_argument 0
+#define required_argument 1
+#define optional_argument 2
+
+// option structure
+struct option
+{
+ const char *name;
+ // has_arg can't be an enum because some compilers complain about
+ // type mismatches in all the code that assumes it is an int.
+ int has_arg;
+ int *flag;
+ int val;
+};
+
+int getopt( int argc, char * const argv[], const char *optstring );
+
+// from getopt.h
+extern char * optarg;
+extern int optind;
+extern int opterr;
+extern int optopt;
+
+// defined in unistd.h
+extern int optreset;
+
+int getopt_long
+(
+ int argc,
+ char * const *argv,
+ const char *optstring,
+ const struct option *longopts,
+ int *longindex
+);
+
+int getopt_long_only
+(
+ int argc,
+ char * const *argv,
+ const char *optstring,
+ const struct option *longopts,
+ int *longindex
+);
Added: lldb/trunk/include/lldb/Host/windows/editlinewin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/editlinewin.h?rev=200565&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Host/windows/editlinewin.h (added)
+++ lldb/trunk/include/lldb/Host/windows/editlinewin.h Fri Jan 31 12:48:46 2014
@@ -0,0 +1,123 @@
+//===-- ELWrapper.h ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#pragma once
+
+#include <stdio.h>
+
+// EditLine editor function return codes.
+// For user-defined function interface
+#define CC_NORM 0
+#define CC_NEWLINE 1
+#define CC_EOF 2
+#define CC_ARGHACK 3
+#define CC_REFRESH 4
+#define CC_CURSOR 5
+#define CC_ERROR 6
+#define CC_FATAL 7
+#define CC_REDISPLAY 8
+#define CC_REFRESH_BEEP 9
+
+// el_set/el_get parameters
+#define EL_PROMPT 0 // , el_pfunc_t
+#define EL_TERMINAL 1 // , const char *
+#define EL_EDITOR 2 // , const char *
+#define EL_SIGNAL 3 // , int);
+#define EL_BIND 4 // , const char *, ..., NULL
+#define EL_TELLTC 5 // , const char *, ..., NULL
+#define EL_SETTC 6 // , const char *, ..., NULL
+#define EL_ECHOTC 7 // , const char *, ..., NULL
+#define EL_SETTY 8 // , const char *, ..., NULL
+#define EL_ADDFN 9 // , const char *, const char *, el_func_t
+#define EL_HIST 10 // , hist_fun_t, const char *
+#define EL_EDITMODE 11 // , int
+#define EL_RPROMPT 12 // , el_pfunc_t
+#define EL_GETCFN 13 // , el_rfunc_t
+#define EL_CLIENTDATA 14 // , void *
+#define EL_UNBUFFERED 15 // , int
+#define EL_PREP_TERM 16 // , int
+#define EL_GETTC 17 // , const char *, ..., NULL
+#define EL_GETFP 18 // , int, FILE **
+#define EL_SETFP 19 // , int, FILE *
+#define EL_REFRESH 20 // , void
+#define EL_PROMPT_ESC 21 // , prompt_func, Char); set/get
+
+#define EL_BUILTIN_GETCFN (NULL)
+
+// history defines
+#define H_FUNC 0 // , UTSL
+#define H_SETSIZE 1 // , const int
+#define H_GETSIZE 2 // , void
+#define H_FIRST 3 // , void
+#define H_LAST 4 // , void
+#define H_PREV 5 // , void
+#define H_NEXT 6 // , void
+#define H_CURR 8 // , const int
+#define H_SET 7 // , int
+#define H_ADD 9 // , const char *
+#define H_ENTER 10 // , const char *
+#define H_APPEND 11 // , const char *
+#define H_END 12 // , void
+#define H_NEXT_STR 13 // , const char *
+#define H_PREV_STR 14 // , const char *
+#define H_NEXT_EVENT 15 // , const int
+#define H_PREV_EVENT 16 // , const int
+#define H_LOAD 17 // , const char *
+#define H_SAVE 18 // , const char *
+#define H_CLEAR 19 // , void
+#define H_SETUNIQUE 20 // , int
+#define H_GETUNIQUE 21 // , void
+#define H_DEL 22 // , int
+
+struct EditLine
+{
+};
+
+struct LineInfo
+{
+ const char *buffer;
+ const char *cursor;
+ const char *lastchar;
+};
+
+struct History
+{
+};
+
+struct HistEvent
+{
+ int num;
+ const char *str;
+};
+
+extern "C"
+{
+ // edit line API
+ EditLine *el_init ( const char *, FILE *, FILE *, FILE * );
+ const char *el_gets ( EditLine *, int * );
+ int el_set ( EditLine *, int, ... );
+
+ void el_end ( EditLine * );
+ void el_reset ( EditLine * );
+ int el_getc ( EditLine *, char * );
+ void el_push ( EditLine *, const char * );
+ void el_beep ( EditLine * );
+ int el_parse ( EditLine *, int, const char ** );
+ int el_get ( EditLine *, int, ... );
+ int el_source ( EditLine *, const char * );
+ void el_resize ( EditLine * );
+ const LineInfo *el_line ( EditLine * );
+ int el_insertstr( EditLine *, const char * );
+ void el_deletestr( EditLine *, int );
+
+ // history API
+ History *history_init( void );
+ void history_end ( History * );
+ int history ( History *, HistEvent *, int, ... );
+};
\ No newline at end of file
Modified: lldb/trunk/source/Commands/CommandObjectGUI.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectGUI.cpp?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectGUI.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectGUI.cpp Fri Jan 31 12:48:46 2014
@@ -38,6 +38,7 @@ CommandObjectGUI::~CommandObjectGUI ()
bool
CommandObjectGUI::DoExecute (Args& args, CommandReturnObject &result)
{
+#ifndef LLDB_DISABLE_CURSES
if (args.GetArgumentCount() == 0)
{
Debugger &debugger = m_interpreter.GetDebugger();
@@ -52,5 +53,9 @@ CommandObjectGUI::DoExecute (Args& args,
result.SetStatus (eReturnStatusFailed);
}
return true;
+#else
+ result.AppendError("lldb was not build with gui support");
+ return false;
+#endif
}
Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Fri Jan 31 12:48:46 2014
@@ -195,6 +195,7 @@ public:
{
StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+#ifndef LLDB_DISABLE_PYTHON
ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
if (interpreter)
{
@@ -309,7 +310,7 @@ public:
error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
error_sp->Flush();
}
-
+#endif // #ifndef LLDB_DISABLE_PYTHON
io_handler.SetIsDone(true);
}
@@ -482,6 +483,7 @@ protected:
{
StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+#ifndef LLDB_DISABLE_PYTHON
ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
if (interpreter)
{
@@ -577,9 +579,8 @@ protected:
error_sp->Flush();
}
+#endif // #ifndef LLDB_DISABLE_PYTHON
io_handler.SetIsDone(true);
-
-
}
public:
Modified: lldb/trunk/source/Core/IOHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/IOHandler.cpp?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/source/Core/IOHandler.cpp (original)
+++ lldb/trunk/source/Core/IOHandler.cpp Fri Jan 31 12:48:46 2014
@@ -11,8 +11,10 @@
#include "lldb/lldb-python.h"
#include <stdio.h> /* ioctl, TIOCGWINSZ */
-#include <sys/ioctl.h> /* ioctl, TIOCGWINSZ */
+#ifndef _MSC_VER
+#include <sys/ioctl.h> /* ioctl, TIOCGWINSZ */
+#endif
#include <string>
@@ -31,8 +33,10 @@
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/ThreadPlan.h"
+#ifndef LLDB_DISABLE_CURSES
#include <ncurses.h>
#include <panel.h>
+#endif
using namespace lldb;
using namespace lldb_private;
@@ -328,9 +332,10 @@ IOHandlerEditline::IOHandlerEditline (De
{
SetPrompt(prompt);
+ bool use_editline = false;
+#ifndef _MSC_VER
const int in_fd = GetInputFD();
struct winsize window_size;
- bool use_editline = false;
if (isatty (in_fd))
{
m_interactive = true;
@@ -340,6 +345,9 @@ IOHandlerEditline::IOHandlerEditline (De
use_editline = true;
}
}
+#else
+ use_editline = true;
+#endif
if (use_editline)
{
@@ -588,6 +596,10 @@ IOHandlerEditline::GotEOF()
m_editline_ap->Interrupt();
}
+// we may want curses to be disabled for some builds
+// for instance, windows
+#ifndef LLDB_DISABLE_CURSES
+
#include "lldb/Core/ValueObject.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/Target.h"
@@ -5274,3 +5286,4 @@ IOHandlerCursesGUI::GotEOF()
{
}
+#endif // #ifndef LLDB_DISABLE_CURSES
\ No newline at end of file
Modified: lldb/trunk/source/Host/common/OptionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/OptionParser.cpp?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/OptionParser.cpp (original)
+++ lldb/trunk/source/Host/common/OptionParser.cpp Fri Jan 31 12:48:46 2014
@@ -9,14 +9,10 @@
#include "lldb/Host/OptionParser.h"
-#ifdef _MSC_VER
-#include "../windows/msvc/getopt.inc"
-#else
-#ifdef _WIN32
+#if (!defined( _MSC_VER ) && defined( _WIN32 ))
#define _BSD_SOURCE // Required so that getopt.h defines optreset
#endif
-#include <getopt.h>
-#endif
+#include "lldb/Host/HostGetOpt.h"
using namespace lldb_private;
Modified: lldb/trunk/source/Host/windows/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/CMakeLists.txt?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/CMakeLists.txt (original)
+++ lldb/trunk/source/Host/windows/CMakeLists.txt Fri Jan 31 12:48:46 2014
@@ -6,4 +6,6 @@ add_lldb_library(lldbHostWindows
Mutex.cpp
Condition.cpp
Windows.cpp
+ EditLineWin.cpp
+ GetOptInc.cpp
)
Added: lldb/trunk/source/Host/windows/EditLineWin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/EditLineWin.cpp?rev=200565&view=auto
==============================================================================
--- lldb/trunk/source/Host/windows/EditLineWin.cpp (added)
+++ lldb/trunk/source/Host/windows/EditLineWin.cpp Fri Jan 31 12:48:46 2014
@@ -0,0 +1,422 @@
+//===-- ELWrapper.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// this file is only relevant for Visual C++
+#if defined( _MSC_VER )
+
+#include "lldb/Host/windows/windows.h"
+
+#include "lldb/Host/windows/editlinewin.h"
+#include <vector>
+#include <assert.h>
+
+// index one of the variable arguments
+// presuming "(EditLine *el, ..." is first in the argument list
+#define GETARG( X ) ( (void* ) *( ( (int**) &el ) + ((X) + 2) ) )
+
+// edit line EL_ADDFN function pointer type
+typedef unsigned char (*el_addfn_func)(EditLine *e, int ch);
+
+// edit line wrapper binding container
+struct el_binding
+{
+ //
+ const char *name;
+ const char *help;
+ // function pointer to callback routine
+ el_addfn_func func;
+ // ascii key this function is bound to
+ const char *key;
+};
+
+// stored key bindings
+static std::vector<el_binding*> _bindings;
+
+//TODO: this should infact be related to the exact edit line context we create
+static void *clientData = NULL;
+
+// store the current prompt string
+// default to what we expect to receive anyway
+static const char *_prompt = "(lldb) ";
+
+#if !defined( _WIP_INPUT_METHOD )
+
+static char *
+el_get_s (char *buffer, int chars)
+{
+ return gets_s(buffer, chars);
+}
+#else
+
+static void
+con_output (char _in)
+{
+ HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
+ DWORD written = 0;
+ // get the cursor position
+ CONSOLE_SCREEN_BUFFER_INFO info;
+ GetConsoleScreenBufferInfo( hout, &info );
+ // output this char
+ WriteConsoleOutputCharacterA( hout, &_in, 1, info.dwCursorPosition, &written );
+ // advance cursor position
+ info.dwCursorPosition.X++;
+ SetConsoleCursorPosition( hout, info.dwCursorPosition );
+}
+
+static void
+con_backspace (void)
+{
+ HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
+ DWORD written = 0;
+ // get cursor position
+ CONSOLE_SCREEN_BUFFER_INFO info;
+ GetConsoleScreenBufferInfo( hout, &info );
+ // nudge cursor backwards
+ info.dwCursorPosition.X--;
+ SetConsoleCursorPosition( hout, info.dwCursorPosition );
+ // blank out the last character
+ WriteConsoleOutputCharacterA( hout, " ", 1, info.dwCursorPosition, &written );
+}
+
+static void
+con_return (void)
+{
+ HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
+ DWORD written = 0;
+ // get cursor position
+ CONSOLE_SCREEN_BUFFER_INFO info;
+ GetConsoleScreenBufferInfo( hout, &info );
+ // move onto the new line
+ info.dwCursorPosition.X = 0;
+ info.dwCursorPosition.Y++;
+ SetConsoleCursorPosition( hout, info.dwCursorPosition );
+}
+
+static bool
+runBind (char _key)
+{
+ for ( int i=0; i<_bindings.size(); i++ )
+ {
+ el_binding *bind = _bindings[i];
+ if ( bind->key[0] == _key )
+ {
+ bind->func( (EditLine*) -1, _key );
+ return true;
+ }
+ }
+ return false;
+}
+
+// replacement get_s which is EL_BIND aware
+static char *
+el_get_s (char *buffer, int chars)
+{
+ //
+ char *head = buffer;
+ //
+ for ( ;; Sleep( 10 ) )
+ {
+ //
+ INPUT_RECORD _record;
+ //
+ DWORD _read = 0;
+ if ( ReadConsoleInputA( GetStdHandle( STD_INPUT_HANDLE ), &_record, 1, &_read ) == FALSE )
+ break;
+ // if we didnt read a key
+ if ( _read == 0 )
+ continue;
+ // only interested in key events
+ if ( _record.EventType != KEY_EVENT )
+ continue;
+ // is the key down
+ if (! _record.Event.KeyEvent.bKeyDown )
+ continue;
+ // read the ascii key character
+ char _key = _record.Event.KeyEvent.uChar.AsciiChar;
+ // non ascii conformant key press
+ if ( _key == 0 )
+ {
+ // check the scan code
+ // if VK_UP scroll back through history
+ // if VK_DOWN scroll forward through history
+ continue;
+ }
+ // try to execute any bind this key may have
+ if ( runBind( _key ) )
+ continue;
+ // if we read a return key
+ if ( _key == '\n' || _key == '\r' )
+ {
+ con_return( );
+ break;
+ }
+ // key is backspace
+ if ( _key == 0x8 )
+ {
+ // avoid deleting past beginning
+ if ( head > buffer )
+ {
+ con_backspace( );
+ head--;
+ }
+ continue;
+ }
+
+ // add this key to the input buffer
+ if ( (head-buffer) < (chars-1) )
+ {
+ con_output( _key );
+ *(head++) = _key;
+ }
+ }
+ // insert end of line character
+ *head = '\0';
+
+ return buffer;
+}
+#endif
+
+// edit line initalise
+EditLine *
+el_init (const char *, FILE *, FILE *, FILE *)
+{
+ //
+ SetConsoleTitleA( "lldb" );
+ // return dummy handle
+ return (EditLine*) -1;
+}
+
+const char *
+el_gets (EditLine *el, int *length)
+{
+ // print the prompt if we have one
+ if ( _prompt != NULL )
+ printf( _prompt );
+ // create a buffer for the user input
+ char *buffer = new char[ MAX_PATH ];
+ // try to get user input string
+ if ( el_get_s( buffer, MAX_PATH ) )
+ {
+ // get the string length in 'length'
+ while ( buffer[ *length ] != '\0' )
+ (*length)++;
+ // return the input buffer
+ // remember that this memory has the be free'd somewhere
+ return buffer;
+ }
+ else
+ {
+ // on error
+ delete [] buffer;
+ return NULL;
+ }
+}
+
+int
+el_set (EditLine *el, int code, ...)
+{
+ int **arg = (int**) ⪙
+ //
+ switch ( code )
+ {
+ // edit line set prompt message
+ case ( EL_PROMPT ):
+ {
+ // EL_PROMPT, char *(*f)( EditLine *)
+ // define a prompt printing function as 'f', which is to return a string that
+ // contains the prompt.
+
+ // get the function pointer from the arg list
+ void *func_vp = (void*) *(arg+2);
+ // cast to suitable prototype
+ const char* (*func_fp)(EditLine*) = (const char*(*)(EditLine *)) func_vp;
+ // call to get the prompt as a string
+ _prompt = func_fp( el );
+ }
+ break;
+ case ( EL_EDITOR ):
+ {
+ // EL_EDITOR, const char *mode
+ // set editing mode to "emacs" or "vi"
+ }
+ break;
+ case ( EL_HIST ):
+ {
+ // EL_HIST, History *(*fun)(History *, int op, ... ), const char *ptr
+ // defines which histroy function to use, which is usualy history(). Ptr should be the
+ // value returned by history_init().
+ }
+ break;
+ case ( EL_ADDFN ):
+ {
+ // EL_ADDFN, const char *name, const char *help, unsigned char (*func)(EditLine *e, int ch)
+ // add a user defined function, func), referred to as 'name' which is invoked when a key which is bound to 'name' is
+ // entered. 'help' is a description of 'name'. at involcation time, 'ch' is the key which caused the invocation. the
+ // return value of 'func()' should be one of:
+ // CC_NORM add a normal character
+ // CC_NEWLINE end of line was entered
+ // CC_EOF EOF was entered
+ // CC_ARGHACK expecting further command input as arguments, do nothing visually.
+ // CC_REFRESH refresh display.
+ // CC_REFRESH_BEEP refresh display and beep.
+ // CC_CURSOR cursor moved so update and perform CC_REFRESH
+ // CC_REDISPLAY redisplay entire input line. this is usefull if a key binding outputs extra information.
+ // CC_ERROR an error occured. beep and flush tty.
+ // CC_FATAL fatal error, reset tty to known state.
+
+ el_binding *binding = new el_binding;
+ binding->name = (const char *) GETARG( 0 );
+ binding->help = (const char *) GETARG( 1 );
+ binding->func = (el_addfn_func) GETARG( 2 );
+ binding->key = 0;
+ // add this to the bindings list
+ _bindings.push_back( binding );
+ }
+ break;
+ case ( EL_BIND ):
+ {
+ // EL_BIND, const char *, ..., NULL
+ // perform the BIND buildin command. Refer to editrc(5) for more information.
+
+ const char *name = (const char*) GETARG( 1 );
+
+ for ( int i=0; i<_bindings.size(); i++ )
+ {
+ el_binding *bind = _bindings[i];
+ if ( strcmp( bind->name, name ) == 0 )
+ {
+ bind->key = (const char *) GETARG( 0 );
+ break;
+ }
+ }
+
+ }
+ break;
+ case ( EL_CLIENTDATA ):
+ {
+ clientData = GETARG( 0 );
+ }
+ break;
+// default:
+// assert( !"Not Implemented!" );
+ }
+ return 0;
+}
+
+void
+el_end (EditLine *el)
+{
+ assert( !"Not implemented!" );
+}
+
+void
+el_reset (EditLine *)
+{
+ assert( !"Not implemented!" );
+}
+
+int
+el_getc (EditLine *, char *)
+{
+ assert( !"Not implemented!" );
+ return 0;
+}
+
+void
+el_push (EditLine *, const char *)
+{
+// assert( !"Not implemented!" );
+}
+
+void
+el_beep (EditLine *)
+{
+ Beep( 1000, 500 );
+}
+
+int
+el_parse (EditLine *, int, const char **)
+{
+ assert( !"Not implemented!" );
+ return 0;
+}
+
+int
+el_get (EditLine *el, int code, ...)
+{
+ switch ( code )
+ {
+ case ( EL_CLIENTDATA ):
+ {
+ void **dout = (void**) GETARG( 0 );
+ *dout = clientData;
+ }
+ break;
+ default:
+ assert( !"Not implemented!" );
+ }
+ return 0;
+}
+
+int
+el_source (EditLine *el, const char *file)
+{
+ // init edit line by reading the contents of 'file'
+ // nothing to do here on windows...
+ return 0;
+}
+
+void
+el_resize (EditLine *)
+{
+ assert( !"Not implemented!" );
+}
+
+const LineInfo *
+el_line (EditLine *el)
+{
+ assert( !"Not implemented!" );
+ return 0;
+}
+
+int
+el_insertstr (EditLine *, const char *)
+{
+ assert( !"Not implemented!" );
+ return 0;
+}
+
+void
+el_deletestr (EditLine *, int)
+{
+ assert( !"Not implemented!" );
+}
+
+History *
+history_init (void)
+{
+ // return dummy handle
+ return (History*) -1;
+}
+
+void
+history_end (History *)
+{
+ assert( !"Not implemented!" );
+}
+
+int
+history (History *, HistEvent *, int op, ...)
+{
+ // perform operation 'op' on the history list with optional argumetns as needed by
+ // the operation.
+ return 0;
+}
+
+#endif
Added: lldb/trunk/source/Host/windows/GetOptInc.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/GetOptInc.cpp?rev=200565&view=auto
==============================================================================
--- lldb/trunk/source/Host/windows/GetOptInc.cpp (added)
+++ lldb/trunk/source/Host/windows/GetOptInc.cpp Fri Jan 31 12:48:46 2014
@@ -0,0 +1,469 @@
+#include "lldb/Host/windows/GetOptInc.h"
+
+// getopt.cpp
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+int opterr = 1; /* if error message should be printed */
+int optind = 1; /* index into parent argv vector */
+int optopt = '?'; /* character checked for validity */
+int optreset; /* reset getopt */
+char *optarg; /* argument associated with option */
+
+#define PRINT_ERROR ((opterr) && (*options != ':'))
+
+#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
+#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
+#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
+
+/* return values */
+#define BADCH (int)'?'
+#define BADARG ((*options == ':') ? (int)':' : (int)'?')
+#define INORDER (int)1
+
+#define EMSG ""
+
+static int getopt_internal(int, char * const *, const char *,
+ const struct option *, int *, int);
+static int parse_long_options(char * const *, const char *,
+ const struct option *, int *, int);
+static int gcd(int, int);
+static void permute_args(int, int, int, char * const *);
+
+static char *place = EMSG; /* option letter processing */
+
+/* XXX: set optreset to 1 rather than these two */
+static int nonopt_start = -1; /* first non option argument (for permute) */
+static int nonopt_end = -1; /* first option after non options (for permute) */
+
+/* Error messages */
+static const char recargchar[] = "option requires an argument -- %c";
+static const char recargstring[] = "option requires an argument -- %s";
+static const char ambig[] = "ambiguous option -- %.*s";
+static const char noarg[] = "option doesn't take an argument -- %.*s";
+static const char illoptchar[] = "unknown option -- %c";
+static const char illoptstring[] = "unknown option -- %s";
+
+/*
+* Compute the greatest common divisor of a and b.
+*/
+static int
+gcd(int a, int b)
+{
+ int c;
+
+ c = a % b;
+ while (c != 0) {
+ a = b;
+ b = c;
+ c = a % b;
+ }
+
+ return (b);
+}
+
+static void pass() {}
+#define warnx(a, ...) pass();
+
+/*
+* Exchange the block from nonopt_start to nonopt_end with the block
+* from nonopt_end to opt_end (keeping the same order of arguments
+* in each block).
+*/
+static void
+permute_args(int panonopt_start, int panonopt_end, int opt_end,
+char * const *nargv)
+{
+ int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+ char *swap;
+
+ /*
+ * compute lengths of blocks and number and size of cycles
+ */
+ nnonopts = panonopt_end - panonopt_start;
+ nopts = opt_end - panonopt_end;
+ ncycle = gcd(nnonopts, nopts);
+ cyclelen = (opt_end - panonopt_start) / ncycle;
+
+ for (i = 0; i < ncycle; i++) {
+ cstart = panonopt_end + i;
+ pos = cstart;
+ for (j = 0; j < cyclelen; j++) {
+ if (pos >= panonopt_end)
+ pos -= nnonopts;
+ else
+ pos += nopts;
+ swap = nargv[pos];
+ /* LINTED const cast */
+ ((char **)nargv)[pos] = nargv[cstart];
+ /* LINTED const cast */
+ ((char **)nargv)[cstart] = swap;
+ }
+ }
+}
+
+/*
+* parse_long_options --
+* Parse long options in argc/argv argument vector.
+* Returns -1 if short_too is set and the option does not match long_options.
+*/
+static int
+parse_long_options(char * const *nargv, const char *options,
+const struct option *long_options, int *idx, int short_too)
+{
+ char *current_argv, *has_equal;
+ size_t current_argv_len;
+ int i, match;
+
+ current_argv = place;
+ match = -1;
+
+ optind++;
+
+ if ((has_equal = strchr(current_argv, '=')) != NULL) {
+ /* argument found (--option=arg) */
+ current_argv_len = has_equal - current_argv;
+ has_equal++;
+ }
+ else
+ current_argv_len = strlen(current_argv);
+
+ for (i = 0; long_options[i].name; i++) {
+ /* find matching long option */
+ if (strncmp(current_argv, long_options[i].name,
+ current_argv_len))
+ continue;
+
+ if (strlen(long_options[i].name) == current_argv_len) {
+ /* exact match */
+ match = i;
+ break;
+ }
+ /*
+ * If this is a known short option, don't allow
+ * a partial match of a single character.
+ */
+ if (short_too && current_argv_len == 1)
+ continue;
+
+ if (match == -1) /* partial match */
+ match = i;
+ else {
+ /* ambiguous abbreviation */
+ if (PRINT_ERROR)
+ warnx(ambig, (int)current_argv_len,
+ current_argv);
+ optopt = 0;
+ return (BADCH);
+ }
+ }
+ if (match != -1) { /* option found */
+ if (long_options[match].has_arg == no_argument
+ && has_equal) {
+ if (PRINT_ERROR)
+ warnx(noarg, (int)current_argv_len,
+ current_argv);
+ /*
+ * XXX: GNU sets optopt to val regardless of flag
+ */
+ if (long_options[match].flag == NULL)
+ optopt = long_options[match].val;
+ else
+ optopt = 0;
+ return (BADARG);
+ }
+ if (long_options[match].has_arg == required_argument ||
+ long_options[match].has_arg == optional_argument) {
+ if (has_equal)
+ optarg = has_equal;
+ else if (long_options[match].has_arg ==
+ required_argument) {
+ /*
+ * optional argument doesn't use next nargv
+ */
+ optarg = nargv[optind++];
+ }
+ }
+ if ((long_options[match].has_arg == required_argument)
+ && (optarg == NULL)) {
+ /*
+ * Missing argument; leading ':' indicates no error
+ * should be generated.
+ */
+ if (PRINT_ERROR)
+ warnx(recargstring,
+ current_argv);
+ /*
+ * XXX: GNU sets optopt to val regardless of flag
+ */
+ if (long_options[match].flag == NULL)
+ optopt = long_options[match].val;
+ else
+ optopt = 0;
+ --optind;
+ return (BADARG);
+ }
+ }
+ else { /* unknown option */
+ if (short_too) {
+ --optind;
+ return (-1);
+ }
+ if (PRINT_ERROR)
+ warnx(illoptstring, current_argv);
+ optopt = 0;
+ return (BADCH);
+ }
+ if (idx)
+ *idx = match;
+ if (long_options[match].flag) {
+ *long_options[match].flag = long_options[match].val;
+ return (0);
+ }
+ else
+ return (long_options[match].val);
+}
+
+/*
+* getopt_internal --
+* Parse argc/argv argument vector. Called by user level routines.
+*/
+static int
+getopt_internal(int nargc, char * const *nargv, const char *options,
+const struct option *long_options, int *idx, int flags)
+{
+ const char *oli; /* option letter list index */
+ int optchar, short_too;
+ static int posixly_correct = -1;
+
+ if (options == NULL)
+ return (-1);
+
+ /*
+ * XXX Some GNU programs (like cvs) set optind to 0 instead of
+ * XXX using optreset. Work around this braindamage.
+ */
+ if (optind == 0)
+ optind = optreset = 1;
+
+ /*
+ * Disable GNU extensions if POSIXLY_CORRECT is set or options
+ * string begins with a '+'.
+ */
+ if (posixly_correct == -1 || optreset)
+ posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
+ if (*options == '-')
+ flags |= FLAG_ALLARGS;
+ else if (posixly_correct || *options == '+')
+ flags &= ~FLAG_PERMUTE;
+ if (*options == '+' || *options == '-')
+ options++;
+
+ optarg = NULL;
+ if (optreset)
+ nonopt_start = nonopt_end = -1;
+start:
+ if (optreset || !*place) { /* update scanning pointer */
+ optreset = 0;
+ if (optind >= nargc) { /* end of argument vector */
+ place = EMSG;
+ if (nonopt_end != -1) {
+ /* do permutation, if we have to */
+ permute_args(nonopt_start, nonopt_end,
+ optind, nargv);
+ optind -= nonopt_end - nonopt_start;
+ }
+ else if (nonopt_start != -1) {
+ /*
+ * If we skipped non-options, set optind
+ * to the first of them.
+ */
+ optind = nonopt_start;
+ }
+ nonopt_start = nonopt_end = -1;
+ return (-1);
+ }
+ if (*(place = nargv[optind]) != '-' ||
+ (place[1] == '\0' && strchr(options, '-') == NULL)) {
+ place = EMSG; /* found non-option */
+ if (flags & FLAG_ALLARGS) {
+ /*
+ * GNU extension:
+ * return non-option as argument to option 1
+ */
+ optarg = nargv[optind++];
+ return (INORDER);
+ }
+ if (!(flags & FLAG_PERMUTE)) {
+ /*
+ * If no permutation wanted, stop parsing
+ * at first non-option.
+ */
+ return (-1);
+ }
+ /* do permutation */
+ if (nonopt_start == -1)
+ nonopt_start = optind;
+ else if (nonopt_end != -1) {
+ permute_args(nonopt_start, nonopt_end,
+ optind, nargv);
+ nonopt_start = optind -
+ (nonopt_end - nonopt_start);
+ nonopt_end = -1;
+ }
+ optind++;
+ /* process next argument */
+ goto start;
+ }
+ if (nonopt_start != -1 && nonopt_end == -1)
+ nonopt_end = optind;
+
+ /*
+ * If we have "-" do nothing, if "--" we are done.
+ */
+ if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
+ optind++;
+ place = EMSG;
+ /*
+ * We found an option (--), so if we skipped
+ * non-options, we have to permute.
+ */
+ if (nonopt_end != -1) {
+ permute_args(nonopt_start, nonopt_end,
+ optind, nargv);
+ optind -= nonopt_end - nonopt_start;
+ }
+ nonopt_start = nonopt_end = -1;
+ return (-1);
+ }
+ }
+
+ /*
+ * Check long options if:
+ * 1) we were passed some
+ * 2) the arg is not just "-"
+ * 3) either the arg starts with -- we are getopt_long_only()
+ */
+ if (long_options != NULL && place != nargv[optind] &&
+ (*place == '-' || (flags & FLAG_LONGONLY))) {
+ short_too = 0;
+ if (*place == '-')
+ place++; /* --foo long option */
+ else if (*place != ':' && strchr(options, *place) != NULL)
+ short_too = 1; /* could be short option too */
+
+ optchar = parse_long_options(nargv, options, long_options,
+ idx, short_too);
+ if (optchar != -1) {
+ place = EMSG;
+ return (optchar);
+ }
+ }
+
+ if ((optchar = (int)*place++) == (int)':' ||
+ (optchar == (int)'-' && *place != '\0') ||
+ (oli = strchr(options, optchar)) == NULL) {
+ /*
+ * If the user specified "-" and '-' isn't listed in
+ * options, return -1 (non-option) as per POSIX.
+ * Otherwise, it is an unknown option character (or ':').
+ */
+ if (optchar == (int)'-' && *place == '\0')
+ return (-1);
+ if (!*place)
+ ++optind;
+ if (PRINT_ERROR)
+ warnx(illoptchar, optchar);
+ optopt = optchar;
+ return (BADCH);
+ }
+ if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+ /* -W long-option */
+ if (*place) /* no space */
+ /* NOTHING */;
+ else if (++optind >= nargc) { /* no arg */
+ place = EMSG;
+ if (PRINT_ERROR)
+ warnx(recargchar, optchar);
+ optopt = optchar;
+ return (BADARG);
+ }
+ else /* white space */
+ place = nargv[optind];
+ optchar = parse_long_options(nargv, options, long_options,
+ idx, 0);
+ place = EMSG;
+ return (optchar);
+ }
+ if (*++oli != ':') { /* doesn't take argument */
+ if (!*place)
+ ++optind;
+ }
+ else { /* takes (optional) argument */
+ optarg = NULL;
+ if (*place) /* no white space */
+ optarg = place;
+ else if (oli[1] != ':') { /* arg not optional */
+ if (++optind >= nargc) { /* no arg */
+ place = EMSG;
+ if (PRINT_ERROR)
+ warnx(recargchar, optchar);
+ optopt = optchar;
+ return (BADARG);
+ }
+ else
+ optarg = nargv[optind];
+ }
+ place = EMSG;
+ ++optind;
+ }
+ /* dump back option letter */
+ return (optchar);
+}
+
+/*
+* getopt --
+* Parse argc/argv argument vector.
+*
+* [eventually this will replace the BSD getopt]
+*/
+int
+getopt(int nargc, char * const *nargv, const char *options)
+{
+
+ /*
+ * We don't pass FLAG_PERMUTE to getopt_internal() since
+ * the BSD getopt(3) (unlike GNU) has never done this.
+ *
+ * Furthermore, since many privileged programs call getopt()
+ * before dropping privileges it makes sense to keep things
+ * as simple (and bug-free) as possible.
+ */
+ return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
+}
+
+/*
+* getopt_long --
+* Parse argc/argv argument vector.
+*/
+int
+getopt_long(int nargc, char * const *nargv, const char *options,
+const struct option *long_options, int *idx)
+{
+ return (getopt_internal(nargc, nargv, options, long_options, idx,
+ FLAG_PERMUTE));
+}
+
+/*
+* getopt_long_only --
+* Parse argc/argv argument vector.
+*/
+int
+getopt_long_only(int nargc, char * const *nargv, const char *options,
+const struct option *long_options, int *idx)
+{
+
+ return (getopt_internal(nargc, nargv, options, long_options, idx,
+ FLAG_PERMUTE | FLAG_LONGONLY));
+}
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Fri Jan 31 12:48:46 2014
@@ -4751,7 +4751,12 @@ public:
return true;
int fds[2];
+#ifdef _MSC_VER
+ // pipe is not supported on windows so default to a fail condition
+ int err = 1;
+#else
int err = pipe(fds);
+#endif
if (err == 0)
{
m_pipe_read.SetDescriptor(fds[0], true);
@@ -4786,6 +4791,8 @@ public:
Terminal terminal(read_fd);
terminal.SetCanonical(false);
terminal.SetEcho(false);
+// FD_ZERO, FD_SET are not supported on windows
+#ifndef _MSC_VER
while (!GetIsDone())
{
fd_set read_fdset;
@@ -4825,6 +4832,7 @@ public:
}
}
}
+#endif
terminal_state.Restore();
}
Modified: lldb/trunk/tools/driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/CMakeLists.txt?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/tools/driver/CMakeLists.txt (original)
+++ lldb/trunk/tools/driver/CMakeLists.txt Fri Jan 31 12:48:46 2014
@@ -1,12 +1,7 @@
set(LLVM_NO_RTTI 1)
add_lldb_executable(lldb
Driver.cpp
- #DriverEvents.cpp
- #DriverOptions.cpp
- #DriverPosix.cpp
- ELWrapper.cpp
Platform.cpp
- GetOptWrapper.cpp
)
target_link_libraries(lldb liblldb)
Removed: lldb/trunk/tools/driver/ELWrapper.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/ELWrapper.cpp?rev=200564&view=auto
==============================================================================
--- lldb/trunk/tools/driver/ELWrapper.cpp (original)
+++ lldb/trunk/tools/driver/ELWrapper.cpp (removed)
@@ -1,422 +0,0 @@
-//===-- ELWrapper.cpp -------------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// this file is only relevant for Visual C++
-#if defined( _MSC_VER )
-
-#include "lldb/Host/windows/windows.h"
-
-#include "ELWrapper.h"
-#include <vector>
-#include <assert.h>
-
-// index one of the variable arguments
-// presuming "(EditLine *el, ..." is first in the argument list
-#define GETARG( X ) ( (void* ) *( ( (int**) &el ) + ((X) + 2) ) )
-
-// edit line EL_ADDFN function pointer type
-typedef unsigned char (*el_addfn_func)(EditLine *e, int ch);
-
-// edit line wrapper binding container
-struct el_binding
-{
- //
- const char *name;
- const char *help;
- // function pointer to callback routine
- el_addfn_func func;
- // ascii key this function is bound to
- const char *key;
-};
-
-// stored key bindings
-static std::vector<el_binding*> _bindings;
-
-//TODO: this should infact be related to the exact edit line context we create
-static void *clientData = NULL;
-
-// store the current prompt string
-// default to what we expect to receive anyway
-static const char *_prompt = "(lldb) ";
-
-#if !defined( _WIP_INPUT_METHOD )
-
-static char *
-el_get_s (char *buffer, int chars)
-{
- return gets_s(buffer, chars);
-}
-#else
-
-static void
-con_output (char _in)
-{
- HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
- DWORD written = 0;
- // get the cursor position
- CONSOLE_SCREEN_BUFFER_INFO info;
- GetConsoleScreenBufferInfo( hout, &info );
- // output this char
- WriteConsoleOutputCharacterA( hout, &_in, 1, info.dwCursorPosition, &written );
- // advance cursor position
- info.dwCursorPosition.X++;
- SetConsoleCursorPosition( hout, info.dwCursorPosition );
-}
-
-static void
-con_backspace (void)
-{
- HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
- DWORD written = 0;
- // get cursor position
- CONSOLE_SCREEN_BUFFER_INFO info;
- GetConsoleScreenBufferInfo( hout, &info );
- // nudge cursor backwards
- info.dwCursorPosition.X--;
- SetConsoleCursorPosition( hout, info.dwCursorPosition );
- // blank out the last character
- WriteConsoleOutputCharacterA( hout, " ", 1, info.dwCursorPosition, &written );
-}
-
-static void
-con_return (void)
-{
- HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
- DWORD written = 0;
- // get cursor position
- CONSOLE_SCREEN_BUFFER_INFO info;
- GetConsoleScreenBufferInfo( hout, &info );
- // move onto the new line
- info.dwCursorPosition.X = 0;
- info.dwCursorPosition.Y++;
- SetConsoleCursorPosition( hout, info.dwCursorPosition );
-}
-
-static bool
-runBind (char _key)
-{
- for ( int i=0; i<_bindings.size(); i++ )
- {
- el_binding *bind = _bindings[i];
- if ( bind->key[0] == _key )
- {
- bind->func( (EditLine*) -1, _key );
- return true;
- }
- }
- return false;
-}
-
-// replacement get_s which is EL_BIND aware
-static char *
-el_get_s (char *buffer, int chars)
-{
- //
- char *head = buffer;
- //
- for ( ;; Sleep( 10 ) )
- {
- //
- INPUT_RECORD _record;
- //
- DWORD _read = 0;
- if ( ReadConsoleInputA( GetStdHandle( STD_INPUT_HANDLE ), &_record, 1, &_read ) == FALSE )
- break;
- // if we didnt read a key
- if ( _read == 0 )
- continue;
- // only interested in key events
- if ( _record.EventType != KEY_EVENT )
- continue;
- // is the key down
- if (! _record.Event.KeyEvent.bKeyDown )
- continue;
- // read the ascii key character
- char _key = _record.Event.KeyEvent.uChar.AsciiChar;
- // non ascii conformant key press
- if ( _key == 0 )
- {
- // check the scan code
- // if VK_UP scroll back through history
- // if VK_DOWN scroll forward through history
- continue;
- }
- // try to execute any bind this key may have
- if ( runBind( _key ) )
- continue;
- // if we read a return key
- if ( _key == '\n' || _key == '\r' )
- {
- con_return( );
- break;
- }
- // key is backspace
- if ( _key == 0x8 )
- {
- // avoid deleting past beginning
- if ( head > buffer )
- {
- con_backspace( );
- head--;
- }
- continue;
- }
-
- // add this key to the input buffer
- if ( (head-buffer) < (chars-1) )
- {
- con_output( _key );
- *(head++) = _key;
- }
- }
- // insert end of line character
- *head = '\0';
-
- return buffer;
-}
-#endif
-
-// edit line initalise
-EditLine *
-el_init (const char *, FILE *, FILE *, FILE *)
-{
- //
- SetConsoleTitleA( "lldb" );
- // return dummy handle
- return (EditLine*) -1;
-}
-
-const char *
-el_gets (EditLine *el, int *length)
-{
- // print the prompt if we have one
- if ( _prompt != NULL )
- printf( _prompt );
- // create a buffer for the user input
- char *buffer = new char[ MAX_PATH ];
- // try to get user input string
- if ( el_get_s( buffer, MAX_PATH ) )
- {
- // get the string length in 'length'
- while ( buffer[ *length ] != '\0' )
- (*length)++;
- // return the input buffer
- // remember that this memory has the be free'd somewhere
- return buffer;
- }
- else
- {
- // on error
- delete [] buffer;
- return NULL;
- }
-}
-
-int
-el_set (EditLine *el, int code, ...)
-{
- int **arg = (int**) ⪙
- //
- switch ( code )
- {
- // edit line set prompt message
- case ( EL_PROMPT ):
- {
- // EL_PROMPT, char *(*f)( EditLine *)
- // define a prompt printing function as 'f', which is to return a string that
- // contains the prompt.
-
- // get the function pointer from the arg list
- void *func_vp = (void*) *(arg+2);
- // cast to suitable prototype
- const char* (*func_fp)(EditLine*) = (const char*(*)(EditLine *)) func_vp;
- // call to get the prompt as a string
- _prompt = func_fp( el );
- }
- break;
- case ( EL_EDITOR ):
- {
- // EL_EDITOR, const char *mode
- // set editing mode to "emacs" or "vi"
- }
- break;
- case ( EL_HIST ):
- {
- // EL_HIST, History *(*fun)(History *, int op, ... ), const char *ptr
- // defines which histroy function to use, which is usualy history(). Ptr should be the
- // value returned by history_init().
- }
- break;
- case ( EL_ADDFN ):
- {
- // EL_ADDFN, const char *name, const char *help, unsigned char (*func)(EditLine *e, int ch)
- // add a user defined function, func), referred to as 'name' which is invoked when a key which is bound to 'name' is
- // entered. 'help' is a description of 'name'. at involcation time, 'ch' is the key which caused the invocation. the
- // return value of 'func()' should be one of:
- // CC_NORM add a normal character
- // CC_NEWLINE end of line was entered
- // CC_EOF EOF was entered
- // CC_ARGHACK expecting further command input as arguments, do nothing visually.
- // CC_REFRESH refresh display.
- // CC_REFRESH_BEEP refresh display and beep.
- // CC_CURSOR cursor moved so update and perform CC_REFRESH
- // CC_REDISPLAY redisplay entire input line. this is usefull if a key binding outputs extra information.
- // CC_ERROR an error occured. beep and flush tty.
- // CC_FATAL fatal error, reset tty to known state.
-
- el_binding *binding = new el_binding;
- binding->name = (const char *) GETARG( 0 );
- binding->help = (const char *) GETARG( 1 );
- binding->func = (el_addfn_func) GETARG( 2 );
- binding->key = 0;
- // add this to the bindings list
- _bindings.push_back( binding );
- }
- break;
- case ( EL_BIND ):
- {
- // EL_BIND, const char *, ..., NULL
- // perform the BIND buildin command. Refer to editrc(5) for more information.
-
- const char *name = (const char*) GETARG( 1 );
-
- for ( int i=0; i<_bindings.size(); i++ )
- {
- el_binding *bind = _bindings[i];
- if ( strcmp( bind->name, name ) == 0 )
- {
- bind->key = (const char *) GETARG( 0 );
- break;
- }
- }
-
- }
- break;
- case ( EL_CLIENTDATA ):
- {
- clientData = GETARG( 0 );
- }
- break;
- default:
- assert( !"Not Implemented!" );
- }
- return 0;
-}
-
-void
-el_end (EditLine *el)
-{
- assert( !"Not implemented!" );
-}
-
-void
-el_reset (EditLine *)
-{
- assert( !"Not implemented!" );
-}
-
-int
-el_getc (EditLine *, char *)
-{
- assert( !"Not implemented!" );
- return 0;
-}
-
-void
-el_push (EditLine *, char *)
-{
- assert( !"Not implemented!" );
-}
-
-void
-el_beep (EditLine *)
-{
- Beep( 1000, 500 );
-}
-
-int
-el_parse (EditLine *, int, const char **)
-{
- assert( !"Not implemented!" );
- return 0;
-}
-
-int
-el_get (EditLine *el, int code, ...)
-{
- switch ( code )
- {
- case ( EL_CLIENTDATA ):
- {
- void **dout = (void**) GETARG( 0 );
- *dout = clientData;
- }
- break;
- default:
- assert( !"Not implemented!" );
- }
- return 0;
-}
-
-int
-el_source (EditLine *el, const char *file)
-{
- // init edit line by reading the contents of 'file'
- // nothing to do here on windows...
- return 0;
-}
-
-void
-el_resize (EditLine *)
-{
- assert( !"Not implemented!" );
-}
-
-const LineInfo *
-el_line (EditLine *el)
-{
- assert( !"Not implemented!" );
- return 0;
-}
-
-int
-el_insertstr (EditLine *, const char *)
-{
- assert( !"Not implemented!" );
- return 0;
-}
-
-void
-el_deletestr (EditLine *, int)
-{
- assert( !"Not implemented!" );
-}
-
-History *
-history_init (void)
-{
- // return dummy handle
- return (History*) -1;
-}
-
-void
-history_end (History *)
-{
- assert( !"Not implemented!" );
-}
-
-int
-history (History *, HistEvent *, int op, ...)
-{
- // perform operation 'op' on the history list with optional argumetns as needed by
- // the operation.
- return 0;
-}
-
-#endif
Removed: lldb/trunk/tools/driver/ELWrapper.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/ELWrapper.h?rev=200564&view=auto
==============================================================================
--- lldb/trunk/tools/driver/ELWrapper.h (original)
+++ lldb/trunk/tools/driver/ELWrapper.h (removed)
@@ -1,122 +0,0 @@
-//===-- ELWrapper.h ---------------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#pragma once
-
-#include <stdio.h>
-
-// EditLine editor function return codes.
-// For user-defined function interface
-#define CC_NORM 0
-#define CC_NEWLINE 1
-#define CC_EOF 2
-#define CC_ARGHACK 3
-#define CC_REFRESH 4
-#define CC_CURSOR 5
-#define CC_ERROR 6
-#define CC_FATAL 7
-#define CC_REDISPLAY 8
-#define CC_REFRESH_BEEP 9
-
-// el_set/el_get parameters
-#define EL_PROMPT 0 // , el_pfunc_t
-#define EL_TERMINAL 1 // , const char *
-#define EL_EDITOR 2 // , const char *
-#define EL_SIGNAL 3 // , int);
-#define EL_BIND 4 // , const char *, ..., NULL
-#define EL_TELLTC 5 // , const char *, ..., NULL
-#define EL_SETTC 6 // , const char *, ..., NULL
-#define EL_ECHOTC 7 // , const char *, ..., NULL
-#define EL_SETTY 8 // , const char *, ..., NULL
-#define EL_ADDFN 9 // , const char *, const char *, el_func_t
-#define EL_HIST 10 // , hist_fun_t, const char *
-#define EL_EDITMODE 11 // , int
-#define EL_RPROMPT 12 // , el_pfunc_t
-#define EL_GETCFN 13 // , el_rfunc_t
-#define EL_CLIENTDATA 14 // , void *
-#define EL_UNBUFFERED 15 // , int
-#define EL_PREP_TERM 16 // , int
-#define EL_GETTC 17 // , const char *, ..., NULL
-#define EL_GETFP 18 // , int, FILE **
-#define EL_SETFP 19 // , int, FILE *
-#define EL_REFRESH 20 // , void
-
-#define EL_BUILTIN_GETCFN (NULL)
-
-// history defines
-#define H_FUNC 0 // , UTSL
-#define H_SETSIZE 1 // , const int
-#define H_GETSIZE 2 // , void
-#define H_FIRST 3 // , void
-#define H_LAST 4 // , void
-#define H_PREV 5 // , void
-#define H_NEXT 6 // , void
-#define H_CURR 8 // , const int
-#define H_SET 7 // , int
-#define H_ADD 9 // , const char *
-#define H_ENTER 10 // , const char *
-#define H_APPEND 11 // , const char *
-#define H_END 12 // , void
-#define H_NEXT_STR 13 // , const char *
-#define H_PREV_STR 14 // , const char *
-#define H_NEXT_EVENT 15 // , const int
-#define H_PREV_EVENT 16 // , const int
-#define H_LOAD 17 // , const char *
-#define H_SAVE 18 // , const char *
-#define H_CLEAR 19 // , void
-#define H_SETUNIQUE 20 // , int
-#define H_GETUNIQUE 21 // , void
-#define H_DEL 22 // , int
-
-struct EditLine
-{
-};
-
-struct LineInfo
-{
- const char *buffer;
- const char *cursor;
- const char *lastchar;
-};
-
-struct History
-{
-};
-
-struct HistEvent
-{
- int num;
- const char *str;
-};
-
-extern "C"
-{
- // edit line API
- EditLine *el_init ( const char *, FILE *, FILE *, FILE * );
- const char *el_gets ( EditLine *, int * );
- int el_set ( EditLine *, int, ... );
-
- void el_end ( EditLine * );
- void el_reset ( EditLine * );
- int el_getc ( EditLine *, char * );
- void el_push ( EditLine *, char * );
- void el_beep ( EditLine * );
- int el_parse ( EditLine *, int, const char ** );
- int el_get ( EditLine *, int, ... );
- int el_source ( EditLine *, const char * );
- void el_resize ( EditLine * );
- const LineInfo *el_line ( EditLine * );
- int el_insertstr( EditLine *, const char * );
- void el_deletestr( EditLine *, int );
-
- // history API
- History *history_init( void );
- void history_end ( History * );
- int history ( History *, HistEvent *, int, ... );
-};
\ No newline at end of file
Removed: lldb/trunk/tools/driver/GetOptWrapper.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/GetOptWrapper.cpp?rev=200564&view=auto
==============================================================================
--- lldb/trunk/tools/driver/GetOptWrapper.cpp (original)
+++ lldb/trunk/tools/driver/GetOptWrapper.cpp (removed)
@@ -1,33 +0,0 @@
-//===-- GetOptWrapper.cpp ---------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// this file is only relevant for Visual C++
-#if defined( _MSC_VER )
-
-#include "GetOptWrapper.h"
-
-/*
-
-// already defined in lldbHostCommon.lib due to 'getopt.inc'
-
-extern int
-getopt_long_only
-(
- int ___argc,
- char *const *___argv,
- const char *__shortopts,
- const struct option *__longopts,
- int *__longind
-)
-{
- return -1;
-}
-*/
-
-#endif
\ No newline at end of file
Removed: lldb/trunk/tools/driver/GetOptWrapper.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/GetOptWrapper.h?rev=200564&view=auto
==============================================================================
--- lldb/trunk/tools/driver/GetOptWrapper.h (original)
+++ lldb/trunk/tools/driver/GetOptWrapper.h (removed)
@@ -1,49 +0,0 @@
-//===-- GetOptWrapper.h -----------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef lldb_GetOptWrapper_h_
-#define lldb_GetOptWrapper_h_
-
-// from getopt.h
-#define no_argument 0
-#define required_argument 1
-#define optional_argument 2
-
-// defined int unistd.h
-extern int optreset;
-
-// from getopt.h
-extern char *optarg;
-extern int optind;
-extern int opterr;
-extern int optopt;
-
-// option structure
-struct option
-{
- const char *name;
- // has_arg can't be an enum because some compilers complain about
- // type mismatches in all the code that assumes it is an int.
- int has_arg;
- int *flag;
- int val;
-};
-
-//
-extern int
-getopt_long_only
-(
- int ___argc,
- char *const *___argv,
- const char *__shortopts,
- const struct option *__longopts,
- int *__longind
-);
-
-#endif // lldb_GetOptWrapper_h_
\ No newline at end of file
Modified: lldb/trunk/tools/driver/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Platform.h?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Platform.h (original)
+++ lldb/trunk/tools/driver/Platform.h Fri Jan 31 12:48:46 2014
@@ -18,9 +18,8 @@
#include <io.h>
#include <eh.h>
#include <inttypes.h>
- #include "ELWrapper.h"
#include "lldb/Host/windows/Windows.h"
- #include "GetOptWrapper.h"
+ #include "lldb/Host/HostGetOpt.h"
struct timeval
{
Modified: lldb/trunk/tools/lldb-platform/lldb-platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-platform/lldb-platform.cpp?rev=200565&r1=200564&r2=200565&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-platform/lldb-platform.cpp (original)
+++ lldb/trunk/tools/lldb-platform/lldb-platform.cpp Fri Jan 31 12:48:46 2014
@@ -11,7 +11,7 @@
// C Includes
#include <errno.h>
-#include <getopt.h>
+#include "lldb/Host/HostGetOpt.h"
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
More information about the lldb-commits
mailing list