exp_dbg.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /* exp_dbg.c: Routines to export debugging information
  2. Copyright (C) 2002-2004 Sebastian Reichelt
  3. Copyright (C) 2005 Kevin Kofler
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  15. #ifdef DEBUGGING_INFO_SUPPORT
  16. /* The format exported by these routines is a COFF file containing both the
  17. actual program and the debugging information (which is stripped out of the
  18. on-calc executable). They are actually object files, but with a ".dbg"
  19. extension to distinguish them from ordinary object files. These files can be
  20. read in by GDB as integrated into TiEmu.
  21. Note that this means that this has to be plain vanilla COFF, NO TIGCC
  22. extensions such as unoptimizable relocs are allowed, unless you are willing
  23. to implement these in GDB/BFD as well. And I really mean IMPLEMENT, not
  24. ignore, cluttering this file with information not used by GDB is useless. As
  25. this format isn't used for linking anyway, the restrictions on the format are
  26. not a problem, and it is pointless to add things not used by GDB. Using
  27. debugging information files for linking purposes or any other non-debugging
  28. purpose is NOT supported. This is NOT a "relocatable linking" feature.
  29. Implementing actual relocatable linking (linking multiple object files into a
  30. single object file) starting from this code is probably possible, but this
  31. code needs to be separate, as relocatable linking SHOULD use TIGCC extensions
  32. in order not to lose information. You'll also have to special-case the
  33. relocatable linking all over the place for things like global imports,
  34. startup sections, merging sections and so on.
  35. -- Kevin Kofler */
  36. #include "exp_dbg.h"
  37. #include "../formats/coff.h"
  38. #include "../manip.h"
  39. #include "../special.h"
  40. #include <string.h>
  41. #define MAX_NAMED_SECTION (3+DI_LAST)
  42. #define FIRST_SECTION_ID_WITH_ZERO_VADDR 4
  43. typedef struct {
  44. OFFSET FileOffset;
  45. OFFSET VirtualOffset;
  46. EXP_FILE *File;
  47. COUNT COFFSectionNumber;
  48. } SectionOffsets;
  49. static OFFSET VAddrs[MAX_NAMED_SECTION+1];
  50. static COUNT SectionID;
  51. static const char *SectionFullNames[MAX_NAMED_SECTION] =
  52. {".text", ".data", ".bss", ".deleted", ".stab", ".stabstr",
  53. ".debug_abbrev", ".debug_aranges",
  54. ".debug_frame", ".debug_info", ".debug_line",
  55. ".debug_loc", ".debug_macinfo",
  56. ".debug_pubnames", ".debug_ranges", ".debug_str",
  57. ".eh_frame"};
  58. // These really ought to be written in LISP rather than C, but...
  59. static void ApplyIfNonNull(void (*f)(const SECTION *, void *),
  60. const SECTION *Section, void *UserData)
  61. {
  62. if (Section)
  63. f (Section, UserData);
  64. SectionID++;
  65. }
  66. static void MapToAllSections(const PROGRAM *Program, void (*f)(const SECTION *, void *), void *UserData)
  67. {
  68. COUNT i;
  69. SectionID = 0;
  70. ApplyIfNonNull (f, Program->MainSection, UserData);
  71. ApplyIfNonNull (f, Program->DataSection, UserData);
  72. ApplyIfNonNull (f, Program->BSSSection, UserData);
  73. for (i = 0; i < DI_LAST; i++)
  74. ApplyIfNonNull (f, Program->DebuggingInfoSection[i], UserData);
  75. }
  76. static void CountSectionCOFFSize (const SECTION *Section, void *UserData)
  77. {
  78. SIZE Size = sizeof(COFF_SECTION);
  79. const SYMBOL *Symbol;
  80. const RELOC *Reloc;
  81. // The accumulated size should always be at least sizeof(COFF_HEADER) + 4.
  82. // Everything else means there was an error.
  83. if (!*(SIZE *)UserData)
  84. return;
  85. if (Section->Data)
  86. Size += Section->Size;
  87. // Section symbol
  88. {
  89. COUNT NameLen = strlen (SectionFullNames[SectionID]);
  90. // Symbol table entry
  91. Size += sizeof (COFF_SYMBOL);
  92. // String table entry
  93. if (NameLen > 8)
  94. Size += NameLen + 1;
  95. }
  96. for_each (Symbol, Section->Symbols)
  97. {
  98. COUNT NameLen = strlen (Symbol->Name);
  99. // Symbol table entry
  100. Size += sizeof (COFF_SYMBOL);
  101. // String table entry
  102. if (NameLen > 8)
  103. Size += NameLen + 1;
  104. }
  105. for_each (Reloc, Section->Relocs)
  106. {
  107. // If this can be resolved to a calculator-dependent value, ignore the
  108. // reloc for now.
  109. if (IsPlainCalcBuiltin (Reloc))
  110. continue;
  111. // We can only emit 4-byte absolute relocs.
  112. if (Reloc->Relative || (Reloc->Size != 4))
  113. {
  114. Error (GetFileName (Section, Reloc->Location), "Cannot emit %ld byte %s reloc to `%s'.", (long) Reloc->Size, Reloc->Relative ? "relative" : "absolute", Reloc->Target.SymbolName);
  115. *(SIZE *)UserData = 0;
  116. return;
  117. }
  118. // Reloc table entry
  119. Size += sizeof (COFF_RELOC);
  120. }
  121. *(SIZE *)UserData += Size;
  122. }
  123. // Get the file size needed to export the debugging information file.
  124. // Returns 0 on failure.
  125. // Call this function once to receive necessary error messages.
  126. static SIZE GetDebuggingInfoFileSize (const PROGRAM *Program)
  127. {
  128. // The "+ 4" is for the size of the string table.
  129. SIZE Size = sizeof(COFF_HEADER) + 4;
  130. MapToAllSections (Program, CountSectionCOFFSize, &Size);
  131. return Size;
  132. }
  133. static void CompareSections (const SECTION *Section, void *UserData)
  134. {
  135. if (*(const SECTION **)UserData == Section)
  136. *(const SECTION **)UserData = NULL;
  137. }
  138. static void AddOne (const SECTION *Section ATTRIBUTE_UNUSED, void *UserData)
  139. {
  140. (*(COUNT *)UserData)++;
  141. }
  142. static void CountSymbols (const SECTION *Section, void *UserData)
  143. {
  144. const SYMBOL *Symbol;
  145. (*(COUNT *)UserData)++; // section symbol
  146. for_each (Symbol, Section->Symbols)
  147. {
  148. (*(COUNT *)UserData)++;
  149. }
  150. }
  151. static void CountSymbolTableOffset (const SECTION *Section, void *UserData)
  152. {
  153. SIZE Size = 0;
  154. const RELOC *Reloc;
  155. if (Section->Data)
  156. Size = Section->Size;
  157. for_each (Reloc, Section->Relocs)
  158. {
  159. // If this can be resolved to a calculator-dependent value, ignore the
  160. // reloc for now.
  161. if (IsPlainCalcBuiltin (Reloc))
  162. continue;
  163. // Reloc table entry
  164. Size += sizeof (COFF_RELOC);
  165. }
  166. *(OFFSET *)UserData += Size;
  167. }
  168. static void WriteSectionHeader (const SECTION *Section, void *UserData)
  169. {
  170. static const char SectionNames[MAX_NAMED_SECTION][COFF_SECTION_NAME_LEN] =
  171. {".text", ".data", ".bss", ".deleted", ".stab",
  172. ".stabstr", ".debug_a"/*bbrev*/, ".debug_a"/*ranges*/,
  173. ".debug_f"/*rame*/, ".debug_i"/*nfo*/, ".debug_l"/*ine*/,
  174. ".debug_l"/*oc*/, ".debug_m"/*acinfo*/,
  175. ".debug_p"/*ubnames*/, ".debug_r"/*anges*/,
  176. ".debug_s"/*tr*/, ".eh_fram"/*e*/};
  177. static const I4 SectionFlags[MAX_NAMED_SECTION] =
  178. {COFF_SECTION_TEXT, COFF_SECTION_DATA, COFF_SECTION_BSS,
  179. COFF_SECTION_TEXT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  180. SIZE Size = 0;
  181. const RELOC *Reloc;
  182. COUNT RelocCount = 0;
  183. COFF_SECTION COFFSectionHeader;
  184. OFFSET VAddr = SectionID < FIRST_SECTION_ID_WITH_ZERO_VADDR ?
  185. ((SectionOffsets *)UserData)->VirtualOffset : 0;
  186. VAddrs[++(((SectionOffsets *)UserData)->COFFSectionNumber)] = VAddr;
  187. if (Section->Data)
  188. Size = Section->Size;
  189. for_each (Reloc, Section->Relocs)
  190. {
  191. // If this can be resolved to a calculator-dependent value, ignore the
  192. // reloc for now.
  193. if (IsPlainCalcBuiltin (Reloc))
  194. continue;
  195. // Reloc table entry
  196. Size += sizeof (COFF_RELOC);
  197. RelocCount++;
  198. }
  199. memcpy (COFFSectionHeader.Name, SectionNames[SectionID], COFF_SECTION_NAME_LEN);
  200. WriteTI4 (COFFSectionHeader.PhysicalAddress, ((SectionOffsets *)UserData)->VirtualOffset);
  201. WriteTI4 (COFFSectionHeader.VirtualAddress, VAddr);
  202. WriteTI4 (COFFSectionHeader.Size, Section->Size);
  203. if (Section->Data)
  204. {
  205. WriteTI4 (COFFSectionHeader.PData, ((SectionOffsets *)UserData)->FileOffset);
  206. WriteTI4 (COFFSectionHeader.PRelocs, ((SectionOffsets *)UserData)->FileOffset + Section->Size);
  207. }
  208. else
  209. {
  210. WriteTI4 (COFFSectionHeader.PData, 0);
  211. WriteTI4 (COFFSectionHeader.PRelocs, ((SectionOffsets *)UserData)->FileOffset);
  212. }
  213. WriteTI4 (COFFSectionHeader.PLines, 0);
  214. WriteTI2 (COFFSectionHeader.RelocCount, RelocCount);
  215. WriteTI2 (COFFSectionHeader.LineCount, 0);
  216. WriteTI4 (COFFSectionHeader.Flags, SectionFlags[SectionID]);
  217. ExportWrite (((SectionOffsets *)UserData)->File, &COFFSectionHeader, sizeof (COFF_SECTION), 1);
  218. ((SectionOffsets *)UserData)->FileOffset += Size;
  219. ((SectionOffsets *)UserData)->VirtualOffset += Section->Size;
  220. }
  221. typedef struct {
  222. const SECTION *Section;
  223. COUNT Current;
  224. COUNT Number;
  225. } COFFSectionNumberStruct;
  226. static void FindCOFFSectionNumber (const SECTION *Section, void *UserData)
  227. {
  228. ((COFFSectionNumberStruct *)UserData)->Current++;
  229. if (((COFFSectionNumberStruct *)UserData)->Section == Section)
  230. ((COFFSectionNumberStruct *)UserData)->Number = ((COFFSectionNumberStruct *)UserData)->Current;
  231. }
  232. static COUNT GetCOFFSectionNumber (const SECTION *Section)
  233. {
  234. COFFSectionNumberStruct COFFSectionNumber = {Section, 0, 0};
  235. MapToAllSections (Section->Parent, FindCOFFSectionNumber, &COFFSectionNumber);
  236. return COFFSectionNumber.Number;
  237. }
  238. typedef struct {
  239. const SYMBOL *Symbol;
  240. COUNT Current;
  241. COUNT Number;
  242. } COFFSymbolNumberStruct;
  243. static void FindCOFFSymbolNumber (const SECTION *Section, void *UserData)
  244. {
  245. const SYMBOL *Symbol;
  246. if (((COFFSymbolNumberStruct *)UserData)->Number) return;
  247. ((COFFSymbolNumberStruct *)UserData)->Current++; // section symbol
  248. for_each (Symbol, Section->Symbols)
  249. {
  250. if (((COFFSymbolNumberStruct *)UserData)->Symbol == Symbol)
  251. {
  252. ((COFFSymbolNumberStruct *)UserData)->Number = ((COFFSymbolNumberStruct *)UserData)->Current;
  253. return;
  254. }
  255. ((COFFSymbolNumberStruct *)UserData)->Current++;
  256. }
  257. }
  258. static COUNT GetCOFFSymbolNumber (const SYMBOL *Symbol)
  259. {
  260. COFFSymbolNumberStruct COFFSymbolNumber = {Symbol, 0, 0};
  261. MapToAllSections (Symbol->Parent->Parent, FindCOFFSymbolNumber, &COFFSymbolNumber);
  262. return COFFSymbolNumber.Number;
  263. }
  264. static void PatchRelocOffsetsIn (const SECTION *Section, void *UserData ATTRIBUTE_UNUSED)
  265. {
  266. const RELOC *Reloc;
  267. for_each (Reloc, Section->Relocs)
  268. {
  269. // If this can be resolved to a calculator-dependent value, ignore the
  270. // reloc for now.
  271. if (IsPlainCalcBuiltin (Reloc))
  272. continue;
  273. if (Section->Data)
  274. {
  275. const SECTION *RelocSection = Reloc->Target.Symbol->Parent;
  276. OFFSET RelocVirtualOffset = GetLocationOffset (RelocSection, &(Reloc->Target)) + Reloc->FixedOffset;
  277. RelocVirtualOffset += VAddrs[GetCOFFSectionNumber (RelocSection)];
  278. WriteTI4 (*(TI4 *)(Section->Data + Reloc->Location), RelocVirtualOffset);
  279. }
  280. else
  281. Error (GetFileName (Section, Reloc->Location), "Reloc at %lx in BSS section.", (unsigned long) Reloc->Relation);
  282. }
  283. }
  284. static void WriteSectionContents (const SECTION *Section, void *UserData)
  285. {
  286. const RELOC *Reloc;
  287. COUNT COFFSectionNumber = ++(((SectionOffsets *)UserData)->COFFSectionNumber);
  288. OFFSET VAddr = VAddrs[COFFSectionNumber];
  289. // Write section data.
  290. if (Section->Data)
  291. ExportWrite (((SectionOffsets *)UserData)->File, Section->Data, Section->Size, 1);
  292. // Write reloc table.
  293. for_each (Reloc, Section->Relocs)
  294. {
  295. COFF_RELOC COFFReloc;
  296. // If this can be resolved to a calculator-dependent value, ignore the
  297. // reloc for now.
  298. if (IsPlainCalcBuiltin (Reloc))
  299. continue;
  300. WriteTI4 (COFFReloc.Location, VAddr + Reloc->Location);
  301. WriteTI4 (COFFReloc.Symbol, GetCOFFSymbolNumber (Reloc->Target.Symbol));
  302. WriteTI2 (COFFReloc.Type, COFF_RELOC_ABS4);
  303. ExportWrite (((SectionOffsets *)UserData)->File, &COFFReloc, sizeof (COFF_RELOC), 1);
  304. }
  305. }
  306. static void PatchRelocOffsetsOut (const SECTION *Section, void *UserData ATTRIBUTE_UNUSED)
  307. {
  308. const RELOC *Reloc;
  309. for_each (Reloc, Section->Relocs)
  310. {
  311. // If this can be resolved to a calculator-dependent value, ignore the
  312. // reloc for now.
  313. if (IsPlainCalcBuiltin (Reloc))
  314. continue;
  315. if (Section->Data)
  316. WriteTI4 (*(TI4 *)(Section->Data + Reloc->Location), 0);
  317. }
  318. }
  319. static void WriteSymbolTable (const SECTION *Section, void *UserData)
  320. {
  321. const SYMBOL *Symbol;
  322. COUNT COFFSectionNumber = ++(((SectionOffsets *)UserData)->COFFSectionNumber);
  323. OFFSET VAddr = VAddrs[COFFSectionNumber];
  324. // Create a new section symbol with exactly the intended name to get around
  325. // the 8 char section name limit.
  326. {
  327. COFF_SYMBOL COFFSymbol;
  328. const char *SectionName = SectionFullNames[SectionID];
  329. COUNT NameLen = strlen (SectionName);
  330. if (NameLen > 8)
  331. {
  332. // String table entry
  333. WriteTI4(*(TI4*)(COFFSymbol.Name.Name), 0);
  334. WriteTI4(COFFSymbol.Name.StringRef.StringOffset, ((SectionOffsets *)UserData)->FileOffset);
  335. ((SectionOffsets *)UserData)->FileOffset += NameLen + 1;
  336. }
  337. else
  338. {
  339. memset (COFFSymbol.Name.Name, 0, 8);
  340. strncpy (COFFSymbol.Name.Name, SectionName, 8);
  341. }
  342. WriteTI4 (COFFSymbol.Value, VAddr);
  343. WriteTI2 (COFFSymbol.Section, COFFSectionNumber);
  344. WriteTI2 (COFFSymbol.Type, 0);
  345. WriteTI1 (COFFSymbol.Class, COFF_SYMBOL_LABEL);
  346. WriteTI1 (COFFSymbol.AuxSymbolCount, 0);
  347. ExportWrite (((SectionOffsets *)UserData)->File, &COFFSymbol, sizeof (COFF_SYMBOL), 1);
  348. }
  349. for_each (Symbol, Section->Symbols)
  350. {
  351. COFF_SYMBOL COFFSymbol;
  352. COUNT NameLen = strlen (Symbol->Name);
  353. if (NameLen > 8)
  354. {
  355. // String table entry
  356. WriteTI4(*(TI4*)(COFFSymbol.Name.Name), 0);
  357. WriteTI4(COFFSymbol.Name.StringRef.StringOffset, ((SectionOffsets *)UserData)->FileOffset);
  358. ((SectionOffsets *)UserData)->FileOffset += NameLen + 1;
  359. }
  360. else
  361. {
  362. memset (COFFSymbol.Name.Name, 0, 8);
  363. strncpy (COFFSymbol.Name.Name, Symbol->Name, 8);
  364. }
  365. WriteTI4 (COFFSymbol.Value, VAddr + Symbol->Location);
  366. WriteTI2 (COFFSymbol.Section, COFFSectionNumber);
  367. WriteTI2 (COFFSymbol.Type, 0);
  368. WriteTI1 (COFFSymbol.Class, Symbol->Exported ? COFF_SYMBOL_EXTERNAL : COFF_SYMBOL_LABEL);
  369. WriteTI1 (COFFSymbol.AuxSymbolCount, 0);
  370. ExportWrite (((SectionOffsets *)UserData)->File, &COFFSymbol, sizeof (COFF_SYMBOL), 1);
  371. }
  372. }
  373. static void WriteStringTable (const SECTION *Section, void *UserData)
  374. {
  375. const SYMBOL *Symbol;
  376. // Section symbol
  377. {
  378. COUNT NameLen = strlen (SectionFullNames[SectionID]);
  379. if (NameLen > 8)
  380. {
  381. // String table entry
  382. ExportWrite ((EXP_FILE *)UserData, SectionFullNames[SectionID], NameLen + 1, 1);
  383. }
  384. }
  385. for_each (Symbol, Section->Symbols)
  386. {
  387. COUNT NameLen = strlen (Symbol->Name);
  388. if (NameLen > 8)
  389. {
  390. // String table entry
  391. ExportWrite ((EXP_FILE *)UserData, Symbol->Name, NameLen + 1, 1);
  392. }
  393. }
  394. }
  395. // Export the internal data structures into a TIOS file.
  396. static BOOLEAN ExportDebuggingInfoFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileSize ATTRIBUTE_UNUSED)
  397. {
  398. COFF_HEADER COFFHeader;
  399. COUNT SectionCount = 0;
  400. COUNT SymbolCount = 0;
  401. SectionOffsets CurrentSectionOffsets;
  402. OFFSET SymbolTableOffset;
  403. const SECTION *Section;
  404. // Check if the file is valid
  405. for_each (Section, Program->Sections)
  406. {
  407. const SECTION *UserData = Section;
  408. MapToAllSections (Program, CompareSections, &UserData);
  409. if (UserData)
  410. Warning (Section->FileName, "Ignoring unmerged section %s",
  411. Section->SectionSymbol->Name);
  412. }
  413. // Write the COFF header
  414. MapToAllSections (Program, AddOne, &SectionCount);
  415. MapToAllSections (Program, CountSymbols, &SymbolCount);
  416. SymbolTableOffset = sizeof (COFF_HEADER) + SectionCount * sizeof (COFF_SECTION);
  417. MapToAllSections (Program, CountSymbolTableOffset, &SymbolTableOffset);
  418. WriteTI2 (COFFHeader.Machine, COFF_MACHINE_M68K);
  419. WriteTI2 (COFFHeader.SectionCount, SectionCount);
  420. WriteTI4 (COFFHeader.TimeStamp, 0);
  421. WriteTI4 (COFFHeader.PSymbols, SymbolTableOffset);
  422. WriteTI4 (COFFHeader.SymbolCount, SymbolCount);
  423. WriteTI2 (COFFHeader.OptHdrSize, 0);
  424. WriteTI2 (COFFHeader.Flags, (COFF_FLAG_32BIT_BE | COFF_FLAG_NO_LINE_NUMBERS));
  425. ExportWrite (File, &COFFHeader, sizeof (COFF_HEADER), 1);
  426. // Write the section headers
  427. CurrentSectionOffsets.FileOffset = sizeof (COFF_HEADER) + SectionCount * sizeof (COFF_SECTION);
  428. CurrentSectionOffsets.VirtualOffset = 0;
  429. CurrentSectionOffsets.File = File;
  430. CurrentSectionOffsets.COFFSectionNumber = 0;
  431. MapToAllSections (Program, WriteSectionHeader, &CurrentSectionOffsets);
  432. // Write the section contents
  433. MapToAllSections (Program, PatchRelocOffsetsIn, NULL);
  434. CurrentSectionOffsets.COFFSectionNumber = 0;
  435. MapToAllSections (Program, WriteSectionContents, &CurrentSectionOffsets);
  436. MapToAllSections (Program, PatchRelocOffsetsOut, NULL);
  437. // Write the symbol table
  438. CurrentSectionOffsets.FileOffset = 4; // skip the string table size
  439. CurrentSectionOffsets.COFFSectionNumber = 0;
  440. MapToAllSections (Program, WriteSymbolTable, &CurrentSectionOffsets);
  441. // Write the string table
  442. ExportWriteTI4 (File, CurrentSectionOffsets.FileOffset); // size
  443. MapToAllSections (Program, WriteStringTable, File);
  444. return TRUE;;
  445. }
  446. // Export the debugging information to a .dbg file.
  447. // This function is a modified version of ExportProgramToFormat.
  448. BOOLEAN ExportDebuggingInfo (const PROGRAM *Program, OUTPUT_FILE_FUNCTION GetOutputFile, OUTPUT_FILE_FINALIZE_FUNCTION FinalizeOutputFile)
  449. {
  450. BOOLEAN Success;
  451. EXP_FILE File;
  452. SIZE Size;
  453. I4 EffectiveSize = 0;
  454. // Fill the output file struct with zeroes.
  455. memset (&File, 0, sizeof (File));
  456. // Get the file size needed to export the file.
  457. Size = GetDebuggingInfoFileSize (Program);
  458. // A size of 0 indicates an error.
  459. if (Size <= 0)
  460. return FALSE;
  461. // Create an output file with the specified format.
  462. if (!(GetOutputFile (&(File.File), Size, 0, FR_DEBUGGING_INFO, FF_GDB_COFF, 0, NULL, FALSE, &EffectiveSize)))
  463. return FALSE;
  464. // Export the program into the output file.
  465. Success = ExportDebuggingInfoFile (Program, &File, Size);
  466. // Finalize and close the output file.
  467. if (FinalizeOutputFile)
  468. FinalizeOutputFile (&(File.File));
  469. return Success;
  470. }
  471. #endif /* DEBUGGING_INFO_SUPPORT */