summaryrefslogtreecommitdiff
path: root/src/ToolBox/SOS/lldbplugin/coreruncommand.cpp
blob: 9187906acd9d3f09c54abc2b93986fb4990f132a (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
// 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>

extern int corerun(const int argc, const char* argv[]);

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

    virtual bool
    DoExecute (lldb::SBDebugger debugger,
               char** arguments,
               lldb::SBCommandReturnObject &result)
    {
        if (arguments)
        {
            int argc = 0;
            char **argv = arguments;
            for (const char* arg = *arguments; arg; arg = *(++arguments))
            {
                ++argc;
            }
            int exitcode = corerun((const int)argc, (const char**)argv);
            if (exitcode != 0)
            {
                result.SetError("corerun failed");
            }
        }
        return result.Succeeded();
    }
};

bool
corerunCommandInitialize(lldb::SBDebugger debugger)
{
    lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter();
    lldb::SBCommand command = interpreter.AddCommand("corerun", new corerunCommand(), "Run a managed app inside the debugger. corerun <exe-path> <managed-program-path> <command-line-args>");
    return true;
}