aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectSource.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2023-06-26 09:16:23 -0700
committerJonas Devlieghere <jonas@devlieghere.com>2023-06-26 10:40:08 -0700
commitd49caf4afc1bc460600b316f9736e01ceeebded5 (patch)
tree9ee2be997a6ac1312bdd90f44a405135037bc460 /lldb/source/Commands/CommandObjectSource.cpp
parent5f69e6682bf0806c13098f79cb5f1ee30f0f8c06 (diff)
downloadllvm-d49caf4afc1bc460600b316f9736e01ceeebded5.zip
llvm-d49caf4afc1bc460600b316f9736e01ceeebded5.tar.gz
llvm-d49caf4afc1bc460600b316f9736e01ceeebded5.tar.bz2
[lldb] Add `source cache dump` and `source cache clear` subcommand
Add two new source subcommands: source cache dump and source cache clear. As the name implies the first one dumps the source cache while the later clears the cache. This patch was motivated by a handful of (internal) bug reports related to sources not being available. Right now those issues can be hard to diagnose. The new commands give users, as well as us as developers, more insight into and control over the source cache. Differential revision: https://reviews.llvm.org/D153685
Diffstat (limited to 'lldb/source/Commands/CommandObjectSource.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectSource.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp
index bbc3142..5fdf157 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -1201,6 +1201,62 @@ protected:
std::string m_reverse_name;
};
+class CommandObjectSourceCacheDump : public CommandObjectParsed {
+public:
+ CommandObjectSourceCacheDump(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "source cache dump",
+ "Dump the state of the source code cache. Intended "
+ "to be used for debugging LLDB itself.",
+ nullptr) {}
+
+ ~CommandObjectSourceCacheDump() override = default;
+
+protected:
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ SourceManager::SourceFileCache &cache = GetDebugger().GetSourceFileCache();
+ cache.Dump(result.GetOutputStream());
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return result.Succeeded();
+ }
+};
+
+class CommandObjectSourceCacheClear : public CommandObjectParsed {
+public:
+ CommandObjectSourceCacheClear(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "source cache clear",
+ "Clear the source code cache.\n", nullptr) {}
+
+ ~CommandObjectSourceCacheClear() override = default;
+
+protected:
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ SourceManager::SourceFileCache &cache = GetDebugger().GetSourceFileCache();
+ cache.Clear();
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ return result.Succeeded();
+ }
+};
+
+class CommandObjectSourceCache : public CommandObjectMultiword {
+public:
+ CommandObjectSourceCache(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(interpreter, "source cache",
+ "Commands for managing the source code cache.",
+ "source cache <sub-command>") {
+ LoadSubCommand(
+ "dump", CommandObjectSP(new CommandObjectSourceCacheDump(interpreter)));
+ LoadSubCommand("clear", CommandObjectSP(new CommandObjectSourceCacheClear(
+ interpreter)));
+ }
+
+ ~CommandObjectSourceCache() override = default;
+
+private:
+ CommandObjectSourceCache(const CommandObjectSourceCache &) = delete;
+ const CommandObjectSourceCache &
+ operator=(const CommandObjectSourceCache &) = delete;
+};
+
#pragma mark CommandObjectMultiwordSource
// CommandObjectMultiwordSource
@@ -1216,6 +1272,8 @@ CommandObjectMultiwordSource::CommandObjectMultiwordSource(
CommandObjectSP(new CommandObjectSourceInfo(interpreter)));
LoadSubCommand("list",
CommandObjectSP(new CommandObjectSourceList(interpreter)));
+ LoadSubCommand("cache",
+ CommandObjectSP(new CommandObjectSourceCache(interpreter)));
}
CommandObjectMultiwordSource::~CommandObjectMultiwordSource() = default;