1 #line 982 "../../src/builtin/snarf.m4"
2 /* -*- buffer-read-only: t -*- vi: set ro:
3 THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT.
4 */
5 #line 982
6 #ifdef HAVE_CONFIG_H
7 #line 982
8 # include <config.h>
9 #line 982
10 #endif
11 #line 982
12 #include <sys/types.h>
13 #line 982
14
15 #line 982
16 #include "mailfromd.h"
17 #line 982
18 #include "prog.h"
19 #line 982
20 #include "builtin.h"
21 #line 982
22
23 #line 982
24
25 #line 1022 "../../src/builtin/snarf.m4"
26
27 /* End of snarf.m4 */
28 #line 1 "debug.bi"
29 /* Debugging API for MFL. -*- c -*-
30 Copyright (C) 2006-2021 Sergey Poznyakoff
31
32 This program is free software; you can redistribute it and/or modify
33 it under the terms of the GNU General Public License as published by
34 the Free Software Foundation; either version 3, or (at your option)
35 any later version.
36
37 This program is distributed in the hope that it will be useful,
38 but WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 GNU General Public License for more details.
41
42 You should have received a copy of the GNU General Public License
43 along with this program. If not, see <http://www.gnu.org/licenses/>. */
44
45
46 #include "mflib/_register.h"
47 #include "srvcfg.h"
48
49 void
50 #line 21
bi_debug_level(eval_environ_t env)51 bi_debug_level(eval_environ_t env)
52 #line 21
53
54 #line 21
55
56 #line 21 "debug.bi"
57 {
58 #line 21
59
60 #line 21
61
62 #line 21
63 long __bi_argcnt;
64 #line 21
65 char * modname;
66 #line 21
67
68 #line 21
69 get_string_arg(env, 1, &modname);
70 #line 21
71
72 #line 21
73 get_numeric_arg(env, 0, &__bi_argcnt);
74 #line 21
75 adjust_stack(env, __bi_argcnt + 1);
76 #line 21
77
78 #line 21
79
80 #line 21
81 if (builtin_module_trace(BUILTIN_IDX_debug))
82 #line 21
83 prog_trace(env, "debug_level %s",((__bi_argcnt > 0) ? modname : ""));;
84 #line 21
85
86 {
87 mu_debug_level_t level;
88 char *name = ((__bi_argcnt > 0) ? modname : NULL);
89 size_t len = name ? strlen (name) : 0;
90
91 if (!(mu_debug_category_level(name, len, &level) == 0))
92 #line 27
93 (
94 #line 27
95 env_throw_bi(env, mfe_range, "debug_level", _("invalid module name: %s"),name)
96 #line 27
97 )
98 #line 29
99 ;
100
101 #line 30
102 do {
103 #line 30
104 push(env, (STKVAL)(mft_number)(level));
105 #line 30
106 goto endlab;
107 #line 30
108 } while (0);
109 }
110 endlab:
111 #line 32
112 env_function_cleanup_flush(env, NULL);
113 #line 32
114 return;
115 #line 32
116 }
117
118 void
119 #line 34
bi_debug_spec(eval_environ_t env)120 bi_debug_spec(eval_environ_t env)
121 #line 34
122
123 #line 34
124
125 #line 34 "debug.bi"
126 {
127 #line 34
128
129 #line 34
130
131 #line 34
132 long __bi_argcnt;
133 #line 34
134 char * MFL_DATASEG modnames;
135 #line 34
136 long showunset;
137 #line 34
138
139 #line 34
140 get_string_arg(env, 1, &modnames);
141 #line 34
142 get_numeric_arg(env, 2, &showunset);
143 #line 34
144
145 #line 34
146 get_numeric_arg(env, 0, &__bi_argcnt);
147 #line 34
148 adjust_stack(env, __bi_argcnt + 1);
149 #line 34
150
151 #line 34
152
153 #line 34
154 if (builtin_module_trace(BUILTIN_IDX_debug))
155 #line 34
156 prog_trace(env, "debug_spec %s %lu",((__bi_argcnt > 0) ? modnames : ""), ((__bi_argcnt > 1) ? showunset : 0));;
157 #line 34
158
159 {
160 mu_stream_t str;
161 size_t off;
162 int rc;
163 char *names = ((__bi_argcnt > 0) ? modnames : NULL);
164
165 rc = mu_memory_stream_create(&str, MU_STREAM_RDWR);
166 if (!(rc == 0))
167 #line 42
168 (
169 #line 42
170 env_throw_bi(env, mfe_failure, "debug_spec", "cannot create stream: %s",mu_strerror(rc))
171 #line 42
172 )
173 #line 44
174 ;
175 rc = mu_debug_format_spec(str, (names && names[0]) ? names : NULL,
176 ((__bi_argcnt > 1) ? showunset : 0));
177 if (rc == 0) {
178 mu_off_t size;
179 char *s;
180 size_t n;
181
182 mu_stream_seek(str, 0, MU_SEEK_SET, NULL);
183 mu_stream_size(str, &size);
184 s = (char*) env_data_ref(env, (off = heap_reserve(env, size + 1)));
185 rc = mu_stream_read(str, s, size, &n);
186 s[n] = 0;
187 }
188
189 mu_stream_destroy(&str);
190 if (!(rc == 0))
191 #line 60
192 (
193 #line 60
194 env_throw_bi(env, mfe_failure, "debug_spec", "%s",mu_strerror(rc))
195 #line 60
196 )
197 #line 62
198 ;
199
200 #line 63
201 do {
202 #line 63
203 push(env, (STKVAL) (mft_size) (off));
204 #line 63
205 goto endlab;
206 #line 63
207 } while (0);
208 }
209 endlab:
210 #line 65
211 env_function_cleanup_flush(env, NULL);
212 #line 65
213 return;
214 #line 65
215 }
216
217 void
218 #line 67
bi_debug(eval_environ_t env)219 bi_debug(eval_environ_t env)
220 #line 67
221
222 #line 67
223
224 #line 67 "debug.bi"
225 {
226 #line 67
227
228 #line 67
229
230 #line 67
231
232 #line 67
233 char * spec;
234 #line 67
235
236 #line 67
237 get_string_arg(env, 0, &spec);
238 #line 67
239
240 #line 67
241
242 #line 67
243 adjust_stack(env, 1);
244 #line 67
245
246 #line 67
247
248 #line 67
249 if (builtin_module_trace(BUILTIN_IDX_debug))
250 #line 67
251 prog_trace(env, "debug %s",spec);;
252 #line 67
253
254 {
255 struct mu_locus_range loc = MU_LOCUS_RANGE_INITIALIZER;
256
257 env_get_locus(env, &loc);
258 mu_stream_ioctl(mu_strerr, MU_IOCTL_LOGSTREAM,
259 MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &loc);
260 mu_debug_parse_spec(spec);
261 mu_stream_ioctl(mu_strerr, MU_IOCTL_LOGSTREAM,
262 MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, NULL);
263 }
264
265 #line 78
266 env_function_cleanup_flush(env, NULL);
267 #line 78
268 return;
269 #line 78
270 }
271
272 void
273 #line 80
bi_program_trace(eval_environ_t env)274 bi_program_trace(eval_environ_t env)
275 #line 80
276
277 #line 80
278
279 #line 80 "debug.bi"
280 {
281 #line 80
282
283 #line 80
284
285 #line 80
286
287 #line 80
288 char * name;
289 #line 80
290
291 #line 80
292 get_string_arg(env, 0, &name);
293 #line 80
294
295 #line 80
296
297 #line 80
298 adjust_stack(env, 1);
299 #line 80
300
301 #line 80
302
303 #line 80
304 if (builtin_module_trace(BUILTIN_IDX_debug))
305 #line 80
306 prog_trace(env, "program_trace %s",name);;
307 #line 80
308
309 {
310 enable_prog_trace(name);
311 }
312
313 #line 84
314 env_function_cleanup_flush(env, NULL);
315 #line 84
316 return;
317 #line 84
318 }
319
320 void
321 #line 86
bi_cancel_program_trace(eval_environ_t env)322 bi_cancel_program_trace(eval_environ_t env)
323 #line 86
324
325 #line 86
326
327 #line 86 "debug.bi"
328 {
329 #line 86
330
331 #line 86
332
333 #line 86
334
335 #line 86
336 char * name;
337 #line 86
338
339 #line 86
340 get_string_arg(env, 0, &name);
341 #line 86
342
343 #line 86
344
345 #line 86
346 adjust_stack(env, 1);
347 #line 86
348
349 #line 86
350
351 #line 86
352 if (builtin_module_trace(BUILTIN_IDX_debug))
353 #line 86
354 prog_trace(env, "cancel_program_trace %s",name);;
355 #line 86
356
357 {
358 disable_prog_trace(name);
359 }
360
361 #line 90
362 env_function_cleanup_flush(env, NULL);
363 #line 90
364 return;
365 #line 90
366 }
367
368 void
369 #line 92
bi_stack_trace(eval_environ_t env)370 bi_stack_trace(eval_environ_t env)
371 #line 92
372
373 #line 92
374
375 #line 92 "debug.bi"
376 {
377 #line 92
378
379 #line 92
380
381 #line 92
382
383 #line 92
384
385 #line 92
386
387 #line 92
388
389 #line 92
390 adjust_stack(env, 0);
391 #line 92
392
393 #line 92
394
395 #line 92
396 if (builtin_module_trace(BUILTIN_IDX_debug))
397 #line 92
398 prog_trace(env, "stack_trace");;
399 #line 92
400
401 {
402 runtime_stack_trace(env);
403 }
404
405 #line 96
406 env_function_cleanup_flush(env, NULL);
407 #line 96
408 return;
409 #line 96
410 }
411
412 void
413 #line 98
bi__reg(eval_environ_t env)414 bi__reg(eval_environ_t env)
415 #line 98
416
417 #line 98
418
419 #line 98 "debug.bi"
420 {
421 #line 98
422
423 #line 98
424
425 #line 98
426
427 #line 98
428 long what;
429 #line 98
430
431 #line 98
432 get_numeric_arg(env, 0, &what);
433 #line 98
434
435 #line 98
436
437 #line 98
438 adjust_stack(env, 1);
439 #line 98
440
441 #line 98
442
443 #line 98
444 if (builtin_module_trace(BUILTIN_IDX_debug))
445 #line 98
446 prog_trace(env, "_reg %lu",what);;
447 #line 98
448
449 {
450 prog_counter_t regval = env_register_read(env, what);
451
452 #line 101
453 do {
454 #line 101
455 push(env, (STKVAL)(mft_number)(regval));
456 #line 101
457 goto endlab;
458 #line 101
459 } while (0);
460 }
461 endlab:
462 #line 103
463 env_function_cleanup_flush(env, NULL);
464 #line 103
465 return;
466 #line 103
467 }
468
469 void
470 #line 105
bi__expand_dataseg(eval_environ_t env)471 bi__expand_dataseg(eval_environ_t env)
472 #line 105
473
474 #line 105
475
476 #line 105 "debug.bi"
477 {
478 #line 105
479
480 #line 105
481
482 #line 105
483
484 #line 105
485 long words;
486 #line 105
487
488 #line 105
489 get_numeric_arg(env, 0, &words);
490 #line 105
491
492 #line 105
493
494 #line 105
495 adjust_stack(env, 1);
496 #line 105
497
498 #line 105
499
500 #line 105
501 if (builtin_module_trace(BUILTIN_IDX_debug))
502 #line 105
503 prog_trace(env, "_expand_dataseg %lu",words);;
504 #line 105
505
506 {
507 if (!(expand_dataseg(env, words) == 0))
508 #line 107
509 (
510 #line 107
511 env_throw_bi(env, mfe_failure, "_expand_dataseg", _("out of stack space; increase #pragma stacksize"))
512 #line 107
513 )
514 #line 109
515 ;
516 }
517
518 #line 111
519 env_function_cleanup_flush(env, NULL);
520 #line 111
521 return;
522 #line 111
523 }
524
525 void
526 #line 113
bi__wd(eval_environ_t env)527 bi__wd(eval_environ_t env)
528 #line 113
529
530 #line 113
531
532 #line 113 "debug.bi"
533 {
534 #line 113
535
536 #line 113
537
538 #line 113
539 long __bi_argcnt;
540 #line 113
541 long seconds;
542 #line 113
543
544 #line 113
545 get_numeric_arg(env, 1, &seconds);
546 #line 113
547
548 #line 113
549 get_numeric_arg(env, 0, &__bi_argcnt);
550 #line 113
551 adjust_stack(env, __bi_argcnt + 1);
552 #line 113
553
554 #line 113
555
556 #line 113
557 if (builtin_module_trace(BUILTIN_IDX_debug))
558 #line 113
559 prog_trace(env, "_wd %lu",((__bi_argcnt > 0) ? seconds : 0));;
560 #line 113
561
562 {
563 mu_wd(((__bi_argcnt > 0) ? seconds : 0));
564 }
565
566 #line 117
567 env_function_cleanup_flush(env, NULL);
568 #line 117
569 return;
570 #line 117
571 }
572
573 void
574 #line 119
bi_callout_transcript(eval_environ_t env)575 bi_callout_transcript(eval_environ_t env)
576 #line 119
577
578 #line 119
579
580 #line 119 "debug.bi"
581 {
582 #line 119
583
584 #line 119
585
586 #line 119
587 long __bi_argcnt;
588 #line 119
589 long val;
590 #line 119
591
592 #line 119
593 get_numeric_arg(env, 1, &val);
594 #line 119
595
596 #line 119
597 get_numeric_arg(env, 0, &__bi_argcnt);
598 #line 119
599 adjust_stack(env, __bi_argcnt + 1);
600 #line 119
601
602 #line 119
603
604 #line 119
605 if (builtin_module_trace(BUILTIN_IDX_debug))
606 #line 119
607 prog_trace(env, "callout_transcript %lu",((__bi_argcnt > 0) ? val : 0));;
608 #line 119
609
610 {
611 int oldval = smtp_transcript;
612 if ((__bi_argcnt > 0))
613 smtp_transcript = val;
614
615 #line 124
616 do {
617 #line 124
618 push(env, (STKVAL)(mft_number)(oldval));
619 #line 124
620 goto endlab;
621 #line 124
622 } while (0);
623 }
624 endlab:
625 #line 126
626 env_function_cleanup_flush(env, NULL);
627 #line 126
628 return;
629 #line 126
630 }
631
632
633 #line 136
634
635 #line 982 "../../src/builtin/snarf.m4"
636
637 #line 982
638
639 #line 982
640
641 #line 982
642 void
643 #line 982
debug_init_builtin(void)644 debug_init_builtin(void)
645 #line 982
646 {
647 #line 982
648
649 #line 982
650 #line 21 "debug.bi"
651 va_builtin_install_ex("debug_level", bi_debug_level, 0, dtype_number, 1, 1, 0|0, dtype_string);
652 #line 34 "debug.bi"
653 va_builtin_install_ex("debug_spec", bi_debug_spec, 0, dtype_string, 2, 2, 0|0, dtype_string, dtype_number);
654 #line 67 "debug.bi"
655 va_builtin_install_ex("debug", bi_debug, 0, dtype_unspecified, 1, 0, 0|0, dtype_string);
656 #line 80 "debug.bi"
657 va_builtin_install_ex("program_trace", bi_program_trace, 0, dtype_unspecified, 1, 0, 0|0, dtype_string);
658 #line 86 "debug.bi"
659 va_builtin_install_ex("cancel_program_trace", bi_cancel_program_trace, 0, dtype_unspecified, 1, 0, 0|0, dtype_string);
660 #line 92 "debug.bi"
661 va_builtin_install_ex("stack_trace", bi_stack_trace, 0, dtype_unspecified, 0, 0, 0|0, dtype_unspecified);
662 #line 98 "debug.bi"
663 va_builtin_install_ex("_reg", bi__reg, 0, dtype_number, 1, 0, 0|0, dtype_number);
664 #line 105 "debug.bi"
665 va_builtin_install_ex("_expand_dataseg", bi__expand_dataseg, 0, dtype_unspecified, 1, 0, 0|0, dtype_number);
666 #line 113 "debug.bi"
667 va_builtin_install_ex("_wd", bi__wd, 0, dtype_unspecified, 1, 1, 0|0, dtype_number);
668 #line 119 "debug.bi"
669 va_builtin_install_ex("callout_transcript", bi_callout_transcript, 0, dtype_number, 1, 1, 0|0, dtype_number);
670
671 #line 982 "../../src/builtin/snarf.m4"
672
673 #line 982
674 /* Declare mailutils_set_debug_level as an alias to 'debug'.
675 I do that manually, because there is no m4 magic for that
676 (so far it is the only built-in alias). */
677 #line 982
678 va_builtin_install_ex("mailutils_set_debug_level",
679 #line 982
680 bi_debug, 0, dtype_unspecified, 1, 0, 0,
681 #line 982
682 dtype_string);
683 #line 982
684
685 #line 982
686 }
687 #line 982 "../../src/builtin/snarf.m4"
688
689