Currently you can set breakpoint using the mangled name, that's
fairly simple: suppose you want to set a breakpoint in the C++
function foo::bar(). Then you first have to look for the mangled
name of that function, you will find it in the symbol table given
by ::nm and it will match with the regexp .*foo.*bar.*, so the command:

  ::nm ! grep 'foo.*bar'

will find the mangled name. And then you can use the mangled name
to set a breakpoint.

  Here's an example with a simple program:

$ cat program.cc
#include <stdio.h>

class foo {

public:
        int bar();

};

foo::bar()
{
        printf("foo::bar");
        return (1);
}

int
main(int argc, char *argv[])
{
        foo f;
        f.bar();
        return (0);
}

  Let's put a breakpoint in the foo::bar() method:

$ mdb ./program
Loading modules: [ libc.so.1 ]

# first we have to set a breakpoint in main() and start the
# program to load the symbol table

 > main:b
 > :r
mdb: stop at main
mdb: target stopped at:
main:           save      %sp, -0x68, %sp

# now we can look for the mangled name of foo::bar()

 > ::nm ! grep 'foo.*bar'
0x00010e48|0x00000038|FUNC |GLOB |0x0  |7       |__1cDfooDbar6M_i_

# we can check this is the right name by demangling it

 > ::dem __1cDfooDbar6M_i_
__1cDfooDbar6M_i_ == int foo::bar

# that's the right one, so we can now set the breakpoint

 > __1cDfooDbar6M_i_:b

# okay, let's continue the execution

 > :c
mdb: stop at __1cDfooDbar6M_i_
mdb: target stopped at:
__1cDfooDbar6M_i_:      save      %sp, -0x68, %sp

 > $c
__1cDfooDbar6M_i_(1, ffbff31c, ffbff324, 21000, 0, 0)
_start+0x108(0, 0, 0, 0, 0, 0)

# or more readable with demangling enabled

 > $G
C++ symbol demangling enabled

 > $c
int foo::bar(1, ffbff31c, ffbff324, 21000, 0, 0)
_start+0x108(0, 0, 0, 0, 0, 0)


This will work for any function except construtors, destructors and
operators (+, -, =, ...) because these functions have special mangled
names. If you need to put breakpoints in such functions I can provide
the way to translate them to mangled names.

Note that all this is for a program compiled with the Sun C++ compiler.
I am not sure it will work with other compilers like gcc because the
mangling process may be different.

alex.


Nicolas Droux wrote:
> Jonathan Adams wrote:
> 
>> On Mon, Sep 19, 2005 at 12:27:31PM -0700, Nicolas Droux wrote:
>>
>>> Hi Folks,
>>>
>>> Is setting breakpoints on C++ methods using demangled names supposed 
>>> to work from mdb?
>>
>>
>>
>> No.
> 
> 
> Are there any plans to support this feature?
> 
>>
>>
>>> My attempts have failed. $G provides some demangling support, is that 
>>> option used only for displaying names?
>>
>>
>>
>> Yes.  Note the "$g" dcmd, which lets you muck with what is displayed
>> (including having the mangled name show up)
> 
> 
> Thanks for the info.
> 
> Nicolas.
> _______________________________________________
> mdb-discuss mailing list
> mdb-discuss at opensolaris.org

Reply via email to