@@ -53,6 +53,7 @@ THE SOFTWARE.
5353#include < vector>
5454#include < thread>
5555#include < mutex>
56+ #include < condition_variable>
5657#include < utility>
5758#include < shared_mutex>
5859#include < filesystem>
@@ -113,6 +114,7 @@ struct KernelArgument {
113114bool buildDwarfAddressMap (const char * filename, size_t offset, size_t hsaco_length, std::map<Dwarf_Addr, SourceLocation>& addressMap);
114115SourceLocation getSourceLocation (const std::map<Dwarf_Addr, SourceLocation>& addrMap, Dwarf_Addr addr);
115116__attribute__ ((visibility(" default" ))) bool getDisassembly(hsa_agent_t agent, const std::string& fileName, std::string& out);
117+ bool getDisassemblyForSymbol (hsa_agent_t agent, const std::string& fileName, const std::string& symbolName, std::string& out);
116118bool invokeProgram (const std::string& programName, const std::vector<std::string>& params, const std::string& outputFileName);
117119std::string create_temp_file_segment (const std::string& filename, std::streamoff offset, std::streamsize length);
118120__attribute__ ((visibility(" default" ))) std::vector<std::string> extractCodeObjects(hsa_agent_t agent, const std::string& fileName);
@@ -210,7 +212,7 @@ class __attribute__((visibility("default"))) kernelDB {
210212 ~kernelDB ();
211213 bool getBasicBlocks (const std::string& name, std::vector<basicBlock>&);
212214 CDNAKernel& getKernel (const std::string& name);
213- bool addFile (const std::string& name, hsa_agent_t agent, const std::string& strFilter);
215+ bool addFile (const std::string& name, hsa_agent_t agent, const std::string& strFilter, bool lazy = false );
214216 bool parseDisassembly (const std::string& text);
215217 void mapDisassemblyToSource (hsa_agent_t agent, const char *elfFilePath);
216218 bool addKernel (std::unique_ptr<CDNAKernel> kernel);
@@ -227,9 +229,15 @@ class __attribute__((visibility("default"))) kernelDB {
227229 bool scanCodeObject (const std::string& co_file);
228230 bool hasKernel (const std::string& name);
229231private:
232+ bool scanCodeObjectForKernel (const std::string& co_file, const std::string& kernelName);
233+ bool parseDisassemblyForKernel (const std::string& text, const std::string& targetKernel);
234+ // / Get kernel symbol names from a .hsaco ELF without disassembling (reads .symtab).
235+ static std::vector<std::string> getKernelNamesFromElf (const std::string& fileName);
236+ // / If kernel is lazy-loaded, disassemble its code object and fill kernels_; then remove from lazy set.
237+ void ensureKernelLoaded (const std::string& name);
230238 void buildLineMap (size_t offset, size_t hsaco_length, const char *elfFilePath);
231239 void extractArgumentsFromDwarf (hsa_agent_t agent, const char *elfFilePath, bool resolve_typedefs);
232- void processKernelsWithAddressMap (const std::map<Dwarf_Addr, SourceLocation>& addrMap);
240+ void processKernelsWithAddressMap (const std::map<Dwarf_Addr, SourceLocation>& addrMap, const std::string& targetKernel = " " );
233241 parse_mode getLineType (std::string& line);
234242 std::string extractKernelName (const std::string& line);
235243 static bool isBranch (const std::string& instruction);
@@ -240,6 +248,17 @@ class __attribute__((visibility("default"))) kernelDB {
240248 std::string fileName_;
241249 std::map<std::string, std::vector<std::string>> file_map_;
242250 std::set<std::string> scanned_code_objects_;
251+ struct LazyKernelEntry {
252+ std::string hsaco_path;
253+ std::string logical_file;
254+ std::string elf_symbol; // raw (mangled) ELF symbol name for --disassemble-symbols
255+ };
256+ // / Lazy-loaded kernels: canonical name -> entry. Filled by addFile(..., lazy=true).
257+ std::map<std::string, LazyKernelEntry> lazy_kernels_;
258+ // / Kernels currently being loaded — prevents concurrent disassembly of the same kernel.
259+ std::set<std::string> loading_kernels_;
260+ std::mutex loading_mutex_;
261+ std::condition_variable loading_cv_;
243262 std::shared_mutex mutex_;
244263};
245264
0 commit comments