Re: Printing bitmap objects in the debugger

Поиск
Список
Период
Сортировка
От Ashutosh Bapat
Тема Re: Printing bitmap objects in the debugger
Дата
Msg-id CAFjFpRcjr+qOfDhD50ZcnYLUZ_dD7hnta8nmjf77jd3e73Vrzg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Printing bitmap objects in the debugger  (Pavan Deolasee <pavan.deolasee@gmail.com>)
Ответы Re: Printing bitmap objects in the debugger  (Michael Paquier <michael.paquier@gmail.com>)
Список pgsql-hackers
On Wed, Sep 14, 2016 at 5:31 PM, Pavan Deolasee
<pavan.deolasee@gmail.com> wrote:
>
> On Wed, Sep 14, 2016 at 3:46 PM, Pavan Deolasee <pavan.deolasee@gmail.com>
> wrote:
>>
>>
>>
>>  lately I'm using LVM debugger (which probably does not have something
>> equivalent),
>
>
> And I was so clueless about lldb's powerful scripting interface. For
> example, you can write something like this in bms_utils.py:
>
> import lldb
>
> def print_bms_members (bms):
>     words = bms.GetChildMemberWithName("words")
>     nwords = int(bms.GetChildMemberWithName("nwords").GetValue())
>
>     ret = 'nwords = {0} bitmap: '.format(nwords,)
>     for i in range(0, nwords):
>         ret += hex(int(words.GetChildAtIndex(0, lldb.eNoDynamicValues,
> True).GetValue()))
>
>     return ret
>

Thanks a lot for digging into it.

> And then do this while attached to lldb debugger:
>
> Process 99659 stopped
> * thread #1: tid = 0x59ba69, 0x00000001090b012f
> postgres`bms_add_member(a=0x00007fe60a0351f8, x=10) + 15 at bitmapset.c:673,
> queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
>     frame #0: 0x00000001090b012f
> postgres`bms_add_member(a=0x00007fe60a0351f8, x=10) + 15 at bitmapset.c:673
>    670 int wordnum,
>    671 bitnum;
>    672
> -> 673 if (x < 0)
>    674 elog(ERROR, "negative bitmapset member not allowed");
>    675 if (a == NULL)
>    676 return bms_make_singleton(x);
> (lldb) script
> Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>>> from bms_utils import *
>>>> bms = lldb.frame.FindVariable ("a")
>>>> print print_bms_members(bms)
> nwords = 1 bitmap: 0x200
>

I can get that kind of output by command
p *bms
p/x (or p/b) *bms->words@(bms->nwords) in gdb.

But I can certainly extend the script you wrote above to print more
meaningful output similar to outBitmapset(). But then this would be
specific to LLVM. GDB too seems to have a similar interface
https://sourceware.org/gdb/wiki/PythonGdbTutorial, so I can probably
use above script with some modifications with GDB as well. Python
script will be easier to maintain as compared to maintaining a patch
that needs to be applied and compiled.

Said that, I am not sure if every debugger supported on every platform
we support has these features. Or may be developers work on only those
platforms which have such powerful debuggers, so it's ok.

Every debugger usually has much easier way to call a function and
print its output, so having a function like the one I have in the
patch makes things easy for all the debuggers and may be developers
not familiar with python.

>
> The complete API reference is available here
> http://lldb.llvm.org/python_reference/index.html
>
> Looks like an interesting SoC project to write useful lldb/gdb scripts to
> print internal structures for ease of debugging :-)
>

+1, if we can include something like that in the repository so as to
avoid every developer maintaining a script of his/her own.

-- 
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Amit Kapila
Дата:
Сообщение: Re: Hash Indexes
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: Printing bitmap objects in the debugger