Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* gdb problem with  'malloc' in unnamed namespace
@ 2008-08-05 12:05 André Pönitz
  2008-08-05 12:13 ` Daniel Jacobowitz
  2008-08-05 12:40 ` Andreas Schwab
  0 siblings, 2 replies; 4+ messages in thread
From: André Pönitz @ 2008-08-05 12:05 UTC (permalink / raw)
  To: gdb


Hi all.

Thanks to Andreas Schwab I have now a pretty minimal example
that makes me think that gdb has a problem with handling a
function called "malloc" in the unnamed namespace:

  echo 'namespace { void malloc(int, int) {} } int main() {}' | g++ -xc++ -g - 
  gdb -batch -ex 'b main' -ex 'r' -ex 'p "xxx"' ./a.out 

yields:

  Breakpoint 1 at 0x400548: file <stdin>, line 1.
  Breakpoint 1, main () at <stdin>:1
  1       <stdin>: No such file or directory.
          in <stdin>
  Current language:  auto; currently c++
  too few arguments in function call

So the 'malloc' from the debugged program is picked up by gdb, even if the
symbol name ("_ZN29_GLOBAL__N__00000000_271D34D06mallocEv") does
not match.

Note that the case of too few argument, the error message is 
slightly more useful as it mentions at least 'malloc':

   echo 'namespace { void malloc() {} } int main() {}' | g++ -xc++ -g -
   gdb -batch -ex 'b main' -ex 'r' -ex 'p "xxx"' ./a.out 

yields:

  Breakpoint 1 at 0x400542: file <stdin>, line 1.
  Breakpoint 1, main () at <stdin>:1
    1       <stdin>: No such file or directory.
        in <stdin>
  Current language:  auto; currently c++
  No memory available to program: call to malloc failed

What can I do from the user side to inform gdb that it should
not use the malloc from the anon namespace?

André 


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

* Re: gdb problem with  'malloc' in unnamed namespace
  2008-08-05 12:05 gdb problem with 'malloc' in unnamed namespace André Pönitz
@ 2008-08-05 12:13 ` Daniel Jacobowitz
  2008-08-05 12:40 ` Andreas Schwab
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2008-08-05 12:13 UTC (permalink / raw)
  To: André Pönitz; +Cc: gdb

On Tue, Aug 05, 2008 at 02:07:13PM +0200, André Pönitz wrote:
> What can I do from the user side to inform gdb that it should
> not use the malloc from the anon namespace?

Nothing, but you could file a bug for GDB's incorrect selection of
the malloc to call.

-- 
Daniel Jacobowitz
CodeSourcery


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

* Re: gdb problem with  'malloc' in unnamed namespace
  2008-08-05 12:05 gdb problem with 'malloc' in unnamed namespace André Pönitz
  2008-08-05 12:13 ` Daniel Jacobowitz
@ 2008-08-05 12:40 ` Andreas Schwab
  2008-08-05 12:56   ` André Pönitz
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2008-08-05 12:40 UTC (permalink / raw)
  To: André Pönitz; +Cc: gdb

André Pönitz <apoenitz@trolltech.com> writes:

> So the 'malloc' from the debugged program is picked up by gdb, even if the
> symbol name ("_ZN29_GLOBAL__N__00000000_271D34D06mallocEv") does
> not match.

Note that symbol lookup also considers the demangled name, which matches
here.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


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

* Re: gdb problem with  'malloc' in unnamed namespace
  2008-08-05 12:40 ` Andreas Schwab
@ 2008-08-05 12:56   ` André Pönitz
  0 siblings, 0 replies; 4+ messages in thread
From: André Pönitz @ 2008-08-05 12:56 UTC (permalink / raw)
  To: gdb

On Tuesday 05 August 2008 14:39:45 you wrote:
> André Pönitz <apoenitz@trolltech.com> writes:
> 
> > So the 'malloc' from the debugged program is picked up by gdb, even if the
> > symbol name ("_ZN29_GLOBAL__N__00000000_271D34D06mallocEv") does
> > not match.
> 
> Note that symbol lookup also considers the demangled name, which matches
> here.

Well, "demangled" in a very C-ish sense: drop all namespace and parameter
information. The symbol name contains parameter information that might
be useful to determine that this is not a suitable kind of malloc:

...$ c++filt 
_ZN29_GLOBAL__N__00000000_271D34D06mallocEii
(anonymous namespace)::malloc(int, int)

Anyway, thanks for the great hint!

Regards,
André


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

end of thread, other threads:[~2008-08-05 12:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-05 12:05 gdb problem with 'malloc' in unnamed namespace André Pönitz
2008-08-05 12:13 ` Daniel Jacobowitz
2008-08-05 12:40 ` Andreas Schwab
2008-08-05 12:56   ` André Pönitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox