Go to the first, previous, next, last section, table of contents.


Language Support

¾ð¾î Áö¿ø

GDB's language support is mainly driven by the symbol reader, although it is possible for the user to set the source language manually.

ºñ·Ï »ç¿ëÀÚ°¡ ¼Ò½º ¾ð¾î¸¦ ¼³Á¤Çϴ°ÍÀÌ °¡´ÉÇÏ´Ù ÇÒÁö¶óµµ, GDBÀÇ ¾ð¾î Áö¿øÀº ½Éº¼ ¸®´õ¿¡¼­ ÆÄ»ýµÇ¾ú´Ù.

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.

GDB´Â µð¹ö±ë info¿¡ ±â·ÏµÈ ÆÄÀÏÀÇ È®ÀåÀÚ¸¦ ã¾Æ ¼Ò½º ¾ð¾î¸¦ ¼±ÅÃÇÑ´Ù.; `.c'´Â C¸¦ ÀǹÌÇϸç, `.f'´Â FortranÀ» ÀǹÌÇÑ´Ù. ¸¸ÀÏ µð¹ö±ë Çü½ÄÀÌ DWARF °°Àº °ÍÀ» Áö¿ø ÇÑ´Ù¸é, Ưº°ÇÑ ¸ñÀûÀÇ ¾ð¾î ½Äº°ÀÚ¸¦ »ç¿ëÇÒ¼ö ÀÖ´Ù.

Adding a Source Language to GDB

¼Ò½º ¾ð¾î¸¦ GDB¿¡ Ãß°¡½ÃÅ°±â

To add other languages to GDB's expression parser, follow the following steps:

´Ù¸¥ ¾ð¾î¸¦ GDB Ç¥Çö½Ä Æļ­(expression parser)¿¡ Ãß°¡½ÃÅ°±â À§ÇØ, ´ÙÀ½ ´Ü°è¸¦ µû¶óÇضó:

Create the expression parser.
expression parser »ý¼ºÇϱâ.
This should reside in a file `lang-exp.y'. Routines for building parsed expressions into a union exp_element list 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:

¿ì¸®´Â BisonÀÌ °¡Áö°í ÀÖ´Â ¸ðµç°ÍÀ» »ç¿ëÇÏÁö ¾ÊÀ¸¸ç, YACCÀº Àü¿ª À̸§(global name)À» Á¤ÀÇÇÑ Æļ­¸¦ ¸¸µé±â ¶§¹®¿¡, ´ÙÀ½ ¶óÀεéÀº ´Ù¾çÇÑ parser°¡ °°Àº Àü¿ª À̸§À» Á¤ÀÇÇÏÁö ¸øÇϵµ·Ï Çϱâ À§ÇØ YACC parserÀÇ ¸ÇÀ§¿¡ Æ÷ÇÔÇØ¾ß ÇÑ´Ù.

#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_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.

Æļ­ÀÇ ¹Ø¿¡, struct language_defn¸¦ Á¤ÀÇÇÏ°í ¾ð¾îÀÇ Àû´çÇÑ °ªÀ¸·Î ÃʱâÈ­ Çضó. initialize_lang ·çƾÀ» Á¤ÀÇÇÏ°í ¾ð¾î°¡ Á¸ÀçÇѴٴ°ÍÀ» GDB¿¡°Ô ¾Ë¸®±â À§ÇØ `add_language(lang_language_defn)'À» È£Ãâ ÇÑ´Ù. ¿©·¯ºÐÀº ´Ù¸¥ Áö¿ø º¯¼ö¿Í ÇÔ¼ö°¡ ÇÊ¿äÇϸç ÀÌ°ÍÀº lang_language_defn ¿¡¼­ Æ÷ÀÎÅ͸¦ ÅëÇØ »ç¿ëµÈ´Ù. `language.h'¿¡ Á¤ÀÇµÈ struct language_defn ¼±¾ðÀ» º¸°í, ´õ ¸¹Àº Á¤º¸¸¦ À§ÇØ ´Ù¸¥ `*-exp.y' ÆÄÀϵ鵵 ÂüÁ¶Çضó.

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_subexp function defined in the file `eval.c'. Add cases for new opcodes in two functions from `parse.c': prefixify_subexp and length_of_subexp. These compute the number of exp_elements that a given operation takes up.

¸¸ÀÏ »õ·Î¿î opcode(¾ð¾îÀÇ ÀÛµ¿À» ³ªÅ¸³»´Â)°¡ ÇÊ¿äÇÏ´Ù¸é, À̰͵éÀ» `expression.h' ¿¡ ³ª¿­µÇ¾î Àִ ŸÀÔ¿¡ Ãß°¡Çضó. `eval.c' ÆÄÀÏ¿¡ Á¤ÀÇµÈ evaluate_subexp ÇÔ¼ö¿¡ ÀÌ ÀÛµ¿µéÀ» À§ÇÑ Áö¿ø Äڵ带 Ãß°¡Çضó. »õ opcode¸¦ À§ÇÑ °æ¿ìµéÀ» `parse.c' ÀÇ µÎ ÇÔ¼ö¿¡ Ãß°¡Çضó:prefixify_subexp ¿Í length_of_subexp. À̰͵éÀº ÁÖ¾îÁø ÀÛµ¿ÀÌ ÀϾ´Â exp_elementÀÇ ¼ö¸¦ °è»êÇÑ´Ù.

Update some existing code
Á¸ÀçÇÏ´Â ÄÚµå °»½Å
Add an enumerated identifier for your language to the enumerated type 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 print_subexp (in `expprint.c') to handle any new expression opcodes you have added to `expression.h'. Also, add the printed representations of your operators to op_print_tab.

¾ð¾î¸¦ À§ÇØ ³ª¿­µÈ ½Äº°ÀÚ¸¦ `defs.h'¿¡ ³ª¿­µÈ ŸÀÔ enum language ¿¡ Ãß°¡Çضó. ¿©·¯ºÐÀÇ ¾ð¾î°¡ Æ÷ÇÔµÈ `language.c'³» ·çƾÀ» °»½ÅÇÑ´Ù. ÀÌµé ·çƾÀ» ŸÀÔ ¼ú¾î¸¦ Æ÷ÇÔÇϸç ÀÌ°ÍÀº(¸î¸î °æ¿ì¿¡) ¾ð¾î ÀÇÁ¸ÀûÀÌ´Ù. ¸¸ÀÏ ¾ð¾î°¡ switch ¹®ÀÚ¿¡ ³ªÅ¸³ªÁö ¾Ê´Â´Ù¸é, ¿¡·¯°¡ º¸°íµÈ´Ù. `language.c'¿¡ Æ÷ÇÔµÈ °ÍÀº º¯¼ö current_language¸¦ °»½ÅÇϱâ À§ÇÑ ÄÚµå¿Í language_lang ³ª¿­µÈ ½Äº°ÀÚ¸¦ Ãâ·Â °¡´ÉÇÑ ¹®ÀÚ¿­·Î ¹ø¿ªÇÏ´Â ·çƾÀÌ´Ù. ¾ð¾î¸¦ Æ÷ÇÔÇϱâ À§ÇØ ÇÔ¼ö _initialize_language¸¦ °»½ÅÇÑ´Ù. ÀÌ ÇÔ¼ö´Â ½ÃÀ۽à ±âº» ¾ð¾î¸¦ ¼±ÅÃÇϸç, ±×·¡¼­ GDB°¡ ¾î¶² ¾ð¾î·Î Á¦À۵Ǿú´À³Ä¿¡ ÀÇÁ¸ÇÑ´Ù. °¢ symtab(source file) ¾ð¾î¸¦ Àû´çÈ÷ ¼³Á¤Çϱâ À§Çؼ­ `symfile.c'³» allocate_symtab¿Í ½Éº¼-ÀÐÀº Äڵ带 °»½ÅÇضó. ÀÌ°ÍÀº °¢ ½ºÅà ÇÁ·¹ÀÓ ·¹º§¿¡¼­ »ç¿ëÇϱâ À§ÇÑ ¾ð¾î¸¦ ¼±ÅÃÇϱâ À§ÇØ »ç¿ëµÈ´Ù. ÇöÀç, ¾ð¾î´Â ¼Ò½º ÆÄÀÏÀÇ È®Àå¿¡ ±â¹ÝÇÑ´Ù. ¸¸ÀÏ ¾ð¾î°¡ ½Éº¼ Á¤º¸¿¡¼­ Ãß·ÐÇϱ⠴õ ÁÁÀ»¼ö ÀÖ´Ù¸é, ½Éº¼-ÀÐÀº Äڵ峻 symtabÀÇ ¾ð¾î¸¦ ¼³Á¤Çضó.

Add a place of call
Add a call to lang_parse() and lang_error in parse_exp_1 (defined in `parse.c').

parse_exp_1(`parse.c'¿¡ Á¤ÀǵÈ)¿¡ lang_parse()¿Í lang_error¸¦ Ãß°¡Çضó.

Use macros to trim code
The user has the option of building GDB for some or all of the languages. If the user decides to build GDB for the language lang, then every file dependent on `language.h' will have the macro _LANG_lang defined in it. Use #ifdefs 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.

»ç¿ëÀÚ´Â ÀϺγª ¸ðµç ¾ð¾î¸¦ À§ÇØ GDB ºôµå½Ã ¿É¼ÇÀ» °¡Áø´Ù. ¸¸ÀÏ »ç¿ëÀÚ°¡ ¾ð¾î lang¸¦ À§Çϵµ·Ï GDB¸¦ ºôµåÇϱâ·Î °áÁ¤ÇÑ´Ù¸é, `language.h'¿¡ ÀÇÁ¸ÇÏ´Â ¸ðµç ÆÄÀÏÀº ¿©±â¿¡ Á¤ÀÇµÈ ¸ÅÅ©·Î _LANG_lang¸¦ °¡Áú °ÍÀÌ´Ù. ¸¸ÀÏ ¿©·¯ºÐÀÇ ¾ð¾î¸¦ »ç¿ëÇÏÁö ¾Ê´Â´Ù¸é »ç¿ëÀÚ´Â ÇÊ¿ä ¾ø´Â Ä¿´Ù¶õ ·çƾÀ» ºüÁ® ³ª°¡±â À§ÇØ #ifdef¸¦ »ç¿ëÇضó. YACC Æļ­¿¡¼­ ÀÌ°ÍÀ» ÇÒ ÇÊ¿ä°¡ ¾ø´Ù´ÂÁ¡¿¡ ÁÖÀÇÇضó. ¿Ö³ÄÇÏ¸é ¸¸ÀÏ GDB°¡ lang¸¦ ºôµåÇÏÁö ¾Ê¾Ò´Ù¸é, `lang-exp.tab.o'(Æļ­ÀÇ ÄÄÆÄÀÏµÈ ÇüÅÂ)´Â GDB¿Í ¸µÅ©µÇÁö ¾Ê´Â´Ù.

Edit `Makefile.in'
Add dependencies in `Makefile.in'. Make sure you update the macro variables such as HFILES and OBJS, otherwise your code may not get linked in, or, worse yet, it may not get tarred into the distribution!

kefile.in'³» ÀÇÁ¸¼ºÀ» Ãß°¡ÇÑ´Ù. HFILES¿Í OBJS °°Àº ¸ÅÅ©·Î º¯¼ö¸¦ È®½ÇÈ÷ °»½ÅÇϵµ·Ï Çضó. ±×·¸Áö ¾ÊÀ¸¸é ÄÚµå´Â ¸µÅ©µÇÁö ¾Ê°Å³ª À߸ø µÇ¾î ¹èÆ÷½Ã tar¸¦ °¡Áú¼ö ¾øÀ»Áö ¸ð¸¥´Ù.


Go to the first, previous, next, last section, table of contents.