Vulkan/Debug: Add Context::Lock::findFile()
Useful for lazily building a new `File` if it hasn't been registered already.
Also assign the file to the location of a new frame. This is a sensible default to have.
Bug: b/145351270
Change-Id: I7c0abff22a0010923428ff5ed0760d6ae63b0c6b
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/48697
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/Vulkan/Debug/Context.cpp b/src/Vulkan/Debug/Context.cpp
index 2a9916e..2ebe7fc 100644
--- a/src/Vulkan/Debug/Context.cpp
+++ b/src/Vulkan/Debug/Context.cpp
@@ -20,6 +20,8 @@
#include "Variable.hpp"
#include "WeakMap.hpp"
+#include "System/Debug.hpp"
+
#include <memory>
#include <mutex>
#include <thread>
@@ -348,6 +350,19 @@
return ctx->files.get(id);
}
+std::shared_ptr<File> Context::Lock::findFile(const std::string &path)
+{
+ for(auto it : ctx->files)
+ {
+ auto &file = it.second;
+ if(file->path() == path)
+ {
+ return file;
+ }
+ }
+ return nullptr;
+}
+
std::vector<std::shared_ptr<File>> Context::Lock::files()
{
std::vector<std::shared_ptr<File>> out;
@@ -368,6 +383,7 @@
frame->locals = createScope(file);
frame->registers = createScope(file);
frame->hovers = createScope(file);
+ frame->location.file = file;
return frame;
}
diff --git a/src/Vulkan/Debug/Context.hpp b/src/Vulkan/Debug/Context.hpp
index acc3ea2..f9315ee 100644
--- a/src/Vulkan/Debug/Context.hpp
+++ b/src/Vulkan/Debug/Context.hpp
@@ -88,6 +88,10 @@
// does not exist or no longer has any external shared_ptr references.
std::shared_ptr<File> get(ID<File>);
+ // findFile() returns the file with the given path, or nullptr if not
+ // found.
+ std::shared_ptr<File> findFile(const std::string &path);
+
// files() returns the full list of files.
std::vector<std::shared_ptr<File>> files();