9 Language Support
gdb chooses the source language by looking at the extension of the file recorded in the debug info; .c means C, .f means Fortran, etc. It may also use a special-purpose language identifier if the debug format supports it, like with DWARF.
9.1 Adding a Source Language to gdb
- Create the expression parser.
This should reside in a file lang-exp.y. Routines for
building parsed expressions into a
union exp_elementlist are in parse.c.
Since we can't depend upon everyone having Bison, and YACC produces parsers that define a bunch of global names, the following lines must be included at the top of the YACC parser, to prevent the various parsers from defining the same global names:
#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_nerrs
At the bottom of your parser, define a
struct language_defnand 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_defnin language.h, and the other *-exp.y files, for more information.
- Add any evaluation routines, if necessary
If you need new opcodes (that represent the operations of the language),
add them to the enumerated type in expression.h. Add support
code for these operations in the
evaluate_subexpfunction defined in the file eval.c. Add cases for new opcodes in two functions from parse.c:
length_of_subexp. These compute the number of
exp_elements that a given operation takes up.
- Update some existing code
Add an enumerated identifier for your language to the enumerated type
enum languagein 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.
allocate_symtabin 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 a place of call
Add a call to lang
parse_exp_1(defined in parse.c).
- Edit Makefile.in
Add dependencies in Makefile.in. Make sure you update the macro
variables such as
OBJS, otherwise your code may not get linked in, or, worse yet, it may not get
tarred into the distribution!