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 conversionThe = 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. $ commandsOf 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:
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 searchingadb 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. Variablesadb 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 variablessunryse% 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 filesadb 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 adbsunryse% 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 mapThe $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:
Once a breakpoint is reached, the following process execution commands can be used to interactively control program execution:
We will be using some of these commands later on in another chapter. |