vmsdbgout.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831
  1. /* Output VMS debug format symbol table information from GCC.
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. Contributed by Douglas B. Rupp (rupp@gnat.com).
  4. Updated by Bernard W. Giroud (bgiroud@users.sourceforge.net).
  5. This file is part of GCC.
  6. GCC is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation; either version 3, or (at your option) any later
  9. version.
  10. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GCC; see the file COPYING3. If not see
  16. <http://www.gnu.org/licenses/>. */
  17. #include "config.h"
  18. #include "system.h"
  19. #include "coretypes.h"
  20. #include "tm.h"
  21. #ifdef VMS_DEBUGGING_INFO
  22. #include "hash-set.h"
  23. #include "machmode.h"
  24. #include "vec.h"
  25. #include "double-int.h"
  26. #include "input.h"
  27. #include "alias.h"
  28. #include "symtab.h"
  29. #include "wide-int.h"
  30. #include "inchash.h"
  31. #include "tree.h"
  32. #include "varasm.h"
  33. #include "version.h"
  34. #include "flags.h"
  35. #include "rtl.h"
  36. #include "output.h"
  37. #include "vmsdbg.h"
  38. #include "debug.h"
  39. #include "langhooks.h"
  40. #include "hard-reg-set.h"
  41. #include "input.h"
  42. #include "function.h"
  43. #include "target.h"
  44. /* Difference in seconds between the VMS Epoch and the Unix Epoch */
  45. static const long long vms_epoch_offset = 3506716800ll;
  46. int vms_file_stats_name (const char *, long long *, long *, char *, int *);
  47. /* NOTE: In the comments in this file, many references are made to "Debug
  48. Symbol Table". This term is abbreviated as `DST' throughout the remainder
  49. of this file. */
  50. typedef struct dst_line_info_struct *dst_line_info_ref;
  51. /* Each entry in the line_info_table maintains the file and
  52. line number associated with the label generated for that
  53. entry. The label gives the PC value associated with
  54. the line number entry. */
  55. typedef struct dst_line_info_struct
  56. {
  57. unsigned long dst_file_num;
  58. unsigned long dst_line_num;
  59. }
  60. dst_line_info_entry;
  61. typedef struct dst_file_info_struct *dst_file_info_ref;
  62. typedef struct dst_file_info_struct
  63. {
  64. char *file_name;
  65. unsigned int max_line;
  66. unsigned int listing_line_start;
  67. long long cdt;
  68. long ebk;
  69. short ffb;
  70. char rfo;
  71. }
  72. dst_file_info_entry;
  73. /* Maximum size (in bytes) of an artificially generated label. */
  74. #define MAX_ARTIFICIAL_LABEL_BYTES 30
  75. /* Make sure we know the sizes of the various types debug can describe. These
  76. are only defaults. If the sizes are different for your target, you should
  77. override these values by defining the appropriate symbols in your tm.h
  78. file. */
  79. #ifndef PTR_SIZE
  80. #define PTR_SIZE 4 /* Must be 32 bits for VMS debug info */
  81. #endif
  82. /* Pointer to a structure of filenames referenced by this compilation unit. */
  83. static dst_file_info_ref file_info_table;
  84. /* Total number of entries in the table (i.e. array) pointed to by
  85. `file_info_table'. This is the *total* and includes both used and unused
  86. slots. */
  87. static unsigned int file_info_table_allocated;
  88. /* Number of entries in the file_info_table which are actually in use. */
  89. static unsigned int file_info_table_in_use;
  90. /* Size (in elements) of increments by which we may expand the filename
  91. table. */
  92. #define FILE_TABLE_INCREMENT 64
  93. typedef char *char_p;
  94. static vec<char_p> funcnam_table;
  95. static vec<unsigned> funcnum_table;
  96. #define FUNC_TABLE_INITIAL 256
  97. /* Local pointer to the name of the main input file. Initialized in
  98. vmsdbgout_init. */
  99. static const char *primary_filename;
  100. static char *module_producer;
  101. static unsigned int module_language;
  102. /* A pointer to the base of a table that contains line information
  103. for each source code line in .text in the compilation unit. */
  104. static dst_line_info_ref line_info_table;
  105. /* Number of elements currently allocated for line_info_table. */
  106. static unsigned int line_info_table_allocated;
  107. /* Number of elements in line_info_table currently in use. */
  108. static unsigned int line_info_table_in_use;
  109. /* Size (in elements) of increments by which we may expand line_info_table. */
  110. #define LINE_INFO_TABLE_INCREMENT 1024
  111. /* Forward declarations for functions defined in this file. */
  112. static char *full_name (const char *);
  113. static unsigned int lookup_filename (const char *);
  114. static int write_debug_header (DST_HEADER *, const char *, int);
  115. static int write_debug_addr (const char *, const char *, int);
  116. static int write_debug_data1 (unsigned int, const char *, int);
  117. static int write_debug_data2 (unsigned int, const char *, int);
  118. static int write_debug_data4 (unsigned long, const char *, int);
  119. static int write_debug_data8 (unsigned long long, const char *, int);
  120. static int write_debug_delta4 (const char *, const char *, const char *, int);
  121. static int write_debug_string (const char *, const char *, int);
  122. static int write_modbeg (int);
  123. static int write_modend (int);
  124. static int write_rtnbeg (int, int);
  125. static int write_rtnend (int, int);
  126. static int write_pclines (int);
  127. static int write_srccorr (int, dst_file_info_entry, int);
  128. static int write_srccorrs (int);
  129. static void vmsdbgout_init (const char *);
  130. static void vmsdbgout_finish (const char *);
  131. static void vmsdbgout_assembly_start (void);
  132. static void vmsdbgout_define (unsigned int, const char *);
  133. static void vmsdbgout_undef (unsigned int, const char *);
  134. static void vmsdbgout_start_source_file (unsigned int, const char *);
  135. static void vmsdbgout_end_source_file (unsigned int);
  136. static void vmsdbgout_begin_block (unsigned int, unsigned int);
  137. static void vmsdbgout_end_block (unsigned int, unsigned int);
  138. static bool vmsdbgout_ignore_block (const_tree);
  139. static void vmsdbgout_source_line (unsigned int, const char *, int, bool);
  140. static void vmsdbgout_write_source_line (unsigned, const char *, int , bool);
  141. static void vmsdbgout_begin_prologue (unsigned int, const char *);
  142. static void vmsdbgout_end_prologue (unsigned int, const char *);
  143. static void vmsdbgout_end_function (unsigned int);
  144. static void vmsdbgout_begin_epilogue (unsigned int, const char *);
  145. static void vmsdbgout_end_epilogue (unsigned int, const char *);
  146. static void vmsdbgout_begin_function (tree);
  147. static void vmsdbgout_decl (tree);
  148. static void vmsdbgout_global_decl (tree);
  149. static void vmsdbgout_type_decl (tree, int);
  150. static void vmsdbgout_abstract_function (tree);
  151. /* The debug hooks structure. */
  152. const struct gcc_debug_hooks vmsdbg_debug_hooks
  153. = {vmsdbgout_init,
  154. vmsdbgout_finish,
  155. vmsdbgout_assembly_start,
  156. vmsdbgout_define,
  157. vmsdbgout_undef,
  158. vmsdbgout_start_source_file,
  159. vmsdbgout_end_source_file,
  160. vmsdbgout_begin_block,
  161. vmsdbgout_end_block,
  162. vmsdbgout_ignore_block,
  163. vmsdbgout_source_line,
  164. vmsdbgout_begin_prologue,
  165. vmsdbgout_end_prologue,
  166. vmsdbgout_begin_epilogue,
  167. vmsdbgout_end_epilogue,
  168. vmsdbgout_begin_function,
  169. vmsdbgout_end_function,
  170. debug_nothing_tree, /* register_main_translation_unit */
  171. vmsdbgout_decl,
  172. vmsdbgout_global_decl,
  173. vmsdbgout_type_decl, /* type_decl */
  174. debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
  175. debug_nothing_tree, /* deferred_inline_function */
  176. vmsdbgout_abstract_function,
  177. debug_nothing_rtx_code_label, /* label */
  178. debug_nothing_int, /* handle_pch */
  179. debug_nothing_rtx_insn, /* var_location */
  180. debug_nothing_void, /* switch_text_section */
  181. debug_nothing_tree_tree, /* set_name */
  182. 0, /* start_end_main_source_file */
  183. TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
  184. };
  185. /* Definitions of defaults for assembler-dependent names of various
  186. pseudo-ops and section names. */
  187. #define VMS_UNALIGNED_SHORT_ASM_OP ".word"
  188. #define VMS_UNALIGNED_INT_ASM_OP ".long"
  189. #define VMS_UNALIGNED_LONG_ASM_OP ".long"
  190. #define VMS_UNALIGNED_DOUBLE_INT_ASM_OP ".quad"
  191. #define VMS_ASM_BYTE_OP ".byte"
  192. #define NUMBYTES(I) ((I) < 256 ? 1 : (I) < 65536 ? 2 : 4)
  193. #define NUMBYTES0(I) ((I) < 128 ? 0 : (I) < 65536 ? 2 : 4)
  194. #ifndef UNALIGNED_PTR_ASM_OP
  195. #define UNALIGNED_PTR_ASM_OP \
  196. (PTR_SIZE == 8 ? VMS_UNALIGNED_DOUBLE_INT_ASM_OP : VMS_UNALIGNED_INT_ASM_OP)
  197. #endif
  198. #ifndef UNALIGNED_OFFSET_ASM_OP
  199. #define UNALIGNED_OFFSET_ASM_OP(OFFSET) \
  200. (NUMBYTES (OFFSET) == 4 \
  201. ? VMS_UNALIGNED_LONG_ASM_OP \
  202. : (NUMBYTES (OFFSET) == 2 ? VMS_UNALIGNED_SHORT_ASM_OP : VMS_ASM_BYTE_OP))
  203. #endif
  204. /* Definitions of defaults for formats and names of various special
  205. (artificial) labels which may be generated within this file (when the -g
  206. options is used and VMS_DEBUGGING_INFO is in effect. If necessary, these
  207. may be overridden from within the tm.h file, but typically, overriding these
  208. defaults is unnecessary. */
  209. static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  210. #ifndef TEXT_END_LABEL
  211. #define TEXT_END_LABEL "Lvetext"
  212. #endif
  213. #ifndef FUNC_BEGIN_LABEL
  214. #define FUNC_BEGIN_LABEL "LVFB"
  215. #endif
  216. #ifndef FUNC_PROLOG_LABEL
  217. #define FUNC_PROLOG_LABEL "LVFP"
  218. #endif
  219. #ifndef FUNC_EPILOG_LABEL
  220. #define FUNC_EPILOG_LABEL "LVEB"
  221. #endif
  222. #ifndef FUNC_END_LABEL
  223. #define FUNC_END_LABEL "LVFE"
  224. #endif
  225. #ifndef BLOCK_BEGIN_LABEL
  226. #define BLOCK_BEGIN_LABEL "LVBB"
  227. #endif
  228. #ifndef BLOCK_END_LABEL
  229. #define BLOCK_END_LABEL "LVBE"
  230. #endif
  231. #ifndef LINE_CODE_LABEL
  232. #define LINE_CODE_LABEL "LVM"
  233. #endif
  234. #ifndef ASM_OUTPUT_DEBUG_DELTA2
  235. #define ASM_OUTPUT_DEBUG_DELTA2(FILE,LABEL1,LABEL2) \
  236. do \
  237. { \
  238. fprintf ((FILE), "\t%s\t", VMS_UNALIGNED_SHORT_ASM_OP); \
  239. assemble_name (FILE, LABEL1); \
  240. fprintf (FILE, "-"); \
  241. assemble_name (FILE, LABEL2); \
  242. } \
  243. while (0)
  244. #endif
  245. #ifndef ASM_OUTPUT_DEBUG_DELTA4
  246. #define ASM_OUTPUT_DEBUG_DELTA4(FILE,LABEL1,LABEL2) \
  247. do \
  248. { \
  249. fprintf ((FILE), "\t%s\t", VMS_UNALIGNED_INT_ASM_OP); \
  250. assemble_name (FILE, LABEL1); \
  251. fprintf (FILE, "-"); \
  252. assemble_name (FILE, LABEL2); \
  253. } \
  254. while (0)
  255. #endif
  256. #ifndef ASM_OUTPUT_DEBUG_ADDR_DELTA
  257. #define ASM_OUTPUT_DEBUG_ADDR_DELTA(FILE,LABEL1,LABEL2) \
  258. do \
  259. { \
  260. fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
  261. assemble_name (FILE, LABEL1); \
  262. fprintf (FILE, "-"); \
  263. assemble_name (FILE, LABEL2); \
  264. } \
  265. while (0)
  266. #endif
  267. #ifndef ASM_OUTPUT_DEBUG_ADDR
  268. #define ASM_OUTPUT_DEBUG_ADDR(FILE,LABEL) \
  269. do \
  270. { \
  271. fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
  272. assemble_name (FILE, LABEL); \
  273. } \
  274. while (0)
  275. #endif
  276. #ifndef ASM_OUTPUT_DEBUG_ADDR_CONST
  277. #define ASM_OUTPUT_DEBUG_ADDR_CONST(FILE,ADDR) \
  278. fprintf ((FILE), "\t%s\t%s", UNALIGNED_PTR_ASM_OP, (ADDR))
  279. #endif
  280. #ifndef ASM_OUTPUT_DEBUG_DATA1
  281. #define ASM_OUTPUT_DEBUG_DATA1(FILE,VALUE) \
  282. fprintf ((FILE), "\t%s\t%#x", VMS_ASM_BYTE_OP, (unsigned char) VALUE)
  283. #endif
  284. #ifndef ASM_OUTPUT_DEBUG_DATA2
  285. #define ASM_OUTPUT_DEBUG_DATA2(FILE,VALUE) \
  286. fprintf ((FILE), "\t%s\t%#x", VMS_UNALIGNED_SHORT_ASM_OP, \
  287. (unsigned short) VALUE)
  288. #endif
  289. #ifndef ASM_OUTPUT_DEBUG_DATA4
  290. #define ASM_OUTPUT_DEBUG_DATA4(FILE,VALUE) \
  291. fprintf ((FILE), "\t%s\t%#lx", VMS_UNALIGNED_INT_ASM_OP, \
  292. (unsigned long) VALUE)
  293. #endif
  294. #ifndef ASM_OUTPUT_DEBUG_DATA
  295. #define ASM_OUTPUT_DEBUG_DATA(FILE,VALUE) \
  296. fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_OFFSET_ASM_OP (VALUE), VALUE)
  297. #endif
  298. #ifndef ASM_OUTPUT_DEBUG_ADDR_DATA
  299. #define ASM_OUTPUT_DEBUG_ADDR_DATA(FILE,VALUE) \
  300. fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_PTR_ASM_OP, \
  301. (unsigned long) VALUE)
  302. #endif
  303. #ifndef ASM_OUTPUT_DEBUG_DATA8
  304. #define ASM_OUTPUT_DEBUG_DATA8(FILE,VALUE) \
  305. fprintf ((FILE), "\t%s\t%#llx", VMS_UNALIGNED_DOUBLE_INT_ASM_OP, \
  306. (unsigned long long) VALUE)
  307. #endif
  308. /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
  309. newline is produced. When flag_verbose_asm is asserted, we add commentary
  310. at the end of the line, so we must avoid output of a newline here. */
  311. #ifndef ASM_OUTPUT_DEBUG_STRING
  312. #define ASM_OUTPUT_DEBUG_STRING(FILE,P) \
  313. do \
  314. { \
  315. register int slen = strlen (P); \
  316. register const char *p = (P); \
  317. register int i; \
  318. fprintf (FILE, "\t.ascii \""); \
  319. for (i = 0; i < slen; i++) \
  320. { \
  321. register int c = p[i]; \
  322. if (c == '\"' || c == '\\') \
  323. putc ('\\', FILE); \
  324. if (c >= ' ' && c < 0177) \
  325. putc (c, FILE); \
  326. else \
  327. fprintf (FILE, "\\%o", c); \
  328. } \
  329. fprintf (FILE, "\""); \
  330. } \
  331. while (0)
  332. #endif
  333. /* Convert a reference to the assembler name of a C-level name. This
  334. macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
  335. a string rather than writing to a file. */
  336. #ifndef ASM_NAME_TO_STRING
  337. #define ASM_NAME_TO_STRING(STR, NAME) \
  338. do \
  339. { \
  340. if ((NAME)[0] == '*') \
  341. strcpy (STR, NAME+1); \
  342. else \
  343. strcpy (STR, NAME); \
  344. } \
  345. while (0)
  346. #endif
  347. /* Output the debug header HEADER. Also output COMMENT if flag_verbose_asm is
  348. set. Return the header size. Just return the size if DOSIZEONLY is
  349. nonzero. */
  350. static int
  351. write_debug_header (DST_HEADER *header, const char *comment, int dosizeonly)
  352. {
  353. if (!dosizeonly)
  354. {
  355. ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
  356. header->dst__header_length.dst_w_length);
  357. if (flag_verbose_asm)
  358. fprintf (asm_out_file, "\t%s record length", ASM_COMMENT_START);
  359. fputc ('\n', asm_out_file);
  360. ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
  361. header->dst__header_type.dst_w_type);
  362. if (flag_verbose_asm)
  363. fprintf (asm_out_file, "\t%s record type (%s)", ASM_COMMENT_START,
  364. comment);
  365. fputc ('\n', asm_out_file);
  366. }
  367. return 4;
  368. }
  369. /* Output the address of SYMBOL. Also output COMMENT if flag_verbose_asm is
  370. set. Return the address size. Just return the size if DOSIZEONLY is
  371. nonzero. */
  372. static int
  373. write_debug_addr (const char *symbol, const char *comment, int dosizeonly)
  374. {
  375. if (!dosizeonly)
  376. {
  377. ASM_OUTPUT_DEBUG_ADDR (asm_out_file, symbol);
  378. if (flag_verbose_asm)
  379. fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
  380. fputc ('\n', asm_out_file);
  381. }
  382. return PTR_SIZE;
  383. }
  384. /* Output the single byte DATA1. Also output COMMENT if flag_verbose_asm is
  385. set. Return the data size. Just return the size if DOSIZEONLY is
  386. nonzero. */
  387. static int
  388. write_debug_data1 (unsigned int data1, const char *comment, int dosizeonly)
  389. {
  390. if (!dosizeonly)
  391. {
  392. ASM_OUTPUT_DEBUG_DATA1 (asm_out_file, data1);
  393. if (flag_verbose_asm)
  394. fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
  395. fputc ('\n', asm_out_file);
  396. }
  397. return 1;
  398. }
  399. /* Output the single word DATA2. Also output COMMENT if flag_verbose_asm is
  400. set. Return the data size. Just return the size if DOSIZEONLY is
  401. nonzero. */
  402. static int
  403. write_debug_data2 (unsigned int data2, const char *comment, int dosizeonly)
  404. {
  405. if (!dosizeonly)
  406. {
  407. ASM_OUTPUT_DEBUG_DATA2 (asm_out_file, data2);
  408. if (flag_verbose_asm)
  409. fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
  410. fputc ('\n', asm_out_file);
  411. }
  412. return 2;
  413. }
  414. /* Output double word DATA4. Also output COMMENT if flag_verbose_asm is set.
  415. Return the data size. Just return the size if DOSIZEONLY is nonzero. */
  416. static int
  417. write_debug_data4 (unsigned long data4, const char *comment, int dosizeonly)
  418. {
  419. if (!dosizeonly)
  420. {
  421. ASM_OUTPUT_DEBUG_DATA4 (asm_out_file, data4);
  422. if (flag_verbose_asm)
  423. fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
  424. fputc ('\n', asm_out_file);
  425. }
  426. return 4;
  427. }
  428. /* Output quad word DATA8. Also output COMMENT if flag_verbose_asm is set.
  429. Return the data size. Just return the size if DOSIZEONLY is nonzero. */
  430. static int
  431. write_debug_data8 (unsigned long long data8, const char *comment,
  432. int dosizeonly)
  433. {
  434. if (!dosizeonly)
  435. {
  436. ASM_OUTPUT_DEBUG_DATA8 (asm_out_file, data8);
  437. if (flag_verbose_asm)
  438. fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
  439. fputc ('\n', asm_out_file);
  440. }
  441. return 8;
  442. }
  443. /* Output the difference between LABEL1 and LABEL2. Also output COMMENT if
  444. flag_verbose_asm is set. Return the data size. Just return the size if
  445. DOSIZEONLY is nonzero. */
  446. static int
  447. write_debug_delta4 (const char *label1, const char *label2,
  448. const char *comment, int dosizeonly)
  449. {
  450. if (!dosizeonly)
  451. {
  452. ASM_OUTPUT_DEBUG_DELTA4 (asm_out_file, label1, label2);
  453. if (flag_verbose_asm)
  454. fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
  455. fputc ('\n', asm_out_file);
  456. }
  457. return 4;
  458. }
  459. /* Output a character string STRING. Also write COMMENT if flag_verbose_asm is
  460. set. Return the string length. Just return the length if DOSIZEONLY is
  461. nonzero. */
  462. static int
  463. write_debug_string (const char *string, const char *comment, int dosizeonly)
  464. {
  465. if (!dosizeonly)
  466. {
  467. ASM_OUTPUT_DEBUG_STRING (asm_out_file, string);
  468. if (flag_verbose_asm)
  469. fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
  470. fputc ('\n', asm_out_file);
  471. }
  472. return strlen (string);
  473. }
  474. /* Output a module begin header and return the header size. Just return the
  475. size if DOSIZEONLY is nonzero. */
  476. static int
  477. write_modbeg (int dosizeonly)
  478. {
  479. DST_MODULE_BEGIN modbeg;
  480. DST_MB_TRLR mb_trlr;
  481. int i;
  482. char *module_name, *m;
  483. int modnamelen;
  484. int prodnamelen;
  485. int totsize = 0;
  486. /* Assumes primary filename has Unix syntax file spec. */
  487. module_name = xstrdup (lbasename (primary_filename));
  488. m = strrchr (module_name, '.');
  489. if (m)
  490. *m = 0;
  491. modnamelen = strlen (module_name);
  492. for (i = 0; i < modnamelen; i++)
  493. module_name[i] = TOUPPER (module_name[i]);
  494. prodnamelen = strlen (module_producer);
  495. modbeg.dst_a_modbeg_header.dst__header_length.dst_w_length
  496. = DST_K_MODBEG_SIZE + modnamelen + DST_K_MB_TRLR_SIZE + prodnamelen - 1;
  497. modbeg.dst_a_modbeg_header.dst__header_type.dst_w_type = DST_K_MODBEG;
  498. modbeg.dst_b_modbeg_flags.dst_v_modbeg_hide = 0;
  499. modbeg.dst_b_modbeg_flags.dst_v_modbeg_version = 1;
  500. modbeg.dst_b_modbeg_flags.dst_v_modbeg_unused = 0;
  501. modbeg.dst_b_modbeg_unused = 0;
  502. modbeg.dst_l_modbeg_language = (DST_LANGUAGE) module_language;
  503. modbeg.dst_w_version_major = DST_K_VERSION_MAJOR;
  504. modbeg.dst_w_version_minor = DST_K_VERSION_MINOR;
  505. modbeg.dst_b_modbeg_name = strlen (module_name);
  506. mb_trlr.dst_b_compiler = strlen (module_producer);
  507. totsize += write_debug_header (&modbeg.dst_a_modbeg_header,
  508. "modbeg", dosizeonly);
  509. totsize += write_debug_data1 (*((char *) &modbeg.dst_b_modbeg_flags),
  510. "flags", dosizeonly);
  511. totsize += write_debug_data1 (modbeg.dst_b_modbeg_unused,
  512. "unused", dosizeonly);
  513. totsize += write_debug_data4 (modbeg.dst_l_modbeg_language,
  514. "language", dosizeonly);
  515. totsize += write_debug_data2 (modbeg.dst_w_version_major,
  516. "DST major version", dosizeonly);
  517. totsize += write_debug_data2 (modbeg.dst_w_version_minor,
  518. "DST minor version", dosizeonly);
  519. totsize += write_debug_data1 (modbeg.dst_b_modbeg_name,
  520. "length of module name", dosizeonly);
  521. totsize += write_debug_string (module_name, "module name", dosizeonly);
  522. totsize += write_debug_data1 (mb_trlr.dst_b_compiler,
  523. "length of compiler name", dosizeonly);
  524. totsize += write_debug_string (module_producer, "compiler name", dosizeonly);
  525. return totsize;
  526. }
  527. /* Output a module end trailer and return the trailer size. Just return
  528. the size if DOSIZEONLY is nonzero. */
  529. static int
  530. write_modend (int dosizeonly)
  531. {
  532. DST_MODULE_END modend;
  533. int totsize = 0;
  534. modend.dst_a_modend_header.dst__header_length.dst_w_length
  535. = DST_K_MODEND_SIZE - 1;
  536. modend.dst_a_modend_header.dst__header_type.dst_w_type = DST_K_MODEND;
  537. totsize += write_debug_header (&modend.dst_a_modend_header, "modend",
  538. dosizeonly);
  539. return totsize;
  540. }
  541. /* Output a routine begin header routine RTNNUM and return the header size.
  542. Just return the size if DOSIZEONLY is nonzero. */
  543. static int
  544. write_rtnbeg (int rtnnum, int dosizeonly)
  545. {
  546. const char *rtnname;
  547. int rtnnamelen;
  548. char *rtnentryname;
  549. int totsize = 0;
  550. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  551. DST_ROUTINE_BEGIN rtnbeg;
  552. DST_PROLOG prolog;
  553. rtnname = funcnam_table[rtnnum];
  554. rtnnamelen = strlen (rtnname);
  555. rtnentryname = concat (rtnname, "..en", NULL);
  556. if (!strcmp (rtnname, "main"))
  557. {
  558. DST_HEADER header;
  559. const char *go = "TRANSFER$BREAK$GO";
  560. /* This command isn't documented in DSTRECORDS, so it's made to
  561. look like what DEC C does */
  562. /* header size - 1st byte + flag byte + STO_LW size
  563. + string count byte + string length */
  564. header.dst__header_length.dst_w_length
  565. = DST_K_DST_HEADER_SIZE - 1 + 1 + 4 + 1 + strlen (go);
  566. header.dst__header_type.dst_w_type = DST_K_TBG;
  567. totsize += write_debug_header (&header, "transfer", dosizeonly);
  568. /* I think this is a flag byte, but I don't know what this flag means */
  569. totsize += write_debug_data1 (0x1, "flags ???", dosizeonly);
  570. /* Routine Begin PD Address */
  571. totsize += write_debug_addr (rtnname, "main procedure descriptor",
  572. dosizeonly);
  573. totsize += write_debug_data1 (strlen (go), "length of main_name",
  574. dosizeonly);
  575. totsize += write_debug_string (go, "main name", dosizeonly);
  576. }
  577. /* The header length never includes the length byte. */
  578. rtnbeg.dst_a_rtnbeg_header.dst__header_length.dst_w_length
  579. = DST_K_RTNBEG_SIZE + rtnnamelen - 1;
  580. rtnbeg.dst_a_rtnbeg_header.dst__header_type.dst_w_type = DST_K_RTNBEG;
  581. rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unused = 0;
  582. rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unalloc = 0;
  583. rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_prototype = 0;
  584. rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_inlined = 0;
  585. rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_no_call = 1;
  586. rtnbeg.dst_b_rtnbeg_name = rtnnamelen;
  587. totsize += write_debug_header (&rtnbeg.dst_a_rtnbeg_header, "rtnbeg",
  588. dosizeonly);
  589. totsize += write_debug_data1 (*((char *) &rtnbeg.dst_b_rtnbeg_flags),
  590. "flags", dosizeonly);
  591. /* Routine Begin Address */
  592. totsize += write_debug_addr (rtnentryname, "routine entry name", dosizeonly);
  593. /* Routine Begin PD Address */
  594. totsize += write_debug_addr (rtnname, "routine procedure descriptor",
  595. dosizeonly);
  596. /* Routine Begin Name */
  597. totsize += write_debug_data1 (rtnbeg.dst_b_rtnbeg_name,
  598. "length of routine name", dosizeonly);
  599. totsize += write_debug_string (rtnname, "routine name", dosizeonly);
  600. free (rtnentryname);
  601. if (debug_info_level > DINFO_LEVEL_TERSE)
  602. {
  603. prolog.dst_a_prolog_header.dst__header_length.dst_w_length
  604. = DST_K_PROLOG_SIZE - 1;
  605. prolog.dst_a_prolog_header.dst__header_type.dst_w_type = DST_K_PROLOG;
  606. totsize += write_debug_header (&prolog.dst_a_prolog_header, "prolog",
  607. dosizeonly);
  608. ASM_GENERATE_INTERNAL_LABEL
  609. (label, FUNC_PROLOG_LABEL,
  610. funcnum_table[rtnnum]);
  611. totsize += write_debug_addr (label, "prolog breakpoint addr",
  612. dosizeonly);
  613. }
  614. return totsize;
  615. }
  616. /* Output a routine end trailer for routine RTNNUM and return the header size.
  617. Just return the size if DOSIZEONLY is nonzero. */
  618. static int
  619. write_rtnend (int rtnnum, int dosizeonly)
  620. {
  621. DST_ROUTINE_END rtnend;
  622. char label1[MAX_ARTIFICIAL_LABEL_BYTES];
  623. char label2[MAX_ARTIFICIAL_LABEL_BYTES];
  624. int totsize;
  625. totsize = 0;
  626. rtnend.dst_a_rtnend_header.dst__header_length.dst_w_length
  627. = DST_K_RTNEND_SIZE - 1;
  628. rtnend.dst_a_rtnend_header.dst__header_type.dst_w_type = DST_K_RTNEND;
  629. rtnend.dst_b_rtnend_unused = 0;
  630. rtnend.dst_l_rtnend_size = 0; /* Calculated below. */
  631. totsize += write_debug_header (&rtnend.dst_a_rtnend_header, "rtnend",
  632. dosizeonly);
  633. totsize += write_debug_data1 (rtnend.dst_b_rtnend_unused, "unused",
  634. dosizeonly);
  635. ASM_GENERATE_INTERNAL_LABEL
  636. (label1, FUNC_BEGIN_LABEL,
  637. funcnum_table[rtnnum]);
  638. ASM_GENERATE_INTERNAL_LABEL
  639. (label2, FUNC_END_LABEL,
  640. funcnum_table[rtnnum]);
  641. totsize += write_debug_delta4 (label2, label1, "routine size", dosizeonly);
  642. return totsize;
  643. }
  644. #define K_DELTA_PC(I) \
  645. ((I) < 128 ? -(I) : (I) < 65536 ? DST_K_DELTA_PC_W : DST_K_DELTA_PC_L)
  646. #define K_SET_LINUM(I) \
  647. ((I) < 256 ? DST_K_SET_LINUM_B \
  648. : (I) < 65536 ? DST_K_SET_LINUM : DST_K_SET_LINUM_L)
  649. #define K_INCR_LINUM(I) \
  650. ((I) < 256 ? DST_K_INCR_LINUM \
  651. : (I) < 65536 ? DST_K_INCR_LINUM_W : DST_K_INCR_LINUM_L)
  652. /* Output the PC to line number correlations and return the size. Just return
  653. the size if DOSIZEONLY is nonzero */
  654. static int
  655. write_pclines (int dosizeonly)
  656. {
  657. unsigned i;
  658. int fn;
  659. int ln, lastln;
  660. int linestart = 0;
  661. int max_line;
  662. DST_LINE_NUM_HEADER line_num;
  663. DST_PCLINE_COMMANDS pcline;
  664. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  665. char lastlabel[MAX_ARTIFICIAL_LABEL_BYTES];
  666. int totsize = 0;
  667. char buff[256];
  668. max_line = file_info_table[1].max_line;
  669. file_info_table[1].listing_line_start = linestart;
  670. linestart = linestart + ((max_line / 100000) + 1) * 100000;
  671. for (i = 2; i < file_info_table_in_use; i++)
  672. {
  673. max_line = file_info_table[i].max_line;
  674. file_info_table[i].listing_line_start = linestart;
  675. linestart = linestart + ((max_line / 10000) + 1) * 10000;
  676. }
  677. /* Set starting address to beginning of text section. */
  678. line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 8;
  679. line_num.dst_a_line_num_header.dst__header_type.dst_w_type = DST_K_LINE_NUM;
  680. pcline.dst_b_pcline_command = DST_K_SET_ABS_PC;
  681. totsize += write_debug_header (&line_num.dst_a_line_num_header,
  682. "line_num", dosizeonly);
  683. totsize += write_debug_data1 (pcline.dst_b_pcline_command,
  684. "line_num (SET ABS PC)", dosizeonly);
  685. if (dosizeonly)
  686. totsize += 4;
  687. else
  688. {
  689. ASM_OUTPUT_DEBUG_ADDR (asm_out_file, TEXT_SECTION_ASM_OP);
  690. if (flag_verbose_asm)
  691. fprintf (asm_out_file, "\t%s line_num", ASM_COMMENT_START);
  692. fputc ('\n', asm_out_file);
  693. }
  694. fn = line_info_table[1].dst_file_num;
  695. ln = (file_info_table[fn].listing_line_start
  696. + line_info_table[1].dst_line_num);
  697. line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 4 + 4;
  698. pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
  699. totsize += write_debug_header (&line_num.dst_a_line_num_header,
  700. "line_num", dosizeonly);
  701. totsize += write_debug_data1 (pcline.dst_b_pcline_command,
  702. "line_num (SET LINUM LONG)", dosizeonly);
  703. sprintf (buff, "line_num (%d)", ln ? ln - 1 : 0);
  704. totsize += write_debug_data4 (ln ? ln - 1 : 0, buff, dosizeonly);
  705. lastln = ln;
  706. strcpy (lastlabel, TEXT_SECTION_ASM_OP);
  707. for (i = 1; i < line_info_table_in_use; i++)
  708. {
  709. int extrabytes;
  710. fn = line_info_table[i].dst_file_num;
  711. ln = (file_info_table[fn].listing_line_start
  712. + line_info_table[i].dst_line_num);
  713. if (ln - lastln > 1)
  714. extrabytes = 5; /* NUMBYTES (ln - lastln - 1) + 1; */
  715. else if (ln <= lastln)
  716. extrabytes = 5; /* NUMBYTES (ln - 1) + 1; */
  717. else
  718. extrabytes = 0;
  719. line_num.dst_a_line_num_header.dst__header_length.dst_w_length
  720. = 8 + extrabytes;
  721. totsize += write_debug_header
  722. (&line_num.dst_a_line_num_header, "line_num", dosizeonly);
  723. if (ln - lastln > 1)
  724. {
  725. int lndif = ln - lastln - 1;
  726. /* K_INCR_LINUM (lndif); */
  727. pcline.dst_b_pcline_command = DST_K_INCR_LINUM_L;
  728. totsize += write_debug_data1 (pcline.dst_b_pcline_command,
  729. "line_num (INCR LINUM LONG)",
  730. dosizeonly);
  731. sprintf (buff, "line_num (%d)", lndif);
  732. totsize += write_debug_data4 (lndif, buff, dosizeonly);
  733. }
  734. else if (ln <= lastln)
  735. {
  736. /* K_SET_LINUM (ln-1); */
  737. pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
  738. totsize += write_debug_data1 (pcline.dst_b_pcline_command,
  739. "line_num (SET LINUM LONG)",
  740. dosizeonly);
  741. sprintf (buff, "line_num (%d)", ln - 1);
  742. totsize += write_debug_data4 (ln - 1, buff, dosizeonly);
  743. }
  744. pcline.dst_b_pcline_command = DST_K_DELTA_PC_L;
  745. totsize += write_debug_data1 (pcline.dst_b_pcline_command,
  746. "line_num (DELTA PC LONG)", dosizeonly);
  747. ASM_GENERATE_INTERNAL_LABEL (label, LINE_CODE_LABEL, i);
  748. totsize += write_debug_delta4 (label, lastlabel, "increment line_num",
  749. dosizeonly);
  750. lastln = ln;
  751. strcpy (lastlabel, label);
  752. }
  753. return totsize;
  754. }
  755. /* Output a source correlation for file FILEID using information saved in
  756. FILE_INFO_ENTRY and return the size. Just return the size if DOSIZEONLY is
  757. nonzero. */
  758. static int
  759. write_srccorr (int fileid, dst_file_info_entry file_info_entry,
  760. int dosizeonly)
  761. {
  762. int src_command_size;
  763. int linesleft = file_info_entry.max_line;
  764. int linestart = file_info_entry.listing_line_start;
  765. int flen = strlen (file_info_entry.file_name);
  766. int linestodo = 0;
  767. DST_SOURCE_CORR src_header;
  768. DST_SRC_COMMAND src_command;
  769. DST_SRC_COMMAND src_command_sf;
  770. DST_SRC_COMMAND src_command_sl;
  771. DST_SRC_COMMAND src_command_sr;
  772. DST_SRC_COMMAND src_command_dl;
  773. DST_SRC_CMDTRLR src_cmdtrlr;
  774. char buff[256];
  775. int totsize = 0;
  776. if (fileid == 1)
  777. {
  778. src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
  779. = DST_K_SOURCE_CORR_HEADER_SIZE + 1 - 1;
  780. src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
  781. = DST_K_SOURCE;
  782. src_command.dst_b_src_command = DST_K_SRC_FORMFEED;
  783. totsize += write_debug_header (&src_header.dst_a_source_corr_header,
  784. "source corr", dosizeonly);
  785. totsize += write_debug_data1 (src_command.dst_b_src_command,
  786. "source_corr (SRC FORMFEED)",
  787. dosizeonly);
  788. }
  789. src_command_size
  790. = DST_K_SRC_COMMAND_SIZE + flen + DST_K_SRC_CMDTRLR_SIZE;
  791. src_command.dst_b_src_command = DST_K_SRC_DECLFILE;
  792. src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length
  793. = src_command_size - 2;
  794. src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags = 0;
  795. src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid
  796. = fileid;
  797. src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt
  798. = file_info_entry.cdt;
  799. src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk
  800. = file_info_entry.ebk;
  801. src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb
  802. = file_info_entry.ffb;
  803. src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo
  804. = file_info_entry.rfo;
  805. src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename
  806. = flen;
  807. src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
  808. = DST_K_SOURCE_CORR_HEADER_SIZE + src_command_size - 1;
  809. src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
  810. = DST_K_SOURCE;
  811. src_cmdtrlr.dst_b_src_df_libmodname = 0;
  812. totsize += write_debug_header (&src_header.dst_a_source_corr_header,
  813. "source corr", dosizeonly);
  814. totsize += write_debug_data1 (src_command.dst_b_src_command,
  815. "source_corr (DECL SRC FILE)", dosizeonly);
  816. totsize += write_debug_data1
  817. (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length,
  818. "source_corr (length)", dosizeonly);
  819. totsize += write_debug_data1
  820. (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags,
  821. "source_corr (flags)", dosizeonly);
  822. totsize += write_debug_data2
  823. (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid,
  824. "source_corr (fileid)", dosizeonly);
  825. totsize += write_debug_data8
  826. (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt,
  827. "source_corr (creation date)", dosizeonly);
  828. totsize += write_debug_data4
  829. (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk,
  830. "source_corr (EOF block number)", dosizeonly);
  831. totsize += write_debug_data2
  832. (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb,
  833. "source_corr (first free byte)", dosizeonly);
  834. totsize += write_debug_data1
  835. (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo,
  836. "source_corr (record and file organization)", dosizeonly);
  837. totsize += write_debug_data1
  838. (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename,
  839. "source_corr (filename length)", dosizeonly);
  840. totsize += write_debug_string (remap_debug_filename (
  841. file_info_entry.file_name),
  842. "source file name", dosizeonly);
  843. totsize += write_debug_data1 (src_cmdtrlr.dst_b_src_df_libmodname,
  844. "source_corr (libmodname)", dosizeonly);
  845. src_command_sf.dst_b_src_command = DST_K_SRC_SETFILE;
  846. src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword = fileid;
  847. src_command_sr.dst_b_src_command = DST_K_SRC_SETREC_W;
  848. src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword = 1;
  849. src_command_sl.dst_b_src_command = DST_K_SRC_SETLNUM_L;
  850. src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong = linestart + 1;
  851. src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
  852. if (linesleft > 65534)
  853. linesleft = linesleft - 65534, linestodo = 65534;
  854. else
  855. linestodo = linesleft, linesleft = 0;
  856. src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
  857. src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
  858. = DST_K_SOURCE_CORR_HEADER_SIZE + 3 + 3 + 5 + 3 - 1;
  859. src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
  860. = DST_K_SOURCE;
  861. if (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword)
  862. {
  863. totsize += write_debug_header (&src_header.dst_a_source_corr_header,
  864. "source corr", dosizeonly);
  865. totsize += write_debug_data1 (src_command_sf.dst_b_src_command,
  866. "source_corr (src setfile)", dosizeonly);
  867. totsize += write_debug_data2
  868. (src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword,
  869. "source_corr (fileid)", dosizeonly);
  870. totsize += write_debug_data1 (src_command_sr.dst_b_src_command,
  871. "source_corr (setrec)", dosizeonly);
  872. totsize += write_debug_data2
  873. (src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword,
  874. "source_corr (recnum)", dosizeonly);
  875. totsize += write_debug_data1 (src_command_sl.dst_b_src_command,
  876. "source_corr (setlnum)", dosizeonly);
  877. totsize += write_debug_data4
  878. (src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong,
  879. "source_corr (linenum)", dosizeonly);
  880. totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
  881. "source_corr (deflines)", dosizeonly);
  882. sprintf (buff, "source_corr (%d)",
  883. src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
  884. totsize += write_debug_data2
  885. (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
  886. buff, dosizeonly);
  887. while (linesleft > 0)
  888. {
  889. src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
  890. = DST_K_SOURCE_CORR_HEADER_SIZE + 3 - 1;
  891. src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
  892. = DST_K_SOURCE;
  893. src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
  894. if (linesleft > 65534)
  895. linesleft = linesleft - 65534, linestodo = 65534;
  896. else
  897. linestodo = linesleft, linesleft = 0;
  898. src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
  899. totsize += write_debug_header (&src_header.dst_a_source_corr_header,
  900. "source corr", dosizeonly);
  901. totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
  902. "source_corr (deflines)", dosizeonly);
  903. sprintf (buff, "source_corr (%d)",
  904. src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
  905. totsize += write_debug_data2
  906. (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
  907. buff, dosizeonly);
  908. }
  909. }
  910. return totsize;
  911. }
  912. /* Output all the source correlation entries and return the size. Just return
  913. the size if DOSIZEONLY is nonzero. */
  914. static int
  915. write_srccorrs (int dosizeonly)
  916. {
  917. unsigned int i;
  918. int totsize = 0;
  919. for (i = 1; i < file_info_table_in_use; i++)
  920. totsize += write_srccorr (i, file_info_table[i], dosizeonly);
  921. return totsize;
  922. }
  923. /* Output a marker (i.e. a label) for the beginning of a function, before
  924. the prologue. */
  925. static void
  926. vmsdbgout_begin_prologue (unsigned int line, const char *file)
  927. {
  928. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  929. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  930. (*dwarf2_debug_hooks.begin_prologue) (line, file);
  931. if (debug_info_level > DINFO_LEVEL_NONE)
  932. {
  933. ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
  934. current_function_funcdef_no);
  935. ASM_OUTPUT_LABEL (asm_out_file, label);
  936. }
  937. }
  938. /* Output a marker (i.e. a label) for the beginning of a function, after
  939. the prologue. */
  940. static void
  941. vmsdbgout_end_prologue (unsigned int line, const char *file)
  942. {
  943. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  944. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  945. (*dwarf2_debug_hooks.end_prologue) (line, file);
  946. if (debug_info_level > DINFO_LEVEL_TERSE)
  947. {
  948. ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL,
  949. current_function_funcdef_no);
  950. ASM_OUTPUT_LABEL (asm_out_file, label);
  951. /* VMS PCA expects every PC range to correlate to some line and file. */
  952. vmsdbgout_write_source_line (line, file, 0, true);
  953. }
  954. }
  955. /* No output for VMS debug, but make obligatory call to Dwarf2 debug */
  956. static void
  957. vmsdbgout_end_function (unsigned int line)
  958. {
  959. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  960. (*dwarf2_debug_hooks.end_function) (line);
  961. }
  962. /* Output a marker (i.e. a label) for the beginning of the epilogue.
  963. This gets called *before* the epilogue code has been generated. */
  964. static void
  965. vmsdbgout_begin_epilogue (unsigned int line, const char *file)
  966. {
  967. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  968. static int save_current_function_funcdef_no = -1;
  969. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  970. (*dwarf2_debug_hooks.begin_epilogue) (line, file);
  971. if (debug_info_level > DINFO_LEVEL_NONE)
  972. {
  973. if (save_current_function_funcdef_no != current_function_funcdef_no)
  974. {
  975. /* Output a label to mark the endpoint of the code generated for this
  976. function. */
  977. ASM_GENERATE_INTERNAL_LABEL (label, FUNC_EPILOG_LABEL,
  978. current_function_funcdef_no);
  979. ASM_OUTPUT_LABEL (asm_out_file, label);
  980. save_current_function_funcdef_no = current_function_funcdef_no;
  981. /* VMS PCA expects every PC range to correlate to some line and
  982. file. */
  983. vmsdbgout_write_source_line (line, file, 0, true);
  984. }
  985. }
  986. }
  987. /* Output a marker (i.e. a label) for the absolute end of the generated code
  988. for a function definition. This gets called *after* the epilogue code has
  989. been generated. */
  990. static void
  991. vmsdbgout_end_epilogue (unsigned int line, const char *file)
  992. {
  993. char label[MAX_ARTIFICIAL_LABEL_BYTES];
  994. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  995. (*dwarf2_debug_hooks.end_epilogue) (line, file);
  996. if (debug_info_level > DINFO_LEVEL_NONE)
  997. {
  998. /* Output a label to mark the endpoint of the code generated for this
  999. function. */
  1000. ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
  1001. current_function_funcdef_no);
  1002. ASM_OUTPUT_LABEL (asm_out_file, label);
  1003. /* VMS PCA expects every PC range to correlate to some line and file. */
  1004. vmsdbgout_write_source_line (line, file, 0, true);
  1005. }
  1006. }
  1007. /* Output a marker (i.e. a label) for the beginning of the generated code for
  1008. a lexical block. */
  1009. static void
  1010. vmsdbgout_begin_block (register unsigned line, register unsigned blocknum)
  1011. {
  1012. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1013. (*dwarf2_debug_hooks.begin_block) (line, blocknum);
  1014. if (debug_info_level > DINFO_LEVEL_TERSE)
  1015. targetm.asm_out.internal_label (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
  1016. }
  1017. /* Output a marker (i.e. a label) for the end of the generated code for a
  1018. lexical block. */
  1019. static void
  1020. vmsdbgout_end_block (register unsigned line, register unsigned blocknum)
  1021. {
  1022. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1023. (*dwarf2_debug_hooks.end_block) (line, blocknum);
  1024. if (debug_info_level > DINFO_LEVEL_TERSE)
  1025. targetm.asm_out.internal_label (asm_out_file, BLOCK_END_LABEL, blocknum);
  1026. }
  1027. /* Not implemented in VMS Debug. */
  1028. static bool
  1029. vmsdbgout_ignore_block (const_tree block)
  1030. {
  1031. bool retval = 0;
  1032. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1033. retval = (*dwarf2_debug_hooks.ignore_block) (block);
  1034. return retval;
  1035. }
  1036. /* Add an entry for function DECL into the funcnam_table. */
  1037. static void
  1038. vmsdbgout_begin_function (tree decl)
  1039. {
  1040. const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
  1041. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1042. (*dwarf2_debug_hooks.begin_function) (decl);
  1043. /* Add the new entry to the end of the function name table. */
  1044. funcnam_table.safe_push (xstrdup (name));
  1045. funcnum_table.safe_push (current_function_funcdef_no);
  1046. }
  1047. static char fullname_buff [4096];
  1048. /* Return the full file specification for FILENAME. The specification must be
  1049. in VMS syntax in order to be processed by VMS Debug. */
  1050. static char *
  1051. full_name (const char *filename)
  1052. {
  1053. #ifdef VMS
  1054. FILE *fp = fopen (filename, "r");
  1055. fgetname (fp, fullname_buff, 1);
  1056. fclose (fp);
  1057. #else
  1058. /* Unix paths really mess up VMS debug. Better to just output the
  1059. base filename. */
  1060. strcpy (fullname_buff, filename);
  1061. #endif
  1062. return fullname_buff;
  1063. }
  1064. /* Lookup a filename (in the list of filenames that we know about here in
  1065. vmsdbgout.c) and return its "index". The index of each (known) filename is
  1066. just a unique number which is associated with only that one filename. We
  1067. need such numbers for the sake of generating labels and references
  1068. to those files numbers. If the filename given as an argument is not
  1069. found in our current list, add it to the list and assign it the next
  1070. available unique index number. In order to speed up searches, we remember
  1071. the index of the filename was looked up last. This handles the majority of
  1072. all searches. */
  1073. static unsigned int
  1074. lookup_filename (const char *file_name)
  1075. {
  1076. static unsigned int last_file_lookup_index = 0;
  1077. register char *fn;
  1078. register unsigned i;
  1079. const char *fnam;
  1080. long long cdt = 0;
  1081. long ebk = 0;
  1082. short ffb = 0;
  1083. char rfo = 0;
  1084. long siz = 0;
  1085. int ver = 0;
  1086. fnam = full_name (file_name);
  1087. /* Check to see if the file name that was searched on the previous call
  1088. matches this file name. If so, return the index. */
  1089. if (last_file_lookup_index != 0)
  1090. {
  1091. fn = file_info_table[last_file_lookup_index].file_name;
  1092. if (strcmp (fnam, fn) == 0)
  1093. return last_file_lookup_index;
  1094. }
  1095. /* Didn't match the previous lookup, search the table */
  1096. for (i = 1; i < file_info_table_in_use; ++i)
  1097. {
  1098. fn = file_info_table[i].file_name;
  1099. if (strcmp (fnam, fn) == 0)
  1100. {
  1101. last_file_lookup_index = i;
  1102. return i;
  1103. }
  1104. }
  1105. /* Prepare to add a new table entry by making sure there is enough space in
  1106. the table to do so. If not, expand the current table. */
  1107. if (file_info_table_in_use == file_info_table_allocated)
  1108. {
  1109. file_info_table_allocated += FILE_TABLE_INCREMENT;
  1110. file_info_table = XRESIZEVEC (dst_file_info_entry, file_info_table,
  1111. file_info_table_allocated);
  1112. }
  1113. if (vms_file_stats_name (file_name, &cdt, &siz, &rfo, &ver) == 0)
  1114. {
  1115. ebk = siz / 512 + 1;
  1116. ffb = siz - ((siz / 512) * 512);
  1117. }
  1118. /* Add the new entry to the end of the filename table. */
  1119. file_info_table[file_info_table_in_use].file_name = xstrdup (fnam);
  1120. file_info_table[file_info_table_in_use].max_line = 0;
  1121. file_info_table[file_info_table_in_use].cdt = cdt;
  1122. file_info_table[file_info_table_in_use].ebk = ebk;
  1123. file_info_table[file_info_table_in_use].ffb = ffb;
  1124. file_info_table[file_info_table_in_use].rfo = rfo;
  1125. last_file_lookup_index = file_info_table_in_use++;
  1126. return last_file_lookup_index;
  1127. }
  1128. /* Output a label to mark the beginning of a source code line entry
  1129. and record information relating to this source line, in
  1130. 'line_info_table' for later output of the .debug_line section. */
  1131. static void
  1132. vmsdbgout_write_source_line (unsigned line, const char *filename,
  1133. int /* discriminator */, bool /* is_stmt */)
  1134. {
  1135. dst_line_info_ref line_info;
  1136. targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
  1137. line_info_table_in_use);
  1138. /* Expand the line info table if necessary. */
  1139. if (line_info_table_in_use == line_info_table_allocated)
  1140. {
  1141. line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
  1142. line_info_table = XRESIZEVEC (dst_line_info_entry, line_info_table,
  1143. line_info_table_allocated);
  1144. }
  1145. /* Add the new entry at the end of the line_info_table. */
  1146. line_info = &line_info_table[line_info_table_in_use++];
  1147. line_info->dst_file_num = lookup_filename (filename);
  1148. line_info->dst_line_num = line;
  1149. if (line > file_info_table[line_info->dst_file_num].max_line)
  1150. file_info_table[line_info->dst_file_num].max_line = line;
  1151. }
  1152. static void
  1153. vmsdbgout_source_line (register unsigned line, register const char *filename,
  1154. int discriminator, bool is_stmt)
  1155. {
  1156. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1157. (*dwarf2_debug_hooks.source_line) (line, filename, discriminator, is_stmt);
  1158. if (debug_info_level >= DINFO_LEVEL_TERSE)
  1159. vmsdbgout_write_source_line (line, filename, discriminator, is_stmt);
  1160. }
  1161. /* Record the beginning of a new source file, for later output.
  1162. At present, unimplemented. */
  1163. static void
  1164. vmsdbgout_start_source_file (unsigned int lineno, const char *filename)
  1165. {
  1166. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1167. (*dwarf2_debug_hooks.start_source_file) (lineno, filename);
  1168. }
  1169. /* Record the end of a source file, for later output.
  1170. At present, unimplemented. */
  1171. static void
  1172. vmsdbgout_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
  1173. {
  1174. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1175. (*dwarf2_debug_hooks.end_source_file) (lineno);
  1176. }
  1177. /* Set up for Debug output at the start of compilation. */
  1178. static void
  1179. vmsdbgout_init (const char *filename)
  1180. {
  1181. const char *language_string = lang_hooks.name;
  1182. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1183. (*dwarf2_debug_hooks.init) (filename);
  1184. if (debug_info_level == DINFO_LEVEL_NONE)
  1185. return;
  1186. /* Remember the name of the primary input file. */
  1187. primary_filename = filename;
  1188. /* Allocate the initial hunk of the file_info_table. */
  1189. file_info_table = XCNEWVEC (dst_file_info_entry, FILE_TABLE_INCREMENT);
  1190. file_info_table_allocated = FILE_TABLE_INCREMENT;
  1191. /* Skip the first entry - file numbers begin at 1. */
  1192. file_info_table_in_use = 1;
  1193. funcnam_table.create (FUNC_TABLE_INITIAL);
  1194. funcnum_table.create (FUNC_TABLE_INITIAL);
  1195. /* Allocate the initial hunk of the line_info_table. */
  1196. line_info_table = XCNEWVEC (dst_line_info_entry, LINE_INFO_TABLE_INCREMENT);
  1197. line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
  1198. /* zero-th entry is allocated, but unused */
  1199. line_info_table_in_use = 1;
  1200. lookup_filename (primary_filename);
  1201. if (lang_GNU_C ())
  1202. module_language = DST_K_C;
  1203. else if (lang_GNU_CXX ())
  1204. module_language = DST_K_CXX;
  1205. else if (!strcmp (language_string, "GNU Ada"))
  1206. module_language = DST_K_ADA;
  1207. else if (!strcmp (language_string, "GNU F77"))
  1208. module_language = DST_K_FORTRAN;
  1209. else
  1210. module_language = DST_K_UNKNOWN;
  1211. module_producer = concat (language_string, " ", version_string, NULL);
  1212. ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
  1213. }
  1214. /* Not implemented in VMS Debug. */
  1215. static void
  1216. vmsdbgout_assembly_start (void)
  1217. {
  1218. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1219. (*dwarf2_debug_hooks.assembly_start) ();
  1220. }
  1221. /* Not implemented in VMS Debug. */
  1222. static void
  1223. vmsdbgout_define (unsigned int lineno, const char *buffer)
  1224. {
  1225. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1226. (*dwarf2_debug_hooks.define) (lineno, buffer);
  1227. }
  1228. /* Not implemented in VMS Debug. */
  1229. static void
  1230. vmsdbgout_undef (unsigned int lineno, const char *buffer)
  1231. {
  1232. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1233. (*dwarf2_debug_hooks.undef) (lineno, buffer);
  1234. }
  1235. /* Not implemented in VMS Debug. */
  1236. static void
  1237. vmsdbgout_decl (tree decl)
  1238. {
  1239. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1240. (*dwarf2_debug_hooks.function_decl) (decl);
  1241. }
  1242. /* Not implemented in VMS Debug. */
  1243. static void
  1244. vmsdbgout_global_decl (tree decl)
  1245. {
  1246. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1247. (*dwarf2_debug_hooks.global_decl) (decl);
  1248. }
  1249. /* Not implemented in VMS Debug. */
  1250. static void
  1251. vmsdbgout_type_decl (tree decl, int local)
  1252. {
  1253. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1254. (*dwarf2_debug_hooks.type_decl) (decl, local);
  1255. }
  1256. /* Not implemented in VMS Debug. */
  1257. static void
  1258. vmsdbgout_abstract_function (tree decl)
  1259. {
  1260. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1261. (*dwarf2_debug_hooks.outlining_inline_function) (decl);
  1262. }
  1263. /* Output stuff that Debug requires at the end of every file and generate the
  1264. VMS Debug debugging info. */
  1265. static void
  1266. vmsdbgout_finish (const char *filename ATTRIBUTE_UNUSED)
  1267. {
  1268. unsigned int i, ifunc;
  1269. int totsize;
  1270. if (write_symbols == VMS_AND_DWARF2_DEBUG)
  1271. (*dwarf2_debug_hooks.finish) (filename);
  1272. if (debug_info_level == DINFO_LEVEL_NONE)
  1273. return;
  1274. /* Output a terminator label for the .text section. */
  1275. switch_to_section (text_section);
  1276. targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
  1277. /* Output debugging information.
  1278. Warning! Do not change the name of the .vmsdebug section without
  1279. changing it in the assembler also. */
  1280. switch_to_section (get_named_section (NULL, ".vmsdebug", 0));
  1281. ASM_OUTPUT_ALIGN (asm_out_file, 0);
  1282. totsize = write_modbeg (1);
  1283. FOR_EACH_VEC_ELT (funcnum_table, i, ifunc)
  1284. {
  1285. totsize += write_rtnbeg (i, 1);
  1286. totsize += write_rtnend (i, 1);
  1287. }
  1288. totsize += write_pclines (1);
  1289. write_modbeg (0);
  1290. FOR_EACH_VEC_ELT (funcnum_table, i, ifunc)
  1291. {
  1292. write_rtnbeg (i, 0);
  1293. write_rtnend (i, 0);
  1294. }
  1295. write_pclines (0);
  1296. if (debug_info_level > DINFO_LEVEL_TERSE)
  1297. {
  1298. totsize = write_srccorrs (1);
  1299. write_srccorrs (0);
  1300. }
  1301. totsize = write_modend (1);
  1302. write_modend (0);
  1303. }
  1304. /* Need for both Dwarf2 on IVMS and VMS Debug on AVMS */
  1305. #ifdef VMS
  1306. #define __NEW_STARLET 1
  1307. #include <vms/rms.h>
  1308. #include <vms/atrdef.h>
  1309. #include <vms/fibdef.h>
  1310. #include <vms/stsdef.h>
  1311. #include <vms/iodef.h>
  1312. #include <vms/fatdef.h>
  1313. #include <vms/descrip.h>
  1314. #include <unixlib.h>
  1315. #define MAXPATH 256
  1316. /* descrip.h doesn't have everything ... */
  1317. typedef struct fibdef* __fibdef_ptr32 __attribute__ (( mode (SI) ));
  1318. struct dsc$descriptor_fib
  1319. {
  1320. unsigned int fib$l_len;
  1321. __fibdef_ptr32 fib$l_addr;
  1322. };
  1323. /* I/O Status Block. */
  1324. struct IOSB
  1325. {
  1326. unsigned short status, count;
  1327. unsigned int devdep;
  1328. };
  1329. static char *tryfile;
  1330. /* Variable length string. */
  1331. struct vstring
  1332. {
  1333. short length;
  1334. char string[NAM$C_MAXRSS+1];
  1335. };
  1336. static char filename_buff [MAXPATH];
  1337. static char vms_filespec [MAXPATH];
  1338. /* Callback function for filespec style conversion. */
  1339. static int
  1340. translate_unix (char *name, int type ATTRIBUTE_UNUSED)
  1341. {
  1342. strncpy (filename_buff, name, MAXPATH);
  1343. filename_buff [MAXPATH - 1] = (char) 0;
  1344. return 0;
  1345. }
  1346. /* Wrapper for DECC function that converts a Unix filespec
  1347. to VMS style filespec. */
  1348. static char *
  1349. to_vms_file_spec (char *filespec)
  1350. {
  1351. strncpy (vms_filespec, "", MAXPATH);
  1352. decc$to_vms (filespec, translate_unix, 1, 1);
  1353. strncpy (vms_filespec, filename_buff, MAXPATH);
  1354. vms_filespec [MAXPATH - 1] = (char) 0;
  1355. return vms_filespec;
  1356. }
  1357. #else
  1358. #define VMS_EPOCH_OFFSET 35067168000000000LL
  1359. #define VMS_GRANULARITY_FACTOR 10000000
  1360. #endif
  1361. /* Return VMS file date, size, format, version given a name. */
  1362. int
  1363. vms_file_stats_name (const char *filename, long long *cdt, long *siz, char *rfo,
  1364. int *ver)
  1365. {
  1366. #ifdef VMS
  1367. struct FAB fab;
  1368. struct NAM nam;
  1369. unsigned long long create;
  1370. FAT recattr;
  1371. char ascnamebuff [256];
  1372. ATRDEF atrlst[]
  1373. = {
  1374. { ATR$S_CREDATE, ATR$C_CREDATE, &create },
  1375. { ATR$S_RECATTR, ATR$C_RECATTR, &recattr },
  1376. { ATR$S_ASCNAME, ATR$C_ASCNAME, &ascnamebuff },
  1377. { 0, 0, 0}
  1378. };
  1379. FIBDEF fib;
  1380. struct dsc$descriptor_fib fibdsc = {sizeof (fib), (void *) &fib};
  1381. struct IOSB iosb;
  1382. long status;
  1383. unsigned short chan;
  1384. struct vstring file;
  1385. struct dsc$descriptor_s filedsc
  1386. = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) file.string};
  1387. struct vstring device;
  1388. struct dsc$descriptor_s devicedsc
  1389. = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) device.string};
  1390. struct vstring result;
  1391. struct dsc$descriptor_s resultdsc
  1392. = {NAM$C_MAXRSS, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (void *) result.string};
  1393. if (strcmp (filename, "<internal>") == 0
  1394. || strcmp (filename, "<built-in>") == 0)
  1395. {
  1396. if (cdt)
  1397. *cdt = 0;
  1398. if (siz)
  1399. *siz = 0;
  1400. if (rfo)
  1401. *rfo = 0;
  1402. if (ver)
  1403. *ver = 0;
  1404. return 0;
  1405. }
  1406. tryfile = to_vms_file_spec (filename);
  1407. /* Allocate and initialize a FAB and NAM structures. */
  1408. fab = cc$rms_fab;
  1409. nam = cc$rms_nam;
  1410. nam.nam$l_esa = file.string;
  1411. nam.nam$b_ess = NAM$C_MAXRSS;
  1412. nam.nam$l_rsa = result.string;
  1413. nam.nam$b_rss = NAM$C_MAXRSS;
  1414. fab.fab$l_fna = tryfile;
  1415. fab.fab$b_fns = strlen (tryfile);
  1416. fab.fab$l_nam = &nam;
  1417. /* Validate filespec syntax and device existence. */
  1418. status = SYS$PARSE (&fab, 0, 0);
  1419. if ((status & 1) != 1)
  1420. return 1;
  1421. file.string[nam.nam$b_esl] = 0;
  1422. /* Find matching filespec. */
  1423. status = SYS$SEARCH (&fab, 0, 0);
  1424. if ((status & 1) != 1)
  1425. return 1;
  1426. file.string[nam.nam$b_esl] = 0;
  1427. result.string[result.length=nam.nam$b_rsl] = 0;
  1428. /* Get the device name and assign an IO channel. */
  1429. strncpy (device.string, nam.nam$l_dev, nam.nam$b_dev);
  1430. devicedsc.dsc$w_length = nam.nam$b_dev;
  1431. chan = 0;
  1432. status = SYS$ASSIGN (&devicedsc, &chan, 0, 0, 0);
  1433. if ((status & 1) != 1)
  1434. return 1;
  1435. /* Initialize the FIB and fill in the directory id field. */
  1436. memset (&fib, 0, sizeof (fib));
  1437. fib.fib$w_did[0] = nam.nam$w_did[0];
  1438. fib.fib$w_did[1] = nam.nam$w_did[1];
  1439. fib.fib$w_did[2] = nam.nam$w_did[2];
  1440. fib.fib$l_acctl = 0;
  1441. fib.fib$l_wcc = 0;
  1442. strcpy (file.string, (strrchr (result.string, ']') + 1));
  1443. filedsc.dsc$w_length = strlen (file.string);
  1444. result.string[result.length = 0] = 0;
  1445. /* Open and close the file to fill in the attributes. */
  1446. status
  1447. = SYS$QIOW (0, chan, IO$_ACCESS|IO$M_ACCESS, &iosb, 0, 0,
  1448. &fibdsc, &filedsc, &result.length, &resultdsc, &atrlst, 0);
  1449. if ((status & 1) != 1)
  1450. return 1;
  1451. if ((iosb.status & 1) != 1)
  1452. return 1;
  1453. result.string[result.length] = 0;
  1454. status = SYS$QIOW (0, chan, IO$_DEACCESS, &iosb, 0, 0, &fibdsc, 0, 0, 0,
  1455. &atrlst, 0);
  1456. if ((status & 1) != 1)
  1457. return 1;
  1458. if ((iosb.status & 1) != 1)
  1459. return 1;
  1460. /* Deassign the channel and exit. */
  1461. status = SYS$DASSGN (chan);
  1462. if ((status & 1) != 1)
  1463. return 1;
  1464. if (cdt) *cdt = create;
  1465. if (siz) *siz = (512 * 65536 * recattr.fat$w_efblkh) +
  1466. (512 * (recattr.fat$w_efblkl - 1)) +
  1467. recattr.fat$w_ffbyte;
  1468. if (rfo) *rfo = recattr.fat$v_rtype;
  1469. if (ver) *ver = strtol (strrchr (ascnamebuff, ';')+1, 0, 10);
  1470. return 0;
  1471. #else
  1472. struct stat buff;
  1473. if ((stat (filename, &buff)) != 0)
  1474. return 1;
  1475. if (cdt)
  1476. *cdt = (long long) (buff.st_mtime * VMS_GRANULARITY_FACTOR)
  1477. + VMS_EPOCH_OFFSET;
  1478. if (siz)
  1479. *siz = buff.st_size;
  1480. if (rfo)
  1481. *rfo = 2; /* Stream LF format */
  1482. if (ver)
  1483. *ver = 1;
  1484. return 0;
  1485. #endif
  1486. }
  1487. #endif