Bug 11606 - GDB does not properly implement the default copy constructor
Summary: GDB does not properly implement the default copy constructor
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.1
: P2 normal
Target Milestone: 7.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 16106
  Show dependency treegraph
 
Reported: 2010-05-17 08:31 UTC by Andre'
Modified: 2017-01-12 19:48 UTC (History)
5 users (show)

See Also:
Host: i486-linux-gnu, applies to any
Target: i486-linux-gnu, applies to any
Build: i486-linux-gnu, applies to any
Last reconfirmed:


Attachments
test case (201 bytes, text/x-csrc)
2010-08-05 15:12 UTC, Sami Wagiaalla
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andre' 2010-05-17 08:31:59 UTC
Evaluating expressions involving sequences of calls with non-trivial
intermediate values produce errors like "Attempt to take address of value not
located in memory." or, in other cases, gdb reporting SIGSEGV in the inferior.

To reproduce:

  echo 'struct S {}; S f() { return S(); } S g(const S &s) { return s; } int
main() { S s = g(f()); }' | g++ -xc++ -o x -g -
  gdb -ex 'b main' -ex run -ex 'p g(f())' ./x

My guess is that the result of the call is transfered from the inferior into
gdb, but not "moved back" for further processing.

The problem can be partially worked around by manually disentangling the calls
and "poking" the intermediate results back into the inferior using something like

def makeValue(type, init):
    gdb.execute("set $d = (%s*)malloc(sizeof(%s))" % (type, type))
    gdb.execute("set *$d = {%s}" % init)
    return gdb.parse_and_eval("$d").dereference()
Comment 1 Pedro Alves 2010-05-17 11:06:25 UTC
Are you saying that the same example sometimes crashes the inferior, while
sometimes results in the "Attempt to take address of value not located in
memory." error, or do you need a different reproducer to cause
SIGSEGV crash in the inferior?  If the latter, do you have such a
reproducer?
Comment 2 Andre' 2010-05-17 13:32:41 UTC
The example given always produces "Attempt to take address of value not
located in memory." as far as I can tell.

The SIGSEGV reports have been showing up in a somewhat more complex setup
involving Qt Creator's pretty-printers for QObject and QModelIndex that also
uses cascaded inferior calls.

I believe the problem is the same, though and would like to save me the trouble
to cut this down to something that's reproducible without a lot of external
dependencies.

Sorry for the confusion.
Comment 3 Sami Wagiaalla 2010-08-05 15:12:47 UTC
Created attachment 4913 [details]
test case
Comment 4 Sami Wagiaalla 2010-08-05 15:13:48 UTC
While the example mentioned can be fixed by setting the lval of the value
returned by call_function_by_hand() lval_memory further nesting does not work.
example attached.
Comment 5 Sami Wagiaalla 2010-08-06 21:34:19 UTC
This issue was also discussed here:
http://www.cygwin.com/ml/gdb-patches/2010-08/msg00053.html
Comment 6 Siva Chandra 2014-06-18 12:58:53 UTC
I might be wrong, but I am inclined to think that this is also linked to bad calling convention similar to PR/13403.
Comment 7 Luis Machado 2017-01-12 19:48:18 UTC
I've checked this against GDB 7.12.50 and it works fine.