This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch, rfc] frame attribute - FRAME_IS_CALLER
- From: Andrew Cagney <ac131313 at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Wed, 09 Jul 2003 16:04:03 -0400
- Subject: [patch, rfc] frame attribute - FRAME_IS_CALLER
Hello,
Ref: Add frame_is_callee_p(), use in dwarf2-frame.c?,
http://sources.redhat.com/ml/gdb-patches/2003-07/msg00046.html
This patch adds a new `frame attribute' methods and defines one
attribute `FRAME_IS_CALLER' (described in comment) (again better name?).
It then uses it in a couple random places so that i know it is working.
thoughts,
The attached would be committed to the mainline, and just the new
methods to the branch.
Andrew
2003-07-09 Andrew Cagney <cagney@redhat.com>
* frame.c (frame_unwind_attrib, get_frame_attrib): New functions.
(pc_notcurrent): Delete function.
(find_frame_sal): Use get_frame_attrib instead of pc_notcurrent.
* frame.h (frame_attrib): Define.
(get_frame_attrib): Declare.
(frame_unwind_attrib): Declare.
* blockframe.c (frame_address_in_block): Use get_frame_attrib
instead of get_frame_type.
Index: blockframe.c
===================================================================
RCS file: /cvs/src/src/gdb/blockframe.c,v
retrieving revision 1.72
diff -u -r1.72 blockframe.c
--- blockframe.c 23 May 2003 17:05:19 -0000 1.72
+++ blockframe.c 9 Jul 2003 19:56:01 -0000
@@ -179,15 +179,11 @@
/* If we are not in the innermost frame, and we are not interrupted
by a signal, frame->pc points to the instruction following the
- call. As a consequence, we need to get the address of the previous
- instruction. Unfortunately, this is not straightforward to do, so
- we just use the address minus one, which is a good enough
- approximation. */
- /* FIXME: cagney/2002-11-10: Should this instead test for
- NORMAL_FRAME? A dummy frame (in fact all the abnormal frames)
- save the PC value in the block. */
- if (get_next_frame (frame) != 0
- && get_frame_type (get_next_frame (frame)) != SIGTRAMP_FRAME)
+ call. As a consequence, we need to get the address of the
+ previous instruction. Unfortunately, this is not straightforward
+ to do, so we just use the address minus one, which is a good
+ enough approximation. */
+ if (get_frame_attrib (frame, FRAME_IS_CALLER))
--pc;
return pc;
Index: frame.c
===================================================================
RCS file: /cvs/src/src/gdb/frame.c,v
retrieving revision 1.130
diff -u -r1.130 frame.c
--- frame.c 7 Jul 2003 20:07:12 -0000 1.130
+++ frame.c 9 Jul 2003 19:56:01 -0000
@@ -2006,8 +2006,8 @@
return frame_pc_unwind (frame->next);
}
-static int
-pc_notcurrent (struct frame_info *frame)
+void
+find_frame_sal (struct frame_info *frame, struct symtab_and_line *sal)
{
/* If FRAME is not the innermost frame, that normally means that
FRAME->pc points at the return instruction (which is *after* the
@@ -2018,15 +2018,8 @@
PC and such a PC indicates the current (rather than next)
instruction/line, consequently, for such cases, want to get the
line containing fi->pc. */
- struct frame_info *next = get_next_frame (frame);
- int notcurrent = (next != NULL && get_frame_type (next) == NORMAL_FRAME);
- return notcurrent;
-}
-
-void
-find_frame_sal (struct frame_info *frame, struct symtab_and_line *sal)
-{
- (*sal) = find_pc_line (get_frame_pc (frame), pc_notcurrent (frame));
+ int pc_notcurrent = get_frame_attrib (frame, FRAME_IS_CALLER);
+ (*sal) = find_pc_line (get_frame_pc (frame), pc_notcurrent);
}
/* Per "frame.h", return the ``address'' of the frame. Code should
@@ -2139,6 +2132,33 @@
{
/* Arrrg! See comment in "frame.h". */
frame->type = type;
+}
+
+int
+get_frame_attrib (struct frame_info *this_frame, enum frame_attrib attrib)
+{
+ return frame_unwind_attrib (this_frame->next, attrib);
+}
+
+int
+frame_unwind_attrib (struct frame_info *next_frame, enum frame_attrib attrib)
+{
+ switch (attrib)
+ {
+ case FRAME_IS_CALLER:
+ /* If the next frame is a sentinel, this frame can't be a
+ caller. */
+ if (next_frame->level < 0)
+ return 0;
+ /* If the next frame isn't normal, this frame can't be a caller.
+ Use get_frame_type because that hides NORMAL_FRAME. */
+ if (get_frame_type (next_frame) != NORMAL_FRAME)
+ return 0;
+ /* Hope its a call frame. */
+ return 1;
+ default:
+ internal_error (__FILE__, __LINE__, "bad switch");
+ }
}
struct frame_extra_info *
Index: frame.h
===================================================================
RCS file: /cvs/src/src/gdb/frame.h,v
retrieving revision 1.104
diff -u -r1.104 frame.h
--- frame.h 7 Jul 2003 14:36:58 -0000 1.104
+++ frame.h 9 Jul 2003 19:56:03 -0000
@@ -322,6 +322,27 @@
};
extern enum frame_type get_frame_type (struct frame_info *);
+/* Frame attributes. These can be tested individually. Please use
+ this in preference to the frame type. */
+
+enum frame_attrib
+{
+ /* THIS is a "caller frame". It executed a "call" instruction as
+ part of creating the NEXT frame (which is the "callee"). Unlike
+ other categories of frames, this frame's PC value does not need
+ to point at valid code. For instance, if the callee is no-return
+ and the caller (this frame) is at the end of the function, any
+ code after the function call instruction may have been eliminated
+ by the compiler leaving this frame's PC pointing outside of the
+ current function or even into the next function. */
+ FRAME_IS_CALLER
+};
+
+extern int get_frame_attrib (struct frame_info *this_frame,
+ enum frame_attrib attrib);
+extern int frame_unwind_attrib (struct frame_info *next_frame,
+ enum frame_attrib attrib);
+
/* FIXME: cagney/2002-11-10: Some targets want to directly mark a
frame as being of a specific type. This shouldn't be necessary.
PC_IN_SIGTRAMP() indicates a SIGTRAMP_FRAME and