使用 Visual Studio 的 Linux 支持调试库代码 [英] Debugging Library Code with Visual Studio's Linux support

查看:29
本文介绍了使用 Visual Studio 的 Linux 支持调试库代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 2017 的集成在适用于 Linux 的 Windows 子系统中本地构建和调试 CMake Linux 应用程序.

I'm using Visual Studio 2017's integration to build and debug a CMake Linux application locally in the Windows Subsystem for Linux.

运行应用程序时,Visual Studio 使用 ssh 连接到 localhost 来运行 cmake -DCMAKE_BUILD_TYPE="Debug" ..make,然后使用 gdbserver 来调试应用程序.这适用于我的应用程序自己的代码,包括断点和逐行调试.

When running the application, Visual Studio uses an ssh connection to localhost to run cmake -DCMAKE_BUILD_TYPE="Debug" .. and make, then uses gdbserver to debug the application. This works fine for my application's own code, including breakpoints and line-by-line debugging.

此应用程序链接到库文件 libhypro.so.17.09,它也是 CMake 项目的一部分.这个库也是在本地构建的(存储在我的 Windows 文件系统中,通过 /mnt/c/ 挂载在 Linux 中构建,就像主应用程序一样)在调试模式下.CMake 确实自动发现了这种依赖关系.

This application links to a library file, libhypro.so.17.09, which is also part of a CMake project. This library is also built locally (stored in my Windows file system, built within Linux through the /mnt/c/ mount, just as the main application) in debug mode. CMake did discover that dependency automatically.

我在调试对该库的调用时遇到问题.例如,如果我在调用库代码之前中断并选择Step Into,这就是我结束的地方:

I'm having trouble debugging my calls to this library. For example, if I break just before a call to library code and choose to Step Into, this is where I end up:

注意

  • 调用堆栈消失了,改为显示 [Unknown/Just-In-Timecompiled code]
  • 我处于一个未处理的异常中(我希望最终会遇到该异常,但肯定不会在 Step Into 之后立即发生)并且
  • 模块窗口显示没有可用的符号.
  • the Call Stack has disappeared, showing [Unknown/Just-In-Time compiled code] instead,
  • I'm inside an unhandled exception (which I'd expect to hit eventually, but certainly not immediately after a Step Into) and
  • the Modules window indicates that no symbols are available.

此外,我确实在库的代码中设置了断点,Visual Studio(正确地)断言断点当前不会被命中".此外,调试输出打印 Loaded '/mnt/c/Users/felix/git/hypro/build/libhypro.so.17.09'.无法找到或打开符号文件.

In addition, I did set a breakpoint in the library's code, and Visual Studio (correctly) asserts that "the breakpoint will not currently be hit". Also, Debug output prints Loaded '/mnt/c/Users/felix/git/hypro/build/libhypro.so.17.09'. Cannot find or open the symbol file.

我比较确定 libhypro.so.17.09 确实 包含调试符号,因为 nm -gC libhypro.so 打印 大量的输出.

I'm relatively certain that libhypro.so.17.09 does include debug symbols as nm -gC libhypro.so prints a lot of output.

我的情况似乎类似于 this question 但我没有手动指定库的路径,它是由CMake.

My case appears to be similar to this question but I'm not specifying the library's path manually, it's discovered by CMake.

为什么 gdb 以及 Visual Studio 无法调试库的代码?

Why are gdb and, in turn, Visual Studio failing to debug the library's code?

推荐答案

如果你在gdbserver模式下调试,默认,在项目中尝试切换到gdb模式属性/调试页面.

If you are debugging in gdbserver mode, the default, try switching to gdb mode in the project properties / debugging page.

基本上,gdbserver 模式是一个不错的想法,但从未完全交付.这是 VCLinux GitHub 站点上关于它的讨论.如您所见,一旦他们解决了控制台应用程序的问题,gdb 将成为默认调试模式.

Basically, gdbserver mode is a nice idea that never quite delivered. Here's one discussion about it on the VCLinux GitHub site. As you'll see, gdb will become the default debugging mode once they've fixed the problems with console applications.

这篇关于使用 Visual Studio 的 Linux 支持调试库代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆