Debugger stops program when stepping from the opening brace line to the first line of the function.

Morten Volden mvolden2 at gmail.com
Mon Jan 2 23:36:11 UTC 2012


Like you said: it is probably the std::string pretty printer that is
the problem.
So I started looking into the pretty printer for std::string myself.
Now the to_string function for std::string looks like this:

    def to_string(self):
        # Make sure &string works, too.
        type = self.val.type
        if type.code == gdb.TYPE_CODE_REF:
            type = type.target ()

        # Calculate the length of the string so that to_string returns
        # the string according to length, not according to first null
        # encountered.
        ptr = self.val ['_M_dataplus']['_M_p']
        realtype = type.unqualified ().strip_typedefs ()
        reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
        header = ptr.cast(reptype) - 1
        len = header.dereference ()['_M_length']
        if hasattr(ptr, "lazy_string"):
            return ptr.lazy_string (length = len)
        return ptr.string (length = len)


So I injeted the following code into the pretty printer:

        return 'The pointer is %s' % str(ptr)


Which gave the following when stepping into the function parseConfigFile:
....
    void parseConfigFile(std::string const& filename)
    {
        std::ifstream is(filename.c_str());

        std::string line;
....


filename "The pointer is 0x603028
\"/home/mvo/projects/projectFileGeneratorII/test/.kdev4/builddirproject.kdev4\""
is           {...}
line        "The pointer is 0x7fff00000001 <Address 0x7fff00000001 out
of bounds>"

Clearly there is a problem with the pointer for the variable 'line'
I changed the code for the pretty printer for std::string to the code
below, and it works like a charm.

    def to_string(self):
        # Make sure &string works, too.
        type = self.val.type
        if type.code == gdb.TYPE_CODE_REF:
            type = type.target ()

        # Calculate the length of the string so that to_string returns
        # the string according to length, not according to first null
        # encountered.
        ptr = self.val ['_M_dataplus']['_M_p']
        realtype = type.unqualified ().strip_typedefs ()
        reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
        header = ptr.cast(reptype) - 1
        len = header.dereference ()['_M_length']
        if hasattr(ptr, "lazy_string"):
            try:
                ret = ptr.lazy_string (length = len)
            except BaseException:
                ret = 'Not initialized string'
            return ret
        return ptr.string (length = len)

My knowledge of python is somewhat limited so this is perhaps not the
correct way to fix the problem?


/Morten

2012/1/2 Niko Sams <niko.sams at gmail.com>:
> On Sun, Jan 1, 2012 at 17:53, Morten Volden <mvolden2 at gmail.com> wrote:
>> Okay.
>>
>> Managed to reproduce the crash when running gdb in gdb. All steps
>> performed before crash AND the backtrace here:
> perfect :D
>>
>> http://pastebin.com/HLLEDCjs
> oh that's without gdb debug symbols. Please install them and do the same again.
>
> Niko
>
> --
> KDevelop-devel mailing list
> KDevelop-devel at kdevelop.org
> https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel



-- 
- When the split is pulled, mr. Grenade is no longer our friend




More information about the KDevelop-devel mailing list