]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/ScriptInterpreter.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / ScriptInterpreter.cpp
1 //===-- ScriptInterpreter.cpp -----------------------------------*- C++ -*-===//
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/Interpreter/ScriptInterpreter.h"
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string>
14
15 #include "lldb/Host/PseudoTerminal.h"
16 #include "lldb/Interpreter/CommandReturnObject.h"
17 #include "lldb/Utility/Status.h"
18 #include "lldb/Utility/Stream.h"
19 #include "lldb/Utility/StringList.h"
20
21 using namespace lldb;
22 using namespace lldb_private;
23
24 ScriptInterpreter::ScriptInterpreter(Debugger &debugger,
25                                      lldb::ScriptLanguage script_lang)
26     : m_debugger(debugger), m_script_lang(script_lang) {}
27
28 ScriptInterpreter::~ScriptInterpreter() {}
29
30 void ScriptInterpreter::CollectDataForBreakpointCommandCallback(
31     std::vector<BreakpointOptions *> &bp_options_vec,
32     CommandReturnObject &result) {
33   result.SetStatus(eReturnStatusFailed);
34   result.AppendError(
35       "ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
36 }
37
38 void ScriptInterpreter::CollectDataForWatchpointCommandCallback(
39     WatchpointOptions *bp_options, CommandReturnObject &result) {
40   result.SetStatus(eReturnStatusFailed);
41   result.AppendError(
42       "ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
43 }
44
45 std::string ScriptInterpreter::LanguageToString(lldb::ScriptLanguage language) {
46   std::string return_value;
47
48   switch (language) {
49   case eScriptLanguageNone:
50     return_value = "None";
51     break;
52   case eScriptLanguagePython:
53     return_value = "Python";
54     break;
55   case eScriptLanguageUnknown:
56     return_value = "Unknown";
57     break;
58   }
59
60   return return_value;
61 }
62
63 lldb::ScriptLanguage
64 ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
65   if (language.equals_lower(LanguageToString(eScriptLanguageNone)))
66     return eScriptLanguageNone;
67   if (language.equals_lower(LanguageToString(eScriptLanguagePython)))
68     return eScriptLanguagePython;
69   return eScriptLanguageUnknown;
70 }
71
72 Status ScriptInterpreter::SetBreakpointCommandCallback(
73     std::vector<BreakpointOptions *> &bp_options_vec,
74     const char *callback_text) {
75   Status return_error;
76   for (BreakpointOptions *bp_options : bp_options_vec) {
77     return_error = SetBreakpointCommandCallback(bp_options, callback_text);
78     if (return_error.Success())
79       break;
80   }
81   return return_error;
82 }
83
84 void ScriptInterpreter::SetBreakpointCommandCallbackFunction(
85     std::vector<BreakpointOptions *> &bp_options_vec,
86     const char *function_name) {
87   for (BreakpointOptions *bp_options : bp_options_vec) {
88     SetBreakpointCommandCallbackFunction(bp_options, function_name);
89   }
90 }
91
92 std::unique_ptr<ScriptInterpreterLocker>
93 ScriptInterpreter::AcquireInterpreterLock() {
94   return std::unique_ptr<ScriptInterpreterLocker>(
95       new ScriptInterpreterLocker());
96 }