⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdbinv-s.m4.in

📁 早期freebsd实现
💻 IN
📖 第 1 页 / 共 3 页
字号:
_dnl__								-*- Texinfo -*-_dnl__ Copyright (c) 1990 1991 1992 Free Software Foundation, Inc._dnl__ This file is part of the source for the GDB manual._dnl__ M4 FRAGMENT $Id: gdbinv-s.m4.in,v 2.13 1992/10/23 08:50:19 grossman Exp $_dnl__ This text diverted to "Remote Debugging" section in general case;_dnl__ however, if we're doing a manual specifically for one of these, it_dnl__ belongs up front (in "Getting In and Out" chapter)._if__(_REMOTESTUB__)@node Remote Serial@subsection The _GDBN__ remote serial protocol@cindex remote serial debugging, overviewTo debug a program running on another machine (the debugging@dfn{target} machine), you must first arrange for all the usualprerequisites for the program to run by itself.  For example, for a Cprogram, you need@enumerate@itemA startup routine to set up the C runtime environment; these usuallyhave a name like @file{crt0}.  The startup routine may be supplied byyour hardware supplier, or you may have to write your own.@item You probably need a C subroutine library to support your program'ssubroutine calls, notably managing input and output.@itemA way of getting your program to the other machine---for example, adownload program.  These are often supplied by the hardwaremanufacturer, but you may have to write your own from hardwaredocumentation.@end enumerateThe next step is to arrange for your program to use a serial port tocommunicate with the machine where _GDBN__ is running (the @dfn{host}machine).  In general terms, the scheme looks like this:@table @emph@item On the host,_GDBN__ already understands how to use this protocol; when everythingelse is set up, you can simply use the @samp{target remote} command(@pxref{Targets,,Specifying a Debugging Target}).@item On the target,you must link with your program a few special-purpose subroutines thatimplement the _GDBN__ remote serial protocol.  The file containing thesesubroutines is called  a @dfn{debugging stub}.@end tableThe debugging stub is specific to the architecture of the remotemachine; for example, use @file{sparc-stub.c} to debug programs on@sc{sparc} boards.@cindex remote serial stub listThese working remote stubs are distributed with _GDBN__:@c FIXME! verify these...@table @code@item sparc-stub.c@kindex sparc-stub.cFor @sc{sparc} architectures.@item m68k-stub.c@kindex m68-stub.cFor Motorola 680x0 architectures.@item i386-stub.c@kindex i36-stub.cFor Intel 386 and compatible architectures.@end tableThe @file{README} file in the _GDBN__ distribution may list otherrecently added stubs.@menu* stub contents::       What the stub can do for you* bootstrapping::       What you must do for the stub* debug session::       Putting it all together* protocol::            Outline of the communication protocol@end menu@node stub contents@subsubsection What the stub can do for you@cindex remote serial stubThe debugging stub for your architecture supplies these threesubroutines:@table @code@item set_debug_traps@kindex set_debug_traps@cindex remote serial stub, initializationThis routine arranges to transfer control to @code{handle_exception}when your program stops.  You must call this subroutine explicitly nearthe beginning of your program.@item handle_exception@kindex handle_exception@cindex remote serial stub, main routineThis is the central workhorse, but your program never calls itexplicitly---the setup code arranges for @code{handle_exception} torun when a trap is triggered.@code{handle_exception} takes control when your program stops duringexecution (for example, on a breakpoint), and mediates communicationswith _GDBN__ on the host machine.  This is where the communicationsprotocol is implemented; @code{handle_exception} acts as the _GDBN__representative on the target machine; it begins by sending summaryinformation on the state of your program, then continues to execute,retrieving and transmitting any information _GDBN__ needs, until youexecute a _GDBN__ command that makes your program resume; at that point,@code{handle_exception} returns control to your own code on the targetmachine. @item breakpoint@cindex @code{breakpoint} subroutine, remoteUse this auxiliary subroutine to make your program contain abreakpoint.  Depending on the particular situation, this may be the onlyway for _GDBN__ to get control.  For instance, if your targetmachine has some sort of interrupt button, you won't need to call this;pressing the interrupt button will transfer control to@code{handle_exception}---in efect, to _GDBN__.  On some machines,simply receiving characters on the serial port may also trigger a trap;again, in that situation, you don't need to call @code{breakpoint} fromyour own program---simply running @samp{target remote} from the host_GDBN__ session will get control.  Call @code{breakpoint} if none of these is true, or if you simply wantto make certain your program stops at a predetermined point for thestart of your debugging session.@end table@node bootstrapping@subsubsection What you must do for the stub@cindex remote stub, support routinesThe debugging stubs that come with _GDBN__ are set up for a particularchip architecture, but they have no information about the rest of yourdebugging target machine.  To allow the stub to work, you must supplythese special low-level subroutines:@table @code@item int getDebugChar()@kindex getDebugCharWrite this subroutine to read a single character from the serial port.It may be identical to @code{getchar} for your target system; adifferent name is used to allow you to distinguish the two if you wish.@item void putDebugChar(int)@kindex putDebugCharWrite this subroutine to write a single character to the serial port.It may be identical to @code{putchar} for your target system; a different name is used to allow you to distinguish the two if you wish.@item void flush_i_cache()@kindex flush_i_cacheWrite this subroutine to flush the instruction cache, if any, on yourtarget machine.  If there is no instruction cache, this subroutine maybe a no-op.On target machines that have instruction caches, _GDBN__ requires thisfunction to make certain that the state of your program is stable.@end table@noindentYou must also make sure this library routine is available:@table @code@item void *memset(void *, int, int)@kindex memsetThis is the standard library function @code{memset} that sets an area ofmemory to a known value.  If you have one of the free versions of@code{libc.a}, @code{memset} can be found there; otherwise, you musteither obtain it from your hardware manufacturer, or write your own.@end tableIf you do not use the GNU C compiler, you may need other standardlibrary subroutines as well; this will vary from one stub to another,but in general the stubs are likely to use any of the common librarysubroutines which @code{gcc} generates as inline code.@node debug session@subsubsection Putting it all together@cindex remote serial debugging summaryIn summary, when your program is ready to debug, you must follow thesesteps.@enumerate@itemMake sure you have the supporting low-level routines:@code{getDebugChar}, @code{putDebugChar}, @code{flush_i_cache},@code{memset}.@itemInsert these lines near the top of your program:@exampleset_debug_traps();breakpoint();@end example@itemCompile and link together: your program, the _GDBN__ debugging stub foryour target architecture, and the supporting subroutines.@itemMake sure you have a serial connection between your target machine andthe _GDBN__ host, and identify the serial port used for this on the host.@itemDownload your program to your target machine (or get it there bywhatever means the manufacturer provides), and start it.@itemTo start remote debugging, run _GDBN__ on the host machine, and specifyas an executable file the program that is running in the remote machine.This tells _GDBN__ how to find your program's symbols and the contentsof its pure text.Then establish communication using the @code{target remote} command.Its argument is the name of the device you're using to control thetarget machine.  For example:@exampletarget remote /dev/ttyb@end example@noindentif the serial line is connected to the device named @file{/dev/ttyb}.  @ignore@c this is from the old text, but it doesn't seem to make sense now that I've@c seen an example...  pesch 4sep1992This will stop the remote machine if it is not already stopped.@end ignore@end enumerateNow you can use all the usual commands to examine and change data and tostep and continue the remote program.To resume the remote program and stop debugging it, use the @code{detach}command.@node protocol@subsubsection Outline of the communication protocol@cindex debugging stub, example@cindex remote stub, example@cindex stub example, remote debuggingThe stub files provided with _GDBN__ implement the target side of thecommunication protocol, and the _GDBN__ side is implemented in the_GDBN__ source file @file{remote.c}.  Normally, you can simply allowthese subroutines to communicate, and ignore the details.  (If you'reimplementing your own stub file, you can still ignore the details: startwith one of the existing stub files.  @file{sparc-stub.c} is the bestorganized, and therefore the easiest to read.)However, there may be occasions when you need to know something aboutthe protocol---for example, if there is only one serial port to yourtarget machine, you might want your program to do something special ifit recognizes a packet meant for _GDBN__.@cindex protocol, _GDBN__ remote serial@cindex serial protocol, _GDBN__ remote@cindex remote serial protocolAll _GDBN__ commands and responses (other than acknowledgements, whichare single characters) are sent as a packet which includes achecksum.  A packet is introduced with the character @samp{$}, and endswith the character @samp{#} followed by a two-digit checksum:@example$@var{packet info}#@var{checksum}@end example@cindex checksum, for _GDBN__ remote@noindent@var{checksum} is computed as the modulo 256 sum of the @var{packetinfo} characters.When either the host or the target machine receives a packet, the firstresponse expected is an acknowledgement: a single character, either@samp{+} (to indicate the package was received correctly) or @samp{-}(to request retransmission).The host (_GDBN__) sends commands, and the target (the debugging stubincorporated in your program) sends data in response.  The target alsosends data when your program stops.Command packets are distinguished by their first character, whichidentifies the kind of command.These are the commands currently supported:@table @code@item gRequests the values of CPU registers.@item GSets the values of CPU registers.@item m@var{addr},@var{count}Read @var{count} bytes at location @var{addr}.@item M@var{addr},@var{count}:@dots{}Write @var{count} bytes at location @var{addr}.@item c@itemx c@var{addr}Resume execution at the current address (or at @var{addr} if supplied).@item s@itemx s@var{addr}Step the target program for one instruction, from either the current

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -