Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set break point at line number correctly in gdb?

Tags:

debugging

gdb

Refer the code below with line numbers with it.

1     void f(string& s){
...
          //some code
...
12        for(unsigned int i = 0; i <= end; i++){
13            unsigned int a = s[i] - 'a' + 1;
14            unsigned int b = s[end-i] - 'a' + 1;
15        }
16    }   

In gdb, I have to check the value of variable b. How do I set breakpoints here correctly. I know that breakpoint has to be after line 14. But, whenever I type line 15, b 15, it adds breakpoint at line 16. Can somebody please help ?

like image 674
Aditya Singh Rathore Avatar asked Nov 23 '25 07:11

Aditya Singh Rathore


1 Answers

I'm not entirely sure on the reason, but a similar thing happens in Visual Studio when setting breakpoints, which makes me think it's a commonplace thing.

My cheap way of getting past this would be adding a line after your equation that says something like:

b = b;

Then setting a breakpoint there

like image 160
user29451 Avatar answered Nov 24 '25 22:11

user29451



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!