UNIX System Management: SDB Command Usage-Program execution control

Source: Internet
Author: User
Keywords UNIX System Management program execution Control command usage
Tags basic command usage continue control debugger debugging display function

We say that the main purpose of program debugging is to observe variable changes. But if the program keeps running until it stops or fails, there will be no chance to observe any variables. Therefore, how to effectively control the execution of the statements in the program, so that when the appropriate time to pause, the debugger to display or set the value of some of the storage unit and then continue from where to stop, is the debugger should have a basic function. In this section we will specifically describe how to control the operation of the program.

The first problem with program execution control is to set breakpoints. A breakpoint is actually a line statement in a program. When a program executes to this statement, control returns repeatedly to SDB, providing the user with other actions, such as the opportunity to display variable values.

1. Setting and deleting breakpoints

There are more ways to set breakpoints in SDB. But basically a variant of the B command. For example, we can use the following statement to set a breakpoint on the first executable row of the main () function (a statement that is not a variable definition):

* MAIN:B

You can also set breakpoints directly with line numbers. For example, in Myprog.c, line 10th is the first executable statement in the main () function, and the same effect can be achieved by using the following command:

* 10b

Note that this is done myprog.c the current file.

If you enter directly:

* b

command, you can set the current line to be a breakpoint. However, if the current row is not an executable statement, then SDB sets a breakpoint at the first executable statement after the current row.

After you finish setting breakpoints, you can use the B command to understand which breakpoints are set in your program:

* B

0x80483f0 myprog.c:10 main+0x8

0x80483f7 myprog.c:11 main+0xf

0x8048407 Myprog.c:12 MAIN+0XLF

0x8048440 Myprog.c:9 Testinput

0x8048447 myprog.c:10 testinput+ 0x7

0x804482 myprog.c:13 testinput+ 0x42

To remove a breakpoint after it has been set, you can use the D command. As:

* MAIN:D

SDB will remove the breakpoint on the first executable line set in the main () function. If you use the D command directly, SDB lists all breakpoints one by one and asks the user if they want to delete them. The answer y breakpoint will be deleted. Use the D command to remove all breakpoints that are set in the program.

Start program running in 2.sdb

We can restart the program after setting the desired breakpoint. This can be used with the R command. As:

* R 111 2

Breakpoint Process 554 function main () in MYPROG.C

10:for (i=1;i<argc:i++)

*

SDB will stop at the first breakpoint in the main () function and display the statement for that line. R gives the two parameters passed to the executable program Myprog. So the above command is entered at the shell prompt:

$ Myrprog 111 2

is the same. The difference is that the execution of the program in the SDB will stop at the breakpoint.

If you enter only

* R

command, SDB to start using the parameters that were supplied to it when the debugger was last executed. If you want to restart the program without any parameters, you can use the

* R

Command。

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.