forked from gbenson/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
3371 lines (2754 loc) · 85.1 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* General utility routines for GDB, the GNU debugger.
Copyright (C) 1986-2015 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "dyn-string.h"
#include <ctype.h>
#include "gdb_wait.h"
#include "event-top.h"
#include "gdbthread.h"
#include "fnmatch.h"
#include "gdb_bfd.h"
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif /* HAVE_SYS_RESOURCE_H */
#ifdef TUI
#include "tui/tui.h" /* For tui_get_command_dimension. */
#endif
#ifdef __GO32__
#include <pc.h>
#endif
#include <signal.h>
#include "timeval-utils.h"
#include "gdbcmd.h"
#include "serial.h"
#include "bfd.h"
#include "target.h"
#include "gdb-demangle.h"
#include "expression.h"
#include "language.h"
#include "charset.h"
#include "annotate.h"
#include "filenames.h"
#include "symfile.h"
#include "gdb_obstack.h"
#include "gdbcore.h"
#include "top.h"
#include "main.h"
#include "solist.h"
#include "inferior.h" /* for signed_pointer_to_address */
#include "gdb_curses.h"
#include "readline/readline.h"
#include "gdb_sys_time.h"
#include <time.h>
#include "gdb_usleep.h"
#include "interps.h"
#include "gdb_regex.h"
#if !HAVE_DECL_MALLOC
extern PTR malloc (); /* ARI: PTR */
#endif
#if !HAVE_DECL_REALLOC
extern PTR realloc (); /* ARI: PTR */
#endif
#if !HAVE_DECL_FREE
extern void free ();
#endif
void (*deprecated_error_begin_hook) (void);
/* Prototypes for local functions */
static void vfprintf_maybe_filtered (struct ui_file *, const char *,
va_list, int) ATTRIBUTE_PRINTF (2, 0);
static void fputs_maybe_filtered (const char *, struct ui_file *, int);
static void prompt_for_continue (void);
static void set_screen_size (void);
static void set_width (void);
/* Time spent in prompt_for_continue in the currently executing command
waiting for user to respond.
Initialized in make_command_stats_cleanup.
Modified in prompt_for_continue and defaulted_query.
Used in report_command_stats. */
static struct timeval prompt_for_continue_wait_time;
/* A flag indicating whether to timestamp debugging messages. */
static int debug_timestamp = 0;
/* Nonzero if we have job control. */
int job_control;
/* Nonzero means quit immediately if Control-C is typed now, rather
than waiting until QUIT is executed. Be careful in setting this;
code which executes with immediate_quit set has to be very careful
about being able to deal with being interrupted at any time. It is
almost always better to use QUIT; the only exception I can think of
is being able to quit out of a system call (using EINTR loses if
the SIGINT happens between the previous QUIT and the system call).
To immediately quit in the case in which a SIGINT happens between
the previous QUIT and setting immediate_quit (desirable anytime we
expect to block), call QUIT after setting immediate_quit. */
int immediate_quit;
/* Nonzero means that strings with character values >0x7F should be printed
as octal escapes. Zero means just print the value (e.g. it's an
international character, and the terminal or window can cope.) */
int sevenbit_strings = 0;
static void
show_sevenbit_strings (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("Printing of 8-bit characters "
"in strings as \\nnn is %s.\n"),
value);
}
/* String to be printed before warning messages, if any. */
char *warning_pre_print = "\nwarning: ";
int pagination_enabled = 1;
static void
show_pagination_enabled (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("State of pagination is %s.\n"), value);
}
/* Cleanup utilities.
These are not defined in cleanups.c (nor declared in cleanups.h)
because while they use the "cleanup API" they are not part of the
"cleanup API". */
static void
do_freeargv (void *arg)
{
freeargv ((char **) arg);
}
struct cleanup *
make_cleanup_freeargv (char **arg)
{
return make_cleanup (do_freeargv, arg);
}
static void
do_dyn_string_delete (void *arg)
{
dyn_string_delete ((dyn_string_t) arg);
}
struct cleanup *
make_cleanup_dyn_string_delete (dyn_string_t arg)
{
return make_cleanup (do_dyn_string_delete, arg);
}
static void
do_bfd_close_cleanup (void *arg)
{
gdb_bfd_unref (arg);
}
struct cleanup *
make_cleanup_bfd_unref (bfd *abfd)
{
return make_cleanup (do_bfd_close_cleanup, abfd);
}
/* Helper function which does the work for make_cleanup_fclose. */
static void
do_fclose_cleanup (void *arg)
{
FILE *file = arg;
fclose (file);
}
/* Return a new cleanup that closes FILE. */
struct cleanup *
make_cleanup_fclose (FILE *file)
{
return make_cleanup (do_fclose_cleanup, file);
}
/* Helper function which does the work for make_cleanup_obstack_free. */
static void
do_obstack_free (void *arg)
{
struct obstack *ob = arg;
obstack_free (ob, NULL);
}
/* Return a new cleanup that frees OBSTACK. */
struct cleanup *
make_cleanup_obstack_free (struct obstack *obstack)
{
return make_cleanup (do_obstack_free, obstack);
}
static void
do_ui_file_delete (void *arg)
{
ui_file_delete (arg);
}
struct cleanup *
make_cleanup_ui_file_delete (struct ui_file *arg)
{
return make_cleanup (do_ui_file_delete, arg);
}
/* Helper function for make_cleanup_ui_out_redirect_pop. */
static void
do_ui_out_redirect_pop (void *arg)
{
struct ui_out *uiout = arg;
if (ui_out_redirect (uiout, NULL) < 0)
warning (_("Cannot restore redirection of the current output protocol"));
}
/* Return a new cleanup that pops the last redirection by ui_out_redirect
with NULL parameter. */
struct cleanup *
make_cleanup_ui_out_redirect_pop (struct ui_out *uiout)
{
return make_cleanup (do_ui_out_redirect_pop, uiout);
}
static void
do_free_section_addr_info (void *arg)
{
free_section_addr_info (arg);
}
struct cleanup *
make_cleanup_free_section_addr_info (struct section_addr_info *addrs)
{
return make_cleanup (do_free_section_addr_info, addrs);
}
struct restore_integer_closure
{
int *variable;
int value;
};
static void
restore_integer (void *p)
{
struct restore_integer_closure *closure = p;
*(closure->variable) = closure->value;
}
/* Remember the current value of *VARIABLE and make it restored when
the cleanup is run. */
struct cleanup *
make_cleanup_restore_integer (int *variable)
{
struct restore_integer_closure *c = XNEW (struct restore_integer_closure);
c->variable = variable;
c->value = *variable;
return make_cleanup_dtor (restore_integer, (void *) c, xfree);
}
/* Remember the current value of *VARIABLE and make it restored when
the cleanup is run. */
struct cleanup *
make_cleanup_restore_uinteger (unsigned int *variable)
{
return make_cleanup_restore_integer ((int *) variable);
}
/* Helper for make_cleanup_unpush_target. */
static void
do_unpush_target (void *arg)
{
struct target_ops *ops = arg;
unpush_target (ops);
}
/* Return a new cleanup that unpushes OPS. */
struct cleanup *
make_cleanup_unpush_target (struct target_ops *ops)
{
return make_cleanup (do_unpush_target, ops);
}
/* Helper for make_cleanup_htab_delete compile time checking the types. */
static void
do_htab_delete_cleanup (void *htab_voidp)
{
htab_t htab = htab_voidp;
htab_delete (htab);
}
/* Return a new cleanup that deletes HTAB. */
struct cleanup *
make_cleanup_htab_delete (htab_t htab)
{
return make_cleanup (do_htab_delete_cleanup, htab);
}
struct restore_ui_file_closure
{
struct ui_file **variable;
struct ui_file *value;
};
static void
do_restore_ui_file (void *p)
{
struct restore_ui_file_closure *closure = p;
*(closure->variable) = closure->value;
}
/* Remember the current value of *VARIABLE and make it restored when
the cleanup is run. */
struct cleanup *
make_cleanup_restore_ui_file (struct ui_file **variable)
{
struct restore_ui_file_closure *c = XNEW (struct restore_ui_file_closure);
c->variable = variable;
c->value = *variable;
return make_cleanup_dtor (do_restore_ui_file, (void *) c, xfree);
}
/* Helper for make_cleanup_value_free_to_mark. */
static void
do_value_free_to_mark (void *value)
{
value_free_to_mark ((struct value *) value);
}
/* Free all values allocated since MARK was obtained by value_mark
(except for those released) when the cleanup is run. */
struct cleanup *
make_cleanup_value_free_to_mark (struct value *mark)
{
return make_cleanup (do_value_free_to_mark, mark);
}
/* Helper for make_cleanup_value_free. */
static void
do_value_free (void *value)
{
value_free (value);
}
/* Free VALUE. */
struct cleanup *
make_cleanup_value_free (struct value *value)
{
return make_cleanup (do_value_free, value);
}
/* Helper for make_cleanup_free_so. */
static void
do_free_so (void *arg)
{
struct so_list *so = arg;
free_so (so);
}
/* Make cleanup handler calling free_so for SO. */
struct cleanup *
make_cleanup_free_so (struct so_list *so)
{
return make_cleanup (do_free_so, so);
}
/* Helper for make_cleanup_restore_current_language. */
static void
do_restore_current_language (void *p)
{
enum language saved_lang = (enum language) (uintptr_t) p;
set_language (saved_lang);
}
/* Remember the current value of CURRENT_LANGUAGE and make it restored when
the cleanup is run. */
struct cleanup *
make_cleanup_restore_current_language (void)
{
enum language saved_lang = current_language->la_language;
return make_cleanup (do_restore_current_language,
(void *) (uintptr_t) saved_lang);
}
/* Helper function for make_cleanup_clear_parser_state. */
static void
do_clear_parser_state (void *ptr)
{
struct parser_state **p = (struct parser_state **) ptr;
*p = NULL;
}
/* Clean (i.e., set to NULL) the parser state variable P. */
struct cleanup *
make_cleanup_clear_parser_state (struct parser_state **p)
{
return make_cleanup (do_clear_parser_state, (void *) p);
}
/* This function is useful for cleanups.
Do
foo = xmalloc (...);
old_chain = make_cleanup (free_current_contents, &foo);
to arrange to free the object thus allocated. */
void
free_current_contents (void *ptr)
{
void **location = ptr;
if (location == NULL)
internal_error (__FILE__, __LINE__,
_("free_current_contents: NULL pointer"));
if (*location != NULL)
{
xfree (*location);
*location = NULL;
}
}
/* Print a warning message. The first argument STRING is the warning
message, used as an fprintf format string, the second is the
va_list of arguments for that string. A warning is unfiltered (not
paginated) so that the user does not need to page through each
screen full of warnings when there are lots of them. */
void
vwarning (const char *string, va_list args)
{
if (deprecated_warning_hook)
(*deprecated_warning_hook) (string, args);
else
{
if (target_supports_terminal_ours ())
target_terminal_ours ();
if (filtered_printing_initialized ())
wrap_here (""); /* Force out any buffered output. */
gdb_flush (gdb_stdout);
if (warning_pre_print)
fputs_unfiltered (warning_pre_print, gdb_stderr);
vfprintf_unfiltered (gdb_stderr, string, args);
fprintf_unfiltered (gdb_stderr, "\n");
}
}
/* Print an error message and return to command level.
The first argument STRING is the error message, used as a fprintf string,
and the remaining args are passed as arguments to it. */
void
verror (const char *string, va_list args)
{
throw_verror (GENERIC_ERROR, string, args);
}
void
error_stream (struct ui_file *stream)
{
char *message = ui_file_xstrdup (stream, NULL);
make_cleanup (xfree, message);
error (("%s"), message);
}
/* Emit a message and abort. */
static void ATTRIBUTE_NORETURN
abort_with_message (const char *msg)
{
if (gdb_stderr == NULL)
fputs (msg, stderr);
else
fputs_unfiltered (msg, gdb_stderr);
abort (); /* NOTE: GDB has only three calls to abort(). */
}
/* Dump core trying to increase the core soft limit to hard limit first. */
void
dump_core (void)
{
#ifdef HAVE_SETRLIMIT
struct rlimit rlim = { RLIM_INFINITY, RLIM_INFINITY };
setrlimit (RLIMIT_CORE, &rlim);
#endif /* HAVE_SETRLIMIT */
abort (); /* NOTE: GDB has only three calls to abort(). */
}
/* Check whether GDB will be able to dump core using the dump_core
function. Returns zero if GDB cannot or should not dump core.
If LIMIT_KIND is LIMIT_CUR the user's soft limit will be respected.
If LIMIT_KIND is LIMIT_MAX only the hard limit will be respected. */
int
can_dump_core (enum resource_limit_kind limit_kind)
{
#ifdef HAVE_GETRLIMIT
struct rlimit rlim;
/* Be quiet and assume we can dump if an error is returned. */
if (getrlimit (RLIMIT_CORE, &rlim) != 0)
return 1;
switch (limit_kind)
{
case LIMIT_CUR:
if (rlim.rlim_cur == 0)
return 0;
case LIMIT_MAX:
if (rlim.rlim_max == 0)
return 0;
}
#endif /* HAVE_GETRLIMIT */
return 1;
}
/* Print a warning that we cannot dump core. */
void
warn_cant_dump_core (const char *reason)
{
fprintf_unfiltered (gdb_stderr,
_("%s\nUnable to dump core, use `ulimit -c"
" unlimited' before executing GDB next time.\n"),
reason);
}
/* Check whether GDB will be able to dump core using the dump_core
function, and print a warning if we cannot. */
static int
can_dump_core_warn (enum resource_limit_kind limit_kind,
const char *reason)
{
int core_dump_allowed = can_dump_core (limit_kind);
if (!core_dump_allowed)
warn_cant_dump_core (reason);
return core_dump_allowed;
}
/* Allow the user to configure the debugger behavior with respect to
what to do when an internal problem is detected. */
const char internal_problem_ask[] = "ask";
const char internal_problem_yes[] = "yes";
const char internal_problem_no[] = "no";
static const char *const internal_problem_modes[] =
{
internal_problem_ask,
internal_problem_yes,
internal_problem_no,
NULL
};
/* Print a message reporting an internal error/warning. Ask the user
if they want to continue, dump core, or just exit. Return
something to indicate a quit. */
struct internal_problem
{
const char *name;
int user_settable_should_quit;
const char *should_quit;
int user_settable_should_dump_core;
const char *should_dump_core;
};
/* Report a problem, internal to GDB, to the user. Once the problem
has been reported, and assuming GDB didn't quit, the caller can
either allow execution to resume or throw an error. */
static void ATTRIBUTE_PRINTF (4, 0)
internal_vproblem (struct internal_problem *problem,
const char *file, int line, const char *fmt, va_list ap)
{
static int dejavu;
int quit_p;
int dump_core_p;
char *reason;
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
/* Don't allow infinite error/warning recursion. */
{
static char msg[] = "Recursive internal problem.\n";
switch (dejavu)
{
case 0:
dejavu = 1;
break;
case 1:
dejavu = 2;
abort_with_message (msg);
default:
dejavu = 3;
/* Newer GLIBC versions put the warn_unused_result attribute
on write, but this is one of those rare cases where
ignoring the return value is correct. Casting to (void)
does not fix this problem. This is the solution suggested
at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509. */
if (write (STDERR_FILENO, msg, sizeof (msg)) != sizeof (msg))
abort (); /* NOTE: GDB has only three calls to abort(). */
exit (1);
}
}
/* Create a string containing the full error/warning message. Need
to call query with this full string, as otherwize the reason
(error/warning) and question become separated. Format using a
style similar to a compiler error message. Include extra detail
so that the user knows that they are living on the edge. */
{
char *msg;
msg = xstrvprintf (fmt, ap);
reason = xstrprintf ("%s:%d: %s: %s\n"
"A problem internal to GDB has been detected,\n"
"further debugging may prove unreliable.",
file, line, problem->name, msg);
xfree (msg);
make_cleanup (xfree, reason);
}
/* Fall back to abort_with_message if gdb_stderr is not set up. */
if (gdb_stderr == NULL)
{
fputs (reason, stderr);
abort_with_message ("\n");
}
/* Try to get the message out and at the start of a new line. */
if (target_supports_terminal_ours ())
target_terminal_ours ();
if (filtered_printing_initialized ())
begin_line ();
/* Emit the message unless query will emit it below. */
if (problem->should_quit != internal_problem_ask
|| !confirm
|| !filtered_printing_initialized ())
fprintf_unfiltered (gdb_stderr, "%s\n", reason);
if (problem->should_quit == internal_problem_ask)
{
/* Default (yes/batch case) is to quit GDB. When in batch mode
this lessens the likelihood of GDB going into an infinite
loop. */
if (!confirm || !filtered_printing_initialized ())
quit_p = 1;
else
quit_p = query (_("%s\nQuit this debugging session? "), reason);
}
else if (problem->should_quit == internal_problem_yes)
quit_p = 1;
else if (problem->should_quit == internal_problem_no)
quit_p = 0;
else
internal_error (__FILE__, __LINE__, _("bad switch"));
fputs_unfiltered (_("\nThis is a bug, please report it."), gdb_stderr);
if (REPORT_BUGS_TO[0])
fprintf_unfiltered (gdb_stderr, _(" For instructions, see:\n%s."),
REPORT_BUGS_TO);
fputs_unfiltered ("\n\n", gdb_stderr);
if (problem->should_dump_core == internal_problem_ask)
{
if (!can_dump_core_warn (LIMIT_MAX, reason))
dump_core_p = 0;
else if (!filtered_printing_initialized ())
dump_core_p = 1;
else
{
/* Default (yes/batch case) is to dump core. This leaves a GDB
`dropping' so that it is easier to see that something went
wrong in GDB. */
dump_core_p = query (_("%s\nCreate a core file of GDB? "), reason);
}
}
else if (problem->should_dump_core == internal_problem_yes)
dump_core_p = can_dump_core_warn (LIMIT_MAX, reason);
else if (problem->should_dump_core == internal_problem_no)
dump_core_p = 0;
else
internal_error (__FILE__, __LINE__, _("bad switch"));
if (quit_p)
{
if (dump_core_p)
dump_core ();
else
exit (1);
}
else
{
if (dump_core_p)
{
#ifdef HAVE_WORKING_FORK
if (fork () == 0)
dump_core ();
#endif
}
}
dejavu = 0;
do_cleanups (cleanup);
}
static struct internal_problem internal_error_problem = {
"internal-error", 1, internal_problem_ask, 1, internal_problem_ask
};
void
internal_verror (const char *file, int line, const char *fmt, va_list ap)
{
internal_vproblem (&internal_error_problem, file, line, fmt, ap);
throw_quit (_("Command aborted."));
}
static struct internal_problem internal_warning_problem = {
"internal-warning", 1, internal_problem_ask, 1, internal_problem_ask
};
void
internal_vwarning (const char *file, int line, const char *fmt, va_list ap)
{
internal_vproblem (&internal_warning_problem, file, line, fmt, ap);
}
static struct internal_problem demangler_warning_problem = {
"demangler-warning", 1, internal_problem_ask, 0, internal_problem_no
};
void
demangler_vwarning (const char *file, int line, const char *fmt, va_list ap)
{
internal_vproblem (&demangler_warning_problem, file, line, fmt, ap);
}
void
demangler_warning (const char *file, int line, const char *string, ...)
{
va_list ap;
va_start (ap, string);
demangler_vwarning (file, line, string, ap);
va_end (ap);
}
/* Dummy functions to keep add_prefix_cmd happy. */
static void
set_internal_problem_cmd (char *args, int from_tty)
{
}
static void
show_internal_problem_cmd (char *args, int from_tty)
{
}
/* When GDB reports an internal problem (error or warning) it gives
the user the opportunity to quit GDB and/or create a core file of
the current debug session. This function registers a few commands
that make it possible to specify that GDB should always or never
quit or create a core file, without asking. The commands look
like:
maint set PROBLEM-NAME quit ask|yes|no
maint show PROBLEM-NAME quit
maint set PROBLEM-NAME corefile ask|yes|no
maint show PROBLEM-NAME corefile
Where PROBLEM-NAME is currently "internal-error" or
"internal-warning". */
static void
add_internal_problem_command (struct internal_problem *problem)
{
struct cmd_list_element **set_cmd_list;
struct cmd_list_element **show_cmd_list;
char *set_doc;
char *show_doc;
set_cmd_list = XNEW (struct cmd_list_element *);
show_cmd_list = XNEW (struct cmd_list_element *);
*set_cmd_list = NULL;
*show_cmd_list = NULL;
set_doc = xstrprintf (_("Configure what GDB does when %s is detected."),
problem->name);
show_doc = xstrprintf (_("Show what GDB does when %s is detected."),
problem->name);
add_prefix_cmd ((char*) problem->name,
class_maintenance, set_internal_problem_cmd, set_doc,
set_cmd_list,
concat ("maintenance set ", problem->name, " ",
(char *) NULL),
0/*allow-unknown*/, &maintenance_set_cmdlist);
add_prefix_cmd ((char*) problem->name,
class_maintenance, show_internal_problem_cmd, show_doc,
show_cmd_list,
concat ("maintenance show ", problem->name, " ",
(char *) NULL),
0/*allow-unknown*/, &maintenance_show_cmdlist);
if (problem->user_settable_should_quit)
{
set_doc = xstrprintf (_("Set whether GDB should quit "
"when an %s is detected"),
problem->name);
show_doc = xstrprintf (_("Show whether GDB will quit "
"when an %s is detected"),
problem->name);
add_setshow_enum_cmd ("quit", class_maintenance,
internal_problem_modes,
&problem->should_quit,
set_doc,
show_doc,
NULL, /* help_doc */
NULL, /* setfunc */
NULL, /* showfunc */
set_cmd_list,
show_cmd_list);
xfree (set_doc);
xfree (show_doc);
}
if (problem->user_settable_should_dump_core)
{
set_doc = xstrprintf (_("Set whether GDB should create a core "
"file of GDB when %s is detected"),
problem->name);
show_doc = xstrprintf (_("Show whether GDB will create a core "
"file of GDB when %s is detected"),
problem->name);
add_setshow_enum_cmd ("corefile", class_maintenance,
internal_problem_modes,
&problem->should_dump_core,
set_doc,
show_doc,
NULL, /* help_doc */
NULL, /* setfunc */
NULL, /* showfunc */
set_cmd_list,
show_cmd_list);
xfree (set_doc);
xfree (show_doc);
}
}
/* Return a newly allocated string, containing the PREFIX followed
by the system error message for errno (separated by a colon).
The result must be deallocated after use. */
static char *
perror_string (const char *prefix)
{
char *err;
char *combined;
err = safe_strerror (errno);
combined = (char *) xmalloc (strlen (err) + strlen (prefix) + 3);
strcpy (combined, prefix);
strcat (combined, ": ");
strcat (combined, err);
return combined;
}
/* Print the system error message for errno, and also mention STRING
as the file name for which the error was encountered. Use ERRCODE
for the thrown exception. Then return to command level. */
void
throw_perror_with_name (enum errors errcode, const char *string)
{
char *combined;
combined = perror_string (string);
make_cleanup (xfree, combined);
/* I understand setting these is a matter of taste. Still, some people
may clear errno but not know about bfd_error. Doing this here is not
unreasonable. */
bfd_set_error (bfd_error_no_error);
errno = 0;
throw_error (errcode, _("%s."), combined);
}
/* See throw_perror_with_name, ERRCODE defaults here to GENERIC_ERROR. */
void
perror_with_name (const char *string)
{
throw_perror_with_name (GENERIC_ERROR, string);
}
/* Same as perror_with_name except that it prints a warning instead
of throwing an error. */
void
perror_warning_with_name (const char *string)
{
char *combined;
combined = perror_string (string);
warning (_("%s"), combined);
xfree (combined);
}
/* Print the system error message for ERRCODE, and also mention STRING
as the file name for which the error was encountered. */
void
print_sys_errmsg (const char *string, int errcode)