]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/mc-boot/GDebug.cc
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / mc-boot / GDebug.cc
1 /* do not edit automatically generated by mc from Debug. */
2 /* Debug.mod provides some simple debugging routines.
3
4 Copyright (C) 2001-2024 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6
7 This file is part of GNU Modula-2.
8
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
22
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
27
28 #include "config.h"
29 #include "system.h"
30 #include <stdbool.h>
31 # if !defined (PROC_D)
32 # define PROC_D
33 typedef void (*PROC_t) (void);
34 typedef struct { PROC_t proc; } PROC;
35 # endif
36
37 #define _Debug_H
38 #define _Debug_C
39
40 # include "GASCII.h"
41 # include "GNumberIO.h"
42 # include "GStdIO.h"
43 # include "Glibc.h"
44 # include "GM2RTS.h"
45
46 # define MaxNoOfDigits 12
47
48 /*
49 Halt - writes a message in the format:
50 Module:Function:Line:Message
51
52 It then terminates by calling HALT.
53 */
54
55 extern "C" void Debug_Halt (const char *Message_, unsigned int _Message_high, const char *Module_, unsigned int _Module_high, const char *Function_, unsigned int _Function_high, unsigned int LineNo);
56
57 /*
58 DebugString - writes a string to the debugging device (Scn.Write).
59 It interprets
60 as carriage return, linefeed.
61 */
62
63 extern "C" void Debug_DebugString (const char *a_, unsigned int _a_high);
64
65 /*
66 WriteLn - writes a carriage return and a newline
67 character.
68 */
69
70 static void WriteLn (void);
71
72
73 /*
74 WriteLn - writes a carriage return and a newline
75 character.
76 */
77
78 static void WriteLn (void)
79 {
80 StdIO_Write (ASCII_cr);
81 StdIO_Write (ASCII_lf);
82 }
83
84
85 /*
86 Halt - writes a message in the format:
87 Module:Function:Line:Message
88
89 It then terminates by calling HALT.
90 */
91
92 extern "C" void Debug_Halt (const char *Message_, unsigned int _Message_high, const char *Module_, unsigned int _Module_high, const char *Function_, unsigned int _Function_high, unsigned int LineNo)
93 {
94 typedef struct Halt__T1_a Halt__T1;
95
96 struct Halt__T1_a { char array[MaxNoOfDigits+1]; };
97 Halt__T1 No;
98 char Message[_Message_high+1];
99 char Module[_Module_high+1];
100 char Function[_Function_high+1];
101
102 /* make a local copy of each unbounded array. */
103 memcpy (Message, Message_, _Message_high+1);
104 memcpy (Module, Module_, _Module_high+1);
105 memcpy (Function, Function_, _Function_high+1);
106
107 Debug_DebugString ((const char *) Module, _Module_high); /* should be large enough for most source files.. */
108 Debug_DebugString ((const char *) ":", 1);
109 Debug_DebugString ((const char *) Function, _Function_high);
110 Debug_DebugString ((const char *) ":", 1);
111 NumberIO_CardToStr (LineNo, 0, (char *) &No.array[0], MaxNoOfDigits);
112 Debug_DebugString ((const char *) ":", 1);
113 Debug_DebugString ((const char *) &No.array[0], MaxNoOfDigits);
114 Debug_DebugString ((const char *) ":", 1);
115 Debug_DebugString ((const char *) Message, _Message_high);
116 Debug_DebugString ((const char *) "\\n", 2);
117 M2RTS_HALT (-1);
118 __builtin_unreachable ();
119 }
120
121
122 /*
123 DebugString - writes a string to the debugging device (Scn.Write).
124 It interprets
125 as carriage return, linefeed.
126 */
127
128 extern "C" void Debug_DebugString (const char *a_, unsigned int _a_high)
129 {
130 unsigned int n;
131 unsigned int high;
132 char a[_a_high+1];
133
134 /* make a local copy of each unbounded array. */
135 memcpy (a, a_, _a_high+1);
136
137 high = _a_high;
138 n = 0;
139 while ((n <= high) && (a[n] != ASCII_nul))
140 {
141 if (a[n] == '\\')
142 {
143 /* avoid dangling else. */
144 if ((n+1) <= high)
145 {
146 /* avoid gcc warning by using compound statement even if not strictly necessary. */
147 if (a[n+1] == 'n')
148 {
149 WriteLn ();
150 n += 1;
151 }
152 else if (a[n+1] == '\\')
153 {
154 /* avoid dangling else. */
155 StdIO_Write ('\\');
156 n += 1;
157 }
158 }
159 }
160 else
161 {
162 StdIO_Write (a[n]);
163 }
164 n += 1;
165 }
166 }
167
168 extern "C" void _M2_Debug_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
169 {
170 }
171
172 extern "C" void _M2_Debug_fini (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
173 {
174 }