在调试器中从DLL查看pimpl [英] Viewing a pimpl from DLL in debugger

查看:129
本文介绍了在调试器中从DLL查看pimpl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pimpl惯用法来隐藏接口的实现细节,以便可以对ABI进行某种程度的保护.我不太了解MS的来龙去脉...在我的大部分开发生涯中都使用Linux.

I am using the pimpl idiom to hide the implementation details of an interface so that I can have some measure of ABI protection. I'm not that well versed on the ins and outs of MS...using Linux for most of my development career.

我无法从调试器检查窗口查看pimpl的内部.我的类型仅扩展到impl的原始指针(它使用智能指针).我尝试导出符号,但这似乎不起作用.我想我实际上要查看的符号没有被导入或什么东西.

I'm unable to view the insides of the pimpl from the debugger inspection window. My types expand only so far as the raw pointer to impl (it uses a smart pointer). I've tried exporting the symbols, but that doesn't seem to work. I suppose the symbols I'm actually trying to view are not being imported or something.

我该如何补救?可视化工具可以调用函数吗?

How do I remedy this? Can visualizers call functions perhaps?

编辑-也许我把导出的东西弄糊涂了.

Edit -- perhaps I confused people with the export thing.

我正在尝试:

object.h:

struct EXPORT object {
    struct EXPORT impl;
    impl * pimpl;
};

object.cpp

object.cpp

struct EXPORT object::impl {
    char member;
};

我认为解决问题的唯一方法是将impls放在库的调试版本中包含的标头中.希望有更好的解决方案.

The only way I can think to solve the problem is to put the impls in headers that are included in debug versions of the library. Hoping for a better solution.

推荐答案

我无法使用此设置复制它:

I could not replicate it with this setup:

CMakeLists.txt

CMakeLists.txt

cmake_minimum_required(VERSION 3.8.0)

project(test)
set(DLL_SRCS thing.cpp)
set(DLL_HDRS thing.h)
add_library(Thing SHARED ${DLL_SRCS} ${DLL_HDRS})

set(Headers_dir ${CMAKE_CURRENT_BINARY_DIR}/dll_public_headers)
configure_file(${DLL_HDRS} ${Headers_dir} COPYONLY)

set(APP_SRCS main.cpp)

add_executable(App ${APP_SRCS})

target_link_libraries(APP Thing)
include_directories(${Headers_dir})

thing.h

#pragma once

struct thing
{
private:
  struct Private;
public:
  thing();
  Private * impl
};

thing.cpp

thing.cpp

#include "thing.h"

struct thing::Private
{
  char member;
}

thing::thing()
{
  impl = new Private;
  impl->member = 'a';
}

main.cpp

#include "thing.h"

int main(int argc, char * argv[])
{
  thing thing_from_dll;
  return 0;
}

如果您无法正常运行,我敦促您提供类似的 mcve .我对此不那么感兴趣,所以不用担心.我仍然会帮助您.

If you don't get it working, I would urge you to provide a similar mcve. I'm not that anal about this, so don't worry. I will still help you.

这在Visual Studio 2017上有效.我在返回0处设置了一个断点,可以看到该成员的值为'a'.

This worked on visual studio 2017. I placed a breakpoint on return 0 and could see that member had the value of 'a'.

我可以认为您的设置中可能唯一缺少的是调试器的源文件.也许它可以加载调试数据库,但实际上并没有在定义了私有实现的位置找到文件.看起来

The only thing I can think that might be missing from your setup are the source files for the debugger. Maybe it can load your debugging database, but doesn't actually find the files where you have defined what your private implementation is. Look here for more details on that.

这篇关于在调试器中从DLL查看pimpl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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