Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Paul Pluzhnikov" <ppluzhnikov@google.com>
To: "Paul Pluzhnikov" <ppluzhnikov@google.com>, gdb-patches@sourceware.org
Subject: Re: [RFA] Patch for PR gdb/2477
Date: Mon, 14 Jul 2008 18:12:00 -0000	[thread overview]
Message-ID: <8ac60eac0807141111r58b047a3j7fd4a39080b1be19@mail.gmail.com> (raw)
In-Reply-To: <20080714174245.GA9888@caradoc.them.org>

[-- Attachment #1: Type: text/plain, Size: 912 bytes --]

On Mon, Jul 14, 2008 at 10:42 AM, Daniel Jacobowitz <drow@false.org> wrote:

> There's nothing special about zero.  It's just an unreadable memory
> address; the same problem will reappear with any other invalid
> pointer.

There is something special about zero -- it very frequently occurs
in correct C++ programs :)

> So if we use TRY_CATCH and RETURN_MASK_ERROR around the call to
> current_cp_abi.rtti_type, we can return NULL in the error case.

Done.

I've also added a "non-zero but invalid" pointer test at ~0UL.
Is there a "canonical" invalid address I should be testing instead?

Thanks,
-- 
Paul Pluzhnikov

ChangeLog
2008-07-14  Paul Pluzhnikov  <ppluzhnikov@google.com>

       PR gdb/2477
       * cp-abi.c (value_virtual_fn_field): Handle invalid pointers.

testsuite/ChangeLog
2008-07-14  Paul Pluzhnikov  <ppluzhnikov@google.com>

       * gdb.cp/class2.exp, gdb.cp/class2.cc: Test for PR2477.

[-- Attachment #2: gdb-patch-2477-20080714-2.txt --]
[-- Type: text/plain, Size: 2645 bytes --]

Index: gdb/cp-abi.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-abi.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 cp-abi.c
--- gdb/cp-abi.c	1 Jan 2008 22:53:09 -0000	1.21
+++ gdb/cp-abi.c	14 Jul 2008 18:01:19 -0000
@@ -22,6 +22,7 @@
 #include "value.h"
 #include "cp-abi.h"
 #include "command.h"
+#include "exceptions.h"
 #include "gdbcmd.h"
 #include "ui-out.h"
 
@@ -89,9 +90,17 @@ value_virtual_fn_field (struct value **a
 struct type *
 value_rtti_type (struct value *v, int *full, int *top, int *using_enc)
 {
+  struct type *ret = NULL;
+  struct gdb_exception e;
   if ((current_cp_abi.rtti_type) == NULL)
     return NULL;
-  return (*current_cp_abi.rtti_type) (v, full, top, using_enc);
+  TRY_CATCH (e, RETURN_MASK_ERROR)
+    {
+      ret = (*current_cp_abi.rtti_type) (v, full, top, using_enc);
+    }
+  if (e.reason < 0)
+    return NULL;
+  return ret;
 }
 
 void
Index: gdb/testsuite/gdb.cp/class2.cc
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/class2.cc,v
retrieving revision 1.6
diff -u -p -u -r1.6 class2.cc
--- gdb/testsuite/gdb.cp/class2.cc	1 Jan 2008 22:53:19 -0000	1.6
+++ gdb/testsuite/gdb.cp/class2.cc	14 Jul 2008 18:01:19 -0000
@@ -41,6 +41,12 @@ B::~B()
   b2 = 902;
 }
 
+struct C : public B
+{
+  A *c1;
+  A *c2;
+};
+
 // Stop the compiler from optimizing away data.
 void refer (A *)
 {
@@ -57,16 +63,19 @@ void refer (empty *)
 
 int main (void)
 {
-  A alpha, *aap, *abp;
+  A alpha, *aap, *abp, *acp;
   B beta, *bbp;
+  C gamma;
   empty e;
 
   alpha.a1 = 100;
   beta.a1 = 200; beta.b1 = 201; beta.b2 = 202;
+  gamma.c1 = 0; gamma.c2 = (A *) ~0UL;
 
   aap = &alpha; refer (aap);
   abp = &beta;  refer (abp);
   bbp = &beta;  refer (bbp);
+  acp = &gamma; refer (acp);
   refer (&e);
 
   return 0;  // marker return 0
Index: gdb/testsuite/gdb.cp/class2.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/class2.exp,v
retrieving revision 1.6
diff -u -p -u -r1.6 class2.exp
--- gdb/testsuite/gdb.cp/class2.exp	1 Jan 2008 22:53:19 -0000	1.6
+++ gdb/testsuite/gdb.cp/class2.exp	14 Jul 2008 18:01:19 -0000
@@ -117,3 +117,10 @@ gdb_test "print * (B *) abp" \
 # Printing the value of an object containing no data fields:
 
 gdb_test "p e" "= \{<No data fields>\}" "print object with no data fields"
+
+# Printing NULL pointers with "set print object on"
+
+gdb_test "set print object on" ""
+gdb_test "p acp" "= \\(C \\*\\) 0x\[a-f0-9\]+"
+gdb_test "p acp->c1" "\\(A \\*\\) 0x0"
+gdb_test "p acp->c2" "\\(A \\*\\) 0xf+"

  reply	other threads:[~2008-07-14 18:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-14 17:32 Paul Pluzhnikov
2008-07-14 17:43 ` Daniel Jacobowitz
2008-07-14 18:12   ` Paul Pluzhnikov [this message]
2008-07-14 18:21     ` Daniel Jacobowitz
2008-07-14 18:30       ` Paul Pluzhnikov
2008-07-15 18:52     ` Ulrich Weigand
2008-07-15 19:03       ` Daniel Jacobowitz
2008-07-15 19:16         ` Paul Pluzhnikov
2008-07-15 20:04           ` Ulrich Weigand
2008-07-15 19:04       ` Paul Pluzhnikov

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=8ac60eac0807141111r58b047a3j7fd4a39080b1be19@mail.gmail.com \
    --to=ppluzhnikov@google.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