-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
114 lines (93 loc) · 3.41 KB
/
main.cpp
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
//===-------- main.cpp - Main driver for the tool -------------------------===//
//
// Part of the SeekBug Project, under the Apache License v2.0.
// See LICENSE for details.
//
//===----------------------------------------------------------------------===//
//
// This file provides the implementation of the main driver.
//
//===----------------------------------------------------------------------===//
#include "seek-bug/AICommands.h"
#include "seek-bug/SeekBugContext.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include "lldb/API/SBCommandInterpreter.h"
#include "lldb/API/SBCommandReturnObject.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBLaunchInfo.h"
#include "lldb/API/SBListener.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBThread.h"
#include <filesystem>
#include <iostream>
using namespace llvm;
namespace {
using namespace cl;
OptionCategory SeekBugCategory("Specific Options");
static opt<bool> Help("h", desc("Alias for -help"), Hidden,
cat(SeekBugCategory));
static opt<std::string> InputFilename(Positional, desc("<input file>"),
cat(SeekBugCategory));
static cl::opt<std::string> DeepSeekLLMPath("deep-seek-llm-path",
cl::desc("Path to DeepSeek LLM."),
cl::init(""), cl::ValueRequired,
cl::cat(SeekBugCategory));
} // namespace
/// @}
//===----------------------------------------------------------------------===//
int main(int argc, char **argv) {
WithColor(llvm::outs(), HighlightColor::String)
<< "=== SeekBug - Modern, Portable and Deep Debugger\n";
HideUnrelatedOptions({&SeekBugCategory});
cl::ParseCommandLineOptions(argc, argv, "Have a chat with your debugger!");
if (Help) {
PrintHelpMessage(false, true);
return 0;
}
if (argc < 3) {
std::cerr << "Usage: " << argv[0]
<< " --deep-seek-llm-path=<path> <program to debug> "
<< std::endl;
return 1;
}
std::string program = argv[2];
SeekBugContext context;
if (!DeepSeekLLMPath.empty()) {
std::filesystem::path p = std::string(DeepSeekLLMPath);
if (p.extension().string() == ".gguf") {
context.DeepSeekLLMPath = DeepSeekLLMPath;
} else {
llvm::WithColor::error() << "No .gguf file specified." << program << '\n';
return 1;
}
} else {
llvm::WithColor::error()
<< "No LLM file specified. Use " << program << '\n';
return 1;
}
// Initialize LLDB.
lldb::SBDebugger::Initialize();
lldb::SBDebugger debugger = lldb::SBDebugger::Create();
// Set debugger options.
// TODO: Check if we need to more.
debugger.SetAsync(false);
// Create a target
lldb::SBTarget target = debugger.CreateTarget(program.c_str());
if (!target.IsValid()) {
llvm::WithColor::error()
<< "Failed to create LLDB target for program: " << program << '\n';
return 1;
}
debugger.SetPrompt("(seek-bug) ");
// Register custom/AI commands.
lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter();
seekbug::RegisterAICommands(interpreter, context);
debugger.RunCommandInterpreter(true, false);
lldb::SBDebugger::Destroy(debugger);
lldb::SBDebugger::Terminate();
WithColor(llvm::outs(), HighlightColor::String)
<< "=== Happy Debugging! Bye!\n";
return 0;
}