* gdb-int.texinfo: Add text on how to define a new host or target
[external/binutils.git] / gdb / doc / gdbint.texinfo
1 GDB Internals documentation
2
3 This needs to be wrapped in texinfo stuff...
4
5   Cleanups
6
7 Cleanups are a structured way to deal with things that need to be done
8 later.  When your code does something (like malloc some memory, or open
9 a file) that needs to be undone later (e.g. free the memory or close
10 the file), it can make a cleanup.  The cleanup will be done at some
11 future point:  when the command is finished, when an error occurs, or
12 when your code decides it's time to do cleanups.
13
14 You can also discard cleanups, that is, throw them away without doing
15 what they say.  This is only done if you ask that it be done.
16
17 Syntax:
18
19         old_chain = make_cleanup (function, arg);
20
21 This makes a cleanup which will cause FUNCTION to be called with ARG
22 (a char *) later.  The result, OLD_CHAIN, is a handle that can be
23 passed to do_cleanups or discard_cleanups later.  Unless you are
24 going to call do_cleanups or discard_cleanups yourself,
25 you can ignore the result from make_cleanup.
26
27         do_cleanups (old_chain);
28
29 Performs all cleanups done since make_cleanup returned OLD_CHAIN.
30 E.g.:   make_cleanup (a, 0); old = make_cleanup (b, 0); do_cleanups (old);
31 will call b() but will not call a().  The cleanup that calls a() will remain
32 in the cleanup chain, and will be done later unless otherwise discarded.
33
34         discard_cleanups (old_chain);
35
36 Same as do_cleanups except that it just removes the cleanups from the
37 chain and does not call the specified functions.
38
39
40 Some functions, e.g. fputs_filtered() or error(), specify that they
41 "should not be called when cleanups are not in place".  This means
42 that any actions you need to reverse in the case of an error or
43 interruption must be on the cleanup chain before you call these functions,
44 since they might never return to your code (they "longjmp" instead).
45
46
47
48   Wrapping output lines
49
50 Output that goes through printf_filtered or fputs_filtered or
51 fputs_demangled needs only to have calls to wrap_here() added 
52 in places that would be good breaking points.  The utility routines
53 will take care of actually wrapping if the line width is exceeded.
54
55 The argument to wrap_here() is an indentation string which is printed
56 ONLY if the line breaks there.  This argument is saved away and used
57 later.  It must remain valid until the next call to wrap_here() or
58 until a newline has been printed through the *_filtered functions.
59 Don't pass in a local variable and then return!
60
61 It is usually best to call wrap_here() after printing a comma or space.
62 If you call it before printing a space, make sure that your indentation
63 properly accounts for the leading space that will print if the line wraps
64 there.
65
66
67
68
69   Configuring GDB for release
70
71
72 GDB should be released after doing "config.gdb none" in the top level
73 directory.  This will leave a makefile there, but no tm- or xm- files.
74 The makefile is needed, for example, for "make gdb.tar.Z"...  If you
75 have tm- or xm-files in the main source directory, C's include rules
76 cause them to be used in preference to tm- and xm-files in the 
77 subdirectories where the user will actually configure and build the
78 binaries.
79
80 "config.gdb none" is also a good way to rebuild the top level Makefile
81 after changing Makefile.dist, alldeps.mak, etc.
82
83
84
85
86   The README file
87
88
89 Check the README file, it often has useful information that does not
90 appear anywhere else in the directory.
91
92
93
94
95   Defining a new host or target architecture
96
97
98 When building support for a new host and/or target, this will help you
99 organize where to put the various parts.  ARCH stands for the
100 architecture involved.
101
102 Object files needed when the host system is an ARCH are listed in the file
103 xconfig/ARCH, in the Makefile macro "XDEPFILES = ...".  You can also
104 define XXXXXX in there.
105
106 There are some "generic" versions of routines that can be used by
107 various host systems.  If these routines work for the ARCH host, you
108 can just include the generic file's name (with .o, not .c) in
109 XDEPFILES.  Otherwise, you will need to write routines that perform the
110 same functions as the generic file, put them into ARCH-xdep.c, and put
111 ARCH-xdep.o into XDEPFILES.  These generic host support files include:
112
113         coredep.c, coredep.o
114
115 fetch_core_registers():
116 Support for reading registers out of a core file.  This routine calls
117 register_addr(), see below.
118
119 register_addr():
120 If your xm-ARCH.h file defines the macro REGISTER_U_ADDR(reg) to be the
121 offset within the "user" struct of a register (represented as a GDB
122 register number), coredep.c will define the register_addr() function
123 and use the macro in it.  If you do not define REGISTER_U_ADDR, but
124 you are using the standard fetch_core_registers, you
125 will need to define your own version of register_addr, put it into
126 your ARCH-xdep.c file, and be sure ARCH-xdep.o is in the XDEPFILES list.
127 If you have your own fetch_core_registers, you only need to define
128 register_addr if your fetch_core_registers calls it.  Many custom
129 fetch_core_registers implementations simply locate the registers
130 themselves.
131
132
133 Files needed when the target system is an ARCH are listed in the file
134 tconfig/ARCH, in the Makefile macro "TDEPFILES = ...".  You can also
135 define XXXXXX in there.
136
137 Similar generic support files for target systems are:
138
139         exec.c, exec.o:
140
141 This file defines functions for accessing files that are executable
142 on the target system.  These functions open and examine an exec file,
143 extract data from one, write data to one, print information about one,
144 etc.  Now that executable files are handled with BFD, every architecture
145 should be able to use the generic exec.c rather than its own custom code.