public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17132] New: Improper evaluation of expressions involving virtual method invocations under EVAL_AVOID_SIDE_EFFECTS
@ 2014-07-09  0:33 sivachandra at gmail dot com
  2014-07-09  0:35 ` [Bug c++/17132] " sivachandra at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: sivachandra at gmail dot com @ 2014-07-09  0:33 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17132

            Bug ID: 17132
           Summary: Improper evaluation of expressions involving virtual
                    method invocations under EVAL_AVOID_SIDE_EFFECTS
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: sivachandra at gmail dot com

When GDB "evaluates" expressions under EVAL_AVOID_SIDE_EFFECTS it incorrectly
emits "Cannot access memory at address 0x0" in some cases. Examples:

/* Example 1  */

struct base
{
  virtual void func();
};

void base::func ()
{
}

base *b = 0;

Then in GDB:

(gdb) ptype b->func()
Cannot access memory at address 0x0

(gdb) p sizeof(b->func())
Cannot access memory at address 0x0

/* End example 1  */

/* Example 2  */

#include <memory>

class A
{
public:
 virtual int type (void);
};

int
A::type ()
{
 return 3;
}

int
main ()
{
 std::unique_ptr<A> a (new A);

 // Invoke A::type so that unique_ptr::operator-> gets generated.
 return a->type();
}

Within GDB, I see this:

(gdb) p a->type()
$1 = 3
(gdb) p 1 && a->type()
Cannot access memory at address 0x0
(gdb) p 1 + a->type()
$2 = 4
(gdb) p 1 || a->type()
Cannot access memory at address 0x0

It does not happen if A::type is not virtual.

/* End example 2  */

I traced this and what I find is that, since the expression involves invoking a
virtual method, find_overload_match tries to pick the implementation of this
method for the most derived type. And for doing that, it tries to read the
vtable for the object via its vptr. Since the object is NULL in example 1, it
trips.

Example 2 is slightly complicated. For logical operations && and ||, GDB
evaluates the first operand, and only evaluates the type of the second operand
as a first step. The reason being, if evaluating the logical operation does not
require invoking an overloaded operator, then the boolean value of the first
operand could determine the result of the operation even without requiring to
evaluate the second operand.

The observed error message is coming when GDB is trying to evaluate the type of
a->type(). At a high level, there are two operations in this expression: '->',
and invocation of method 'type'. Since GDB only wants the type of the
expression, it evaluates it under EVAL_AVOID_SIDE_EFFECTS. The intermediate
results are zeroed values of the correct type. But now, since 'type' is a
virtual function, GDB internally looks up the vtable of the zeroed intermediate
object to pick the implementation for the most derived type. This is where it
trips with "Cannot access memory at address 0x0".

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/17132] Improper evaluation of expressions involving virtual method invocations under EVAL_AVOID_SIDE_EFFECTS
  2014-07-09  0:33 [Bug c++/17132] New: Improper evaluation of expressions involving virtual method invocations under EVAL_AVOID_SIDE_EFFECTS sivachandra at gmail dot com
@ 2014-07-09  0:35 ` sivachandra at gmail dot com
  2014-08-16  1:33 ` cvs-commit at gcc dot gnu.org
  2023-12-26 18:24 ` ssbssa at sourceware dot org
  2 siblings, 0 replies; 4+ messages in thread
From: sivachandra at gmail dot com @ 2014-07-09  0:35 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17132

Siva Chandra <sivachandra at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sivachandra at gmail dot com
           Assignee|unassigned at sourceware dot org   |sivachandra at google dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/17132] Improper evaluation of expressions involving virtual method invocations under EVAL_AVOID_SIDE_EFFECTS
  2014-07-09  0:33 [Bug c++/17132] New: Improper evaluation of expressions involving virtual method invocations under EVAL_AVOID_SIDE_EFFECTS sivachandra at gmail dot com
  2014-07-09  0:35 ` [Bug c++/17132] " sivachandra at gmail dot com
@ 2014-08-16  1:33 ` cvs-commit at gcc dot gnu.org
  2023-12-26 18:24 ` ssbssa at sourceware dot org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2014-08-16  1:33 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17132

--- Comment #1 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  e66d44466912ecf581f6b67ff299d064c7bf4f1a (commit)
      from  940df408121be31beed22ef7a5ad133cb1592726 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e66d44466912ecf581f6b67ff299d064c7bf4f1a

commit e66d44466912ecf581f6b67ff299d064c7bf4f1a
Author: Siva Chandra <sivachandra@chromium.org>
Date:   Wed Jul 9 10:25:48 2014 -0700

    Add new argument NOSIDE to find_overload_match.

    This is a fix for PR c++/17132.
    If this new argument is set to EVAL_AVOID_SIDE_EFFECTS, then the object's
    memory will not be read while picking the best overload match.

    gdb/

        * eval.c: Update all calls to find_overload_match.
        * valarith.c: Likewise.
        (value_user_defined_cpp_op, value_user_defined_op): New
        argument NOSIDE.  Update all callers.
        * valops.c (find_overload_match): New argument NOSIDE.
        * value.h (find_overload_match): Update signature.

    gdb/testsuite

        * gdb.cp/pr17132.cc: New file.
        * gdb.cp/pr17132.exp: New file.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                    |   10 ++++++
 gdb/eval.c                       |    6 ++--
 gdb/testsuite/ChangeLog          |    6 ++++
 gdb/testsuite/gdb.cp/pr17132.cc  |   61 ++++++++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.cp/pr17132.exp |   40 +++++++++++++++++++++++++
 gdb/valarith.c                   |   15 +++++----
 gdb/valops.c                     |   19 +++++++++--
 gdb/value.h                      |    3 +-
 8 files changed, 146 insertions(+), 14 deletions(-)
 create mode 100644 gdb/testsuite/gdb.cp/pr17132.cc
 create mode 100644 gdb/testsuite/gdb.cp/pr17132.exp

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/17132] Improper evaluation of expressions involving virtual method invocations under EVAL_AVOID_SIDE_EFFECTS
  2014-07-09  0:33 [Bug c++/17132] New: Improper evaluation of expressions involving virtual method invocations under EVAL_AVOID_SIDE_EFFECTS sivachandra at gmail dot com
  2014-07-09  0:35 ` [Bug c++/17132] " sivachandra at gmail dot com
  2014-08-16  1:33 ` cvs-commit at gcc dot gnu.org
@ 2023-12-26 18:24 ` ssbssa at sourceware dot org
  2 siblings, 0 replies; 4+ messages in thread
From: ssbssa at sourceware dot org @ 2023-12-26 18:24 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17132

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ssbssa at sourceware dot org
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |7.9

--- Comment #2 from Hannes Domani <ssbssa at sourceware dot org> ---
(In reply to Sourceware Commits from comment #1)
> This is an automated email from the git hooks/post-receive script. It was
> generated because a ref change was pushed to the repository containing
> the project "gdb and binutils".
> 
> The branch, master has been updated
>        via  e66d44466912ecf581f6b67ff299d064c7bf4f1a (commit)
>       from  940df408121be31beed22ef7a5ad133cb1592726 (commit)
> 
> Those revisions listed above that are new to this repository have
> not appeared on any other notification email; so we list those
> revisions in full, below.
> 
> - Log -----------------------------------------------------------------
> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;
> h=e66d44466912ecf581f6b67ff299d064c7bf4f1a
> 
> commit e66d44466912ecf581f6b67ff299d064c7bf4f1a
> Author: Siva Chandra <sivachandra@chromium.org>
> Date:   Wed Jul 9 10:25:48 2014 -0700
> 
>     Add new argument NOSIDE to find_overload_match.
>     
>     This is a fix for PR c++/17132.
>     If this new argument is set to EVAL_AVOID_SIDE_EFFECTS, then the object's
>     memory will not be read while picking the best overload match.
>     
>     gdb/
>     
>     	* eval.c: Update all calls to find_overload_match.
>     	* valarith.c: Likewise.
>     	(value_user_defined_cpp_op, value_user_defined_op): New
>     	argument NOSIDE.  Update all callers.
>     	* valops.c (find_overload_match): New argument NOSIDE.
>     	* value.h (find_overload_match): Update signature.
>     
>     gdb/testsuite
>     
>     	* gdb.cp/pr17132.cc: New file.
>     	* gdb.cp/pr17132.exp: New file.
> 
> -----------------------------------------------------------------------
> 
> Summary of changes:
>  gdb/ChangeLog                    |   10 ++++++
>  gdb/eval.c                       |    6 ++--
>  gdb/testsuite/ChangeLog          |    6 ++++
>  gdb/testsuite/gdb.cp/pr17132.cc  |   61
> ++++++++++++++++++++++++++++++++++++++
>  gdb/testsuite/gdb.cp/pr17132.exp |   40 +++++++++++++++++++++++++
>  gdb/valarith.c                   |   15 +++++----
>  gdb/valops.c                     |   19 +++++++++--
>  gdb/value.h                      |    3 +-
>  8 files changed, 146 insertions(+), 14 deletions(-)
>  create mode 100644 gdb/testsuite/gdb.cp/pr17132.cc
>  create mode 100644 gdb/testsuite/gdb.cp/pr17132.exp

Was fixed by this commit.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-26 18:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-09  0:33 [Bug c++/17132] New: Improper evaluation of expressions involving virtual method invocations under EVAL_AVOID_SIDE_EFFECTS sivachandra at gmail dot com
2014-07-09  0:35 ` [Bug c++/17132] " sivachandra at gmail dot com
2014-08-16  1:33 ` cvs-commit at gcc dot gnu.org
2023-12-26 18:24 ` ssbssa at sourceware dot org

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).