To add other languages to GDB's expression parser, follow the following steps:
#define yyparse lang_parse #define yylex lang_lex #define yyerror lang_error #define yylval lang_lval #define yychar lang_char #define yydebug lang_debug #define yypact lang_pact #define yyr1 lang_r1 #define yyr2 lang_r2 #define yydef lang_def #define yychk lang_chk #define yypgo lang_pgo #define yyact lang_act #define yyexca lang_exca #define yyerrflag lang_errflag #define yynerrs lang_nerrsAt the bottom of your parser, define a
struct language_defn
and
initialize it with the right values for your language. Define an
initialize_lang
routine and have it call
`add_language(lang_language_defn)' to tell the rest of GDB
that your language exists. You'll need some other supporting variables
and functions, which will be used via pointers from your
lang_language_defn
. See the declaration of struct
language_defn
in `language.h', and the other `*-exp.y' files,
for more information.
eval.c:evaluate_subexp()
. Add cases
for new opcodes in two functions from `parse.c':
prefixify_subexp()
and length_of_subexp()
. These compute
the number of exp_element
s that a given operation takes up.
enum language
in `defs.h'.
Update the routines in `language.c' so your language is included. These
routines include type predicates and such, which (in some cases) are
language dependent. If your language does not appear in the switch
statement, an error is reported.
Also included in `language.c' is the code that updates the variable
current_language
, and the routines that translate the
language_lang
enumerated identifier into a printable
string.
Update the function _initialize_language
to include your language. This
function picks the default language upon startup, so is dependent upon
which languages that GDB is built for.
Update allocate_symtab
in `symfile.c' and/or symbol-reading
code so that the language of each symtab (source file) is set properly.
This is used to determine the language to use at each stack frame level.
Currently, the language is set based upon the extension of the source
file. If the language can be better inferred from the symbol
information, please set the language of the symtab in the symbol-reading
code.
Add helper code to expprint.c:print_subexp()
to handle any new
expression opcodes you have added to `expression.h'. Also, add the
printed representations of your operators to op_print_tab
.
lang_parse()
and lang_error
in
parse.c:parse_exp_1()
.
_LANG_lang
defined in it. Use #ifdef
s to
leave out large routines that the user won't need if he or she is not
using your language.
Note that you do not need to do this in your YACC parser, since if GDB
is not build for lang, then `lang-exp.tab.o' (the
compiled form of your parser) is not linked into GDB at all.
See the file `configure.in' for how GDB is configured for different
languages.
HFILES
and OBJS
, otherwise your code may
not get linked in, or, worse yet, it may not get tar
red into the
distribution!