Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptScriptGroup.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- RenderScriptScriptGroup.cpp ---------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "lldb/Breakpoint/StoppointCallbackContext.h"
10
#include "lldb/Core/Debugger.h"
11
#include "lldb/Core/PluginManager.h"
12
#include "lldb/Interpreter/CommandInterpreter.h"
13
#include "lldb/Interpreter/CommandObjectMultiword.h"
14
#include "lldb/Interpreter/CommandReturnObject.h"
15
#include "lldb/Interpreter/Options.h"
16
#include "lldb/Symbol/Symbol.h"
17
#include "lldb/Symbol/Type.h"
18
#include "lldb/Symbol/VariableList.h"
19
#include "lldb/Target/Process.h"
20
#include "lldb/Target/Target.h"
21
#include "lldb/Utility/Args.h"
22
#include "lldb/Utility/ConstString.h"
23
#include "lldb/Utility/Log.h"
24
#include "lldb/Utility/Status.h"
25
26
#include "RenderScriptRuntime.h"
27
#include "RenderScriptScriptGroup.h"
28
29
using namespace lldb;
30
using namespace lldb_private;
31
using namespace lldb_renderscript;
32
33
class CommandObjectRenderScriptScriptGroupBreakpointSet
34
    : public CommandObjectParsed {
35
public:
36
  CommandObjectRenderScriptScriptGroupBreakpointSet(
37
      CommandInterpreter &interpreter)
38
      : CommandObjectParsed(
39
            interpreter, "renderscript scriptgroup breakpoint set",
40
            "Place a breakpoint on all kernels forming a script group.",
41
            "renderscript scriptgroup breakpoint set <group_name>",
42
6.21k
            eCommandRequiresProcess | eCommandProcessMustBeLaunched) {
43
6.21k
    CommandArgumentData name_arg{eArgTypeName, eArgRepeatPlus};
44
6.21k
    m_arguments.push_back({name_arg});
45
6.21k
  }
46
47
6.20k
  ~CommandObjectRenderScriptScriptGroupBreakpointSet() override = default;
48
49
0
  bool DoExecute(Args &command, CommandReturnObject &result) override {
50
0
    Stream &stream = result.GetOutputStream();
51
0
    RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>(
52
0
        m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(
53
0
            eLanguageTypeExtRenderScript));
54
0
    assert(runtime);
55
0
    auto &target = m_exe_ctx.GetTargetSP();
56
0
    bool stop_on_all = false;
57
0
    const llvm::StringRef long_stop_all("--stop-on-all"), short_stop_all("-a");
58
0
    std::vector<ConstString> sites;
59
0
    sites.reserve(command.GetArgumentCount());
60
0
    for (size_t i = 0; i < command.GetArgumentCount(); ++i) {
61
0
      const auto arg = command.GetArgumentAtIndex(i);
62
0
      if (long_stop_all == arg || short_stop_all == arg)
63
0
        stop_on_all = true;
64
0
      else
65
0
        sites.push_back(ConstString(arg));
66
0
    }
67
0
    for (const auto &name : sites) {
68
0
      runtime->PlaceBreakpointOnScriptGroup(target, stream, name, stop_on_all);
69
0
    }
70
0
    result.SetStatus(eReturnStatusSuccessFinishResult);
71
0
    return true;
72
0
  }
73
};
74
75
class CommandObjectRenderScriptScriptGroupBreakpoint
76
    : public CommandObjectMultiword {
77
public:
78
  CommandObjectRenderScriptScriptGroupBreakpoint(
79
      CommandInterpreter &interpreter)
80
      : CommandObjectMultiword(
81
            interpreter, "renderscript scriptgroup breakpoint",
82
            "Renderscript scriptgroup breakpoint interaction.",
83
            "renderscript scriptgroup breakpoint set [--stop-on-all/-a]"
84
            "<scriptgroup name> ...",
85
6.21k
            eCommandRequiresProcess | eCommandProcessMustBeLaunched) {
86
6.21k
    LoadSubCommand(
87
6.21k
        "set",
88
6.21k
        CommandObjectSP(new CommandObjectRenderScriptScriptGroupBreakpointSet(
89
6.21k
            interpreter)));
90
6.21k
  }
91
92
6.20k
  ~CommandObjectRenderScriptScriptGroupBreakpoint() override = default;
93
};
94
95
class CommandObjectRenderScriptScriptGroupList : public CommandObjectParsed {
96
public:
97
  CommandObjectRenderScriptScriptGroupList(CommandInterpreter &interpreter)
98
      : CommandObjectParsed(interpreter, "renderscript scriptgroup list",
99
                            "List all currently discovered script groups.",
100
                            "renderscript scriptgroup list",
101
                            eCommandRequiresProcess |
102
6.21k
                                eCommandProcessMustBeLaunched) {}
103
104
6.20k
  ~CommandObjectRenderScriptScriptGroupList() override = default;
105
106
0
  bool DoExecute(Args &command, CommandReturnObject &result) override {
107
0
    Stream &stream = result.GetOutputStream();
108
0
    RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>(
109
0
        m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(
110
0
            eLanguageTypeExtRenderScript));
111
0
    assert(runtime);
112
0
    const RSScriptGroupList &groups = runtime->GetScriptGroups();
113
    // print script group count
114
0
    stream.Printf("%" PRIu64 " script %s", uint64_t(groups.size()),
115
0
                  (groups.size() == 1) ? "group" : "groups");
116
0
    stream.EOL();
117
    // print script group details
118
0
    stream.IndentMore();
119
0
    for (const RSScriptGroupDescriptorSP &g : groups) {
120
0
      if (g) {
121
0
        stream.Indent();
122
        // script group name
123
0
        stream.Printf("%s", g->m_name.AsCString());
124
0
        stream.EOL();
125
        // print out the kernels
126
0
        stream.IndentMore();
127
0
        for (const auto &k : g->m_kernels) {
128
0
          stream.Indent();
129
0
          stream.Printf(". %s", k.m_name.AsCString());
130
0
          stream.EOL();
131
0
        }
132
0
        stream.IndentLess();
133
0
      }
134
0
    }
135
0
    stream.IndentLess();
136
0
    result.SetStatus(eReturnStatusSuccessFinishResult);
137
0
    return true;
138
0
  }
139
};
140
141
class CommandObjectRenderScriptScriptGroup : public CommandObjectMultiword {
142
public:
143
  CommandObjectRenderScriptScriptGroup(CommandInterpreter &interpreter)
144
      : CommandObjectMultiword(interpreter, "renderscript scriptgroup",
145
                               "Command set for interacting with scriptgroups.",
146
                               nullptr, eCommandRequiresProcess |
147
6.21k
                                            eCommandProcessMustBeLaunched) {
148
6.21k
    LoadSubCommand(
149
6.21k
        "breakpoint",
150
6.21k
        CommandObjectSP(
151
6.21k
            new CommandObjectRenderScriptScriptGroupBreakpoint(interpreter)));
152
6.21k
    LoadSubCommand(
153
6.21k
        "list", CommandObjectSP(
154
6.21k
                    new CommandObjectRenderScriptScriptGroupList(interpreter)));
155
6.21k
  }
156
157
6.20k
  ~CommandObjectRenderScriptScriptGroup() override = default;
158
};
159
160
lldb::CommandObjectSP NewCommandObjectRenderScriptScriptGroup(
161
6.21k
    lldb_private::CommandInterpreter &interpreter) {
162
6.21k
  return CommandObjectSP(new CommandObjectRenderScriptScriptGroup(interpreter));
163
6.21k
}