Beispiel #1
0
void
CommandObject::GetArgumentHelp (Stream &str, CommandArgumentType arg_type, CommandInterpreter &interpreter)
{
    const ArgumentTableEntry* table = CommandObject::GetArgumentTable();
    ArgumentTableEntry *entry = (ArgumentTableEntry *) &(table[arg_type]);
    
    // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up...

    if (entry->arg_type != arg_type)
        entry = CommandObject::FindArgumentDataByType (arg_type);

    if (!entry)
        return;

    StreamString name_str;
    name_str.Printf ("<%s>", entry->arg_name);

    if (entry->help_function)
    {
        const char* help_text = entry->help_function();
        if (!entry->help_function.self_formatting)
        {
            interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", help_text,
                                                 name_str.GetSize());
        }
        else
        {
            interpreter.OutputHelpText(str, name_str.GetData(), "--", help_text,
                                       name_str.GetSize());
        }
    }
    else
        interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", entry->help_text, name_str.GetSize());
}
bool
FilesType::List( CommandInterpreter& inInterpreter )
{
  string dir = inInterpreter.GetOptionalToken(),
         wildcard = inInterpreter.GetOptionalToken();
  return DirectoryType::ListSelection( inInterpreter, dir, wildcard, &FileUtils::IsFile );
}
bool
DirectoryType::Exists( CommandInterpreter& inInterpreter )
{
  bool result = FileUtils::IsDirectory( inInterpreter.GetToken() );
  inInterpreter.Out() << ( result ? "true" : "false" );
  return true;
}
bool
StateType::List( CommandInterpreter& inInterpreter )
{
  Lock lock( inInterpreter.StateMachine() );
  inInterpreter.Out() << GetState( inInterpreter );
  return true;
}
bool
StateType::Exists( CommandInterpreter& inInterpreter )
{
  Lock lock( inInterpreter.StateMachine() );
  bool exists = inInterpreter.StateMachine().States().Exists( inInterpreter.GetToken() );
  inInterpreter.Out() << ( exists ? "true" : "false" );
  return true;
}
bool
StateType::Get( CommandInterpreter& inInterpreter )
{
  Lock lock( inInterpreter.StateMachine() );
  const State& state = GetState( inInterpreter ); // GetState() tests for existence of the state.
  inInterpreter.Out() <<  inInterpreter.StateMachine().GetStateValue( state.Name().c_str() );
  return true;
}
bool
PathType::Exists( CommandInterpreter& inInterpreter )
{
  string path = inInterpreter.GetToken();
  bool result = FileUtils::IsFile( path ) || FileUtils::IsDirectory( path );
  inInterpreter.Out() << ( result ? "true" : "false" );
  return true;
}
bool
DirectoryType::Make( CommandInterpreter& inInterpreter )
{
  string dir = inInterpreter.GetToken();
  if( !FileUtils::MakeDirectory( dir ) )
    inInterpreter.Out() << "Could not make directory \"" << dir << "\"";
  return true;
}
bool
LineType::Read( CommandInterpreter& inInterpreter )
{
  string line;
  if( !inInterpreter.ReadLine( line ) )
    throw bciexception( "No input associated with command interpreter of type " << ClassName( typeid( inInterpreter ) ) );
  inInterpreter.Out() << line;
  return true;
}
bool
StatesType::Clear( CommandInterpreter& inInterpreter )
{
  Lock lock( inInterpreter.StateMachine() );
  if( inInterpreter.StateMachine().SystemState() != StateMachine::Idle )
    throw bciexception( "Must be in idle state to clear states" );
  inInterpreter.StateMachine().States().Clear();
  return true;
}
bool
FileType::Extract( CommandInterpreter& inInterpreter )
{
  string file = inInterpreter.GetToken();
  if( !::stricmp( file.c_str(), "Base" ) )
    inInterpreter.Out() << FileUtils::ExtractBase( inInterpreter.GetToken() );
  else
    inInterpreter.Out() << FileUtils::ExtractFile( file );
  return true;
}
bool
DirectoryType::Rename( CommandInterpreter& inInterpreter )
{
  string dir = inInterpreter.GetToken(),
         newName = inInterpreter.GetToken();
  if( !FileUtils::IsDirectory( dir ) )
    throw bciexception( "There is no directory named \"" << dir << "\"" );
  if( !FileUtils::Rename( dir, newName ) )
    throw bciexception( "Could not rename \"" << dir << "\" to \"" << newName << "\"" );
  return true;
}
bool
FileType::Rename( CommandInterpreter& inInterpreter )
{
  string file = inInterpreter.GetToken(),
         newName = inInterpreter.GetToken();
  if( !FileUtils::IsFile( file ) )
    throw bciexception( "There is no file named \"" << file << "\"" );
  if( !FileUtils::Rename( file, newName ) )
    throw bciexception( "Could not rename file \"" << file << "\" to \"" << newName << "\"" );
  return true;
}
bool
StatesType::List( CommandInterpreter& inInterpreter )
{
  Lock lock( inInterpreter.StateMachine() );
  string pattern = inInterpreter.GetRemainingTokens();
  if( pattern.empty() )
    pattern = "*";
  const StateList& states = inInterpreter.StateMachine().States();
  for( int i = 0; i < states.Size(); ++i )
    if( WildcardMatch( pattern, states[i].Name(), false ) )
      inInterpreter.Out() << states[i] << '\n';
  return true;
}
bool
DirectoryType::List( CommandInterpreter& inInterpreter )
{
  string args;
#if _WIN32
  args = "/n ";
#else
  args = "-l ";
#endif
  string remainder = inInterpreter.GetRemainingTokens();
  args += remainder;
  inInterpreter.Out() << ListDirectory( args );
  return true;
}
Beispiel #16
0
void
Property::DumpDescription (CommandInterpreter &interpreter,
                           Stream &strm,
                           uint32_t output_width,
                           bool display_qualified_name) const
{
    if (m_value_sp)
    {
        const char *desc = GetDescription();

        if (desc)
        {
            StreamString qualified_name;
            const OptionValueProperties *sub_properties = m_value_sp->GetAsProperties();
            if (sub_properties)
            {
                strm.EOL();
                
                if (m_value_sp->DumpQualifiedName(qualified_name))
                    strm.Printf("'%s' variables:\n\n", qualified_name.GetString().c_str());
                sub_properties->DumpAllDescriptions(interpreter, strm);
            }
            else
            {
                if (desc)
                {
                    if (display_qualified_name)
                    {
                        StreamString qualified_name;
                        DumpQualifiedName(qualified_name);
                        interpreter.OutputFormattedHelpText (strm,
                                                             qualified_name.GetString().c_str(),
                                                             "--",
                                                             desc,
                                                             output_width);
                    }
                    else
                    {
                        interpreter.OutputFormattedHelpText (strm,
                                                             m_name.GetCString(),
                                                             "--",
                                                             desc,
                                                             output_width);
                    }
                }
            }
        }
    }
}
int
CommandCompletions::SettingsNames (CommandInterpreter &interpreter,
                                   const char *partial_setting_name,
                                   int match_start_point,
                                   int max_return_elements,
                                   SearchFilter *searcher,
                                   bool &word_complete,
                                   StringList &matches)
{
    // Cache the full setting name list
    static StringList g_property_names;
    if (g_property_names.GetSize() == 0)
    {
        // Generate the full setting name list on demand
        lldb::OptionValuePropertiesSP properties_sp (interpreter.GetDebugger().GetValueProperties());
        if (properties_sp)
        {
            StreamString strm;
            properties_sp->DumpValue(nullptr, strm, OptionValue::eDumpOptionName);
            const std::string &str = strm.GetString();
            g_property_names.SplitIntoLines(str.c_str(), str.size());
        }
    }
    
    size_t exact_matches_idx = SIZE_MAX;
    const size_t num_matches = g_property_names.AutoComplete (partial_setting_name, matches, exact_matches_idx);
    word_complete = exact_matches_idx != SIZE_MAX;
    return num_matches;
}
bool
OptionGroupFormat::ParserGDBFormatLetter (CommandInterpreter &interpreter, char format_letter, Format &format, uint32_t &byte_size)
{
    m_has_gdb_format = true;
    switch (format_letter)
    {
        case 'o': format = eFormatOctal;        m_prev_gdb_format = format_letter; return true; 
        case 'x': format = eFormatHex;          m_prev_gdb_format = format_letter; return true;
        case 'd': format = eFormatDecimal;      m_prev_gdb_format = format_letter; return true;
        case 'u': format = eFormatUnsigned;     m_prev_gdb_format = format_letter; return true;
        case 't': format = eFormatBinary;       m_prev_gdb_format = format_letter; return true;
        case 'f': format = eFormatFloat;        m_prev_gdb_format = format_letter; return true;
        case 'a': format = eFormatAddressInfo;
        {
            ExecutionContext exe_ctx(interpreter.GetExecutionContext());
            Target *target = exe_ctx.GetTargetPtr();
            if (target)
                byte_size = target->GetArchitecture().GetAddressByteSize();
            m_prev_gdb_format = format_letter;
            return true;
        }
        case 'i': format = eFormatInstruction;  m_prev_gdb_format = format_letter; return true;
        case 'c': format = eFormatChar;         m_prev_gdb_format = format_letter; return true;
        case 's': format = eFormatCString;      m_prev_gdb_format = format_letter; return true;
        case 'T': format = eFormatOSType;       m_prev_gdb_format = format_letter; return true;
        case 'A': format = eFormatHexFloat;     m_prev_gdb_format = format_letter; return true;
        case 'b': byte_size = 1;                m_prev_gdb_size = format_letter;   return true;
        case 'h': byte_size = 2;                m_prev_gdb_size = format_letter;   return true;
        case 'w': byte_size = 4;                m_prev_gdb_size = format_letter;   return true;
        case 'g': byte_size = 8;                m_prev_gdb_size = format_letter;   return true;
        default:  break;
    }
    return false;
}
int
CommandCompletions::SourceFiles(CommandInterpreter &interpreter,
                                const char *partial_file_name,
                                int match_start_point,
                                int max_return_elements,
                                SearchFilter *searcher,
                                bool &word_complete,
                                StringList &matches)
{
    word_complete = true;
    // Find some way to switch "include support files..."
    SourceFileCompleter completer (interpreter,
                                   false, 
                                   partial_file_name, 
                                   match_start_point, 
                                   max_return_elements,
                                   matches);

    if (searcher == nullptr)
    {
        lldb::TargetSP target_sp = interpreter.GetDebugger().GetSelectedTarget();
        SearchFilterForUnconstrainedSearches null_searcher (target_sp);
        completer.DoCompletion (&null_searcher);
    }
    else
    {
        completer.DoCompletion (searcher);
    }
    return matches.GetSize();
}
int
CommandCompletions::Symbols 
(
    CommandInterpreter &interpreter,
    const char *partial_file_name,
    int match_start_point,
    int max_return_elements,
    SearchFilter *searcher,
    bool &word_complete,
    StringList &matches)
{
    word_complete = true;
    SymbolCompleter completer (interpreter,
                               partial_file_name, 
                               match_start_point, 
                               max_return_elements, 
                               matches);

    if (searcher == NULL)
    {
        lldb::TargetSP target_sp = interpreter.GetDebugger().GetSelectedTarget();
        SearchFilterForUnconstrainedSearches null_searcher (target_sp);
        completer.DoCompletion (&null_searcher);
    }
    else
    {
        completer.DoCompletion (searcher);
    }
    return matches.GetSize();
}
int CommandCompletions::SettingsNames(CommandInterpreter &interpreter,
                                      CompletionRequest &request,
                                      SearchFilter *searcher) {
  // Cache the full setting name list
  static StringList g_property_names;
  if (g_property_names.GetSize() == 0) {
    // Generate the full setting name list on demand
    lldb::OptionValuePropertiesSP properties_sp(
        interpreter.GetDebugger().GetValueProperties());
    if (properties_sp) {
      StreamString strm;
      properties_sp->DumpValue(nullptr, strm, OptionValue::eDumpOptionName);
      const std::string &str = strm.GetString();
      g_property_names.SplitIntoLines(str.c_str(), str.size());
    }
  }

  size_t exact_matches_idx = SIZE_MAX;
  StringList matches;
  g_property_names.AutoComplete(request.GetCursorArgumentPrefix(), matches,
                                exact_matches_idx);
  request.SetWordComplete(exact_matches_idx != SIZE_MAX);
  request.AddCompletions(matches);
  return request.GetNumberOfMatches();
}
void
OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter)
{
    // If these defaults change, be sure to modify AnyOptionWasSet().
    show_types        = false;
    no_summary_depth  = 0;
    show_location     = false;
    flat_output       = false;
    use_objc          = false;
    max_depth         = UINT32_MAX;
    ptr_depth         = 0;
    use_synth         = true;
    be_raw            = false;
    ignore_cap        = false;
    run_validator     = false;
    
    Target *target = interpreter.GetExecutionContext().GetTargetPtr();
    if (target != nullptr)
        use_dynamic = target->GetPreferDynamicValue();
    else
    {
        // If we don't have any targets, then dynamic values won't do us much good.
        use_dynamic = lldb::eNoDynamicValues;
    }
}
Beispiel #23
0
void callback( String& topic, String& message )
{
    //Serial.print(topic);
    //Serial.print(":");
    //Serial.println(message);

    interpreter.interpret( topic, message );
}
bool
StateType::Insert( CommandInterpreter& inInterpreter )
{
  string name = inInterpreter.GetToken();
  string line = inInterpreter.GetRemainder(),
         stateline = name + " " + line + " 0 0";
  State state;
  istringstream iss( stateline );
  if( !( iss >> state ) )
    throw bciexception( "Invalid state definition" );
  {
    Lock lock( inInterpreter.StateMachine() );
    switch( inInterpreter.StateMachine().SystemState() )
    {
      case StateMachine::Idle:
      case StateMachine::WaitingForConnection:
      case StateMachine::Publishing:
      case StateMachine::Information:
        break;
      default:
        throw bciexception( "Could not add state " << name << " to list after information phase" );
    }
    inInterpreter.StateMachine().States().Add( state );
  }
  inInterpreter.StateMachine().ExecuteCallback( BCI_OnState, stateline.c_str() );
  inInterpreter.Log() << "Added state " << name << " to list";
  return true;
}
bool
Interpreter::SignalType::Get( CommandInterpreter& inInterpreter )
{
    Lock lock( inInterpreter.StateMachine() );
    const GenericSignal& signal = inInterpreter.StateMachine().ControlSignal();
    string name = inInterpreter.GetToken();
    if( !::stricmp( name.c_str(), "Channels" ) )
    {
        inInterpreter.Out() << signal.Channels();
    }
    else if( !::stricmp( name.c_str(), "Elements" ) )
    {
        inInterpreter.Out() << signal.Elements();
    }
    else
    {
        CommandInterpreter::ArgumentList args;
        inInterpreter.ParseArguments( name, args );
        if( ::stricmp( name.c_str(), "Signal" ) )
            throw bciexception( "Use 'Signal' to address the signal" );
        if( args.size() != 1 || args[0].size() != 2 )
            throw bciexception( "Expected two signal indices" );
        int idx1 = ::atoi( args[0][0].c_str() ) - 1,
            idx2 = ::atoi( args[0][1].c_str() ) - 1;
        if( idx1 < 0 || idx2 < 0 || idx1 >= signal.Channels() || idx2 >= signal.Elements() )
            throw bciexception( "Signal index out of range" );
        inInterpreter.Out() << signal( idx1, idx2 );
    }
    return true;
}
bool
LineType::Write( CommandInterpreter& inInterpreter )
{
  string args = inInterpreter.GetRemainingTokens(),
         line;
  istringstream iss( args );
  ParserToken arg;
  if( iss >> arg )
    line = arg;
  while( iss >> arg )
  {
    line += " ";
    line += arg;
  }
  if( !inInterpreter.WriteLine( line ) )
    throw bciexception( "No output associated with command interpreter of type " << ClassName( typeid( inInterpreter ) ) );
  return true;
}
bool
DirectoryType::ForceRemove( CommandInterpreter& inInterpreter )
{
  string dir = inInterpreter.GetToken();
  if( !FileUtils::IsDirectory( dir ) )
    throw bciexception( "There is no directory named \"" << dir << "\"" );
  if( !FileUtils::RemoveDirectory( dir, true ) )
    throw bciexception( "Could not remove directory \"" << dir << "\"" );
  return true;
}
int
CommandCompletions::VariablePath (CommandInterpreter &interpreter,
                                  const char *partial_name,
                                  int match_start_point,
                                  int max_return_elements,
                                  SearchFilter *searcher,
                                  bool &word_complete,
                                  lldb_private::StringList &matches)
{
    return Variable::AutoComplete (interpreter.GetExecutionContext(), partial_name, matches, word_complete);
}
bool
StateType::Set( CommandInterpreter& inInterpreter )
{
  string name;
  State::ValueType value = 0;
  ostringstream oss;
  {
    Lock lock( inInterpreter.StateMachine() );
    State& state = GetState( inInterpreter );
    name = state.Name();
    value = ::atoi( inInterpreter.GetToken().c_str() );
    if( !inInterpreter.StateMachine().SetStateValue( name.c_str(), value ) )
      throw bciexception( "Could not set state " << name << " to " << value );
    // StateMachine::SetStateValue() does not set the value of the state object in its state list.
    state.SetValue( value );
    oss << state;
  }
  inInterpreter.StateMachine().ExecuteCallback( BCI_OnState, oss.str().c_str() );
  inInterpreter.Log() << "Set state " << name << " to " << value;
  return true;
}
bool
DirectoryType::ListSelection( CommandInterpreter& inInterpreter, const string& inDir, const string& inWildcard, bool (*inSelector)( const string& ) )
{
  string dir = inDir.empty() ? "." : inDir,
         wildcard = inWildcard.empty() ? "*" : inWildcard;
  dir = FileUtils::CanonicalPath( dir );
  FileUtils::List list;
  if( !FileUtils::ListDirectory( dir, list ) )
    throw bciexception( "Could not list directory \"" << dir << "\"" );
  for( size_t i = 0; i < list.size(); ++i )
    if( WildcardMatch( wildcard, list[i], false ) && inSelector( FileUtils::EnsureSeparator( dir ) + list[i] ) )
      inInterpreter.Out() << list[i] << '\n';
  return true;
}