public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug mi/28454] New: MI -var-list-children bad performance with simple pretty printers
@ 2021-10-15  8:25 andrey.lesnikov at jetbrains dot com
  2023-08-31 17:09 ` [Bug varobj/28454] " tromey at sourceware dot org
  0 siblings, 1 reply; 2+ messages in thread
From: andrey.lesnikov at jetbrains dot com @ 2021-10-15  8:25 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28454

            Bug ID: 28454
           Summary: MI -var-list-children bad performance with simple
                    pretty printers
           Product: gdb
           Version: 9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: mi
          Assignee: unassigned at sourceware dot org
          Reporter: andrey.lesnikov at jetbrains dot com
  Target Milestone: ---

Created attachment 13722
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13722&action=edit
a zip copy of the https://github.com/ozkriff/gdb_slow_var_list_children repo

A sample project (sadly, I wasn't able to minimize the sample project further)
is based on https://vulkan-tutorial.com/Multisampling Vulkan demo with minor
tweaks:

https://github.com/ozkriff/gdb_slow_var_list_children (a zip copy is also
attached)

Steps to reproduce the issue:

- clone the gdb_slow_var_list_children repo and cd into it
- `cmake -DCMAKE_BUILD_TYPE=Debug -Btarget`
- `cd target`
- `cmake --build .`
- `gdb -q -ex "source -v ../gdb-commands"`
  The gdb-commands GDB script basically sets up a simple pretty-printer from
printers.py, sets a breakpoint, launches the executable and calls
-var-list-children that take unexpectedly significant time (up to 6 seconds on
my machine with i9-9980HK) to execute despite not doing that much work.


Additional info:

- Ubuntu 20.04.3 LTS
- Linux 5.4.0-88-generic #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021 x86_64
x86_64 x86_64 GNU/Linux
- GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
- gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
- cmake version 3.16.3


The gdb-commands script:

```
# run with something like "gdb -q -ex "source -v gdb-commands" | gnomon -h 1"

interpreter-exec mi2 "-gdb-set print elements 250"
interpreter-exec mi2 "-gdb-set print repeats 0"
interpreter-exec mi2 "-gdb-set print object on"
interpreter-exec mi2 "-gdb-set print asm-demangle on"
interpreter-exec mi2 "-gdb-set python print-stack full"
interpreter-exec mi2 "-gdb-set backtrace past-main on"
interpreter-exec mi2 "-gdb-show mi-async"
interpreter-exec mi2 "handle SIGSTOP stop nopass"
interpreter-exec mi2 "info pretty-printer"

interpreter-exec mi2 "python import sys; sys.dont_write_bytecode = True;"
interpreter-exec mi2 "python import sys; sys.path.insert(0, \"..\"); from
printers import register_default_printers; register_default_printers(None);"
interpreter-exec mi2 "-enable-pretty-printing"

interpreter-exec mi2 "-file-exec-and-symbols "vksample""
interpreter-exec mi2 "-break-insert -f "src/main.cpp:357""

interpreter-exec mi2 "-gdb-set charset UTF-8"
interpreter-exec mi2 "-exec-run"

interpreter-exec mi2 "0-gdb-set $__poke_gdb=1"
interpreter-exec mi2 "-stack-list-frames --thread 1 0 100"
interpreter-exec mi2 "-stack-list-variables --thread 1 --frame 0 --no-values"
interpreter-exec mi2 "-interpreter-exec --thread 1 --frame 0 console
\"whatis/mt this\""
interpreter-exec mi2 "-data-evaluate-expression --thread 1 --frame 0 $fp"
interpreter-exec mi2 "-stack-list-frames --thread 1 1 101"

interpreter-exec mi2 "-var-create var1_this * \"this\""
interpreter-exec mi2 "-var-list-children --all-values "var1_this" -1 -1"
interpreter-exec mi2 "-var-list-children --all-values "var1_this.private" 0 44"

quit
```

printers.py:

```
import gdb


def untypedef(type_obj):
    if (type_obj.code == gdb.TYPE_CODE_REF
            or type_obj.code == getattr(gdb, 'TYPE_CODE_RVALUE_REF', None)):
        type_obj = type_obj.target()
    if type_obj.code == gdb.TYPE_CODE_TYPEDEF:
        type_obj = type_obj.strip_typedefs()
    return type_obj


def lookup(val):
    type = untypedef(val.type)
    if type.code == gdb.TYPE_CODE_PTR:
        try:
            dereferenced = val.dereference()
            dereferenced.fetch_lazy()
        except gdb.error as e:
            print('ERROR: ', str(e))
        else:
            delegate = gdb.default_visualizer(dereferenced)
            assert(delegate is None)
            # normally, the delegate would be passed into a custom pretty
printer next
    return None


def register_default_printers(obj):
    gdb.printing.register_pretty_printer(obj, lookup)
```


The main.cpp is too big to inline as a text so I'm leaving it in the
repo/attachment.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug varobj/28454] MI -var-list-children bad performance with simple pretty printers
  2021-10-15  8:25 [Bug mi/28454] New: MI -var-list-children bad performance with simple pretty printers andrey.lesnikov at jetbrains dot com
@ 2023-08-31 17:09 ` tromey at sourceware dot org
  0 siblings, 0 replies; 2+ messages in thread
From: tromey at sourceware dot org @ 2023-08-31 17:09 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28454

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|mi                          |varobj
                 CC|                            |tromey at sourceware dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-31 17:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15  8:25 [Bug mi/28454] New: MI -var-list-children bad performance with simple pretty printers andrey.lesnikov at jetbrains dot com
2023-08-31 17:09 ` [Bug varobj/28454] " tromey at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).