Example #1
0
bool SlavesManager::add(const string& hostname, uint16_t port)
{
  // Ignore request if slave is already active.
  if (active.contains(hostname, port)) {
    LOG(WARNING) << "Attempted to add an already added slave!";
    return false;
  }

  // Make sure this slave is not currently deactivated.
  if (inactive.contains(hostname, port)) {
    LOG(WARNING) << "Attempted to add a deactivated slave, "
                 << "try activating it instead!";
    return false;
  }

  // Ask the storage system to persist the addition.
  Future<bool> added =
    process::dispatch(storage->self(), &SlavesManagerStorage::add,
                      hostname, port);

  added.await();

  if (added.isReady() && added.get()) {
    active.put(hostname, port);

    // Tell the master that this slave is now active.
    process::dispatch(master, &Master::activatedSlaveHostnamePort,
                      hostname, port);

    return true;
  }

  return false;
}
Example #2
0
bool SlavesManager::remove(const string& hostname, uint16_t port)
{
  // Make sure the slave is currently activated or deactivated.
  if (!active.contains(hostname, port) &&
      !inactive.contains(hostname, port)) {
    LOG(WARNING) << "Attempted to remove unknown slave!";
    return false;
  }

  // Get the storage system to persist the removal.
  Future<bool> removed =
    process::dispatch(storage->self(), &SlavesManagerStorage::remove,
                      hostname, port);

  removed.await();

  if (removed.isReady() && removed.get()) {
    active.remove(hostname, port);
    inactive.remove(hostname, port);

    // Tell the master that this slave is now deactivated.
    process::dispatch(master, &Master::deactivatedSlaveHostnamePort,
                      hostname, port);

    return true;
  }

  return false;
}
Example #3
0
// Return true if CMD begins recording commands 
bool starts_recording(const string& cmd)
{
    return cmd.contains("if", 0) ||
	cmd.contains("while", 0) ||
	cmd.contains("def", 0) ||
	cmd.contains("doc", 0) ||
	cmd.contains("comm", 0); 
}
Example #4
0
static bool starts_with(const string& cmd, const string& prefix)
{
    if (prefix.empty())
	return false;

    return cmd == prefix || 
	(prefix.contains(' ', -1) && cmd.contains(prefix, 0)) ||
	cmd.contains(prefix + " ", 0);
}
Example #5
0
void set_status_from_gdb(const string& text)
{
    if (private_gdb_input)
	return;

    if (!show_next_line_in_status && !text.contains(gdb->prompt(), -1))
	return;

    // Fetch line before prompt in GDB window
    String s = XmTextGetString(gdb_w);
    string message = s + messagePosition;
    XtFree(s);

    if (message.empty() && text.contains('\n'))
	message = text;

    if (show_next_line_in_status && 
	(message.empty() || message[message.length() - 1] != '\n'))
	return;

    // Skip prompt and uncomplete lines
    int idx = message.index('\n', -1);
    if (idx >= 0)
	message = message.before(idx);

    strip_trailing_newlines(message);
    if (message.empty() && text.contains('\n'))
	message = text;

    if (show_next_line_in_status)
    {
	messagePosition = XmTextGetLastPosition(gdb_w) + text.length();
	show_next_line_in_status = false;
	message.gsub('\n', ' ');
    }
    else
    {
	// Show first line only
	while (!message.empty() && message[0] == '\n')
	    message = message.after('\n');
	if (message.contains('\n'))
	    message = message.before('\n');
    }

    strip_trailing_newlines(message);
    message.gsub('\t', ' ');
    if (message.empty())
	return;

    // Don't log this stuff - it's already logged
    bool old_log_status = log_status;
    log_status = false;
    set_status(message);
    log_status = old_log_status;
}
Example #6
0
// In FORTRAN mode, GDB issues last dimensions first.  Insert new
// dimension before first dimension and convert to FORTRAN
// multi-dimension syntax.
string DispValue::add_member_name(const string& base, 
				  const string& member_name)
{
    if (gdb->program_language() == LANGUAGE_FORTRAN && 
	member_name.contains('(', 0) &&	base.contains('('))
    {
	return base.before('(') + member_name.before(')') + ", " + 
	    base.after('(');
    }

    return base + member_name;
}
Example #7
0
int INIparser::addSection(string filename, string sectionName)
{
	if(sectionName.contains('='))
	{
		// qDebug() << "Invalid characters in sectionName";
		// qDebug() << "User cannot use '='";
		return -4;
	}

	string temp = filename.toLower();
	if(!filename.contains(".ini"))
	{
		temp = temp + ".ini";
	}
	File file(temp);

	if(!file.exists())
	{
		// qDebug() << "File does not exists";
		return -1;
	}

	if(!file.open(QIODevice::ReadWrite | QIODevice::Text))		// |QIODevice::Text to enable \n
	{
		// qDebug() << "Cannot open file";
		return -2;
	}

	string string = file.readAll();
	sectionName = '[' + sectionName + ']';

	if(string.contains(sectionName))
	{
		// qDebug() << "sectionName already exists";
		file.close();
		return -3;
	}

	if(file.pos() != 0)					// To remove whitespace at beginning of file
	{
		string = string + "\n\n";
	}

	string.append(sectionName);

	file.resize(0);						// Empty the file
	file.write(string.toUtf8());		// Write to the file
	file.close();
	return 0;
}
Example #8
0
int INIparser::createVariable(string filename, string data, string value)
{
	if(data.contains('='))
	{
		// qDebug() << "Invalid characters in data";
		// qDebug() << "User cannot use '='";
		return -4;
	}

	string temp = filename.toLower();
	if(!filename.contains(".ini"))
	{
		temp = temp + ".ini";
	}
	File file(temp);

	if(!file.exists())
	{
		// qDebug() << "File does not exists";
		return -1;
	}

	if(!file.open(QIODevice::ReadWrite | QIODevice::Text))		// |QIODevice::Text to enable \n
	{
		// qDebug() << "Cannot open file";
		return -2;
	}

	string string = file.readAll();
	if(string.contains(data + '='))
	{
		// qDebug() << "Data already exists";
		file.close();
		return -3;
	}

	if(file.pos() != 0)								// To remove whitespace at beginning of file
	{
		string = '\n' + data + '=' + value;
	}
	else
	{
		string = data + '=' + value;
	}

	file.write(string.toUtf8());
	file.close();
	return 0;
}
Example #9
0
// True if VALUE is an valid value (i.e., no error message)
bool is_valid(const string& value, GDBAgent *gdb)
{
    if (gdb->program_language() == LANGUAGE_PERL)
	return true;		// Everything is valid in perl

    // If VALUE ends in two words, it is an error message like `not
    // active' or `no symbol in current context.'.  XDB issues
    // `Unknown name "Foo" (UE369)' and `Local is not active (UE421)'.
#if RUNTIME_REGEX
    static regex rxinvalid_value("("
				 "[a-zA-Z]+ [a-zA-Z]+.*"
				 "|.*[a-zA-Z]+ [a-zA-Z]+(\\.|>)?"
				 ")\n?");
#endif

    if (value.contains("Unknown name"))
	return false;

    if (value.contains("Name unknown"))
	return false;

    if (value.contains("not active"))
	return false;

    if (value.contains("not defined"))
	return false;

    if (value.contains("not valid"))
	return false;

    if (value.contains("Was expecting"))
	return false;		// JDB 1.2

    if (value.contains("incorrect type"))
	return false;		// JDB 1.2

    if (value.contains("not a valid"))
	return false;		// JDB 1.2

    if (value.contains("Encountered \"", 0))
	return false;		// JDB 1.2

    // In JDB 1.2, values start with `instance of'
    if (!value.contains("instance of", 0) && value.matches(rxinvalid_value))
	return false;

    return true;
}
Example #10
0
// Return directory name
static string dirname(const string& file)
{
    if (file.contains('/'))
	return file.before('/', -1);
    else
	return ".";
}
Example #11
0
bool SlavesManager::deactivate(const string& hostname, uint16_t port)
{
  // Make sure the slave is currently activated.
  if (active.contains(hostname, port)) {
    // Get the storage system to persist the deactivation.
    Future<bool> deactivated =
      process::dispatch(storage->self(), &SlavesManagerStorage::deactivate,
                        hostname, port);

    deactivated.await();

    if (deactivated.isReady() && deactivated.get()) {
      active.remove(hostname, port);
      inactive.put(hostname, port);

      // Tell the master that this slave is now deactivated.
      process::dispatch(master, &Master::deactivatedSlaveHostnamePort,
                        hostname, port);

      return true;
    }
  }

  return false;
}
Example #12
0
// Return next display info from GDB_ANSWER; "" if none.
string read_next_disp_info (string& gdb_answer, GDBAgent *gdb)
{
    switch (gdb->type())
    {
    case GDB:
    case PYDB:
    {
	int startpos = gdb_answer.index (": ");
	int i = startpos + 2;

	for (;;)
	{
	    while (i < int(gdb_answer.length()) && gdb_answer[i] != '\n')
		i++;
	    if (i >= int(gdb_answer.length()))
	    {
		// Take entire remaining output as display
		string next_disp_info = gdb_answer;
		gdb_answer = "";
		return next_disp_info;
	    }

	    assert(gdb_answer[i] == '\n');
	    if (gdb_answer.contains(rxgdb_begin_of_display_info, i + 1))
	    {
		// Use output up to `\n[0-9]' as display
		string next_disp_info = gdb_answer.before(i);
		gdb_answer = gdb_answer.after(i);
		return next_disp_info;
	    }

	    i++;
	}
    }

    case DBX:
    {
	string next_disp_info;
	int i = gdb_answer.index('\n');
	if (i > 0)
	{
	    next_disp_info = gdb_answer.before(i);
	    gdb_answer = gdb_answer.after(i);
	}
	else
	{
	    next_disp_info = gdb_answer;
	    gdb_answer = "";
	}
	return next_disp_info;
    }

    case XDB:
    case JDB:
    case PERL:
	break;			// FIXME
    }

    return "";
}
Example #13
0
// Return index of first display in GDB_ANSWER; -1 if none
int display_index (const string& gdb_answer, GDBAgent *gdb)
{
#if RUNTIME_REGEX
    static regex rxgdb_begin_of_display("[1-9][0-9]*:  *[^ ]");
    static regex rxdbx_begin_of_display("[^ \t\n)}][^=\n]* = ");
#endif

    const regex *prx = 0;

    switch (gdb->type())
    {
    case GDB: 
    case PYDB:
    case DBG:
	prx = &rxgdb_begin_of_display;
	break;

    case BASH:
    case DBX:
    case JDB:
    case PERL:
    case XDB:
	prx = &rxdbx_begin_of_display;
	break;
    }

    const regex& rx = *prx;

    for (unsigned i = 0; i < gdb_answer.length(); i++)
	if (i == 0 || gdb_answer[i - 1] == '\n')
	    if (gdb_answer.contains(rx, i))
		return i;

    return -1;
}
Example #14
0
// Return ID in `fortranized' form -- that is, in lower/upper case and
// with `_' suffix.
static string _fortranize_globals(const string& id)
{
    if (!id.contains('_', -1))
    {
	// 1. Try `_'  postfix, lower-case.  Global objects in g77.
	// 2. Try `__' postfix, lower-case.  In g77, if the name contains `_'.
	// 3. Try `_'  postfix, upper-case.  Global objects in f77.
	// 4. Try `__' postfix, upper-case.  In f77?

	for (int caps = 0; caps < 2; caps++)
	{
	    string new_id = caps ? upcase(id) : downcase(id);
	    
	    for (int suffix_length = 1; suffix_length < 3; suffix_length++)
	    {
		new_id += '_';
		if (is_valid(gdbValue(new_id), gdb))
		    return new_id;
	    }
	}
    }

    // Don't know what to try next - use as given
    return id;
}
Example #15
0
// Return index of first display in GDB_ANSWER; -1 if none
static int display_info_index (const string& gdb_answer, GDBAgent *gdb)
{
    const regex *prx = 0;

    switch (gdb->type())
    {
    case GDB: 
    case PYDB:
    case DBG:
	prx = &rxgdb_begin_of_display_info;
	break;

    case DBX:
	prx = &rxdbx_begin_of_display_info;
	break;

    case JDB:
    case XDB:
    case PERL:
    case BASH:
	return -1;		// No displays in these debuggers
    }

    const regex& rx = *prx;

    for (unsigned i = 0; i < gdb_answer.length(); i++)
	if (i == 0 || gdb_answer[i - 1] == '\n')
	    if (gdb_answer.contains(rx, i))
		return i;

    return -1;
}
Example #16
0
string set_history_filter(const string& cmd)
{
    string arg;

    if (cmd.contains(" = "))
	arg = cmd.after(" = ");
    else if (cmd.contains(" := "))
	arg = cmd.after(" := ");

    if (!arg.empty())
    {
	strip_space(arg);
	return arg;
    }

    return "";
}
Example #17
0
static void send_and_replot(PlotWindowInfo *plot, string cmd)
{
    if (cmd.matches(rxwhite))
	return;

    if (!cmd.contains('\n', -1))
	cmd += "\n";
    if (cmd.contains("help", 0))
	cmd += "\n";		// Exit `help'
    else
	cmd += "replot\n";

    if (plot->area != 0)
	plot->area->plot_pending();

    send(plot, cmd);
}
Example #18
0
// True if CMD has no effect on DDD state
bool is_nop_cmd(const string& cmd)
{
    if (app_data.play_log != 0)
    {
	if (cmd.contains('/', 0) ||
	    cmd.contains('?', 0) ||
	    cmd.contains('.', 0) ||
	    cmd.contains('!', 0))
	    return true;
    }

#if RUNTIME_REGEX
    // All these command have no effect on DDD state
    static regex rxnop_cmd("[ \t]*(echo|help|show|info|where|shell|sh|x)([ \t]+.*)?");
#endif

    return cmd.matches(rxnop_cmd);
}
Example #19
0
static bool try_arg(const string& cmd, const string& prefix_, string& arg)
{
    if (prefix_.empty())
	return false;		// No such command
    string prefix( prefix_ );
    if (!prefix.contains(" ", -1))
	prefix += " ";

    if (cmd.contains(prefix, 0))
    {
	arg = cmd.after(prefix);
	strip_space(arg);

	// Strip format stuff
	while (arg.contains('/', 0))
	    arg = arg.after(' ');

	if (arg.contains("'", 0))
	{
	    // Quoted arg -- add as unquoted
	    arg = unquote(arg);
	    return true;
	}
	else if (is_file_pos(arg))
	{
	    // FILE:LINE arg -- ignore
	    return false;
	}
	else if (arg.matches(rxint))
	{
	    // LINE arg -- ignore
	    return false;
	}
	else
	{
	    // Other arg -- add unchanged
	    return true;
	}
    }

    // Bad prefix -- ignore
    return false;
}
Example #20
0
// True if COND is `false' or starts with `false and'
bool BreakPoint::is_false(const string& cond)
{
    if (cond == false_value())
	return true;

    const string c = downcase(cond);
    const string prefix = downcase(false_value() + and_op());

    return c.contains(prefix, 0);
}
Example #21
0
// True if CMD changes debuggee
bool is_file_cmd (const string& cmd, GDBAgent *gdb)
{
    if (cmd == "# reset")
	return true;

    switch (gdb->type())
    {
    case GDB:
    case PYDB:
    case DBG:
    {
#if RUNTIME_REGEX
	static regex rxfile_cmd("[ \t]*(file|load)([ \t]+.*)?");
#endif
	return cmd.matches (rxfile_cmd);
    }

    case DBX:
    {
#if RUNTIME_REGEX
	static regex rxdebug_cmd("[ \t]*(debug|givenfile)([ \t]+.*)?");
#endif
	return cmd.matches (rxdebug_cmd);
    }

    case XDB:
	return cmd.contains("#file ", 0);

    case JDB:
	return cmd.contains("load ", 0);

    case PERL:
	return cmd.contains("exec ", 0);

    case BASH:
	return cmd.contains("exec ", 0);
    }

    assert(0);
    ::abort();
    return false;
}
Example #22
0
// True if VALUE is an valid value (i.e., no error message)
bool is_valid(const string& value, GDBAgent *gdb)
{
    if (gdb->program_language() == LANGUAGE_PERL)
	return true;		// Everything is valid in perl

    // If VALUE ends in two words, it is an error message like `not
    // active' or `no symbol in current context.'.  XDB issues
    // `Unknown name "Foo" (UE369)' and `Local is not active (UE421)'.
#if RUNTIME_REGEX
    static regex rxinvalid_value("("
				 "[a-zA-Z]+ [a-zA-Z]+.*"
				 "|.*[a-zA-Z]+ [a-zA-Z]+(\\.|>)?"
				 ")\n?");
#endif

    return !value.contains("Unknown name") 
	&& !value.contains("not active")
	&& !value.contains("not defined")
	&& !value.matches(rxinvalid_value);
}
Example #23
0
static string app_value(const string& resource, const string& value)
{
    String app_name;
    String app_class;
    XtGetApplicationNameAndClass(XtDisplay(find_shell()), 
				 &app_name, &app_class);

    if (resource.contains(string(app_name) + ".", 0))
	return string(app_class) + resource.from(".") + ": " + value;
    else
	return string(app_class) + "*" + resource + ": " + value;
}
Example #24
0
static void gdbEditOutputHP(Agent *, void *, void *call_data)
{
    DataLength *input = (DataLength *)call_data;
    output_buffer += string(input->data, input->length);
    while (output_buffer.contains('\n'))
    {
	set_status(output_buffer.before('\n'));
	output_buffer = output_buffer.after('\n');
    }
    if (output_buffer != "")
	set_status(output_buffer);
}
Example #25
0
void PosBuffer::filter_pydb(string& answer)
{
    if (already_read != PosComplete && !answer.contains('\n'))
    {
	// Position info is incomplete
	answer_buffer = answer;
	answer = "";
	already_read = PosPart;
	return;
    }

    // `Breakpoint N, FUNCTION (ARGS...) at file:line_no'
    // rxstopped_func defined for GDB...if it changes, change here
    int fn_index = index(answer, rxstopped_func, "Breakpoint");
    if (fn_index >= 0)
    {
	fetch_function(answer, fn_index, func_buffer);
    }
    else
    {
	// `#FRAME FUNCTION(args) at file:line_no'
	// Likewise rxframe_func defined for GDB
	int frame_index = index(answer, rxframe_addr, "#");
	if (frame_index == 0
	    || frame_index > 0 && answer[frame_index - 1] == '\n')
	{
	    fetch_function(answer, frame_index, func_buffer);
	}
    }

    int lineinfo  = answer.index("Lineinfo");
    // Lineinfo <function> at file:lineno
    if (lineinfo == 0 || (lineinfo > 0 && answer[lineinfo - 1] == '\n'))
    {
	answer = answer.after('<');
	func_buffer = answer.before('>');
    }

    string result = answer.after(" at ");
    result = result.before('\n');
    if (result.contains(':'))
    {
	pos_buffer = result;
	already_read = PosComplete;
    }

    // Don't need the answer anymore when line matches 'Lineinfo'
    if (lineinfo >= 0)
    {
	answer = "";
    }
}
// Determine debugger type from DEBUGGER_NAME
bool get_debugger_type(const string& debugger_name, DebuggerType& type)
{
    for (int i = 0; i < int(XtNumber(debuggers)); i++)
	if (debugger_name.contains(debuggers[i].cmd))
	{
	    // Found
	    type = debuggers[i].type;
	    return true;
	}

    // Failed
    return false;
}
Example #27
0
void gdb_button_command(const string& command, Widget origin)
{
    if (command.contains("..."))
    {
	set_current_line(command.before("...") + " ");
    }
    else
    {
	string c = command;
	c.gsub("()", source_arg->get_string());
	if (add_running_arguments(c, origin))
	    gdb_command(c, origin);
    }
}
Example #28
0
string replaceIllegalNameChars(string fn, bool allowWC) {
	const string illegal = getIllegalNameChars(allowWC);
	string_formatter output;
	for(t_size walk = 0; walk < fn.length(); ++walk) {
		const char c = fn[walk];
		if (string::isNonTextChar(c) || illegal.contains(c)) {
			string replacement = replaceIllegalChar(c);
			if (replacement.containsAnyChar(illegal)) /*per-OS weirdness security*/ replacement = "_";
			output << replacement.ptr();
		} else {
			output.add_byte(c);
		}
	}
	return output.toString();
}
Example #29
0
int INIparser::deleteVariable(string filename, string data)
{
	string temp = filename.toLower();
	if(!filename.contains(".ini"))
	{
		temp = temp + ".ini";
	}
	File file(temp);

	if(!file.exists())
	{
		// qDebug() << "File does not exists";
		return -1;
	}

	if(!file.open(QIODevice::ReadWrite))
	{
		// qDebug() << "Cannot open file";
		return -2;
	}

	string string = file.readAll();
	if(!string.contains(data + '='))
	{
		// qDebug() << "Data does not exists";
		file.close();
		return -3;
	}

	file.seek(0);							// Reset pos to start of file
	temp = "";								// Clear temp
	while(!file.atEnd())
	{
		// Add all the lines which don't contain <data>
		string = file.readLine();
		if(!string.contains(data + '='))
		{
			temp.append(string);
		}
	}

	file.resize(0);					// Empty the file
	file.write(temp.toUtf8());		// Write to the file
	file.close();

	return 0;
}
Example #30
0
// True if CMD changes variables
bool is_assign_cmd(const string& cmd, GDBAgent *gdb)
{
#if RUNTIME_REGEX
    static regex rxset1_cmd("[ \t]*(set[ \t]+var[a-z]*|assign|pq)([ \t]+.*)?");
    static regex rxset2_cmd("[ \t]*(set|p|print|output)[ \t]+[^=]+=[^=].*");
    static regex rxset3_cmd("[ \t]*[^=]+=[^=].*");
#endif

    DebuggerType type = gdb->type();

    if (type == PERL && cmd.contains("O ", 0))
	return false;		// Setting command

    return cmd.matches(rxset1_cmd) || 
	((type == GDB || type == JDB) && cmd.matches(rxset2_cmd)) ||
	((type == PYDB || type == PERL) && cmd.matches(rxset3_cmd));
}