@@ -127,6 +127,18 @@ dxil_debug_info::DxcPixDxilDebugInfo::InstructionOffsetsFromSourceLocation(
127127 ppOffsets, m_pMalloc, m_pSession, FileName, SourceLine, SourceColumn);
128128}
129129
130+ STDMETHODIMP
131+ dxil_debug_info::DxcPixDxilDebugInfo::SourceLocationsFromInstructionOffset (
132+ _In_ DWORD InstructionOffset,
133+ _COM_Outptr_ IDxcPixDxilSourceLocations **ppSourceLocations) {
134+
135+ llvm::Instruction *IP = FindInstruction (InstructionOffset);
136+
137+ return dxil_debug_info::NewDxcPixDxilDebugInfoObjectOrThrow<
138+ dxil_debug_info::DxcPixDxilSourceLocations>(
139+ ppSourceLocations, m_pMalloc, m_pSession, IP);
140+ }
141+
130142static bool CompareFilenames (const wchar_t * l, const char * r)
131143{
132144 while (*l && *r) {
@@ -207,3 +219,67 @@ DWORD dxil_debug_info::DxcPixDxilInstructionOffsets::GetOffsetByIndex(DWORD Inde
207219 }
208220 return static_cast <DWORD>(-1 );
209221}
222+
223+
224+ dxil_debug_info::DxcPixDxilSourceLocations::DxcPixDxilSourceLocations (
225+ IMalloc* pMalloc,
226+ dxil_dia::Session* pSession,
227+ llvm::Instruction* IP)
228+ {
229+ const llvm::DITypeIdentifierMap EmptyMap;
230+
231+ if (const llvm::DebugLoc& DL = IP->getDebugLoc ())
232+ {
233+ auto * S = llvm::dyn_cast<llvm::DIScope>(DL.getScope ());
234+ while (S != nullptr && !llvm::isa<llvm::DIFile>(S))
235+ {
236+ S = S->getScope ().resolve (EmptyMap);
237+ }
238+
239+ if (S != nullptr )
240+ {
241+ Location loc;
242+ loc.Line = DL->getLine ();
243+ loc.Column = DL->getColumn ();
244+ loc.Filename = CA2W (S->getFilename ().data ());
245+ m_locations.emplace_back (std::move (loc));
246+ }
247+ }
248+ }
249+
250+ STDMETHODIMP_ (DWORD) dxil_debug_info::DxcPixDxilSourceLocations::GetCount()
251+ {
252+ return static_cast <DWORD>(m_locations.size ());
253+ }
254+
255+ STDMETHODIMP dxil_debug_info::DxcPixDxilSourceLocations::GetFileNameByIndex (
256+ _In_ DWORD Index, _Outptr_result_z_ BSTR *Name)
257+ {
258+ if (Index >= static_cast <DWORD>(m_locations.size ()))
259+ {
260+ return E_BOUNDS;
261+ }
262+ *Name = m_locations[Index].Filename .Copy ();
263+ return S_OK;
264+ }
265+
266+ STDMETHODIMP_ (DWORD) dxil_debug_info::DxcPixDxilSourceLocations::GetColumnByIndex(
267+ _In_ DWORD Index)
268+ {
269+ if (Index >= static_cast <DWORD>(m_locations.size ()))
270+ {
271+ return E_BOUNDS;
272+ }
273+ return m_locations[Index].Column ;
274+ }
275+
276+ STDMETHODIMP_ (DWORD) dxil_debug_info::DxcPixDxilSourceLocations::GetLineNumberByIndex(
277+ _In_ DWORD Index)
278+ {
279+ if (Index >= static_cast <DWORD>(m_locations.size ()))
280+ {
281+ return E_BOUNDS;
282+ }
283+ return m_locations[Index].Line ;
284+ }
285+
0 commit comments