const char *default_debugger(const string& debugger_name, DebuggerType type)
{
    if (type == DBX && debugger_name == "ladebug")
    {
	// This happens when using the `--ladebug' option.
	return "ladebug";
    }

    if (type == GDB && debugger_name == "wdb")
    {
	// This happens when using the `--wdb' option.
	return "wdb";
    }

    int i;
    for (i = 0; i < int(XtNumber(debuggers)); i++)
	if (type == debuggers[i].type && have_cmd(debuggers[i].cmd))
	    return debuggers[i].cmd;

    for (i = 0; i < int(XtNumber(debuggers)); i++)
	if (type == debuggers[i].type)
	    return debuggers[i].cmd;

    // This can't happen.
    assert(0);
    ::abort();
    return "false";
}
Exemple #2
0
void parse_botcmd(int idx, const char* code, const char* msg) {
  const botcmd_t *cmd = search_botcmd_t((const botcmd_t*)&C_bot, code, lengthof(C_bot) - 1);

  if (cmd) {
    /* Found a match */
    if (have_cmd(NULL, cmd->type))
      (cmd->func) (idx, (char*)msg);
  }
}
void cmd_handler::run_command_loop(const std::string & prompt)
{
    UNUSED_PARAM(prompt);
    bool run = true;
    register_handler("quit",
            [&run](const cmd_vector_t & cmd)
            {
                UNUSED_PARAM(cmd);
                run = false;
                return true;
            }, 0, "quit this program");

    std::string line;

    while (run)
    {
        line = readline("\n>");
        if (line.empty())
        {
            continue;
        }
        auto splits = split<std::string>(line, ' ');
        if (splits.size() > 0)
        {
            const std::string & verb = splits[0];
            if (have_cmd(verb))
            {
                std::string help;
                if (!do_cmd(splits, help))
                {
                    std::cerr << help << std::endl;
                }
                else
                {
                    add_history(line);
                }
            }
            else
            {
                std::cerr << "Unrecognized command: " << verb << std::endl;
            }
        }
    }
}
// Return an appropriate debugger type from ARGC/ARGV.
// Set ARG if debugger type could be deduced from an argument.
DebuggerInfo::DebuggerInfo(int argc, const char * const argv[])
    : type(DebuggerType(-1)),
      arg("")
{
    DebuggerType fallback = DebuggerType(-1);
    get_debugger_type(app_data.debugger, fallback);

    static bool have_bash   = (fallback == BASH || have_cmd("bash"));
    static bool have_dbg    = (fallback == DBG  || have_cmd("dbg"));
    static bool have_perl   = (fallback == PERL || have_cmd("perl"));
    static bool have_python = (fallback == PYDB || have_cmd("python"));

    // 1. Check for Perl and Python scripts as given.

    int i;
    for (i = 1; i < argc; i++)
    {
	arg = argv[i];

	if (arg.contains('-', 0))
	    continue;		// Option

	if (have_perl && is_perl_file(arg))
	{
	    type = PERL;
	    return;
	}

	if (have_bash && is_bash_file(arg))
	{
	    type = BASH;
	    return;
	}

	if (have_python && is_python_file(arg))
	{
	    type = PYDB;
	    return;
	}
	
	if (have_dbg && is_php_file(arg))
	{
	    type = DBG;
	    return;
	}
    }


    // 2. Check for executable binary as given.

    static bool have_gdb = (fallback == GDB || have_cmd("gdb"));
    static bool have_dbx = 
	(fallback == DBX || have_cmd("dbx") || have_cmd("ladebug"));
    static bool have_xdb = (fallback == XDB || have_cmd("xdb"));

    for (i = 1; i < argc; i++)
    {
	arg = argv[i];

	if (arg.contains('-', 0))
	    continue;		// Option

	if (is_debuggee_file(arg))
	{
	    if (fallback == GDB || fallback == DBX || fallback == XDB)
	    {
		type = fallback;
		return;
	    }

	    if (have_gdb)
	    {
		type = GDB;
		return;
	    }

	    if (have_dbx)
	    {
		type = DBX;
		return;
	    }

	    if (have_xdb)
	    {
		type = XDB;
		return;
	    }
	}
    }


    // 3. Check for Java class in current directory.

    static bool have_jdb = (fallback == JDB || have_cmd("jdb"));

    if (have_jdb)
    {
	for (i = 1; i < argc; i++)
	{
	    arg = argv[i];

	    if (arg.contains('-', 0))
		continue;		// Option
	    if (arg.contains('/', 0))
		continue;		// File

	    arg.gsub('.', '/');

	    if (is_regular_file(arg + ".java"))
	    {
		type = JDB;
		return;
	    }

	    if (is_regular_file(arg + ".class"))
	    {
		type = JDB;
		return;
	    }
	}
    }


    // 4. Check for executable binary in PATH.

    for (i = 1; i < argc; i++)
    {
	arg = argv[i];

	if (arg.contains('-', 0))
	    continue;		// Option

	const char *path_s = getenv("PATH");
	if (path_s == 0)
	    path_s = ".";

	string path = path_s;
	while (!path.empty())
	{
	    string dir;
	    if (path.contains(':'))
		dir = path.before(':');
	    else
		dir = path;
	    path = path.after(':');

	    if (dir.empty())
		dir = ".";
	    if (!dir.contains('/', -1))
		dir += '/';

	    if (is_debuggee_file(dir + arg))
	    {
		if (fallback == GDB || fallback == DBX || fallback == XDB)
		{
		    type = fallback;
		    return;
		}

		if (have_gdb)
		{
		    type = GDB;
		    return;
		}

		if (have_dbx)
		{
		    type = DBX;
		    return;
		}

		if (have_xdb)
		{
		    type = XDB;
		    return;
		}
	    }
	}
    }


    // 5. Check for Java class in CLASSPATH.

    if (have_jdb)
    {
	for (i = 1; i < argc; i++)
	{
	    arg = argv[i];

	    if (arg.contains('-', 0))
		continue;		// Option
	    if (arg.contains('/', 0))
		continue;		// File

	    const char *classpath_s = getenv("CLASSPATH");
	    if (classpath_s == 0)
		classpath_s = ".";

	    string classpath = classpath_s;
	    while (!classpath.empty())
	    {
		string dir;
		if (classpath.contains(':'))
		    dir = classpath.before(':');
		else
		    dir = classpath;
		classpath = classpath.after(':');

		if (dir.empty())
		    dir = ".";
		if (!dir.contains('/', -1))
		    dir += '/';

		string path = arg;
		path.gsub('.', '/');

		if (is_regular_file(dir + path + ".java"))
		{
		    type = JDB;
		    return;
		}

		if (is_regular_file(dir + path + ".class"))
		{
		    type = JDB;
		    return;
		}
	    }
	}
    }


    // 6. Use fallback.

    arg = "";

    if (fallback != DebuggerType(-1))
    {
	type = fallback;
	return;
    }


    // 7. All fails.  Use GDB.
    type = GDB;
}