Example #1
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 #2
0
void BreakPoint::process_jdb(string& info_output)
{
    int colon = info_output.index(':');
    if (colon >= 0)
    {
	string class_name = info_output.before(colon);
	int line_no = get_positive_nr(info_output.after(colon));
	if (line_no >= 0 && !class_name.empty())
	{
	    // Strip JDB 1.2 info like `breakpoint', etc.
	    strip_space(class_name);
	    int last_space = class_name.index(" ", -1);
	    if (last_space > 0)
		class_name = class_name.after(last_space);

	    myfile_name = class_name;
	    myline_nr   = line_no;

	    // Kill this line
	    int beginning_of_line = colon;
	    while (beginning_of_line >= 0 && 
		   info_output[beginning_of_line] != '\n')
		beginning_of_line--;
	    beginning_of_line++;

	    int next_nl = info_output.index('\n', colon);
	    if (next_nl >= 0)
		info_output = info_output.before(beginning_of_line)
		    + info_output.from(next_nl);
	    else
		info_output = info_output.before(beginning_of_line);
	}
    }
}
Example #3
0
// Check whether LINE is a valid PS line.  Exclude occurrences of PS_COMMAND.
static bool valid_ps_line(const string& line, const string& ps_command)
{
    int pid = ps_pid(line);
    if (pid == 0)
	return false;		// No PID

    // You don't want to debug DDD, don't you?
    if (!remote_gdb() && pid == getpid())
	return false;

    // Neither should you debug GDB by itself.
    if (pid == gdb->pid())
	return false;

    // Don't issue lines containing `ps' (or whatever the first word
    // in PS_COMMAND is).
    string ps = ps_command;
    if (ps.contains(' '))
	ps = ps.before(' ');
    ps = basename(ps.chars());
    int index = line.index(ps);
    if (index > 0
	&& (line[index - 1] == '/' || is_separator(line[index - 1]))
	&& (line.length() == index + ps.length()
	    || is_separator(line[index + ps.length()])))
	return false;

    // Okay, just leave it
    return true;
}
Example #4
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 = "";
    }
}
Example #5
0
// Return the Nth component from NAME, or DEFAULT_VALUE if none
static string component(string name, FontComponent n)
{
    // If name does not begin with `-', assume it's a font family
    if (!name.contains('-', 0))
	name.prepend("-*-");

    // Let I point to the Nth occurrence of `-'
    int i = -1;
    while (n >= Foundry && (i = name.index('-', i + 1)) >= 0)
	n--;

    string w;
    if (i >= 0)
    {
	w = name.after(i);
	if (w.contains('-'))
	    w = w.before('-');
    }

    return w;
}
Example #6
0
// Filter all lines from ANSWER beginning with LINE.  This is required
// to suppress the line number output after a `stopping in' message.
void PosBuffer::filter_line(string& answer) const
{
    if (already_read != PosComplete)
	return;

    string line_s = pos_buffer;
    if (line_s.contains(':'))
	line_s = line_s.after(':');
    int line = atoi(line_s.chars());
    if (line <= 0)
	return;

    int pos = 0;
    do {
	if (atoi(answer.chars() + pos) == line)
	{
	    answer = answer.before(pos) + answer.after('\n', pos);
	    break;
	}
	pos = answer.index('\n', pos) + 1;
    } while (pos > 0);
}
Example #7
0
// Fetch current scope from GDB `where' output (a function name).
// This also works for JDB `where' output.
string get_scope(const string& where_output)
{
    // The word before the first parenthesis is the current function.
    int index = where_output.index('(');
    if (index < 0)
	return "";		// no current scope

    do {
	index--;
    } while (index >= 0 && isspace(where_output[index]));

    int end_of_name = index + 1;

    do {
	index--;
    } while (index >= 0 && !isspace(where_output[index]));

    int start_of_name = index + 1;

    return where_output.at(start_of_name, 
			   end_of_name - start_of_name);
}
Example #8
0
// Initialization
void DispValue::init(DispValue *parent, int depth, string& value,
		     DispValueType given_type)
{
#if LOG_CREATE_VALUES
    std::clog << "Building value from " << quote(value) << "\n";
#endif

    // Be sure the value is not changed in memory
    value.consuming(true);

    const char *initial_value = value.chars();

    static const DispValueArray empty(0);
    _children = empty;

    if (background(value.length()))
    {
	clear();

	mytype = Simple;
	_value = "(Aborted)";
	value  = "Aborted\n";
	return;
    }

    mytype = given_type;
    if (mytype == UnknownType && 
	(parent == 0 || parent->type() == List) && print_name.empty())
	mytype = Text;
    if (mytype == UnknownType && parent == 0 && is_user_command(print_name))
	mytype = List;
    if (mytype == UnknownType)
	mytype = determine_type(value);

    bool ignore_repeats = (parent != 0 && parent->type() == Array);

    char perl_type = '\0';

    switch (mytype)
    {

    case Simple:
    {
	_value = read_simple_value(value, depth, ignore_repeats);
#if LOG_CREATE_VALUES
	std::clog << mytype << ": " << quote(_value) << "\n";
#endif
	perl_type = '$';
	break;
    }

    case Text:
    {
	// Read in a line of text
	if (value.contains('\n'))
	    _value = value.through('\n');
	else
	    _value = value;
	value = value.after('\n');
#if LOG_CREATE_VALUES
	std::clog << mytype << ": " << quote(_value) << "\n";
#endif
	perl_type = '$';
	break;
    }

    case Pointer:
    {
	_value = read_pointer_value(value, ignore_repeats);
	_dereferenced = false;

#if LOG_CREATE_VALUES
	std::clog << mytype << ": " << quote(_value) << "\n";
#endif
	// Hide vtable pointers.
	if (_value.contains("virtual table") || _value.contains("vtable"))
	    myexpanded = false;
	perl_type = '$';

	// In Perl, pointers may be followed by indented `pointed to'
	// info.  Skip this.
	if (gdb->type() == PERL)
	{
	    while (value.contains("\n  ", 0))
	    {
		value = value.after("\n  ");
		value = value.from("\n");
	    }
	}		
	break;
    }

    case Array:
    {
	string base = normalize_base(myfull_name);

	_orientation = app_data.array_orientation;

#if LOG_CREATE_VALUES
	std::clog << mytype << ": " << "\n";
#endif

	read_array_begin(value, myaddr);

	// Check for `vtable entries' prefix.
	string vtable_entries = read_vtable_entries(value);
	if (!vtable_entries.empty())
	{
	    _children += parse_child(depth, vtable_entries, myfull_name);
	}

	// Read the array elements.  Assume that the type is the
	// same across all elements.
	DispValueType member_type = UnknownType;
	if (!_have_index_base)
	{
	    _index_base = index_base(base, depth);
	    _have_index_base = true;
	}
	int array_index = _index_base;

	// The array has at least one element.  Otherwise, GDB
	// would treat it as a pointer.
	do {
	    const char *repeated_value = value.chars();
	    string member_name = 
		gdb->index_expr("", itostring(array_index++));
	    DispValue *dv = parse_child(depth, value,
					add_member_name(base, member_name), 
					member_name, member_type);
	    member_type = dv->type();
	    _children += dv;

	    int repeats = read_repeats(value);

	    if (expand_repeated_values)
	    {
		// Create one value per repeat
		while (--repeats > 0)
		{
		    member_name = 
			gdb->index_expr("", itostring(array_index++));
		    string val = repeated_value;
		    DispValue *repeated_dv = 
			parse_child(depth, val, 
				    add_member_name(base, member_name),
				    member_name, member_type);
		    _children += repeated_dv;
		}
	    }
	    else
	    {
		// Show repetition in member
		if (repeats > 1)
		{
		    array_index--;

#if 0
		    // We use the GDB `artificial array' notation here,
		    // since repeat recognition is supported in GDB only.
		    member_name += "@" + itostring(repeats);

		    dv->full_name() = add_member_name(base, member_name);
		    dv->name()      = member_name;
#endif
		    dv->repeats()   = repeats;

		    array_index += repeats;
		}
	    }

	    if (background(value.length()))
	    {
		init(parent, depth, value);
		return;
	    }
	} while (read_array_next(value));
	read_array_end(value);

	// Expand only if at top-level.
	myexpanded = (depth == 0 || nchildren() <= 1);

#if LOG_CREATE_VALUES
	std::clog << mytype << " has " << nchildren() << " members\n";
#endif
	perl_type = '@';
	break;
    }

    case List:
	// Some DBXes issue the local variables via a frame line, just
	// like `set_date(d = 0x10003060, day_of_week = Sat, day = 24,
	// month = 12, year = 1994)'.  Make this more readable.
	munch_dump_line(value);

	// FALL THROUGH
    case Struct:
    {
	_orientation  = app_data.struct_orientation;
	_member_names = app_data.show_member_names;

	bool found_struct_begin   = false;
	bool read_multiple_values = false;
	
#if LOG_CREATE_VALUES
	std::clog << mytype << " " << quote(myfull_name) << "\n";
#endif
	string member_prefix = myfull_name;
	string member_suffix = "";
	if (mytype == List)
	{
	    member_prefix = "";
	    read_multiple_values = true;
	}
	else
	{
	    // In C and Java, `*' binds tighter than `.'
	    if (member_prefix.contains('*', 0))
	    {
		if (gdb->program_language() == LANGUAGE_C)
		{
		    // Use the C `->' operator instead
		    member_prefix.del("*");
		    if (member_prefix.contains('(', 0) &&
			member_prefix.contains(')', -1))
			member_prefix = unquote(member_prefix);

#if RUNTIME_REGEX
		    static regex rxchain("[-a-zA-Z0-9::_>.`]+");
#endif
		    if (member_prefix.matches(rxchain))
		    {
			// Simple chain of identifiers - prepend `->'
			member_prefix += "->";
		    }
		    else
		    {
			member_prefix.prepend("(");
			member_prefix += ")->";
		    }
		}
		else
		{
		    member_prefix.prepend("(");
		    member_prefix += ").";
		}
	    }
	    else if (gdb->program_language() == LANGUAGE_PERL)
	    {
		// In Perl, members of A are accessed as A{'MEMBER_NAME'}
		member_prefix = normalize_base(member_prefix) + "{'";
		member_suffix = "'}";
	    }
	    else if (gdb->program_language() == LANGUAGE_PHP)
	    {
		// In PHP, members of $A are accessed as $A['MEMBER_NAME']
		member_prefix = normalize_base(member_prefix) + "['";
		member_suffix = "']";
	    }
	    else if (gdb->program_language() == LANGUAGE_FORTRAN)
	    {
		// In Fortran, members of A are accessed as A%B
		member_prefix = normalize_base(member_prefix) + "%";
	    }
	    else
	    {
		// In all other languages, members are accessed as A.B
		member_prefix = normalize_base(member_prefix) + ".";
	    }

	    // In case we do not find a struct beginning, read only one value
	    found_struct_begin = read_struct_begin(value, myaddr);
	    read_multiple_values = found_struct_begin;
	}

	// Prepend base class in case of multiple inheritance
	// FIXME: This should be passed as an argument
	static string baseclass_prefix;
	member_prefix += baseclass_prefix;
	int base_classes = 0;

	bool more_values = true;
	while (more_values)
	{
	    // In a List, we may have `member' names like `(a + b)'.
	    // Don't be picky about this.
	    bool picky = (mytype == Struct);
	    string member_name = read_member_name(value, picky);

	    if (member_name.empty())
	    {
		// Some struct stuff that is not a member
		DispValue *dv = parse_child(depth, value, myfull_name, "");

		if (dv->type() == Struct)
		{
		    // What's this - a struct within a struct?  Just
		    // adopt the members.
		    // (This happens when we finally found the struct
		    // after having read all the AIX DBX base classes.)
		    for (int i = 0; i < dv->nchildren(); i++)
		    {
			DispValue *dv2 = dv->child(i)->link();
			_children += dv2;
		    }
		    dv->unlink();
		}
		else
		{
		    _children += dv;
		}

		more_values = read_multiple_values && read_struct_next(value);
	    }
	    else if (is_BaseClass_name(member_name))
	    {
		// Base class member
		string saved_baseclass_prefix = baseclass_prefix;
		base_classes++;

		if (base_classes > 1)
		{
		    // Multiple inheritance.  Be sure to
		    // reference further members unambiguously.
		    //
		    // Note: we don't do that for the first base class,
		    // because this might turn ambiguous again.
		    //
		    // Example:
		    //
		    //    Base
		    //    |   |
		    //    I1 I2
		    //     \ /
		    //      C
		    //
		    // Members of I1::Base are not prefixed, members
		    // of I2::Base get `I2::' as base class prefix.
		    // If we did this already for the first base class,
		    // members of both I1 and I2 would get `Base::' as
		    // base class prefix.

		    switch (gdb->program_language())
		    {
		    case LANGUAGE_C: // C++
			baseclass_prefix = unquote(member_name) + "::";
			break;

		    default:
			// Do nothing (yet)
			break;
		    }
		}

		DispValue *dv = 
		    parse_child(depth, value, myfull_name, member_name);
		_children += dv;

		baseclass_prefix = saved_baseclass_prefix;

		more_values = read_multiple_values && read_struct_next(value);

		// Skip a possible `members of CLASS:' prefix
		read_members_prefix(value);

		// AIX DBX does not place a separator between base
		// classes and the other members, so we always
		// continue reading after having found a base
		// class.  After all, the own class members are
		// still missing.
		if (mytype == Struct && !found_struct_begin)
		    more_values = true;
	    }
	    else
	    {
		// Ordinary member
		string full_name = "";

		if (member_name == " ")
		{
		    // Anonymous union
		    full_name = myfull_name;
		}
		
		if (member_name.contains('.'))
		{
		    if (gdb->has_quotes())
		    {
			// The member name contains `.' => quote it.  This
			// happens with vtable pointers on Linux (`_vptr.').
			full_name = member_prefix + quote(member_name, '\'') + 
			    member_suffix;
		    }
		    else
		    {
			// JDB (and others?) prepend the class name 
			// to inherited members.  Omit this.
			full_name = 
			    member_prefix + member_name.after('.', -1) + 
			    member_suffix;
		    }
		}
		
		if (full_name.empty())
		{
		    // Ordinary member
		    full_name = member_prefix + member_name + member_suffix;
		}

		DispValue *child = 
		    parse_child(depth, value, full_name, member_name);

		if (child->type() == Text)
		{
		    // Found a text as child - child value must be empty
		    string empty = "";
		    _children += 
			parse_child(depth, empty, full_name, member_name);

		    string v = child->value();
		    strip_space(v);
		    if (!v.empty())
			_children += child;
		}
		else
		{
		    _children += child;
		}

		more_values = read_multiple_values && read_struct_next(value);
	    }

	    if (background(value.length()))
	    {
		init(parent, depth, value);
		return;
	    }
	}

	if (mytype == List && !value.empty())
	{
	    // Add remaining value as text
	    _children += parse_child(depth, value, "");
	}

	if (found_struct_begin)
	{
	    // Skip the remainder
	    read_struct_end(value);
	}

	// Expand only if at top-level.
	myexpanded = (depth == 0 || nchildren() <= 1);

#if LOG_CREATE_VALUES
	std::clog << mytype << " "
		  << quote(myfull_name)
		  << " has " << nchildren() << " members\n";
#endif

	perl_type = '%';
	break;
    }

    case Reference:
    {
	myexpanded = true;

	int sep = value.index('@');
	sep = value.index(':', sep);

	string ref = value.before(sep);
	value = value.after(sep);

	string addr = gdb->address_expr(myfull_name);

	_children += parse_child(depth, ref, addr, myfull_name, Pointer);
	_children += parse_child(depth, value, myfull_name);

	if (background(value.length()))
	{
	    init(parent, depth, value);
	    return;
	}

	perl_type = '$';	// No such thing in Perl...
	break;
    }

    case Sequence:
    case UnknownType:
	assert(0);
	abort();
    }

    // Handle trailing stuff (`sequences')
    if (parent == 0 || parent->type() != Sequence)
    {
	bool need_clear = true;
	while (sequence_pending(value, parent))
	{
	    if (need_clear)
	    {
#if LOG_CREATE_VALUES
		std::clog << "Sequence detected at " << quote(value) << "\n";
#endif

		clear();
		value = initial_value;

		mytype = Sequence;

#if LOG_CREATE_VALUES
		std::clog << mytype << " " << quote(myfull_name) << "\n";
#endif

		need_clear = false;
	    }
	    
	    const char *old_value = value.chars();

	    DispValue *dv = parse_child(depth, value, myfull_name);

	    if (value == old_value)
	    {
		// Nothing consumed - stop here
		dv->unlink();
		break;
	    }
	    else if (dv->type() == Simple && dv->value().empty())
	    {
		// Empty value - ignore
		dv->unlink();
	    }
	    else
	    {
		_children += dv;
	    }
	}

#if LOG_CREATE_VALUES
	if (!need_clear)
	{
	    std::clog << mytype << " "
		      << quote(myfull_name)
		      << " has " << nchildren() << " members\n";
	}
#endif
    }

    if (gdb->program_language() == LANGUAGE_PERL && is_perl_prefix(perl_type))
    {
	// Set new type
	if (!myfull_name.empty() && is_perl_prefix(myfull_name[0]))
	    myfull_name[0] = perl_type;
    }

    background(value.length());
    changed = true;
}
Example #9
0
int line_of_listing(string& listing, bool silent)
{
    string message;
    while (!listing.empty()
	   && !listing.contains('>', 0) 
	   && !listing.contains('*', 1) 
	   && atoi(listing.chars()) == 0)
    {
	message += listing.through('\n');
	listing = listing.after('\n');
    }

    if (!silent)
	post_gdb_message(message);

    int idx = -1;

    if (idx < 0 && gdb->type() == JDB)
    {
	// JDB issues `=>' in the listed line
	int idx = listing.index("\t=> \t");
	while (idx > 0 && listing[idx - 1] != '\n')
	    idx--;
    }

    if (idx < 0 && gdb->type() == DBX)
    {
	// SGI DBX issues `*' in column 2 before the `list'ed line.
	// Quite useful.
#if RUNTIME_REGEX
	static regex rxnlstar("\n.[*]");
#endif
	int idx = index(listing, rxnlstar, "\n");
	if (idx < 0 && listing.contains('*', 1))
	    idx = 1;
    }

    if (idx < 0 && gdb->type() == DBX)
    {
	// DEC and SGI DBX issue `>' in column 1 before the current
	// execution line.  Quite useful.
	int idx = listing.index("\n>");
	if (idx < 0 && listing.contains('>', 0))
	    idx = 0;
    }

    // Use the first number found.
    int num_idx = listing.index(rxint, max(idx, 0));
    int line = 0;
    if (num_idx >= 0)
	line = atoi(listing.chars() + num_idx);

    if (line == 0)
    {
	// Weird.  No source?
    }
    else if (idx < 0)
    {
	// No indicator found - 
	// the position we are looking for is in the middle
	line += (listing.freq('\n') + 1) / 2 - 1;
    }

    return line;
}
Example #10
0
void PosBuffer::filter_jdb(string& answer)
{
    if (already_read != PosComplete && !answer.contains('\n'))
    {
	// Position info is incomplete
	answer_buffer = answer;
	answer = "";
	already_read = PosPart;
	return;
    }

    int index = 0;
    while (index >= 0 && !answer.empty())
    {
	string line = answer.from(index);
	if (line.contains('\n'))
	    line = line.before('\n');
	strip_trailing_space(line);

	// Having reached a breakpoint, JDB 1.1 uses a format like
	// `(HelloWorld:3)'.
	// Having loaded a class, JDB uses `class(foo.bar.HelloWorld)'.

	// This may be prefixed by the fully qualified class
	// name (`path'), as in
	// `GlobalView.Map.MapController.createMap (MapController:53)'.
	// In such a case, prefer the fully qualified name.
#if RUNTIME_REGEX
	static regex 
	    rxjdbpos("((class|interface)[(][A-Za-z][A-Za-z0-9.]*[)]|"
		     "[(][A-Za-z][A-Za-z0-9.]*:[1-9][0-9]*[)])");
#endif
	if (gdb->has_debug_command() && line.matches(rxjdbpos))
	{
	    string file = line.after('(');
	    file = file.before(')');
	    string line_no = "0";
	    if (file.contains(':'))
	    {
		line_no = file.after(':');
		file = file.before(':');
	    }
 
	    // Check whether a fully qualified class name is prepended
	    int class_index = line.index('(') - 1;
	    while (class_index >= 0 && line[class_index] == ' ')
		class_index--;
	    while (class_index >= 1 && line[class_index - 1] != ' ')
		class_index--;
	    if (class_index >= 0)
	    {
		string class_name = line.from(class_index);
		class_name = class_name.before('(');
		strip_trailing_space(class_name);
		if (class_name.contains('.') && 
		    class_name.matches(rxchain))
		{
		    // Strip method
		    class_name = class_name.before('.', -1);

		    if (class_name.contains("." + file))
		    {
			// CLASS_NAME is more qualified - use it
			file = class_name;
		    }
		}
	    }

	    pos_buffer	 = file + ":" + line_no;
	    already_read = PosComplete;

#if 0
	    // Delete this line from output
	    int next_index = answer.index('\n', index);
	    if (next_index < 0)
		next_index = answer.length();
	    else
		next_index++;
	    answer.at(index, next_index - index) = "";
#endif
	    break;
	}
	else if (line.contains("line="))
	{
	    // JDB 1.2 output format:
	    // `Step completed: thread="main", jtest.array_test(), 
	    //  line=77, bci=206'

	    string line_no = line.after("line=");
	    line_no = line_no.before(", ");

	    string class_name = line.after(", ");
	    class_name = class_name.before(", ");
	    if (class_name.contains("("))
	    {
		// Within a method
		class_name = class_name.before('(');
		if (class_name.contains("."))
		    class_name = class_name.before('.', -1);
	    }

	    string file = class_name;
	    strip_space(file);

	    pos_buffer	 = file + ":" + line_no;
	    already_read = PosComplete;

	    break;
	}
	else
	{
	    // Look at next line
	    index = answer.index('\n', index);
	    if (index >= 0)
		index++;
	}
    }
}
Example #11
0
// Return true iff ANSWER has a line beginning with PREFIX
static bool has_prefix(const string& answer, const string& prefix)
{
    int index = answer.index(prefix);
    return index == 0 || index > 0 && answer[index - 1] == '\n';
}
Example #12
0
void PosBuffer::filter_dbx(string& answer)
{
    string file;		// File name found
    string line;		// Line number found

    // When reaching a breakpoint, DBX issues the breakpoint
    // number before the status line.  Check for this and
    // initialize defaults from breakpoint position.
    strip_leading_space(answer);
    if (answer.contains('(', 0) || answer.contains('[', 0))
    {
	// Get breakpoint position
	string ans = answer;
	int num = read_positive_nr(ans);
	string pos = source_view->bp_pos(num);
	if (!pos.empty())
	{
	    file = pos.before(':');
	    line = pos.after(':');
	}
    }

    // DEC DBX way issue warnings like
    // `warning: "./cxxtest.C":157 has no code associated with it'
    // right within the position info.

    int start_of_warning = answer.index("\nwarning");
    if (start_of_warning >= 0)
    {
	int open_bracket  = answer.index('[');
	int close_bracket = answer.index(']');
	if (open_bracket >= 0 && open_bracket < start_of_warning &&
	    close_bracket >= 0 && close_bracket > start_of_warning)
	{
	    // Remove warning

	    int end_of_warning = answer.index('\n', start_of_warning + 1);
	    while (end_of_warning < int(answer.length()) && 
		   answer[end_of_warning] == '\n')
		end_of_warning++;

	    while (start_of_warning > 0 && 
		   answer[start_of_warning - 1] == '\n')
		start_of_warning--;

	    int warning_length = end_of_warning - start_of_warning;
	    answer.at(start_of_warning, warning_length) = "";
	}
    }

#if RUNTIME_REGEX
    static regex rxdbxfunc2(
	".*line  *[1-9][0-9]*  *in  *(file  *)?\"[^\"]*\"\n.*");
#endif
    if (already_read != PosComplete && answer.matches(rxdbxfunc2))
    {
	// AIX DBX issues `up', `down' and `func' output
	// in the format `FUNCTION(ARGS), line LINE in "FILE"'.
	// SUN DBX uses `line LINE in file "FILE"' instead.
	// We check for the `line LINE' part.

	line = answer.after(" line ");
	line = line.through(rxint);

	file = answer.after('\"');
	file = file.before('\"');

	if (!line.empty())
	{
	    already_read = PosComplete;
	    // answer = answer.after("\n");
	}
    }

#if RUNTIME_REGEX
    static regex rxdbxpos("[[][^]]*:[1-9][0-9]*[^]]*[]].*");
#endif
    int dbxpos_index = -1;
    if (already_read != PosComplete && 
	(dbxpos_index = index(answer, rxdbxpos, "[")) >= 0)
    {
	// DEC DBX issues breakpoint lines in the format
	// "[new_tree:113 ,0x400858] \ttree->right = NULL;"
		
	line = answer.from(dbxpos_index);
	if (line.contains("[#", 0))
	{
	    // This is a Ladebug breakpoint, no position info.
	}
	else
	{
	    // Note that the function name may contain "::" sequences.
	    while (line.contains("::"))
		line = line.after("::");
	    line = line.after(":");
	    line = line.through(rxint);
	    if (!line.empty())
	    {
		if (answer.index('\n', dbxpos_index) >= 0)
		{
		    already_read = PosComplete;

		    // Strip position info and line
		    strip_leading_space(answer);
		    if (answer.contains('[', 0))
			answer = answer.after("\n");
		}
		else
		{
		    // Wait for `\n' such that we can delete the line
		    answer_buffer = answer;
		    answer = "";
		    already_read = PosPart;
		    return;
		}
	    }
	}
    }

    if (already_read != PosComplete && 
	(answer.contains("stopped in ") || 
	 answer.contains("stopped at ")))
    {
	int stopped_index = answer.index("stopped");
	assert(stopped_index >= 0);

	// Stop reached
	// AIX DBX issues lines like
	// `[4] stopped in unnamed block $b382 at line 4259 in file
	//      "/msdev/sms/ms7/riosqa/src/tffi/fi2tofu.c" ($t1)'
	int in_file_index = answer.index("in file ", stopped_index);
	int bracket_index = answer.index("[", stopped_index);

	if (in_file_index >= 0)
	{
	    // File name given
	    file = answer.from(in_file_index);
	    file = file.after("in file ");
	    if (file.contains('\n'))
		file = file.before('\n');
	    if (file.contains('"', 0))
	    {
		file = file.after('"');
		file = file.before('"');
	    }
	}
	else if (bracket_index >= 0)
	{
	    // DEC DBX and SGI DBX output format:
	    // `[3] Process  1852 (cxxtest) 
	    // stopped at [::main:266 ,0x1000a028]'
	    line = answer.after(bracket_index);
	    func_buffer = line;
	    while (line.contains("::"))
		line = line.after("::");
	    line = line.from(":");
	    func_buffer = func_buffer.before(line);
	    line = line.after(":");
	    line = line.through(rxint);
	    // answer = answer.after("\n");
	}
	else
	{
	    // Function name given
	    string func = answer.after(stopped_index);
	    func = func.after("stopped");
	    if (func.contains(" at "))
		func = func.before(" at ");
	    func_buffer = func;
	}

	if (!func_buffer.empty())
	{
	    // With DEC's `ladebug', the function name is fully qualified,
	    // as in `stopped at [void tree_test(void):277 0x120003f44]'
	    // We use only the base name (`tree_test' in this case).

	    // (We could avoid this if `ladebug' offered a way to look
	    // up fully qualified names.  Does it? - AZ)
	    if (func_buffer.contains('('))
		func_buffer = func_buffer.before('(');
	    while (func_buffer.contains(' '))
		func_buffer = func_buffer.after(' ');
	}

	if (line.empty())
	{
	    line = answer.after("at line ", stopped_index);
	    line = line.through(rxint);
	    if ((!file.empty() || !func_buffer.empty()) &&
		!answer.contains("at line "))
		line = "0";
	}

	if (!line.empty())
	    already_read = PosComplete;
    }

#if RUNTIME_REGEX
    static regex rxdbxfunc("[a-zA-Z_][^[]*: *[1-9][0-9]*  *.*");
#endif
    if (already_read != PosComplete && answer.matches(rxdbxfunc))
    {
	// DEC DBX issues `up', `down' and `func' output
	// in the format `FUNCTION: LINE  TEXT'
		
	// Note that the function name may contain "::" sequences.
	line = answer;
	while (line.contains("::"))
	    line = line.after("::");

	line = line.after(":");
	strip_leading_space(line);
	if (line.contains(rxint, 0))
	{
	    line = line.through(rxint);
	    if (!line.empty())
	    {
		if (answer.contains('\n'))
		{
		    // Got it!
		    already_read = PosComplete;
		    answer = answer.after("\n");
		}
		else
		{
		    // Wait for `\n' such that we can delete the line
		    answer_buffer = answer;
		    answer = "";
		    already_read = PosPart;
		    return;
		}
	    }
	}
    }

    if (already_read != PosComplete && 
	answer.contains("Current function is "))
    {
	// Up/Down command entered
	string nr = answer.after("\n");
	if (!nr.empty())
	{
	    line = itostring(atoi(nr.chars()));
	    already_read = PosComplete;
		    
	    // Show current function only
	    answer = answer.from("Current function is ");
	    answer = answer.through("\n");
	    func_buffer = answer.after("function is ");
	    func_buffer = func_buffer.before("\n");
	}
	else
	{
	    answer_buffer = answer;
	    answer = "";
	    already_read = PosPart;
	    return;
	}
    }

    if (already_read != PosComplete && 
	(!answer.contains('\n') ||
	 (answer.contains('[') && !answer.contains(']'))))
    {
	// Position info is incomplete
	answer_buffer = answer;
	answer = "";
	already_read = PosPart;
	return;
    }

    if (already_read == PosComplete && !line.empty())
    {
	if (!file.empty())
	    pos_buffer = file + ":" + line;
	else
	    pos_buffer = line;
    }

    if (already_read == PosComplete && pos_buffer.empty())
	already_read = Null;
}
Example #13
0
void PosBuffer::filter_dbg(string& answer)
{
    int idx1, idx2;
    
    if (already_read != PosComplete && !answer.contains('\n'))
    {
	// Position info is incomplete
	answer_buffer = answer;
	answer = "";
	already_read = PosPart;
	return;
    }

    idx1 = 0;
    while (idx1 < (int)answer.length())
    {
        idx2 = answer.index('\n', idx1);
	if (idx2 < 0) idx2 = answer.length();	
	string line = answer.at(idx1, idx2 - idx1);
	if (line.contains('\n'))
	    line = line.before('\n');
	strip_trailing_space(line);
		
	// DBG uses a format like `test.php:4 <main>\n echo $a."hello world."'
#if RUNTIME_REGEX
	static regex rxdbgpos("[^ \t]*:[ \t]*[1-9][0-9]*[ \t]*<.*>");
	static regex rxdbgframepos("#[0-9]*[ \t]*<.*>[ \t]*at[ \t]*[^ \t]*:[ \t]*[1-9][0-9]*");
#endif
	if (line.matches(rxdbgpos)) 
	{
	    string file = line.before(':');
	    line = line.after(':');
		    
	    string line_no = line;
	    strip_leading_space(line_no);
	    line_no = line_no.before(' ');
	    
	    line = line.after('<');
	    func_buffer  = line.before('>');
	    strip_leading_space(func_buffer);
		    
	    pos_buffer   = file + ":" + line_no;
	    
	    // Delete this line from output
	    answer.at(idx1, idx2 - idx1 + 1) = "";
	    already_read = PosComplete;
	    break;

	} else if (line.matches(rxdbgframepos)) 
	{
	    string addr = line.before(">");
	    func_buffer = addr.after('<');
	    strip_leading_space(func_buffer);
	    
	    string file = line.after(">");
	    file = file.after("at");
	    strip_leading_space(file);
	    
	    string line_no = file.after(':');
	    strip_leading_space(line_no);
	
	    file = file.before(':');
	    	    
	    pos_buffer   = file + ":" + line_no;
	    
	    // Delete this line from output
	    answer.at(idx1, idx2 - idx1 + 1) = "";
	    already_read = PosComplete;
	    break;
	}
	
	idx1 = idx2+1;
    }
}
Example #14
0
void PosBuffer::filter_gdb(string& answer)
{
    // Try to find out current PC even for non-existent source

    if (check_pc && pc_buffer.empty())
    {
	// `$pc = ADDRESS'
#if RUNTIME_REGEX
	static regex rxpc("\\$pc  *=  *" RXADDRESS);
#endif
	int pc_index = index(answer, rxpc, "$pc ");
	if (pc_index >= 0)
	{
	    int addr_index = answer.index('=');
	    fetch_address(answer, addr_index, pc_buffer);
		    
	    // Strip this line from ANSWER
	    int end_line = answer.index('\n', pc_index);
	    int start_line = pc_index;
	    while (start_line > 0 
		   && answer[start_line - 1] != '\n')
		start_line--;
		    
	    if (end_line < 0)
		answer.from(start_line) = "";
	    else
		answer.at(start_line, end_line - start_line + 1) 
		    = "";
	}
    }
	    
    if (check_pc && pc_buffer.empty() || 
	check_func && func_buffer.empty())
    {
	// `Breakpoint N, ADDRESS in FUNCTION (ARGS...)'
#if RUNTIME_REGEX
	static regex rxstopped_addr("Breakpoint  *[1-9][0-9]*,  *"
				    RXADDRESS);
#endif
	int pc_index = index(answer, rxstopped_addr, "Breakpoint");
	if (pc_index >= 0)
	{
	    annotate("stopped");
	    pc_index = answer.index(',');
	    fetch_address(answer, pc_index, pc_buffer);
	    fetch_in_function(answer, pc_index, func_buffer);
	}
    }
	    
    if (check_pc && pc_buffer.empty() || 
	check_func && func_buffer.empty())
    {
	// `#FRAME ADDRESS in FUNCTION (ARGS...)'
#if RUNTIME_REGEX
	static regex rxframe_addr("#[0-9][0-9]*  *" RXADDRESS);
#endif
		
	int pc_index = index(answer, rxframe_addr, "#");
	if (pc_index == 0
	    || pc_index > 0 && answer[pc_index - 1] == '\n')
	{
	    pc_index = answer.index(' ');
	    fetch_address(answer, pc_index, pc_buffer);
	    fetch_in_function(answer, pc_index, func_buffer);
	}
    }
	    
    if (check_pc && pc_buffer.empty() || 
	check_func && func_buffer.empty())
    {
	// `No line number available for 
	// address ADDRESS <FUNCTION>'
#if RUNTIME_REGEX
	static regex rxaddr("address  *" RXADDRESS);
#endif
		
	int pc_index = index(answer, rxaddr, "address ");
	if (pc_index >= 0)
	{
	    pc_index = answer.index(' ');
	    fetch_address(answer, pc_index, pc_buffer);
	    if (func_buffer.empty())
	    {
		string line = answer.from(pc_index);
		line = line.after('<');
		line = line.before('>');
		if (!line.empty())
		    func_buffer = line;
	    }
	}
    }

    if (check_pc && pc_buffer.empty() && !answer.empty())
    {
	// `ADDRESS in FUNCTION'
#if RUNTIME_REGEX
	static regex rxaddress_in(RXADDRESS " in ");
#endif
	int pc_index = -1;
	if (is_address_start(answer[0]) 
	    && answer.contains(rxaddress_in, 0))
	{
	    pc_index = 0;
	}
	else
	{
#if RUNTIME_REGEX
	    static regex rxnladdress_in("\n" RXADDRESS " in ");
#endif
	    pc_index = index(answer, rxnladdress_in, "\n");
	}
		
	if (pc_index >= 0)
	{
	    fetch_address(answer, pc_index, pc_buffer);
	    fetch_in_function(answer, pc_index, func_buffer);
	}
    }

    // Try to find out current function name, even for
    // non-existing addresses
    if (check_func && func_buffer.empty())
    {
	// `Breakpoint N, FUNCTION (ARGS...)'
	// This regex used for PYDB as well.
#if RUNTIME_REGEX
	static regex rxstopped_func("Breakpoint  *[1-9][0-9]*,  *");
#endif
	int bp_index = index(answer, rxstopped_func, "Breakpoint");
	if (bp_index >= 0)
	    fetch_function(answer, bp_index, func_buffer);
    }

    if (check_func && func_buffer.empty())
    {
	// `#FRAME FUNCTION'
#if RUNTIME_REGEX
	static regex rxframe_func("#[0-9][0-9]*  *[a-zA-Z_].*[(]");
#endif
	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);
	}
    }

    if (check_func && func_buffer.empty())
    {
	// FUNCTION (ARGS...) at FILE:POS
	int at_index = answer.index(" at ");
	if (at_index > 0)
	{
	    int nl_index = 
		answer.index('\n', at_index - answer.length() - 1) + 1;
	    fetch_function(answer, nl_index, func_buffer);

	    // Try to construct position from `at FILE:POS' (vxworks)
	    string file = answer.after(" at ");
	    file = file.before('\n');

	    if (file.contains(rxaddress, 0))
	    {
		// This is `at ADDRESS' (GDB output)
	    }
	    else if (file.contains(":") && !file.contains(": "))
	    {
		pos_buffer = file;
		already_read = PosComplete;
		return;
	    }
		
	}
    }
	    
    // Look for regular source info
    // (GDB's annotations are prefixed with "^Z^Z")
    int index1 = answer.index ("\032\032");
	    
    if (index1 < 0) 
    {
	int index_p = answer.index ("\032");
	if (index_p >= 0 && index_p == int(answer.length()) - 1)
	{
	    // Possible begin of position info at end of ANSWER
	    answer_buffer = "\032";
	    answer = answer.before (index_p);
	    already_read = PosPart;
	    return;
	}
		
	// Handle erroneous `info line' output like
	// `Line number 10 is out of range for "t1.f".'
	// At least get the file name.
#if RUNTIME_REGEX
	static regex rxout_of_range(
	    "Line number [0-9]+ is out of range for ");
#endif
	index_p = index(answer, rxout_of_range, "Line number");
	if (index_p >= 0)
	{
	    string file = answer.after('\"', index_p);
	    file = file.before('\"');
	    pos_buffer = file + ":1";
	    already_read = PosComplete;
	    return;
	}

	// Try to construct position from `Line xxxx of "filename"' (vxworks)
	// which is the output of an 'info line' command
	string line = answer.after("Line ");
	string file = answer.after('\"');
	if (!line.empty() && !file.empty())
	{
	    line = line.before(" of");
	    file = file.before('\"') + ":" + line;
	    if (!line.empty() && !file.empty())
	    {
		pos_buffer = file;
		already_read = PosComplete;
		return;
	    }
	}
	// Try FUNCTION (ARGS...) at FILE:POS
	// here to properly handle up/down commands 
	int at_index = answer.index(" at ");
	int br_index = answer.index("Break");
	if ( (at_index > 0) && (br_index < 0) )
	{
	    int nl_index = 
		answer.index('\n', at_index - answer.length() - 1) + 1;
	    fetch_function(answer, nl_index, func_buffer);

	    // Try to construct position from `at FILE:POS' (vxworks)
	    string file = answer.after(" at ");
	    file = file.before('\n');
	    if (!file.empty())
	    {
		pos_buffer = file;
		already_read = PosComplete;
		return;
	    }
		
	}
	
	// Nothing found
	return;
    }
	    
    // ANSWER contains position info
    int index2 = answer.index ("\n", index1);

    if (index2 == -1)
    {
	// Position info is incomplete
	answer_buffer = answer.from (index1);
	answer = answer.before (index1);
	already_read = PosPart;
	return;
    }

    assert (index1 < index2);

    // Position info is complete
    pos_buffer = answer.at(index1 + 2, index2 - (index1 + 2));

    if (pos_buffer.contains("source ", 0))
    {
	// This happens with GDB in annotation level 2
	pos_buffer = pos_buffer.after("source ");
    }

    int last_colon = pos_buffer.index(':', -1);
    pc_buffer = pos_buffer.after(last_colon);
    if (!pc_buffer.contains(rxaddress_start, 0))
	pc_buffer = "0x" + pc_buffer;
    pc_buffer = pc_buffer.through(rxaddress);

    answer.at(index1, index2 - index1 + 1) = "";
    if (!pos_buffer.empty())
	already_read = PosComplete;
}
Example #15
0
void PosBuffer::filter_bash(string& answer)
{
    // Check for regular source info
    int index1 = answer.index ("\032\032");
	    
    if (index1 < 0) 
    {
	int index_p = answer.index ("\032");
	if (index_p >= 0 && index_p == int(answer.length()) - 1)
	{
	    // Possible begin of position info at end of ANSWER
	    answer_buffer = "\032";
	    answer = answer.before (index_p);
	    already_read = PosPart;
	    return;
	}
    }
    else
    {
	// ANSWER contains position info
	int index2 = answer.index("\n", index1);
	    
	if (index2 == -1)
	{
	    // Position info is incomplete
	    answer_buffer = answer.from (index1);
	    answer = answer.before (index1);
	    already_read = PosPart;
	    return;
	}
	else
	{
	    assert (index1 < index2);
	    
	    // Position info is complete
	    already_read = PosComplete;
	    pos_buffer = answer.at(index1 + 2, index2 - (index1 + 2));
	    answer.at(index1, index2 - index1 + 1) = "";
	}
    }

    if (already_read != PosComplete)
    {
	// Try '(FILE:LINE):\n';

	// INDEX points at the start of a line
	int index = 0;
	while (index >= 0 && !answer.empty())
	{
	    string line = answer.from(index);
	    if (line.contains('\n'))
		line = line.before('\n');
	    strip_trailing_space(line);
		    
#if RUNTIME_REGEX
	    static regex rxbashpos("[(][^:]*:[1-9][0-9]*[)]:");
#endif
	    if (line.matches(rxbashpos))
	    {
		// Fetch position
		pos_buffer = line.after('(');
		pos_buffer = pos_buffer.before(')');
		already_read = PosComplete;

		// Delete this line from output
		int next_index = answer.index('\n', index);
		if (next_index < 0)
		    next_index = answer.length();
		else
		    next_index++;
		answer.at(index, next_index - index) = "";
		break;
	    }
	    else
	    {
		// Look at next line
		index = answer.index('\n', index);
		if (index >= 0)
		    index++;
	    }
	}
    }
}
Example #16
0
void PosBuffer::filter_xdb(string& answer)
{
    if (already_read != PosComplete && !answer.contains('\n'))
    {
	// Position info is incomplete
	answer_buffer = answer;
	answer = "";
	already_read = PosPart;
	return;
    }

    // INDEX points at the start of a line
    int index = 0;
    while (index >= 0 && !answer.empty())
    {
	string line = answer.from(index);
	if (line.contains('\n'))
	    line = line.before('\n');
	strip_trailing_space(line);
		
	// XDB uses a format like `ctest.c: main: 4: int a = 33;'
#if RUNTIME_REGEX
	static regex rxxdbpos("[^ \t]*:.*: [1-9][0-9]*[: ].*");
#endif
	if (line.matches(rxxdbpos))
	{
	    string file = line.before(':');
	    line = line.after(':');
		    
	    // The function name may contain "::"
	    string func = line;
	    while (line.contains("::"))
		line = line.after("::");
	    line = line.from(':');
	    func = func.before(line);
		    
	    line = line.after(':');
	    string line_no = line.before(':');
		    
	    strip_leading_space(func);
	    strip_leading_space(line_no);
	    line_no = line_no.through(rxint);
		    
	    pos_buffer   = file + ":" + line_no;
	    func_buffer  = func;
	    already_read = PosComplete;
		    
	    // Delete this line from output
	    int next_index = answer.index('\n', index);
	    if (next_index < 0)
		next_index = answer.length();
	    else
		next_index++;
	    answer.at(index, next_index - index) = "";
	    break;
	}
	else
	{
	    // Look at next line
	    index = answer.index('\n', index);
	    if (index >= 0)
		index++;
	}
    }
	    
    // Check for trailing `:' in last line
    index = answer.index('\n', -1) + 1;
    if (already_read != PosComplete 
	&& answer.index(':', index) >= 0)
    {
	answer_buffer = answer.from(index);
	answer.from(index) = "";
	already_read = PosPart;
	return;
    }
}
Example #17
0
// Fetch position from GDB output ANSWER.
void PosBuffer::filter (string& answer)
{
    if (answer.length() == 0)
	return;

    // Check program state
    switch (gdb->type())
    {
    case BASH:
    {
 	if (has_prefix(answer, "Reading "))
 	    started = true;
	break;
    }

    case GDB:
    {
	// If GDB prints a "Current function" line, it overrides whatever
	// came before (e.g. "stopped in").
	if (has_prefix(answer, "Current function is "))
	    already_read= Null;

	// Check program state
	if (has_prefix(answer, "Starting program: "))
	    started = true;

	if (has_prefix(answer, "The program no longer exists"))
	    terminated = true;

	if (has_prefix(answer, "Program received signal"))
	    signaled = true;

	if (has_prefix(answer, "Program terminated with signal"))
	    signaled = terminated = true;

	if (answer.contains("has changed; re-reading symbols"))
	    recompiled = true;

	if (has_prefix(answer, "Current language: "))
	    gdb->program_language(answer);

	if (has_prefix(answer, "The current source language is "))
	    gdb->program_language(answer);

	if (terminated)
	    annotate("exited");
	if (signaled)
	    annotate("signalled");
    }
    break;

    case DBG:
    {
 	// Check program state
 	if (has_prefix(answer, "Starting program: "))
 	    started = true;
    }
    break;

    case DBX:
    {
	if (has_prefix(answer, "Running: "))
	    started = true;

	if (answer.contains("has been recompiled"))
	    recompiled = true;

	if (has_prefix(answer, "signal "))
	    signaled = true;
    }
    break;

    case MAKE:
    {
 	if (has_prefix(answer, "Reading makefiles..."))
 	    started = true;
	break;
    }

    case PERL:
    {
	if (has_prefix(answer, "Loading DB routines from perl5db.pl"))
	  recompiled = true;
    }
    break;

    case XDB:
    case JDB:
    case PYDB:
	break;			// Nothing special
    }

    // Check for terminated program
    int i = -1;
    while ((i = answer.index("rogram", i + 1)) > 0)
    {
	int j = i;
	while (j > 0 && answer[j - 1] != '\n')
	    j--;
	
#if RUNTIME_REGEX
	static regex rxterminated("([Tt]he )?[Pp]rogram "
				  "(exited|terminated"
				  "|is not being run|no longer exists).*");
#endif
	if (answer.matches(rxterminated, j))
	    terminated = true;
    }

    if (answer.contains("no active process") 
	|| answer.contains("execution completed")
	|| answer.contains("application exited"))
	terminated = true;

    // Check for auto command
    if (app_data.auto_commands)
    {
	answer.prepend(auto_cmd_part);
	auto_cmd_part = "";

	string pfx = app_data.auto_command_prefix;

	if (!auto_cmd_buffer.empty() && !auto_cmd_buffer.contains('\n', -1))
	{
	    // Complete pending auto command
	    if (answer.contains('\n'))
	    {
		auto_cmd_buffer += answer.through('\n');
		answer = answer.after('\n');
	    }
	    else
	    {
		auto_cmd_buffer += answer;
		answer = "";
	    }
	}

	int index;
	while ((index = answer.index(pfx)) >= 0)
	{
	    string cmd = answer.from(index);
	    if (cmd.contains('\n'))
		cmd = cmd.through('\n');
	    answer = 
		answer.before(index) + answer.from(int(index + cmd.length()));
	    cmd = cmd.after(pfx);
	    auto_cmd_buffer += cmd;
	}

	if (pfx.contains(answer, 0))
	{
	    auto_cmd_part = answer;
	    answer = "";
	}
    }

    // Fetch and store position info, return remainder
    switch (already_read)
    {
    case PosComplete:
	if (gdb->type() == GDB)
	    filter_gdb(answer);		// Slurp in the source annotation
	// Nothing more to filter - skip possible line number info
	filter_line(answer);
	break;

    case PosPart:
	answer.prepend (answer_buffer);
	answer_buffer = "";
	already_read = Null;
	// FALL THROUGH

    case Null:
    {
	// Now go for the actual position.
	switch (gdb->type())
	{
	case BASH:
	    filter_bash(answer);
	    break;
	
	case DBG:
	    filter_dbg(answer);
	    break;

	case DBX:
	    filter_dbx(answer);
	    break;

	case GDB:
	    filter_gdb(answer);
	    break;

	case JDB:
	    filter_jdb(answer);
	    break;

	case MAKE:
	    filter_make(answer);
	    break;

	case PERL:
	    filter_perl(answer);
	    break;

	case PYDB:
	    filter_pydb(answer);
	    break;

	case XDB:
	    filter_xdb(answer);
	    break;
	}

	filter_line(answer);
    }

    break;
    }
}