//===-- CommandObjectSource.cpp ---------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "CommandObjectSource.h" // C Includes // C++ Includes // Other libraries and framework includes // Project includes #include "lldb/Interpreter/Args.h" #include "lldb/Core/Debugger.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Target/Process.h" #include "lldb/Target/TargetList.h" using namespace lldb; using namespace lldb_private; const char *k_space_characters = "\t\n\v\f\r "; //------------------------------------------------------------------------- // CommandObjectSource //------------------------------------------------------------------------- CommandObjectSource::CommandObjectSource() : CommandObject ("source", "Reads in debugger commands from the file and executes them.", "source ") { } CommandObjectSource::~CommandObjectSource () { } bool CommandObjectSource::Execute ( CommandInterpreter &interpreter, Args& args, CommandReturnObject &result ) { const int argc = args.GetArgumentCount(); if (argc == 1) { const char *filename = args.GetArgumentAtIndex(0); bool success = true; result.AppendMessageWithFormat ("Executing commands in '%s'.\n", filename); FileSpec cmd_file (filename); if (cmd_file.Exists()) { STLStringArray commands; success = cmd_file.ReadFileLines (commands); STLStringArray::iterator pos = commands.begin(); // Trim out any empty lines or lines that start with the comment // char '#' while (pos != commands.end()) { bool remove_string = false; size_t non_space = pos->find_first_not_of (k_space_characters); if (non_space == std::string::npos) remove_string = true; // Empty line else if ((*pos)[non_space] == '#') remove_string = true; // Comment line that starts with '#' if (remove_string) pos = commands.erase(pos); else ++pos; } if (commands.size() > 0) { const size_t num_commands = commands.size(); size_t i; for (i = 0; i