SymbolReader.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. //
  2. // This code is the managed pdb reader interface for PERWAPI.
  3. // Written by John Gough, April 2007.
  4. // Copyright(c) 2007-2010 John Gough, and Queensland University of Technology
  5. //
  6. // NOTES:
  7. // Q: Where does this code come from?
  8. // A: At the heart of the code is some COM interop that accesses the
  9. // facilities of mscoree.dll. Unfortunately, the type library for
  10. // this component is incomplete, and does not cover the symbol store
  11. // functionality. There is some MIDL, and the C++ header files
  12. // cor.h and corsym.h. From here comes the guid values, for
  13. // example, and critically the order of the interface methods.
  14. // The managed interfaces, such as ISymbolReader, are defined in
  15. // [mscorlib]System.Diagnostics.SymbolStore.
  16. //
  17. // This file provides managed wrappers for the unmanaged interfaces.
  18. // These wrappers implement the managed interfaces.
  19. // Not all methods are implemented. Those that are not will throw
  20. // NotImplementedException.
  21. //
  22. // Some of the functionality currently not used by PERWAPI is left
  23. // unimplemented, and throws a NotImplementedException if called.
  24. //
  25. // THANKS:
  26. // Wayne Kelly, whose SimpleWriter, in C++ pointed the way.
  27. // Adam Nathan, whose ".NET and COM" tells you more than you want to know
  28. // Microsoft's Iron Python and MDBG samples answered remaining questions
  29. //
  30. using System;
  31. using System.Collections.Generic;
  32. using System.Text;
  33. using System.Runtime.InteropServices;
  34. using System.Runtime.InteropServices.ComTypes;
  35. using System.Diagnostics.SymbolStore;
  36. namespace QUT.Symbols {
  37. public class SymbolReader : ISymbolReader {
  38. private ISymUnmanagedReader private_reader;
  39. /// <summary>
  40. /// Constructor for SymbolReader.
  41. /// Just creates a reference to the unmanaged reader
  42. /// from the COM world. This Reader only implements
  43. /// the method(s) required by PERWAPI.
  44. /// </summary>
  45. /// <param name="filename"></param>
  46. public SymbolReader(string filename) {
  47. object ppb = null;
  48. object pUnk = null;
  49. object pBnd = null;
  50. IntPtr importer = IntPtr.Zero;
  51. object retVal = null;
  52. try {
  53. OLE32.CoCreateInstance(ref XGuid.dispenserClassID, null, 1, ref XGuid.dispenserIID, out ppb);
  54. OLE32.CoCreateInstance(ref XGuid.binderCLSID, null, 1, ref XGuid.binderIID, out pBnd);
  55. // Get the metadata dispenser from mscoree.dll
  56. Util.ComCheck(ppb != null, "Failed to create metadata dispenser");
  57. ((IMetaDataDispenserSubset)ppb).OpenScope(filename, 0, ref XGuid.importerIID, out pUnk);
  58. Util.ComCheck(pUnk != null, "Failed to open scope");
  59. importer = Marshal.GetComInterfaceForObject(pUnk, typeof(IMetadataImport));
  60. ((ISymUnmanagedBinder)pBnd).GetReaderForFile(importer, filename, null, out retVal);
  61. private_reader = (ISymUnmanagedReader)retVal;
  62. }
  63. catch (Exception x) {
  64. Console.WriteLine(x.Message);
  65. }
  66. finally {
  67. if (importer != IntPtr.Zero)
  68. Marshal.Release(importer);
  69. }
  70. }
  71. // ============================================================================
  72. // ========================== ISymbolReader Methods ===========================
  73. // ============================================================================
  74. /// <summary>
  75. /// This is the only SymbolReader method required by PERWAPI
  76. /// at this stage.
  77. /// </summary>
  78. /// <param name="tok">The metadata token</param>
  79. /// <returns>The SymbolMethod object for the token</returns>
  80. public ISymbolMethod GetMethod(SymbolToken tok) {
  81. // MIDL is ...
  82. //[PreserveSig]
  83. //int GetMethod(
  84. // SymbolToken methodToken,
  85. // [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedMethod retVal);
  86. ISymUnmanagedMethod unMeth = null;
  87. int hr = private_reader.GetMethod(tok, out unMeth);
  88. if (hr == OLE32.hr_E_FAIL) // could be empty method
  89. return null;
  90. else // any other abnormal HRESULT
  91. Marshal.ThrowExceptionForHR(hr);
  92. // All ok ...
  93. return new SymbolMethod(unMeth);
  94. }
  95. // This one not used by PERWAPI yet.
  96. public ISymbolMethod GetMethod(SymbolToken tok, int ver) {
  97. ISymUnmanagedMethod unMeth = null;
  98. int hr = private_reader.GetMethodByVersion(tok, ver, out unMeth);
  99. if (hr == OLE32.hr_E_FAIL) // could be empty method
  100. return null;
  101. else // any other abnormal HRESULT
  102. Marshal.ThrowExceptionForHR(hr);
  103. // All ok ...
  104. return new SymbolMethod(unMeth);
  105. }
  106. /// <summary>
  107. /// Gets user entry point for a reader.
  108. /// Returns null if reader is attached to a PE-file
  109. /// that does not have an entry point.
  110. /// </summary>
  111. public SymbolToken UserEntryPoint {
  112. get {
  113. SymbolToken retVal;
  114. int hr = private_reader.GetUserEntryPoint(out retVal);
  115. if (hr == OLE32.hr_E_FAIL)
  116. return new SymbolToken(0);
  117. else
  118. Marshal.ThrowExceptionForHR(hr);
  119. return retVal;
  120. }
  121. }
  122. #region unimplemented methods
  123. // Summary:
  124. // Gets a document specified by the language, vendor, and type.
  125. //
  126. // Parameters:
  127. // url:
  128. // The URL that identifies the document.
  129. //
  130. // documentType:
  131. // The type of the document. You can specify this parameter as System.Guid.Empty.
  132. //
  133. // languageVendor:
  134. // The identity of the vendor for the document language. You can specify this
  135. // parameter as System.Guid.Empty.
  136. //
  137. // language:
  138. // The document language. You can specify this parameter as System.Guid.Empty.
  139. //
  140. // Returns:
  141. // The specified document.
  142. public ISymbolDocument GetDocument(
  143. string url,
  144. Guid language,
  145. Guid languageVendor,
  146. Guid documentType) {
  147. throw new NotImplementedException("No QUT.SymbolReader.GetDocument");
  148. }
  149. //
  150. // Summary:
  151. // Gets an array of all documents defined in the symbol store.
  152. //
  153. // Returns:
  154. // An array of all documents defined in the symbol store.
  155. public ISymbolDocument[] GetDocuments() {
  156. throw new NotImplementedException("No QUT.SymbolReader.GetDocuments");
  157. }
  158. //
  159. // Summary:
  160. // Gets all global variables in the module.
  161. //
  162. // Returns:
  163. // An array of all variables in the module.
  164. public ISymbolVariable[] GetGlobalVariables() {
  165. throw new NotImplementedException("No QUT.SymbolReader.GetGetGlobalVariables");
  166. }
  167. //
  168. // Summary:
  169. // Gets the namespaces that are defined in the global scope within the current
  170. // symbol store.
  171. //
  172. // Returns:
  173. // The namespaces defined in the global scope within the current symbol store.
  174. public ISymbolNamespace[] GetNamespaces() {
  175. throw new NotImplementedException("No QUT.SymbolReader.GetNamespaces");
  176. }
  177. //
  178. // Summary:
  179. // Gets an attribute value when given the attribute name.
  180. //
  181. // Parameters:
  182. // name:
  183. // The attribute name.
  184. //
  185. // parent:
  186. // The metadata token for the object for which the attribute is requested.
  187. //
  188. // Returns:
  189. // The value of the attribute.
  190. public byte[] GetSymAttribute(SymbolToken parent, string name) {
  191. throw new NotImplementedException("No QUT.SymbolReader.GetSymAttribute");
  192. }
  193. #endregion unimplemented methods
  194. /// <summary>
  195. /// Gets the method that contains a specified position of the document
  196. /// </summary>
  197. /// <param name="document">The document object</param>
  198. /// <param name="line">Source line number</param>
  199. /// <param name="column">Source column number</param>
  200. /// <returns>The chosen method</returns>
  201. public ISymbolMethod GetMethodFromDocumentPosition(ISymbolDocument doc, int line, int column) {
  202. ISymUnmanagedMethod unMeth = null;
  203. private_reader.GetMethodFromDocumentPosition(
  204. ((SymbolDocument)doc).WrappedDoc, line, column, out unMeth);
  205. return new SymbolMethod(unMeth);
  206. }
  207. public ISymbolVariable[] GetVariables(SymbolToken parent) {
  208. int varNm = 0;
  209. private_reader.GetVariables(parent, 0, out varNm, null);
  210. ISymUnmanagedVariable[] unVars = new ISymUnmanagedVariable[varNm];
  211. SymbolVariable[] retVal = new SymbolVariable[varNm];
  212. private_reader.GetVariables(parent, varNm, out varNm, unVars);
  213. for (int i = 0; i < varNm; i++)
  214. retVal[i] = new SymbolVariable(unVars[i]);
  215. return retVal;
  216. }
  217. }
  218. // ============================ End of SymbolReader ===========================
  219. /// <summary>
  220. /// This is the managed wrapper for the unmanaged
  221. /// Method descriptor. This implements the interface
  222. /// System.Diagnostics.SymbolStore.ISymbolMethod
  223. /// </summary>
  224. public class SymbolMethod : ISymbolMethod {
  225. private const int INVALID = -1;
  226. private ISymUnmanagedMethod private_method;
  227. internal SymbolMethod(ISymUnmanagedMethod unMeth) {
  228. private_method = unMeth;
  229. }
  230. /// <summary>
  231. /// Gets the root scope of the method
  232. /// </summary>
  233. public ISymbolScope RootScope { // Needed by PERWAPI
  234. get {
  235. ISymUnmanagedScope retVal = null;
  236. private_method.GetRootScope(out retVal);
  237. return new SymbolScope(retVal);
  238. }
  239. }
  240. /// <summary>
  241. /// Gets the sequence point count for the method
  242. /// </summary>
  243. public int SequencePointCount { // Needed by PERWAPI
  244. get {
  245. int retVal = 0;
  246. private_method.GetSequencePointCount(out retVal);
  247. return retVal;
  248. }
  249. }
  250. /// <summary>
  251. /// Gets the symbol token for the method
  252. /// </summary>
  253. public SymbolToken Token {
  254. get {
  255. SymbolToken tok;
  256. private_method.GetToken(out tok);
  257. return tok;
  258. }
  259. }
  260. /// <summary>
  261. /// Gets the namespace for the method
  262. /// </summary>
  263. /// <returns>The namespace object</returns>
  264. public ISymbolNamespace GetNamespace() {
  265. ISymUnmanagedNamespace retVal = null;
  266. private_method.GetNamespace(out retVal);
  267. return new SymbolNamespace(retVal);
  268. }
  269. /// <summary>
  270. /// Gets the parameters of the method
  271. /// </summary>
  272. /// <returns>The method parameters</returns>
  273. public ISymbolVariable[] GetParameters() {
  274. int pNum = 0;
  275. // Call GetParameters just to get pNum
  276. private_method.GetParameters(0, out pNum, null);
  277. ISymUnmanagedVariable[] unVars = new ISymUnmanagedVariable[pNum];
  278. ISymbolVariable[] manVars = new ISymbolVariable[pNum];
  279. // Now call again to get the real information
  280. private_method.GetParameters(pNum, out pNum, unVars);
  281. for (int i = 0; i < pNum; i++)
  282. manVars[i] = new SymbolVariable(unVars[i]);
  283. return manVars;
  284. }
  285. #region unimplemented methods
  286. public int[] GetRanges(ISymbolDocument document, int line, int column) {
  287. throw new NotImplementedException("No QUT.SymbolMethod.GetRanges");
  288. }
  289. public ISymbolScope GetScope(int offset) {
  290. throw new NotImplementedException("No QUT.SymbolMethod.GetScope");
  291. }
  292. public int GetOffset(
  293. ISymbolDocument document,
  294. int line,
  295. int column) {
  296. throw new NotImplementedException("No QUT.SymbolMethod.GetOffset");
  297. }
  298. private void GetAndCheckLength(int[] arr, ref int num) {
  299. if (arr != null) {
  300. if (num == INVALID)
  301. num = arr.Length;
  302. else
  303. Util.ArgCheck(num == arr.Length, "Invalid arg to GetSequencePoints");
  304. }
  305. }
  306. public bool GetSourceStartEnd(ISymbolDocument[] docs, int[] lines, int[] columns) {
  307. throw new NotImplementedException("No QUT.SymbolMethod.GetSourceStartEnd");
  308. }
  309. #endregion unimplemented methods
  310. /// <summary>
  311. /// Gets the sequence points defined for this method
  312. /// </summary>
  313. /// <param name="offsets">array of IL offsets</param>
  314. /// <param name="documents">array of documents</param>
  315. /// <param name="lines">start line number array</param>
  316. /// <param name="columns">start column number array</param>
  317. /// <param name="endLines">end line number array</param>
  318. /// <param name="endColumns">start line number array</param>
  319. public void GetSequencePoints( // This method needed by PERWAPI
  320. int[] offsets,
  321. ISymbolDocument[] documents,
  322. int[] lines,
  323. int[] columns,
  324. int[] endLines,
  325. int[] endColumns) {
  326. int spCount = INVALID;
  327. GetAndCheckLength(offsets, ref spCount);
  328. GetAndCheckLength(lines, ref spCount);
  329. GetAndCheckLength(columns, ref spCount);
  330. GetAndCheckLength(endLines, ref spCount);
  331. GetAndCheckLength(endColumns, ref spCount);
  332. if (spCount == INVALID)
  333. spCount = 0;
  334. int dcCount = documents.Length;
  335. ISymUnmanagedDocument[] unDocs = new ISymUnmanagedDocument[dcCount];
  336. private_method.GetSequencePoints(
  337. dcCount, out spCount, offsets, unDocs, lines, columns, endLines, endColumns);
  338. for (int i = 0; i < dcCount; i++)
  339. documents[i] = new SymbolDocument(unDocs[i]);
  340. return;
  341. }
  342. }
  343. // ============================ End of SymbolMethod ===========================
  344. /// <summary>
  345. /// This class is a managed wrapper for the unmanaged
  346. /// Scope descriptor. The defintions for ISymbolScope
  347. /// come from metadata.
  348. /// </summary>
  349. public class SymbolScope : ISymbolScope {
  350. private ISymUnmanagedScope private_scope;
  351. internal SymbolScope(ISymUnmanagedScope unScope) {
  352. private_scope = unScope;
  353. }
  354. /// <summary>
  355. /// Returns the end offset of the wrapped scope
  356. /// </summary>
  357. public int EndOffset {
  358. get {
  359. int offset;
  360. private_scope.GetEndOffset(out offset);
  361. return offset;
  362. }
  363. }
  364. /// <summary>
  365. /// Returns the method that contains the current lexical scope
  366. /// </summary>
  367. public ISymbolMethod Method {
  368. get {
  369. ISymUnmanagedMethod unMeth = null;
  370. private_scope.GetMethod(out unMeth);
  371. return new SymbolMethod(unMeth);
  372. }
  373. }
  374. /// <summary>
  375. /// Returns the parent lexical scope of the current scope
  376. /// </summary>
  377. public ISymbolScope Parent {
  378. get {
  379. ISymUnmanagedScope unScope = null;
  380. private_scope.GetParent(out unScope);
  381. return new SymbolScope(unScope);
  382. }
  383. }
  384. /// <summary>
  385. /// Returns the start offset of the current lexical scope
  386. /// </summary>
  387. public int StartOffset {
  388. get {
  389. int offset;
  390. private_scope.GetStartOffset(out offset);
  391. return offset;
  392. }
  393. }
  394. /// <summary>
  395. /// Returns the child lexical scopes of the current lexical scope.
  396. /// </summary>
  397. /// <returns></returns>
  398. public ISymbolScope[] GetChildren() {
  399. int chNum = 0;
  400. private_scope.GetChildren(0, out chNum, null);
  401. ISymUnmanagedScope[] unScps = new ISymUnmanagedScope[chNum];
  402. ISymbolScope[] manScps = new ISymbolScope[chNum];
  403. private_scope.GetChildren(chNum, out chNum, unScps);
  404. for (int i = 0; i < chNum; i++)
  405. manScps[i] = new SymbolScope(unScps[i]);
  406. return manScps;
  407. }
  408. /// <summary>
  409. /// Gets the local variables within the current lexical scope
  410. /// </summary>
  411. /// <returns>The local variables of the current scope</returns>
  412. public ISymbolVariable[] GetLocals() {
  413. int lcNum = 0;
  414. private_scope.GetLocals(0, out lcNum, null);
  415. ISymUnmanagedVariable[] unVars = new ISymUnmanagedVariable[lcNum];
  416. ISymbolVariable[] manVars = new ISymbolVariable[lcNum];
  417. private_scope.GetLocals(lcNum, out lcNum, unVars);
  418. for (int i = 0; i < lcNum; i++)
  419. manVars[i] = new SymbolVariable(unVars[i]);
  420. return manVars;
  421. }
  422. /// <summary>
  423. /// Gets the namespaces that are used within the current scope
  424. /// </summary>
  425. /// <returns>The namespaces that are used within the current scope</returns>
  426. public ISymbolNamespace[] GetNamespaces() {
  427. int nmNum = 0;
  428. private_scope.GetNamespaces(0, out nmNum, null);
  429. ISymUnmanagedNamespace[] unNams = new ISymUnmanagedNamespace[nmNum];
  430. ISymbolNamespace[] manNams = new ISymbolNamespace[nmNum];
  431. private_scope.GetNamespaces(nmNum, out nmNum, unNams);
  432. for (int i = 0; i < nmNum; i++)
  433. manNams[i] = new SymbolNamespace(unNams[i]);
  434. return manNams;
  435. }
  436. }
  437. // ============================ End of SymbolScope ===========================
  438. /// <summary>
  439. /// Managed wrapper for ISymUnmanagedNamespace
  440. /// </summary>
  441. public class SymbolNamespace : ISymbolNamespace {
  442. private ISymUnmanagedNamespace private_namespace;
  443. internal SymbolNamespace(ISymUnmanagedNamespace unNmsp) {
  444. private_namespace = unNmsp;
  445. }
  446. // Summary:
  447. // Gets the current namespace.
  448. //
  449. // Returns:
  450. // The current namespace.
  451. public string Name {
  452. get {
  453. StringBuilder bldr;
  454. int nmLen = 0;
  455. private_namespace.GetName(0, out nmLen, null);
  456. bldr = new StringBuilder(nmLen);
  457. private_namespace.GetName(nmLen, out nmLen, bldr);
  458. return bldr.ToString();
  459. }
  460. }
  461. // Summary:
  462. // Gets the child members of the current namespace.
  463. //
  464. // Returns:
  465. // The child members of the current namespace.
  466. public ISymbolNamespace[] GetNamespaces() {
  467. throw new NotImplementedException("No QUT.SymbolNamespace.GetNamespaces");
  468. }
  469. //
  470. // Summary:
  471. // Gets all the variables defined at global scope within the current namespace.
  472. //
  473. // Returns:
  474. // The variables defined at global scope within the current namespace.
  475. public ISymbolVariable[] GetVariables() {
  476. throw new NotImplementedException("No QUT.SymbolNamespace.GetVariables");
  477. }
  478. }
  479. // ============================ End of SymbolReader ===========================
  480. /// <summary>
  481. /// Managed wrapper for ISymUnmanagedDocument
  482. /// </summary>
  483. public class SymbolDocument : ISymbolDocument {
  484. private ISymUnmanagedDocument private_document;
  485. /// <summary>
  486. /// Constructor for SymbolDocument
  487. /// </summary>
  488. /// <param name="unDoc"></param>
  489. internal SymbolDocument(ISymUnmanagedDocument unDoc) {
  490. private_document = unDoc;
  491. }
  492. /// <summary>
  493. /// Gets the wrapped document
  494. /// </summary>
  495. internal ISymUnmanagedDocument WrappedDoc {
  496. get { return private_document; }
  497. }
  498. /// <summary>
  499. /// Returns a GUID identifying the checksum algorithm.
  500. /// Returns Guid.Zero if there is no checksum.
  501. /// </summary>
  502. public Guid CheckSumAlgorithmId {
  503. get {
  504. Guid retVal = new Guid();
  505. private_document.GetCheckSumAlgorithmId(ref retVal);
  506. return retVal;
  507. }
  508. }
  509. /// <summary>
  510. /// Gets the document type guid
  511. /// </summary>
  512. public Guid DocumentType {
  513. get {
  514. Guid retVal = new Guid();
  515. private_document.GetDocumentType(ref retVal);
  516. return retVal;
  517. }
  518. }
  519. /// <summary>
  520. /// Value is true if document is stored in the symbol store, otherwise false.
  521. /// </summary>
  522. public bool HasEmbeddedSource {
  523. get {
  524. bool retVal = false;
  525. private_document.HasEmbeddedSource(out retVal);
  526. return retVal;
  527. }
  528. }
  529. /// <summary>
  530. /// Gets the language guid
  531. /// </summary>
  532. public Guid Language {
  533. get {
  534. Guid retVal = new Guid();
  535. private_document.GetLanguage(ref retVal);
  536. return retVal;
  537. }
  538. }
  539. /// <summary>
  540. /// Gets the language vendor guid
  541. /// </summary>
  542. public Guid LanguageVendor {
  543. get {
  544. Guid retVal = new Guid();
  545. private_document.GetLanguageVendor(ref retVal);
  546. return retVal;
  547. }
  548. }
  549. /// <summary>
  550. /// Gets the source length of the current document
  551. /// </summary>
  552. public int SourceLength {
  553. get {
  554. int retVal = 0;
  555. private_document.GetSourceLength(out retVal);
  556. return retVal;
  557. }
  558. }
  559. /// <summary>
  560. /// Gets the URL of the current document
  561. /// </summary>
  562. public string URL {
  563. get {
  564. int strLen;
  565. private_document.GetURL(0, out strLen, null);
  566. StringBuilder retVal = new StringBuilder(strLen);
  567. private_document.GetURL(strLen, out strLen, retVal);
  568. return retVal.ToString();
  569. }
  570. }
  571. /// <summary>
  572. /// Gets the closest line that has a sequence point
  573. /// </summary>
  574. /// <param name="line">A line in the document</param>
  575. /// <returns>The closest line with a sequence point</returns>
  576. public int FindClosestLine(int line) {
  577. int retVal;
  578. private_document.FindClosestLine(line, out retVal);
  579. return retVal;
  580. }
  581. #region unimplemented methods
  582. /// <summary>
  583. /// Gets the checksum
  584. /// </summary>
  585. /// <returns>The checksum</returns>
  586. public byte[] GetCheckSum() {
  587. throw new NotImplementedException("No QUT.SymbolDocument.GetCheckSum");
  588. }
  589. //
  590. // Summary:
  591. // Gets the embedded document source for the specified range.
  592. //
  593. // Parameters:
  594. // startLine:
  595. // The starting line in the current document.
  596. //
  597. // endLine:
  598. // The ending line in the current document.
  599. //
  600. // startColumn:
  601. // The starting column in the current document.
  602. //
  603. // endColumn:
  604. // The ending column in the current document.
  605. //
  606. // Returns:
  607. // The document source for the specified range.
  608. public byte[] GetSourceRange(int startLine, int startColumn, int endLine, int endColumn) {
  609. throw new NotImplementedException("No QUT.SymbolDocument.GetSourceRange");
  610. }
  611. #endregion unimplemented methods
  612. }
  613. // ========================== End of SymbolDocument ===========================
  614. /// <summary>
  615. /// Managed wrapper for ISymUnmanagedVariable
  616. /// </summary>
  617. public class SymbolVariable : ISymbolVariable {
  618. private ISymUnmanagedVariable private_variable;
  619. internal SymbolVariable(ISymUnmanagedVariable unVar) {
  620. private_variable = unVar;
  621. }
  622. /// <summary>
  623. /// Gets the first address of the variable
  624. /// </summary>
  625. public int AddressField1 {
  626. get {
  627. int retVal;
  628. private_variable.GetAddressField1(out retVal);
  629. return retVal;
  630. }
  631. }
  632. /// <summary>
  633. /// Gets the second address of the variable
  634. /// </summary>
  635. public int AddressField2 {
  636. get {
  637. int retVal;
  638. private_variable.GetAddressField2(out retVal);
  639. return retVal;
  640. }
  641. }
  642. /// <summary>
  643. /// Gets the third address of the variable
  644. /// </summary>
  645. public int AddressField3 {
  646. get {
  647. int retVal;
  648. private_variable.GetAddressField3(out retVal);
  649. return retVal;
  650. }
  651. }
  652. /// <summary>
  653. /// Gets the type of the address. The result is a
  654. /// System.Diagnostics.SymbolStore.SymAddressKind
  655. /// enumeration value.
  656. /// </summary>
  657. public SymAddressKind AddressKind {
  658. get {
  659. int retVal;
  660. private_variable.GetAddressKind(out retVal);
  661. return (SymAddressKind)retVal;
  662. }
  663. }
  664. /// <summary>
  665. /// Gets the variable attributes
  666. /// </summary>
  667. public object Attributes {
  668. get {
  669. int retVal;
  670. private_variable.GetAttributes(out retVal);
  671. return retVal;
  672. }
  673. }
  674. /// <summary>
  675. /// Gets the end offset of the variable
  676. /// </summary>
  677. public int EndOffset {
  678. get {
  679. int retVal;
  680. private_variable.GetEndOffset(out retVal);
  681. return retVal;
  682. }
  683. }
  684. /// <summary>
  685. /// Gets the name of the variable
  686. /// </summary>
  687. public string Name {
  688. get {
  689. StringBuilder bldr;
  690. int nmLen = 0;
  691. private_variable.GetName(0, out nmLen, null);
  692. bldr = new StringBuilder(nmLen);
  693. private_variable.GetName(nmLen, out nmLen, bldr);
  694. return bldr.ToString();
  695. }
  696. }
  697. /// <summary>
  698. /// Gets the start offset of the variable
  699. /// </summary>
  700. public int StartOffset {
  701. get {
  702. int retVal;
  703. private_variable.GetStartOffset(out retVal);
  704. return retVal;
  705. }
  706. }
  707. /// <summary>
  708. /// Gets the variable signature
  709. /// </summary>
  710. /// <returns>The signature blob</returns>
  711. public byte[] GetSignature() {
  712. int sgLen;
  713. private_variable.GetSignature(0, out sgLen, null);
  714. byte[] retVal = new byte[sgLen];
  715. private_variable.GetSignature(sgLen, out sgLen, retVal);
  716. return retVal;
  717. }
  718. }
  719. // ========================== End of SymbolVariable ===========================
  720. }