chigraph  master
Systems programming language written for beginners in LLVM
Debugger.hpp
1 
3 #pragma once
4 
5 #ifndef CHI_DEBUGGER_DEBUGGER_HPP
6 #define CHI_DEBUGGER_DEBUGGER_HPP
7 
8 #include <lldb/API/SBBreakpoint.h>
9 #include <lldb/API/SBDebugger.h>
10 #include <lldb/API/SBListener.h>
11 #include <lldb/API/SBProcess.h>
12 #include <lldb/API/SBTarget.h>
13 
14 #include <chi/GraphFunction.hpp>
15 #include <chi/GraphModule.hpp>
16 
17 namespace chi {
18 
20 class Debugger {
21 public:
25  Debugger(const char* pathToChig, GraphModule& mod);
26 
27  // no copy or move, doesn't really make sense
28  Debugger(const Debugger& other) = delete;
29  Debugger(Debugger&& other) = delete;
30 
32  ~Debugger();
33 
34  Debugger& operator=(const Debugger&) = delete;
35  Debugger& operator=(Debugger&&) = delete;
36 
46  Result start(
47  const char** argv = nullptr, const char** envp = nullptr,
48  const boost::filesystem::path& workingDirectory = boost::filesystem::current_path());
49 
52  Result terminate();
53 
57  bool isAttached() const { return mProcess.IsValid(); }
58 
61  bool running() const {
62  if (!isAttached()) { return false; }
63  return lldbProcess().GetState() == lldb::eStateRunning;
64  }
65 
69 
72  Result pause();
73 
78  Result setBreakpoint(NodeInstance& node, lldb::SBBreakpoint* bp = nullptr);
79 
83  bool removeBreakpoint(NodeInstance& node);
84 
87  std::vector<const NodeInstance*> listBreakpoints() const;
88 
96  lldb::SBValue inspectNodeOutput(const NodeInstance& inst, size_t id, lldb::SBFrame frame = {});
97 
101  lldb::SBValue inspectLocalVariable(boost::string_view name);
102 
107  NodeInstance* nodeFromFrame(lldb::SBFrame frame = {});
108 
111  GraphModule& module() const { return *mModule; }
112 
116  lldb::SBTarget lldbTarget() const { return mTarget; }
117 
121  lldb::SBProcess lldbProcess() const { return mProcess; }
122 
126  lldb::SBDebugger lldbDebugger() const { return mDebugger; }
127 
128 private:
129  lldb::SBDebugger mDebugger;
130  lldb::SBTarget mTarget;
131  lldb::SBProcess mProcess;
132 
133  GraphModule* mModule = nullptr;
134 
135  std::unordered_map<const NodeInstance*, lldb::SBBreakpoint> mBreakpoints;
136 };
137 
141 unsigned lineNumberFromNode(NodeInstance& inst);
142 
143 } // namespace chi
144 
145 #endif // CHI_DEBUGGER_DEBUGGER_HPP
Result start(const char **argv=nullptr, const char **envp=nullptr, const boost::filesystem::path &workingDirectory=boost::filesystem::current_path())
Start debugging the process.
Definition: Debugger.cpp:145
bool isAttached() const
Check if this debugger is attached to a process It&#39;s true if the process is stopped or if it&#39;s curret...
Definition: Debugger.hpp:57
GraphModule & module() const
Get the module that&#39;s being debugged by this debugger.
Definition: Debugger.hpp:111
Result processContinue()
Continue the execution of the process.
Definition: Debugger.cpp:77
Result setBreakpoint(NodeInstance &node, lldb::SBBreakpoint *bp=nullptr)
Set a breakpoint on a given node.
Definition: Debugger.cpp:110
Result pause()
Pause the execution state.
Definition: Debugger.cpp:93
Result terminate()
Terminate the inferior process.
Definition: Debugger.cpp:60
lldb::SBTarget lldbTarget() const
Get the target Keep in mind the return isn&#39;t necessarily valid, although it should be...
Definition: Debugger.hpp:116
lldb::SBProcess lldbProcess() const
Get the process This will only be valid if there&#39;s an attached process.
Definition: Debugger.hpp:121
An instance of a node.
bool running() const
Check if the process is executing.
Definition: Debugger.hpp:61
lldb::SBValue inspectLocalVariable(boost::string_view name)
Get the value of a local variable.
lldb::SBValue inspectNodeOutput(const NodeInstance &inst, size_t id, lldb::SBFrame frame={})
Get the output of a node.
Definition: Debugger.cpp:223
unsigned lineNumberFromNode(NodeInstance &inst)
Get the mapped line number from a node.
Definition: Debugger.cpp:282
NodeInstance * nodeFromFrame(lldb::SBFrame frame={})
Get a NodeInstance from a frame.
Definition: Debugger.cpp:244
std::vector< const NodeInstance * > listBreakpoints() const
List the curretnly set breakpoints.
Definition: Debugger.cpp:216
Debugger(const char *pathToChig, GraphModule &mod)
Default constructor.
Definition: Debugger.cpp:33
bool removeBreakpoint(NodeInstance &node)
Remove a breakpoint from a node.
Definition: Debugger.cpp:138
Module that holds graph functions.
Definition: GraphModule.hpp:16
Defines the GraphModule class.
The namespace where chigraph lives.
~Debugger()
Destructor.
Definition: Debugger.cpp:58
The result object, used for identifiying errors with good diagnostics.
Definition: Result.hpp:72
lldb::SBDebugger lldbDebugger() const
Get the debugger This should probably be valid...not sure why it wouldn&#39;t be.
Definition: Debugger.hpp:126
Declares the GraphFunction class.
Helper class for using LLDB with chigraph.
Definition: Debugger.hpp:20