To invoke a function repeatedly in GDB using the call command

Source: Internet
Author: User

GDB is often used for branch coverage testing of functions in white-box testing, but it is difficult to trigger test object functions and the test is inefficient.

Suppose the test function fun1 has 10 branches. Each time you enter FUN1, you need to set 10 variables.

In general, it is necessary to operate 10 * 10 = 100 times in gdb to overwrite the branch.


After finding, there is a method in gdb that repeats the function and overwrites the branch with 10+10 = 20 times.


GdB Use steps:

1) First break point to the function

The following functions are available:

int Webprc_cmmenu_lchk (web_cmmenu_lan_path_chk_status *result, int filetype,cm_common_info *cominf, WEB_FLAG_TYPE Type, char *errmsg)


2) for the first time, manually enter the function

GDB will display the following msg:

Breakpoint 2, Webprc_cmmenu_lchk (result=0x1006cc8c, filetype=60, cominf=0x48197008, type=0 ' \000 ',    errmsg= 0x10087f30 "\302\302\302\302\302\302" ...) At webcmmenu.c:212212         Webprc_lock (web_sem_lock);(gdb) n213         result->status.status.size = sizeof (web_ Cmmenu_lan_path_chk_status);   (gdb) n214         result->run_status = websts_cmmenu1_lanpatch_chk;                     


In the first two lines, the values of each parameter are shown when entering Webprc_cmmenu_lchk:

<pre>

result = 0x1006cc8c

filetype = 60

cominf=0x48197008

Type=0

ErrMsg = 0X10087F30

</pre>

3) To continue execution, do not exit the function when it reaches the end of the function "}"!

Execute the following command in GDB:

Call Webprc_cmmenu_lchk (result=0x1006cc8c, filetype=60, cominf=0x48197008, TYPE=0,ERRMSG=0X10087F30)


GDB will output the following log:

The program being debugged stopped and a function called from GDB. Evaluation of the expression containing the function (WEBPRC_CMMENU_LCHK) is to be abandoned. When the function was done executing, GDB would silently stop.

This means that the WEBPRC_CMMENU_LCHK function is re-executed, and the entry parameter is the same as the last execution.


Principle:

The call command in GDB is often used to assign values to strings, most of which are called System library functions.

When you invoke a function in a project, you can naturally call the function repeatedly, as long as you determine the state of the register when the function is entered.


To invoke a function repeatedly in GDB using the call command

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.