OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [blockframe.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
/* Get info from stack frames;
2
   convert between frames, blocks, functions and pc values.
3
   Copyright 1986, 87, 88, 89, 91, 94, 95, 96, 97, 1998
4
   Free Software Foundation, Inc.
5
 
6
   This file is part of GDB.
7
 
8
   This program is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 2 of the License, or
11
   (at your option) any later version.
12
 
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
 
18
   You should have received a copy of the GNU General Public License
19
   along with this program; if not, write to the Free Software
20
   Foundation, Inc., 59 Temple Place - Suite 330,
21
   Boston, MA 02111-1307, USA.  */
22
 
23
#include "defs.h"
24
#include "symtab.h"
25
#include "bfd.h"
26
#include "symfile.h"
27
#include "objfiles.h"
28
#include "frame.h"
29
#include "gdbcore.h"
30
#include "value.h"              /* for read_register */
31
#include "target.h"             /* for target_has_stack */
32
#include "inferior.h"           /* for read_pc */
33
#include "annotate.h"
34
 
35
/* Prototypes for exported functions. */
36
 
37
void _initialize_blockframe (void);
38
 
39
/* A default FRAME_CHAIN_VALID, in the form that is suitable for most
40
   targets.  If FRAME_CHAIN_VALID returns zero it means that the given
41
   frame is the outermost one and has no caller. */
42
 
43
int
44
file_frame_chain_valid (chain, thisframe)
45
     CORE_ADDR chain;
46
     struct frame_info *thisframe;
47
{
48
  return ((chain) != 0
49
          && !inside_entry_file (FRAME_SAVED_PC (thisframe)));
50
}
51
 
52
/* Use the alternate method of avoiding running up off the end of the
53
   frame chain or following frames back into the startup code.  See
54
   the comments in objfiles.h. */
55
 
56
int
57
func_frame_chain_valid (chain, thisframe)
58
     CORE_ADDR chain;
59
     struct frame_info *thisframe;
60
{
61
  return ((chain) != 0
62
          && !inside_main_func ((thisframe)->pc)
63
          && !inside_entry_func ((thisframe)->pc));
64
}
65
 
66
/* A very simple method of determining a valid frame */
67
 
68
int
69
nonnull_frame_chain_valid (chain, thisframe)
70
     CORE_ADDR chain;
71
     struct frame_info *thisframe;
72
{
73
  return ((chain) != 0);
74
}
75
 
76
/* Is ADDR inside the startup file?  Note that if your machine
77
   has a way to detect the bottom of the stack, there is no need
78
   to call this function from FRAME_CHAIN_VALID; the reason for
79
   doing so is that some machines have no way of detecting bottom
80
   of stack.
81
 
82
   A PC of zero is always considered to be the bottom of the stack. */
83
 
84
int
85
inside_entry_file (addr)
86
     CORE_ADDR addr;
87
{
88
  if (addr == 0)
89
    return 1;
90
  if (symfile_objfile == 0)
91
    return 0;
92
  if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
93
    {
94
      /* Do not stop backtracing if the pc is in the call dummy
95
         at the entry point.  */
96
      /* FIXME: Won't always work with zeros for the last two arguments */
97
      if (PC_IN_CALL_DUMMY (addr, 0, 0))
98
        return 0;
99
    }
100
  return (addr >= symfile_objfile->ei.entry_file_lowpc &&
101
          addr < symfile_objfile->ei.entry_file_highpc);
102
}
103
 
104
/* Test a specified PC value to see if it is in the range of addresses
105
   that correspond to the main() function.  See comments above for why
106
   we might want to do this.
107
 
108
   Typically called from FRAME_CHAIN_VALID.
109
 
110
   A PC of zero is always considered to be the bottom of the stack. */
111
 
112
int
113
inside_main_func (pc)
114
     CORE_ADDR pc;
115
{
116
  if (pc == 0)
117
    return 1;
118
  if (symfile_objfile == 0)
119
    return 0;
120
 
121
  /* If the addr range is not set up at symbol reading time, set it up now.
122
     This is for FRAME_CHAIN_VALID_ALTERNATE. I do this for coff, because
123
     it is unable to set it up and symbol reading time. */
124
 
125
  if (symfile_objfile->ei.main_func_lowpc == INVALID_ENTRY_LOWPC &&
126
      symfile_objfile->ei.main_func_highpc == INVALID_ENTRY_HIGHPC)
127
    {
128
      struct symbol *mainsym;
129
 
130
      mainsym = lookup_symbol ("main", NULL, VAR_NAMESPACE, NULL, NULL);
131
      if (mainsym && SYMBOL_CLASS (mainsym) == LOC_BLOCK)
132
        {
133
          symfile_objfile->ei.main_func_lowpc =
134
            BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym));
135
          symfile_objfile->ei.main_func_highpc =
136
            BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym));
137
        }
138
    }
139
  return (symfile_objfile->ei.main_func_lowpc <= pc &&
140
          symfile_objfile->ei.main_func_highpc > pc);
141
}
142
 
143
/* Test a specified PC value to see if it is in the range of addresses
144
   that correspond to the process entry point function.  See comments
145
   in objfiles.h for why we might want to do this.
146
 
147
   Typically called from FRAME_CHAIN_VALID.
148
 
149
   A PC of zero is always considered to be the bottom of the stack. */
150
 
151
int
152
inside_entry_func (pc)
153
     CORE_ADDR pc;
154
{
155
  if (pc == 0)
156
    return 1;
157
  if (symfile_objfile == 0)
158
    return 0;
159
  if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
160
    {
161
      /* Do not stop backtracing if the pc is in the call dummy
162
         at the entry point.  */
163
      /* FIXME: Won't always work with zeros for the last two arguments */
164
      if (PC_IN_CALL_DUMMY (pc, 0, 0))
165
        return 0;
166
    }
167
  return (symfile_objfile->ei.entry_func_lowpc <= pc &&
168
          symfile_objfile->ei.entry_func_highpc > pc);
169
}
170
 
171
/* Info about the innermost stack frame (contents of FP register) */
172
 
173
static struct frame_info *current_frame;
174
 
175
/* Cache for frame addresses already read by gdb.  Valid only while
176
   inferior is stopped.  Control variables for the frame cache should
177
   be local to this module.  */
178
 
179
static struct obstack frame_cache_obstack;
180
 
181
void *
182
frame_obstack_alloc (size)
183
     unsigned long size;
184
{
185
  return obstack_alloc (&frame_cache_obstack, size);
186
}
187
 
188
void
189
frame_saved_regs_zalloc (fi)
190
     struct frame_info *fi;
191
{
192
  fi->saved_regs = (CORE_ADDR *)
193
    frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
194
  memset (fi->saved_regs, 0, SIZEOF_FRAME_SAVED_REGS);
195
}
196
 
197
 
198
/* Return the innermost (currently executing) stack frame.  */
199
 
200
struct frame_info *
201
get_current_frame ()
202
{
203
  if (current_frame == NULL)
204
    {
205
      if (target_has_stack)
206
        current_frame = create_new_frame (read_fp (), read_pc ());
207
      else
208
        error ("No stack.");
209
    }
210
  return current_frame;
211
}
212
 
213
void
214
set_current_frame (frame)
215
     struct frame_info *frame;
216
{
217
  current_frame = frame;
218
}
219
 
220
/* Create an arbitrary (i.e. address specified by user) or innermost frame.
221
   Always returns a non-NULL value.  */
222
 
223
struct frame_info *
224
create_new_frame (addr, pc)
225
     CORE_ADDR addr;
226
     CORE_ADDR pc;
227
{
228
  struct frame_info *fi;
229
  char *name;
230
 
231
  fi = (struct frame_info *)
232
    obstack_alloc (&frame_cache_obstack,
233
                   sizeof (struct frame_info));
234
 
235
  /* Arbitrary frame */
236
  fi->saved_regs = NULL;
237
  fi->next = NULL;
238
  fi->prev = NULL;
239
  fi->frame = addr;
240
  fi->pc = pc;
241
  find_pc_partial_function (pc, &name, (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
242
  fi->signal_handler_caller = IN_SIGTRAMP (fi->pc, name);
243
 
244
#ifdef INIT_EXTRA_FRAME_INFO
245
  INIT_EXTRA_FRAME_INFO (0, fi);
246
#endif
247
 
248
  return fi;
249
}
250
 
251
/* Return the frame that FRAME calls (NULL if FRAME is the innermost
252
   frame).  */
253
 
254
struct frame_info *
255
get_next_frame (frame)
256
     struct frame_info *frame;
257
{
258
  return frame->next;
259
}
260
 
261
/* Flush the entire frame cache.  */
262
 
263
void
264
flush_cached_frames ()
265
{
266
  /* Since we can't really be sure what the first object allocated was */
267
  obstack_free (&frame_cache_obstack, 0);
268
  obstack_init (&frame_cache_obstack);
269
 
270
  current_frame = NULL;         /* Invalidate cache */
271
  select_frame (NULL, -1);
272
  annotate_frames_invalid ();
273
}
274
 
275
/* Flush the frame cache, and start a new one if necessary.  */
276
 
277
void
278
reinit_frame_cache ()
279
{
280
  flush_cached_frames ();
281
 
282
  /* FIXME: The inferior_pid test is wrong if there is a corefile.  */
283
  if (inferior_pid != 0)
284
    {
285
      select_frame (get_current_frame (), 0);
286
    }
287
}
288
 
289
/* Return nonzero if the function for this frame lacks a prologue.  Many
290
   machines can define FRAMELESS_FUNCTION_INVOCATION to just call this
291
   function.  */
292
 
293
int
294
frameless_look_for_prologue (frame)
295
     struct frame_info *frame;
296
{
297
  CORE_ADDR func_start, after_prologue;
298
 
299
  func_start = get_pc_function_start (frame->pc);
300
  if (func_start)
301
    {
302
      func_start += FUNCTION_START_OFFSET;
303
      after_prologue = func_start;
304
#ifdef SKIP_PROLOGUE_FRAMELESS_P
305
      /* This is faster, since only care whether there *is* a
306
         prologue, not how long it is.  */
307
      after_prologue = SKIP_PROLOGUE_FRAMELESS_P (after_prologue);
308
#else
309
      after_prologue = SKIP_PROLOGUE (after_prologue);
310
#endif
311
      return after_prologue == func_start;
312
    }
313
  else if (frame->pc == 0)
314
    /* A frame with a zero PC is usually created by dereferencing a
315
       NULL function pointer, normally causing an immediate core dump
316
       of the inferior. Mark function as frameless, as the inferior
317
       has no chance of setting up a stack frame.  */
318
    return 1;
319
  else
320
    /* If we can't find the start of the function, we don't really
321
       know whether the function is frameless, but we should be able
322
       to get a reasonable (i.e. best we can do under the
323
       circumstances) backtrace by saying that it isn't.  */
324
    return 0;
325
}
326
 
327
/* Default a few macros that people seldom redefine.  */
328
 
329
#if !defined (INIT_FRAME_PC)
330
#define INIT_FRAME_PC(fromleaf, prev) \
331
  prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \
332
              prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
333
#endif
334
 
335
#ifndef FRAME_CHAIN_COMBINE
336
#define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
337
#endif
338
 
339
/* Return a structure containing various interesting information
340
   about the frame that called NEXT_FRAME.  Returns NULL
341
   if there is no such frame.  */
342
 
343
struct frame_info *
344
get_prev_frame (next_frame)
345
     struct frame_info *next_frame;
346
{
347
  CORE_ADDR address = 0;
348
  struct frame_info *prev;
349
  int fromleaf = 0;
350
  char *name;
351
 
352
  /* If the requested entry is in the cache, return it.
353
     Otherwise, figure out what the address should be for the entry
354
     we're about to add to the cache. */
355
 
356
  if (!next_frame)
357
    {
358
#if 0
359
      /* This screws value_of_variable, which just wants a nice clean
360
         NULL return from block_innermost_frame if there are no frames.
361
         I don't think I've ever seen this message happen otherwise.
362
         And returning NULL here is a perfectly legitimate thing to do.  */
363
      if (!current_frame)
364
        {
365
          error ("You haven't set up a process's stack to examine.");
366
        }
367
#endif
368
 
369
      return current_frame;
370
    }
371
 
372
  /* If we have the prev one, return it */
373
  if (next_frame->prev)
374
    return next_frame->prev;
375
 
376
  /* On some machines it is possible to call a function without
377
     setting up a stack frame for it.  On these machines, we
378
     define this macro to take two args; a frameinfo pointer
379
     identifying a frame and a variable to set or clear if it is
380
     or isn't leafless.  */
381
 
382
  /* Still don't want to worry about this except on the innermost
383
     frame.  This macro will set FROMLEAF if NEXT_FRAME is a
384
     frameless function invocation.  */
385
  if (!(next_frame->next))
386
    {
387
      fromleaf = FRAMELESS_FUNCTION_INVOCATION (next_frame);
388
      if (fromleaf)
389
        address = FRAME_FP (next_frame);
390
    }
391
 
392
  if (!fromleaf)
393
    {
394
      /* Two macros defined in tm.h specify the machine-dependent
395
         actions to be performed here.
396
         First, get the frame's chain-pointer.
397
         If that is zero, the frame is the outermost frame or a leaf
398
         called by the outermost frame.  This means that if start
399
         calls main without a frame, we'll return 0 (which is fine
400
         anyway).
401
 
402
         Nope; there's a problem.  This also returns when the current
403
         routine is a leaf of main.  This is unacceptable.  We move
404
         this to after the ffi test; I'd rather have backtraces from
405
         start go curfluy than have an abort called from main not show
406
         main.  */
407
      address = FRAME_CHAIN (next_frame);
408
      if (!FRAME_CHAIN_VALID (address, next_frame))
409
        return 0;
410
      address = FRAME_CHAIN_COMBINE (address, next_frame);
411
    }
412
  if (address == 0)
413
    return 0;
414
 
415
  prev = (struct frame_info *)
416
    obstack_alloc (&frame_cache_obstack,
417
                   sizeof (struct frame_info));
418
 
419
  prev->saved_regs = NULL;
420
  if (next_frame)
421
    next_frame->prev = prev;
422
  prev->next = next_frame;
423
  prev->prev = (struct frame_info *) 0;
424
  prev->frame = address;
425
  prev->signal_handler_caller = 0;
426
 
427
/* This change should not be needed, FIXME!  We should
428
   determine whether any targets *need* INIT_FRAME_PC to happen
429
   after INIT_EXTRA_FRAME_INFO and come up with a simple way to
430
   express what goes on here.
431
 
432
   INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame
433
   (where the PC is already set up) and here (where it isn't).
434
   INIT_FRAME_PC is only called from here, always after
435
   INIT_EXTRA_FRAME_INFO.
436
 
437
   The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the PC
438
   value (which hasn't been set yet).  Some other machines appear to
439
   require INIT_EXTRA_FRAME_INFO before they can do INIT_FRAME_PC.  Phoo.
440
 
441
   We shouldn't need INIT_FRAME_PC_FIRST to add more complication to
442
   an already overcomplicated part of GDB.   gnu@cygnus.com, 15Sep92.
443
 
444
   Assuming that some machines need INIT_FRAME_PC after
445
   INIT_EXTRA_FRAME_INFO, one possible scheme:
446
 
447
   SETUP_INNERMOST_FRAME()
448
   Default version is just create_new_frame (read_fp ()),
449
   read_pc ()).  Machines with extra frame info would do that (or the
450
   local equivalent) and then set the extra fields.
451
   SETUP_ARBITRARY_FRAME(argc, argv)
452
   Only change here is that create_new_frame would no longer init extra
453
   frame info; SETUP_ARBITRARY_FRAME would have to do that.
454
   INIT_PREV_FRAME(fromleaf, prev)
455
   Replace INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC.  This should
456
   also return a flag saying whether to keep the new frame, or
457
   whether to discard it, because on some machines (e.g.  mips) it
458
   is really awkward to have FRAME_CHAIN_VALID called *before*
459
   INIT_EXTRA_FRAME_INFO (there is no good way to get information
460
   deduced in FRAME_CHAIN_VALID into the extra fields of the new frame).
461
   std_frame_pc(fromleaf, prev)
462
   This is the default setting for INIT_PREV_FRAME.  It just does what
463
   the default INIT_FRAME_PC does.  Some machines will call it from
464
   INIT_PREV_FRAME (either at the beginning, the end, or in the middle).
465
   Some machines won't use it.
466
   kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94.  */
467
 
468
#ifdef INIT_FRAME_PC_FIRST
469
  INIT_FRAME_PC_FIRST (fromleaf, prev);
470
#endif
471
 
472
#ifdef INIT_EXTRA_FRAME_INFO
473
  INIT_EXTRA_FRAME_INFO (fromleaf, prev);
474
#endif
475
 
476
  /* This entry is in the frame queue now, which is good since
477
     FRAME_SAVED_PC may use that queue to figure out its value
478
     (see tm-sparc.h).  We want the pc saved in the inferior frame. */
479
  INIT_FRAME_PC (fromleaf, prev);
480
 
481
  /* If ->frame and ->pc are unchanged, we are in the process of getting
482
     ourselves into an infinite backtrace.  Some architectures check this
483
     in FRAME_CHAIN or thereabouts, but it seems like there is no reason
484
     this can't be an architecture-independent check.  */
485
  if (next_frame != NULL)
486
    {
487
      if (prev->frame == next_frame->frame
488
          && prev->pc == next_frame->pc)
489
        {
490
          next_frame->prev = NULL;
491
          obstack_free (&frame_cache_obstack, prev);
492
          return NULL;
493
        }
494
    }
495
 
496
  find_pc_partial_function (prev->pc, &name,
497
                            (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
498
  if (IN_SIGTRAMP (prev->pc, name))
499
    prev->signal_handler_caller = 1;
500
 
501
  return prev;
502
}
503
 
504
CORE_ADDR
505
get_frame_pc (frame)
506
     struct frame_info *frame;
507
{
508
  return frame->pc;
509
}
510
 
511
 
512
#ifdef FRAME_FIND_SAVED_REGS
513
/* XXX - deprecated.  This is a compatibility function for targets
514
   that do not yet implement FRAME_INIT_SAVED_REGS.  */
515
/* Find the addresses in which registers are saved in FRAME.  */
516
 
517
void
518
get_frame_saved_regs (frame, saved_regs_addr)
519
     struct frame_info *frame;
520
     struct frame_saved_regs *saved_regs_addr;
521
{
522
  if (frame->saved_regs == NULL)
523
    {
524
      frame->saved_regs = (CORE_ADDR *)
525
        frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
526
    }
527
  if (saved_regs_addr == NULL)
528
    {
529
      struct frame_saved_regs saved_regs;
530
      FRAME_FIND_SAVED_REGS (frame, saved_regs);
531
      memcpy (frame->saved_regs, &saved_regs, SIZEOF_FRAME_SAVED_REGS);
532
    }
533
  else
534
    {
535
      FRAME_FIND_SAVED_REGS (frame, *saved_regs_addr);
536
      memcpy (frame->saved_regs, saved_regs_addr, SIZEOF_FRAME_SAVED_REGS);
537
    }
538
}
539
#endif
540
 
541
/* Return the innermost lexical block in execution
542
   in a specified stack frame.  The frame address is assumed valid.  */
543
 
544
struct block *
545
get_frame_block (frame)
546
     struct frame_info *frame;
547
{
548
  CORE_ADDR pc;
549
 
550
  pc = frame->pc;
551
  if (frame->next != 0 && frame->next->signal_handler_caller == 0)
552
    /* We are not in the innermost frame and we were not interrupted
553
       by a signal.  We need to subtract one to get the correct block,
554
       in case the call instruction was the last instruction of the block.
555
       If there are any machines on which the saved pc does not point to
556
       after the call insn, we probably want to make frame->pc point after
557
       the call insn anyway.  */
558
    --pc;
559
  return block_for_pc (pc);
560
}
561
 
562
struct block *
563
get_current_block ()
564
{
565
  return block_for_pc (read_pc ());
566
}
567
 
568
CORE_ADDR
569
get_pc_function_start (pc)
570
     CORE_ADDR pc;
571
{
572
  register struct block *bl;
573
  register struct symbol *symbol;
574
  register struct minimal_symbol *msymbol;
575
  CORE_ADDR fstart;
576
 
577
  if ((bl = block_for_pc (pc)) != NULL &&
578
      (symbol = block_function (bl)) != NULL)
579
    {
580
      bl = SYMBOL_BLOCK_VALUE (symbol);
581
      fstart = BLOCK_START (bl);
582
    }
583
  else if ((msymbol = lookup_minimal_symbol_by_pc (pc)) != NULL)
584
    {
585
      fstart = SYMBOL_VALUE_ADDRESS (msymbol);
586
    }
587
  else
588
    {
589
      fstart = 0;
590
    }
591
  return (fstart);
592
}
593
 
594
/* Return the symbol for the function executing in frame FRAME.  */
595
 
596
struct symbol *
597
get_frame_function (frame)
598
     struct frame_info *frame;
599
{
600
  register struct block *bl = get_frame_block (frame);
601
  if (bl == 0)
602
    return 0;
603
  return block_function (bl);
604
}
605
 
606
 
607
/* Return the blockvector immediately containing the innermost lexical block
608
   containing the specified pc value and section, or 0 if there is none.
609
   PINDEX is a pointer to the index value of the block.  If PINDEX
610
   is NULL, we don't pass this information back to the caller.  */
611
 
612
struct blockvector *
613
blockvector_for_pc_sect (pc, section, pindex, symtab)
614
     register CORE_ADDR pc;
615
     struct sec *section;
616
     int *pindex;
617
     struct symtab *symtab;
618
 
619
{
620
  register struct block *b;
621
  register int bot, top, half;
622
  struct blockvector *bl;
623
 
624
  if (symtab == 0)               /* if no symtab specified by caller */
625
    {
626
      /* First search all symtabs for one whose file contains our pc */
627
      if ((symtab = find_pc_sect_symtab (pc, section)) == 0)
628
        return 0;
629
    }
630
 
631
  bl = BLOCKVECTOR (symtab);
632
  b = BLOCKVECTOR_BLOCK (bl, 0);
633
 
634
  /* Then search that symtab for the smallest block that wins.  */
635
  /* Use binary search to find the last block that starts before PC.  */
636
 
637
  bot = 0;
638
  top = BLOCKVECTOR_NBLOCKS (bl);
639
 
640
  while (top - bot > 1)
641
    {
642
      half = (top - bot + 1) >> 1;
643
      b = BLOCKVECTOR_BLOCK (bl, bot + half);
644
      if (BLOCK_START (b) <= pc)
645
        bot += half;
646
      else
647
        top = bot + half;
648
    }
649
 
650
  /* Now search backward for a block that ends after PC.  */
651
 
652
  while (bot >= 0)
653
    {
654
      b = BLOCKVECTOR_BLOCK (bl, bot);
655
      if (BLOCK_END (b) > pc)
656
        {
657
          if (pindex)
658
            *pindex = bot;
659
          return bl;
660
        }
661
      bot--;
662
    }
663
  return 0;
664
}
665
 
666
/* Return the blockvector immediately containing the innermost lexical block
667
   containing the specified pc value, or 0 if there is none.
668
   Backward compatibility, no section.  */
669
 
670
struct blockvector *
671
blockvector_for_pc (pc, pindex)
672
     register CORE_ADDR pc;
673
     int *pindex;
674
{
675
  return blockvector_for_pc_sect (pc, find_pc_mapped_section (pc),
676
                                  pindex, NULL);
677
}
678
 
679
/* Return the innermost lexical block containing the specified pc value
680
   in the specified section, or 0 if there is none.  */
681
 
682
struct block *
683
block_for_pc_sect (pc, section)
684
     register CORE_ADDR pc;
685
     struct sec *section;
686
{
687
  register struct blockvector *bl;
688
  int index;
689
 
690
  bl = blockvector_for_pc_sect (pc, section, &index, NULL);
691
  if (bl)
692
    return BLOCKVECTOR_BLOCK (bl, index);
693
  return 0;
694
}
695
 
696
/* Return the innermost lexical block containing the specified pc value,
697
   or 0 if there is none.  Backward compatibility, no section.  */
698
 
699
struct block *
700
block_for_pc (pc)
701
     register CORE_ADDR pc;
702
{
703
  return block_for_pc_sect (pc, find_pc_mapped_section (pc));
704
}
705
 
706
/* Return the function containing pc value PC in section SECTION.
707
   Returns 0 if function is not known.  */
708
 
709
struct symbol *
710
find_pc_sect_function (pc, section)
711
     CORE_ADDR pc;
712
     struct sec *section;
713
{
714
  register struct block *b = block_for_pc_sect (pc, section);
715
  if (b == 0)
716
    return 0;
717
  return block_function (b);
718
}
719
 
720
/* Return the function containing pc value PC.
721
   Returns 0 if function is not known.  Backward compatibility, no section */
722
 
723
struct symbol *
724
find_pc_function (pc)
725
     CORE_ADDR pc;
726
{
727
  return find_pc_sect_function (pc, find_pc_mapped_section (pc));
728
}
729
 
730
/* These variables are used to cache the most recent result
731
 * of find_pc_partial_function. */
732
 
733
static CORE_ADDR cache_pc_function_low = 0;
734
static CORE_ADDR cache_pc_function_high = 0;
735
static char *cache_pc_function_name = 0;
736
static struct sec *cache_pc_function_section = NULL;
737
 
738
/* Clear cache, e.g. when symbol table is discarded. */
739
 
740
void
741
clear_pc_function_cache ()
742
{
743
  cache_pc_function_low = 0;
744
  cache_pc_function_high = 0;
745
  cache_pc_function_name = (char *) 0;
746
  cache_pc_function_section = NULL;
747
}
748
 
749
/* Finds the "function" (text symbol) that is smaller than PC but
750
   greatest of all of the potential text symbols in SECTION.  Sets
751
   *NAME and/or *ADDRESS conditionally if that pointer is non-null.
752
   If ENDADDR is non-null, then set *ENDADDR to be the end of the
753
   function (exclusive), but passing ENDADDR as non-null means that
754
   the function might cause symbols to be read.  This function either
755
   succeeds or fails (not halfway succeeds).  If it succeeds, it sets
756
   *NAME, *ADDRESS, and *ENDADDR to real information and returns 1.
757
   If it fails, it sets *NAME, *ADDRESS, and *ENDADDR to zero and
758
   returns 0.  */
759
 
760
int
761
find_pc_sect_partial_function (pc, section, name, address, endaddr)
762
     CORE_ADDR pc;
763
     asection *section;
764
     char **name;
765
     CORE_ADDR *address;
766
     CORE_ADDR *endaddr;
767
{
768
  struct partial_symtab *pst;
769
  struct symbol *f;
770
  struct minimal_symbol *msymbol;
771
  struct partial_symbol *psb;
772
  struct obj_section *osect;
773
  int i;
774
  CORE_ADDR mapped_pc;
775
 
776
  mapped_pc = overlay_mapped_address (pc, section);
777
 
778
  if (mapped_pc >= cache_pc_function_low &&
779
      mapped_pc < cache_pc_function_high &&
780
      section == cache_pc_function_section)
781
    goto return_cached_value;
782
 
783
  /* If sigtramp is in the u area, it counts as a function (especially
784
     important for step_1).  */
785
#if defined SIGTRAMP_START
786
  if (IN_SIGTRAMP (mapped_pc, (char *) NULL))
787
    {
788
      cache_pc_function_low = SIGTRAMP_START (mapped_pc);
789
      cache_pc_function_high = SIGTRAMP_END (mapped_pc);
790
      cache_pc_function_name = "<sigtramp>";
791
      cache_pc_function_section = section;
792
      goto return_cached_value;
793
    }
794
#endif
795
 
796
  msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section);
797
  pst = find_pc_sect_psymtab (mapped_pc, section);
798
  if (pst)
799
    {
800
      /* Need to read the symbols to get a good value for the end address.  */
801
      if (endaddr != NULL && !pst->readin)
802
        {
803
          /* Need to get the terminal in case symbol-reading produces
804
             output.  */
805
          target_terminal_ours_for_output ();
806
          PSYMTAB_TO_SYMTAB (pst);
807
        }
808
 
809
      if (pst->readin)
810
        {
811
          /* Checking whether the msymbol has a larger value is for the
812
             "pathological" case mentioned in print_frame_info.  */
813
          f = find_pc_sect_function (mapped_pc, section);
814
          if (f != NULL
815
              && (msymbol == NULL
816
                  || (BLOCK_START (SYMBOL_BLOCK_VALUE (f))
817
                      >= SYMBOL_VALUE_ADDRESS (msymbol))))
818
            {
819
              cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f));
820
              cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
821
              cache_pc_function_name = SYMBOL_NAME (f);
822
              cache_pc_function_section = section;
823
              goto return_cached_value;
824
            }
825
        }
826
      else
827
        {
828
          /* Now that static symbols go in the minimal symbol table, perhaps
829
             we could just ignore the partial symbols.  But at least for now
830
             we use the partial or minimal symbol, whichever is larger.  */
831
          psb = find_pc_sect_psymbol (pst, mapped_pc, section);
832
 
833
          if (psb
834
              && (msymbol == NULL ||
835
                  (SYMBOL_VALUE_ADDRESS (psb)
836
                   >= SYMBOL_VALUE_ADDRESS (msymbol))))
837
            {
838
              /* This case isn't being cached currently. */
839
              if (address)
840
                *address = SYMBOL_VALUE_ADDRESS (psb);
841
              if (name)
842
                *name = SYMBOL_NAME (psb);
843
              /* endaddr non-NULL can't happen here.  */
844
              return 1;
845
            }
846
        }
847
    }
848
 
849
  /* Not in the normal symbol tables, see if the pc is in a known section.
850
     If it's not, then give up.  This ensures that anything beyond the end
851
     of the text seg doesn't appear to be part of the last function in the
852
     text segment.  */
853
 
854
  osect = find_pc_sect_section (mapped_pc, section);
855
 
856
  if (!osect)
857
    msymbol = NULL;
858
 
859
  /* Must be in the minimal symbol table.  */
860
  if (msymbol == NULL)
861
    {
862
      /* No available symbol.  */
863
      if (name != NULL)
864
        *name = 0;
865
      if (address != NULL)
866
        *address = 0;
867
      if (endaddr != NULL)
868
        *endaddr = 0;
869
      return 0;
870
    }
871
 
872
  cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
873
  cache_pc_function_name = SYMBOL_NAME (msymbol);
874
  cache_pc_function_section = section;
875
 
876
  /* Use the lesser of the next minimal symbol in the same section, or
877
     the end of the section, as the end of the function.  */
878
 
879
  /* Step over other symbols at this same address, and symbols in
880
     other sections, to find the next symbol in this section with
881
     a different address.  */
882
 
883
  for (i = 1; SYMBOL_NAME (msymbol + i) != NULL; i++)
884
    {
885
      if (SYMBOL_VALUE_ADDRESS (msymbol + i) != SYMBOL_VALUE_ADDRESS (msymbol)
886
        && SYMBOL_BFD_SECTION (msymbol + i) == SYMBOL_BFD_SECTION (msymbol))
887
        break;
888
    }
889
 
890
  if (SYMBOL_NAME (msymbol + i) != NULL
891
      && SYMBOL_VALUE_ADDRESS (msymbol + i) < osect->endaddr)
892
    cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + i);
893
  else
894
    /* We got the start address from the last msymbol in the objfile.
895
       So the end address is the end of the section.  */
896
    cache_pc_function_high = osect->endaddr;
897
 
898
return_cached_value:
899
 
900
  if (address)
901
    {
902
      if (pc_in_unmapped_range (pc, section))
903
        *address = overlay_unmapped_address (cache_pc_function_low, section);
904
      else
905
        *address = cache_pc_function_low;
906
    }
907
 
908
  if (name)
909
    *name = cache_pc_function_name;
910
 
911
  if (endaddr)
912
    {
913
      if (pc_in_unmapped_range (pc, section))
914
        {
915
          /* Because the high address is actually beyond the end of
916
             the function (and therefore possibly beyond the end of
917
             the overlay), we must actually convert (high - 1)
918
             and then add one to that. */
919
 
920
          *endaddr = 1 + overlay_unmapped_address (cache_pc_function_high - 1,
921
                                                   section);
922
        }
923
      else
924
        *endaddr = cache_pc_function_high;
925
    }
926
 
927
  return 1;
928
}
929
 
930
/* Backward compatibility, no section argument */
931
 
932
int
933
find_pc_partial_function (pc, name, address, endaddr)
934
     CORE_ADDR pc;
935
     char **name;
936
     CORE_ADDR *address;
937
     CORE_ADDR *endaddr;
938
{
939
  asection *section;
940
 
941
  section = find_pc_overlay (pc);
942
  return find_pc_sect_partial_function (pc, section, name, address, endaddr);
943
}
944
 
945
/* Return the innermost stack frame executing inside of BLOCK,
946
   or NULL if there is no such frame.  If BLOCK is NULL, just return NULL.  */
947
 
948
struct frame_info *
949
block_innermost_frame (block)
950
     struct block *block;
951
{
952
  struct frame_info *frame;
953
  register CORE_ADDR start;
954
  register CORE_ADDR end;
955
 
956
  if (block == NULL)
957
    return NULL;
958
 
959
  start = BLOCK_START (block);
960
  end = BLOCK_END (block);
961
 
962
  frame = NULL;
963
  while (1)
964
    {
965
      frame = get_prev_frame (frame);
966
      if (frame == NULL)
967
        return NULL;
968
      if (frame->pc >= start && frame->pc < end)
969
        return frame;
970
    }
971
}
972
 
973
/* Return the full FRAME which corresponds to the given CORE_ADDR
974
   or NULL if no FRAME on the chain corresponds to CORE_ADDR.  */
975
 
976
struct frame_info *
977
find_frame_addr_in_frame_chain (frame_addr)
978
     CORE_ADDR frame_addr;
979
{
980
  struct frame_info *frame = NULL;
981
 
982
  if (frame_addr == (CORE_ADDR) 0)
983
    return NULL;
984
 
985
  while (1)
986
    {
987
      frame = get_prev_frame (frame);
988
      if (frame == NULL)
989
        return NULL;
990
      if (FRAME_FP (frame) == frame_addr)
991
        return frame;
992
    }
993
}
994
 
995
#ifdef SIGCONTEXT_PC_OFFSET
996
/* Get saved user PC for sigtramp from sigcontext for BSD style sigtramp.  */
997
 
998
CORE_ADDR
999
sigtramp_saved_pc (frame)
1000
     struct frame_info *frame;
1001
{
1002
  CORE_ADDR sigcontext_addr;
1003
  char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
1004
  int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT;
1005
  int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT;
1006
 
1007
  /* Get sigcontext address, it is the third parameter on the stack.  */
1008
  if (frame->next)
1009
    sigcontext_addr = read_memory_integer (FRAME_ARGS_ADDRESS (frame->next)
1010
                                           + FRAME_ARGS_SKIP
1011
                                           + sigcontext_offs,
1012
                                           ptrbytes);
1013
  else
1014
    sigcontext_addr = read_memory_integer (read_register (SP_REGNUM)
1015
                                           + sigcontext_offs,
1016
                                           ptrbytes);
1017
 
1018
  /* Don't cause a memory_error when accessing sigcontext in case the stack
1019
     layout has changed or the stack is corrupt.  */
1020
  target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes);
1021
  return extract_unsigned_integer (buf, ptrbytes);
1022
}
1023
#endif /* SIGCONTEXT_PC_OFFSET */
1024
 
1025
 
1026
/* Are we in a call dummy?  The code below which allows DECR_PC_AFTER_BREAK
1027
   below is for infrun.c, which may give the macro a pc without that
1028
   subtracted out.  */
1029
 
1030
extern CORE_ADDR text_end;
1031
 
1032
int
1033
pc_in_call_dummy_before_text_end (pc, sp, frame_address)
1034
     CORE_ADDR pc;
1035
     CORE_ADDR sp;
1036
     CORE_ADDR frame_address;
1037
{
1038
  return ((pc) >= text_end - CALL_DUMMY_LENGTH
1039
          && (pc) <= text_end + DECR_PC_AFTER_BREAK);
1040
}
1041
 
1042
int
1043
pc_in_call_dummy_after_text_end (pc, sp, frame_address)
1044
     CORE_ADDR pc;
1045
     CORE_ADDR sp;
1046
     CORE_ADDR frame_address;
1047
{
1048
  return ((pc) >= text_end
1049
          && (pc) <= text_end + CALL_DUMMY_LENGTH + DECR_PC_AFTER_BREAK);
1050
}
1051
 
1052
/* Is the PC in a call dummy?  SP and FRAME_ADDRESS are the bottom and
1053
   top of the stack frame which we are checking, where "bottom" and
1054
   "top" refer to some section of memory which contains the code for
1055
   the call dummy.  Calls to this macro assume that the contents of
1056
   SP_REGNUM and FP_REGNUM (or the saved values thereof), respectively,
1057
   are the things to pass.
1058
 
1059
   This won't work on the 29k, where SP_REGNUM and FP_REGNUM don't
1060
   have that meaning, but the 29k doesn't use ON_STACK.  This could be
1061
   fixed by generalizing this scheme, perhaps by passing in a frame
1062
   and adding a few fields, at least on machines which need them for
1063
   PC_IN_CALL_DUMMY.
1064
 
1065
   Something simpler, like checking for the stack segment, doesn't work,
1066
   since various programs (threads implementations, gcc nested function
1067
   stubs, etc) may either allocate stack frames in another segment, or
1068
   allocate other kinds of code on the stack.  */
1069
 
1070
int
1071
pc_in_call_dummy_on_stack (pc, sp, frame_address)
1072
     CORE_ADDR pc;
1073
     CORE_ADDR sp;
1074
     CORE_ADDR frame_address;
1075
{
1076
  return (INNER_THAN ((sp), (pc))
1077
          && (frame_address != 0)
1078
          && INNER_THAN ((pc), (frame_address)));
1079
}
1080
 
1081
int
1082
pc_in_call_dummy_at_entry_point (pc, sp, frame_address)
1083
     CORE_ADDR pc;
1084
     CORE_ADDR sp;
1085
     CORE_ADDR frame_address;
1086
{
1087
  return ((pc) >= CALL_DUMMY_ADDRESS ()
1088
          && (pc) <= (CALL_DUMMY_ADDRESS () + DECR_PC_AFTER_BREAK));
1089
}
1090
 
1091
 
1092
/*
1093
 * GENERIC DUMMY FRAMES
1094
 *
1095
 * The following code serves to maintain the dummy stack frames for
1096
 * inferior function calls (ie. when gdb calls into the inferior via
1097
 * call_function_by_hand).  This code saves the machine state before
1098
 * the call in host memory, so we must maintain an independant stack
1099
 * and keep it consistant etc.  I am attempting to make this code
1100
 * generic enough to be used by many targets.
1101
 *
1102
 * The cheapest and most generic way to do CALL_DUMMY on a new target
1103
 * is probably to define CALL_DUMMY to be empty, CALL_DUMMY_LENGTH to
1104
 * zero, and CALL_DUMMY_LOCATION to AT_ENTRY.  Then you must remember
1105
 * to define PUSH_RETURN_ADDRESS, because no call instruction will be
1106
 * being executed by the target.  Also FRAME_CHAIN_VALID as
1107
 * generic_{file,func}_frame_chain_valid and FIX_CALL_DUMMY as
1108
 * generic_fix_call_dummy.  */
1109
 
1110
/* Dummy frame.  This saves the processor state just prior to setting
1111
   up the inferior function call.  Older targets save the registers
1112
   target stack (but that really slows down function calls).  */
1113
 
1114
struct dummy_frame
1115
{
1116
  struct dummy_frame *next;
1117
 
1118
  CORE_ADDR pc;
1119
  CORE_ADDR fp;
1120
  CORE_ADDR sp;
1121
  CORE_ADDR top;
1122
  char *registers;
1123
};
1124
 
1125
static struct dummy_frame *dummy_frame_stack = NULL;
1126
 
1127
/* Function: find_dummy_frame(pc, fp, sp)
1128
   Search the stack of dummy frames for one matching the given PC, FP and SP.
1129
   This is the work-horse for pc_in_call_dummy and read_register_dummy     */
1130
 
1131
char *
1132
generic_find_dummy_frame (pc, fp)
1133
     CORE_ADDR pc;
1134
     CORE_ADDR fp;
1135
{
1136
  struct dummy_frame *dummyframe;
1137
 
1138
  if (pc != entry_point_address ())
1139
    return 0;
1140
 
1141
  for (dummyframe = dummy_frame_stack; dummyframe != NULL;
1142
       dummyframe = dummyframe->next)
1143
    if (fp == dummyframe->fp
1144
        || fp == dummyframe->sp
1145
        || fp == dummyframe->top)
1146
      /* The frame in question lies between the saved fp and sp, inclusive */
1147
      return dummyframe->registers;
1148
 
1149
  return 0;
1150
}
1151
 
1152
/* Function: pc_in_call_dummy (pc, fp)
1153
   Return true if this is a dummy frame created by gdb for an inferior call */
1154
 
1155
int
1156
generic_pc_in_call_dummy (pc, sp, fp)
1157
     CORE_ADDR pc;
1158
     CORE_ADDR sp;
1159
     CORE_ADDR fp;
1160
{
1161
  /* if find_dummy_frame succeeds, then PC is in a call dummy */
1162
  /* Note: SP and not FP is passed on. */
1163
  return (generic_find_dummy_frame (pc, sp) != 0);
1164
}
1165
 
1166
/* Function: read_register_dummy
1167
   Find a saved register from before GDB calls a function in the inferior */
1168
 
1169
CORE_ADDR
1170
generic_read_register_dummy (pc, fp, regno)
1171
     CORE_ADDR pc;
1172
     CORE_ADDR fp;
1173
     int regno;
1174
{
1175
  char *dummy_regs = generic_find_dummy_frame (pc, fp);
1176
 
1177
  if (dummy_regs)
1178
    return extract_address (&dummy_regs[REGISTER_BYTE (regno)],
1179
                            REGISTER_RAW_SIZE (regno));
1180
  else
1181
    return 0;
1182
}
1183
 
1184
/* Save all the registers on the dummy frame stack.  Most ports save the
1185
   registers on the target stack.  This results in lots of unnecessary memory
1186
   references, which are slow when debugging via a serial line.  Instead, we
1187
   save all the registers internally, and never write them to the stack.  The
1188
   registers get restored when the called function returns to the entry point,
1189
   where a breakpoint is laying in wait.  */
1190
 
1191
void
1192
generic_push_dummy_frame ()
1193
{
1194
  struct dummy_frame *dummy_frame;
1195
  CORE_ADDR fp = (get_current_frame ())->frame;
1196
 
1197
  /* check to see if there are stale dummy frames,
1198
     perhaps left over from when a longjump took us out of a
1199
     function that was called by the debugger */
1200
 
1201
  dummy_frame = dummy_frame_stack;
1202
  while (dummy_frame)
1203
    if (INNER_THAN (dummy_frame->fp, fp))       /* stale -- destroy! */
1204
      {
1205
        dummy_frame_stack = dummy_frame->next;
1206
        free (dummy_frame->registers);
1207
        free (dummy_frame);
1208
        dummy_frame = dummy_frame_stack;
1209
      }
1210
    else
1211
      dummy_frame = dummy_frame->next;
1212
 
1213
  dummy_frame = xmalloc (sizeof (struct dummy_frame));
1214
  dummy_frame->registers = xmalloc (REGISTER_BYTES);
1215
 
1216
  dummy_frame->pc = read_register (PC_REGNUM);
1217
  dummy_frame->sp = read_register (SP_REGNUM);
1218
  dummy_frame->top = dummy_frame->sp;
1219
  dummy_frame->fp = fp;
1220
  read_register_bytes (0, dummy_frame->registers, REGISTER_BYTES);
1221
  dummy_frame->next = dummy_frame_stack;
1222
  dummy_frame_stack = dummy_frame;
1223
}
1224
 
1225
void
1226
generic_save_dummy_frame_tos (sp)
1227
     CORE_ADDR sp;
1228
{
1229
  dummy_frame_stack->top = sp;
1230
}
1231
 
1232
/* Restore the machine state from either the saved dummy stack or a
1233
   real stack frame. */
1234
 
1235
void
1236
generic_pop_current_frame (void (*popper) (struct frame_info * frame))
1237
{
1238
  struct frame_info *frame = get_current_frame ();
1239
 
1240
  if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
1241
    generic_pop_dummy_frame ();
1242
  else
1243
    (*popper) (frame);
1244
}
1245
 
1246
/* Function: pop_dummy_frame
1247
   Restore the machine state from a saved dummy stack frame. */
1248
 
1249
void
1250
generic_pop_dummy_frame ()
1251
{
1252
  struct dummy_frame *dummy_frame = dummy_frame_stack;
1253
 
1254
  /* FIXME: what if the first frame isn't the right one, eg..
1255
     because one call-by-hand function has done a longjmp into another one? */
1256
 
1257
  if (!dummy_frame)
1258
    error ("Can't pop dummy frame!");
1259
  dummy_frame_stack = dummy_frame->next;
1260
  write_register_bytes (0, dummy_frame->registers, REGISTER_BYTES);
1261
  flush_cached_frames ();
1262
 
1263
  free (dummy_frame->registers);
1264
  free (dummy_frame);
1265
}
1266
 
1267
/* Function: frame_chain_valid
1268
   Returns true for a user frame or a call_function_by_hand dummy frame,
1269
   and false for the CRT0 start-up frame.  Purpose is to terminate backtrace */
1270
 
1271
int
1272
generic_file_frame_chain_valid (fp, fi)
1273
     CORE_ADDR fp;
1274
     struct frame_info *fi;
1275
{
1276
  if (PC_IN_CALL_DUMMY (FRAME_SAVED_PC (fi), fp, fp))
1277
    return 1;                   /* don't prune CALL_DUMMY frames */
1278
  else                          /* fall back to default algorithm (see frame.h) */
1279
    return (fp != 0
1280
            && (INNER_THAN (fi->frame, fp) || fi->frame == fp)
1281
            && !inside_entry_file (FRAME_SAVED_PC (fi)));
1282
}
1283
 
1284
int
1285
generic_func_frame_chain_valid (fp, fi)
1286
     CORE_ADDR fp;
1287
     struct frame_info *fi;
1288
{
1289
  if (PC_IN_CALL_DUMMY ((fi)->pc, fp, fp))
1290
    return 1;                   /* don't prune CALL_DUMMY frames */
1291
  else                          /* fall back to default algorithm (see frame.h) */
1292
    return (fp != 0
1293
            && (INNER_THAN (fi->frame, fp) || fi->frame == fp)
1294
            && !inside_main_func ((fi)->pc)
1295
            && !inside_entry_func ((fi)->pc));
1296
}
1297
 
1298
/* Function: fix_call_dummy
1299
   Stub function.  Generic dumy frames typically do not need to fix
1300
   the frame being created */
1301
 
1302
void
1303
generic_fix_call_dummy (dummy, pc, fun, nargs, args, type, gcc_p)
1304
     char *dummy;
1305
     CORE_ADDR pc;
1306
     CORE_ADDR fun;
1307
     int nargs;
1308
     struct value **args;
1309
     struct type *type;
1310
     int gcc_p;
1311
{
1312
  return;
1313
}
1314
 
1315
/* Function: get_saved_register
1316
   Find register number REGNUM relative to FRAME and put its (raw,
1317
   target format) contents in *RAW_BUFFER.
1318
 
1319
   Set *OPTIMIZED if the variable was optimized out (and thus can't be
1320
   fetched).  Note that this is never set to anything other than zero
1321
   in this implementation.
1322
 
1323
   Set *LVAL to lval_memory, lval_register, or not_lval, depending on
1324
   whether the value was fetched from memory, from a register, or in a
1325
   strange and non-modifiable way (e.g. a frame pointer which was
1326
   calculated rather than fetched).  We will use not_lval for values
1327
   fetched from generic dummy frames.
1328
 
1329
   Set *ADDRP to the address, either in memory on as a REGISTER_BYTE
1330
   offset into the registers array.  If the value is stored in a dummy
1331
   frame, set *ADDRP to zero.
1332
 
1333
   To use this implementation, define a function called
1334
   "get_saved_register" in your target code, which simply passes all
1335
   of its arguments to this function.
1336
 
1337
   The argument RAW_BUFFER must point to aligned memory.  */
1338
 
1339
void
1340
generic_get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
1341
     char *raw_buffer;
1342
     int *optimized;
1343
     CORE_ADDR *addrp;
1344
     struct frame_info *frame;
1345
     int regnum;
1346
     enum lval_type *lval;
1347
{
1348
  if (!target_has_registers)
1349
    error ("No registers.");
1350
 
1351
  /* Normal systems don't optimize out things with register numbers.  */
1352
  if (optimized != NULL)
1353
    *optimized = 0;
1354
 
1355
  if (addrp)                    /* default assumption: not found in memory */
1356
    *addrp = 0;
1357
 
1358
  /* Note: since the current frame's registers could only have been
1359
     saved by frames INTERIOR TO the current frame, we skip examining
1360
     the current frame itself: otherwise, we would be getting the
1361
     previous frame's registers which were saved by the current frame.  */
1362
 
1363
  while (frame && ((frame = frame->next) != NULL))
1364
    {
1365
      if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
1366
        {
1367
          if (lval)             /* found it in a CALL_DUMMY frame */
1368
            *lval = not_lval;
1369
          if (raw_buffer)
1370
            memcpy (raw_buffer,
1371
                    generic_find_dummy_frame (frame->pc, frame->frame) +
1372
                    REGISTER_BYTE (regnum),
1373
                    REGISTER_RAW_SIZE (regnum));
1374
          return;
1375
        }
1376
 
1377
      FRAME_INIT_SAVED_REGS (frame);
1378
      if (frame->saved_regs != NULL
1379
          && frame->saved_regs[regnum] != 0)
1380
        {
1381
          if (lval)             /* found it saved on the stack */
1382
            *lval = lval_memory;
1383
          if (regnum == SP_REGNUM)
1384
            {
1385
              if (raw_buffer)   /* SP register treated specially */
1386
                store_address (raw_buffer, REGISTER_RAW_SIZE (regnum),
1387
                               frame->saved_regs[regnum]);
1388
            }
1389
          else
1390
            {
1391
              if (addrp)        /* any other register */
1392
                *addrp = frame->saved_regs[regnum];
1393
              if (raw_buffer)
1394
                read_memory (frame->saved_regs[regnum], raw_buffer,
1395
                             REGISTER_RAW_SIZE (regnum));
1396
            }
1397
          return;
1398
        }
1399
    }
1400
 
1401
  /* If we get thru the loop to this point, it means the register was
1402
     not saved in any frame.  Return the actual live-register value.  */
1403
 
1404
  if (lval)                     /* found it in a live register */
1405
    *lval = lval_register;
1406
  if (addrp)
1407
    *addrp = REGISTER_BYTE (regnum);
1408
  if (raw_buffer)
1409
    read_register_gen (regnum, raw_buffer);
1410
}
1411
 
1412
void
1413
_initialize_blockframe (void)
1414
{
1415
  obstack_init (&frame_cache_obstack);
1416
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.