简体   繁体   中英

GDB Breakpoints are inaccurrate on Mac

I have been using gdb on Mac recently but sometimes the breakpoints are wrong such that if I assign a breakpoint and run gdb sometimes skips the breakpoint or breaks on the wrong line. Can anyone help me out? I've tried to find the simplest case of the issue below.:

Project
|
+-- CMakeLists.txt
|    
+-- include
|    |  
|    +-- A.hpp
|
+-- src 
     |  
     +-- main.cpp

A.hpp

#pragma once

class A { 
public: 
   A(const char* t){};
}; 

main.cpp

1 #include<string>
2 #include"A.hpp"
3 int main(){ 
4   std::string s = "";
5   A a = "";
6   return 0;
7 }

CMakeLists.txt

1 cmake_minimum_required (VERSION 3.0)
2
3
4 file(GLOB SOURCES "src/*.cpp")
5 set(CMAKE_BUILD_TYPE Debug)
6 
7 add_executable(main ${SOURCES})
8
9 target_include_directories(main PUBLIC include)

If I try to set a breakpoint in main.cpp line 4 where the string is assigned and run main in gdb, it stops on line 5. I think that this happens when standard headers like are used. If I change line 4 to a simple assignment like int i = 0;, the breakpoint stops on line 4 as expected.

I Have:

Mac Version High Sierra 10.13.6

CMakeVersion: 3.12.0

GDB version: 8.0.1 (installed via homebrew)

Thanks for any help in advance.

gdb sometimes skips the breakpoint or breaks on the wrong line

In general, this happens when the code is built with optimizations.

I know you've selected CMAKE_BUILD_TYPE Debug , but perhaps that is still doing an optimized build for some reason?

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