add directory study
This commit is contained in:
259
study/Ref-docs/manual gdb/gdbint/gdbint_7.html
Normal file
259
study/Ref-docs/manual gdb/gdbint/gdbint_7.html
Normal file
@@ -0,0 +1,259 @@
|
||||
<HTML>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<!-- Created on October, 18 2002 by texi2html 1.64 -->
|
||||
<!--
|
||||
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
|
||||
Karl Berry <karl@freefriends.org>
|
||||
Olaf Bachmann <obachman@mathematik.uni-kl.de>
|
||||
and many others.
|
||||
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
|
||||
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
|
||||
|
||||
-->
|
||||
<HEAD>
|
||||
<TITLE>GDB Internals: Language Support</TITLE>
|
||||
|
||||
<META NAME="description" CONTENT="GDB Internals: Language Support">
|
||||
<META NAME="keywords" CONTENT="GDB Internals: Language Support">
|
||||
<META NAME="resource-type" CONTENT="document">
|
||||
<META NAME="distribution" CONTENT="global">
|
||||
<META NAME="Generator" CONTENT="texi2html 1.64">
|
||||
|
||||
</HEAD>
|
||||
|
||||
<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
|
||||
|
||||
<A NAME="SEC61"></A>
|
||||
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
||||
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_6.html#SEC60"> < </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_7.html#SEC62"> > </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_8.html#SEC63"> << </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint.html#SEC_Top"> Up </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_8.html#SEC63"> >> </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint.html#SEC_Top">Top</A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_toc.html#SEC_Contents">Contents</A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_19.html#SEC186">Index</A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_abt.html#SEC_About"> ? </A>]</TD>
|
||||
</TR></TABLE>
|
||||
<H1> 7. Language Support </H1>
|
||||
<!--docid::SEC61::-->
|
||||
<P>
|
||||
|
||||
<A NAME="IDX127"></A>
|
||||
GDB's language support is mainly driven by the symbol reader,
|
||||
although it is possible for the user to set the source language
|
||||
manually.
|
||||
</P><P>
|
||||
|
||||
GDB chooses the source language by looking at the extension
|
||||
of the file recorded in the debug info; <TT>`.c'</TT> means C, <TT>`.f'</TT>
|
||||
means Fortran, etc. It may also use a special-purpose language
|
||||
identifier if the debug format supports it, like with DWARF.
|
||||
</P><P>
|
||||
|
||||
<HR SIZE="6">
|
||||
<A NAME="SEC62"></A>
|
||||
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
||||
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_7.html#SEC61"> < </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_8.html#SEC63"> > </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_7.html#SEC61"> << </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_7.html#SEC61"> Up </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_8.html#SEC63"> >> </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint.html#SEC_Top">Top</A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_toc.html#SEC_Contents">Contents</A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_19.html#SEC186">Index</A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_abt.html#SEC_About"> ? </A>]</TD>
|
||||
</TR></TABLE>
|
||||
<H2> 7.1 Adding a Source Language to GDB </H2>
|
||||
<!--docid::SEC62::-->
|
||||
<P>
|
||||
|
||||
<A NAME="IDX128"></A>
|
||||
To add other languages to GDB's expression parser, follow the
|
||||
following steps:
|
||||
</P><P>
|
||||
|
||||
<DL COMPACT>
|
||||
<DT><EM>Create the expression parser.</EM>
|
||||
<DD><P>
|
||||
|
||||
<A NAME="IDX129"></A>
|
||||
This should reside in a file <TT>`<VAR>lang</VAR>-exp.y'</TT>. Routines for
|
||||
building parsed expressions into a <CODE>union exp_element</CODE> list are in
|
||||
<TT>`parse.c'</TT>.
|
||||
</P><P>
|
||||
|
||||
<A NAME="IDX130"></A>
|
||||
Since we can't depend upon everyone having Bison, and YACC produces
|
||||
parsers that define a bunch of global names, the following lines
|
||||
<STRONG>must</STRONG> be included at the top of the YACC parser, to prevent the
|
||||
various parsers from defining the same global names:
|
||||
</P><P>
|
||||
|
||||
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>#define yyparse <VAR>lang</VAR>_parse
|
||||
#define yylex <VAR>lang</VAR>_lex
|
||||
#define yyerror <VAR>lang</VAR>_error
|
||||
#define yylval <VAR>lang</VAR>_lval
|
||||
#define yychar <VAR>lang</VAR>_char
|
||||
#define yydebug <VAR>lang</VAR>_debug
|
||||
#define yypact <VAR>lang</VAR>_pact
|
||||
#define yyr1 <VAR>lang</VAR>_r1
|
||||
#define yyr2 <VAR>lang</VAR>_r2
|
||||
#define yydef <VAR>lang</VAR>_def
|
||||
#define yychk <VAR>lang</VAR>_chk
|
||||
#define yypgo <VAR>lang</VAR>_pgo
|
||||
#define yyact <VAR>lang</VAR>_act
|
||||
#define yyexca <VAR>lang</VAR>_exca
|
||||
#define yyerrflag <VAR>lang</VAR>_errflag
|
||||
#define yynerrs <VAR>lang</VAR>_nerrs
|
||||
</FONT></pre></td></tr></table></P><P>
|
||||
|
||||
At the bottom of your parser, define a <CODE>struct language_defn</CODE> and
|
||||
initialize it with the right values for your language. Define an
|
||||
<CODE>initialize_<VAR>lang</VAR></CODE> routine and have it call
|
||||
<SAMP>`add_language(<VAR>lang</VAR>_language_defn)'</SAMP> 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
|
||||
<CODE><VAR>lang</VAR>_language_defn</CODE>. See the declaration of <CODE>struct
|
||||
language_defn</CODE> in <TT>`language.h'</TT>, and the other <TT>`*-exp.y'</TT> files,
|
||||
for more information.
|
||||
</P><P>
|
||||
|
||||
<DT><EM>Add any evaluation routines, if necessary</EM>
|
||||
<DD><P>
|
||||
|
||||
<A NAME="IDX131"></A>
|
||||
<A NAME="IDX132"></A>
|
||||
<A NAME="IDX133"></A>
|
||||
<A NAME="IDX134"></A>
|
||||
If you need new opcodes (that represent the operations of the language),
|
||||
add them to the enumerated type in <TT>`expression.h'</TT>. Add support
|
||||
code for these operations in the <CODE>evaluate_subexp</CODE> function
|
||||
defined in the file <TT>`eval.c'</TT>. Add cases
|
||||
for new opcodes in two functions from <TT>`parse.c'</TT>:
|
||||
<CODE>prefixify_subexp</CODE> and <CODE>length_of_subexp</CODE>. These compute
|
||||
the number of <CODE>exp_element</CODE>s that a given operation takes up.
|
||||
</P><P>
|
||||
|
||||
<DT><EM>Update some existing code</EM>
|
||||
<DD><P>
|
||||
|
||||
Add an enumerated identifier for your language to the enumerated type
|
||||
<CODE>enum language</CODE> in <TT>`defs.h'</TT>.
|
||||
</P><P>
|
||||
|
||||
Update the routines in <TT>`language.c'</TT> 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.
|
||||
</P><P>
|
||||
|
||||
<A NAME="IDX135"></A>
|
||||
Also included in <TT>`language.c'</TT> is the code that updates the variable
|
||||
<CODE>current_language</CODE>, and the routines that translate the
|
||||
<CODE>language_<VAR>lang</VAR></CODE> enumerated identifier into a printable
|
||||
string.
|
||||
</P><P>
|
||||
|
||||
<A NAME="IDX136"></A>
|
||||
Update the function <CODE>_initialize_language</CODE> to include your
|
||||
language. This function picks the default language upon startup, so is
|
||||
dependent upon which languages that GDB is built for.
|
||||
</P><P>
|
||||
|
||||
<A NAME="IDX137"></A>
|
||||
Update <CODE>allocate_symtab</CODE> in <TT>`symfile.c'</TT> 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.
|
||||
</P><P>
|
||||
|
||||
<A NAME="IDX138"></A>
|
||||
<A NAME="IDX139"></A>
|
||||
Add helper code to <CODE>print_subexp</CODE> (in <TT>`expprint.c'</TT>) to handle any new
|
||||
expression opcodes you have added to <TT>`expression.h'</TT>. Also, add the
|
||||
printed representations of your operators to <CODE>op_print_tab</CODE>.
|
||||
</P><P>
|
||||
|
||||
<DT><EM>Add a place of call</EM>
|
||||
<DD><P>
|
||||
|
||||
<A NAME="IDX140"></A>
|
||||
Add a call to <CODE><VAR>lang</VAR>_parse()</CODE> and <CODE><VAR>lang</VAR>_error</CODE> in
|
||||
<CODE>parse_exp_1</CODE> (defined in <TT>`parse.c'</TT>).
|
||||
</P><P>
|
||||
|
||||
<DT><EM>Use macros to trim code</EM>
|
||||
<DD><P>
|
||||
|
||||
<A NAME="IDX141"></A>
|
||||
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
|
||||
<VAR>lang</VAR>, then every file dependent on <TT>`language.h'</TT> will have the
|
||||
macro <CODE>_LANG_<VAR>lang</VAR></CODE> defined in it. Use <CODE>#ifdef</CODE>s to
|
||||
leave out large routines that the user won't need if he or she is not
|
||||
using your language.
|
||||
</P><P>
|
||||
|
||||
Note that you do not need to do this in your YACC parser, since if GDB
|
||||
is not build for <VAR>lang</VAR>, then <TT>`<VAR>lang</VAR>-exp.tab.o'</TT> (the
|
||||
compiled form of your parser) is not linked into GDB at all.
|
||||
</P><P>
|
||||
|
||||
See the file <TT>`configure.in'</TT> for how GDB is configured
|
||||
for different languages.
|
||||
</P><P>
|
||||
|
||||
<DT><EM>Edit <TT>`Makefile.in'</TT></EM>
|
||||
<DD><P>
|
||||
|
||||
Add dependencies in <TT>`Makefile.in'</TT>. Make sure you update the macro
|
||||
variables such as <CODE>HFILES</CODE> and <CODE>OBJS</CODE>, otherwise your code may
|
||||
not get linked in, or, worse yet, it may not get <CODE>tar</CODE>red into the
|
||||
distribution!
|
||||
</DL>
|
||||
<P>
|
||||
|
||||
<A NAME="Host Definition"></A>
|
||||
</P><P>
|
||||
|
||||
<HR SIZE="6">
|
||||
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
||||
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_7.html#SEC61"> << </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_8.html#SEC63"> >> </A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint.html#SEC_Top">Top</A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_toc.html#SEC_Contents">Contents</A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_19.html#SEC186">Index</A>]</TD>
|
||||
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdbint_abt.html#SEC_About"> ? </A>]</TD>
|
||||
</TR></TABLE>
|
||||
<BR>
|
||||
<FONT SIZE="-1">
|
||||
|
||||
<address>
|
||||
|
||||
<p>Please send FSF & GNU inquiries & questions to <a
|
||||
href="mailto:gnu@gnu.org">gnu@gnu.org</a>. There are also <a
|
||||
href="http://www.gnu.org/home.html#ContactInfo">other ways to
|
||||
contact</a> the FSF.</p>
|
||||
|
||||
<p>These pages are maintained by <a
|
||||
href="http://www.gnu.org/software/gdb/">the GDB developers</a>.</p>
|
||||
|
||||
<p>Copyright Free Software Foundation, Inc., 59 Temple Place - Suite
|
||||
330, Boston, MA 02111, USA.</p>
|
||||
|
||||
<p>Verbatim copying and distribution of this entire article is
|
||||
permitted in any medium, provided this notice is preserved.</p>
|
||||
|
||||
</address>
|
||||
|
||||
This document was generated
|
||||
by <I>GDB Administrator</I> on <I>October, 18 2002</I>
|
||||
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
|
||||
"><I>texi2html</I></A>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
Reference in New Issue
Block a user