简体   繁体   English

Visual Studio调试器扩展获取用户设置

[英]Visual Studio Debugger Extension get user settings

I'm writing a visual studio extension based on the Concord Samples Hello World project. 我正在根据Concord Samples Hello World项目编写一个Visual Studio扩展。 The goal is to let the user filter out stack frames by setting a list of search strings. 目的是让用户通过设置搜索字符串列表来筛选出堆栈帧。 If any of the search strings are in a stack frame, it is omitted. 如果任何搜索字符串在堆栈框中,则将其省略。

I've got the filter working for a hardcoded list. 我已经将过滤器用于硬编码列表。 That needs to be in a non-package-based dll project in order for the debugger to pick it up. 为了使调试器能够接收它,它必须位于基于非软件包的dll项目中。 And I have a vsix project that references that dll with an OptionPageGrid to accept the list of strings. 我有一个vsix项目,该文件使用OptionPageGrid引用该dll来接受字符串列表。 But I can't for the life of me find a way to connect them. 但是我无法终生找到联系他们的方法。

On the debugger side, my code looks something like this: 在调试器方面,我的代码如下所示:

    DkmStackWalkFrame[] IDkmCallStackFilter.FilterNextFrame(DkmStackContext stackContext, DkmStackWalkFrame input)
    {
        if (input == null) // null input frame indicates the end of the call stack. This sample does nothing on end-of-stack.
            return null;
        if (input.InstructionAddress == null) // error case
            return new[] { input };

        DkmWorkList workList = DkmWorkList.Create(null);
        DkmLanguage language = input.Process.EngineSettings.GetLanguage(new DkmCompilerId());
        DkmInspectionContext inspection = DkmInspectionContext.Create(stackContext.InspectionSession, input.RuntimeInstance, input.Thread, 1000,
            DkmEvaluationFlags.None, DkmFuncEvalFlags.None, 10, language, null);

        string frameName = "";
        inspection.GetFrameName(workList, input, DkmVariableInfoFlags.None, result => GotFrameName(result, out frameName));

        workList.Execute();

        CallstackCollapserDataItem dataItem = CallstackCollapserDataItem.GetInstance(stackContext);

        bool omitFrame = false;
        foreach (string filterString in dataItem.FilterStrings)
        {
            if (frameName.Contains(filterString))
            {
                omitFrame = true;
            }
        }

The CallstackCollapserDataItem is where I theoretically need to retrieve the strings from user settings. 理论上,CallstackCollapserDataItem是我从用户设置中检索字符串的地方。 But I don't have access to any services/packages in order to eg ask for WritableSettingsStore, like in You've Been Haacked's Example . 但是我无权访问任何服务/软件包,例如,请求WritableSettingsStore,就像You've Hahabed的Example中一样 Nor can I get my OptionPageGrid, like in the MSDN Options Example . 我也无法像MSDN Options Example中那样获得OptionPageGrid。

The other thing I tried was based on this StackOverflow question . 我尝试的另一件事是基于这个StackOverflow问题 I overrode the LoadSettingsFromStorage function of my OptionPageGrid and attempted to set a static variable on a public class in the dll project. 我覆盖了OptionPageGrid的LoadSettingsFromStorage函数,并尝试在dll项目的公共类上设置静态变量。 But if that code existed in the LoadSettingsFromStorage function at all, the settings failed to load without even entering the function. 但是,如果该代码完全存在于LoadSettingsFromStorage函数中,则即使不进入该函数也无法加载设置。 Which felt like voodoo to me. 这对我来说就像伏都教。 Comment out the line that sets the variable, the breakpoint hits normally, the settings load normally. 注释掉设置变量的行,断点正常,设置正常加载。 Restore it, and the function isn't even entered. 恢复它,甚至没有输入该功能。

I'm at a loss. 我很茫然。 I really just want to pass a string into my Concord extension, and I really don't care how. 我真的只想将字符串传递到我的Concord扩展名中,而且我真的不在乎如何。

Ok, apparently all I needed to do was post the question here for me to figure out the last little pieces. 好的,显然我要做的就是在这里发布问题,以便我找出最后的小片段。 In my CallstackCollapserDataItem : DkmDataItem class, I added the following code: 在我的CallstackCollapserDataItem:DkmDataItem类中,添加了以下代码:

    private CallstackCollapserDataItem()
    {
        string registryRoot = DkmGlobalSettings.RegistryRoot;
        string propertyPath = "vsix\\CallstackCollapserOptionPageGrid";
        string fullKey = "HKEY_CURRENT_USER\\" + registryRoot + "\\ApplicationPrivateSettings\\" + propertyPath;
        string savedStringSetting = (string)Registry.GetValue(fullKey, "SearchStrings", "");

        string semicolonSeparatedStrings = "";
        // The setting resembles "1*System String*Foo;Bar"
        if (savedStringSetting != null && savedStringSetting.Length > 0 && savedStringSetting.Split('*').Length == 3)
        {
            semicolonSeparatedStrings = savedStringSetting.Split('*')[2];
        }
    }

vsix is the assembly in which CallstackCollapserOptionPageGrid is a DialogPage, and SearchStrings is its public property that's saved out of the options menu. vsix是程序集,其中CallstackCollapserOptionPageGrid是DialogPage,而SearchStrings是其公共属性,该属性保存在选项菜单之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM