[Lldb-commits] [lldb] r208972 - Initial commit of LLDB Machine Interface Frontend.
Deepak Panickal
deepak at codeplay.com
Fri May 16 03:51:03 PDT 2014
Added: lldb/trunk/tools/lldb-mi/MIUtilString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilString.cpp?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilString.cpp (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilString.cpp Fri May 16 05:51:01 2014
@@ -0,0 +1,468 @@
+//===-- MIUtilString.cpp ----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: MIUtilString.h
+//
+// Overview: CMIUtilString implementation.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+// Third party headers
+#include <memory> // std::unique_ptr
+#include <stdarg.h> // va_list, va_start, var_end
+#include <sstream> // std::stringstream
+#include <string.h> // for strcpy
+#include <limits.h> // for ULONG_MAX
+
+// In-house headers:
+#include "MIUtilString.h"
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilString constructor.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilString::CMIUtilString( void )
+: std::string()
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilString constructor.
+// Type: Method.
+// Args: vpData - Pointer to UTF8 text data.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilString::CMIUtilString( const MIchar * vpData )
+: std::string( vpData )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilString constructor.
+// Type: Method.
+// Args: vpData - Pointer to UTF8 text data.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilString::CMIUtilString( const MIchar * const * vpData )
+: std::string( (const char *) vpData )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilString destructor.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilString::~CMIUtilString( void )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Perform a snprintf format style on a string data. A new string object is
+// created and returned.
+// Type: Static method.
+// Args: vrFormat - (R) Format string data instruction.
+// vArgs - (R) Var list args of any type.
+// Return: CMIUtilString - Number of splits found in the string data.
+// Throws: None.
+//--
+CMIUtilString CMIUtilString::FormatPriv( const CMIUtilString & vrFormat, va_list vArgs )
+{
+ CMIUtilString strResult;
+ MIint nFinal = 0;
+ MIint n = vrFormat.size();
+
+ // create a copy va_list to reset when we spin
+ va_list argsCpy;
+ va_copy( argsCpy, vArgs );
+
+ if( n == 0 )
+ return strResult;
+
+ n = n * 2; // Reserve 2 times as much the length of the vrFormat
+
+ std::unique_ptr< char[] > pFormatted;
+ while( 1 )
+ {
+ pFormatted.reset( new char[ n ] );
+ strncpy( &pFormatted[ 0 ], vrFormat.c_str(), n );
+
+ // AD fix:
+ // We need to restore the variable argument list pointer to the start again
+ // before running vsnprintf() more then once
+ va_copy( vArgs, argsCpy );
+
+ nFinal = vsnprintf( &pFormatted[ 0 ], n, vrFormat.c_str(), vArgs );
+ if( (nFinal < 0) || (nFinal >= n) )
+ n += abs( nFinal - n + 1 );
+ else
+ break;
+ }
+
+ strResult = pFormatted.get();
+
+ return strResult;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Perform a snprintf format style on a string data. A new string object is
+// created and returned.
+// Type: Static method.
+// Args: vrFormat - (R) Format string data instruction.
+// ... - (R) Var list args of any type.
+// Return: CMIUtilString - Number of splits found in the string data.
+// Throws: None.
+//--
+CMIUtilString CMIUtilString::Format( const CMIUtilString & vrFormating, ... )
+{
+ va_list args;
+ va_start( args, vrFormating );
+ CMIUtilString strResult = CMIUtilString::FormatPriv( vrFormating, args );
+ va_end( args );
+
+ return strResult;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Perform a snprintf format style on a string data. A new string object is
+// created and returned.
+// Type: Static method.
+// Args: vrFormat - (R) Format string data instruction.
+// vArgs - (R) Var list args of any type.
+// Return: CMIUtilString - Number of splits found in the string data.
+// Throws: None.
+//--
+CMIUtilString CMIUtilString::FormatValist( const CMIUtilString & vrFormating, va_list vArgs )
+{
+ return CMIUtilString::FormatPriv( vrFormating, vArgs );
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Splits string into array of strings using delimiter. If multiple delimiter
+// are found in sequence then they are not added to the list of splits.
+// Type: Method.
+// Args: vData - (R) String data to be split up.
+// vDelimiter - (R) Delimiter char or text.
+// vwVecSplits - (W) Container of splits found in string data.
+// Return: MIuint - Number of splits found in the string data.
+// Throws: None.
+//--
+MIuint CMIUtilString::Split( const CMIUtilString & vDelimiter, VecString_t & vwVecSplits ) const
+{
+ vwVecSplits.clear();
+
+ if( this->empty() || vDelimiter.empty() )
+ return 0;
+
+ MIint nPos = find( vDelimiter );
+ if( nPos == (MIint) std::string::npos )
+ {
+ vwVecSplits.push_back( *this );
+ return 1;
+ }
+ const MIint strLen( length() );
+ if( nPos == strLen )
+ {
+ vwVecSplits.push_back( *this );
+ return 1;
+ }
+
+ MIuint nAdd1( 1 );
+ if( (nPos > 0) && (substr( 0, nPos ) != vDelimiter) )
+ {
+ nPos = 0;
+ nAdd1 = 0;
+ }
+ MIint nPos2 = find( vDelimiter, nPos + 1 );
+ while( nPos2 != (MIint) std::string::npos )
+ {
+ const MIuint len( nPos2 - nPos - nAdd1 );
+ const std::string strSection( substr( nPos + nAdd1, len ) );
+ if( strSection != vDelimiter )
+ vwVecSplits.push_back( strSection.c_str() );
+ nPos += len + 1;
+ nPos2 = find( vDelimiter, nPos + 1 );
+ nAdd1 = 0;
+ }
+ const std::string strSection( substr( nPos, strLen - nPos ) );
+ if( (strSection.length() != 0) && (strSection != vDelimiter) )
+ vwVecSplits.push_back( strSection.c_str() );
+
+ return vwVecSplits.size();
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Remove '\n' from the end of string if found. It does not alter
+// *this string.
+// Type: Method.
+// Args: None.
+// Return: CMIUtilString - New version of the string.
+// Throws: None.
+//--
+CMIUtilString CMIUtilString::StripCREndOfLine( void ) const
+{
+ const MIint nPos = rfind( '\n' );
+ if( nPos == (MIint) std::string::npos )
+ return *this;
+
+ const CMIUtilString strNew( substr( 0, nPos ).c_str() );
+
+ return strNew;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Remove all '\n' from the string and replace with a space. It does not alter
+// *this string.
+// Type: Method.
+// Args: None.
+// Return: CMIUtilString - New version of the string.
+// Throws: None.
+//--
+CMIUtilString CMIUtilString::StripCRAll( void ) const
+{
+ return FindAndReplace( "\n", " " );
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Find and replace all matches of a sub string with another string. It does not
+// alter *this string.
+// Type: Method.
+// Args: vFind - (R) The string to look for.
+// vReplaceWith - (R) The string to replace the vFind match.
+// Return: CMIUtilString - New version of the string.
+// Throws: None.
+//--
+CMIUtilString CMIUtilString::FindAndReplace( const CMIUtilString & vFind, const CMIUtilString & vReplaceWith ) const
+{
+ if( vFind.empty() || this->empty() )
+ return *this;
+
+ MIint nPos = find( vFind );
+ if( nPos == (MIint) std::string::npos )
+ return *this;
+
+ CMIUtilString strNew( *this );
+ while( nPos != (MIint) std::string::npos )
+ {
+ strNew.replace( nPos, vFind.length(), vReplaceWith );
+ nPos += vReplaceWith.length();
+ nPos = strNew.find( vFind, nPos );
+ }
+
+ return strNew;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Check if *this string is a decimal number.
+// Type: Method.
+// Args: None.
+// Return: bool - True = yes number, false not a number.
+// Throws: None.
+//--
+bool CMIUtilString::IsNumber( void ) const
+{
+ if( empty() )
+ return false;
+
+ if( (at( 0 ) == '-') && (length() == 1) )
+ return false;
+
+ const MIint nPos = find_first_not_of( "-.0123456789" );
+ if( nPos != (MIint) std::string::npos )
+ return false;
+
+ return true;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Extract the number from the string. The number can be either a hexadecimal or
+// natural number. It cannot contain other non-numeric characters.
+// Type: Method.
+// Args: vwrNumber - (W) Number exracted from the string.
+// Return: bool - True = yes number, false not a number.
+// Throws: None.
+//--
+bool CMIUtilString::ExtractNumber( MIint64 & vwrNumber ) const
+{
+ vwrNumber = 0;
+
+ if( !IsNumber() )
+ {
+ if( ExtractNumberFromHexadecimal( vwrNumber ) )
+ return true;
+
+ return false;
+ }
+
+ std::stringstream ss( const_cast< CMIUtilString & >( *this ) );
+ ss >> vwrNumber;
+
+ return true;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Extract the number from the hexadecimal string..
+// Type: Method.
+// Args: vwrNumber - (W) Number exracted from the string.
+// Return: bool - True = yes number, false not a number.
+// Throws: None.
+//--
+bool CMIUtilString::ExtractNumberFromHexadecimal( MIint64 & vwrNumber ) const
+{
+ vwrNumber = 0;
+
+ const MIint nPos = find_first_not_of( "x01234567890ABCDEFabcedf" );
+ if( nPos != (MIint) std::string::npos )
+ return false;
+
+ const MIint64 nNum = ::strtoul( this->c_str(), nullptr, 16 );
+ if( nNum != ULONG_MAX )
+ {
+ vwrNumber = nNum;
+ return true;
+ }
+
+ return true;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Determine if the text is all valid alpha numeric characters. Letters can be
+// either upper or lower case.
+// Type: Static method.
+// Args: vrText - (R) The text data to examine.
+// Return: bool - True = yes all alpha, false = one or more chars is non alpha.
+// Throws: None.
+//--
+bool CMIUtilString::IsAllValidAlphaAndNumeric( const MIchar & vrText )
+{
+ const MIuint len = ::strlen( &vrText );
+ if( len == 0 )
+ return false;
+
+ MIchar * pPtr = const_cast< MIchar * >( &vrText );
+ for( MIuint i = 0; i < len; i++, pPtr++ )
+ {
+ const MIchar c = *pPtr;
+ if( ::isalnum( (int) c ) == 0 )
+ return false;
+ }
+
+ return true;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Check if two strings share equal contents.
+// Type: Method.
+// Args: vrLhs - (R) String A.
+// vrRhs - (R) String B.
+// Return: bool - True = yes equal, false - different.
+// Throws: None.
+//--
+bool CMIUtilString::Compare( const CMIUtilString & vrLhs, const CMIUtilString & vrRhs )
+{
+ // Check the sizes match
+ if( vrLhs.size() != vrRhs.size() )
+ return false;
+
+ return (::strncmp( vrLhs.c_str(), vrRhs.c_str(), vrLhs.size() ) == 0);
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Remove from either end of *this string the following: " \t\n\v\f\r".
+// Type: Method.
+// Args: None.
+// Return: CMIUtilString - Trimmed string.
+// Throws: None.
+//--
+CMIUtilString CMIUtilString::Trim( void ) const
+{
+ CMIUtilString strNew( *this );
+ const MIchar * pWhiteSpace = " \t\n\v\f\r";
+ const MIint nPos = find_last_not_of( pWhiteSpace );
+ if( nPos != (MIint) std::string::npos )
+ {
+ strNew = substr( 0, nPos + 1 ).c_str();
+ }
+ const MIint nPos2 = strNew.find_first_not_of( pWhiteSpace );
+ if( nPos2 != (MIint) std::string::npos )
+ {
+ strNew = strNew.substr( nPos2 ).c_str();
+ }
+
+ return strNew;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Remove from either end of *this string the specified character.
+// Type: Method.
+// Args: None.
+// Return: CMIUtilString - Trimmed string.
+// Throws: None.
+//--
+CMIUtilString CMIUtilString::Trim( const MIchar vChar ) const
+{
+ CMIUtilString strNew( *this );
+ const MIuint nLen = strNew.length();
+ if( nLen > 1 )
+ {
+ if( (strNew[ 0 ] == vChar) && (strNew[ nLen - 1 ] == vChar) )
+ strNew = strNew.substr( 1, nLen - 2 ).c_str();
+ }
+
+ return strNew;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Do a printf equivalent for printing a number in binary i.e. "b%llB".
+// Type: Static method.
+// Args: vnDecimal - (R) The number to represent in binary.
+// Return: CMIUtilString - Binary number in text.
+// Throws: None.
+//--
+CMIUtilString CMIUtilString::FormatBinary( const MIuint64 vnDecimal )
+{
+ CMIUtilString strBinaryNumber;
+
+ const MIuint nConstBits = 64;
+ MIuint nRem[ nConstBits + 1 ];
+ MIint i = 0;
+ MIuint nLen = 0;
+ MIuint64 nNum = vnDecimal;
+ while( (nNum > 0) && (nLen < nConstBits) )
+ {
+ nRem[ i++ ] = nNum % 2;
+ nNum = nNum >> 1;
+ nLen++;
+ }
+ MIchar pN[ nConstBits + 1 ];
+ MIuint j = 0;
+ for( i = nLen; i > 0; --i, j++ )
+ {
+ pN[ j ] = '0' + nRem[ i - 1 ];
+ }
+ pN[ j ] = 0; // String NUL termination
+
+ strBinaryNumber = CMIUtilString::Format( "0b%s", &pN[ 0 ] );
+
+ return strBinaryNumber;
+}
+
\ No newline at end of file
Added: lldb/trunk/tools/lldb-mi/MIUtilString.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilString.h?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilString.h (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilString.h Fri May 16 05:51:01 2014
@@ -0,0 +1,78 @@
+//===-- MIUtilString.h ------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: MIUtilString.h
+//
+// Overview: CMIUtilString interface.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+#pragma once
+
+// Third party headers:
+#include <string>
+#include <vector>
+
+// In-house headers:
+#include "MIDataTypes.h"
+
+//++ ============================================================================
+// Details: MI common code utility class. Used to help handle text.
+// Derived from std::string
+// Gotchas: None.
+// Authors: Illya Rudkin 02/02/2014.
+// Changes: None.
+//--
+class CMIUtilString : public std::string
+{
+// Typdefs:
+public:
+ typedef std::vector< CMIUtilString > VecString_t;
+
+// Static method:
+public:
+ static CMIUtilString Format( const CMIUtilString & vrFormating, ... );
+ static CMIUtilString FormatBinary( const MIuint64 vnDecimal );
+ static CMIUtilString FormatValist( const CMIUtilString & vrFormating, va_list vArgs );
+ static bool IsAllValidAlphaAndNumeric( const MIchar & vrText );
+ static bool Compare( const CMIUtilString & vrLhs, const CMIUtilString & vrRhs );
+
+// Methods:
+public:
+ /* ctor */ CMIUtilString( void );
+ /* ctor */ CMIUtilString( const MIchar * vpData );
+ /* ctor */ CMIUtilString( const MIchar * const * vpData );
+ //
+ MIuint Split( const CMIUtilString & vDelimiter, VecString_t & vwVecSplits ) const;
+ CMIUtilString Trim( void ) const;
+ CMIUtilString Trim( const MIchar vChar ) const;
+ CMIUtilString StripCREndOfLine( void ) const;
+ CMIUtilString StripCRAll( void ) const;
+ CMIUtilString FindAndReplace( const CMIUtilString & vFind, const CMIUtilString & vReplaceWith ) const;
+ bool IsNumber( void ) const;
+ bool ExtractNumber( MIint64 & vwrNumber ) const;
+
+// Overrideable:
+public:
+ /* dtor */ virtual ~CMIUtilString( void );
+
+// Static method:
+private:
+ static CMIUtilString FormatPriv( const CMIUtilString & vrFormat, va_list vArgs );
+
+// Methods:
+private:
+ bool ExtractNumberFromHexadecimal( MIint64 & vwrNumber ) const;
+};
Added: lldb/trunk/tools/lldb-mi/MIUtilSystemLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilSystemLinux.cpp?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilSystemLinux.cpp (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilSystemLinux.cpp Fri May 16 05:51:01 2014
@@ -0,0 +1,122 @@
+//===-- MIUtilSystemLinux.cpp -----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: MIUtilSystemLinux.cpp
+//
+// Overview: CMIUtilSystemLinux implementation.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+// Include compiler configuration
+#include "MICmnConfig.h"
+
+#if defined( __linux )
+
+// In-house headers:
+#include "MIUtilSystemLinux.h"
+#include "MICmnResources.h"
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilSystemLinux constructor.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilSystemLinux::CMIUtilSystemLinux( void )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilSystemLinux destructor.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilSystemLinux::~CMIUtilSystemLinux( void )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieve the OS system error message for the given system error code.
+// Type: Method.
+// Args: vError - (R) OS error code value.
+// vrwErrorMsg - (W) The error message.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilSystemLinux::GetOSErrorMsg( const MIint vError, CMIUtilString & vrwErrorMsg ) const
+{
+ // Reset
+ vrwErrorMsg.clear();
+
+ bool bOk = MIstatus::failure;
+
+ // ToDo: Implement LINUX version
+
+ return bOk;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieve if possible the OS last error description.
+// Type: Method.
+// Args: None.
+// Return: CMIUtilString - Error description.
+// Throws: None.
+//--
+CMIUtilString CMIUtilSystemLinux::GetOSLastError( void ) const
+{
+ CMIUtilString errorMsg( "Error fn not implemented " );
+
+ // ToDo: Implement LINUX version
+
+ return errorMsg;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieves the fully qualified path for the this application. If the function
+// fails the string is filled with the error message.
+// Type: Method.
+// Args: vrwFileNamePath - (W) The excutable's name and path or last error description.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilSystemLinux::GetExecutablesPath( CMIUtilString & vrwFileNamePath ) const
+{
+ vrwFileNamePath = CMIUtilString( "." );
+ return MIstatus::success;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieves the fully qualified path for the Log file for this application.
+// If the function fails the string is filled with the error message.
+// Append a dummy file name on the end of the path. This will be stripped off
+// later and the real log file name replaces it.
+// Type: Method.
+// Args: vrwFileNamePath - (W) The Log file's name and path or last error description.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilSystemLinux::GetLogFilesPath( CMIUtilString & vrwFileNamePath ) const
+{
+ vrwFileNamePath = CMIUtilString( "." );
+ return MIstatus::success;
+}
+
+#endif // #if defined( __linux )
Added: lldb/trunk/tools/lldb-mi/MIUtilSystemLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilSystemLinux.h?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilSystemLinux.h (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilSystemLinux.h Fri May 16 05:51:01 2014
@@ -0,0 +1,60 @@
+//===-- CMIUtilSystemLinux.h ------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: CMIUtilSystemLinux.h
+//
+// Overview: CMIUtilSystemLinux interface.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+#pragma once
+
+// Include compiler configuration
+#include "MICmnConfig.h"
+
+#if defined( __linux )
+
+// In-house headers:
+#include "MIUtilString.h"
+
+//++ ============================================================================
+// Details: MI common code utility class. Used to set or retrieve information
+// about the current system or user.
+// *** If you change, remove or add functionality it must be replicated
+// *** for the all platforms supported; Windows, OSX, LINUX
+// Gotchas: None.
+// Authors: Illya Rudkin 29/01/2014.
+// Changes: None.
+//--
+class CMIUtilSystemLinux
+{
+// Methods:
+public:
+ /* ctor */ CMIUtilSystemLinux( void );
+
+ bool GetOSErrorMsg( const MIint vError, CMIUtilString & vrwErrorMsg ) const;
+ CMIUtilString GetOSLastError( void ) const;
+ bool GetExecutablesPath( CMIUtilString & vrwFileNamePath ) const;
+ bool GetLogFilesPath( CMIUtilString & vrwFileNamePath ) const;
+
+// Overrideable:
+public:
+ // From CMICmnBase
+ /* dtor */ virtual ~CMIUtilSystemLinux( void );
+};
+
+typedef CMIUtilSystemLinux CMIUtilSystem;
+
+#endif // #if defined( __linux )
Added: lldb/trunk/tools/lldb-mi/MIUtilSystemOsx.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilSystemOsx.cpp?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilSystemOsx.cpp (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilSystemOsx.cpp Fri May 16 05:51:01 2014
@@ -0,0 +1,128 @@
+//===-- MIUtilSystemOsx.cpp -------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: MIUtilSystemOsx.cpp
+//
+// Overview: CMIUtilSystemOsx implementation.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+// Include compiler configuration
+#include "MICmnConfig.h"
+
+#if defined( __APPLE__ )
+
+// In-house headers:
+#include "MIUtilSystemOsx.h"
+#include "MICmnResources.h"
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilSystemOsx constructor.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilSystemOsx::CMIUtilSystemOsx( void )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilSystemOsx destructor.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilSystemOsx::~CMIUtilSystemOsx( void )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieve the OS system error message for the given system error code.
+// Type: Method.
+// Args: vError - (R) OS error code value.
+// vrwErrorMsg - (W) The error message.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilSystemOsx::GetOSErrorMsg( const MIint vError, CMIUtilString & vrwErrorMsg ) const
+{
+ // Reset
+ vrwErrorMsg.clear();
+
+ bool bOk = MIstatus::failure;
+
+ // ToDo: Implement LINUX version
+
+ return bOk;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieve if possible the OS last error description.
+// Type: Method.
+// Args: None.
+// Return: CMIUtilString - Error description.
+// Throws: None.
+//--
+CMIUtilString CMIUtilSystemOsx::GetOSLastError( void ) const
+{
+ CMIUtilString errorMsg( "Error fn not implemented" );
+
+ // ToDo: Implement LINUX version
+
+ return errorMsg;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieves the fully qualified path for the this application. If the function
+// fails the string is filled with the error message.
+// Type: Method.
+// Args: vrwFileNamePath - (W) The excutable's name and path or last error description.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilSystemOsx::GetExecutablesPath( CMIUtilString & vrwFileNamePath ) const
+{
+ bool bOk = MIstatus::failure;
+
+ // ToDo: Implement OSX version
+
+ return bOk;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieves the fully qualified path for the Log file for this application.
+// If the function fails the string is filled with the error message.
+// Append a dummy file name on the end of the path. This will be stripped off
+// later and the real log file name replaces it.
+// Type: Method.
+// Args: vrwFileNamePath - (W) The Log file's name and path or last error description.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilSystemOsx::GetLogFilesPath( CMIUtilString & vrwFileNamePath ) const
+{
+ bool bOk = MIstatus::failure;
+
+ // ToDo: Implement OSX version
+
+ return bOk;
+}
+
+#endif // #if defined( __APPLE__ )
Added: lldb/trunk/tools/lldb-mi/MIUtilSystemOsx.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilSystemOsx.h?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilSystemOsx.h (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilSystemOsx.h Fri May 16 05:51:01 2014
@@ -0,0 +1,60 @@
+//===-- MICmnConfig.h -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: CMIUtilSystemOsx.h
+//
+// Overview: CMIUtilSystemOsx interface.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+#pragma once
+
+// Include compiler configuration
+#include "MICmnConfig.h"
+
+#if defined( __APPLE__ )
+
+// In-house headers:
+#include "MIUtilString.h"
+
+//++ ============================================================================
+// Details: MI common code utility class. Used to set or retrieve information
+// about the current system or user.
+// *** If you change, remove or add functionality it must be replicated
+// *** for the all platforms supported; Windows, OSX, LINUX
+// Gotchas: None.
+// Authors: Illya Rudkin 29/01/2014.
+// Changes: None.
+//--
+class CMIUtilSystemOsx
+{
+// Methods:
+public:
+ /* ctor */ CMIUtilSystemOsx( void );
+
+ bool GetOSErrorMsg( const MIint vError, CMIUtilString & vrwErrorMsg ) const;
+ CMIUtilString GetOSLastError( void ) const;
+ bool GetExecutablesPath( CMIUtilString & vrwFileNamePath ) const;
+ bool GetLogFilesPath( CMIUtilString & vrwFileNamePath ) const;
+
+// Overrideable:
+public:
+ // From CMICmnBase
+ /* dtor */ virtual ~CMIUtilSystemOsx( void );
+};
+
+typedef CMIUtilSystemOsx CMIUtilSystem;
+
+#endif // #if defined( __APPLE__ )
Added: lldb/trunk/tools/lldb-mi/MIUtilSystemWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilSystemWindows.cpp?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilSystemWindows.cpp (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilSystemWindows.cpp Fri May 16 05:51:01 2014
@@ -0,0 +1,154 @@
+//===-- MIUtilSystemWindows.cpp ---------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: MIUtilSystemWindows.cpp
+//
+// Overview: CMIUtilSystemWindows implementation.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+// Include compiler configuration
+#include "MICmnConfig.h"
+
+#if defined( _MSC_VER )
+
+// Third party headers
+#include <memory> // std::unique_ptr
+#include <Windows.h>
+#include <WinBase.h> // ::FormatMessage()
+
+// In-house headers:
+#include "MIUtilSystemWindows.h"
+#include "MICmnResources.h"
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilSystemWindows constructor.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilSystemWindows::CMIUtilSystemWindows( void )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilSystemWindows destructor.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilSystemWindows::~CMIUtilSystemWindows( void )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieve the OS system error message for the given system error code.
+// Type: Method.
+// Args: vError - (R) OS error code value.
+// vrwErrorMsg - (W) The error message.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilSystemWindows::GetOSErrorMsg( const MIint vError, CMIUtilString & vrwErrorMsg ) const
+{
+ // Reset
+ vrwErrorMsg.clear();
+
+ const MIuint nBufLen = 1024;
+ std::unique_ptr< char[] > pBuffer;
+ pBuffer.reset( new char[ nBufLen ] );
+
+ // CMIUtilString Format is not used as cannot replicate the behavior of ::FormatMessage which
+ // can take into account locality while retrieving the error message from the system.
+ const int nLength = ::FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ nullptr, (DWORD) vError, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
+ reinterpret_cast< LPTSTR >( &pBuffer[ 0 ] ),
+ nBufLen, nullptr );
+ bool bOk = MIstatus::success;
+ if( nLength != 0 )
+ vrwErrorMsg = &pBuffer[ 0 ];
+ else
+ bOk = MIstatus::failure;
+
+ return bOk;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieve if possible the OS last error description.
+// Type: Method.
+// Args: None.
+// Return: CMIUtilString - Error description.
+// Throws: None.
+//--
+CMIUtilString CMIUtilSystemWindows::GetOSLastError( void ) const
+{
+ CMIUtilString errorMsg;
+ const DWORD dwLastError = ::GetLastError();
+ if( dwLastError != 0 )
+ {
+ if( !GetOSErrorMsg( dwLastError, errorMsg ) )
+ errorMsg = MIRSRC( IDE_OS_ERR_RETRIEVING );
+ }
+ else
+ errorMsg = MIRSRC( IDE_OS_ERR_UNKNOWN );
+
+ return errorMsg;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieves the fully qualified path for the this application. If the function
+// fails the string is filled with the error message.
+// Type: Method.
+// Args: vrwFileNamePath - (W) The excutable's name and path or last error description.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilSystemWindows::GetExecutablesPath( CMIUtilString & vrwFileNamePath ) const
+{
+ bool bOk = MIstatus::success;
+ HMODULE hModule = ::GetModuleHandle( nullptr );
+ char pPath[ MAX_PATH ];
+ const DWORD nLen = ::GetModuleFileName( hModule, &pPath[ 0 ], MAX_PATH );
+ const CMIUtilString strLastErr( GetOSLastError() );
+ if( (nLen != 0) && (strLastErr == "Unknown OS error") )
+ vrwFileNamePath = &pPath[ 0 ];
+ else
+ {
+ bOk = MIstatus::failure;
+ vrwFileNamePath = strLastErr;
+ }
+
+ return bOk;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Retrieves the fully qualified path for the Log file for this application.
+// If the function fails the string is filled with the error message.
+// Type: Method.
+// Args: vrwFileNamePath - (W) The Log file's name and path or last error description.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilSystemWindows::GetLogFilesPath( CMIUtilString & vrwFileNamePath ) const
+{
+ return GetExecutablesPath( vrwFileNamePath );
+}
+
+#endif // #if defined( _MSC_VER )
Added: lldb/trunk/tools/lldb-mi/MIUtilSystemWindows.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilSystemWindows.h?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilSystemWindows.h (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilSystemWindows.h Fri May 16 05:51:01 2014
@@ -0,0 +1,59 @@
+//===-- MIUtilSystemWindows.h -----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: MIUtilSystemWindows.h
+//
+// Overview: CMIUtilSystemWindows interface.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+#pragma once
+
+// Include compiler configuration
+#include "MICmnConfig.h"
+
+#if defined( _MSC_VER )
+
+// In-house headers:
+#include "MIUtilString.h"
+
+//++ ============================================================================
+// Details: MI common code utility class. Used to set or retrieve information
+// about the current system or user.
+// *** If you change, remove or add functionality it must be replicated
+// *** for the all platforms supported; Windows, OSX, LINUX
+// Gotchas: None.
+// Authors: Illya Rudkin 29/01/2014.
+// Changes: None.
+//--
+class CMIUtilSystemWindows
+{
+// Methods:
+public:
+ /* ctor */ CMIUtilSystemWindows( void );
+
+ bool GetOSErrorMsg( const MIint vError, CMIUtilString & vrwErrorMsg ) const;
+ CMIUtilString GetOSLastError( void ) const;
+ bool GetExecutablesPath( CMIUtilString & vrwFileNamePath ) const;
+ bool GetLogFilesPath( CMIUtilString & vrwFileNamePath ) const;
+
+// Overrideable:
+public:
+ // From CMICmnBase
+ /* dtor */ virtual ~CMIUtilSystemWindows( void );
+};
+
+typedef CMIUtilSystemWindows CMIUtilSystem;
+
+#endif // #if defined( _MSC_VER )
Added: lldb/trunk/tools/lldb-mi/MIUtilTermios.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilTermios.cpp?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilTermios.cpp (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilTermios.cpp Fri May 16 05:51:01 2014
@@ -0,0 +1,69 @@
+//===-- MIUtilTermios.cpp ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: MIUtilTermios.cpp
+//
+// Overview: Terminal setting termios functions.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+// Third party headers:
+#include <stdlib.h>
+
+// In-house headers:
+#include "MIUtilTermios.h"
+#include "Platform.h"
+
+namespace MIUtilTermios
+{
+// Instantiations:
+static bool g_bOldStdinTermiosIsValid = false; // True = yes valid, false = no valid
+static struct termios g_sOldStdinTermios;
+
+//++ ------------------------------------------------------------------------------------
+// Details: Reset the terminal settings. This function is added as an ::atexit handler
+// to make sure we clean up. See StdinTerminosSet().
+// Type: Global function.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+void StdinTermiosReset( void )
+{
+ if( g_bOldStdinTermiosIsValid )
+ {
+ g_bOldStdinTermiosIsValid = false;
+ ::tcsetattr( STDIN_FILENO, TCSANOW, &g_sOldStdinTermios );
+ }
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Set the terminal settings function. StdinTermiosReset() is called when to
+// reset to this to before and application exit.
+// Type: Global function.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+void StdinTermiosSet( void )
+{
+ if( ::tcgetattr( STDIN_FILENO, &g_sOldStdinTermios ) == 0 )
+ {
+ g_bOldStdinTermiosIsValid = true;
+ ::atexit( StdinTermiosReset );
+ }
+}
+
+} // namespace MIUtilTermios
Added: lldb/trunk/tools/lldb-mi/MIUtilTermios.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilTermios.h?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilTermios.h (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilTermios.h Fri May 16 05:51:01 2014
@@ -0,0 +1,30 @@
+//===-- MIUtilTermios.h -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: MIUtilTermios.h
+//
+// Overview: Terminal setting termios functions.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+#pragma once
+
+namespace MIUtilTermios
+{
+
+extern void StdinTermiosReset( void );
+extern void StdinTermiosSet( void );
+
+} // MIUtilTermios
Added: lldb/trunk/tools/lldb-mi/MIUtilThreadBaseStd.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilThreadBaseStd.cpp?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilThreadBaseStd.cpp (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilThreadBaseStd.cpp Fri May 16 05:51:01 2014
@@ -0,0 +1,342 @@
+//===-- MIUtilThreadBaseStd.cpp ---------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: MIUtilThreadBaseStd.cpp
+//
+// Overview: CMIUtilThread implementation.
+// CMIUtilThreadActiveObjBase implementation.
+// CMIUtilThreadMutex implementation.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+// Include compiler configuration
+#include "MICmnConfig.h"
+
+// Third Party Headers:
+#include <assert.h>
+
+// In-house headers:
+#include "MIUtilThreadBaseStd.h"
+#include "MICmnThreadMgrStd.h"
+
+//++ ------------------------------------------------------------------------------------
+// Details: Constructor.
+// Type: None.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilThreadActiveObjBase::CMIUtilThreadActiveObjBase( void )
+: m_references( 0 )
+, m_bHasBeenKilled( false )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Destructor.
+// Type: None.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilThreadActiveObjBase::~CMIUtilThreadActiveObjBase( void )
+{
+ // Make sure our thread is not alive before we die
+ m_thread.Join();
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Check if an object is already running.
+// Type: Method.
+// Args: None.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilThreadActiveObjBase::ThreadIsActive( void )
+{
+ // Create a new thread to occupy this threads Run() function
+ return m_thread.IsActive();
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Set up *this thread.
+// Type: Mrthod.
+// Args: None.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilThreadActiveObjBase::ThreadExecute( void )
+{
+ // Create a new thread to occupy this threads Run() function
+ return m_thread.Start( ThreadEntry, this );
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Aquire a reference to CMIUtilThreadActiveObjBase.
+// Type: Method.
+// Args: None.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilThreadActiveObjBase::Acquire( void )
+{
+ // Access to this function is serial
+ CMIUtilThreadLock serial( m_mutex );
+
+ // >0 == *this thread is alive
+ m_references++;
+
+ return MIstatus::success;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Release a reference to CMIUtilThreadActiveObjBase.
+// Type: Method.
+// Args: None.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilThreadActiveObjBase::Release( void )
+{
+ // Access to this function is serial
+ CMIUtilThreadLock serial( m_mutex );
+
+ // 0 == kill off *this thread
+ m_references--;
+
+ return MIstatus::success;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Force this thread to stop, regardless of references
+// Type: Method.
+// Args: None.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilThreadActiveObjBase::ThreadKill( void )
+{
+ // Access to this function is serial
+ CMIUtilThreadLock serial( m_mutex );
+
+ // Set this thread to killed status
+ m_bHasBeenKilled = true;
+
+ return MIstatus::success;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Proxy to thread join.
+// Type: Method.
+// Args: None.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilThreadActiveObjBase::ThreadJoin( void )
+{
+ return m_thread.Join();
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: This function is the entry point of this object thread.
+// It is a trampoline to an instances operation manager.
+// Type: Static method.
+// Args: vpThisClass - (R) From the system (our CMIUtilThreadActiveObjBase from the ctor).
+// Return: MIuint - 0 = success.
+// Throws: None.
+//--
+MIuint CMIUtilThreadActiveObjBase::ThreadEntry( void * vpThisClass )
+{
+ // The argument is a pointer to a CMIUtilThreadActiveObjBase class
+ // as passed from the initialize function, so we can safely cast it.
+ assert( vpThisClass != nullptr );
+ CMIUtilThreadActiveObjBase * pActive = reinterpret_cast< CMIUtilThreadActiveObjBase * >( vpThisClass );
+
+ // Start the management routine of this object
+ pActive->ThreadManage();
+
+ // Thread death
+ return 0;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: This function forms a small management routine, to handle the thread's running.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+void CMIUtilThreadActiveObjBase::ThreadManage( void )
+{
+ bool bAlive = true;
+
+ // Infinite loop
+ while( bAlive )
+ {
+ // Scope the lock while we access m_isDying
+ {
+ // Lock down access to the interface
+ CMIUtilThreadLock serial( m_mutex );
+
+ // Quit the run loop if we are dying
+ if( m_references == 0 )
+ break;
+ }
+ // Execute the run routine
+ if( !ThreadRun( bAlive ) )
+ // Thread's run function failed (MIstatus::failure)
+ break;
+
+ // We will die if we have been signaled to die
+ bAlive &= !m_bHasBeenKilled;
+ }
+
+ // Execute the finish routine just before we die
+ // to give the object a chance to clean up
+ ThreadFinish();
+}
+
+//---------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------
+
+//
+CMIUtilThread::CMIUtilThread( void )
+: m_pThread( nullptr )
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMIUtilThread destructor.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+CMIUtilThread::~CMIUtilThread( void )
+{
+ Join();
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Wait for thread to stop.
+// Type: Method.
+// Args: None.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilThread::Join( void )
+{
+ if( m_pThread != nullptr )
+ {
+ // Wait for this thread to die
+ m_pThread->join();
+
+ // Scope the thread lock while we modify the pointer
+ {
+ CMIUtilThreadLock _lock( m_mutex );
+ delete m_pThread;
+ m_pThread = nullptr;
+ }
+ }
+
+ return MIstatus::success;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Is the thread doing work.
+// Type: Method.
+// Args: None.
+// Return: bool - True = Yes active, false = not active.
+// Throws: None.
+//--
+bool CMIUtilThread::IsActive( void )
+{
+ // Lock while we access the thread pointer
+ CMIUtilThreadLock _lock( m_mutex );
+ if( m_pThread == nullptr )
+ return false;
+ else
+ return true;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Set up *this thread.
+// Type: Method.
+// Args: vpFn (R) - Function pointer to thread's main function.
+// vpArg (R) - Pointer arguments to pass to the thread.
+// Return: MIstatus::success - Functional succeeded.
+// MIstatus::failure - Functional failed.
+// Throws: None.
+//--
+bool CMIUtilThread::Start( FnThreadProc vpFn, void * vpArg )
+{
+ // Create the std thread, which starts immediately
+ m_pThread = new std::thread( vpFn, vpArg );
+
+ // We expect to always be able to create one
+ assert( m_pThread != nullptr );
+
+ return MIstatus::success;
+}
+
+//---------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------
+
+//++ ------------------------------------------------------------------------------------
+// Details: Take resource.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+void CMIUtilThreadMutex::Lock( void )
+{
+ m_mutex.lock();
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Release resource.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+void CMIUtilThreadMutex::Unlock( void )
+{
+ m_mutex.unlock();
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Take resource if available. Immediately return in either case.
+// Type: Method.
+// Args: None.
+// Return: True - mutex has been locked.
+// False - mutex could not be locked.
+// Throws: None.
+//--
+bool CMIUtilThreadMutex::TryLock( void )
+{
+ return m_mutex.try_lock();
+}
+
Added: lldb/trunk/tools/lldb-mi/MIUtilThreadBaseStd.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilThreadBaseStd.h?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilThreadBaseStd.h (added)
+++ lldb/trunk/tools/lldb-mi/MIUtilThreadBaseStd.h Fri May 16 05:51:01 2014
@@ -0,0 +1,171 @@
+//===-- MIUtilThreadBaseStd.h -----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//++
+// File: MIUtilThreadBaseStd.h
+//
+// Overview: CMIUtilThread interface.
+// CMIUtilThreadActiveObjBase interface.
+// CMIUtilThreadMutex interface.
+// CMIUtilThreadLock interface.
+//
+// Environment: Compilers: Visual C++ 12.
+// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
+// Libraries: See MIReadmetxt.
+//
+// Copyright: None.
+//--
+
+#pragma once
+
+// Third party headers:
+#ifdef _MSC_VER
+#include <eh.h>
+#endif
+#include <thread>
+#include <mutex>
+
+// In-house headers:
+#include "MICmnConfig.h"
+#include "MIDataTypes.h"
+#include "MIUtilString.h"
+
+//++ ============================================================================
+// Details: MI common code utility class. Handle thread mutual exclusion.
+// Embed Mutexes in your Active Object and then use them through Locks.
+// Gotchas: None.
+// Authors: Aidan Dodds 10/03/2014.
+// Changes: None.
+//--
+class CMIUtilThreadMutex
+{
+ // Methods:
+public:
+ /* ctor */ CMIUtilThreadMutex( void ) { };
+ //
+ void Lock( void ); // Wait until mutex can be obtained
+ void Unlock( void ); // Release the mutex
+ bool TryLock( void ); // Gain the lock if available
+
+// Overrideable:
+public:
+ // From CMICmnBase
+ /* dtor */ virtual ~CMIUtilThreadMutex( void ) { };
+
+// Attributes:
+private:
+ std::recursive_mutex m_mutex;
+};
+
+//++ ============================================================================
+// Details: MI common code utility class. Thread object.
+// Gotchas: None.
+// Authors: Aidan Dodds 10/03/2014.
+// Changes: None.
+//--
+class CMIUtilThread
+{
+// Typedef:
+public:
+ typedef MIuint (* FnThreadProc) (void * vpThisClass);
+
+// Methods:
+public:
+ /* ctor */ CMIUtilThread( void );
+ //
+ bool Start( FnThreadProc vpFn, void * vpArg ); // Start execution of this thread
+ bool Join( void ); // Wait for this thread to stop
+ bool IsActive( void ); // Returns true if this thread is running
+
+// Overrideable:
+public:
+ /* dtor */ virtual ~CMIUtilThread( void );
+
+// Methods:
+private:
+ CMIUtilThreadMutex m_mutex;
+ std::thread * m_pThread;
+};
+
+//++ ============================================================================
+// Details: MI common code utility class. Base class for a worker thread active
+// object. Runs an 'captive thread'.
+// Gotchas: None.
+// Authors: Aidan Dodds 10/03/2014..
+// Changes: None.
+//--
+class CMIUtilThreadActiveObjBase
+{
+// Methods:
+public:
+ /* ctor */ CMIUtilThreadActiveObjBase( void );
+ //
+ bool Acquire( void ); // Obtain a reference to this object
+ bool Release( void ); // Release a reference to this object
+ bool ThreadIsActive( void ); // Return true if this object is running
+ bool ThreadJoin( void ); // Wait for this thread to stop running
+ bool ThreadKill( void ); // Force this thread to stop, regardless of references
+ bool ThreadExecute( void ); // Start this objects execution in another thread
+ void ThreadManage( void );
+
+// Overrideable:
+public:
+ /* dtor */ virtual ~CMIUtilThreadActiveObjBase( void );
+ //
+ // Each thread object must supple a unique name that can be used to locate it
+ virtual const CMIUtilString & ThreadGetName( void ) const = 0;
+
+// Statics:
+protected:
+ static MIuint ThreadEntry( void * vpThisClass ); // Thread entry point
+
+// Overrideable:
+protected:
+ virtual bool ThreadRun( bool &vrIsAlive ) = 0; // Call the main worker method
+ virtual bool ThreadFinish( void ) = 0; // Finish of what you were doing
+
+// Attributes:
+protected:
+ volatile MIuint m_references; // Stores the current lifetime state of this thread, 0 = running, > 0 = shutting down
+ volatile bool m_bHasBeenKilled; // Set to true when this thread has been killed
+ CMIUtilThread m_thread; // The execution thread
+ CMIUtilThreadMutex m_mutex; // This mutex allows us to safely communicate with this thread object across the interface from multiple threads
+};
+
+//++ ============================================================================
+// Details: MI common code utility class. Handle thread resource locking.
+// Put Locks inside all the methods of your Active Object that access
+// data shared with the captive thread.
+// Gotchas: None.
+// Authors: Aidan Dodds 10/03/2014.
+// Changes: None.
+//--
+class CMIUtilThreadLock
+{
+// Methods:
+public:
+ /* ctor */
+ CMIUtilThreadLock( CMIUtilThreadMutex & vMutex )
+ : m_rMutex( vMutex )
+ {
+ m_rMutex.Lock();
+ }
+
+// Overrideable:
+public:
+ /* dtor */
+ virtual ~CMIUtilThreadLock( void )
+ {
+ m_rMutex.Unlock();
+ }
+
+// Attributes:
+private:
+ CMIUtilThreadMutex & m_rMutex;
+};
Added: lldb/trunk/tools/lldb-mi/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/Makefile?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/Makefile (added)
+++ lldb/trunk/tools/lldb-mi/Makefile Fri May 16 05:51:01 2014
@@ -0,0 +1,32 @@
+##===- tools/lldb-mi/Makefile -------------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+LLDB_LEVEL := ../..
+
+TOOLNAME = lldb-mi
+
+NO_PEDANTIC = 1
+
+LLVMLibsOptions += -ledit -llldb -llldbUtility
+
+include $(LLDB_LEVEL)/Makefile
+
+ifeq ($(HOST_OS),Darwin)
+ LLVMLibsOptions += -Wl,-rpath, at loader_path/../lib/
+ LLVMLibsOptions += -Wl,-sectcreate -Wl,__TEXT -Wl,__info_plist -Wl,"$(PROJ_SRC_DIR)/lldb-Info.plist"
+endif
+
+ifneq (,$(filter $(HOST_OS), Linux GNU/kFreeBSD))
+ LLVMLibsOptions += -Wl,-rpath,$(LibDir)
+endif
+
+ifeq ($(HOST_OS),FreeBSD)
+ CPP.Flags += -I/usr/include/edit #-v
+ LLVMLibsOptions += -Wl,-rpath,$(LibDir)
+endif
+
Added: lldb/trunk/tools/lldb-mi/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/Platform.cpp?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/Platform.cpp (added)
+++ lldb/trunk/tools/lldb-mi/Platform.cpp Fri May 16 05:51:01 2014
@@ -0,0 +1,109 @@
+//===-- Platform.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 <process.h>
+#include <assert.h>
+
+#include "Platform.h"
+
+// the control handler or SIGINT handler
+static sighandler_t _ctrlHandler = NULL;
+
+// the default console control handler
+BOOL
+WINAPI CtrlHandler (DWORD ctrlType)
+{
+ if ( _ctrlHandler != NULL )
+ {
+ _ctrlHandler( 0 );
+ return TRUE;
+ }
+ return FALSE;
+}
+
+int
+ioctl (int d, int request, ...)
+{
+ switch ( request )
+ {
+ // request the console windows size
+ case ( TIOCGWINSZ ):
+ {
+ va_list vl;
+ va_start(vl,request);
+ // locate the window size structure on stack
+ winsize *ws = va_arg(vl, winsize*);
+ // get screen buffer information
+ CONSOLE_SCREEN_BUFFER_INFO info;
+ if ( GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &info ) == TRUE )
+ // fill in the columns
+ ws->ws_col = info.dwMaximumWindowSize.X;
+ va_end(vl);
+ return 0;
+ }
+ break;
+ default:
+ assert( !"Not implemented!" );
+ }
+ return -1;
+}
+
+int
+kill (pid_t pid, int sig)
+{
+ // is the app trying to kill itself
+ if ( pid == getpid( ) )
+ exit( sig );
+ //
+ assert( !"Not implemented!" );
+ return -1;
+}
+
+int
+tcsetattr (int fd, int optional_actions, const struct termios *termios_p)
+{
+ assert( !"Not implemented!" );
+ return -1;
+}
+
+int
+tcgetattr (int fildes, struct termios *termios_p)
+{
+// assert( !"Not implemented!" );
+ // error return value (0=success)
+ return -1;
+}
+
+sighandler_t
+signal (int sig, sighandler_t sigFunc)
+{
+ switch ( sig )
+ {
+ case ( SIGINT ):
+ {
+ _ctrlHandler = sigFunc;
+ SetConsoleCtrlHandler( CtrlHandler, TRUE );
+ }
+ break;
+ case ( SIGPIPE ):
+ case ( SIGWINCH ):
+ case ( SIGTSTP ):
+ case ( SIGCONT ):
+ // ignore these for now
+ break;
+ default:
+ assert( !"Not implemented!" );
+ }
+ return 0;
+}
+
+#endif
Added: lldb/trunk/tools/lldb-mi/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/Platform.h?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/Platform.h (added)
+++ lldb/trunk/tools/lldb-mi/Platform.h Fri May 16 05:51:01 2014
@@ -0,0 +1,109 @@
+//===-- Platform.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
+
+#if defined( _MSC_VER )
+
+ // this will stop signal.h being included
+ #define _INC_SIGNAL
+
+ #include <io.h>
+ #include <eh.h>
+ #include <inttypes.h>
+ #include <lldb/Host/windows/Windows.h>
+ #include <lldb/Host/HostGetOpt.h>
+
+ // This is not used by MI
+ struct timeval
+ {
+ long tv_sec;
+ long tv_usec;
+ };
+
+ struct winsize
+ {
+ long ws_col;
+ };
+
+ typedef unsigned char cc_t;
+ typedef unsigned int speed_t;
+ typedef unsigned int tcflag_t;
+
+ // fcntl.h // This is not used by MI
+ #define O_NOCTTY 0400
+
+ // ioctls.h
+ #define TIOCGWINSZ 0x5413
+
+ // tcsetattr arguments
+ #define TCSANOW 0
+
+ #define NCCS 32
+ struct termios
+ {
+ tcflag_t c_iflag; // input mode flags
+ tcflag_t c_oflag; // output mode flags
+ tcflag_t c_cflag; // control mode flags
+ tcflag_t c_lflag; // local mode flags
+ cc_t c_line; // line discipline
+ cc_t c_cc[NCCS]; // control characters
+ speed_t c_ispeed; // input speed
+ speed_t c_ospeed; // output speed
+ };
+
+ typedef long pid_t;
+
+ #define STDIN_FILENO 0
+ #define PATH_MAX MAX_PATH
+ #define snprintf _snprintf
+
+ extern int ioctl( int d, int request, ... );
+ extern int kill ( pid_t pid, int sig );
+ extern int tcsetattr( int fd, int optional_actions, const struct termios *termios_p );
+ extern int tcgetattr( int fildes, struct termios *termios_p );
+
+ // signal handler function pointer type
+ typedef void (*sighandler_t)(int);
+
+ // CODETAG_IOR_SIGNALS
+ // signal.h
+ #define SIGINT 2 // Terminal interrupt signal
+ #define SIGQUIT 3 // Terminal quit signal
+ #define SIGKILL 9 // Kill (cannot be caught or ignored)
+ #define SIGPIPE 13 // Write on a pipe with no one to read it
+ #define SIGCONT 18 // Continue executing, if stopped.
+ #define SIGTSTP 20 // Terminal stop signal
+ #define SIGSTOP 23 // Stop executing (cannot be caught or ignored)
+ #define SIGWINCH 28 // (== SIGVTALRM)
+ #define SIG_DFL ( (sighandler_t) -1 ) // Default handler
+ #define SIG_IGN ( (sighandler_t) -2 ) // Ignored
+
+ extern sighandler_t signal( int sig, sighandler_t );
+
+#else
+
+ #include <inttypes.h>
+
+ #include <getopt.h>
+ #include <libgen.h>
+ #include <sys/ioctl.h>
+ #include <termios.h>
+ #include <unistd.h>
+
+ #include <histedit.h>
+ #include <pthread.h>
+ #include <sys/time.h>
+
+ #if defined(__FreeBSD__)
+ #include <readline/readline.h>
+ #else
+ #include <editline/readline.h>
+ #endif
+
+#endif
Added: lldb/trunk/tools/lldb-mi/lldb-Info.plist
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/lldb-Info.plist?rev=208972&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/lldb-Info.plist (added)
+++ lldb/trunk/tools/lldb-mi/lldb-Info.plist Fri May 16 05:51:01 2014
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.apple.lldb</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>lldb-mi</string>
+ <key>CFBundleVersion</key>
+ <string>2</string>
+ <key>SecTaskAccess</key>
+ <array>
+ <string>allowed</string>
+ <string>debug</string>
+ </array>
+</dict>
+</plist>
More information about the lldb-commits
mailing list