Sublime Forum

SublimeGDB debugging C++: No source file named Main.cpp

#1

Hi.
I am having problems debugging C++ with sublimeGDB. It seems to be working if I compile a simple C++ hello world application from the commandline. But if I use CMake it says No source file named . I am trying to use the same compilerflags.


I compile from commandline using

gcc -g -Wno-psabi -Wno-unused-result -std=c++11 Main.cpp -o hello

In my CMakeLists file I have the same flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wno-psabi -Wno-unused-result -std=c++11")

If I run *file hello* I get *hello: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=023a9e0db2d619093487993e35c49047d75c5fac, for GNU/Linux 3.2.0, with debug_info, not stripped* for both files. So they should both be debuggable.

My .sublime-project file is like this

{
“folders”:
[
{
“path”: “.”
}
],
“build_systems”:
[
{
“name”: “CMake”,
“cmd”: ["./callcmake.sh"],
“working_dir”: “${folder:${file}}/CMakeLists”,
},
{
“name”: “imx”,
“cmd”: [“make”],
“working_dir”: “${folder:${file}}/CMakeLists/build/imx”,
},
{
“name”: “x86”,
“cmd”: [“make”],
“working_dir”: “${folder:${file}}/CMakeLists/build/x86”,
},
{
“name”: “unit”,
“cmd”: [“make”],
“working_dir”: “${folder:${file}}/CMakeLists/build/unit”,
},
{
“name”: “test”,
“cmd”: [“make”],
“working_dir”: “${folder:${file}}/CMakeLists/build/test”,
},
],
“settings”:
{
“sublimegdb_executables”:
{
“hello”:
{
“commandline”: “gdb -nx -readnow -fullname --interpreter=mi -args CMakeLists/build/x86/hello”,
“workingdir”: “/home/clausen/SVN/workspace/MM_HWP2_PU/Branches/FirstGo/”
},
“ZZZ”:
{
“commandline”: “gdb -nx -readnow -fullname --interpreter=mi -args CMakeLists/build/x86/ZZZ”,
“workingdir”: “/home/clausen/SVN/workspace/MM_HWP2_PU/Branches/FirstGo/”
},
}
}
}


And also here is the CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
project(Check)

message(STATUS “”)
message(STATUS " *** Building main project for x86_64 *** ")
message(STATUS “”)

if(DEFINED ENV{PROJECTROOT})
set(PROJECTROOT $ENV{PROJECTROOT})
message(STATUS “PROJECTROOT set to ${PROJECTROOT}”)
else()
set(PROJECTROOT SVN/main/Trunk/)
message(STATUS “Environment variable not defined. PROJECTROOT set to SVN/main/Trunk/”)
endif()

ADD_CUSTOM_TARGET(debug
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
)

ADD_CUSTOM_TARGET(release
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
)

SET(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -std=c++11 -g -Wno-psabi -Wno-unused-result”)
SET(CMAKE_EXE_LINKER_FLAGS “${CMAKE_EXE_LINKER_FLAGS}”)

set(SW_VERSION “1.2.3”)

include_directories(${PROJECTROOT}/System)
include_directories(${PROJECTROOT}/Stubs/somethingFake)

function(BUILD_STUB NAME)
file(GLOB SOURCE “${PROJECTROOT}/Stubs/${NAME}/*.cpp”)
add_library(${NAME} SHARED ${SOURCE})
endfunction()

function(BUILD_APPLICATION NAME)
file(GLOB SOURCE “${PROJECTROOT}/${NAME}/*.cpp”)
add_executable(${NAME} ${SOURCE})
foreach(f ${ARGN})
target_link_libraries(${NAME} ${f})
endforeach()
endfunction()

function(BUILD_LIBRARY NAME)
file(GLOB SOURCE “${PROJECTROOT}/${NAME}/*.cpp”)
add_library(${NAME} SHARED ${SOURCE})
foreach(f ${ARGN})
target_link_libraries(${NAME} ${f})
endforeach()
endfunction()

build_stub(somethingFake)
build_library(System)

build_application(UAH)
build_application(ZZZ)

0 Likes

#2

This is a bit out of my area of expertise, I’m sure someone more epxerienced will be of more help.

I think you might be missing a line of regex

“file_regex”:"^(|…[^:]):([0-9]):?([0-9])?:? (.)$",

between [cmd] and working [dir] this allows Sublime to get output from external operations, I think

(Better minds than mine will hopefully give you a better answer, also I’ve just copied and pasted my line of regex from my build file…)

0 Likes

#3

Thank you for your answer.
It seems that a couple of restarts was what it took to get it working.
I have no idea what went wrong, but now it works like a charm.
But anyway thank you for your effort.

0 Likes

#4

Awesome, shows what I know :wink:

0 Likes