Author Topic: Dereferencing pointers in tooltips (GDB)  (Read 8912 times)

Offline Vuki

  • Multiple posting newcomer
  • *
  • Posts: 41
Dereferencing pointers in tooltips (GDB)
« on: November 11, 2013, 11:01:46 pm »
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);

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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Dereferencing pointers in tooltips (GDB)
« Reply #1 on: November 11, 2013, 11:10:02 pm »
What do the devs think about this modification?
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...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Vuki

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: Dereferencing pointers in tooltips (GDB)
« Reply #2 on: November 12, 2013, 04:20:31 pm »
Lets start with a minimal sample that demonstrates the problem or at least posting the full log from the debugger.

Here goes a minimal sample:

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

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:

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);

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}


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}

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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Dereferencing pointers in tooltips (GDB)
« Reply #3 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Vuki

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: Dereferencing pointers in tooltips (GDB)
« Reply #4 on: November 15, 2013, 01:24:38 pm »
Should be fixed in SVN. Please test and report if there are more issues with this feature.

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