From: Martin Baulig <martin@gnome.org>
To: gdb@sources.redhat.com
Subject: Lifetime of local variables
Date: Fri, 12 Apr 2002 16:18:00 -0000 [thread overview]
Message-ID: <86u1qghdp5.fsf@einstein.home-of-linux.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 1247 bytes --]
Hi,
I was recently working a bit on debugging support for C# (using Mono)
and I need a way to tell GDB about the lifetime of local variables. In
C#, the JIT engine may decide to store two different variables at the
same stack offset if they aren't used throughout the whole function.
Now I was wondering how to do this - DWARF 2 already has a
`DW_AT_begin_scope' but unfortunately no `DW_AT_end_scope' - can we
add this or something similar as a GNU extension ?
After looking at the code, I found out that `struct symbol' contains a
`ranges' field which seems to do exactly what I want - but this field
isn't used anywhere.
The following patch
* adds a new DWARF 2 attribute DW_AT_end_scope to specify the end of
a local variable's scope.
* initializes SYMBOL_RANGES() in dwarf2read.c if DW_AT_begin_scope and
DW_AT_end_scope are specified.
[FIXME: According to the DWARF 2 specification, this attribute takes
an offset (DW_FROM_data), not an address - but I found now
way to get the current frame's address in new_symbol(), this
needs to be fixed.]
* checks whether the current PC is within the symbol's SYMBOL_RANGES()
when listing the local variables of a function and when printing a
variable.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gdb-variable-scopes.patch --]
[-- Type: text/x-patch, Size: 5169 bytes --]
Index: include/elf/ChangeLog
===================================================================
RCS file: /cvs/src/src/include/elf/ChangeLog,v
retrieving revision 1.121
diff -u -u -p -r1.121 ChangeLog
--- include/elf/ChangeLog 13 Feb 2002 18:14:48 -0000 1.121
+++ include/elf/ChangeLog 12 Apr 2002 19:50:31 -0000
@@ -1,3 +1,7 @@
+2002-04-12 Martin Baulig <martin@gnome.org>
+
+ * dwarf2.h (DW_AT_end_scope): Added as GNU extension.
+
2002-02-13 Matt Fredette <fredette@netbsd.org>
* m68k.h (EF_M68000): Define.
Index: include/elf/dwarf2.h
===================================================================
RCS file: /cvs/src/src/include/elf/dwarf2.h,v
retrieving revision 1.8
diff -u -u -p -r1.8 dwarf2.h
--- include/elf/dwarf2.h 28 Jan 2002 23:26:53 -0000 1.8
+++ include/elf/dwarf2.h 12 Apr 2002 19:50:32 -0000
@@ -328,6 +328,8 @@ enum dwarf_attribute
DW_AT_src_coords = 0x2104,
DW_AT_body_begin = 0x2105,
DW_AT_body_end = 0x2106,
+ DW_AT_end_scope = 0x2121,
+
/* VMS Extensions. */
DW_AT_VMS_rtnbeg_pd_address = 0x2201
};
Index: gdb/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.2421
diff -u -u -p -r1.2421 ChangeLog
--- gdb/ChangeLog 12 Apr 2002 07:37:17 -0000 1.2421
+++ gdb/ChangeLog 12 Apr 2002 19:50:38 -0000
@@ -1,3 +1,14 @@
+2002-04-12 Martin Baulig <martin@gnome.org>
+
+ * dwarf2read.c (new_symbol): If DW_AT_start_scope and DW_AT_end_scope
+ are specified, set SYMBOL_RANGES().
+
+ * findvar.c (read_var_value): Check whether the current PC is within
+ the SYMBOL_RANGES(), return NULL if not.
+
+ * stack.c (print_block_frame_locals): Only print vars if the current PC
+ is in their SYMBOL_RANGES().
+
2002-04-12 Kevin Buettner <kevinb@redhat.com>
From Jimi X <jimix@watson.ibm.com>:
Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.52
diff -u -u -p -r1.52 dwarf2read.c
--- gdb/dwarf2read.c 4 Apr 2002 22:26:43 -0000 1.52
+++ gdb/dwarf2read.c 12 Apr 2002 19:50:44 -0000
@@ -4394,6 +4394,19 @@ new_symbol (struct die_info *die, struct
add_symbol_to_list (sym, list_in_scope);
break;
}
+ attr = dwarf_attr (die, DW_AT_start_scope);
+ attr2 = dwarf_attr (die, DW_AT_end_scope);
+ if (attr && attr2)
+ {
+ struct range_list *r = (struct range_list *)
+ obstack_alloc (&objfile->type_obstack,
+ sizeof (struct range_list));
+
+ r->start = DW_ADDR (attr);
+ r->end = DW_ADDR (attr2);
+
+ SYMBOL_RANGES (sym) = r;
+ }
attr = dwarf_attr (die, DW_AT_location);
if (attr)
{
Index: gdb/findvar.c
===================================================================
RCS file: /cvs/src/src/gdb/findvar.c,v
retrieving revision 1.31
diff -u -u -p -r1.31 findvar.c
--- gdb/findvar.c 9 Apr 2002 03:06:13 -0000 1.31
+++ gdb/findvar.c 12 Apr 2002 19:50:45 -0000
@@ -417,9 +417,11 @@ struct value *
read_var_value (register struct symbol *var, struct frame_info *frame)
{
register struct value *v;
+ register struct range_list *r;
struct type *type = SYMBOL_TYPE (var);
CORE_ADDR addr;
register int len;
+ int range_ok = 0;
v = allocate_value (type);
VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */
@@ -429,6 +431,23 @@ read_var_value (register struct symbol *
if (frame == NULL)
frame = selected_frame;
+
+ if (!SYMBOL_RANGES (var))
+ range_ok = 1;
+ else
+ {
+ for (r = SYMBOL_RANGES (var); r; r = r->next)
+ {
+ if (r->start <= frame->pc && r->end > frame->pc)
+ {
+ range_ok = 1;
+ break;
+ }
+ }
+ }
+
+ if (!range_ok)
+ return NULL;
switch (SYMBOL_CLASS (var))
{
Index: gdb/stack.c
===================================================================
RCS file: /cvs/src/src/gdb/stack.c,v
retrieving revision 1.33
diff -u -u -p -r1.33 stack.c
--- gdb/stack.c 10 Apr 2002 23:32:33 -0000 1.33
+++ gdb/stack.c 12 Apr 2002 19:50:47 -0000
@@ -1173,14 +1173,36 @@ print_block_frame_locals (struct block *
case LOC_REGISTER:
case LOC_STATIC:
case LOC_BASEREG:
- values_printed = 1;
- for (j = 0; j < num_tabs; j++)
- fputs_filtered ("\t", stream);
- fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
- fputs_filtered (" = ", stream);
- print_variable_value (sym, fi, stream);
- fprintf_filtered (stream, "\n");
- break;
+ {
+ struct range_list *r;
+ int range_ok = 0;
+
+ if (!SYMBOL_RANGES (sym))
+ range_ok = 1;
+ else
+ {
+ for (r = SYMBOL_RANGES (sym); r; r = r->next)
+ {
+ if (r->start <= fi->pc && r->end > fi->pc)
+ {
+ range_ok = 1;
+ break;
+ }
+ }
+ }
+
+ if (range_ok)
+ {
+ values_printed = 1;
+ for (j = 0; j < num_tabs; j++)
+ fputs_filtered ("\t", stream);
+ fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
+ fputs_filtered (" = ", stream);
+ print_variable_value (sym, fi, stream);
+ fprintf_filtered (stream, "\n");
+ }
+ break;
+ }
default:
/* Ignore symbols which are not locals. */
[-- Attachment #3: Type: text/plain, Size: 37 bytes --]
--
Martin Baulig
martin@gnome.org
next reply other threads:[~2002-04-12 23:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-12 16:18 Martin Baulig [this message]
2002-04-12 16:42 ` Daniel Jacobowitz
2002-04-13 4:35 ` Martin Baulig
2002-04-13 5:08 ` Momchil Velikov
2002-04-13 5:42 ` Martin Baulig
2002-04-13 11:32 ` Daniel Jacobowitz
2002-04-13 12:53 ` Martin Baulig
2002-04-13 12:59 ` Daniel Jacobowitz
2002-04-13 13:10 ` Momchil Velikov
2002-04-16 5:56 ` Daniel Berlin
2002-04-16 6:15 ` Daniel Berlin
2002-04-16 15:07 ` Jim Blandy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86u1qghdp5.fsf@einstein.home-of-linux.org \
--to=martin@gnome.org \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox