c++/2473: Program under debugg receives SIGSEGV when passing obj by value
drazen@gmail.com
drazen@gmail.com
Tue Jul 8 02:48:00 GMT 2008
>Number: 2473
>Category: c++
>Synopsis: Program under debugg receives SIGSEGV when passing obj by value
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jul 08 02:48:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: drazen@gmail.com
>Release: 6.3
>Organization:
>Environment:
uname -a
Linux belgrade 2.4.21-50.ELsmp #1 SMP Tue May 8 17:10:20 EDT 2007
x86_64 x86_64 x86_64 GNU/Linux
compiler: g++ 3.4.6
>Description:
Hi,
I bring the following code into the debugger:
0 //-------------------------------------------------
1 class F {
2 public:
3 int m_F;
4 //-------
5 F(int x) : m_F(x) // constructor
6 { }
7 F(const F& f) : m_F(f.m_F) // copy constructor
8 { }
9 };
10 //NOTE: object is passed, not reference
11 int getMember(F f) //
12 {
13 return f.m_F;
14 }
15
16 int main()
17 {
18 F f1(3);
19 int i = getMember(f1);
20 return 0;
21 }
22
23 //----------------------------------------------
As I step through main, line 19 executes correctly, and
"i" contains 3 as expected.
Then I invoke "getMember()" from the debugger, and the program under the debugger receives SIGSEGV:
(gdb) print getMember(f1)
Program received signal SIGSEGV, Segmentation fault.
getMember (f1=Cannot access memory at address 0x3) at f.cc:15
The program being debugged was signaled while in a function called
from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (getMember(F))
will be abandoned.
------------------------------------------------------------------------------
1. If "getMember()" takes reference to F, everything is
fine when "getMember()" is called from within gdb.
2. If I use C instead of C++, and struct, again everything
is fine.
3. I tried using gdb 6.3 and 6.8 (the newest), and both
behave identically.
Thanks, Drazen
>How-To-Repeat:
Compile and run the above program in the debugger.
>Fix:
No known fix.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gdb-prs
mailing list