public inbox for
help / color / mirror / Atom feed
From: "andrey.lesnikov at jetbrains dot com" <>
Subject: [Bug mi/28454] New: MI -var-list-children bad performance with simple pretty printers
Date: Fri, 15 Oct 2021 08:25:03 +0000	[thread overview]
Message-ID: <> (raw)

            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
a zip copy of the repo

A sample project (sadly, I wasn't able to minimize the sample project further)
is based on Vulkan demo with minor
tweaks: (a zip copy is also

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, 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"


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 =
    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:
            dereferenced = val.dereference()
        except gdb.error as e:
            print('ERROR: ', str(e))
            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

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

             reply	other threads:[~2021-10-15  8:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-15  8:25 andrey.lesnikov at jetbrains dot com [this message]
2023-08-31 17:09 ` [Bug varobj/28454] " tromey at sourceware dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).