reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
//===-- RenderScriptScriptGroup.cpp -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Symbol/Type.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"

#include "RenderScriptRuntime.h"
#include "RenderScriptScriptGroup.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_renderscript;

class CommandObjectRenderScriptScriptGroupBreakpointSet
    : public CommandObjectParsed {
public:
  CommandObjectRenderScriptScriptGroupBreakpointSet(
      CommandInterpreter &interpreter)
      : CommandObjectParsed(
            interpreter, "renderscript scriptgroup breakpoint set",
            "Place a breakpoint on all kernels forming a script group.",
            "renderscript scriptgroup breakpoint set <group_name>",
            eCommandRequiresProcess | eCommandProcessMustBeLaunched) {}

  ~CommandObjectRenderScriptScriptGroupBreakpointSet() override = default;

  bool DoExecute(Args &command, CommandReturnObject &result) override {
    Stream &stream = result.GetOutputStream();
    RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>(
        m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(
            eLanguageTypeExtRenderScript));
    assert(runtime);
    auto &target = m_exe_ctx.GetTargetSP();
    bool stop_on_all = false;
    const llvm::StringRef long_stop_all("--stop-on-all"), short_stop_all("-a");
    std::vector<ConstString> sites;
    sites.reserve(command.GetArgumentCount());
    for (size_t i = 0; i < command.GetArgumentCount(); ++i) {
      const auto arg = command.GetArgumentAtIndex(i);
      if (long_stop_all == arg || short_stop_all == arg)
        stop_on_all = true;
      else
        sites.push_back(ConstString(arg));
    }
    for (const auto &name : sites) {
      runtime->PlaceBreakpointOnScriptGroup(target, stream, name, stop_on_all);
    }
    result.SetStatus(eReturnStatusSuccessFinishResult);
    return true;
  }
};

class CommandObjectRenderScriptScriptGroupBreakpoint
    : public CommandObjectMultiword {
public:
  CommandObjectRenderScriptScriptGroupBreakpoint(
      CommandInterpreter &interpreter)
      : CommandObjectMultiword(
            interpreter, "renderscript scriptgroup breakpoint",
            "Renderscript scriptgroup breakpoint interaction.",
            "renderscript scriptgroup breakpoint set [--stop-on-all/-a]"
            "<scriptgroup name> ...",
            eCommandRequiresProcess | eCommandProcessMustBeLaunched) {
    LoadSubCommand(
        "set",
        CommandObjectSP(new CommandObjectRenderScriptScriptGroupBreakpointSet(
            interpreter)));
  }

  ~CommandObjectRenderScriptScriptGroupBreakpoint() override = default;
};

class CommandObjectRenderScriptScriptGroupList : public CommandObjectParsed {
public:
  CommandObjectRenderScriptScriptGroupList(CommandInterpreter &interpreter)
      : CommandObjectParsed(interpreter, "renderscript scriptgroup list",
                            "List all currently discovered script groups.",
                            "renderscript scriptgroup list",
                            eCommandRequiresProcess |
                                eCommandProcessMustBeLaunched) {}

  ~CommandObjectRenderScriptScriptGroupList() override = default;

  bool DoExecute(Args &command, CommandReturnObject &result) override {
    Stream &stream = result.GetOutputStream();
    RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>(
        m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(
            eLanguageTypeExtRenderScript));
    assert(runtime);
    const RSScriptGroupList &groups = runtime->GetScriptGroups();
    // print script group count
    stream.Printf("%" PRIu64 " script %s", uint64_t(groups.size()),
                  (groups.size() == 1) ? "group" : "groups");
    stream.EOL();
    // print script group details
    stream.IndentMore();
    for (const RSScriptGroupDescriptorSP &g : groups) {
      if (g) {
        stream.Indent();
        // script group name
        stream.Printf("%s", g->m_name.AsCString());
        stream.EOL();
        // print out the kernels
        stream.IndentMore();
        for (const auto &k : g->m_kernels) {
          stream.Indent();
          stream.Printf(". %s", k.m_name.AsCString());
          stream.EOL();
        }
        stream.IndentLess();
      }
    }
    stream.IndentLess();
    result.SetStatus(eReturnStatusSuccessFinishResult);
    return true;
  }
};

class CommandObjectRenderScriptScriptGroup : public CommandObjectMultiword {
public:
  CommandObjectRenderScriptScriptGroup(CommandInterpreter &interpreter)
      : CommandObjectMultiword(interpreter, "renderscript scriptgroup",
                               "Command set for interacting with scriptgroups.",
                               nullptr, eCommandRequiresProcess |
                                            eCommandProcessMustBeLaunched) {
    LoadSubCommand(
        "breakpoint",
        CommandObjectSP(
            new CommandObjectRenderScriptScriptGroupBreakpoint(interpreter)));
    LoadSubCommand(
        "list", CommandObjectSP(
                    new CommandObjectRenderScriptScriptGroupList(interpreter)));
  }

  ~CommandObjectRenderScriptScriptGroup() override = default;
};

lldb::CommandObjectSP NewCommandObjectRenderScriptScriptGroup(
    lldb_private::CommandInterpreter &interpreter) {
  return CommandObjectSP(new CommandObjectRenderScriptScriptGroup(interpreter));
}