This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] Enhance completer for fields of structures.



   I send here a rather big patch in only one part, because
its not a Request for Approval, but really a 
Request for Comments and Suggestions.

   The first part of my patch had a completely different purpose:
I worked on the pascal parser (p-exp.y) to add some
better pascal string support.
I wanted in particular to get a correct output for
(gdb) print St[4]
if St is a pascal string.
But as both Free Pascal Compiler (FPC) and GNU Pascal Compiler (GPC)
generate debug info that handle pascal strings as records,
I had to add a way to know the current type of a part of a expression 
while it is being parsed.

  This is done by setting the current_type (a struct type *)
inside p-exp.y. Then using is_pascal_string_type function
I can handle the array index and correctly display the char.

But then I realized that this current_type pointer could be used 
in the completer functions, because if we know the current type in the middle
of an expression, then we should be able to correctly search for fields
of the current structured type (and in nothing else).

   The patch attached below does allow me to get a 
correct completion of expressions like
if X is a variable of type
PRECORD, PRECORD being a pointer to type 
TRECORD = record
    x,y : longint;
    next : precord;
end;

(gdb) print X^.N
if I press tab, I get  X^.NEXT
even if there are several global variables starting with letter N.

ChangeLog entry:
(Not for real commit, but just to explain the patch a little more in details).

	* completer.c (location_completer): call make_symbol_completion_list
	with orig_text first to try to find out if a structured type is the current valid type
	and if the completion list should be included from that field list.

   	* p-exp.y: set current_type to the current valid type to be able to
	display pascal string elements correctly and to enhance the completer.
Remarks: there are problably lots of places where the current_type should be reset to
NULL but is not done in that code.
	(push_type, pop_type): New functions to handle current_type for complex expressions.

	* p-lang.h: New prototype for is_pascal_string_type function.

	* p-lang.c (is_pascal_string_type): New argument getting the name of the field 
	containing the char array. Return type changed to return the index of the char array +1
	or zero if not a pascal string type.

	* p-valprint.c (pascal_val_print): Adapt to newprototype of is_pascal_string_type function.

	* parse.c (parse_for_type): New function allowing to return the type at the end of
	an incomplete expression (to be used for completer function).
	(current_parser_expression_type): New variable used in the parse_for_type function.
	(in_parse_for_type): New variable used to suppress error output if parsers if called from within
	parse_for_type, where errors are expected as the expression is incomplete.

	* parser-defs.h (parse_for_type): Declaration of new function implemented in parse.c.
	(current_parser_expression_type): New variable.
	(in_parse_for_type): New variable.
Remark: that variable could probably remain static in parse.c 

	* symtab.c (make_symbol_completion_list): return directly after having filled up
	the list array with matching field elements if a structured type was found with parse_for_type function.

This are the main lines of my patch.

   As said earlier, I mostly want to have opinions about the outlines of this change.



Attachment: all.diffs
Description: Text document



Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07  Fax : (33)-3-88-41-40-99

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]