Miscellaneous commands


A lot of special miscellaneous commands don't fit the general adb data display command syntax. Let's talk about some of them now.

Value conversion

The = command is used for conversion. Rather than looking up a value in memory and displaying it, the equals sign prints the value of the address field according to the format you specify. You can use this command for printing in different bases, for example, converting hexadecimal to decimal, or for displaying the actual hexadecimal address associated with a symbol.

Let's try a couple of examples of the = command. Below, we convert a hexadecimal value into date format. We also get the hexadecimal representation of the 4-byte character sequence "Hiya." (Yes, as shown below, adb can be run without any arguments.)

 Hiya...  adb   123456=Y  1970 Jan 14 14:24:06  'Hiya'=X  48697961  $q  Hiya... 

The = command is also sometimes used in macros to print labels. You might see a line like the one below ”

 .="Top label"nnn 

”with no actual display of a numeric value. All this command sequence does is print the string "Top label" and a couple of newlines. There was no request to display a data value from either the object file or the core file. In this example, the value of dot would not change.

Note

Even though there may be no memory reference involved, = can modify the value of dot. When using = , always remember that dot ( . ) may have changed.


$ commands

Of course, there are some useful commands that just don't fit in any major categories. This miscellaneous catchall set uses modifiers to the $ command. These include:

$c

Prints a C stack traceback. Originally, there were several different compilers for UNIX, and each had an individual code generator that used separate stack formats. This meant you needed a command to dump out C language stacks, Fortran stacks, or Pascal stacks. When the compilers were eventually modified to use a common code generator (and thus the same type of stack), the need for all these different commands went away, and the $c stack command is the one that survived. By default, $c will display six calling arguments. $c X , where X is 0 through f, can be used to specify how many arguments to display. You can also provide an address to $c (in front of the $) to tell adb "the top of the stack starts here." This combination is used in some macros to display stack tracebacks for various different stacks in the kernel.

$C

Prints a C stack traceback and saved frame pointer and saved program counter values.

$r

Displays the current values of the machine registers. There are lots of machine registers on SPARC; this command will show you their contents. Generally , this command is not too useful for kernel crash dumps, because the values displayed belong to the code in the panic() routine, but the stack pointer can come in handy.

$x

(and $X ) Displays the current values of the floating-point registers.

$<

Reads a macro file. Think of it as "redirecting standard input" away from the keyboard to a file. When the file runs out of commands, control is returned to the user at the keyboard.

$>

Sends output to a file, if you provide a filename. If the name is omitted, output returns to the screen for the following commands.

$v

Displays adb variable values in octal.

$M

Displays the names of the kadb built-in macros.

$q

Quits, or exits, adb . For vi users, it usually takes two tries to get out of adb. After the familiar :q exit command results in a "bad modifier" error message, you remember "Oh yes, I'm in adb " and type the correct $q command. For those who are impatient, a Control-D will also exit adb .

There are other commands that are not commonly used. The man page for adb will give you the details on these and other exciting features.

Pattern searching

adb does have a limited ability to search for patterns. As a part of the display commands, you can ask for a matching pattern to be located. These will start at the given address and look in the appropriate file (? for the object file, / for the core file) until the value is found or adb runs out of data to look at. You can also provide a mask, which allows you to look for only certain bits. By default, the mask is -1 , which scans for a complete match.

The command is ?L or /L to search for full words, and ?l or /l to look for short half-words. After the command, give the value followed by the mask. If adb finds a match, it will set dot to that address.

We will see an example of the pattern searching command in the one of the case studies later on.

Variables

adb maintains some internal variables for storing values. If you need to keep something around, there are commands available to store into and retrieve from local adb variables. These variables are restricted to single-letter or single-digit names, so you can have variables a through z, A through Z, and 0 through 9 in which to store things. Some of these have dedicated uses (a few of the numbers ), and some are initialized when adb starts up, but in general you've got 50 or so places to stash things. Use the $v command to check the current usage of the adb variables.

As you'll see in Chapter 12, some of the adb macros use variables to temporarily keep addresses, so if you plan to use macros, check to see which variables they are using. You'll need to use names that the macros don't modify. Uppercase letters are generally a safe bet, since they are rarely seen in macro files.

The register names of the CPU, such as %i3 , %l0 , and %g6 , are also available as "variables," but in this case these names really refer to the registers of the machine. Modifying these, especially when debugging a running program, will have an effect on the program execution and on the results of some operations.

A couple of commands are available to work with these variables and registers. The > command acts like redirecting standard output, or sending data: it stores the "address," the left-hand side of the command, into the variable. The opposite command, <, retrieves a value from a register and uses it as a value. For example, the commands shown below store the decimal value 1234 into variable p , take the value in p , copy it into Z , and then print the value in Z as a hex number.

Figure 8-2 Using adb variables
 sunryse%  adb   $v  variables  (Currently no variables are set)   0t1234>p   $v  variables  p = 02322  (Variable values are displayed in octal)   <p=X  4d2  <p>Z   $v  variables  = 02322  p = 02322  Z = 02322  <p=D  1234  $q  sunryse% 

The < and > commands will also work on registers, to extract or modify their values. Thus <sp will get the contents of the current stack pointer register in the CPU.

Writing to the object and core files

adb is often used to modify the contents of a program or even the running kernel. This means writing into the object file or the core file, changing some of the values.

The normal mode of operation is viewing: You can look, but you can't touch. By adding the -w flag to the startup parameters for adb , you can use the write commands. These are essentially modifiers to the two display commands we saw before, which look at either the object file or the core file.

Using the ? command, we can modify four consecutive bytes in the object file by using a W command with it. The bytes need not be full-word aligned. Here's an example that demonstrates this command.

Figure 8-3 Modifying the contents of a file via adb
 sunryse%  adb -w memofile -   123?X  0x123:          20746f20  123?W 100  0x123:          0x20746f20      =       0x100  123?X  0x123:          100  $q  sunryse% 

This will write the value 100 (hex) into the four bytes starting at address 0x123 in the object file. Similarly, if we use a lowercase w command, we will write two bytes.

By use of / , modifications can be made to the core or memory file. (The above example did not have a specified core file.)

If you start out in read-only mode and decide that you really want to make some changes, the $W command will reopen the files as if you had started adb with the -w flag.

Note

Modifications to the object file and core file via adb are made immediately. If you change your mind about a modification, you will need to perform a second write command to put the original value back before any real damage is done.


Address map

The $m command will display the current set of addresses that adb thinks are valid. Just as your program, or the kernel, has sections of real code or data, adb keeps track of which areas of memory have pieces of the program or actual values in them. The map displayed by the $m command identifies what address ranges are considered "known" for each of the two files ” object file and core file ” along with some information about how adb will actually locate the correct place. In general, this is only useful when looking at user programs; it helps track down segmentation violations and shows where dynamic libraries have been mapped in.

Interactive debugging sessions (process control)

When discussing UNIX system crash dump analysis, it is easy to forget that adb is a general-purpose debugger that can be used interactively with running programs. When adb is used as an interactive debugger, there are a number of colon ( : ) commands to use for process and program control. These same commands can be used with kadb, the kernel absolute debugger, when working with the running kernel.

One of the primary uses for the colon commands is to set and remove breakpoints. Breakpoints are special instructions inserted into the code that cause the program (the kernel or a user utility) to stop and transfer control to the debugger. When a breakpoint is reached, program execution is frozen, allowing you to examine or change memory, look at registers, and even change the code if you desire .

The following breakpoint commands are available:

address :b

Sets a breakpoint at address

$b

Displays all the breakpoints currently set up

address :d

Deletes a breakpoint at the address

:z

Zaps (deletes) all the breakpoints

Once a breakpoint is reached, the following process execution commands can be used to interactively control program execution:

:r

Runs the program (starts or restarts program execution)

:c

Continues execution

:s

Steps, executing only one instruction

:e

Steps, treating called routines as one enormous instruction

:u

Continues, stopping immediately after the next function call

We will be using some of these commands later on in another chapter.



PANIC. UNIX System Crash Dump Analysis Handbook
PANIC! UNIX System Crash Dump Analysis Handbook (Bk/CD-ROM)
ISBN: 0131493868
EAN: 2147483647
Year: 1994
Pages: 289
Authors: Chris Drake

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net