forked from gbenson/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.c
2678 lines (2301 loc) · 76.9 KB
/
stack.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
/* Print and select stack frames 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 "value.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "expression.h"
#include "language.h"
#include "frame.h"
#include "gdbcmd.h"
#include "gdbcore.h"
#include "target.h"
#include "source.h"
#include "breakpoint.h"
#include "demangle.h"
#include "inferior.h"
#include "annotate.h"
#include "ui-out.h"
#include "block.h"
#include "stack.h"
#include "dictionary.h"
#include "reggroups.h"
#include "regcache.h"
#include "solib.h"
#include "valprint.h"
#include "gdbthread.h"
#include "cp-support.h"
#include "disasm.h"
#include "inline-frame.h"
#include "linespec.h"
#include "cli/cli-utils.h"
#include "objfiles.h"
#include <ctype.h>
#include "symfile.h"
#include "extension.h"
/* The possible choices of "set print frame-arguments", and the value
of this setting. */
static const char *const print_frame_arguments_choices[] =
{"all", "scalars", "none", NULL};
static const char *print_frame_arguments = "scalars";
/* If non-zero, don't invoke pretty-printers for frame arguments. */
static int print_raw_frame_arguments;
/* The possible choices of "set print entry-values", and the value
of this setting. */
const char print_entry_values_no[] = "no";
const char print_entry_values_only[] = "only";
const char print_entry_values_preferred[] = "preferred";
const char print_entry_values_if_needed[] = "if-needed";
const char print_entry_values_both[] = "both";
const char print_entry_values_compact[] = "compact";
const char print_entry_values_default[] = "default";
static const char *const print_entry_values_choices[] =
{
print_entry_values_no,
print_entry_values_only,
print_entry_values_preferred,
print_entry_values_if_needed,
print_entry_values_both,
print_entry_values_compact,
print_entry_values_default,
NULL
};
const char *print_entry_values = print_entry_values_default;
/* Prototypes for local functions. */
static void print_frame_local_vars (struct frame_info *, int,
struct ui_file *);
static void print_frame (struct frame_info *frame, int print_level,
enum print_what print_what, int print_args,
struct symtab_and_line sal);
static void set_last_displayed_sal (int valid,
struct program_space *pspace,
CORE_ADDR addr,
struct symtab *symtab,
int line);
/* Zero means do things normally; we are interacting directly with the
user. One means print the full filename and linenumber when a
frame is printed, and do so in a format emacs18/emacs19.22 can
parse. Two means print similar annotations, but in many more
cases and in a slightly different syntax. */
int annotation_level = 0;
/* These variables hold the last symtab and line we displayed to the user.
* This is where we insert a breakpoint or a skiplist entry by default. */
static int last_displayed_sal_valid = 0;
static struct program_space *last_displayed_pspace = 0;
static CORE_ADDR last_displayed_addr = 0;
static struct symtab *last_displayed_symtab = 0;
static int last_displayed_line = 0;
/* Return 1 if we should display the address in addition to the location,
because we are in the middle of a statement. */
static int
frame_show_address (struct frame_info *frame,
struct symtab_and_line sal)
{
/* If there is a line number, but no PC, then there is no location
information associated with this sal. The only way that should
happen is for the call sites of inlined functions (SAL comes from
find_frame_sal). Otherwise, we would have some PC range if the
SAL came from a line table. */
if (sal.line != 0 && sal.pc == 0 && sal.end == 0)
{
if (get_next_frame (frame) == NULL)
gdb_assert (inline_skipped_frames (inferior_ptid) > 0);
else
gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME);
return 0;
}
return get_frame_pc (frame) != sal.pc;
}
/* Show or print a stack frame FRAME briefly. The output is format
according to PRINT_LEVEL and PRINT_WHAT printing the frame's
relative level, function name, argument list, and file name and
line number. If the frame's PC is not at the beginning of the
source line, the actual PC is printed at the beginning. */
void
print_stack_frame (struct frame_info *frame, int print_level,
enum print_what print_what,
int set_current_sal)
{
/* For mi, alway print location and address. */
if (ui_out_is_mi_like_p (current_uiout))
print_what = LOC_AND_ADDRESS;
TRY
{
print_frame_info (frame, print_level, print_what, 1 /* print_args */,
set_current_sal);
if (set_current_sal)
set_current_sal_from_frame (frame);
}
CATCH (e, RETURN_MASK_ERROR)
{
}
END_CATCH
}
/* Print nameless arguments of frame FRAME on STREAM, where START is
the offset of the first nameless argument, and NUM is the number of
nameless arguments to print. FIRST is nonzero if this is the first
argument (not just the first nameless argument). */
static void
print_frame_nameless_args (struct frame_info *frame, long start, int num,
int first, struct ui_file *stream)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
int i;
CORE_ADDR argsaddr;
long arg_value;
for (i = 0; i < num; i++)
{
QUIT;
argsaddr = get_frame_args_address (frame);
if (!argsaddr)
return;
arg_value = read_memory_integer (argsaddr + start,
sizeof (int), byte_order);
if (!first)
fprintf_filtered (stream, ", ");
fprintf_filtered (stream, "%ld", arg_value);
first = 0;
start += sizeof (int);
}
}
/* Print single argument of inferior function. ARG must be already
read in.
Errors are printed as if they would be the parameter value. Use zeroed ARG
iff it should not be printed accoring to user settings. */
static void
print_frame_arg (const struct frame_arg *arg)
{
struct ui_out *uiout = current_uiout;
struct cleanup *old_chain;
struct ui_file *stb;
const char *error_message = NULL;
stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb);
gdb_assert (!arg->val || !arg->error);
gdb_assert (arg->entry_kind == print_entry_values_no
|| arg->entry_kind == print_entry_values_only
|| (!ui_out_is_mi_like_p (uiout)
&& arg->entry_kind == print_entry_values_compact));
annotate_arg_begin ();
make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (arg->sym),
SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
if (arg->entry_kind == print_entry_values_compact)
{
/* It is OK to provide invalid MI-like stream as with
PRINT_ENTRY_VALUE_COMPACT we never use MI. */
fputs_filtered ("=", stb);
fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (arg->sym),
SYMBOL_LANGUAGE (arg->sym),
DMGL_PARAMS | DMGL_ANSI);
}
if (arg->entry_kind == print_entry_values_only
|| arg->entry_kind == print_entry_values_compact)
fputs_filtered ("@entry", stb);
ui_out_field_stream (uiout, "name", stb);
annotate_arg_name_end ();
ui_out_text (uiout, "=");
if (!arg->val && !arg->error)
ui_out_text (uiout, "...");
else
{
if (arg->error)
error_message = arg->error;
else
{
TRY
{
const struct language_defn *language;
struct value_print_options opts;
/* Avoid value_print because it will deref ref parameters. We
just want to print their addresses. Print ??? for args whose
address we do not know. We pass 2 as "recurse" to val_print
because our standard indentation here is 4 spaces, and
val_print indents 2 for each recurse. */
annotate_arg_value (value_type (arg->val));
/* Use the appropriate language to display our symbol, unless the
user forced the language to a specific language. */
if (language_mode == language_mode_auto)
language = language_def (SYMBOL_LANGUAGE (arg->sym));
else
language = current_language;
get_no_prettyformat_print_options (&opts);
opts.deref_ref = 1;
opts.raw = print_raw_frame_arguments;
/* True in "summary" mode, false otherwise. */
opts.summary = !strcmp (print_frame_arguments, "scalars");
common_val_print (arg->val, stb, 2, &opts, language);
}
CATCH (except, RETURN_MASK_ERROR)
{
error_message = except.message;
}
END_CATCH
}
if (error_message != NULL)
fprintf_filtered (stb, _("<error reading variable: %s>"),
error_message);
}
ui_out_field_stream (uiout, "value", stb);
/* Also invoke ui_out_tuple_end. */
do_cleanups (old_chain);
annotate_arg_end ();
}
/* Read in inferior function local SYM at FRAME into ARGP. Caller is
responsible for xfree of ARGP->ERROR. This function never throws an
exception. */
void
read_frame_local (struct symbol *sym, struct frame_info *frame,
struct frame_arg *argp)
{
struct value *val = NULL;
argp->sym = sym;
argp->val = NULL;
argp->error = NULL;
TRY
{
argp->val = read_var_value (sym, NULL, frame);
}
CATCH (except, RETURN_MASK_ERROR)
{
argp->error = xstrdup (except.message);
}
END_CATCH
}
/* Read in inferior function parameter SYM at FRAME into ARGP. Caller is
responsible for xfree of ARGP->ERROR. This function never throws an
exception. */
void
read_frame_arg (struct symbol *sym, struct frame_info *frame,
struct frame_arg *argp, struct frame_arg *entryargp)
{
struct value *val = NULL, *entryval = NULL;
char *val_error = NULL, *entryval_error = NULL;
int val_equal = 0;
if (print_entry_values != print_entry_values_only
&& print_entry_values != print_entry_values_preferred)
{
TRY
{
val = read_var_value (sym, NULL, frame);
}
CATCH (except, RETURN_MASK_ERROR)
{
val_error = alloca (strlen (except.message) + 1);
strcpy (val_error, except.message);
}
END_CATCH
}
if (SYMBOL_COMPUTED_OPS (sym) != NULL
&& SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry != NULL
&& print_entry_values != print_entry_values_no
&& (print_entry_values != print_entry_values_if_needed
|| !val || value_optimized_out (val)))
{
TRY
{
const struct symbol_computed_ops *ops;
ops = SYMBOL_COMPUTED_OPS (sym);
entryval = ops->read_variable_at_entry (sym, frame);
}
CATCH (except, RETURN_MASK_ERROR)
{
if (except.error != NO_ENTRY_VALUE_ERROR)
{
entryval_error = (char *) alloca (strlen (except.message) + 1);
strcpy (entryval_error, except.message);
}
}
END_CATCH
if (entryval != NULL && value_optimized_out (entryval))
entryval = NULL;
if (print_entry_values == print_entry_values_compact
|| print_entry_values == print_entry_values_default)
{
/* For MI do not try to use print_entry_values_compact for ARGP. */
if (val && entryval && !ui_out_is_mi_like_p (current_uiout))
{
struct type *type = value_type (val);
if (value_lazy (val))
value_fetch_lazy (val);
if (value_lazy (entryval))
value_fetch_lazy (entryval);
if (value_contents_eq (val, 0, entryval, 0, TYPE_LENGTH (type)))
{
/* Initialize it just to avoid a GCC false warning. */
struct value *val_deref = NULL, *entryval_deref;
/* DW_AT_GNU_call_site_value does match with the current
value. If it is a reference still try to verify if
dereferenced DW_AT_GNU_call_site_data_value does not
differ. */
TRY
{
struct type *type_deref;
val_deref = coerce_ref (val);
if (value_lazy (val_deref))
value_fetch_lazy (val_deref);
type_deref = value_type (val_deref);
entryval_deref = coerce_ref (entryval);
if (value_lazy (entryval_deref))
value_fetch_lazy (entryval_deref);
/* If the reference addresses match but dereferenced
content does not match print them. */
if (val != val_deref
&& value_contents_eq (val_deref, 0,
entryval_deref, 0,
TYPE_LENGTH (type_deref)))
val_equal = 1;
}
CATCH (except, RETURN_MASK_ERROR)
{
/* If the dereferenced content could not be
fetched do not display anything. */
if (except.error == NO_ENTRY_VALUE_ERROR)
val_equal = 1;
else if (except.message != NULL)
{
entryval_error = (char *) alloca (strlen (except.message) + 1);
strcpy (entryval_error, except.message);
}
}
END_CATCH
/* Value was not a reference; and its content matches. */
if (val == val_deref)
val_equal = 1;
if (val_equal)
entryval = NULL;
}
}
/* Try to remove possibly duplicate error message for ENTRYARGP even
in MI mode. */
if (val_error && entryval_error
&& strcmp (val_error, entryval_error) == 0)
{
entryval_error = NULL;
/* Do not se VAL_EQUAL as the same error message may be shown for
the entry value even if no entry values are present in the
inferior. */
}
}
}
if (entryval == NULL)
{
if (print_entry_values == print_entry_values_preferred)
{
gdb_assert (val == NULL);
TRY
{
val = read_var_value (sym, NULL, frame);
}
CATCH (except, RETURN_MASK_ERROR)
{
val_error = alloca (strlen (except.message) + 1);
strcpy (val_error, except.message);
}
END_CATCH
}
if (print_entry_values == print_entry_values_only
|| print_entry_values == print_entry_values_both
|| (print_entry_values == print_entry_values_preferred
&& (!val || value_optimized_out (val))))
{
entryval = allocate_optimized_out_value (SYMBOL_TYPE (sym));
entryval_error = NULL;
}
}
if ((print_entry_values == print_entry_values_compact
|| print_entry_values == print_entry_values_if_needed
|| print_entry_values == print_entry_values_preferred)
&& (!val || value_optimized_out (val)) && entryval != NULL)
{
val = NULL;
val_error = NULL;
}
argp->sym = sym;
argp->val = val;
argp->error = val_error ? xstrdup (val_error) : NULL;
if (!val && !val_error)
argp->entry_kind = print_entry_values_only;
else if ((print_entry_values == print_entry_values_compact
|| print_entry_values == print_entry_values_default) && val_equal)
{
argp->entry_kind = print_entry_values_compact;
gdb_assert (!ui_out_is_mi_like_p (current_uiout));
}
else
argp->entry_kind = print_entry_values_no;
entryargp->sym = sym;
entryargp->val = entryval;
entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL;
if (!entryval && !entryval_error)
entryargp->entry_kind = print_entry_values_no;
else
entryargp->entry_kind = print_entry_values_only;
}
/* Print the arguments of frame FRAME on STREAM, given the function
FUNC running in that frame (as a symbol), where NUM is the number
of arguments according to the stack frame (or -1 if the number of
arguments is unknown). */
/* Note that currently the "number of arguments according to the
stack frame" is only known on VAX where i refers to the "number of
ints of arguments according to the stack frame". */
static void
print_frame_args (struct symbol *func, struct frame_info *frame,
int num, struct ui_file *stream)
{
struct ui_out *uiout = current_uiout;
int first = 1;
/* Offset of next stack argument beyond the one we have seen that is
at the highest offset, or -1 if we haven't come to a stack
argument yet. */
long highest_offset = -1;
/* Number of ints of arguments that we have printed so far. */
int args_printed = 0;
struct cleanup *old_chain;
struct ui_file *stb;
/* True if we should print arguments, false otherwise. */
int print_args = strcmp (print_frame_arguments, "none");
stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb);
if (func)
{
const struct block *b = SYMBOL_BLOCK_VALUE (func);
struct block_iterator iter;
struct symbol *sym;
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
struct frame_arg arg, entryarg;
QUIT;
/* Keep track of the highest stack argument offset seen, and
skip over any kinds of symbols we don't care about. */
if (!SYMBOL_IS_ARGUMENT (sym))
continue;
switch (SYMBOL_CLASS (sym))
{
case LOC_ARG:
case LOC_REF_ARG:
{
long current_offset = SYMBOL_VALUE (sym);
int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
/* Compute address of next argument by adding the size of
this argument and rounding to an int boundary. */
current_offset =
((current_offset + arg_size + sizeof (int) - 1)
& ~(sizeof (int) - 1));
/* If this is the highest offset seen yet, set
highest_offset. */
if (highest_offset == -1
|| (current_offset > highest_offset))
highest_offset = current_offset;
/* Add the number of ints we're about to print to
args_printed. */
args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
}
/* We care about types of symbols, but don't need to
keep track of stack offsets in them. */
case LOC_REGISTER:
case LOC_REGPARM_ADDR:
case LOC_COMPUTED:
case LOC_OPTIMIZED_OUT:
default:
break;
}
/* We have to look up the symbol because arguments can have
two entries (one a parameter, one a local) and the one we
want is the local, which lookup_symbol will find for us.
This includes gcc1 (not gcc2) on SPARC when passing a
small structure and gcc2 when the argument type is float
and it is passed as a double and converted to float by
the prologue (in the latter case the type of the LOC_ARG
symbol is double and the type of the LOC_LOCAL symbol is
float). */
/* But if the parameter name is null, don't try it. Null
parameter names occur on the RS/6000, for traceback
tables. FIXME, should we even print them? */
if (*SYMBOL_LINKAGE_NAME (sym))
{
struct symbol *nsym;
nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
b, VAR_DOMAIN, NULL).symbol;
gdb_assert (nsym != NULL);
if (SYMBOL_CLASS (nsym) == LOC_REGISTER
&& !SYMBOL_IS_ARGUMENT (nsym))
{
/* There is a LOC_ARG/LOC_REGISTER pair. This means
that it was passed on the stack and loaded into a
register, or passed in a register and stored in a
stack slot. GDB 3.x used the LOC_ARG; GDB
4.0-4.11 used the LOC_REGISTER.
Reasons for using the LOC_ARG:
(1) Because find_saved_registers may be slow for
remote debugging.
(2) Because registers are often re-used and stack
slots rarely (never?) are. Therefore using
the stack slot is much less likely to print
garbage.
Reasons why we might want to use the LOC_REGISTER:
(1) So that the backtrace prints the same value
as "print foo". I see no compelling reason
why this needs to be the case; having the
backtrace print the value which was passed
in, and "print foo" print the value as
modified within the called function, makes
perfect sense to me.
Additional note: It might be nice if "info args"
displayed both values.
One more note: There is a case with SPARC
structure passing where we need to use the
LOC_REGISTER, but this is dealt with by creating
a single LOC_REGPARM in symbol reading. */
/* Leave sym (the LOC_ARG) alone. */
;
}
else
sym = nsym;
}
/* Print the current arg. */
if (!first)
ui_out_text (uiout, ", ");
ui_out_wrap_hint (uiout, " ");
if (!print_args)
{
memset (&arg, 0, sizeof (arg));
arg.sym = sym;
arg.entry_kind = print_entry_values_no;
memset (&entryarg, 0, sizeof (entryarg));
entryarg.sym = sym;
entryarg.entry_kind = print_entry_values_no;
}
else
read_frame_arg (sym, frame, &arg, &entryarg);
if (arg.entry_kind != print_entry_values_only)
print_frame_arg (&arg);
if (entryarg.entry_kind != print_entry_values_no)
{
if (arg.entry_kind != print_entry_values_only)
{
ui_out_text (uiout, ", ");
ui_out_wrap_hint (uiout, " ");
}
print_frame_arg (&entryarg);
}
xfree (arg.error);
xfree (entryarg.error);
first = 0;
}
}
/* Don't print nameless args in situations where we don't know
enough about the stack to find them. */
if (num != -1)
{
long start;
if (highest_offset == -1)
start = gdbarch_frame_args_skip (get_frame_arch (frame));
else
start = highest_offset;
print_frame_nameless_args (frame, start, num - args_printed,
first, stream);
}
do_cleanups (old_chain);
}
/* Set the current source and line to the location given by frame
FRAME, if possible. When CENTER is true, adjust so the relevant
line is in the center of the next 'list'. */
void
set_current_sal_from_frame (struct frame_info *frame)
{
struct symtab_and_line sal;
find_frame_sal (frame, &sal);
if (sal.symtab != NULL)
set_current_source_symtab_and_line (&sal);
}
/* If ON, GDB will display disassembly of the next source line when
execution of the program being debugged stops.
If AUTO (which is the default), or there's no line info to determine
the source line of the next instruction, display disassembly of next
instruction instead. */
static enum auto_boolean disassemble_next_line;
static void
show_disassemble_next_line (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
fprintf_filtered (file,
_("Debugger's willingness to use "
"disassemble-next-line is %s.\n"),
value);
}
/* Use TRY_CATCH to catch the exception from the gdb_disassembly
because it will be broken by filter sometime. */
static void
do_gdb_disassembly (struct gdbarch *gdbarch,
int how_many, CORE_ADDR low, CORE_ADDR high)
{
TRY
{
gdb_disassembly (gdbarch, current_uiout, 0,
DISASSEMBLY_RAW_INSN, how_many,
low, high);
}
CATCH (exception, RETURN_MASK_ERROR)
{
/* If an exception was thrown while doing the disassembly, print
the error message, to give the user a clue of what happened. */
exception_print (gdb_stderr, exception);
}
END_CATCH
}
/* Print information about frame FRAME. The output is format according
to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS. The meaning of
PRINT_WHAT is:
SRC_LINE: Print only source line.
LOCATION: Print only location.
LOC_AND_SRC: Print location and source line.
Used in "where" output, and to emit breakpoint or step
messages. */
void
print_frame_info (struct frame_info *frame, int print_level,
enum print_what print_what, int print_args,
int set_current_sal)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
struct symtab_and_line sal;
int source_print;
int location_print;
struct ui_out *uiout = current_uiout;
if (get_frame_type (frame) == DUMMY_FRAME
|| get_frame_type (frame) == SIGTRAMP_FRAME
|| get_frame_type (frame) == ARCH_FRAME)
{
struct cleanup *uiout_cleanup
= make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
gdbarch, get_frame_pc (frame));
/* Do this regardless of SOURCE because we don't have any source
to list for this frame. */
if (print_level)
{
ui_out_text (uiout, "#");
ui_out_field_fmt_int (uiout, 2, ui_left, "level",
frame_relative_level (frame));
}
if (ui_out_is_mi_like_p (uiout))
{
annotate_frame_address ();
ui_out_field_core_addr (uiout, "addr",
gdbarch, get_frame_pc (frame));
annotate_frame_address_end ();
}
if (get_frame_type (frame) == DUMMY_FRAME)
{
annotate_function_call ();
ui_out_field_string (uiout, "func", "<function called from gdb>");
}
else if (get_frame_type (frame) == SIGTRAMP_FRAME)
{
annotate_signal_handler_caller ();
ui_out_field_string (uiout, "func", "<signal handler called>");
}
else if (get_frame_type (frame) == ARCH_FRAME)
{
ui_out_field_string (uiout, "func", "<cross-architecture call>");
}
ui_out_text (uiout, "\n");
annotate_frame_end ();
/* If disassemble-next-line is set to auto or on output the next
instruction. */
if (disassemble_next_line == AUTO_BOOLEAN_AUTO
|| disassemble_next_line == AUTO_BOOLEAN_TRUE)
do_gdb_disassembly (get_frame_arch (frame), 1,
get_frame_pc (frame), get_frame_pc (frame) + 1);
do_cleanups (uiout_cleanup);
return;
}
/* If FRAME is not the innermost frame, that normally means that
FRAME->pc points to *after* the call instruction, and we want to
get the line containing the call, never the next line. But if
the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
next frame was not entered as the result of a call, and we want
to get the line containing FRAME->pc. */
find_frame_sal (frame, &sal);
location_print = (print_what == LOCATION
|| print_what == LOC_AND_ADDRESS
|| print_what == SRC_AND_LOC);
if (location_print || !sal.symtab)
print_frame (frame, print_level, print_what, print_args, sal);
source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
/* If disassemble-next-line is set to auto or on and doesn't have
the line debug messages for $pc, output the next instruction. */
if ((disassemble_next_line == AUTO_BOOLEAN_AUTO
|| disassemble_next_line == AUTO_BOOLEAN_TRUE)
&& source_print && !sal.symtab)
do_gdb_disassembly (get_frame_arch (frame), 1,
get_frame_pc (frame), get_frame_pc (frame) + 1);
if (source_print && sal.symtab)
{
int done = 0;
int mid_statement = ((print_what == SRC_LINE)
&& frame_show_address (frame, sal));
if (annotation_level)
done = identify_source_line (sal.symtab, sal.line, mid_statement,
get_frame_pc (frame));
if (!done)
{
if (deprecated_print_frame_info_listing_hook)
deprecated_print_frame_info_listing_hook (sal.symtab,
sal.line,
sal.line + 1, 0);
else
{
struct value_print_options opts;
get_user_print_options (&opts);
/* We used to do this earlier, but that is clearly
wrong. This function is used by many different
parts of gdb, including normal_stop in infrun.c,
which uses this to print out the current PC
when we stepi/nexti into the middle of a source
line. Only the command line really wants this
behavior. Other UIs probably would like the
ability to decide for themselves if it is desired. */
if (opts.addressprint && mid_statement)
{
ui_out_field_core_addr (uiout, "addr",
gdbarch, get_frame_pc (frame));
ui_out_text (uiout, "\t");
}
print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
}
}
/* If disassemble-next-line is set to on and there is line debug
messages, output assembly codes for next line. */
if (disassemble_next_line == AUTO_BOOLEAN_TRUE)
do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end);
}
if (set_current_sal)
{
CORE_ADDR pc;
if (get_frame_pc_if_available (frame, &pc))
set_last_displayed_sal (1, sal.pspace, pc, sal.symtab, sal.line);
else
set_last_displayed_sal (0, 0, 0, 0, 0);
}
annotate_frame_end ();
gdb_flush (gdb_stdout);
}
/* Remember the last symtab and line we displayed, which we use e.g.
* as the place to put a breakpoint when the `break' command is
* invoked with no arguments. */
static void
set_last_displayed_sal (int valid, struct program_space *pspace,
CORE_ADDR addr, struct symtab *symtab,
int line)
{
last_displayed_sal_valid = valid;
last_displayed_pspace = pspace;
last_displayed_addr = addr;
last_displayed_symtab = symtab;
last_displayed_line = line;
if (valid && pspace == NULL)
{
clear_last_displayed_sal ();
internal_error (__FILE__, __LINE__,
_("Trying to set NULL pspace."));
}
}
/* Forget the last sal we displayed. */
void
clear_last_displayed_sal (void)
{
last_displayed_sal_valid = 0;
last_displayed_pspace = 0;
last_displayed_addr = 0;
last_displayed_symtab = 0;
last_displayed_line = 0;
}
/* Is our record of the last sal we displayed valid? If not,
* the get_last_displayed_* functions will return NULL or 0, as
* appropriate. */
int
last_displayed_sal_is_valid (void)
{
return last_displayed_sal_valid;
}
/* Get the pspace of the last sal we displayed, if it's valid. */
struct program_space *
get_last_displayed_pspace (void)
{
if (last_displayed_sal_valid)
return last_displayed_pspace;
return 0;
}
/* Get the address of the last sal we displayed, if it's valid. */
CORE_ADDR
get_last_displayed_addr (void)