MAVSDK icon indicating copy to clipboard operation
MAVSDK copied to clipboard

vscode - debug: step into MAVSDK functions

Open ygratz opened this issue 1 year ago • 7 comments

Hi, I'm using VSCode to build and debug takeoff_and_land example. I opened VSCode for the MAVSDK (>MAVSDK\code .) and build the library using CMake. And then opened another VSCode for the takeoff_and_land example build (using CMake) and debug it. It works ok. I open SITL and I manage to connect to the copter and see the cmds work. However - I do not manage to step-into any of the MAVSDK library functions. For example: action.takeoff(); it doesn't step-into the function, rather it passes it.

What shall I do in order to be able to step-into the library functions? Thanks

ygratz avatar May 21 '23 13:05 ygratz

I don't know VSCode well but one thing to check is that you're using the debug build, and not release.

julianoes avatar May 21 '23 21:05 julianoes

Yes, I'm using the debug build

ygratz avatar May 22 '23 07:05 ygratz

Ok, but is the library also debug build? Like did you build mavsdk in debug, or are you using the library installed from the deb packet? That one would be release.

julianoes avatar May 22 '23 08:05 julianoes

I did build the mavsdk in debug mode. Also the example.

ygratz avatar May 22 '23 08:05 ygratz

I'm using mavsdk with fetchContent. If you add a breakpoint into the mavsdk function it stops there and you can step from there.

tlapik123 avatar May 22 '23 13:05 tlapik123

tlapik123 hi, can you be more specific on how you use the fetchContent?

ygratz avatar Jun 05 '23 06:06 ygratz

tlapik123 hi, can you be more specific on how you use the fetchContent?

Sure! Here is the code.

include(FetchContent)

set(PACKAGE_NAME mavsdk)

FetchContent_Declare(
    ${PACKAGE_NAME}
    GIT_REPOSITORY https://github.com/mavlink/MAVSDK.git
    GIT_TAG 3cd9aa992b8defe9687db3a6b71964363cd0f63b
)

FetchContent_GetProperties(${PACKAGE_NAME})
if(NOT ${PACKAGE_NAME}_POPULATED)
    FetchContent_Populate(${PACKAGE_NAME})

    add_subdirectory(${${PACKAGE_NAME}_SOURCE_DIR} ${${PACKAGE_NAME}_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

You can use the latest commit instead of commit provided.

You can include this in your CMakeLists.txt directly or you can create a separate .cmake file somewhere and include it with include(<relative path to .cmake file>)

Then in the CMakeLists.txt you need to link against it.

# link against mavsdk
target_link_libraries(<your target here>
    PRIVATE mavsdk
)

tlapik123 avatar Jun 05 '23 09:06 tlapik123