public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Patrick Frants <osscontribute@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] [Bug gdb/13669] Infinite recursion in cp_print_value_fields
Date: Tue, 17 Oct 2017 14:21:00 -0000	[thread overview]
Message-ID: <CAEsN4ZuEypFadJACWFwO7xTLbGHa1LHUWfjewAgBUE5rg_fHsw@mail.gmail.com> (raw)

First time contributor here, could not find a good example for this patch.
Please bear with me and help me get the content into acceptable form:

This fixes Bug gdb/13669 (
https://sourceware.org/bugzilla/show_bug.cgi?id=13669)

cp_print_value_fields() in cp-valprint.c optionally skips static members
based on options->static_field_print. Additionally cp_print_value_fields()
has a parameter dont_print_statmem, which instructs the current invocation
to skip static members. The "if () continue" statement (line 236) fails to
take into account this parameter and therefore gdb gets into an infinite
recursion involving cp_print_value_fields() and cp_print_static_field().

Sample backtrace (note dont_print_statmem=1):
(gdb) bt 30
#0  0x00007ffff754737d in __libc_sigaction () from target:/lib64/libc.so.6
#1  0x0000000000527c65 in gdb_demangle (name=0xd97683 "m_blendColour",
options=3) at cp-support.c:1524
#2  0x0000000000646a6f in fprintf_symbol_filtered (stream=0x7fffffffd580,
name=0xd97683 "m_blendColour", lang=<optimized out>, arg_mode=3) at
utils.c:2433
#3  0x000000000052866f in cp_print_value_fields (type=<optimized out>,
type@entry=0xdc90c0, real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612, stream=stream@entry=0x7fffffffd580,
recurse=recurse@entry=16284, val=0x221f040, options=0x7fffffffcda0,
dont_print_vb=0x0, dont_print_statmem=1) at cp-valprint.c:267
#4  0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16284, stream=0x7fffffffd580, val=0x221f040, type=<optimized out>)
at cp-valprint.c:672
#5  cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16283,
val=0x221eb90, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#6  0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16283, stream=0x7fffffffd580, val=0x221eb90, type=<optimized out>)
at cp-valprint.c:672
#7  cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16282,
val=0x221e710, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#8  0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16282, stream=0x7fffffffd580, val=0x221e710, type=<optimized out>)
at cp-valprint.c:672
#9  cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16281,
val=0x221f7b0, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#10 0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16281, stream=0x7fffffffd580, val=0x221f7b0, type=<optimized out>)
at cp-valprint.c:672
#11 cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16280,
val=0x221e100, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#12 0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16280, stream=0x7fffffffd580, val=0x221e100, type=<optimized out>)
at cp-valprint.c:672
#13 cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16279,
val=0x2213190, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#14 0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16279, stream=0x7fffffffd580, val=0x2213190, type=<optimized out>)
at cp-valprint.c:672
#15 cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16278,
val=0x2212d20, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#16 0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16278, stream=0x7fffffffd580, val=0x2212d20, type=<optimized out>)
at cp-valprint.c:672
#17 cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16277,
val=0x2212860, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#18 0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16277, stream=0x7fffffffd580, val=0x2212860, type=<optimized out>)
at cp-valprint.c:672
#19 cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16276,
val=0x2213660, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#20 0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16276, stream=0x7fffffffd580, val=0x2213660, type=<optimized out>)
at cp-valprint.c:672
#21 cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16275,
val=0x22121d0, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#22 0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16275, stream=0x7fffffffd580, val=0x22121d0, type=<optimized out>)
at cp-valprint.c:672
#23 cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16274,
val=0x2211e10, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#24 0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16274, stream=0x7fffffffd580, val=0x2211e10, type=<optimized out>)
at cp-valprint.c:672
#25 cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16273,
val=0x2214210, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#26 0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16273, stream=0x7fffffffd580, val=0x2214210, type=<optimized out>)
at cp-valprint.c:672
#27 cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16272,
val=0x2213d60, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
#28 0x0000000000529301 in cp_print_static_field (options=0x7fffffffcda0,
recurse=16272, stream=0x7fffffffd580, val=0x2213d60, type=<optimized out>)
at cp-valprint.c:672
#29 cp_print_value_fields (type=<optimized out>, type@entry=0xdc90c0,
real_type=<optimized out>, offset=offset@entry=0,
address=address@entry=6295612,
stream=stream@entry=0x7fffffffd580, recurse=recurse@entry=16271,
val=0x22137d0, options=0x7fffffffcda0, dont_print_vb=0x0,
dont_print_statmem=1) at cp-valprint.c:333
(More stack frames follow...)

------------------------------------------------
REPRODUCTION:
The issue is reproducable with the test program (
https://sourceware.org/bugzilla/attachment.cgi?id=8166) provided by Daniel
Lopez as part of the issue
https://sourceware.org/bugzilla/show_bug.cgi?id=13669
------------------------------------------------
CHANGELOG:
 2017-10-17 Patrick Frants <osscontributor@gmail.com>
 * gdb/cp-valprint.c (cp_print_value_fields): Obey dont_print_statmem
parameter to avoid infinite recursion.
 ------------------------------------------------
PATCH:
diff --git a/a/binutils-gdb/gdb/cp-valprint.c
b/b/binutils-gdb/gdb/cp-valprint.c
index fb9bfd9..9dda6e2 100644
--- a/a/binutils-gdb/gdb/cp-valprint.c
+++ b/b/binutils-gdb/gdb/cp-valprint.c
@@ -230,7 +230,7 @@ cp_print_value_fields (struct type *type, struct type
*real_type,
          const gdb_byte *valaddr = value_contents_for_printing (val);

          /* If requested, skip printing of static fields.  */
-         if (!options->static_field_print
+         if ( (!options->static_field_print || dont_print_statmem)
              && field_is_static (&TYPE_FIELD (type, i)))
            continue;

                 reply	other threads:[~2017-10-17 14:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=CAEsN4ZuEypFadJACWFwO7xTLbGHa1LHUWfjewAgBUE5rg_fHsw@mail.gmail.com \
    --to=osscontribute@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).