Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

608 lines
8.1 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. dbgdev.cxx
  6. Abstract:
  7. Debug Device Interface class
  8. Author:
  9. Steve Kiraly (SteveKi) 10-Dec-1995
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "dbgdev.hxx"
  15. /*++
  16. Routine Name:
  17. TDebugDevice
  18. Routine Description:
  19. Constructor
  20. Arguments:
  21. pszConfiguration - pointer to colon separated configuration string.
  22. Return Value:
  23. Nothing
  24. --*/
  25. TDebugDevice::
  26. TDebugDevice(
  27. IN LPCTSTR pszConfiguration,
  28. IN EDebugType eDebugType
  29. ) : _pszConfiguration( NULL ),
  30. _eCharType( kUnknown ),
  31. _eDebugType( eDebugType ),
  32. TDebugNodeDouble()
  33. {
  34. //
  35. // If configuration data was provided.
  36. //
  37. if( pszConfiguration && _tcslen( pszConfiguration ) )
  38. {
  39. _pszConfiguration = INTERNAL_NEW TCHAR [ _tcslen( pszConfiguration ) + 1];
  40. //
  41. // Copy the configuration data.
  42. //
  43. if( _pszConfiguration )
  44. {
  45. _tcscpy( _pszConfiguration, pszConfiguration );
  46. //
  47. // Get the character type.
  48. //
  49. TIterator i( this );
  50. for( i.First(); !i.IsDone(); i.Next() )
  51. {
  52. //
  53. // The first item is defined as the character type.
  54. //
  55. if( i.Index() == 1 )
  56. {
  57. //
  58. // Look for the ansi specifier.
  59. //
  60. _eCharType = !_tcsicmp( i.Current(), kstrAnsi ) ? kAnsi : kUnicode;
  61. break;
  62. }
  63. }
  64. }
  65. }
  66. }
  67. /*++
  68. Routine Name:
  69. TDebugDevice
  70. Routine Description:
  71. Destructor releases the configuration string.
  72. Arguments:
  73. None.
  74. Return Value:
  75. Nothing
  76. --*/
  77. TDebugDevice::
  78. ~TDebugDevice(
  79. VOID
  80. )
  81. {
  82. INTERNAL_DELETE [] _pszConfiguration;
  83. }
  84. /*++
  85. Routine Name:
  86. bValid
  87. Routine Description:
  88. Valid object indicator.
  89. Arguments:
  90. None.
  91. Return Value:
  92. Nothing
  93. --*/
  94. BOOL
  95. TDebugDevice::
  96. bValid(
  97. VOID
  98. ) const
  99. {
  100. return TRUE;
  101. }
  102. /*++
  103. Routine Name:
  104. eGetCharType
  105. Routine Description:
  106. Retrives the devices character type.
  107. Arguments:
  108. None.
  109. Return Value:
  110. Devices character type
  111. --*/
  112. TDebugDevice::ECharType
  113. TDebugDevice::
  114. eGetCharType(
  115. VOID
  116. ) const
  117. {
  118. return _eCharType;
  119. }
  120. /*++
  121. Routine Name:
  122. eGetDeviceType
  123. Routine Description:
  124. Retrives the device type.
  125. Arguments:
  126. None.
  127. Return Value:
  128. Debug Device Type
  129. --*/
  130. EDebugType
  131. TDebugDevice::
  132. eGetDebugType(
  133. VOID
  134. ) const
  135. {
  136. return _eDebugType;
  137. }
  138. /*++
  139. Routine Name:
  140. pszGetConfigurationString
  141. Routine Description:
  142. Retrives the raw devices configuration string.
  143. Arguments:
  144. None.
  145. Return Value:
  146. Pointer to device configuration string.
  147. --*/
  148. LPCTSTR
  149. TDebugDevice::
  150. pszGetConfigurationString(
  151. VOID
  152. ) const
  153. {
  154. return _pszConfiguration;
  155. }
  156. /*++
  157. Routine Name:
  158. MapStringTypeToDevice
  159. Routine Description:
  160. Map the device string to a device enumeration.
  161. Arguments:
  162. pszDeviceString - pointer to device type string.
  163. Return Value:
  164. Device type enumeration
  165. --*/
  166. UINT
  167. TDebugDevice::
  168. MapStringTypeToDevice(
  169. IN LPCTSTR pszDeviceString
  170. ) const
  171. {
  172. DeviceMap aDeviceMap [] = { { kDbgNull, kstrDeviceNull},
  173. { kDbgConsole, kstrConsole },
  174. { kDbgDebugger, kstrDebugger },
  175. { kDbgFile, kstrFile },
  176. { kDbgBackTrace, kstrBacktrace } };
  177. for( UINT i = 0; i < COUNTOF( aDeviceMap ); i++ )
  178. {
  179. if( !_tcsicmp( aDeviceMap[i].Name, pszDeviceString ) )
  180. {
  181. return aDeviceMap[i].Id;
  182. }
  183. }
  184. return kDbgNull;
  185. }
  186. /********************************************************************
  187. Debug Iterator device class.
  188. ********************************************************************/
  189. /*++
  190. Routine Name:
  191. TIterator
  192. Routine Description:
  193. Constructor
  194. Arguments:
  195. pszConfiguration - pointer to colon separated configuration string.
  196. Return Value:
  197. Nothing
  198. --*/
  199. TDebugDevice::TIterator::
  200. TIterator(
  201. IN TDebugDevice *DbgDevice
  202. ) : _pStr( NULL ),
  203. _pCurrent( NULL ),
  204. _pEnd( NULL ),
  205. _bValid( FALSE ),
  206. _uIndex( 0 )
  207. {
  208. //
  209. // Make a copy of the configuration string for iteration.
  210. // The configuration string is defined as a colon delimited
  211. // string, the iterator needs a copy because it replaces the
  212. // colons with nulls for isolating its pieces.
  213. //
  214. if( DbgDevice->_pszConfiguration && _tcslen( DbgDevice->_pszConfiguration ) )
  215. {
  216. _pStr = INTERNAL_NEW TCHAR [ _tcslen(DbgDevice->_pszConfiguration) + 1 ];
  217. if( _pStr )
  218. {
  219. _tcscpy( _pStr, DbgDevice->_pszConfiguration );
  220. _bValid = TRUE;
  221. }
  222. }
  223. }
  224. /*++
  225. Routine Name:
  226. TIterator
  227. Routine Description:
  228. Destructor
  229. Arguments:
  230. None.
  231. Return Value:
  232. Nothing
  233. --*/
  234. TDebugDevice::TIterator::
  235. ~TIterator(
  236. VOID
  237. )
  238. {
  239. INTERNAL_DELETE [] _pStr;
  240. }
  241. /*++
  242. Routine Name:
  243. bValid
  244. Routine Description:
  245. Indicates if this class is valid.
  246. Arguments:
  247. None.
  248. Return Value:
  249. TRUE valid, FALSE invalid.
  250. --*/
  251. BOOL
  252. TDebugDevice::TIterator::
  253. bValid(
  254. VOID
  255. ) const
  256. {
  257. return _bValid;
  258. }
  259. /*++
  260. Routine Name:
  261. First
  262. Routine Description:
  263. Starts the interator.
  264. Arguments:
  265. None.
  266. Return Value:
  267. Nothing
  268. --*/
  269. VOID
  270. TDebugDevice::TIterator::
  271. First(
  272. VOID
  273. )
  274. {
  275. if( !_bValid )
  276. return;
  277. //
  278. // If running iteration was reset with a first call
  279. // Put back the colon.
  280. //
  281. if( _pEnd )
  282. *_pEnd = _T(':');
  283. //
  284. // Reset index.
  285. //
  286. _uIndex = 1;
  287. //
  288. // Skip leading colons
  289. //
  290. for( _pCurrent = _pStr; *_pCurrent && *_pCurrent == _T(':'); _pCurrent++);
  291. //
  292. // Search for next colon.
  293. //
  294. for( _pEnd = _pCurrent; *_pEnd && *_pEnd != _T(':'); _pEnd++);
  295. //
  296. // Place the null to complete the string.
  297. //
  298. if( *_pEnd )
  299. *_pEnd = NULL;
  300. else
  301. _pEnd = NULL;
  302. }
  303. /*++
  304. Routine Name:
  305. Next
  306. Routine Description:
  307. Advance to the next item.
  308. Arguments:
  309. None.
  310. Return Value:
  311. Nothing
  312. --*/
  313. VOID
  314. TDebugDevice::TIterator::
  315. Next(
  316. VOID
  317. )
  318. {
  319. if( !_bValid )
  320. return;
  321. //
  322. // If iteration is pending put back the colon and advance
  323. // to the next character.
  324. //
  325. if( _pEnd )
  326. {
  327. *_pEnd = _T(':');
  328. _pEnd++;
  329. }
  330. else
  331. {
  332. //
  333. // End iteration, defined as _pCurrent == _pEnd == NULL
  334. //
  335. _pCurrent = _pEnd;
  336. return;
  337. }
  338. //
  339. // Update current.
  340. //
  341. _pCurrent = _pEnd;
  342. //
  343. // Skip leading colons
  344. //
  345. for( ; *_pCurrent && *_pCurrent == _T(':'); _pCurrent++);
  346. //
  347. // Advance to the end of the current item.
  348. //
  349. for( _pEnd = _pCurrent; *_pEnd && *_pEnd != _T(':'); _pEnd++);
  350. //
  351. // Replace colon with a null
  352. //
  353. if( *_pEnd )
  354. *_pEnd = NULL;
  355. else
  356. _pEnd = NULL;
  357. _uIndex++;
  358. }
  359. /*++
  360. Routine Name:
  361. IsDone
  362. Routine Description:
  363. Indicates if there are any more items.
  364. Arguments:
  365. None.
  366. Return Value:
  367. TRUE no mote items, FALSE more items availabe.
  368. --*/
  369. BOOL
  370. TDebugDevice::TIterator::
  371. IsDone(
  372. VOID
  373. ) const
  374. {
  375. if( !_bValid )
  376. return TRUE;
  377. if( _pCurrent == NULL && _pEnd == NULL )
  378. return TRUE;
  379. return FALSE;
  380. }
  381. /*++
  382. Routine Name:
  383. Current
  384. Routine Description:
  385. Returns pointer to current item.
  386. Arguments:
  387. None.
  388. Return Value:
  389. Pointer to item. NULL if no more items, or error.
  390. --*/
  391. LPCTSTR
  392. TDebugDevice::TIterator::
  393. Current(
  394. VOID
  395. ) const
  396. {
  397. if( !_bValid )
  398. return NULL;
  399. return _pCurrent;
  400. }
  401. /*++
  402. Routine Name:
  403. Index
  404. Routine Description:
  405. Returns current item index.
  406. Arguments:
  407. None.
  408. Return Value:
  409. Index starting with 1 to N
  410. --*/
  411. UINT
  412. TDebugDevice::TIterator::
  413. Index(
  414. VOID
  415. ) const
  416. {
  417. if( !_bValid )
  418. return 0;
  419. return _uIndex;
  420. }