简体   繁体   中英

Not able to set breakpoints in gdb

My C++ project folder structure is as shown below.

在此处输入图片说明

I am trying to debug the program using gdb in my linux machine. My main function is in g2o.cpp which is inside g2o_cli folder. I am able to put breakpoints in the files in this folder by

 break g2o.cpp:<line_number>

But I am not able to put breakpoints in the files in other folders, for example, a file optimizer.cpp in the 'core' folder. I tried giving the absolute path from my home directory

break ~/HOME/g2o/core/optimizer.cpp:<line_number>

but it is giving an error

  No source file named ~/HOME/g2o/core/optimizer.cpp

I also tried ../../core/optimizer.cpp instead of the absolute path. Still it did not work.

I saw a similar question here . But none of the possible reasons mentioned in the answer is applicable in my case. The file optimizer.cpp is not a shared library and the entire project was compiled using cmake.

How does gdb take folder paths? How can I give the relative folder path?

A dirty hack you can use on x86 is to use int3 . Just use the statement asm volatile ("int 3"); in the code where you want the breakpoint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM