The following sections explain how to start the adb debugging program from a variety of files, use the adb prompt, use shell commands from within the adb program, and stop the adb program.
You can debug any executable C or assembly language program file by entering a command line of the form:
adb FileName
where FileName is the name of the executable program file to be debugged. The adb program opens the file and prepares its text (instructions) and data for subsequent debugging. For example, the command:
adb sample
prepares the program named sample for examination and operation.
Once started, the adb debug program places the cursor on a new line and waits for you to type commands.
If you start the adb debug program with the name of a nonexistent or incorrectly formatted file, the adb program first displays an error message and then waits for commands. For example, if you start the adb program with the command:
adb sample
and the sample file does not exist, the adb program displays the message:
sample: no such file or directory.
You can start the adb debug program without a file name. In this case, the adb program searches for the default a.out file in your current working directory and prepares it for debugging. Thus, the command:
adb
adb a.out
The adb program starts with the a.out file and waits for a command. If the a.out file does not exist, the adb program starts without a file and does not display an error message.
You can use the adb debug program to examine the core image files of programs that caused fatal system errors. Core image files maintain a record of the contents of the CPU registers, stack, and memory areas of your program at the time of the error. Therefore, core image files provide a way to determine the cause of an error.
To examine a core image file with its corresponding program, you must give the name of both the core and the program file. The command line has the form:
adb ProgramFile CoreFile
where ProgramFile is the file name of the program that caused the error, and CoreFile is the file name of the core image file generated by the system. The adb program then uses information from both files to provide responses to your commands.
If you do not give the filename of the core image file, the adb program searches for the default core file, named core, in your current working directory. If such a file is found, the adb program determines whether the core file belongs to the ProgramFile. If so, the adb program uses it. Otherwise, the adb program discards the core file by giving an appropriate error message.
You can use the adb program to examine data files by giving the name of the data file in place of the program or core file. For example, to examine a data file named outdata, enter:
adb outdata
The adb program opens a file called outdata and lets you examine its contents. This method of examining files is useful if the file contains non-ASCII data. The adb program provides a way to look at the contents of the file in a variety of formats and structures. The adb command may display a warning when you give the name of a non-ASCII data file in place of a program file. This usually happens when the content of the data file is similar to a program file. Like core files, data files cannot be executed.
If you open a program or data file with the -w flag of the adb command, you can make changes and corrections to the file. For example, the command:
adb -w sample
opens the program file sample for writing. You can then use adb commands to examine and modify this file. The -w flag causes the adb program to create a given file if it does not already exist. The option also lets you write directly to memory after running the given program.
After you have started the adb program you can redefine your prompt with the $P subcommand.
To change the [adb:scat]>> prompt to Enter a debug command--->, enter:
$P"Enter a debug command--->"
The quotes are not necessary when redefining the new prompt from the adb command line.
You can run shell commands without leaving the adb program by using the adb escape command (!) (exclamation point). The escape command has the form:
In this format Command is the shell command you want to run. You must provide any required arguments with the command. The adb program passes this command to the system shell that calls it. When the command is finished, the shell returns control to the adb program. For example, to display the date, enter the following command:
! date
The system displays the date and restores control to the adb program.
You can stop the adb program and return to the system shell by using the $q or $Q subcommands. You can also stop the adb program by typing the Ctrl-D key sequence. You cannot stop the adb program by pressing the Interrupt or Quit keys. These keys cause adb to wait for a new command.
Displaying and Manipulating the Source File with the adb Program
Customizing the adb Debug Program