Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb,why "next" show each source line twice?

Tags:

c++

c

gdb

everyone,when use "next" instruction within gdb,i found each line of sourcecode display twice-----i am quite sure,these code are not in any loop.this is the phenomenon:

(gdb) frame
#0  ap_get_client_block (r=0x8560d48, 
    buffer=0xb68501b7 "<?xml version=\"1.0\" encoding=\"utf-8\"?><Root><OperCode>SMS101</OperCode><AppId>SMSMsgFilterReq</AppId><Req><UserMobile>13925237429</UserMobile><SendMsg>abc圲34¨圲23a露07\214圲21¢<237朲11?东215圲10°<214朲27¥応227露07\214正常,hao"..., bufsiz=81920) at http_filters.c:1540
1540        if (r->remaining < 0 || (!r->read_chunked && r->remaining == 0)) {
(gdb) n
1544        bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
(gdb) 
1545        if (bb == NULL) {
(gdb) 
1544        bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
(gdb) 
1545        if (bb == NULL) {

-----the line 1544,1545 are not in any loop,but they got repeated. May anybody enlighten me?

like image 905
basketballnewbie Avatar asked Jul 20 '12 09:07

basketballnewbie


People also ask

How to put break point in GDB?

Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main.

What is the GDB command that will show the address of the next instruction to execute when the current function reaches its one return statement?

It is often useful to do ' display/i $pc ' when stepping by machine instructions. This makes GDB automatically display the next instruction to be executed, each time your program stops.

What does print in GDB do?

The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages). expr is an expression (in the source language).

What command removes a breakpoint?

With the clear command you can delete breakpoints according to where they are in your program. With the delete command you can delete individual breakpoints, watchpoints, or catchpoints by specifying their breakpoint numbers.


1 Answers

What level of optimisation did you have when you compiled this?

Even a minimal level of optimisation can cause your debugger to jump around the source lines like crazy as the compiler inlines, reorders and generally plays with your code.

like image 60
Tom Tanner Avatar answered Nov 11 '22 04:11

Tom Tanner