summaryrefslogtreecommitdiff
path: root/src/ToolBox/SOS/lldbplugin/setclrpathcommand.cpp
blob: 220830667180970521ece8508ee1cc46ac262270 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#include "sosplugin.h"
#include <dlfcn.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <limits.h>

class setclrpathCommand : public lldb::SBCommandPluginInterface
{
public:
    setclrpathCommand()
    {
    }

    virtual bool
    DoExecute (lldb::SBDebugger debugger,
               char** arguments,
               lldb::SBCommandReturnObject &result)
    {
        if (arguments[0] == NULL)
        {
            result.Printf("Load path for sos/dac/dbi: '%s'\n", g_coreclrDirectory == NULL ? "<none>" : g_coreclrDirectory);
        }
        else {
            if (g_coreclrDirectory != NULL)
            {
                free(g_coreclrDirectory);
            }

            std::string path(arguments[0]);
            if (path[path.length() - 1] != '/')
            {
                path.append("/");
            }

            g_coreclrDirectory = strdup(path.c_str());
            result.Printf("Set load path for sos/dac/dbi to '%s'\n", g_coreclrDirectory);
        }
        return result.Succeeded();
    }
};

bool
setclrpathCommandInitialize(lldb::SBDebugger debugger)
{
    lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter();
    lldb::SBCommand command = interpreter.AddCommand("setclrpath", new setclrpathCommand(), "Set the path to load coreclr sos/dac/dbi files. setclrpath <path>");
    return true;
}