Skip to content

Commit a1b3f67

Browse files
jeffnnJeff Noyle
authored andcommitted
impl (#3200)
Co-authored-by: Jeff Noyle <[email protected]>
1 parent 0a351d6 commit a1b3f67

4 files changed

Lines changed: 160 additions & 1 deletion

File tree

include/dxc/dxcpix.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,16 @@ struct __declspec(uuid("eb71f85e-8542-44b5-87da-9d76045a1910"))
140140
virtual STDMETHODIMP_(DWORD) GetOffsetByIndex(_In_ DWORD Index) = 0;
141141
};
142142

143-
struct __declspec(uuid("6dd5d45e-a417-4a26-b0ff-bdb7d6dcc63d"))
143+
struct __declspec(uuid("761c833d-e7b8-4624-80f8-3a3fb4146342"))
144+
IDxcPixDxilSourceLocations : public IUnknown
145+
{
146+
virtual STDMETHODIMP_(DWORD) GetCount() = 0;
147+
virtual STDMETHODIMP_(DWORD) GetLineNumberByIndex(_In_ DWORD Index) = 0;
148+
virtual STDMETHODIMP_(DWORD) GetColumnByIndex(_In_ DWORD Index) = 0;
149+
virtual STDMETHODIMP GetFileNameByIndex(_In_ DWORD Index, _Outptr_result_z_ BSTR *Name) = 0;
150+
};
151+
152+
struct __declspec(uuid("b875638e-108a-4d90-a53a-68d63773cb38"))
144153
IDxcPixDxilDebugInfo : public IUnknown
145154
{
146155
virtual STDMETHODIMP GetLiveVariablesAt(
@@ -164,6 +173,10 @@ IDxcPixDxilDebugInfo : public IUnknown
164173
_In_ DWORD SourceLine,
165174
_In_ DWORD SourceColumn,
166175
_COM_Outptr_ IDxcPixDxilInstructionOffsets** ppOffsets) = 0;
176+
177+
virtual STDMETHODIMP SourceLocationsFromInstructionOffset(
178+
_In_ DWORD InstructionOffset,
179+
_COM_Outptr_ IDxcPixDxilSourceLocations**ppSourceLocations) = 0;
167180
};
168181

169182
struct __declspec(uuid("61b16c95-8799-4ed8-bdb0-3b6c08a141b4"))

lib/DxilDia/DxcPixDxilDebugInfo.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
130142
static 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+

lib/DxilDia/DxcPixDxilDebugInfo.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class DxcPixDxilDebugInfo : public IDxcPixDxilDebugInfo
8484
_In_ DWORD SourceColumn,
8585
_COM_Outptr_ IDxcPixDxilInstructionOffsets **ppOffsets) override;
8686

87+
STDMETHODIMP SourceLocationsFromInstructionOffset(
88+
_In_ DWORD InstructionOffset,
89+
_COM_Outptr_ IDxcPixDxilSourceLocations** ppSourceLocations) override;
90+
8791
llvm::Module *GetModuleRef();
8892

8993
IMalloc *GetMallocNoRef()
@@ -118,4 +122,38 @@ class DxcPixDxilInstructionOffsets : public IDxcPixDxilInstructionOffsets
118122
virtual STDMETHODIMP_(DWORD) GetCount() override;
119123
virtual STDMETHODIMP_(DWORD) GetOffsetByIndex(_In_ DWORD Index) override;
120124
};
125+
126+
class DxcPixDxilSourceLocations : public IDxcPixDxilSourceLocations
127+
{
128+
private:
129+
DXC_MICROCOM_TM_REF_FIELDS()
130+
131+
DxcPixDxilSourceLocations(
132+
IMalloc* pMalloc,
133+
dxil_dia::Session *pSession,
134+
llvm::Instruction* IP);
135+
136+
struct Location
137+
{
138+
CComBSTR Filename;
139+
DWORD Line;
140+
DWORD Column;
141+
};
142+
std::vector<Location> m_locations;
143+
144+
public:
145+
DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL()
146+
DXC_MICROCOM_TM_ALLOC(DxcPixDxilSourceLocations)
147+
148+
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) {
149+
return DoBasicQueryInterface<IDxcPixDxilSourceLocations>(this, iid, ppvObject);
150+
}
151+
152+
virtual STDMETHODIMP_(DWORD) GetCount() override;
153+
virtual STDMETHODIMP_(DWORD) GetLineNumberByIndex(_In_ DWORD Index) override;
154+
virtual STDMETHODIMP_(DWORD) GetColumnByIndex(_In_ DWORD Index)override;
155+
virtual STDMETHODIMP GetFileNameByIndex(_In_ DWORD Index,
156+
_Outptr_result_z_ BSTR *Name) override;
157+
};
158+
121159
} // namespace dxil_debug_info

lib/DxilDia/DxcPixEntrypoints.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,13 @@ struct IDxcPixDxilDebugInfoEntrypoint : public Entrypoint<IDxcPixDxilDebugInfo>
728728
{
729729
return InvokeOnReal(&IInterface::InstructionOffsetsFromSourceLocation, CheckNotNull(InParam(FileName)), SourceLine, SourceColumn, CheckNotNull(OutParam(ppOffsets)));
730730
}
731+
732+
STDMETHODIMP SourceLocationsFromInstructionOffset(
733+
_In_ DWORD InstructionOffset,
734+
_COM_Outptr_ IDxcPixDxilSourceLocations** ppSourceLocations) override
735+
{
736+
return InvokeOnReal(&IInterface::SourceLocationsFromInstructionOffset, InstructionOffset, CheckNotNull(OutParam(ppSourceLocations)));
737+
}
731738
};
732739
DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixDxilDebugInfo);
733740

@@ -747,6 +754,31 @@ struct IDxcPixDxilInstructionOffsetsEntrypoint : public Entrypoint<IDxcPixDxilIn
747754
};
748755
DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixDxilInstructionOffsets);
749756

757+
struct IDxcPixDxilSourceLocationsEntrypoint : public Entrypoint<IDxcPixDxilSourceLocations>
758+
{
759+
DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixDxilSourceLocationsEntrypoint);
760+
761+
STDMETHODIMP_(DWORD) GetCount() override
762+
{
763+
return InvokeOnReal(&IInterface::GetCount);
764+
}
765+
766+
STDMETHODIMP_(DWORD) GetLineNumberByIndex(_In_ DWORD Index) override
767+
{
768+
return InvokeOnReal(&IInterface::GetLineNumberByIndex, Index);
769+
}
770+
771+
STDMETHODIMP_(DWORD) GetColumnByIndex(_In_ DWORD Index) override
772+
{
773+
return InvokeOnReal(&IInterface::GetColumnByIndex, Index);
774+
}
775+
STDMETHODIMP GetFileNameByIndex(_In_ DWORD Index, _Outptr_result_z_ BSTR* Name) override
776+
{
777+
return InvokeOnReal(&IInterface::GetFileNameByIndex, Index, CheckNotNull(OutParam(Name)));
778+
}
779+
};
780+
DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixDxilSourceLocations);
781+
750782
struct IDxcPixCompilationInfoEntrypoint
751783
: public Entrypoint<IDxcPixCompilationInfo>
752784
{

0 commit comments

Comments
 (0)