Re: Printing bitmap objects in the debugger

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: Printing bitmap objects in the debugger
Дата
Msg-id CA+TgmoYdDwuRfHShbYa0sqnJMgjr7-XbMD-B5o_BGONq4noF_w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Printing bitmap objects in the debugger  (Pavan Deolasee <pavan.deolasee@gmail.com>)
Ответы Re: Printing bitmap objects in the debugger  (Pavan Deolasee <pavan.deolasee@gmail.com>)
Re: Printing bitmap objects in the debugger  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Wed, Sep 14, 2016 at 8:01 AM, 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
>
> 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
>
>
> 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 :-)

This seems like a very complicated mechanism of substituting for a
very simple patch.  Your LLDB script is about the same number of lines
as Ashutosh's patch and only works for people who use LLDB.  Plus,
once you write it, you've got to enter the Python interpreter to use
it and then run three more lines of code that aren't easy to remember.
In contrast, with Ashutosh's proposed patch, you just write:

p bms_to_char(bms_object)

...and you're done.  Now, I grant that his approach bloats the binary
and yours does not, but nobody complains about pprint() bloating the
binary.  If that's actually an issue people are really concerned about
then let's just reject this and Ashutosh can patch his local copy.  If
that's not a serious problem then let's take the patch.  If anything,
I think this discussion shows that LLDB macros are probably too much
of a pain to be seriously considered for everyday use, unless perhaps
you're the sort of person who plans to spend the day inside the Python
shell anyway.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: select_parallel test fails with nonstandard block size
Следующее
От: Robert Haas
Дата:
Сообщение: Re: select_parallel test fails with nonstandard block size