3eadfce9d6252cc9a72fb45f1ef01e0f4651fa08
[deliverable/binutils-gdb.git] / gdb / doc / gdbint.texinfo
1 \input texinfo
2 @setfilename gdbint.info
3 @c $Id$
4 @ifinfo
5 This file documents the internals of the GNU debugger GDB.
6
7 Copyright (C) 1990, 1991 Free Software Foundation, Inc.
8 Contributed by Cygnus Support. Written by John Gilmore.
9
10 Permission is granted to make and distribute verbatim copies of
11 this manual provided the copyright notice and this permission notice
12 are preserved on all copies.
13
14 @ignore
15 Permission is granted to process this file through Tex and print the
16 results, provided the printed document carries copying permission
17 notice identical to this one except for the removal of this paragraph
18 (this paragraph not being relevant to the printed manual).
19
20 @end ignore
21 Permission is granted to copy or distribute modified versions of this
22 manual under the terms of the GPL (for which purpose this text may be
23 regarded as a program in the language TeX).
24 @end ifinfo
25
26 @setchapternewpage off
27 @settitle GDB Internals
28 @titlepage
29 @title{Working in GDB}
30 @subtitle{A guide to the internals of the GNU debugger}
31 @author John Gilmore
32 @author Cygnus Support
33 @page
34 @tex
35 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
36 \xdef\manvers{\$Revision$} % For use in headers, footers too
37 {\parskip=0pt
38 \hfill Cygnus Support\par
39 \hfill \manvers\par
40 \hfill \TeX{}info \texinfoversion\par
41 }
42 @end tex
43
44 @vskip 0pt plus 1filll
45 Copyright @copyright{} 1990, 1991 Free Software Foundation, Inc.
46
47 Permission is granted to make and distribute verbatim copies of
48 this manual provided the copyright notice and this permission notice
49 are preserved on all copies.
50
51 @end titlepage
52
53 @node Top, Cleanups, (dir), (dir)
54
55 @menu
56 * Cleanups:: Cleanups
57 * Wrapping:: Wrapping output lines
58 * Releases:: Configuring GDB for release
59 * README:: The README file
60 * New Architectures:: Defining a new host or target architecture
61 * Host:: Adding a New Host
62 * Target:: Adding a New Target
63 * Config:: Extending @code{configure}
64 * BFD support for GDB:: How BFD and GDB interface
65 * Host versus Target:: What features are in which files
66 * Symbol Reading:: Defining new symbol readers
67 * Languages:: Defining new source languages
68
69 @end menu
70
71 @node Cleanups, Wrapping, Top, Top
72 @chapter Cleanups
73
74 Cleanups are a structured way to deal with things that need to be done
75 later. When your code does something (like @code{malloc} some memory, or open
76 a file) that needs to be undone later (e.g. free the memory or close
77 the file), it can make a cleanup. The cleanup will be done at some
78 future point: when the command is finished, when an error occurs, or
79 when your code decides it's time to do cleanups.
80
81 You can also discard cleanups, that is, throw them away without doing
82 what they say. This is only done if you ask that it be done.
83
84 Syntax:
85
86 @table @code
87 @item @var{old_chain} = make_cleanup (@var{function}, @var{arg});
88 Make a cleanup which will cause @var{function} to be called with @var{arg}
89 (a @code{char *}) later. The result, @var{old_chain}, is a handle that can be
90 passed to @code{do_cleanups} or @code{discard_cleanups} later. Unless you are
91 going to call @code{do_cleanups} or @code{discard_cleanups} yourself,
92 you can ignore the result from @code{make_cleanup}.
93
94
95 @item do_cleanups (@var{old_chain});
96 Perform all cleanups done since @code{make_cleanup} returned @var{old_chain}.
97 E.g.:
98 @example
99 make_cleanup (a, 0);
100 old = make_cleanup (b, 0);
101 do_cleanups (old);
102 @end example
103 @noindent
104 will call @code{b()} but will not call @code{a()}. The cleanup that calls @code{a()} will remain
105 in the cleanup chain, and will be done later unless otherwise discarded.@refill
106
107 @item discard_cleanups (@var{old_chain});
108 Same as @code{do_cleanups} except that it just removes the cleanups from the
109 chain and does not call the specified functions.
110
111 @end table
112
113 Some functions, e.g. @code{fputs_filtered()} or @code{error()}, specify that they
114 ``should not be called when cleanups are not in place''. This means
115 that any actions you need to reverse in the case of an error or
116 interruption must be on the cleanup chain before you call these functions,
117 since they might never return to your code (they @samp{longjmp} instead).
118
119
120 @node Wrapping, Releases, Cleanups, Top
121 @chapter Wrapping output lines
122
123 Output that goes through @code{printf_filtered} or @code{fputs_filtered} or
124 @code{fputs_demangled} needs only to have calls to @code{wrap_here} added
125 in places that would be good breaking points. The utility routines
126 will take care of actually wrapping if the line width is exceeded.
127
128 The argument to @code{wrap_here} is an indentation string which is printed
129 @emph{only} if the line breaks there. This argument is saved away and used
130 later. It must remain valid until the next call to @code{wrap_here} or
131 until a newline has been printed through the @code{*_filtered} functions.
132 Don't pass in a local variable and then return!
133
134 It is usually best to call wrap_here() after printing a comma or space.
135 If you call it before printing a space, make sure that your indentation
136 properly accounts for the leading space that will print if the line wraps
137 there.
138
139 Any function or set of functions that produce filtered output must finish
140 by printing a newline, to flush the wrap buffer, before switching to
141 unfiltered ("printf") output. Symbol reading routines that print
142 warnings are a good example.
143
144
145 @node Releases, README, Wrapping, Top
146 @chapter Configuring GDB for release
147
148
149 GDB should be released after doing @samp{./configure none} in the top level
150 directory. This will leave a makefile there, but no tm- or xm- files.
151 The makefile is needed, for example, for @samp{make gdb.tar.Z}@dots{} If you
152 have tm- or xm-files in the main source directory, C's include rules
153 cause them to be used in preference to tm- and xm-files in the
154 subdirectories where the user will actually configure and build the
155 binaries.
156
157 @samp{./configure none} is also a good way to rebuild the top level Makefile
158 after changing Makefile.in, alldeps.mak, etc.
159
160 @emph{TEMPORARY RELEASE PROCEDURE FOR DOCUMENTATION}
161 @file{gdb.texinfo} is currently marked up using the texinfo-2 macros,
162 which are not yet a default for anything (but we have to start using
163 them sometime).
164
165 For making paper, the only thing this implies is the right generation of
166 texinfo.tex needs to be included in the distribution.
167
168 For making info files, however, rather than duplicating the texinfo2
169 distribution, generate gdb.texinfo locally, and include the files
170 gdb.info* in the distribution. Note the plural;
171 @samp{M-x texinfo-format-buffer} will split the document into one overall file
172 and five or so include files.
173
174 @node README, New Architectures, Releases, Top
175 @chapter The README file
176
177
178 Check the README file, it often has useful information that does not
179 appear anywhere else in the directory.
180
181
182
183 @node New Architectures, Host, README, Top
184 @chapter Defining a new host or target architecture
185
186
187 When building support for a new host and/or target, this will help you
188 organize where to put the various parts. @var{ARCH} stands for the
189 architecture involved.
190
191 Object files needed when the host system is an @var{ARCH} are listed in
192 the file @file{xconfig/@var{ARCH}}, in the Makefile macro @samp{XDEPFILES
193 = }@dots{}. The header file that defines the host system should be
194 called xm-@var{ARCH}.h, and should be specified as the value of @samp{XM_FILE=}
195 in @file{xconfig/@var{ARCH}}.
196 You can also define @samp{CC}, @samp{REGEX} and @samp{REGEX1},
197 @samp{SYSV_DEFINE}, @samp{XM_CFLAGS}, etc in there; see @file{Makefile.in}.
198
199 There are some ``generic'' versions of routines that can be used by
200 various host systems. If these routines work for the @var{ARCH} host,
201 you can just include the generic file's name (with .o, not .c) in
202 @code{XDEPFILES}. Otherwise, you will need to write routines that
203 perform the same functions as the generic file, put them into
204 @code{@var{ARCH}-xdep.c}, and put @code{@var{ARCH}-xdep.o} into
205 @code{XDEPFILES}. These generic host support files include:
206
207 @example
208 coredep.c, coredep.o
209 @end example
210
211 @table @code
212 @item fetch_core_registers()
213 Support for reading registers out of a core file. This routine calls
214 @code{register_addr(}), see below.
215
216 @item register_addr()
217 If your @code{xm-@var{ARCH}.h} file defines the macro
218 @code{REGISTER_U_ADDR(reg)} to be the offset within the @samp{user}
219 struct of a register (represented as a GDB register number),
220 @file{coredep.c} will define the @code{register_addr()} function and use
221 the macro in it. If you do not define @code{REGISTER_U_ADDR}, but you
222 are using the standard @code{fetch_core_registers}, you will need to
223 define your own version of @code{register_addr}, put it into your
224 @code{@var{ARCH}-xdep.c} file, and be sure @code{@var{ARCH}-xdep.o} is
225 in the @code{XDEPFILES} list. If you have your own
226 @code{fetch_core_registers}, you only need to define
227 @code{register_addr} if your @code{fetch_core_registers} calls it. Many
228 custom @code{fetch_core_registers} implementations simply locate the
229 registers themselves.@refill
230 @end table
231
232 Object files needed when the target system is an @var{ARCH} are listed in
233 the file @file{tconfig/@var{ARCH}}, in the Makefile macro @samp{TDEPFILES
234 = }@dots{}. The header file that defines the target system should be
235 called tm-@var{ARCH}.h, and should be specified as the value of @samp{TM_FILE}
236 in @file{tconfig/@var{ARCH}}.
237 You can also define @samp{TM_CFLAGS}, @samp{TM_CLIBS}, and @samp{TM_CDEPS}
238 in there; see @file{Makefile.in}.
239
240 Similar generic support files for target systems are:
241
242 @example
243 exec.c, exec.o:
244 @end example
245
246 This file defines functions for accessing files that are executable
247 on the target system. These functions open and examine an exec file,
248 extract data from one, write data to one, print information about one,
249 etc. Now that executable files are handled with BFD, every architecture
250 should be able to use the generic exec.c rather than its own custom code.
251
252 @node Host, Target, New Architectures, Top
253 @chapter Adding a New Host
254
255 There are two halves to making GDB work on a new machine. First,
256 you have to make it host on the new machine (compile there, handle
257 that machine's terminals properly, etc). If you will be cross-debugging
258 to some other kind of system, you are done.
259
260 (If you want to use GDB to debug programs that run on the new machine,
261 you have to get it to understand the machine's object files, symbol
262 files, and interfaces to processes. @pxref{Target}.)
263
264 Most of the work in making GDB compile on a new machine is in specifying
265 the configuration of the machine. This is done in a dizzying variety
266 of header files and configuration scripts, which we hope to make more
267 sensible soon. Let's say your new host is called an XXX (e.g. sun4),
268 and its full three-part configuration name is XARCH-XVEND-XOS (e.g.
269 sparc-sun-sunos4). In particular:
270
271 At the top level, edit @file{config.sub} and add XARCH, XVEND, and
272 XOS to the lists of supported architectures, vendors, and operating systems
273 near the bottom of the file. Also, add XXX as an alias that maps to
274 XARCH-XVEND-XOS. You can test your changes by running
275
276 @example
277 ./config.sub XXX
278 @end example
279 @noindent
280 and
281 @example
282 ./config.sub XARCH-XVEND-XOS
283 @end example
284 @noindent
285 which should both respond with XARCH-XVEND-XOS and no error messages.
286
287 Then edit @file{include/sysdep.h}. Add a new #define for XXX_SYS, with
288 a numeric value not already in use. Add a new section that says
289
290 @example
291 #if HOST_SYS==XXX_SYS
292 #include <sys/h-XXX.h>
293 #endif
294 @end example
295
296 Now create a new file @file{include/sys/h-XXX.h}. Examine the other
297 h-*.h files as templates, and create one that brings in the right include
298 files for your system, and defines any host-specific macros needed by
299 GDB.
300
301 Now, go to the bfd directory and edit @file{bfd/configure.in}. Add shell
302 script code to recognize your XARCH-XVEND-XOS configuration, and set
303 bfd_host to XXX when you recognize it. Now create a file
304 @file{bfd/config/hmake-XXX}, which includes the line:
305
306 @example
307 HDEFINES=-DHOST_SYS=XXX_SYS
308 @end example
309
310 (If you have the binutils in the same tree, you'll have to do the same
311 thing to in the binutils directory as you've done in the bfd directory.)
312
313 It's likely that the libiberty and readline directories won't need any
314 changes for your configuration, but if they do, you can change the
315 @file{configure.in} file there to recognize your system and map to an
316 hmake-XXX file. Then add @file{hmake-XXX} to the @file{config/} subdirectory,
317 to set any makefile variables you need. The only current options
318 in there are things like -DSYSV.
319
320 Aha! Now to configure GDB itself! Modify @file{gdb/configure.in} to
321 recognize your system and set gdb_host to XXX. Add a file
322 @file{gdb/xconfig/XXX} which specifies XDEPFILES=(whatever is needed),
323 and XM_FILE= xm-XXX.h. Create @file{gdb/xm-XXX.h} with the appropriate
324 #define's for your system (crib from existing xm-*.h files).
325 If your machine needs custom support routines, you can put them in
326 a file @file{gdb/XXX-xdep.c}, and add XXX-xdep.o to the XDEPFILES=
327 line. If not, you can use the generic routines for ptrace support
328 (infptrace.o) and core files (coredep.o). These can be customized
329 in various ways by macros defined in your @file{xm-XXX.h} file.
330
331 Now, from the top level (above bfd, gdb, etc), run:
332
333 @example
334 ./configure -template=./configure
335 @end example
336
337 This will rebuild all your configure scripts, using the new
338 configure.in files that you modified. (You can also run this command
339 at any subdirectory level.) You are now ready to try configuring
340 GDB to compile for your system. Do:
341
342 @example
343 ./configure XXX +target=vxworks960
344 @end example
345
346 This will configure your system to cross-compile for VxWorks on
347 the Intel 960, which is probably not what you really want, but it's
348 a test case that works at this stage. (You haven't set up to be
349 able to debug programs that run @emph{on} XXX yet.)
350
351 If this succeeds, you can try building it all with:
352
353 @example
354 make
355 @end example
356
357 Good luck! Comments and suggestions about this section are particularly
358 welcome; send them to bug-gdb@@prep.ai.mit.edu.
359
360 When hosting GDB on a new operating system, to make it possible
361 to debug core files, you will need to either
362 write specific code for parsing your OS's core files, or customize
363 bfd/trad-core.c. First, use whatever #include files your machine uses
364 to define the struct of registers that is accessible (possibly in the
365 upage) in a core file (rather than <machine/reg.h>), and an include
366 file that defines whatever header exists on a core file (e.g. the
367 u-area or a "struct core"). Then modify @samp{trad_unix_core_file_p}
368 to use these values to set up the section information for the data
369 segment, stack segment, any other segments in the core file (perhaps
370 shared library contents or control information), "registers" segment,
371 and if there are two discontiguous sets of registers (e.g. integer and
372 float), the "reg2" segment. This section information basically
373 delimits areas in the core file in a standard way, which the
374 section-reading routines in BFD know how to seek around in.
375
376 Then back in GDB, you need a matching routine called fetch_core_registers.
377 If you can use the generic one, it's in core-dep.c; if not, it's in
378 your foobar-xdep.c file. It will be passed a char pointer
379 to the entire "registers" segment, its length, and a zero; or a char
380 pointer to the entire "regs2" segment, its length, and a 2. The
381 routine should suck out the supplied register values and install them into
382 gdb's "registers" array. (@xref{New Architectures}
383 for more info about this.)
384
385 @node Target, Config, Host, Top
386 @chapter Adding a New Target
387
388 When adding support for a new target machine, there are various areas
389 of support that might need change, or might be OK.
390
391 If you are using an existing object file format (a.out or COFF),
392 there is probably little to be done. See @file{bfd/doc/bfd.texinfo}
393 for more information on writing new a.out or COFF versions.
394
395 If you need to add a new object file format, you are beyond the scope
396 of this document right now. Look at the structure of the a.out
397 and COFF support, build a transfer vector (xvec) for your new format,
398 and start populating it with routines. Add it to the list in
399 @file{bfd/targets.c}.
400
401 If you are adding a new existing CPU chip (e.g. m68k family), you'll
402 need to define an XARCH-opcode.h file, a tm-XARCH.h file that gives
403 the basic layout of the chip (registers, stack, etc), probably
404 an XARCH-tdep.c file that has support routines for tm-XARCH.h, etc.
405
406 If you are adding a new operating system for an existing CPU chip,
407 add a tm-XOS.h file that describes the operating system facilities
408 that are unusual (extra symbol table info; the breakpoint
409 instruction needed; etc). Then write a @file{tm-XARCH-XOS.h}
410 that just #include's tm-XARCH.h and tm-XOS.h. (Now that we have
411 three-part configuration names, this will probably get revised to
412 separate the OS configuration from the ARCH configuration. FIXME.)
413
414 @node Config, BFD support for GDB, Target, Top
415 @chapter Extending @code{configure}
416 Once you have added a new host, target, or both, you'll also need to
417 extend the @code{configure} script to recognize the new configuration
418 possibilities.
419
420 You shouldn't edit the @code{configure} script itself to add hosts or
421 targets; instead, edit the script fragments in the file
422 @code{configure.in}. To handle new hosts, modify the segment after the
423 comment @samp{# per-host}; to handle new targets, modify after @samp{#
424 per-target}.
425 @c Would it be simpler to just use different per-host and per-target
426 @c *scripts*, and call them from {configure} ?
427
428 Then fold your changes into the @code{configure} script by using the
429 @code{+template} option, and specifying @code{configure} itself as the
430 template:
431 @example
432 configure +template=configure
433 @end example
434 @c If "configure" is the only workable option value for +template, it's
435 @c kind of silly to insist that it be provided. If it isn't, somebody
436 @c please fill in here what are others... (then delete this comment!)
437
438 @node BFD support for GDB, Host versus Target, Config, Top
439 @chapter Binary File Descriptor library support for GDB
440
441 BFD provides support for GDB in several ways:
442
443 @table @emph
444 @item identifying executable and core files
445 BFD will identify a variety of file types, including a.out, coff, and
446 several variants thereof, as well as several kinds of core files.
447
448 @item access to sections of files
449 BFD parses the file headers to determine the names, virtual addresses,
450 sizes, and file locations of all the various named sections in files
451 (such as the text section or the data section). GDB simply calls
452 BFD to read or write section X at byte offset Y for length Z.
453
454 @item specialized core file support
455 BFD provides routines to determine the failing command name stored
456 in a core file, the signal with which the program failed, and whether
457 a core file matches (i.e. could be a core dump of) a particular executable
458 file.
459
460 @item locating the symbol information
461 GDB uses an internal interface of BFD to determine where to find the
462 symbol information in an executable file or symbol-file. GDB itself
463 handles the reading of symbols, since BFD does not ``understand'' debug
464 symbols, but GDB uses BFD's cached information to find the symbols,
465 string table, etc.
466 @end table
467
468 The interface for symbol reading is described in @xref{Symbol Reading}.
469
470 @node Host versus Target, Symbol Reading, BFD support for GDB, Top
471 @chapter What is considered ``host-dependent'' versus ``target-dependent''?
472
473 The xconfig/*, xm-*.h and *-xdep.c files are for host support. The
474 question is, what features or aspects of a debugging or cross-debugging
475 environment are considered to be ``host'' support.
476
477 Defines and include files needed to build on the host are host support.
478 Examples are tty support, system defined types, host byte order, host
479 float format.
480
481 Unix child process support is considered an aspect of the host. Since
482 when you fork on the host you are still on the host, the various macros
483 needed for finding the registers in the upage, running ptrace, and such
484 are all in the host-dependent files.
485
486 This is still somewhat of a grey area; I (John Gilmore) didn't do the
487 xm- and tm- split for gdb (it was done by Jim Kingdon) so I have had to
488 figure out the grounds on which it was split, and make my own choices
489 as I evolve it. I have moved many things out of the xdep files
490 actually, partly as a result of BFD and partly by removing duplicated
491 code.
492
493
494 @node Symbol Reading, Languages, Host versus Target, Top
495 @chapter Symbol Reading
496
497 GDB reads symbols from "symbol files". The usual symbol file is the
498 file containing the program which gdb is debugging. GDB can be directed
499 to use a different file for symbols (with the ``symbol-file''
500 command), and it can also read more symbols via the ``add-file'' and ``load''
501 commands, or while reading symbols from shared libraries.
502
503 Symbol files are initially opened by @file{symfile.c} using the BFD
504 library. BFD identifies the type of the file by examining its header.
505 @code{symfile_init} then uses this identification to locate a
506 set of symbol-reading functions.
507
508 Symbol reading modules identify themselves to GDB by calling
509 @code{add_symtab_fns} during their module initialization. The argument
510 to @code{add_symtab_fns} is a @code{struct sym_fns} which contains
511 the name (or name prefix) of the symbol format, the length of the prefix,
512 and pointers to four functions. These functions are called at various
513 times to process symbol-files whose identification matches the specified
514 prefix.
515
516 The functions supplied by each module are:
517
518 @table @code
519 @item XXX_symfile_init(struct sym_fns *sf)
520
521 Called from @code{symbol_file_add} when we are about to read a new
522 symbol file. This function should clean up any internal state
523 (possibly resulting from half-read previous files, for example)
524 and prepare to read a new symbol file. Note that the symbol file
525 which we are reading might be a new "main" symbol file, or might
526 be a secondary symbol file whose symbols are being added to the
527 existing symbol table.
528
529 The argument to @code{XXX_symfile_init} is a newly allocated
530 @code{struct sym_fns} whose @code{bfd} field contains the BFD
531 for the new symbol file being read. Its @code{private} field
532 has been zeroed, and can be modified as desired. Typically,
533 a struct of private information will be @code{malloc}'d, and
534 a pointer to it will be placed in the @code{private} field.
535
536 There is no result from @code{XXX_symfile_init}, but it can call
537 @code{error} if it detects an unavoidable problem.
538
539 @item XXX_new_init()
540
541 Called from @code{symbol_file_add} when discarding existing symbols.
542 This function need only handle
543 the symbol-reading module's internal state; the symbol table data
544 structures visible to the rest of GDB will be discarded by
545 @code{symbol_file_add}. It has no arguments and no result.
546 It may be called after @code{XXX_symfile_init}, if a new symbol
547 table is being read, or may be called alone if all symbols are
548 simply being discarded.
549
550 @item XXX_symfile_read(struct sym_fns *sf, CORE_ADDR addr, int mainline)
551
552 Called from @code{symbol_file_add} to actually read the symbols from a
553 symbol-file into a set of psymtabs or symtabs.
554
555 @code{sf} points to the struct sym_fns originally passed to
556 @code{XXX_sym_init} for possible initialization. @code{addr} is the
557 offset between the file's specified start address and its true address
558 in memory. @code{mainline} is 1 if this is the main symbol table being
559 read, and 0 if a secondary symbol file (e.g. shared library or
560 dynamically loaded file) is being read.@refill
561 @end table
562
563 In addition, if a symbol-reading module creates psymtabs when
564 XXX_symfile_read is called, these psymtabs will contain a pointer to
565 a function @code{XXX_psymtab_to_symtab}, which can be called from
566 any point in the GDB symbol-handling code.
567
568 @table @code
569 @item XXX_psymtab_to_symtab (struct partial_symtab *pst)
570
571 Called from @code{psymtab_to_symtab} (or the PSYMTAB_TO_SYMTAB
572 macro) if the psymtab has not already been read in and had its
573 @code{pst->symtab} pointer set. The argument is the psymtab
574 to be fleshed-out into a symtab. Upon return, pst->readin
575 should have been set to 1, and pst->symtab should contain a
576 pointer to the new corresponding symtab, or zero if there
577 were no symbols in that part of the symbol file.
578 @end table
579
580 @node Languages, , Host versus Target, Top
581 @chapter Adding a Source Language to GDB
582
583 To add other languages to GDB's expression parser, follow the following steps:
584
585 @table @emph
586 @item Create the expression parser.
587
588 This should reside in a file called <lang>-exp.y. Routines for building
589 parsed expressions into a (struct exp_elt) list are in parser-code.c.
590
591 Since we can't depend upon everyone having Bison, the following lines
592 @emph{musg} be included at the top of the YACC parser:
593
594 @example
595 #define yyparse <lang>_parse
596 #define yylex <lang>_lex
597 #define yyerror <lang>_error
598 #define yylval <lang>_lval
599 #define yychar <lang>_char
600 #define yydebug <lang>_debug
601 #define yypact <lang>_pact
602 #define yyr1 <lang>_r1
603 #define yyr2 <lang>_r2
604 #define yydef <lang>_def
605 #define yychk <lang>_chk
606 #define yypgo <lang>_pgo
607 #define yyact <lang>_act
608 #define yyexca <lang>_exca
609 @end example
610
611 This will prevent name conflicts between the various parsers.
612
613 @item Add any evaluation routines, if necessary
614
615 If you need new opcodes (that represent the operations of the language),
616 add them to the ennumerated type in expression.h.
617 Add support code for these operations in eval.c:evaluate_subexp()
618 Add cases for new opcodes in parser-code.c:prefixify_subexp() and
619 parser-code.c:length_of_subexp(). These compute the number of
620 exp_elements that a given operation takes up.
621
622 @item Update some existing code
623
624 Add an ennumerated identifier for your language to the ennumerated type
625 enum language in symtab.h.
626
627 Update the routines in language.c so your language is included. These
628 routines include type predicates and such, which (in some cases) are
629 language dependent. If your language does not appear in the switch
630 statement, an error is reported.
631
632 Also included in language.c is the code that updates the variable
633 working_lang, and the routines that translate the language_<lang>
634 ennumerated identifier into a printable string.
635
636 Update the function _intitialize_language to include your language. This
637 function picks the default language upon startup, so is dependent upon
638 which languages that GDB is built for.
639
640 Update symfile.c and/or symbol-reading code so that the language of
641 each symtab (source file) is set properly. This is used to determine the
642 language to use at each stack frame level. Currently, the language
643 is set based upon the extension of the source file. If the language
644 can be better inferred from the symbol information, please set the
645 language of the symtab in the symbol-reading code.
646
647 Add helper code to expprint.c:print_subexp() to handle any new expression
648 opcodes you have added to expression.h. Also, add the printed
649 representations of your operators to op_print_tab.
650
651 @item Add a place of call
652
653 Add a call to <lang>_parse() and <lang>_error in parse.c:parse_exp_1().
654
655 @item Use macros to trim code
656
657 The user has the option of building GDB for some or all of the languages.
658 If the user decides to build GDB for the language <lang>, then every file
659 dependent on language.h will have the macro _LANG_<lang> defined in it.
660 Use #ifdefs to leave out large routines that the user won't need if
661 he/she is not using your language.
662
663 Note that you do not need to do this in your YACC parser, since if GDB is
664 not build for <lang>, then <lang>-exp.tab.o (the compiled form of your
665 parser) is not linked into GDB at all.
666
667 See the file configure.in for how GDB is configured for different languages.
668
669 @item Edit Makefile.in
670
671 Add dependencies in Makefile.in. Make sure you update the macro
672 variables such as HFILES and OBJS, otherwise your code may not get linked
673 in, or, worse yet, it may not get tarred into the distribution!
674
675 @contents
676 @bye
677
This page took 0.048129 seconds and 4 git commands to generate.