LLDB  mainline
ScriptInterpreter.cpp
Go to the documentation of this file.
1 //===-- ScriptInterpreter.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 
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string>
14 
17 #include "lldb/Utility/Status.h"
18 #include "lldb/Utility/Stream.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 
29 
31  std::vector<BreakpointOptions *> &bp_options_vec,
32  CommandReturnObject &result) {
34  result.AppendError(
35  "This script interpreter does not support breakpoint callbacks.");
36 }
37 
39  WatchpointOptions *bp_options, CommandReturnObject &result) {
41  result.AppendError(
42  "This script interpreter does not support watchpoint callbacks.");
43 }
44 
46  const char *filename, bool init_session, lldb_private::Status &error,
47  StructuredData::ObjectSP *module_sp) {
48  error.SetErrorString(
49  "This script interpreter does not support importing modules.");
50  return false;
51 }
52 
54  switch (language) {
56  return "None";
58  return "Python";
59  case eScriptLanguageLua:
60  return "Lua";
62  return "Unknown";
63  }
64  llvm_unreachable("Unhandled ScriptInterpreter!");
65 }
66 
68 ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
69  if (language.equals_lower(LanguageToString(eScriptLanguageNone)))
70  return eScriptLanguageNone;
71  if (language.equals_lower(LanguageToString(eScriptLanguagePython)))
72  return eScriptLanguagePython;
73  if (language.equals_lower(LanguageToString(eScriptLanguageLua)))
74  return eScriptLanguageLua;
76 }
77 
79  std::vector<BreakpointOptions *> &bp_options_vec,
80  const char *callback_text) {
81  Status return_error;
82  for (BreakpointOptions *bp_options : bp_options_vec) {
83  return_error = SetBreakpointCommandCallback(bp_options, callback_text);
84  if (return_error.Success())
85  break;
86  }
87  return return_error;
88 }
89 
91  std::vector<BreakpointOptions *> &bp_options_vec, const char *function_name,
92  StructuredData::ObjectSP extra_args_sp) {
93  Status error;
94  for (BreakpointOptions *bp_options : bp_options_vec) {
95  error = SetBreakpointCommandCallbackFunction(bp_options, function_name,
96  extra_args_sp);
97  if (!error.Success())
98  return error;
99  }
100  return error;
101 }
102 
103 std::unique_ptr<ScriptInterpreterLocker>
105  return std::unique_ptr<ScriptInterpreterLocker>(
107 }
A class to manage flag bits.
Definition: Debugger.h:70
A class that represents a running process on the host machine.
static std::string LanguageToString(lldb::ScriptLanguage language)
virtual std::unique_ptr< ScriptInterpreterLocker > AcquireInterpreterLock()
static lldb::ScriptLanguage StringToLanguage(const llvm::StringRef &string)
virtual bool LoadScriptingModule(const char *filename, bool init_session, lldb_private::Status &error, StructuredData::ObjectSP *module_sp=nullptr)
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:242
Status SetBreakpointCommandCallbackFunction(std::vector< BreakpointOptions *> &bp_options_vec, const char *function_name, StructuredData::ObjectSP extra_args_sp)
bool Success() const
Test for success condition.
Definition: Status.cpp:288
virtual void CollectDataForBreakpointCommandCallback(std::vector< BreakpointOptions *> &options, CommandReturnObject &result)
Status SetBreakpointCommandCallback(std::vector< BreakpointOptions *> &bp_options_vec, const char *callback_text)
Set the specified text as the callback for the breakpoint.
"lldb/Breakpoint/WatchpointOptions.h" Class that manages the options on a watchpoint.
void void AppendError(llvm::StringRef in_string)
"lldb/Breakpoint/BreakpointOptions.h" Class that manages the options on a breakpoint or breakpoint lo...
Definition: SBAddress.h:15
std::shared_ptr< Object > ObjectSP
virtual void CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options, CommandReturnObject &result)
void SetStatus(lldb::ReturnStatus status)
ScriptLanguage
Script interpreter types.
An error handling class.
Definition: Status.h:44