gdbint_11.html   [plain text]


<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
     from /mnt/apple/gdb/source/gdb.apple/source/gdb/gdb/doc/gdbint.texinfo on 23 November 1999 -->

<TITLE>GDB Internals - Native Debugging</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="gdbint_1.html">first</A>, <A HREF="gdbint_10.html">previous</A>, <A HREF="gdbint_12.html">next</A>, <A HREF="gdbint_16.html">last</A> section, <A HREF="gdbint_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC75" HREF="gdbint_toc.html#TOC75">Native Debugging</A></H1>

<P>
Several files control GDB's configuration for native support:

</P>
<DL COMPACT>

<DT><TT>`gdb/config/<VAR>arch</VAR>/<VAR>xyz</VAR>.mh'</TT>
<DD>
Specifies Makefile fragments needed when hosting <EM>or native</EM> on
machine <VAR>xyz</VAR>.  In particular, this lists the required
native-dependent object files, by defining <SAMP>`NATDEPFILES=...'</SAMP>.
Also specifies the header file which describes native support on
<VAR>xyz</VAR>, by defining <SAMP>`NAT_FILE= nm-<VAR>xyz</VAR>.h'</SAMP>.  You can also
define <SAMP>`NAT_CFLAGS'</SAMP>, <SAMP>`NAT_ADD_FILES'</SAMP>, <SAMP>`NAT_CLIBS'</SAMP>,
<SAMP>`NAT_CDEPS'</SAMP>, etc.; see <TT>`Makefile.in'</TT>.

<DT><TT>`gdb/config/<VAR>arch</VAR>/nm-<VAR>xyz</VAR>.h'</TT>
<DD>
(<TT>`nm.h'</TT> is a link to this file, created by configure).  Contains C
macro definitions describing the native system environment, such as
child process control and core file support.

<DT><TT>`gdb/<VAR>xyz</VAR>-nat.c'</TT>
<DD>
Contains any miscellaneous C code required for this native support of
this machine.  On some machines it doesn't exist at all.

</DL>

<P>
There are some "generic" versions of routines that can be used by
various systems.  These can be customized in various ways by macros
defined in your <TT>`nm-<VAR>xyz</VAR>.h'</TT> file.  If these routines work for
the <VAR>xyz</VAR> host, you can just include the generic file's name (with
<SAMP>`.o'</SAMP>, not <SAMP>`.c'</SAMP>) in <CODE>NATDEPFILES</CODE>.

</P>
<P>
Otherwise, if your machine needs custom support routines, you will need
to write routines that perform the same functions as the generic file.
Put them into <CODE><VAR>xyz</VAR>-nat.c</CODE>, and put <CODE><VAR>xyz</VAR>-nat.o</CODE>
into <CODE>NATDEPFILES</CODE>.

</P>
<DL COMPACT>

<DT><TT>`inftarg.c'</TT>
<DD>
This contains the <EM>target_ops vector</EM> that supports Unix child
processes on systems which use ptrace and wait to control the child.

<DT><TT>`procfs.c'</TT>
<DD>
This contains the <EM>target_ops vector</EM> that supports Unix child
processes on systems which use /proc to control the child.

<DT><TT>`fork-child.c'</TT>
<DD>
This does the low-level grunge that uses Unix system calls to do a "fork
and exec" to start up a child process.

<DT><TT>`infptrace.c'</TT>
<DD>
This is the low level interface to inferior processes for systems using
the Unix <CODE>ptrace</CODE> call in a vanilla way.

</DL>



<H2><A NAME="SEC76" HREF="gdbint_toc.html#TOC76">Native core file Support</A></H2>

<DL COMPACT>

<DT><TT>`core-aout.c::fetch_core_registers()'</TT>
<DD>
Support for reading registers out of a core file.  This routine calls
<CODE>register_addr()</CODE>, see below.  Now that BFD is used to read core
files, virtually all machines should use <CODE>core-aout.c</CODE>, and should
just provide <CODE>fetch_core_registers</CODE> in <CODE><VAR>xyz</VAR>-nat.c</CODE> (or
<CODE>REGISTER_U_ADDR</CODE> in <CODE>nm-<VAR>xyz</VAR>.h</CODE>).

<DT><TT>`core-aout.c::register_addr()'</TT>
<DD>
If your <CODE>nm-<VAR>xyz</VAR>.h</CODE> file defines the macro
<CODE>REGISTER_U_ADDR(addr, blockend, regno)</CODE>, it should be defined to
set <CODE>addr</CODE> to the offset within the <SAMP>`user'</SAMP> struct of GDB
register number <CODE>regno</CODE>.  <CODE>blockend</CODE> is the offset within the
"upage" of <CODE>u.u_ar0</CODE>.  If <CODE>REGISTER_U_ADDR</CODE> is defined,
<TT>`core-aout.c'</TT> will define the <CODE>register_addr()</CODE> function and
use the macro in it.  If you do not define <CODE>REGISTER_U_ADDR</CODE>, but
you are using the standard <CODE>fetch_core_registers()</CODE>, you will need
to define your own version of <CODE>register_addr()</CODE>, put it into your
<CODE><VAR>xyz</VAR>-nat.c</CODE> file, and be sure <CODE><VAR>xyz</VAR>-nat.o</CODE> is in
the <CODE>NATDEPFILES</CODE> list.  If you have your own
<CODE>fetch_core_registers()</CODE>, you may not need a separate
<CODE>register_addr()</CODE>.  Many custom <CODE>fetch_core_registers()</CODE>
implementations simply locate the registers themselves.
</DL>

<P>
When making GDB run native on a new operating system, to make it
possible to debug core files, you will need to either write specific
code for parsing your OS's core files, or customize
<TT>`bfd/trad-core.c'</TT>.  First, use whatever <CODE>#include</CODE> files your
machine uses to define the struct of registers that is accessible
(possibly in the u-area) in a core file (rather than
<TT>`machine/reg.h'</TT>), and an include file that defines whatever header
exists on a core file (e.g. the u-area or a <SAMP>`struct core'</SAMP>).  Then
modify <CODE>trad_unix_core_file_p()</CODE> to use these values to set up the
section information for the data segment, stack segment, any other
segments in the core file (perhaps shared library contents or control
information), "registers" segment, and if there are two discontiguous
sets of registers (e.g.  integer and float), the "reg2" segment.  This
section information basically delimits areas in the core file in a
standard way, which the section-reading routines in BFD know how to seek
around in.

</P>
<P>
Then back in GDB, you need a matching routine called
<CODE>fetch_core_registers()</CODE>.  If you can use the generic one, it's in
<TT>`core-aout.c'</TT>; if not, it's in your <TT>`<VAR>xyz</VAR>-nat.c'</TT> file.
It will be passed a char pointer to the entire "registers" segment,
its length, and a zero; or a char pointer to the entire "regs2"
segment, its length, and a 2.  The routine should suck out the supplied
register values and install them into GDB's "registers" array.

</P>
<P>
If your system uses <TT>`/proc'</TT> to control processes, and uses ELF
format core files, then you may be able to use the same routines for
reading the registers out of processes and out of core files.

</P>


<H2><A NAME="SEC77" HREF="gdbint_toc.html#TOC77">ptrace</A></H2>



<H2><A NAME="SEC78" HREF="gdbint_toc.html#TOC78">/proc</A></H2>



<H2><A NAME="SEC79" HREF="gdbint_toc.html#TOC79">win32</A></H2>



<H2><A NAME="SEC80" HREF="gdbint_toc.html#TOC80">shared libraries</A></H2>



<H2><A NAME="SEC81" HREF="gdbint_toc.html#TOC81">Native Conditionals</A></H2>

<P>
When GDB is configured and compiled, various macros are defined or left
undefined, to control compilation when the host and target systems are
the same.  These macros should be defined (or left undefined) in
<TT>`nm-<VAR>system</VAR>.h'</TT>.

</P>
<DL COMPACT>

<DT><CODE>ATTACH_DETACH</CODE>
<DD>
If defined, then GDB will include support for the <CODE>attach</CODE> and
<CODE>detach</CODE> commands.

<DT><CODE>CHILD_PREPARE_TO_STORE</CODE>
<DD>
If the machine stores all registers at once in the child process, then
define this to ensure that all values are correct.  This usually entails
a read from the child.

[Note that this is incorrectly defined in <TT>`xm-<VAR>system</VAR>.h'</TT> files
currently.]

<DT><CODE>FETCH_INFERIOR_REGISTERS</CODE>
<DD>
Define this if the native-dependent code will provide its own routines
<CODE>fetch_inferior_registers</CODE> and <CODE>store_inferior_registers</CODE> in
<TT>`<VAR>HOST</VAR>-nat.c'</TT>.  If this symbol is <EM>not</EM> defined, and
<TT>`infptrace.c'</TT> is included in this configuration, the default
routines in <TT>`infptrace.c'</TT> are used for these functions.

<DT><CODE>FILES_INFO_HOOK</CODE>
<DD>
(Only defined for Convex.)

<DT><CODE>FP0_REGNUM</CODE>
<DD>
This macro is normally defined to be the number of the first floating
point register, if the machine has such registers.  As such, it would
appear only in target-specific code.  However, /proc support uses this
to decide whether floats are in use on this target.

<DT><CODE>GET_LONGJMP_TARGET</CODE>
<DD>
For most machines, this is a target-dependent parameter.  On the
DECstation and the Iris, this is a native-dependent parameter, since
&#60;setjmp.h&#62; is needed to define it.

This macro determines the target PC address that longjmp() will jump to,
assuming that we have just stopped at a longjmp breakpoint.  It takes a
CORE_ADDR * as argument, and stores the target PC value through this
pointer.  It examines the current state of the machine as needed.

<DT><CODE>KERNEL_U_ADDR</CODE>
<DD>
Define this to the address of the <CODE>u</CODE> structure (the "user
struct", also known as the "u-page") in kernel virtual memory.  GDB
needs to know this so that it can subtract this address from absolute
addresses in the upage, that are obtained via ptrace or from core files.
On systems that don't need this value, set it to zero.

<DT><CODE>KERNEL_U_ADDR_BSD</CODE>
<DD>
Define this to cause GDB to determine the address of <CODE>u</CODE> at
runtime, by using Berkeley-style <CODE>nlist</CODE> on the kernel's image in
the root directory.

<DT><CODE>KERNEL_U_ADDR_HPUX</CODE>
<DD>
Define this to cause GDB to determine the address of <CODE>u</CODE> at
runtime, by using HP-style <CODE>nlist</CODE> on the kernel's image in the
root directory.

<DT><CODE>ONE_PROCESS_WRITETEXT</CODE>
<DD>
Define this to be able to, when a breakpoint insertion fails, warn the
user that another process may be running with the same executable.

<DT><CODE>PROC_NAME_FMT</CODE>
<DD>
Defines the format for the name of a <TT>`/proc'</TT> device.  Should be
defined in <TT>`nm.h'</TT> <EM>only</EM> in order to override the default
definition in <TT>`procfs.c'</TT>.

<DT><CODE>PTRACE_FP_BUG</CODE>
<DD>
mach386-xdep.c

<DT><CODE>PTRACE_ARG3_TYPE</CODE>
<DD>
The type of the third argument to the <CODE>ptrace</CODE> system call, if it
exists and is different from <CODE>int</CODE>.

<DT><CODE>REGISTER_U_ADDR</CODE>
<DD>
Defines the offset of the registers in the "u area".

<DT><CODE>SHELL_COMMAND_CONCAT</CODE>
<DD>
If defined, is a string to prefix on the shell command used to start the
inferior.

<DT><CODE>SHELL_FILE</CODE>
<DD>
If defined, this is the name of the shell to use to run the inferior.
Defaults to <CODE>"/bin/sh"</CODE>.

<DT><CODE>SOLIB_ADD (filename, from_tty, targ)</CODE>
<DD>
Define this to expand into an expression that will cause the symbols in
<VAR>filename</VAR> to be added to GDB's symbol table.

<DT><CODE>SOLIB_CREATE_INFERIOR_HOOK</CODE>
<DD>
Define this to expand into any shared-library-relocation code that you
want to be run just after the child process has been forked.

<DT><CODE>START_INFERIOR_TRAPS_EXPECTED</CODE>
<DD>
When starting an inferior, GDB normally expects to trap twice; once when
the shell execs, and once when the program itself execs.  If the actual
number of traps is something other than 2, then define this macro to
expand into the number expected.

<DT><CODE>SVR4_SHARED_LIBS</CODE>
<DD>
Define this to indicate that SVR4-style shared libraries are in use.

<DT><CODE>USE_PROC_FS</CODE>
<DD>
This determines whether small routines in <TT>`*-tdep.c'</TT>, which
translate register values between GDB's internal representation and the
/proc representation, are compiled.

<DT><CODE>U_REGS_OFFSET</CODE>
<DD>
This is the offset of the registers in the upage.  It need only be
defined if the generic ptrace register access routines in
<TT>`infptrace.c'</TT> are being used (that is, <TT>`infptrace.c'</TT> is
configured in, and <CODE>FETCH_INFERIOR_REGISTERS</CODE> is not defined).  If
the default value from <TT>`infptrace.c'</TT> is good enough, leave it
undefined.

The default value means that u.u_ar0 <EM>points to</EM> the location of
the registers.  I'm guessing that <CODE>#define U_REGS_OFFSET 0</CODE> means
that u.u_ar0 <EM>is</EM> the location of the registers.

<DT><CODE>CLEAR_SOLIB</CODE>
<DD>
objfiles.c

<DT><CODE>DEBUG_PTRACE</CODE>
<DD>
Define this to debug ptrace calls.

</DL>

<P><HR><P>
Go to the <A HREF="gdbint_1.html">first</A>, <A HREF="gdbint_10.html">previous</A>, <A HREF="gdbint_12.html">next</A>, <A HREF="gdbint_16.html">last</A> section, <A HREF="gdbint_toc.html">table of contents</A>.
</BODY>
</HTML>