################################################################################# # # # gdbinit-MacsBug # # # # Macsbug-syle gdb command definitions and plugin loader # # # # Ira L. Ruben # # Copyright Apple Computer, Inc. 2000-2001 # # # ################################################################################# # This file can be either sourced'ed in by .gdbinit or explicitly to define a set # of gdb commands that simulate a subset of MacsBug commands. It is as faithful # a simulation as possible within the limits of the environment. There are also # some extensions where it makes sense in the context of the debugging paradigm # imposed by gdb. Also a MacsBug-like UI is supported (use the MB command to # initiate the UI). # Once gdb is loaded type HELP to see a summary of all gdb command classes. # There are three additional classes for MacsBug: "macsbug", "screen", and # "useful". Typing "help macsbug" give a summary of all MacsBug commands. Typing # "help screen" gives a summary of all MacsBug screen UI-related commands which # are additions to this MacsBug implementation. Typing "help useful" give a list # of "useful" gdb commands that could be used to extend this script. Some of # these are used internally, or are descendents from the original gdb script that # preceded this script, or are just plain useful in their own right and should # probably be in gdb in the first place!. # Two existing classes, "aliases" and "support" also list some MacsBug commands. # The "aliases" class lists aliases for some commands that don't follow the # standard gdb abbreviation conventions (e.g., SC6 is the same as SC). The # "support" class lists the SET options. # As indicated at the end of the HELP class summary you can type "mb-notes" to # get some additional information specifically related to this implementation of # MacsBug. # Finally, also as indicated in the HELP summary, typing "help" followed by a # command name displays a summary for that specific command. # NOTE: The expression syntax used in the gdb commands is written using C syntax # so this implementation is only applicable for debugging C/C++. If you # are trying to debug any other language, you're probably screwed! # The author has endeavored to produce as complete a set of MacsBug commands as # feasible within the restrictions imposed by the environment. But others may # have additional ideas. So contributions and embellishments are welcome. The # only restrictions are that to be placed in this particular universe of commands # they must be variants of *EXISTING* MacsBug commands. Any other "flavors" do # not belong here, except perhaps those dealing with the UI. # You will not see many of the commands in this file. That's because they are # implemented in a set of plugins that are loaded from this file with the Apple # gdb LOAD_PLUGIN command. This is an Apple-specific extension to gdb. Not only # that the plugins must be built for the system they are running on (or at least # compatible with the version of gdb on that system). As such these are not as # portable as the pure script version on which this implementation is based. # Revision history # # 12-Dec-2000 ILR Took the original gdbinit-MacsBug-without-plugin # script as the starting point for this script. # However this script is a shadow of its former # self! Most of the commands are now written using # the Apple gdb plugin architecture. Also a # MacsBug-like UI is implemented. # 3-Jan-2001 ILR Override the LIST command to make listing contiguous # when the MacsBug screen is off. # 9-Jan-2001 ILR Removed G command and made it a plugin to get around # gdb bug involving executing commands assoicated # with a breakpoint initiated from a CONTINUE # executed withing a DEFINE command. # Added RA (run again) command. # Fixed some capitalization errors in help commands. # ################################################################################### ################################################################################### # # TO DO: # 1. Fix TV to display AltiVec regs when OS gives them to gdb and gdb to me. # 2. Fix the TF display. # ################################################################################### ################################################################################### # Current highest command identifier value for $__lastcmd__ is 44 # 19, 20 are available. # In each command assign $__lastcmd__ to a unique command number for each new # command where applicable and update the above comment to make it easier to # remember what to assign to future commands. # $__lastcmd__ is not just "noise". Some MacsBug simulated commands need to # know what the previous command was to perform the required MacsBug semantics. ################################################################################### ################################################################################### # # MB-NOTES - Additional info about MacsBug implementation. # define mb-notes help mb-notes end #2345678901234567890123456789012345678901234567890123456789012345678901234567890 document mb-notes Ê The "MacsBug" supported here is gdb extended to support a subset of the Mac Classic MacsBug commands and a MacsBug-like screen UI. Thus it basically is a variant of MacsBug with source-level debugging! Ê Use gdb's HELP to see the list of supported commands. You will see two additional classes when you type HELP; "macsbug" and "screen". They will allow you to see a summary of the additional supported commands. Below are some additional notes relating to this implementations differences with the Mac Classic MacsBug. Ê Ê1. The $dot gdb variable is the last address referenced by certain commands. ÊÊÊÊThis corresponds to Mac Classic's MacsBug '.' variable. For example, SM ÊÊÊÊsets $dot to the first address that was changed. The default for many ÊÊÊÊcommands is to use $dot as their address argument. Typing DM will display ÊÊÊÊthe memory just set and set the last command to DM. A return after the ÊÊÊÊparameterless DM command will use the $dot set by it to display then next ÊÊÊÊblock of memory in sequence. Note that this is the normal MacsBug behavior ÊÊÊÊbut that is different from gdb which would repeat the last command. Ê Ê2. The $colon gdb variable is the address of the start of the proc containing ÊÊÊÊthe current PC when the target is running. Ê Ê3. Only C/C++ can be debugged since the gdb commands use C/C++ syntax for ÊÊÊÊtheir implementation (restriction imposed by this implementation's use of ÊÊÊÊgdb). Ê Ê4. Arguments are written using C/C++ syntax (e.g., use -> instead of ^, != ÊÊÊÊinstead of <>, etc.). Ê Ê5. Only one command per line allowed (gdb restriction). Ê Ê6. Some restrictions on the commands that are supported. Do help on individual ÊÊÊÊcommands for details. Ê Ê7. Decimal values are shown without leading '#' and hex is shown with ÊÊÊÊa '0x' prefix (except in disassemblies and other displays where it's ÊÊÊÊobvious it's hex). Ê Ê8. The input radix is as defined by the gdb "SET input-radix" command. The ÊÊÊÊdefault is decimal unlike MacsBug which defaults to hex. Use the gdb ÊÊÊÊcommand "SHOW input-radix" to verify the input radix. Ê Ê9. Many of the commands are not permitted until there is a target program ÊÊÊÊrunning (using the G or gdb RUN command). Most of the commands will ÊÊÊÊcause some kind of error report until there is a target running. Of ÊÊÊÊcourse with Mac Classic MacsBug there is always something running. But ÊÊÊÊthat's not the case with gdb. Ê 10. Some of the MacsBug SET options are supported. Use HELP support to see ÊÊÊÊa summary of SET commands. All the MacsBug SET options start with "mb-" ÊÊÊÊso you can use standard command completion (hitting tab after typing the ÊÊÊÊ"mb" will show you all those SET options. For compatibility with ÊÊÊÊMac Classic MacsBug, SET ditto and SET unmangle are also supported. Ê 11. Some Mac Classic MacsBug commands like SC6, SC7, and SC or ILP and IL ÊÊÊÊare identical in the gdb implementation. These alternatives take the ÊÊÊÊform of gdb aliases. Use HELP aliases to see the supported aliases. Ê 12. SI is defined as the MacsBug S command since gdb already has a S ÊÊÊÊcommand. But this overrides gdb's SI abbreviation for STEPI. Ê 13. When the MacsBug screen is being used command lines may be continued ÊÊÊÊ(using '\') within the area defined for commands. The default number ÊÊÊÊof lines is 2 but may be increased up to 15 using the SET mb-cmd-area. ÊÊÊÊContinuing more than the allotted space is allowed but will cause the ÊÊÊÊcommand lines to scroll up within their area. Unfortunately this does ÊÊÊÊnot happen if a command is interactively created with DEFINE and you ÊÊÊÊtry to continue one of the command's lines. The continuations are ÊÊÊÊallowed. But they just don't scroll. Ê 14. Unlike Mac Classic MacsBug, there is only one screen for gdb and the ÊÊÊÊtarget program. Further, gdb has no control over output generated by ÊÊÊÊthe target program or caused by it (e.g., dyld messages). Thus the ÊÊÊÊMacsBug screen could get "mangled". Use the REFRESH command to restore ÊÊÊÊthe MacsBug screen or turn off the MacsBug screen and debug with gdb's ÊÊÊÊnormal scroll mode. All the MacsBug commands still work in scroll mode ÊÊÊÊand any commands that cause disassembly will display the current ÊÊÊÊregisters on the right side of the terminal screen (to minimize the ÊÊÊÊaffect on scroll back viewing). Ê 15. A set of possibly useful commands for extending this script are available. ÊÊÊÊTyping "help useful" will list those commands. You will see some output ÊÊÊÊcommands that write their output to stderr instead of stdout. This is ÊÊÊÊonly significant in the context of the MacsBug screen. When the MacsBug ÊÊÊÊscreen is on (MB on) all output goes into the history area. Output to ÊÊÊÊstderr is written in red. By convention this should be used for error ÊÊÊÊreporting only. Ê end ################################################################################### # Note, you will not see the commands defined here with "HELP user-defined". Look # # for them with "HELP macsbug" along with all other MacsBug commands. # ################################################################################### # # BRC [addr] # define BRC if ($argc == 0) delete else clear $arg0 end set $__lastcmd__ = 1 end document BRC BRC [addr] -- Clear all breakpoints or one breakpoint at addr. See also gdb's DELETE command (clears breakpoints by number), and DISABLE. end ################################################################################### # # BRD [n] # define BRD if ($argc == 0) info breakpoints else info breakpoints $arg0 end set $__lastcmd__ = 2 end document BRD BRD -- Show all breakpoints (or breakpoint n). end ################################################################################### # # ES # define ES set confirm off quit end document ES ES -- exit to shell (unconditionally quit gdb). end ################################################################################### # # MR # define MR if ($argc != 0) __error Only the parameterless form of MR is supported. else finish end set $__lastcmd__ = 15 end document MR MR -- Return from current frame. Ê Macsbug features not supported: offset and addr arguments end ################################################################################### # # T [n] [m] # define T __is_running The program is not running. if ($__argc == 0) SO else if ($__argc == 1) SO $__arg0 else SO $__arg0 $__arg1 end end #set $__lastcmd__ = 25 end document T T [n] [m] -- Same as SO. end ################################################################################### # # TF # #PowerPC FPU Registers # S S # F N I I Z I O Q C # FPSCR F E V O U Z X A S D D M V F F F R V V O U Z X N # X X X X X X X N I I Z Z C R I C < > = ? T T I E E E E E I RN # 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 00 # # FPR0 = FFF 8000082004000 -NAN(000) # FPR1 = 408 4700000000000 6.540000000000000e+2 # - - - # FPR30 = 000 0000000000000 0.000000000000000e+0 # FPR31 = 000 0000000000000 0.000000000000000e+0 # # There's no way to display the floating regs in hex like this. So we'll # just have to settle with what info registers $fN produces. It's a # pretty good approximation so it isn't too bad. # define TF # Following causes an appropriate error message if regs are unabailable. set $accessible = $f0 printf "PowerPC Vector Registers\n" printf " S S\n" printf " F N I I Z I O Q C\n" printf " FPSCR F E V O U Z X A S D D M V F F F R V V O U Z X N\n" printf " X X X X X X X N I I Z Z C R I C < > = ? T T I E E E E E I RN\n" printf " " set $i = 0 set $r = $fpscr while ($i++ < 32) printf "%1d", ($r >> (32-$i)) & 1 if ($i < 31) printf " " end end printf "\n\n" info registers $f0 info registers $f1 info registers $f2 info registers $f3 info registers $f4 info registers $f5 info registers $f6 info registers $f7 info registers $f8 info registers $f9 info registers $f10 info registers $f11 info registers $f12 info registers $f13 info registers $f14 info registers $f15 info registers $f16 info registers $f17 info registers $f18 info registers $f19 info registers $f20 info registers $f21 info registers $f22 info registers $f23 info registers $f24 info registers $f25 info registers $f26 info registers $f27 info registers $f28 info registers $f29 info registers $f30 info registers $f31 set $__lastcmd__ = 27 end document TF TF -- Display the floating point registers. end ################################################################################### # # TV # #PowerPC Vector Registers # S # VRsave = 00000000 N A # J T # VSCR = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # # V0 = 00000000 00000000 00000000 00000000 0.0000e+0 0.0000e+0 0.0000e+0 0.0000e+0 # V1 = 53706F74 20636865 636B206F 66207472 1.0327e+12 1.9262e-19 4.3373e+21 1.8943e+23 # - - - # V30 = 7FFFDEAD 7FFFDEAD 7FFFDEAD 7FFFDEAD NAN(222) NAN(222) NAN(222) NAN(222) # V31 = 7FFFDEAD 7FFFDEAD 7FFFDEAD 7FFFDEAD NAN(222) NAN(222) NAN(222) NAN(222) # define TV printf "PowerPC Vector Registers\n" printf "%c[31m", 0x1B printf " Not available - can't get or manipulate the vector registers yet! Sorry. Sigh :-(\n" printf "\n" printf "%c[0m\n", 0x1B info registers set $__lastcmd__ = 28 end document TV TV -- Display the vector registers (not yet supported). end ################################################################################### ################################################################################### load-plugin /usr/libexec/gdb/plugins/MacsBug/MacsBug_plugins