User forums > General (but related to Code::Blocks)

Dereferencing pointers in tooltips (GDB)

(1/1)

Vuki:
Hello. I've been using CodeBlocks for a long time. Recently I started setting it up in order to improve the GDB debugging performance, so I've configured various pretty printers. However, one thing that bugged me was that hovering a mouse over a pointer shows only the pointer address in the tooltip. Programmers are interested in the pointer content, not the address. Therefore, I've downloaded and compiled C::B code and run it through the debugger. I found the following code in gdb_commands.h, function GdbCmd_TooltipEvaluation::ParseOutput:


--- Code: ---            ParseGDBWatchValue(watch, contents);
            if (!m_Address.empty() && m_autoDereferenced)
                watch->SetValue(m_Address);

--- End code ---

In case of a pointer, contents already contains the dereferenced value which is correctly stored in watch. However, the next two lines write the pointer address back into watch, so the tooltip shows only the address.

Simply by removing (commenting out) these two lines I was able to show the dereferenced pointer's content in the tooltip, without any side effects observed (except for null pointers that write the "Cannot access memory at 0x0" string). So my question is what are these lines needed for?

What do the devs think about this modification? Can it be made in the trunk? I think that it improves the debugging ergonomy, no need to use the watches panel.

Tested on python-enabled GNU gdb (GDB) 7.4.50.20120522-cvs, from this forum, on Windows XP.

oBFusCATed:

--- Quote from: Vuki on November 11, 2013, 11:01:46 pm ---What do the devs think about this modification?

--- End quote ---
Lets start with a minimal sample that demonstrates the problem or at least posting the full log from the debugger.
Probably this is a bug... the idea of the code is to also print the address of the expression...

Vuki:

--- Quote from: oBFusCATed on November 11, 2013, 11:10:02 pm ---Lets start with a minimal sample that demonstrates the problem or at least posting the full log from the debugger.

--- End quote ---

Here goes a minimal sample:


--- Code: ---int main() {
    int i = 123;
    int* pi = &i;
    return 0;
}
--- End code ---

Cursor over pi. Debugger log:


--- Code: ---[debug]> whatis pi
[debug]type = int *
[debug]>>>>>>cb_gdb:
[debug]> output pi
[debug](int *) 0x23fee8>>>>>>cb_gdb:
[debug]> output *pi
[debug]123>>>>>>cb_gdb:

--- End code ---

Good, gdb dereferenced the value. Now, passing through the mentioned code:


--- Code: ---            ParseGDBWatchValue(watch, contents);
            if (!m_Address.empty() && m_autoDereferenced)
                watch->SetValue(m_Address);

--- End code ---

After ParseGDBWatchValue:


--- Code: ---(gdb) p *(watch._M_ptr)
$26 = {<cbWatch> = {_vptr.cbWatch = 0x6d903d28, m_parent = warning: (Internal er
ror: pc 0x0 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

std::tr1::weak_ptr (empty) 0x0,
    m_children = std::vector of length 0, capacity 0, m_changed = true,
    m_removed = false, m_expanded = false, m_autoUpdate = true},
  m_symbol = {<wxStringBase> = {static npos = <optimized out>,
      m_pchData = 0x7817334 L"*pi"}, <No data fields>},
  m_type = {<wxStringBase> = {static npos = <optimized out>,
      m_pchData = 0x7d63214 L"int *"}, <No data fields>},
  m_raw_value = {<wxStringBase> = {static npos = <optimized out>,
      m_pchData = 0x77ee47c L"123"}, <No data fields>},
  m_debug_value = {<wxStringBase> = {static npos = <optimized out>,
      m_pchData = 0x62b92134 L""}, <No data fields>}, m_format = Undefined,
  m_array_start = 0, m_array_count = 0, m_is_array = false,
  m_forTooltip = false}

--- End code ---


Still good, m_raw_value contains the dereferenced value. But after the next two lines:


--- Code: ---(gdb) p *(watch._M_ptr)
$27 = {<cbWatch> = {_vptr.cbWatch = 0x6d903d28, m_parent = warning: (Internal er
ror: pc 0x0 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

std::tr1::weak_ptr (empty) 0x0,
    m_children = std::vector of length 0, capacity 0, m_changed = true,
    m_removed = false, m_expanded = false, m_autoUpdate = true},
  m_symbol = {<wxStringBase> = {static npos = <optimized out>,
      m_pchData = 0x7817334 L"*pi"}, <No data fields>},
  m_type = {<wxStringBase> = {static npos = <optimized out>,
      m_pchData = 0x7d63214 L"int *"}, <No data fields>},
  m_raw_value = {<wxStringBase> = {static npos = <optimized out>,
      m_pchData = 0x77e4ca4 L"0x23fee8"}, <No data fields>},
  m_debug_value = {<wxStringBase> = {static npos = <optimized out>,
      m_pchData = 0x62b92134 L""}, <No data fields>}, m_format = Undefined,
  m_array_start = 0, m_array_count = 0, m_is_array = false,
  m_forTooltip = false}

--- End code ---

The pointer address overwrote the dereferenced value which is nowhere to be seen.
Tooltip displays: *pi | 0x23fee8 | int *
and it's wrong, it's 'pi', not '*pi'.

After these two lines are commented out, tooltip is: *pi | 123 | int *
So it works as I expected.

I hope I made it clear. I tested this on clean CB installation (latest SVN) on different computers and it always worked like this.

oBFusCATed:
Should be fixed in SVN. Please test and report if there are more issues with this feature.

Vuki:

--- Quote from: oBFusCATed on November 12, 2013, 11:02:40 pm ---Should be fixed in SVN. Please test and report if there are more issues with this feature.

--- End quote ---

Tested and seems to work fine for normal pointers. No problems found. Thank you.

Navigation

[0] Message Index

Go to full version